[clang] [lldb] [ASTImporter][lldb] Avoid implicit imports in VisitFieldDecl (PR #107828)

2024-09-10 Thread Michael Buch via cfe-commits

Michael137 wrote:

> As I understand it, minimal import is used in LLDB for performance reasons, 
> so we don't waste time parsing and loading AST elements that we don't need. 
> It sounds like a fine idea in general. Implicit imports of external sources 
> in Clang, however, turn import process into a minefield, where you have no 
> idea if a "pure" operation can cause a major change the target AST. 
> "Complete" types are really incomplete, and there is no single point at which 
> they are all guaranteed to be finalized.

Yup, agreed. Our idea is summarized in 
https://discourse.llvm.org/t/rfc-lldb-more-reliable-completion-of-record-types/77442.
 Basically the goal is to guarantee that a call to `getDefinition`, *will* 
fetch the definition. This is something that Clang already does, but we just 
never implement (via `CompleteRedeclChain`). You're right that the "minimal 
import" mode was implemented for perf. reasons. Though we should probably 
revisit this. I think we can make LLDB use non-minimal import for record types 
while keeping the number of transitive imports contained. It would still 
require changes to the importer to be smarter about what we import, but we 
wouldn't have these "complete but incomplete" types floating around.

> Perhaps this approach was taken to minimize impact of external sources on the 
> rest of Clang, to avoid introducing a concept of "not-fully-loaded-AST" 
> everywhere. Understandable, but we have these issues now.

Possibly, I'm not entirely sure of the history here either. But afaiu external 
sources are a thing because of Clang modules, we re-used it for DWARF later on 
(or at least that's my impression). There's quite a lot of difference in the 
way that LLDB makes use of this API, which is where some of the tension comes 
from.

https://github.com/llvm/llvm-project/pull/107828
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)

2024-09-10 Thread Jun Zhang via cfe-commits


@@ -0,0 +1,400 @@
+//===--- InterpreterValuePrinter.cpp - Value printing utils -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file implements routines for in-process value printing in clang-repl.
+//
+//===--===//
+
+#include "IncrementalParser.h"
+#include "InterpreterUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/PrettyPrinter.h"
+#include "clang/AST/Type.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Interpreter/Interpreter.h"
+#include "clang/Interpreter/Value.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Sema/Sema.h"
+
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+#include 
+
+#include 
+
+namespace clang {
+
+llvm::Expected
+Interpreter::CompileDtorCall(CXXRecordDecl *CXXRD) {
+  assert(CXXRD && "Cannot compile a destructor for a nullptr");
+  if (auto Dtor = Dtors.find(CXXRD); Dtor != Dtors.end())
+return Dtor->getSecond();
+
+  if (CXXRD->hasIrrelevantDestructor())
+return llvm::orc::ExecutorAddr{};
+
+  CXXDestructorDecl *DtorRD =
+  getCompilerInstance()->getSema().LookupDestructor(CXXRD);
+
+  llvm::StringRef Name =
+  getCodeGen()->GetMangledName(GlobalDecl(DtorRD, Dtor_Base));
+  auto AddrOrErr = getSymbolAddress(Name);
+  if (!AddrOrErr)
+return AddrOrErr.takeError();
+
+  Dtors[CXXRD] = *AddrOrErr;
+  return AddrOrErr;
+}
+
+enum InterfaceKind { NoAlloc, WithAlloc, CopyArray, NewTag };
+
+class InterfaceKindVisitor
+: public TypeVisitor {
+
+  Sema &S;
+  Expr *E;
+  llvm::SmallVectorImpl &Args;
+
+public:
+  InterfaceKindVisitor(Sema &S, Expr *E, llvm::SmallVectorImpl &Args)
+  : S(S), E(E), Args(Args) {}
+
+  InterfaceKind computeInterfaceKind(QualType Ty) {
+return Visit(Ty.getTypePtr());
+  }
+
+  InterfaceKind VisitRecordType(const RecordType *Ty) {
+return InterfaceKind::WithAlloc;
+  }
+
+  InterfaceKind VisitMemberPointerType(const MemberPointerType *Ty) {
+return InterfaceKind::WithAlloc;
+  }
+
+  InterfaceKind VisitConstantArrayType(const ConstantArrayType *Ty) {
+return InterfaceKind::CopyArray;
+  }
+
+  InterfaceKind VisitFunctionProtoType(const FunctionProtoType *Ty) {
+HandlePtrType(Ty);
+return InterfaceKind::NoAlloc;
+  }
+
+  InterfaceKind VisitPointerType(const PointerType *Ty) {
+HandlePtrType(Ty);
+return InterfaceKind::NoAlloc;
+  }
+
+  InterfaceKind VisitReferenceType(const ReferenceType *Ty) {
+ExprResult AddrOfE = S.CreateBuiltinUnaryOp(SourceLocation(), UO_AddrOf, 
E);
+assert(!AddrOfE.isInvalid() && "Can not create unary expression");
+Args.push_back(AddrOfE.get());
+return InterfaceKind::NoAlloc;
+  }
+
+  InterfaceKind VisitBuiltinType(const BuiltinType *Ty) {
+if (Ty->isNullPtrType())
+  Args.push_back(E);
+else if (Ty->isFloatingType())
+  Args.push_back(E);
+else if (Ty->isIntegralOrEnumerationType())
+  HandleIntegralOrEnumType(Ty);
+else if (Ty->isVoidType()) {
+  // Do we need to still run `E`?
+}
+
+return InterfaceKind::NoAlloc;
+  }
+
+  InterfaceKind VisitEnumType(const EnumType *Ty) {
+HandleIntegralOrEnumType(Ty);
+return InterfaceKind::NoAlloc;
+  }
+
+private:
+  // Force cast these types to the uint that fits the register size. That way 
we
+  // reduce the number of overloads of `__clang_Interpreter_SetValueNoAlloc`.
+  void HandleIntegralOrEnumType(const Type *Ty) {
+ASTContext &Ctx = S.getASTContext();
+uint64_t PtrBits = Ctx.getTypeSize(Ctx.VoidPtrTy);
+QualType UIntTy = Ctx.getBitIntType(/*Unsigned=*/true, PtrBits);
+TypeSourceInfo *TSI = Ctx.getTrivialTypeSourceInfo(UIntTy);
+ExprResult CastedExpr =
+S.BuildCStyleCastExpr(SourceLocation(), TSI, SourceLocation(), E);
+assert(!CastedExpr.isInvalid() && "Cannot create cstyle cast expr");
+Args.push_back(CastedExpr.get());
+  }
+
+  void HandlePtrType(const Type *Ty) {
+ASTContext &Ctx = S.getASTContext();
+TypeSourceInfo *TSI = Ctx.getTrivialTypeSourceInfo(Ctx.VoidPtrTy);
+ExprResult CastedExpr =
+S.BuildCStyleCastExpr(SourceLocation(), TSI, SourceLocation(), E);
+assert(!CastedExpr.isInvalid() && "Can not create cstyle cast expression");
+Args.push_back(CastedExpr.get());
+  }
+};
+
+// This synthesizes a call expression to a speciall
+// function that is responsible for generating the Value.
+// In general, we transform:
+//   clang-repl> x
+// To:
+//   // 1. If x is a built-in type like int, float.
+//   __clang_Interpreter_SetValueNoAlloc(ThisInterp, OpaqueValue, xQualType, 
x);
+//   // 2. If x is a struct, and a lvalue.
+/

[clang] [Lex] Avoid repeated hash lookups (NFC) (PR #107963)

2024-09-10 Thread Nikita Popov via cfe-commits

https://github.com/nikic approved this pull request.


https://github.com/llvm/llvm-project/pull/107963
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Format] Avoid repeated hash lookups (NFC) (PR #107962)

2024-09-10 Thread Nikita Popov via cfe-commits

https://github.com/nikic approved this pull request.


https://github.com/llvm/llvm-project/pull/107962
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Tablegen] Avoid repeated hash lookps (NFC) (PR #107961)

2024-09-10 Thread Nikita Popov via cfe-commits

https://github.com/nikic approved this pull request.


https://github.com/llvm/llvm-project/pull/107961
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [sanitizer] Document AddressSanitizer security considerations (PR #100937)

2024-09-10 Thread via cfe-commits

https://github.com/bigb4ng updated 
https://github.com/llvm/llvm-project/pull/100937

>From 7f45c4233607bb5208f4c7123f38fe21c8b8f10e Mon Sep 17 00:00:00 2001
From: bigb4ng 
Date: Sun, 28 Jul 2024 18:26:38 +0300
Subject: [PATCH] [sanitizer] Document sanitizers security considerations

Follow-up to PR #92593
---
 clang/docs/AddressSanitizer.rst   |  8 
 ...HardwareAssistedAddressSanitizerDesign.rst |  8 
 clang/docs/LeakSanitizer.rst  |  8 
 clang/docs/MemorySanitizer.rst|  8 
 clang/docs/ThreadSanitizer.rst|  8 
 clang/docs/UndefinedBehaviorSanitizer.rst | 10 ++
 llvm/docs/GwpAsan.rst | 20 +++
 7 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/clang/docs/AddressSanitizer.rst b/clang/docs/AddressSanitizer.rst
index e1997153f20370..76fdf559950599 100644
--- a/clang/docs/AddressSanitizer.rst
+++ b/clang/docs/AddressSanitizer.rst
@@ -313,6 +313,14 @@ Limitations
   usually expected.
 * Static linking of executables is not supported.
 
+Security Considerations
+===
+
+AddressSanitizer is a bug detection tool and its runtime is not meant to be
+linked against production executables. While it may be useful for testing,
+AddressSanitizer's runtime was not developed with security-sensitive
+constraints in mind and may compromise the security of the resulting 
executable.
+
 Supported Platforms
 ===
 
diff --git a/clang/docs/HardwareAssistedAddressSanitizerDesign.rst 
b/clang/docs/HardwareAssistedAddressSanitizerDesign.rst
index f89ca117427ad7..20db41c032c561 100644
--- a/clang/docs/HardwareAssistedAddressSanitizerDesign.rst
+++ b/clang/docs/HardwareAssistedAddressSanitizerDesign.rst
@@ -262,6 +262,14 @@ than that of AddressSanitizer:
 `1/TG` extra memory for the shadow
 and some overhead due to `TG`-aligning all objects.
 
+Security Considerations
+===
+
+HWASAN is a bug detection tool and its runtime is not meant to be
+linked against production executables. While it may be useful for testing,
+HWASAN's runtime was not developed with security-sensitive
+constraints in mind and may compromise the security of the resulting 
executable.
+
 Supported architectures
 ===
 HWASAN relies on `Address Tagging`_ which is only available on AArch64.
diff --git a/clang/docs/LeakSanitizer.rst b/clang/docs/LeakSanitizer.rst
index 6858f32957ebed..adcb6421c6a1f9 100644
--- a/clang/docs/LeakSanitizer.rst
+++ b/clang/docs/LeakSanitizer.rst
@@ -43,6 +43,14 @@ To use LeakSanitizer in stand-alone mode, link your program 
with
 link step, so that it would link in proper LeakSanitizer run-time library
 into the final executable.
 
+Security Considerations
+===
+
+LeakSanitizer is a bug detection tool and its runtime is not meant to be
+linked against production executables. While it may be useful for testing,
+LeakSanitizer's runtime was not developed with security-sensitive
+constraints in mind and may compromise the security of the resulting 
executable.
+
 Supported Platforms
 ===
 
diff --git a/clang/docs/MemorySanitizer.rst b/clang/docs/MemorySanitizer.rst
index bcc6cc808e8bae..886a12ff62adc5 100644
--- a/clang/docs/MemorySanitizer.rst
+++ b/clang/docs/MemorySanitizer.rst
@@ -191,6 +191,14 @@ uninstrumented libc. For example, the authors were able to 
bootstrap
 MemorySanitizer-instrumented Clang compiler by linking it with
 self-built instrumented libc++ (as a replacement for libstdc++).
 
+Security Considerations
+===
+
+MemorySanitizer is a bug detection tool and its runtime is not meant to be
+linked against production executables. While it may be useful for testing,
+MemorySanitizer's runtime was not developed with security-sensitive
+constraints in mind and may compromise the security of the resulting 
executable.
+
 Supported Platforms
 ===
 
diff --git a/clang/docs/ThreadSanitizer.rst b/clang/docs/ThreadSanitizer.rst
index 98d5307d824f9e..5dc78fa5a7a564 100644
--- a/clang/docs/ThreadSanitizer.rst
+++ b/clang/docs/ThreadSanitizer.rst
@@ -135,6 +135,14 @@ Limitations
   flag had been supplied if compiling without ``-fPIC``, and as though the
   ``-pie`` flag had been supplied if linking an executable.
 
+Security Considerations
+---
+
+ThreadSanitizer is a bug detection tool and its runtime is not meant to be
+linked against production executables. While it may be useful for testing,
+ThreadSanitizer's runtime was not developed with security-sensitive
+constraints in mind and may compromise the security of the resulting 
executable.
+
 Current Status
 --
 
diff --git a/clang/docs/UndefinedBehaviorSanitizer.rst 
b/clang/docs/UndefinedBehaviorSanitizer.rst
index 531d56e313826c..e5dfd750f4e6f7 100644
--- a/clang/docs/UndefinedBehaviorSanitizer.rst
+++ b/clang/docs/UndefinedBehaviorSanitizer.

[clang] [PowerPC] Support set_flt_rounds builtin (PR #73750)

2024-09-10 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises updated 
https://github.com/llvm/llvm-project/pull/73750

>From db3bd53b27ee5fcb0572e0a43ca4cd4ed1376e65 Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Tue, 10 Sep 2024 15:25:37 +0800
Subject: [PATCH] [PowerPC] Support set_flt_rounds builtin

---
 clang/docs/LanguageExtensions.rst   | 6 +++---
 clang/lib/Sema/SemaChecking.cpp | 4 +++-
 clang/test/CodeGen/builtin_set_flt_rounds.c | 3 +++
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index c08697282cbfe8..35642fdbdb4b3b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3919,9 +3919,9 @@ standard:
 - ``4``  - to nearest, ties away from zero
 The effect of passing some other value to ``__builtin_flt_rounds`` is
 implementation-defined. ``__builtin_set_flt_rounds`` is currently only 
supported
-to work on x86, x86_64, Arm and AArch64 targets. These builtins read and modify
-the floating-point environment, which is not always allowed and may have 
unexpected
-behavior. Please see the section on `Accessing the floating point environment 
`_
 for more information.
+to work on x86, x86_64, powerpc, powerpc64, Arm and AArch64 targets. These 
builtins
+read and modify the floating-point environment, which is not always allowed 
and may
+have unexpected behavior. Please see the section on `Accessing the floating 
point environment 
`_
 for more information.
 
 String builtins
 ---
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 99500daca295c9..081cb16a55e535 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2212,7 +2212,9 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 if (CheckBuiltinTargetInSupported(
 *this, TheCall,
 {llvm::Triple::x86, llvm::Triple::x86_64, llvm::Triple::arm,
- llvm::Triple::thumb, llvm::Triple::aarch64, 
llvm::Triple::amdgcn}))
+ llvm::Triple::thumb, llvm::Triple::aarch64, llvm::Triple::amdgcn,
+ llvm::Triple::ppc, llvm::Triple::ppc64, llvm::Triple::ppcle,
+ llvm::Triple::ppc64le}))
   return ExprError();
 break;
 
diff --git a/clang/test/CodeGen/builtin_set_flt_rounds.c 
b/clang/test/CodeGen/builtin_set_flt_rounds.c
index fc483fcc232aa4..c5c8e905dbd4f8 100644
--- a/clang/test/CodeGen/builtin_set_flt_rounds.c
+++ b/clang/test/CodeGen/builtin_set_flt_rounds.c
@@ -2,6 +2,9 @@
 // RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck 
%s
 // RUN: %clang_cc1 -triple aarch64-gnu-linux %s -emit-llvm -o - | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-windows-msvc %s -emit-llvm -o - | FileCheck 
%s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -emit-llvm -o - | FileCheck %s
 void test_builtin_set_flt_rounds() {
   __builtin_set_flt_rounds(1);
   // CHECK: call void @llvm.set.rounding(i32 1)

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [PowerPC] Support set_flt_rounds builtin (PR #73750)

2024-09-10 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises ready_for_review 
https://github.com/llvm/llvm-project/pull/73750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [APINotes] Avoid repeated hash lookups (NFC) (PR #107959)

2024-09-10 Thread Nikita Popov via cfe-commits

https://github.com/nikic approved this pull request.


https://github.com/llvm/llvm-project/pull/107959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [PowerPC] Support set_flt_rounds builtin (PR #73750)

2024-09-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qiu Chaofan (ecnelises)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/73750.diff


3 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+3-3) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+3-1) 
- (modified) clang/test/CodeGen/builtin_set_flt_rounds.c (+3) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index c08697282cbfe8..35642fdbdb4b3b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3919,9 +3919,9 @@ standard:
 - ``4``  - to nearest, ties away from zero
 The effect of passing some other value to ``__builtin_flt_rounds`` is
 implementation-defined. ``__builtin_set_flt_rounds`` is currently only 
supported
-to work on x86, x86_64, Arm and AArch64 targets. These builtins read and modify
-the floating-point environment, which is not always allowed and may have 
unexpected
-behavior. Please see the section on `Accessing the floating point environment 
`_
 for more information.
+to work on x86, x86_64, powerpc, powerpc64, Arm and AArch64 targets. These 
builtins
+read and modify the floating-point environment, which is not always allowed 
and may
+have unexpected behavior. Please see the section on `Accessing the floating 
point environment 
`_
 for more information.
 
 String builtins
 ---
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 99500daca295c9..081cb16a55e535 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2212,7 +2212,9 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 if (CheckBuiltinTargetInSupported(
 *this, TheCall,
 {llvm::Triple::x86, llvm::Triple::x86_64, llvm::Triple::arm,
- llvm::Triple::thumb, llvm::Triple::aarch64, 
llvm::Triple::amdgcn}))
+ llvm::Triple::thumb, llvm::Triple::aarch64, llvm::Triple::amdgcn,
+ llvm::Triple::ppc, llvm::Triple::ppc64, llvm::Triple::ppcle,
+ llvm::Triple::ppc64le}))
   return ExprError();
 break;
 
diff --git a/clang/test/CodeGen/builtin_set_flt_rounds.c 
b/clang/test/CodeGen/builtin_set_flt_rounds.c
index fc483fcc232aa4..c5c8e905dbd4f8 100644
--- a/clang/test/CodeGen/builtin_set_flt_rounds.c
+++ b/clang/test/CodeGen/builtin_set_flt_rounds.c
@@ -2,6 +2,9 @@
 // RUN: %clang_cc1 -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck 
%s
 // RUN: %clang_cc1 -triple aarch64-gnu-linux %s -emit-llvm -o - | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-windows-msvc %s -emit-llvm -o - | FileCheck 
%s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -emit-llvm -o - | FileCheck %s
 void test_builtin_set_flt_rounds() {
   __builtin_set_flt_rounds(1);
   // CHECK: call void @llvm.set.rounding(i32 1)

``




https://github.com/llvm/llvm-project/pull/73750
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [sanitizer] Document AddressSanitizer security considerations (PR #100937)

2024-09-10 Thread via cfe-commits

bigb4ng wrote:

@vitalybuka Done.

@fmayer If you have any other nits (especially for GWP-ASan section) I'd be 
glad to hear them.

https://github.com/llvm/llvm-project/pull/100937
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Tablegen] Avoid repeated hash lookps (NFC) (PR #107961)

2024-09-10 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh approved this pull request.


https://github.com/llvm/llvm-project/pull/107961
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add code completion for C++20 keywords. (PR #107982)

2024-09-10 Thread via cfe-commits

https://github.com/16bit-ykiko created 
https://github.com/llvm/llvm-project/pull/107982

This commit adds code completion for C++20 keywords.

1. complete `concept` in template context
- [x] `template conce^` -> `concept`
- [ ] `conce^`

2. complete `requires` 
- [x] constraints in template context: `template requi^` -> 
`requires`
- [x] requires expression: `int x = requ^` -> `requires (parameters) { 
requirements }`
- [x] nested requirement: `requires { requ^ }` -> `requires expression ;` 

3. complete coroutine keywords
- [x] `co_await^` in expression: `co_aw^` -> `co_await expression;`
- [x] `co_yield` in function body: `co_yi^` -> `co_yield expression;` 
- [x] `co_return` in function body: `co_re^` -> `co_return expression;`

4. specifiers: `char8_t`, `consteval`, `constinit`


>From fedea9e4fd57b618fe341e0c30982bff0f098c52 Mon Sep 17 00:00:00 2001
From: ykiko 
Date: Tue, 10 Sep 2024 14:59:10 +0800
Subject: [PATCH 1/2] add co_return, co_await, co_yield, consteval, constinit,
 concept, requires, char8_t.

---
 clang/lib/Sema/SemaCodeComplete.cpp | 61 +
 1 file changed, 61 insertions(+)

diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 88d4732c7d5c6a..d8f6b1dada942a 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -1837,6 +1837,11 @@ static void AddTypeSpecifierResults(const LangOptions 
&LangOpts,
   Builder.AddChunk(CodeCompletionString::CK_RightParen);
   Results.AddResult(Result(Builder.TakeString()));
 }
+
+if(LangOpts.CPlusPlus20){
+  Results.AddResult(Result("char8_t", CCP_Type));
+  Results.AddResult(Result("concept", CCP_Keyword));
+}
   } else
 Results.AddResult(Result("__auto_type", CCP_Type));
 
@@ -1889,6 +1894,10 @@ 
AddStorageSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC,
 Results.AddResult(Result("constexpr"));
 Results.AddResult(Result("thread_local"));
   }
+
+  if (LangOpts.CPlusPlus20) {
+Results.AddResult(Result("constinit"));
+  }
 }
 
 static void
@@ -1912,6 +1921,9 @@ 
AddFunctionSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC,
   case SemaCodeCompletion::PCC_Template:
 if (LangOpts.CPlusPlus || LangOpts.C99)
   Results.AddResult(Result("inline"));
+
+if (LangOpts.CPlusPlus20)
+  Results.AddResult(Result("consteval"));
 break;
 
   case SemaCodeCompletion::PCC_ObjCInstanceVariableList:
@@ -2487,6 +2499,14 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
   Builder.AddPlaceholderChunk("expression");
   Builder.AddChunk(CodeCompletionString::CK_SemiColon);
   Results.AddResult(Result(Builder.TakeString()));
+  // "co_return expression ;" for coroutines(C++20).
+  if (SemaRef.getLangOpts().CPlusPlus20) {
+Builder.AddTypedTextChunk("co_return");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+Results.AddResult(Result(Builder.TakeString()));
+  }
   // When boolean, also add 'return true;' and 'return false;'.
   if (ReturnType->isBooleanType()) {
 Builder.AddTypedTextChunk("return true");
@@ -2707,6 +2727,47 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
 Builder.AddChunk(CodeCompletionString::CK_RightParen);
 Results.AddResult(Result(Builder.TakeString()));
   }
+
+  if (SemaRef.getLangOpts().CPlusPlus20) {
+// co_await expression
+Builder.AddResultTypeChunk("");
+Builder.AddTypedTextChunk("co_await");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Results.AddResult(Result(Builder.TakeString()));
+
+// co_yield expression
+Builder.AddResultTypeChunk("");
+Builder.AddTypedTextChunk("co_yield");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Results.AddResult(Result(Builder.TakeString()));
+
+// requires (parameters) { requirements }
+Builder.AddResultTypeChunk("bool");
+Builder.AddTypedTextChunk("requires");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+Builder.AddPlaceholderChunk("parameters");
+Builder.AddChunk(CodeCompletionString::CK_RightParen);
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddPlaceholderChunk("requirements");
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddChunk(CodeCompletionString::CK_RightBrace);
+Results.Ad

[clang] Add code completion for C++20 keywords. (PR #107982)

2024-09-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: ykiko (16bit-ykiko)


Changes

This commit adds code completion for C++20 keywords.

1. complete `concept` in template context
- [x] `template conce^` -> `concept`
- [ ] `conce^`

2. complete `requires` 
- [x] constraints in template context: `template requi^` 
-> `requires`
- [x] requires expression: `int x = requ^` -> `requires (parameters) { 
requirements }`
- [x] nested requirement: `requires { requ^ }` -> `requires expression 
;` 

3. complete coroutine keywords
- [x] `co_await^` in expression: `co_aw^` -> `co_await expression;`
- [x] `co_yield` in function body: `co_yi^` -> `co_yield expression;` 
- [x] `co_return` in function body: `co_re^` -> `co_return expression;`

4. specifiers: `char8_t`, `consteval`, `constinit`


---
Full diff: https://github.com/llvm/llvm-project/pull/107982.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+69) 


``diff
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 88d4732c7d5c6a..4647d65430b8c3 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -1837,6 +1837,10 @@ static void AddTypeSpecifierResults(const LangOptions 
&LangOpts,
   Builder.AddChunk(CodeCompletionString::CK_RightParen);
   Results.AddResult(Result(Builder.TakeString()));
 }
+
+if(LangOpts.CPlusPlus20){
+  Results.AddResult(Result("char8_t", CCP_Type));
+}
   } else
 Results.AddResult(Result("__auto_type", CCP_Type));
 
@@ -1889,6 +1893,10 @@ 
AddStorageSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC,
 Results.AddResult(Result("constexpr"));
 Results.AddResult(Result("thread_local"));
   }
+
+  if (LangOpts.CPlusPlus20) {
+Results.AddResult(Result("constinit"));
+  }
 }
 
 static void
@@ -1912,6 +1920,9 @@ 
AddFunctionSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC,
   case SemaCodeCompletion::PCC_Template:
 if (LangOpts.CPlusPlus || LangOpts.C99)
   Results.AddResult(Result("inline"));
+
+if (LangOpts.CPlusPlus20)
+  Results.AddResult(Result("consteval"));
 break;
 
   case SemaCodeCompletion::PCC_ObjCInstanceVariableList:
@@ -2254,6 +2265,10 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
 [[fallthrough]];
 
   case SemaCodeCompletion::PCC_Template:
+if (SemaRef.getLangOpts().CPlusPlus20 && CCC == 
SemaCodeCompletion::PCC_Template)
+Results.AddResult(Result("concept", CCP_Keyword));
+[[fallthrough]];
+
   case SemaCodeCompletion::PCC_MemberTemplate:
 if (SemaRef.getLangOpts().CPlusPlus && Results.includeCodePatterns()) {
   // template < parameters >
@@ -2266,6 +2281,11 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
   Results.AddResult(Result("template", CodeCompletionResult::RK_Keyword));
 }
 
+if(SemaRef.getLangOpts().CPlusPlus20 && 
+  (CCC == SemaCodeCompletion::PCC_Template || CCC == 
SemaCodeCompletion::PCC_MemberTemplate)) {
+  Results.AddResult(Result("requires", CCP_Keyword));
+}
+
 AddStorageSpecifiers(CCC, SemaRef.getLangOpts(), Results);
 AddFunctionSpecifiers(CCC, SemaRef.getLangOpts(), Results);
 break;
@@ -2487,6 +2507,14 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
   Builder.AddPlaceholderChunk("expression");
   Builder.AddChunk(CodeCompletionString::CK_SemiColon);
   Results.AddResult(Result(Builder.TakeString()));
+  // "co_return expression ;" for coroutines(C++20).
+  if (SemaRef.getLangOpts().CPlusPlus20) {
+Builder.AddTypedTextChunk("co_return");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+Results.AddResult(Result(Builder.TakeString()));
+  }
   // When boolean, also add 'return true;' and 'return false;'.
   if (ReturnType->isBooleanType()) {
 Builder.AddTypedTextChunk("return true");
@@ -2707,6 +2735,47 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
 Builder.AddChunk(CodeCompletionString::CK_RightParen);
 Results.AddResult(Result(Builder.TakeString()));
   }
+
+  if (SemaRef.getLangOpts().CPlusPlus20) {
+// co_await expression
+Builder.AddResultTypeChunk("");
+Builder.AddTypedTextChunk("co_await");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Results.AddResult(Result(Builder.TakeString()));
+
+// co_yield expression
+Builder.AddResultTypeChunk("");
+Builder.AddTypedTextChunk("co_yield");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Results.AddResult(Result(Bu

[clang] Add code completion for C++20 keywords. (PR #107982)

2024-09-10 Thread via cfe-commits

https://github.com/16bit-ykiko edited 
https://github.com/llvm/llvm-project/pull/107982
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] correct argument offset for function template partial ordering (PR #107972)

2024-09-10 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/107972
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add code completion for C++20 keywords. (PR #107982)

2024-09-10 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 1c334debecd70bd28e61a36c40c3f96cf5467331 
9a1a85c1c98a7e1826a3836028ddf7d37fdecd90 --extensions cpp -- 
clang/lib/Sema/SemaCodeComplete.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 4647d65430..3477604619 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -1838,7 +1838,7 @@ static void AddTypeSpecifierResults(const LangOptions 
&LangOpts,
   Results.AddResult(Result(Builder.TakeString()));
 }
 
-if(LangOpts.CPlusPlus20){
+if (LangOpts.CPlusPlus20) {
   Results.AddResult(Result("char8_t", CCP_Type));
 }
   } else
@@ -2265,8 +2265,9 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
 [[fallthrough]];
 
   case SemaCodeCompletion::PCC_Template:
-if (SemaRef.getLangOpts().CPlusPlus20 && CCC == 
SemaCodeCompletion::PCC_Template)
-Results.AddResult(Result("concept", CCP_Keyword));
+if (SemaRef.getLangOpts().CPlusPlus20 &&
+CCC == SemaCodeCompletion::PCC_Template)
+  Results.AddResult(Result("concept", CCP_Keyword));
 [[fallthrough]];
 
   case SemaCodeCompletion::PCC_MemberTemplate:
@@ -2281,8 +2282,9 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
   Results.AddResult(Result("template", CodeCompletionResult::RK_Keyword));
 }
 
-if(SemaRef.getLangOpts().CPlusPlus20 && 
-  (CCC == SemaCodeCompletion::PCC_Template || CCC == 
SemaCodeCompletion::PCC_MemberTemplate)) {
+if (SemaRef.getLangOpts().CPlusPlus20 &&
+(CCC == SemaCodeCompletion::PCC_Template ||
+ CCC == SemaCodeCompletion::PCC_MemberTemplate)) {
   Results.AddResult(Result("requires", CCP_Keyword));
 }
 
@@ -2766,7 +2768,7 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
 Builder.AddChunk(CodeCompletionString::CK_RightBrace);
 Results.AddResult(Result(Builder.TakeString()));
 
-if(llvm::isa(SemaRef.CurContext)){
+if (llvm::isa(SemaRef.CurContext)) {
   // requires expression ;
   Builder.AddResultTypeChunk("");
   Builder.AddTypedTextChunk("requires");

``




https://github.com/llvm/llvm-project/pull/107982
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-10 Thread via cfe-commits

Discookie wrote:

Internal was the wrong word there, the distinction is only about whether AnnexK 
is available or not, in the context of the checked code. We certainly could 
eliminate `CustomAnnexKFunctions`, but that would mean that it's the user's 
responsibility to check whether AnnexK is available, outside of the code being 
checked.
Ultimately I don't think it would get too much use, if for nothing other than 
being able to reproduce the default-checked functions with just the 
`Custom__Functions`.

https://github.com/llvm/llvm-project/pull/106350
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Format] Avoid repeated hash lookups (NFC) (PR #107962)

2024-09-10 Thread Owen Pan via cfe-commits

https://github.com/owenca approved this pull request.


https://github.com/llvm/llvm-project/pull/107962
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add code completion for C++20 keywords. (PR #107982)

2024-09-10 Thread via cfe-commits

https://github.com/16bit-ykiko updated 
https://github.com/llvm/llvm-project/pull/107982

>From fedea9e4fd57b618fe341e0c30982bff0f098c52 Mon Sep 17 00:00:00 2001
From: ykiko 
Date: Tue, 10 Sep 2024 14:59:10 +0800
Subject: [PATCH 1/3] add co_return, co_await, co_yield, consteval, constinit,
 concept, requires, char8_t.

---
 clang/lib/Sema/SemaCodeComplete.cpp | 61 +
 1 file changed, 61 insertions(+)

diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 88d4732c7d5c6a..d8f6b1dada942a 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -1837,6 +1837,11 @@ static void AddTypeSpecifierResults(const LangOptions 
&LangOpts,
   Builder.AddChunk(CodeCompletionString::CK_RightParen);
   Results.AddResult(Result(Builder.TakeString()));
 }
+
+if(LangOpts.CPlusPlus20){
+  Results.AddResult(Result("char8_t", CCP_Type));
+  Results.AddResult(Result("concept", CCP_Keyword));
+}
   } else
 Results.AddResult(Result("__auto_type", CCP_Type));
 
@@ -1889,6 +1894,10 @@ 
AddStorageSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC,
 Results.AddResult(Result("constexpr"));
 Results.AddResult(Result("thread_local"));
   }
+
+  if (LangOpts.CPlusPlus20) {
+Results.AddResult(Result("constinit"));
+  }
 }
 
 static void
@@ -1912,6 +1921,9 @@ 
AddFunctionSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC,
   case SemaCodeCompletion::PCC_Template:
 if (LangOpts.CPlusPlus || LangOpts.C99)
   Results.AddResult(Result("inline"));
+
+if (LangOpts.CPlusPlus20)
+  Results.AddResult(Result("consteval"));
 break;
 
   case SemaCodeCompletion::PCC_ObjCInstanceVariableList:
@@ -2487,6 +2499,14 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
   Builder.AddPlaceholderChunk("expression");
   Builder.AddChunk(CodeCompletionString::CK_SemiColon);
   Results.AddResult(Result(Builder.TakeString()));
+  // "co_return expression ;" for coroutines(C++20).
+  if (SemaRef.getLangOpts().CPlusPlus20) {
+Builder.AddTypedTextChunk("co_return");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+Results.AddResult(Result(Builder.TakeString()));
+  }
   // When boolean, also add 'return true;' and 'return false;'.
   if (ReturnType->isBooleanType()) {
 Builder.AddTypedTextChunk("return true");
@@ -2707,6 +2727,47 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
 Builder.AddChunk(CodeCompletionString::CK_RightParen);
 Results.AddResult(Result(Builder.TakeString()));
   }
+
+  if (SemaRef.getLangOpts().CPlusPlus20) {
+// co_await expression
+Builder.AddResultTypeChunk("");
+Builder.AddTypedTextChunk("co_await");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Results.AddResult(Result(Builder.TakeString()));
+
+// co_yield expression
+Builder.AddResultTypeChunk("");
+Builder.AddTypedTextChunk("co_yield");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Results.AddResult(Result(Builder.TakeString()));
+
+// requires (parameters) { requirements }
+Builder.AddResultTypeChunk("bool");
+Builder.AddTypedTextChunk("requires");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+Builder.AddPlaceholderChunk("parameters");
+Builder.AddChunk(CodeCompletionString::CK_RightParen);
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddPlaceholderChunk("requirements");
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddChunk(CodeCompletionString::CK_RightBrace);
+Results.AddResult(Result(Builder.TakeString()));
+
+if(llvm::isa(SemaRef.CurContext)){
+  // requires expression ;
+  Builder.AddResultTypeChunk("");
+  Builder.AddTypedTextChunk("requires");
+  Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+  Builder.AddPlaceholderChunk("expression");
+  Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+  Results.AddResult(Result(Builder.TakeString()));
+}
+  }
 }
 
 if (SemaRef.getLangOpts().ObjC) {

>From 36a0db2b827baaabe17c5cd7b576802be586c69c Mon Sep 17 00:00:00 2001
From: ykiko 
Date: Tue, 10 Sep 2024 15:50:04 +0800
Subject: [PATCH 2/3] make concept and requires more sensitive to context.

---
 c

[clang-tools-extra] [clang-tidy] add default error message for performance-avoid-endl (PR #107867)

2024-09-10 Thread Danny Mösch via cfe-commits


@@ -225,3 +225,14 @@ void bad_custom_stream() {
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use 'std::endl' with 
streams; use '\n' instead [performance-avoid-endl]
   // CHECK-FIXES: logger << '\n';
 }
+
+namespace gh107859 {
+
+#define ENDL std::endl;
+
+void bad_macro() {
+  std::cout << ENDL;

SimplyDanny wrote:

But a replacement is always added, isn't it? What am I missing?

https://github.com/llvm/llvm-project/pull/107867
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [Clang] Add __type_list_dedup builtin to deduplicate types in template arguments (PR #106730)

2024-09-10 Thread Ilya Biryukov via cfe-commits


@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __type_list_dedup BuiltinTemplateDecl.
+  BTK__type_list_dedup,

ilya-biryukov wrote:

I have mentioned that in the RFC, see [alternatives 
considered](https://discourse.llvm.org/t/rfc-adding-builtin-for-deduplicating-type-lists/80986#p-328944-alternative-considered-type-trait-4)
 section.

I think the builtin template is better because it:
- provides the most obvious semantics for type aliases and avoids confusion,
- avoids the need for instantiation of the underlying template with 
non-duplicated list types,
- is simpler to implement.

https://github.com/llvm/llvm-project/pull/106730
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Format] Avoid repeated hash lookups (NFC) (PR #107962)

2024-09-10 Thread Owen Pan via cfe-commits


@@ -86,9 +86,7 @@ void ObjCPropertyAttributeOrderFixer::sortPropertyAttributes(
   Value = Tok->TokenText;
 }
 
-auto It = SortOrderMap.find(Attribute);
-if (It == SortOrderMap.end())
-  It = SortOrderMap.insert({Attribute, SortOrderMap.size()}).first;
+auto It = SortOrderMap.try_emplace(Attribute, SortOrderMap.size()).first;
 
 // Sort the indices based on the priority stored in `SortOrderMap`.
 const auto Ordinal = It->second;

owenca wrote:

My preference:
```suggestion
// Sort the indices based on the priority stored in `SortOrderMap`.
const auto Ordinal =
SortOrderMap.try_emplace(Attribute, SortOrderMap.size()).first->second;
```
And delete lines 89-91.

https://github.com/llvm/llvm-project/pull/107962
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [Clang] Add __type_list_dedup builtin to deduplicate types in template arguments (PR #106730)

2024-09-10 Thread Ilya Biryukov via cfe-commits


@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __type_list_dedup BuiltinTemplateDecl.
+  BTK__type_list_dedup,

ilya-biryukov wrote:

On the argument of adding `VariadicTransformType`, maybe it's useful for 
something, but I definitely don't see why introducing a new bulitin template is 
more complicated than introducing a new type trait. I think they're quite on 
par in terms of complexity and we should be looking at what fits the language 
design better (see first two bullet points above on why I feel it's a better 
choice for the language).

https://github.com/llvm/llvm-project/pull/106730
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [Clang] Add __type_list_dedup builtin to deduplicate types in template arguments (PR #106730)

2024-09-10 Thread via cfe-commits

cor3ntin wrote:

(This is in my list of PR/RFC to review, I'll try to get to it this week)

https://github.com/llvm/llvm-project/pull/106730
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [Clang] Add __type_list_dedup builtin to deduplicate types in template arguments (PR #106730)

2024-09-10 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov updated 
https://github.com/llvm/llvm-project/pull/106730

>From a46885df62ff64f355abb010f778d84309acd10f Mon Sep 17 00:00:00 2001
From: Ilya Biryukov 
Date: Fri, 23 Aug 2024 17:27:26 +0200
Subject: [PATCH 1/5] [Clang] Add __type_list_dedup builtin to deduplicate
 types in template arguments

This allows to deduplicate the type lists efficiently in C++. It is
possible to achieve the same effect via template metaprogramming, but
performance of the resulting code is much lower than in the compiler.

We have observed that this code is quite common in our internal codebase
and this builtin allows to have significant savings (up to 25% of
compile time on targets that already take 3 minutes to compile).
The same builtin is also used widely enough in the codebase that we
expect a savings from a long tail of uses, too, although it is hard to
put an estimate on this number in advance.

The implementation aims to be as simple as possible and relies on the
exsisting machinery for builtin templates.
---
 .../clangd/unittests/FindTargetTests.cpp  |  6 
 clang/include/clang/AST/ASTContext.h  | 11 ++
 clang/include/clang/AST/DeclID.h  |  3 ++
 clang/include/clang/Basic/Builtins.h  |  5 ++-
 clang/lib/AST/ASTContext.cpp  |  8 +
 clang/lib/AST/ASTImporter.cpp |  3 ++
 clang/lib/AST/DeclTemplate.cpp| 31 
 clang/lib/Lex/PPMacroExpansion.cpp|  1 +
 clang/lib/Sema/SemaLookup.cpp |  7 +++-
 clang/lib/Sema/SemaTemplate.cpp   | 36 +--
 clang/lib/Serialization/ASTReader.cpp |  6 
 clang/lib/Serialization/ASTWriter.cpp |  3 ++
 .../test/Import/builtin-template/Inputs/S.cpp |  7 
 clang/test/Import/builtin-template/test.cpp   | 10 +-
 clang/test/PCH/type_list_dedup.cpp| 20 +++
 .../SemaTemplate/temp-param-list-dedup.cpp| 33 +
 16 files changed, 185 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/PCH/type_list_dedup.cpp
 create mode 100644 clang/test/SemaTemplate/temp-param-list-dedup.cpp

diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 3220a5a6a98250..d9f788cbf2a8a2 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -731,6 +731,12 @@ TEST_F(TargetDeclTest, BuiltinTemplates) {
 using type_pack_element = [[__type_pack_element]];
   )cpp";
   EXPECT_DECLS("TemplateSpecializationTypeLoc", );
+
+  Code = R"cpp(
+template  Templ, class... Types>
+using type_list_dedup = [[__type_list_dedup]];
+  )cpp";
+  EXPECT_DECLS("TemplateSpecializationTypeLoc", );
 }
 
 TEST_F(TargetDeclTest, MemberOfTemplate) {
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 89bb5768dbd40d..1960ec1e99f652 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -401,6 +401,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__type_list_dedup'.
+  mutable IdentifierInfo *TypeListDedupName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -608,6 +611,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *TypeListDedupDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager &SourceMgr;
@@ -1115,6 +1119,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getTypeListDedupDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -2006,6 +2011,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getTypeListDedupName() const {
+if (!TypeListDedupName)
+  TypeListDedupName = &Idents.get("__type_list_dedup");
+return TypeListDedupName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index 81454a247229f5..41cecf1b8a9ebf 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -83,6 +83,9 @@ enum PredefinedDeclIDs {
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID,
 
+  /// The

[clang] [clang-tools-extra] [Clang] Add __type_list_dedup builtin to deduplicate types in template arguments (PR #106730)

2024-09-10 Thread Ilya Biryukov via cfe-commits


@@ -38,9 +40,11 @@
 #include "clang/Sema/Template.h"
 #include "clang/Sema/TemplateDeduction.h"
 #include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/raw_ostream.h"

ilya-biryukov wrote:

thanks! removed it.

https://github.com/llvm/llvm-project/pull/106730
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Attempt to further split the arch default and implied exts. (PR #106304)

2024-09-10 Thread Tomas Matheson via cfe-commits

tmatheson-arm wrote:

Are you planning to follow through with this?

https://github.com/llvm/llvm-project/pull/106304
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add code completion for C++20 keywords. (PR #107982)

2024-09-10 Thread via cfe-commits

https://github.com/16bit-ykiko updated 
https://github.com/llvm/llvm-project/pull/107982

>From fedea9e4fd57b618fe341e0c30982bff0f098c52 Mon Sep 17 00:00:00 2001
From: ykiko 
Date: Tue, 10 Sep 2024 14:59:10 +0800
Subject: [PATCH 1/4] add co_return, co_await, co_yield, consteval, constinit,
 concept, requires, char8_t.

---
 clang/lib/Sema/SemaCodeComplete.cpp | 61 +
 1 file changed, 61 insertions(+)

diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 88d4732c7d5c6a..d8f6b1dada942a 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -1837,6 +1837,11 @@ static void AddTypeSpecifierResults(const LangOptions 
&LangOpts,
   Builder.AddChunk(CodeCompletionString::CK_RightParen);
   Results.AddResult(Result(Builder.TakeString()));
 }
+
+if(LangOpts.CPlusPlus20){
+  Results.AddResult(Result("char8_t", CCP_Type));
+  Results.AddResult(Result("concept", CCP_Keyword));
+}
   } else
 Results.AddResult(Result("__auto_type", CCP_Type));
 
@@ -1889,6 +1894,10 @@ 
AddStorageSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC,
 Results.AddResult(Result("constexpr"));
 Results.AddResult(Result("thread_local"));
   }
+
+  if (LangOpts.CPlusPlus20) {
+Results.AddResult(Result("constinit"));
+  }
 }
 
 static void
@@ -1912,6 +1921,9 @@ 
AddFunctionSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC,
   case SemaCodeCompletion::PCC_Template:
 if (LangOpts.CPlusPlus || LangOpts.C99)
   Results.AddResult(Result("inline"));
+
+if (LangOpts.CPlusPlus20)
+  Results.AddResult(Result("consteval"));
 break;
 
   case SemaCodeCompletion::PCC_ObjCInstanceVariableList:
@@ -2487,6 +2499,14 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
   Builder.AddPlaceholderChunk("expression");
   Builder.AddChunk(CodeCompletionString::CK_SemiColon);
   Results.AddResult(Result(Builder.TakeString()));
+  // "co_return expression ;" for coroutines(C++20).
+  if (SemaRef.getLangOpts().CPlusPlus20) {
+Builder.AddTypedTextChunk("co_return");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+Results.AddResult(Result(Builder.TakeString()));
+  }
   // When boolean, also add 'return true;' and 'return false;'.
   if (ReturnType->isBooleanType()) {
 Builder.AddTypedTextChunk("return true");
@@ -2707,6 +2727,47 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
 Builder.AddChunk(CodeCompletionString::CK_RightParen);
 Results.AddResult(Result(Builder.TakeString()));
   }
+
+  if (SemaRef.getLangOpts().CPlusPlus20) {
+// co_await expression
+Builder.AddResultTypeChunk("");
+Builder.AddTypedTextChunk("co_await");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Results.AddResult(Result(Builder.TakeString()));
+
+// co_yield expression
+Builder.AddResultTypeChunk("");
+Builder.AddTypedTextChunk("co_yield");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Results.AddResult(Result(Builder.TakeString()));
+
+// requires (parameters) { requirements }
+Builder.AddResultTypeChunk("bool");
+Builder.AddTypedTextChunk("requires");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+Builder.AddPlaceholderChunk("parameters");
+Builder.AddChunk(CodeCompletionString::CK_RightParen);
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddPlaceholderChunk("requirements");
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddChunk(CodeCompletionString::CK_RightBrace);
+Results.AddResult(Result(Builder.TakeString()));
+
+if(llvm::isa(SemaRef.CurContext)){
+  // requires expression ;
+  Builder.AddResultTypeChunk("");
+  Builder.AddTypedTextChunk("requires");
+  Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+  Builder.AddPlaceholderChunk("expression");
+  Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+  Results.AddResult(Result(Builder.TakeString()));
+}
+  }
 }
 
 if (SemaRef.getLangOpts().ObjC) {

>From 36a0db2b827baaabe17c5cd7b576802be586c69c Mon Sep 17 00:00:00 2001
From: ykiko 
Date: Tue, 10 Sep 2024 15:50:04 +0800
Subject: [PATCH 2/4] make concept and requires more sensitive to context.

---
 c

[clang] Add code completion for C++20 keywords. (PR #107982)

2024-09-10 Thread via cfe-commits

https://github.com/16bit-ykiko updated 
https://github.com/llvm/llvm-project/pull/107982

>From fedea9e4fd57b618fe341e0c30982bff0f098c52 Mon Sep 17 00:00:00 2001
From: ykiko 
Date: Tue, 10 Sep 2024 14:59:10 +0800
Subject: [PATCH 1/5] add co_return, co_await, co_yield, consteval, constinit,
 concept, requires, char8_t.

---
 clang/lib/Sema/SemaCodeComplete.cpp | 61 +
 1 file changed, 61 insertions(+)

diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 88d4732c7d5c6a..d8f6b1dada942a 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -1837,6 +1837,11 @@ static void AddTypeSpecifierResults(const LangOptions 
&LangOpts,
   Builder.AddChunk(CodeCompletionString::CK_RightParen);
   Results.AddResult(Result(Builder.TakeString()));
 }
+
+if(LangOpts.CPlusPlus20){
+  Results.AddResult(Result("char8_t", CCP_Type));
+  Results.AddResult(Result("concept", CCP_Keyword));
+}
   } else
 Results.AddResult(Result("__auto_type", CCP_Type));
 
@@ -1889,6 +1894,10 @@ 
AddStorageSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC,
 Results.AddResult(Result("constexpr"));
 Results.AddResult(Result("thread_local"));
   }
+
+  if (LangOpts.CPlusPlus20) {
+Results.AddResult(Result("constinit"));
+  }
 }
 
 static void
@@ -1912,6 +1921,9 @@ 
AddFunctionSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC,
   case SemaCodeCompletion::PCC_Template:
 if (LangOpts.CPlusPlus || LangOpts.C99)
   Results.AddResult(Result("inline"));
+
+if (LangOpts.CPlusPlus20)
+  Results.AddResult(Result("consteval"));
 break;
 
   case SemaCodeCompletion::PCC_ObjCInstanceVariableList:
@@ -2487,6 +2499,14 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
   Builder.AddPlaceholderChunk("expression");
   Builder.AddChunk(CodeCompletionString::CK_SemiColon);
   Results.AddResult(Result(Builder.TakeString()));
+  // "co_return expression ;" for coroutines(C++20).
+  if (SemaRef.getLangOpts().CPlusPlus20) {
+Builder.AddTypedTextChunk("co_return");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+Results.AddResult(Result(Builder.TakeString()));
+  }
   // When boolean, also add 'return true;' and 'return false;'.
   if (ReturnType->isBooleanType()) {
 Builder.AddTypedTextChunk("return true");
@@ -2707,6 +2727,47 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
 Builder.AddChunk(CodeCompletionString::CK_RightParen);
 Results.AddResult(Result(Builder.TakeString()));
   }
+
+  if (SemaRef.getLangOpts().CPlusPlus20) {
+// co_await expression
+Builder.AddResultTypeChunk("");
+Builder.AddTypedTextChunk("co_await");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Results.AddResult(Result(Builder.TakeString()));
+
+// co_yield expression
+Builder.AddResultTypeChunk("");
+Builder.AddTypedTextChunk("co_yield");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Results.AddResult(Result(Builder.TakeString()));
+
+// requires (parameters) { requirements }
+Builder.AddResultTypeChunk("bool");
+Builder.AddTypedTextChunk("requires");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+Builder.AddPlaceholderChunk("parameters");
+Builder.AddChunk(CodeCompletionString::CK_RightParen);
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddPlaceholderChunk("requirements");
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddChunk(CodeCompletionString::CK_RightBrace);
+Results.AddResult(Result(Builder.TakeString()));
+
+if(llvm::isa(SemaRef.CurContext)){
+  // requires expression ;
+  Builder.AddResultTypeChunk("");
+  Builder.AddTypedTextChunk("requires");
+  Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+  Builder.AddPlaceholderChunk("expression");
+  Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+  Results.AddResult(Result(Builder.TakeString()));
+}
+  }
 }
 
 if (SemaRef.getLangOpts().ObjC) {

>From 36a0db2b827baaabe17c5cd7b576802be586c69c Mon Sep 17 00:00:00 2001
From: ykiko 
Date: Tue, 10 Sep 2024 15:50:04 +0800
Subject: [PATCH 2/5] make concept and requires more sensitive to context.

---
 c

[clang] [clang][bytecode] Fix lookup in source locations in implicit ctors (PR #107992)

2024-09-10 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/107992

Implicit functions may still have a body. The !hasBody() check is enough.

>From 336d735f9c40987b3c31d3422747d403dd6d6165 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 10 Sep 2024 11:39:38 +0200
Subject: [PATCH] [clang][bytecode] Fix lookup in source locations in implicit
 ctors

Implicit functions may still have a body. The !hasBody() check is
enough.
---
 clang/lib/AST/ByteCode/InterpFrame.cpp| 10 +-
 clang/test/AST/ByteCode/builtin-functions.cpp |  7 +++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp 
b/clang/lib/AST/ByteCode/InterpFrame.cpp
index 6830a7b37f1da5..6c1e446458dc57 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.cpp
+++ b/clang/lib/AST/ByteCode/InterpFrame.cpp
@@ -210,28 +210,28 @@ Pointer InterpFrame::getParamPointer(unsigned Off) {
 SourceInfo InterpFrame::getSource(CodePtr PC) const {
   // Implicitly created functions don't have any code we could point at,
   // so return the call site.
-  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
+  if (Func && !Func->hasBody() && Caller)
 return Caller->getSource(RetPC);
 
   return S.getSource(Func, PC);
 }
 
 const Expr *InterpFrame::getExpr(CodePtr PC) const {
-  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
-return Caller->getExpr(RetPC);
+  if (Func && !Func->hasBody() && Caller)
+return Caller->getExpr(PC);
 
   return S.getExpr(Func, PC);
 }
 
 SourceLocation InterpFrame::getLocation(CodePtr PC) const {
-  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
+  if (Func && !Func->hasBody() && Caller)
 return Caller->getLocation(RetPC);
 
   return S.getLocation(Func, PC);
 }
 
 SourceRange InterpFrame::getRange(CodePtr PC) const {
-  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
+  if (Func && !Func->hasBody() && Caller)
 return Caller->getRange(RetPC);
 
   return S.getRange(Func, PC);
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 9c9ca23e0a6a69..9fd5eae67a21f6 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -968,3 +968,10 @@ namespace FunctionStart {
   static_assert(__builtin_function_start(a) == a, ""); // both-error {{not an 
integral constant expression}} \
// both-note 
{{comparison of addresses of literals has unspecified value}}
 }
+
+namespace BuiltinInImplicitCtor {
+  constexpr struct {
+int a = __builtin_isnan(1.0);
+  } Foo;
+  static_assert(Foo.a == 0, "");
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][bytecode] Fix lookup in source locations in implicit ctors (PR #107992)

2024-09-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Implicit functions may still have a body. The !hasBody() check is enough.

---
Full diff: https://github.com/llvm/llvm-project/pull/107992.diff


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/InterpFrame.cpp (+5-5) 
- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+7) 


``diff
diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp 
b/clang/lib/AST/ByteCode/InterpFrame.cpp
index 6830a7b37f1da5..6c1e446458dc57 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.cpp
+++ b/clang/lib/AST/ByteCode/InterpFrame.cpp
@@ -210,28 +210,28 @@ Pointer InterpFrame::getParamPointer(unsigned Off) {
 SourceInfo InterpFrame::getSource(CodePtr PC) const {
   // Implicitly created functions don't have any code we could point at,
   // so return the call site.
-  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
+  if (Func && !Func->hasBody() && Caller)
 return Caller->getSource(RetPC);
 
   return S.getSource(Func, PC);
 }
 
 const Expr *InterpFrame::getExpr(CodePtr PC) const {
-  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
-return Caller->getExpr(RetPC);
+  if (Func && !Func->hasBody() && Caller)
+return Caller->getExpr(PC);
 
   return S.getExpr(Func, PC);
 }
 
 SourceLocation InterpFrame::getLocation(CodePtr PC) const {
-  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
+  if (Func && !Func->hasBody() && Caller)
 return Caller->getLocation(RetPC);
 
   return S.getLocation(Func, PC);
 }
 
 SourceRange InterpFrame::getRange(CodePtr PC) const {
-  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
+  if (Func && !Func->hasBody() && Caller)
 return Caller->getRange(RetPC);
 
   return S.getRange(Func, PC);
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 9c9ca23e0a6a69..9fd5eae67a21f6 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -968,3 +968,10 @@ namespace FunctionStart {
   static_assert(__builtin_function_start(a) == a, ""); // both-error {{not an 
integral constant expression}} \
// both-note 
{{comparison of addresses of literals has unspecified value}}
 }
+
+namespace BuiltinInImplicitCtor {
+  constexpr struct {
+int a = __builtin_isnan(1.0);
+  } Foo;
+  static_assert(Foo.a == 0, "");
+}

``




https://github.com/llvm/llvm-project/pull/107992
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [X86] AMD Zen 5 Initial enablement (PR #107964)

2024-09-10 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon approved this pull request.

LGTM as a base patch (znver4 + extra isas) - we should hold off from cherry 
picking into 19.x until we see the scope of the follow up patches.

https://github.com/llvm/llvm-project/pull/107964
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Clang][LLVM][AArch64] Add intrinsic for MOVT SME2 instruction (PR #97602)

2024-09-10 Thread via cfe-commits

CarolineConcatto wrote:

The ACLE was merged so we can merge this patch when approved.
Therefore the ping.

https://github.com/llvm/llvm-project/pull/97602
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Clang][LLVM][AArch64] Add intrinsic for LUTI4 SME2 instruction (PR #97755)

2024-09-10 Thread via cfe-commits

CarolineConcatto wrote:

The ACLE was merged so we can merge this patch when approved.
Therefore the ping.

https://github.com/llvm/llvm-project/pull/97755
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Introduce FunctionParmPackDecl for expanded lambda captures (PR #107995)

2024-09-10 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/107995

This patch continues the effort of #86265, fixing another issue involving 
expanded captures that were not able to held off in the process of the inner 
lambda's transformation.

Similar to FunctionParmPackExpr, FunctionParmPackDecl is introduced to model 
expanded parameters (particularly, lambda parameters) in the situation where 
the expansion shouldn't occur in the subsequent transformation. This node acts 
as an intermediate Decl and thus should not show up in the eventual AST.

Fixes #18873


>From c97f213bc412dd2a4d6ee5c8e58a82f04dbbd03b Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 10 Sep 2024 17:23:55 +0800
Subject: [PATCH] [Clang] Introduce FunctionParmPackDecl for expanded lambda
 captures

---
 clang/docs/ReleaseNotes.rst   |  2 +-
 clang/include/clang/AST/DeclTemplate.h| 37 +++
 clang/include/clang/AST/RecursiveASTVisitor.h |  2 +
 clang/include/clang/Basic/DeclNodes.td|  1 +
 clang/include/clang/Sema/Template.h   |  3 ++
 .../include/clang/Serialization/ASTBitCodes.h |  5 ++-
 clang/lib/AST/DeclBase.cpp|  1 +
 clang/lib/AST/DeclTemplate.cpp| 37 +++
 clang/lib/CodeGen/CGDecl.cpp  |  1 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 25 -
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  5 +++
 clang/lib/Sema/TreeTransform.h| 14 +--
 clang/lib/Serialization/ASTCommon.cpp |  1 +
 clang/lib/Serialization/ASTReaderDecl.cpp | 11 ++
 clang/lib/Serialization/ASTWriterDecl.cpp | 10 +
 .../SemaCXX/fold_lambda_with_variadics.cpp| 31 
 clang/tools/libclang/CIndex.cpp   |  1 +
 17 files changed, 157 insertions(+), 30 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 250821a9f9c45c..f39c39f8646d08 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -344,7 +344,7 @@ Bug Fixes to C++ Support
   module imports in those situations. (#GH60336)
 - Fix init-capture packs having a size of one before being instantiated. 
(#GH63677)
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
-  (#GH99877).
+  (#GH99877), (#GH18873).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
 - Fixed an assertion failure when selecting a function from an overload set 
that includes a
   specialization of a conversion function template.
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 687715a22e9fd3..3730f5bee09d2a 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -3220,6 +3220,43 @@ class ImplicitConceptSpecializationDecl final
   friend class ASTDeclReader;
 };
 
+class FunctionParmPackDecl final
+: public Decl,
+  private llvm::TrailingObjects {
+  friend TrailingObjects;
+  friend class ASTDeclReader;
+
+  /// The function parameter pack which was referenced.
+  NamedDecl *Pattern;
+
+  unsigned NumExpansions;
+
+  FunctionParmPackDecl(DeclContext *DC, SourceLocation StartLoc,
+   NamedDecl *Pattern, ArrayRef ExpandedParams);
+
+  void setExpandedParams(ArrayRef ExpandedParams);
+
+public:
+  static FunctionParmPackDecl *Create(ASTContext &C, DeclContext *DC,
+  SourceLocation StartLoc,
+  NamedDecl *Pattern,
+  ArrayRef ExpandedParams);
+
+  static FunctionParmPackDecl *
+  CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumExpansions);
+
+  ArrayRef getExpandedParams() const {
+return ArrayRef(getTrailingObjects(), NumExpansions);
+  }
+
+  unsigned getNumExpansions() const { return NumExpansions; }
+
+  NamedDecl *getPattern() const { return Pattern; }
+
+  static bool classofKind(Kind K) { return K == FunctionParmPack; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+};
+
 /// A template parameter object.
 ///
 /// Template parameter objects represent values of class type used as template
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 3389670a2ab9d9..3297e9eb009678 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2353,6 +2353,8 @@ DEF_TRAVERSE_DECL(ImplicitConceptSpecializationDecl, {
   TRY_TO(TraverseTemplateArguments(D->getTemplateArguments()));
 })
 
+DEF_TRAVERSE_DECL(FunctionParmPackDecl, {})
+
 #undef DEF_TRAVERSE_DECL
 
 // - Stmt traversal -
diff --git a/clang/include/clang/Basic/DeclNodes.td 
b/clang/include/clang/Basic/DeclNodes.td
index 48396e85c5adac..694d3d8b79a183 100644
--- a/clang/include/

[clang] Add code completion for C++20 keywords. (PR #107982)

2024-09-10 Thread Yanzuo Liu via cfe-commits


@@ -0,0 +1,35 @@
+const char8_t x = 1;
+
+template requires true
+const int y = requires { typename T::type; requires T::value; };
+
+int f(){ co_await 1; }
+
+// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:1:3 %s | FileCheck 
--check-prefix=CHECK-TOP-LEVEL %s
+// CHECK-TOP-LEVEL: const
+// CHECK-TOP-LEVEL: consteval
+// CHECK-TOP-LEVEL: constexpr
+// CHECK-TOP-LEVEL: constinit
+
+// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:1:12 %s | FileCheck 
--check-prefix=CHECK-TOP-LEVEL %s
+// CHECK-TOP-LEVEL: char8_t
+
+// RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:4:3 %s | FileCheck 
--check-prefix=CHECK-REQUIRES %s
+// CHECK-REQUIRES: concept
+// CHECK-REQUIRES: const
+// CHECK-REQUIRES: consteval
+// CHECK-REQUIRES: constexpr
+// CHECK-REQUIRES: constinit
+
+// RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:3:27 %s | FileCheck 
--check-prefix=CHECK-REQUIRES %s
+// CHECK-REQUIRES: requires
+
+// RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:4:20 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
+// CHECK-CC1-NEXT: COMPLETION: Pattern: [#bool#]requires (<#parameters#>) {
+// CHECK-CC1-NEXT: <#requirements#>
+// CHECK-CC1-NEXT: }
+
+// RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:6:13 %s | FileCheck 
--check-prefix=CHECK-COAWAIT %s
+// CHECK-COAWAIT: Pattern : co_await <#expression#>
+// CHECK-COAWAIT: Pattern : co_return <#expression#>;
+// CHECK-COAWAIT: Pattern : co_yield <#expression#>

zwuis wrote:

A new line character is required at end of file.

https://github.com/llvm/llvm-project/pull/107982
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RISCV] Allow -mcmodel= to accept large for RV64 (PR #107817)

2024-09-10 Thread Alex Bradbury via cfe-commits

asb wrote:

I think we want to set a define for this as well, for consistency with medany 
and medlow (as tested in test/Preprocessor/riscv-cmodel.c). I submitted a 
trivial PR to riscv-c-api-doc to add this 
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/86 which I'd hope lands 
quickly.

https://github.com/llvm/llvm-project/pull/107817
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add code completion for C++20 keywords. (PR #107982)

2024-09-10 Thread via cfe-commits

https://github.com/16bit-ykiko updated 
https://github.com/llvm/llvm-project/pull/107982

>From fedea9e4fd57b618fe341e0c30982bff0f098c52 Mon Sep 17 00:00:00 2001
From: ykiko 
Date: Tue, 10 Sep 2024 14:59:10 +0800
Subject: [PATCH 1/6] add co_return, co_await, co_yield, consteval, constinit,
 concept, requires, char8_t.

---
 clang/lib/Sema/SemaCodeComplete.cpp | 61 +
 1 file changed, 61 insertions(+)

diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 88d4732c7d5c6a..d8f6b1dada942a 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -1837,6 +1837,11 @@ static void AddTypeSpecifierResults(const LangOptions 
&LangOpts,
   Builder.AddChunk(CodeCompletionString::CK_RightParen);
   Results.AddResult(Result(Builder.TakeString()));
 }
+
+if(LangOpts.CPlusPlus20){
+  Results.AddResult(Result("char8_t", CCP_Type));
+  Results.AddResult(Result("concept", CCP_Keyword));
+}
   } else
 Results.AddResult(Result("__auto_type", CCP_Type));
 
@@ -1889,6 +1894,10 @@ 
AddStorageSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC,
 Results.AddResult(Result("constexpr"));
 Results.AddResult(Result("thread_local"));
   }
+
+  if (LangOpts.CPlusPlus20) {
+Results.AddResult(Result("constinit"));
+  }
 }
 
 static void
@@ -1912,6 +1921,9 @@ 
AddFunctionSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC,
   case SemaCodeCompletion::PCC_Template:
 if (LangOpts.CPlusPlus || LangOpts.C99)
   Results.AddResult(Result("inline"));
+
+if (LangOpts.CPlusPlus20)
+  Results.AddResult(Result("consteval"));
 break;
 
   case SemaCodeCompletion::PCC_ObjCInstanceVariableList:
@@ -2487,6 +2499,14 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
   Builder.AddPlaceholderChunk("expression");
   Builder.AddChunk(CodeCompletionString::CK_SemiColon);
   Results.AddResult(Result(Builder.TakeString()));
+  // "co_return expression ;" for coroutines(C++20).
+  if (SemaRef.getLangOpts().CPlusPlus20) {
+Builder.AddTypedTextChunk("co_return");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+Results.AddResult(Result(Builder.TakeString()));
+  }
   // When boolean, also add 'return true;' and 'return false;'.
   if (ReturnType->isBooleanType()) {
 Builder.AddTypedTextChunk("return true");
@@ -2707,6 +2727,47 @@ 
AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC,
 Builder.AddChunk(CodeCompletionString::CK_RightParen);
 Results.AddResult(Result(Builder.TakeString()));
   }
+
+  if (SemaRef.getLangOpts().CPlusPlus20) {
+// co_await expression
+Builder.AddResultTypeChunk("");
+Builder.AddTypedTextChunk("co_await");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Results.AddResult(Result(Builder.TakeString()));
+
+// co_yield expression
+Builder.AddResultTypeChunk("");
+Builder.AddTypedTextChunk("co_yield");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("expression");
+Results.AddResult(Result(Builder.TakeString()));
+
+// requires (parameters) { requirements }
+Builder.AddResultTypeChunk("bool");
+Builder.AddTypedTextChunk("requires");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+Builder.AddPlaceholderChunk("parameters");
+Builder.AddChunk(CodeCompletionString::CK_RightParen);
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddPlaceholderChunk("requirements");
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddChunk(CodeCompletionString::CK_RightBrace);
+Results.AddResult(Result(Builder.TakeString()));
+
+if(llvm::isa(SemaRef.CurContext)){
+  // requires expression ;
+  Builder.AddResultTypeChunk("");
+  Builder.AddTypedTextChunk("requires");
+  Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+  Builder.AddPlaceholderChunk("expression");
+  Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+  Results.AddResult(Result(Builder.TakeString()));
+}
+  }
 }
 
 if (SemaRef.getLangOpts().ObjC) {

>From 36a0db2b827baaabe17c5cd7b576802be586c69c Mon Sep 17 00:00:00 2001
From: ykiko 
Date: Tue, 10 Sep 2024 15:50:04 +0800
Subject: [PATCH 2/6] make concept and requires more sensitive to context.

---
 c

[clang] Add code completion for C++20 keywords. (PR #107982)

2024-09-10 Thread via cfe-commits


@@ -0,0 +1,35 @@
+const char8_t x = 1;
+
+template requires true
+const int y = requires { typename T::type; requires T::value; };
+
+int f(){ co_await 1; }
+
+// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:1:3 %s | FileCheck 
--check-prefix=CHECK-TOP-LEVEL %s
+// CHECK-TOP-LEVEL: const
+// CHECK-TOP-LEVEL: consteval
+// CHECK-TOP-LEVEL: constexpr
+// CHECK-TOP-LEVEL: constinit
+
+// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:1:12 %s | FileCheck 
--check-prefix=CHECK-TOP-LEVEL %s
+// CHECK-TOP-LEVEL: char8_t
+
+// RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:4:3 %s | FileCheck 
--check-prefix=CHECK-REQUIRES %s
+// CHECK-REQUIRES: concept
+// CHECK-REQUIRES: const
+// CHECK-REQUIRES: consteval
+// CHECK-REQUIRES: constexpr
+// CHECK-REQUIRES: constinit
+
+// RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:3:27 %s | FileCheck 
--check-prefix=CHECK-REQUIRES %s
+// CHECK-REQUIRES: requires
+
+// RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:4:20 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
+// CHECK-CC1-NEXT: COMPLETION: Pattern: [#bool#]requires (<#parameters#>) {
+// CHECK-CC1-NEXT: <#requirements#>
+// CHECK-CC1-NEXT: }
+
+// RUN: %clang-cc1 -std=c++20 -code-completion-at=%s:6:13 %s | FileCheck 
--check-prefix=CHECK-COAWAIT %s
+// CHECK-COAWAIT: Pattern : co_await <#expression#>
+// CHECK-COAWAIT: Pattern : co_return <#expression#>;
+// CHECK-COAWAIT: Pattern : co_yield <#expression#>

16bit-ykiko wrote:

fix.

https://github.com/llvm/llvm-project/pull/107982
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][Clang][SVE] Refactor AArch64SVEACLETypes.def to enabled more uses. (PR #107599)

2024-09-10 Thread Paul Walker via cfe-commits

https://github.com/paulwalker-arm updated 
https://github.com/llvm/llvm-project/pull/107599

>From 05670ea720be07ff8c1645ca90fff00460029de7 Mon Sep 17 00:00:00 2001
From: Paul Walker 
Date: Fri, 6 Sep 2024 12:10:19 +0100
Subject: [PATCH] [NFC][Clang][SVE] Refactor AArch64SVEACLETypes.def to enabled
 more uses.

Some switch statements require all SVE builtin types to be manually
specified. This patch refactors the SVE_*_TYPE macros so that such
code can be generated during preprocessing.

I've tried to establish a minimal interface that covers all types
where no special information is required and then created a set of
macros that are dedicated to specific datatypes (i.e. int, float).

This patch is groundwork to simplify the changing of SVE tuple types
to become struct based as well as work to support the FP8 ACLE.
---
 .../clang/Basic/AArch64SVEACLETypes.def   | 178 +++---
 clang/lib/AST/ASTContext.cpp  | 162 +---
 clang/lib/AST/ItaniumMangle.cpp   |  16 +-
 clang/lib/CodeGen/CodeGenTypes.cpp|  70 ++-
 4 files changed, 178 insertions(+), 248 deletions(-)

diff --git a/clang/include/clang/Basic/AArch64SVEACLETypes.def 
b/clang/include/clang/Basic/AArch64SVEACLETypes.def
index fa9c1ac0491c45..56e6179a664e26 100644
--- a/clang/include/clang/Basic/AArch64SVEACLETypes.def
+++ b/clang/include/clang/Basic/AArch64SVEACLETypes.def
@@ -8,28 +8,48 @@
 //
 //  This file defines various SVE builtin types.  The macros are:
 //
-//SVE_TYPE(Name, Id, SingletonId) - A builtin type that has not been
-//covered by any other #define.  Defining this macro covers all
-//the builtins.
+//SVE_TYPE:
+//- (Name, MangledName, Id, SingletonId)
+//A builtin type that has not been covered by any other #define. Defining
+//this macro covers all the builtin types.
 //
-//SVE_VECTOR_TYPE(Name, Id, SingletonId, ElKind, ElBits, IsSigned, IsFP) -
-//An SVE scalable vector.
+//SVE_VECTOR_TYPE, SVE_PREDICATE_TYPE, SVE_OPAQUE_TYPE:
+//- (Name, MangledName, Id, SingletonId)
+//A builtin type that has not been covered by any other #define. Defining
+//this macro covers the named subset of builtin types.
 //
-//SVE_PREDICATE_TYPE(Name, Id, SingletonId, ElKind) - An SVE scalable
-//predicate.
+//SVE_VECTOR_TYPE_INT
+//- (Name, MangledName, Id, SingletonId, NumEls, ElBits, NF, IsSigned)
+//Defining the macro covers the integer vector types.
+//
+//SVE_VECTOR_TYPE_FLOAT, SVE_VECTOR_TYPE_BFLOAT:
+//- (Name, MangledName, Id, SingletonId, NumEls, ElBits, NF)
+//Defining the macro covers the floating point vector types.
+//
+//SVE_PREDICATE_TYPE_ALL:
+//- (Name, MangledName, Id, SingletonId, NumEls, NF)
+//Defining the macro covers the boolean vector types.
 //
 // where:
 //
 //  - Name is the name of the builtin type.
 //
+//  - MangledName is the mangled name of the builtin type.
+//
 //  - BuiltinType::Id is the enumerator defining the type.
 //
 //  - Context.SingletonId is the global singleton of this type.
 //
 //  - ElKind enumerates the type of the elements.
 //
+//  - NumEls enumerates the number of the elements.
+//
 //  - ElBits is the size of one element in bits.
 //
+//  - NF enumerates the number of sub-vectors.
+//TODO: Tuple types are represented as a concatination of "NumEls x ElBits"
+//vectors.  This will be changed to become a struct containing NF vectors.
+//
 //  - IsSigned is true for vectors of signed integer elements and
 //for vectors of floating-point elements.
 //
@@ -39,102 +59,134 @@
 
//===--===//
 
 #ifndef SVE_VECTOR_TYPE
-#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId, NumEls, ElBits,
\
-IsSigned, IsFP, IsBF)  
\
+#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
   SVE_TYPE(Name, Id, SingletonId)
 #endif
 
+#ifndef SVE_VECTOR_TYPE_DETAILS
+#define SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, 
ElBits, NF, IsSigned, IsFP, IsBF) \
+  SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId)
+#endif
+
+#ifndef SVE_VECTOR_TYPE_BFLOAT
+#define SVE_VECTOR_TYPE_BFLOAT(Name, MangledName, Id, SingletonId, NumEls, 
ElBits, NF) \
+  SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, ElBits, 
NF, false, false, true)
+#endif
+
+#ifndef SVE_VECTOR_TYPE_FLOAT
+#define SVE_VECTOR_TYPE_FLOAT(Name, MangledName, Id, SingletonId, NumEls, 
ElBits, NF) \
+  SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, ElBits, 
NF, false, true, false)
+#endif
+
+#ifndef SVE_VECTOR_TYPE_INT
+#define SVE_VECTOR_TYPE_INT(Name, MangledName, Id, SingletonId, NumEls, 
ElBits, NF, IsSigned) \
+  SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, ElBits, 
NF, IsSigned, false, false)
+#endif
+
 #ifndef SVE_PREDICATE_TYPE
-#define SVE_PREDICATE_TYPE(Name, MangledName, 

[clang] Add code completion for C++20 keywords. (PR #107982)

2024-09-10 Thread via cfe-commits

16bit-ykiko wrote:

Also test with clangd, it work well.

![image](https://github.com/user-attachments/assets/e988b77b-25d9-4ec8-9d16-3123d5bcae83)
![image](https://github.com/user-attachments/assets/a738e0cf-311e-44fb-b75a-38be35e6277e)
![image](https://github.com/user-attachments/assets/feceeb96-d20b-4583-a9df-d6f7d4890b00)
![image](https://github.com/user-attachments/assets/b1bfee21-8380-4c4e-b6f0-983a0793c758)
![image](https://github.com/user-attachments/assets/d44f99b4-84b7-4d13-9ec4-8bd1ac16f08e)
![Uploading image.png…]()
![image](https://github.com/user-attachments/assets/00a5cfe6-2069-44ff-80e2-79f4905459ce)


https://github.com/llvm/llvm-project/pull/107982
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RISCV] Add testcase for -mcmodel= (PR #107816)

2024-09-10 Thread Alex Bradbury via cfe-commits

https://github.com/asb approved this pull request.

LGTM.

https://github.com/llvm/llvm-project/pull/107816
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility to AMDGPU. (PR #107997)

2024-09-10 Thread Amit Kumar Pandey via cfe-commits

https://github.com/ampandey-1995 created 
https://github.com/llvm/llvm-project/pull/107997

HIPAMDToolChain and AMDGPUToolChain both depends on the 
"shouldSkipSanitizeOption" api to sanitize/not sanitize device code.

>From 4a9c7b7412f4f8f03d69b255ce1e7b46877db4fd Mon Sep 17 00:00:00 2001
From: Amit Pandey 
Date: Tue, 10 Sep 2024 15:53:28 +0530
Subject: [PATCH] [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility
 to AMDGPU.

HIPAMDToolChain and AMDGPUToolChain both depends on the
"shouldSkipSanitizeOption" api to sanitize/not sanitize device code.
---
 clang/lib/Driver/ToolChains/AMDGPU.cpp | 36 +
 clang/lib/Driver/ToolChains/AMDGPU.h   |  6 +
 clang/lib/Driver/ToolChains/HIPAMD.cpp | 37 --
 3 files changed, 42 insertions(+), 37 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index a788aba57546c8..74f70573c5feb8 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -1054,3 +1054,39 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList &DriverArgs,
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
 }
+
+bool AMDGPUToolChain::shouldSkipSanitizeOption(
+const ToolChain &TC, const llvm::opt::ArgList &DriverArgs,
+StringRef TargetID, const llvm::opt::Arg *A) const {
+  // For actions without targetID, do nothing.
+  if (TargetID.empty())
+return false;
+  Option O = A->getOption();
+  if (!O.matches(options::OPT_fsanitize_EQ))
+return false;
+
+  if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
+  options::OPT_fno_gpu_sanitize, true))
+return true;
+
+  auto &Diags = TC.getDriver().getDiags();
+
+  // For simplicity, we only allow -fsanitize=address
+  SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
+  if (K != SanitizerKind::Address)
+return true;
+
+  llvm::StringMap FeatureMap;
+  auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
+
+  assert(OptionalGpuArch && "Invalid Target ID");
+  (void)OptionalGpuArch;
+  auto Loc = FeatureMap.find("xnack");
+  if (Loc == FeatureMap.end() || !Loc->second) {
+Diags.Report(
+clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
+<< A->getAsString(DriverArgs) << TargetID << "xnack+";
+return true;
+  }
+  return false;
+}
\ No newline at end of file
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h 
b/clang/lib/Driver/ToolChains/AMDGPU.h
index 7e70dae8ce152e..a9b4552a1f91a4 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -97,6 +97,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public 
Generic_ELF {
   /// Needed for translating LTO options.
   const char *getDefaultLinker() const override { return "ld.lld"; }
 
+  /// Should skip sanitize options.
+  bool shouldSkipSanitizeOption(const ToolChain &TC,
+const llvm::opt::ArgList &DriverArgs,
+StringRef TargetID,
+const llvm::opt::Arg *A) const;
+
   /// Uses amdgpu-arch tool to get arch of the system GPU. Will return error
   /// if unable to find one.
   virtual Expected>
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index cbb8fab69a316d..bae05cc0bb7353 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -36,43 +36,6 @@ using namespace llvm::opt;
 #define NULL_FILE "/dev/null"
 #endif
 
-static bool shouldSkipSanitizeOption(const ToolChain &TC,
- const llvm::opt::ArgList &DriverArgs,
- StringRef TargetID,
- const llvm::opt::Arg *A) {
-  // For actions without targetID, do nothing.
-  if (TargetID.empty())
-return false;
-  Option O = A->getOption();
-  if (!O.matches(options::OPT_fsanitize_EQ))
-return false;
-
-  if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
-  options::OPT_fno_gpu_sanitize, true))
-return true;
-
-  auto &Diags = TC.getDriver().getDiags();
-
-  // For simplicity, we only allow -fsanitize=address
-  SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
-  if (K != SanitizerKind::Address)
-return true;
-
-  llvm::StringMap FeatureMap;
-  auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
-
-  assert(OptionalGpuArch && "Invalid Target ID");
-  (void)OptionalGpuArch;
-  auto Loc = FeatureMap.find("xnack");
-  if (Loc == FeatureMap.end() || !Loc->second) {
-Diags.Report(
-clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
-<< A->getAsString(DriverArgs) << TargetID << "xnack+";
-return true;
-  }
-  return false;
-}
-
 void

[clang] [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility to AMDGPU. (PR #107997)

2024-09-10 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Amit Kumar Pandey (ampandey-1995)


Changes

HIPAMDToolChain and AMDGPUToolChain both depends on the 
"shouldSkipSanitizeOption" api to sanitize/not sanitize device code.

---
Full diff: https://github.com/llvm/llvm-project/pull/107997.diff


3 Files Affected:

- (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+36) 
- (modified) clang/lib/Driver/ToolChains/AMDGPU.h (+6) 
- (modified) clang/lib/Driver/ToolChains/HIPAMD.cpp (-37) 


``diff
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index a788aba57546c8..74f70573c5feb8 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -1054,3 +1054,39 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList &DriverArgs,
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
 }
+
+bool AMDGPUToolChain::shouldSkipSanitizeOption(
+const ToolChain &TC, const llvm::opt::ArgList &DriverArgs,
+StringRef TargetID, const llvm::opt::Arg *A) const {
+  // For actions without targetID, do nothing.
+  if (TargetID.empty())
+return false;
+  Option O = A->getOption();
+  if (!O.matches(options::OPT_fsanitize_EQ))
+return false;
+
+  if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
+  options::OPT_fno_gpu_sanitize, true))
+return true;
+
+  auto &Diags = TC.getDriver().getDiags();
+
+  // For simplicity, we only allow -fsanitize=address
+  SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
+  if (K != SanitizerKind::Address)
+return true;
+
+  llvm::StringMap FeatureMap;
+  auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
+
+  assert(OptionalGpuArch && "Invalid Target ID");
+  (void)OptionalGpuArch;
+  auto Loc = FeatureMap.find("xnack");
+  if (Loc == FeatureMap.end() || !Loc->second) {
+Diags.Report(
+clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
+<< A->getAsString(DriverArgs) << TargetID << "xnack+";
+return true;
+  }
+  return false;
+}
\ No newline at end of file
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h 
b/clang/lib/Driver/ToolChains/AMDGPU.h
index 7e70dae8ce152e..a9b4552a1f91a4 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -97,6 +97,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public 
Generic_ELF {
   /// Needed for translating LTO options.
   const char *getDefaultLinker() const override { return "ld.lld"; }
 
+  /// Should skip sanitize options.
+  bool shouldSkipSanitizeOption(const ToolChain &TC,
+const llvm::opt::ArgList &DriverArgs,
+StringRef TargetID,
+const llvm::opt::Arg *A) const;
+
   /// Uses amdgpu-arch tool to get arch of the system GPU. Will return error
   /// if unable to find one.
   virtual Expected>
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index cbb8fab69a316d..bae05cc0bb7353 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -36,43 +36,6 @@ using namespace llvm::opt;
 #define NULL_FILE "/dev/null"
 #endif
 
-static bool shouldSkipSanitizeOption(const ToolChain &TC,
- const llvm::opt::ArgList &DriverArgs,
- StringRef TargetID,
- const llvm::opt::Arg *A) {
-  // For actions without targetID, do nothing.
-  if (TargetID.empty())
-return false;
-  Option O = A->getOption();
-  if (!O.matches(options::OPT_fsanitize_EQ))
-return false;
-
-  if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
-  options::OPT_fno_gpu_sanitize, true))
-return true;
-
-  auto &Diags = TC.getDriver().getDiags();
-
-  // For simplicity, we only allow -fsanitize=address
-  SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
-  if (K != SanitizerKind::Address)
-return true;
-
-  llvm::StringMap FeatureMap;
-  auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
-
-  assert(OptionalGpuArch && "Invalid Target ID");
-  (void)OptionalGpuArch;
-  auto Loc = FeatureMap.find("xnack");
-  if (Loc == FeatureMap.end() || !Loc->second) {
-Diags.Report(
-clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
-<< A->getAsString(DriverArgs) << TargetID << "xnack+";
-return true;
-  }
-  return false;
-}
-
 void AMDGCN::Linker::constructLlvmLinkCommand(Compilation &C,
  const JobAction &JA,
  const InputInfoList &Inputs,

``




https://github.com/llvm/llvm-project/pull/107997
_

[clang] [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility to AMDGPU. (PR #107997)

2024-09-10 Thread Amit Kumar Pandey via cfe-commits

https://github.com/ampandey-1995 updated 
https://github.com/llvm/llvm-project/pull/107997

>From 01e86b92efbb311ddc1a4383d0c63c23f757e33f Mon Sep 17 00:00:00 2001
From: Amit Pandey 
Date: Tue, 10 Sep 2024 15:53:28 +0530
Subject: [PATCH] [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' API to
 AMDGPU.

HIPAMDToolChain and AMDGPUOpenMPToolChain both depends on the
"shouldSkipSanitizeOption" api to sanitize/not sanitize device code.
---
 clang/lib/Driver/ToolChains/AMDGPU.cpp | 36 +
 clang/lib/Driver/ToolChains/AMDGPU.h   |  6 +
 clang/lib/Driver/ToolChains/HIPAMD.cpp | 37 --
 3 files changed, 42 insertions(+), 37 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index a788aba57546c8..74f70573c5feb8 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -1054,3 +1054,39 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList &DriverArgs,
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
 }
+
+bool AMDGPUToolChain::shouldSkipSanitizeOption(
+const ToolChain &TC, const llvm::opt::ArgList &DriverArgs,
+StringRef TargetID, const llvm::opt::Arg *A) const {
+  // For actions without targetID, do nothing.
+  if (TargetID.empty())
+return false;
+  Option O = A->getOption();
+  if (!O.matches(options::OPT_fsanitize_EQ))
+return false;
+
+  if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
+  options::OPT_fno_gpu_sanitize, true))
+return true;
+
+  auto &Diags = TC.getDriver().getDiags();
+
+  // For simplicity, we only allow -fsanitize=address
+  SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
+  if (K != SanitizerKind::Address)
+return true;
+
+  llvm::StringMap FeatureMap;
+  auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
+
+  assert(OptionalGpuArch && "Invalid Target ID");
+  (void)OptionalGpuArch;
+  auto Loc = FeatureMap.find("xnack");
+  if (Loc == FeatureMap.end() || !Loc->second) {
+Diags.Report(
+clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
+<< A->getAsString(DriverArgs) << TargetID << "xnack+";
+return true;
+  }
+  return false;
+}
\ No newline at end of file
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h 
b/clang/lib/Driver/ToolChains/AMDGPU.h
index 7e70dae8ce152e..a9b4552a1f91a4 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -97,6 +97,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public 
Generic_ELF {
   /// Needed for translating LTO options.
   const char *getDefaultLinker() const override { return "ld.lld"; }
 
+  /// Should skip sanitize options.
+  bool shouldSkipSanitizeOption(const ToolChain &TC,
+const llvm::opt::ArgList &DriverArgs,
+StringRef TargetID,
+const llvm::opt::Arg *A) const;
+
   /// Uses amdgpu-arch tool to get arch of the system GPU. Will return error
   /// if unable to find one.
   virtual Expected>
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index cbb8fab69a316d..bae05cc0bb7353 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -36,43 +36,6 @@ using namespace llvm::opt;
 #define NULL_FILE "/dev/null"
 #endif
 
-static bool shouldSkipSanitizeOption(const ToolChain &TC,
- const llvm::opt::ArgList &DriverArgs,
- StringRef TargetID,
- const llvm::opt::Arg *A) {
-  // For actions without targetID, do nothing.
-  if (TargetID.empty())
-return false;
-  Option O = A->getOption();
-  if (!O.matches(options::OPT_fsanitize_EQ))
-return false;
-
-  if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
-  options::OPT_fno_gpu_sanitize, true))
-return true;
-
-  auto &Diags = TC.getDriver().getDiags();
-
-  // For simplicity, we only allow -fsanitize=address
-  SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
-  if (K != SanitizerKind::Address)
-return true;
-
-  llvm::StringMap FeatureMap;
-  auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
-
-  assert(OptionalGpuArch && "Invalid Target ID");
-  (void)OptionalGpuArch;
-  auto Loc = FeatureMap.find("xnack");
-  if (Loc == FeatureMap.end() || !Loc->second) {
-Diags.Report(
-clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
-<< A->getAsString(DriverArgs) << TargetID << "xnack+";
-return true;
-  }
-  return false;
-}
-
 void AMDGCN::Linker::constructLlvmLinkCommand(Compilation &C,
  const JobAction &JA,

[clang] [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility to AMDGPU. (PR #107997)

2024-09-10 Thread Amit Kumar Pandey via cfe-commits

https://github.com/ampandey-1995 updated 
https://github.com/llvm/llvm-project/pull/107997

>From 4c6b015445e5820d8b09db0d3b4dba23f1413c77 Mon Sep 17 00:00:00 2001
From: Amit Pandey 
Date: Tue, 10 Sep 2024 15:53:28 +0530
Subject: [PATCH] [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility
 to AMDGPU.

HIPAMDToolChain and AMDGPUOpenMPToolChain both depends on the
"shouldSkipSanitizeOption" api to sanitize/not sanitize device code.
---
 clang/lib/Driver/ToolChains/AMDGPU.cpp | 36 +
 clang/lib/Driver/ToolChains/AMDGPU.h   |  6 +
 clang/lib/Driver/ToolChains/HIPAMD.cpp | 37 --
 3 files changed, 42 insertions(+), 37 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index a788aba57546c8..74f70573c5feb8 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -1054,3 +1054,39 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList &DriverArgs,
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
 }
+
+bool AMDGPUToolChain::shouldSkipSanitizeOption(
+const ToolChain &TC, const llvm::opt::ArgList &DriverArgs,
+StringRef TargetID, const llvm::opt::Arg *A) const {
+  // For actions without targetID, do nothing.
+  if (TargetID.empty())
+return false;
+  Option O = A->getOption();
+  if (!O.matches(options::OPT_fsanitize_EQ))
+return false;
+
+  if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
+  options::OPT_fno_gpu_sanitize, true))
+return true;
+
+  auto &Diags = TC.getDriver().getDiags();
+
+  // For simplicity, we only allow -fsanitize=address
+  SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
+  if (K != SanitizerKind::Address)
+return true;
+
+  llvm::StringMap FeatureMap;
+  auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
+
+  assert(OptionalGpuArch && "Invalid Target ID");
+  (void)OptionalGpuArch;
+  auto Loc = FeatureMap.find("xnack");
+  if (Loc == FeatureMap.end() || !Loc->second) {
+Diags.Report(
+clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
+<< A->getAsString(DriverArgs) << TargetID << "xnack+";
+return true;
+  }
+  return false;
+}
\ No newline at end of file
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h 
b/clang/lib/Driver/ToolChains/AMDGPU.h
index 7e70dae8ce152e..a9b4552a1f91a4 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -97,6 +97,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public 
Generic_ELF {
   /// Needed for translating LTO options.
   const char *getDefaultLinker() const override { return "ld.lld"; }
 
+  /// Should skip sanitize options.
+  bool shouldSkipSanitizeOption(const ToolChain &TC,
+const llvm::opt::ArgList &DriverArgs,
+StringRef TargetID,
+const llvm::opt::Arg *A) const;
+
   /// Uses amdgpu-arch tool to get arch of the system GPU. Will return error
   /// if unable to find one.
   virtual Expected>
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index cbb8fab69a316d..bae05cc0bb7353 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -36,43 +36,6 @@ using namespace llvm::opt;
 #define NULL_FILE "/dev/null"
 #endif
 
-static bool shouldSkipSanitizeOption(const ToolChain &TC,
- const llvm::opt::ArgList &DriverArgs,
- StringRef TargetID,
- const llvm::opt::Arg *A) {
-  // For actions without targetID, do nothing.
-  if (TargetID.empty())
-return false;
-  Option O = A->getOption();
-  if (!O.matches(options::OPT_fsanitize_EQ))
-return false;
-
-  if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
-  options::OPT_fno_gpu_sanitize, true))
-return true;
-
-  auto &Diags = TC.getDriver().getDiags();
-
-  // For simplicity, we only allow -fsanitize=address
-  SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
-  if (K != SanitizerKind::Address)
-return true;
-
-  llvm::StringMap FeatureMap;
-  auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
-
-  assert(OptionalGpuArch && "Invalid Target ID");
-  (void)OptionalGpuArch;
-  auto Loc = FeatureMap.find("xnack");
-  if (Loc == FeatureMap.end() || !Loc->second) {
-Diags.Report(
-clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
-<< A->getAsString(DriverArgs) << TargetID << "xnack+";
-return true;
-  }
-  return false;
-}
-
 void AMDGCN::Linker::constructLlvmLinkCommand(Compilation &C,
  const JobAction &JA,

[clang] [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility to AMDGPU. (PR #107997)

2024-09-10 Thread Amit Kumar Pandey via cfe-commits

https://github.com/ampandey-1995 edited 
https://github.com/llvm/llvm-project/pull/107997
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)

2024-09-10 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev updated 
https://github.com/llvm/llvm-project/pull/107737

>From 2aa7527b52656d064c39aec94c9f1001ed10f7d8 Mon Sep 17 00:00:00 2001
From: Vassil Vassilev 
Date: Fri, 6 Sep 2024 09:52:36 +
Subject: [PATCH 1/3] [clang-repl] Simplify the value printing logic to enable
 out-of-process.

This patch improves the design of the IncrementalParser and Interpreter classes.
Now the incremental parser is only responsible for building the partial
translation unit declaration and the AST, while the Interpreter fills in the
lower level llvm::Module and other JIT-related infrastructure. Finally the
Interpreter class now orchestrates the AST and the LLVM IR with the
IncrementalParser and IncrementalExecutor classes.

The design improvement allows us to rework some of the logic that extracts an
interpreter value into the clang::Value object. The new implementation
simplifies use-cases which are used for out-of-process execution by allowing
interpreter to be inherited or customized with an clang::ASTConsumer.

This change will enable completing the pretty printing work which is in
llvm/llvm-project#84769
---
 .../clang/Frontend/MultiplexConsumer.h|   3 +-
 clang/include/clang/Interpreter/Interpreter.h |  53 +-
 clang/lib/Frontend/MultiplexConsumer.cpp  |   7 +
 clang/lib/Interpreter/CMakeLists.txt  |   1 +
 clang/lib/Interpreter/DeviceOffload.cpp   |  10 +-
 clang/lib/Interpreter/DeviceOffload.h |  14 +-
 clang/lib/Interpreter/IncrementalExecutor.cpp |   2 +-
 clang/lib/Interpreter/IncrementalParser.cpp   | 253 +--
 clang/lib/Interpreter/IncrementalParser.h |  45 +-
 clang/lib/Interpreter/Interpreter.cpp | 648 ++
 .../Interpreter/InterpreterValuePrinter.cpp   | 400 +++
 .../Interpreter/CodeCompletionTest.cpp|   2 +-
 .../Interpreter/InterpreterExtensionsTest.cpp |  64 +-
 13 files changed, 707 insertions(+), 795 deletions(-)
 create mode 100644 clang/lib/Interpreter/InterpreterValuePrinter.cpp

diff --git a/clang/include/clang/Frontend/MultiplexConsumer.h 
b/clang/include/clang/Frontend/MultiplexConsumer.h
index 3a7670d7a51aa6..b190750bb29fb8 100644
--- a/clang/include/clang/Frontend/MultiplexConsumer.h
+++ b/clang/include/clang/Frontend/MultiplexConsumer.h
@@ -53,6 +53,7 @@ class MultiplexConsumer : public SemaConsumer {
 public:
   // Takes ownership of the pointers in C.
   MultiplexConsumer(std::vector> C);
+  MultiplexConsumer(std::unique_ptr C);
   ~MultiplexConsumer() override;
 
   // ASTConsumer
@@ -80,7 +81,7 @@ class MultiplexConsumer : public SemaConsumer {
   void InitializeSema(Sema &S) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 1234608bb58647..cbb1cfd4ab02a8 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -14,11 +14,9 @@
 #ifndef LLVM_CLANG_INTERPRETER_INTERPRETER_H
 #define LLVM_CLANG_INTERPRETER_INTERPRETER_H
 
-#include "clang/AST/Decl.h"
 #include "clang/AST/GlobalDecl.h"
 #include "clang/Interpreter/PartialTranslationUnit.h"
 #include "clang/Interpreter/Value.h"
-#include "clang/Sema/Ownership.h"
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
@@ -38,6 +36,9 @@ class ThreadSafeContext;
 namespace clang {
 
 class CompilerInstance;
+class CodeGenerator;
+class CXXRecordDecl;
+class Decl;
 class IncrementalExecutor;
 class IncrementalParser;
 
@@ -77,26 +78,27 @@ class IncrementalCompilerBuilder {
   llvm::StringRef CudaSDKPath;
 };
 
-/// Generate glue code between the Interpreter's built-in runtime and user 
code.
-class RuntimeInterfaceBuilder {
-public:
-  virtual ~RuntimeInterfaceBuilder() = default;
-
-  using TransformExprFunction = ExprResult(RuntimeInterfaceBuilder *Builder,
-   Expr *, ArrayRef);
-  virtual TransformExprFunction *getPrintValueTransformer() = 0;
-};
+class IncrementalAction;
+class InProcessPrintingASTConsumer;
 
 /// Provides top-level interfaces for incremental compilation and execution.
 class Interpreter {
+  friend class Value;
+  friend InProcessPrintingASTConsumer;
+
   std::unique_ptr TSCtx;
+  /// Long-lived, incremental parsing action.
+  std::unique_ptr Act;
   std::unique_ptr IncrParser;
   std::unique_ptr IncrExecutor;
-  std::unique_ptr RuntimeIB;
 
   // An optional parser for CUDA offloading
   std::unique_ptr DeviceParser;
 
+  /// List containing every information about every incrementally parsed piece
+  /// of code.
+  std::list PTUs;
+
   unsigned InitPTUSize = 0;
 
   // This member holds the last result of the value printing. It's a class
@@ -104,15 +106,15 @@ class Interpreter {
   // printing happens, it's in an invalid state.
   Value LastValue;
 
-  // Add

[clang] [clang][bytecode] Fix lookup in source locations in implicit ctors (PR #107992)

2024-09-10 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/107992

>From 8b5a1fbba508c4e88fd00f2ee6b310dae762855e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 10 Sep 2024 11:39:38 +0200
Subject: [PATCH] [clang][bytecode] Fix lookup in source locations in implicit
 ctors

Implicit functions may still have a body. The !hasBody() check is
enough.
---
 clang/lib/AST/ByteCode/InterpFrame.cpp| 19 ++-
 clang/test/AST/ByteCode/builtin-functions.cpp |  7 +++
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp 
b/clang/lib/AST/ByteCode/InterpFrame.cpp
index 6830a7b37f1da5..28e189bb339e62 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.cpp
+++ b/clang/lib/AST/ByteCode/InterpFrame.cpp
@@ -207,31 +207,40 @@ Pointer InterpFrame::getParamPointer(unsigned Off) {
   return Pointer(B);
 }
 
+static bool funcHasUsableBody(const Function *F) {
+  assert(F);
+
+  if (F->isConstructor() || F->isDestructor())
+return true;
+
+  return !F->getDecl()->isImplicit();
+}
+
 SourceInfo InterpFrame::getSource(CodePtr PC) const {
   // Implicitly created functions don't have any code we could point at,
   // so return the call site.
-  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
+  if (Func && !funcHasUsableBody(Func) && Caller)
 return Caller->getSource(RetPC);
 
   return S.getSource(Func, PC);
 }
 
 const Expr *InterpFrame::getExpr(CodePtr PC) const {
-  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
-return Caller->getExpr(RetPC);
+  if (Func && !funcHasUsableBody(Func) && Caller)
+return Caller->getExpr(PC);
 
   return S.getExpr(Func, PC);
 }
 
 SourceLocation InterpFrame::getLocation(CodePtr PC) const {
-  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
+  if (Func && !funcHasUsableBody(Func) && Caller)
 return Caller->getLocation(RetPC);
 
   return S.getLocation(Func, PC);
 }
 
 SourceRange InterpFrame::getRange(CodePtr PC) const {
-  if (Func && (!Func->hasBody() || Func->getDecl()->isImplicit()) && Caller)
+  if (Func && !funcHasUsableBody(Func) && Caller)
 return Caller->getRange(RetPC);
 
   return S.getRange(Func, PC);
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 9c9ca23e0a6a69..9fd5eae67a21f6 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -968,3 +968,10 @@ namespace FunctionStart {
   static_assert(__builtin_function_start(a) == a, ""); // both-error {{not an 
integral constant expression}} \
// both-note 
{{comparison of addresses of literals has unspecified value}}
 }
+
+namespace BuiltinInImplicitCtor {
+  constexpr struct {
+int a = __builtin_isnan(1.0);
+  } Foo;
+  static_assert(Foo.a == 0, "");
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RISCV] Allow -mcmodel= to accept large for RV64 (PR #107817)

2024-09-10 Thread Christoph Müllner via cfe-commits

https://github.com/cmuellner commented:

What I am missing is:
* adjustments in `clang/lib/Basic/Targets/RISCV.cpp` to emit the macro 
`__riscv_cmodel_large`
* new tests in `clang/test/Preprocessor/riscv-cmodel.c`

Related PRs:
* https://github.com/riscv-non-isa/riscv-c-api-doc/pull/86
* https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/59


https://github.com/llvm/llvm-project/pull/107817
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)

2024-09-10 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev updated 
https://github.com/llvm/llvm-project/pull/107737

>From 2aa7527b52656d064c39aec94c9f1001ed10f7d8 Mon Sep 17 00:00:00 2001
From: Vassil Vassilev 
Date: Fri, 6 Sep 2024 09:52:36 +
Subject: [PATCH 1/4] [clang-repl] Simplify the value printing logic to enable
 out-of-process.

This patch improves the design of the IncrementalParser and Interpreter classes.
Now the incremental parser is only responsible for building the partial
translation unit declaration and the AST, while the Interpreter fills in the
lower level llvm::Module and other JIT-related infrastructure. Finally the
Interpreter class now orchestrates the AST and the LLVM IR with the
IncrementalParser and IncrementalExecutor classes.

The design improvement allows us to rework some of the logic that extracts an
interpreter value into the clang::Value object. The new implementation
simplifies use-cases which are used for out-of-process execution by allowing
interpreter to be inherited or customized with an clang::ASTConsumer.

This change will enable completing the pretty printing work which is in
llvm/llvm-project#84769
---
 .../clang/Frontend/MultiplexConsumer.h|   3 +-
 clang/include/clang/Interpreter/Interpreter.h |  53 +-
 clang/lib/Frontend/MultiplexConsumer.cpp  |   7 +
 clang/lib/Interpreter/CMakeLists.txt  |   1 +
 clang/lib/Interpreter/DeviceOffload.cpp   |  10 +-
 clang/lib/Interpreter/DeviceOffload.h |  14 +-
 clang/lib/Interpreter/IncrementalExecutor.cpp |   2 +-
 clang/lib/Interpreter/IncrementalParser.cpp   | 253 +--
 clang/lib/Interpreter/IncrementalParser.h |  45 +-
 clang/lib/Interpreter/Interpreter.cpp | 648 ++
 .../Interpreter/InterpreterValuePrinter.cpp   | 400 +++
 .../Interpreter/CodeCompletionTest.cpp|   2 +-
 .../Interpreter/InterpreterExtensionsTest.cpp |  64 +-
 13 files changed, 707 insertions(+), 795 deletions(-)
 create mode 100644 clang/lib/Interpreter/InterpreterValuePrinter.cpp

diff --git a/clang/include/clang/Frontend/MultiplexConsumer.h 
b/clang/include/clang/Frontend/MultiplexConsumer.h
index 3a7670d7a51aa6..b190750bb29fb8 100644
--- a/clang/include/clang/Frontend/MultiplexConsumer.h
+++ b/clang/include/clang/Frontend/MultiplexConsumer.h
@@ -53,6 +53,7 @@ class MultiplexConsumer : public SemaConsumer {
 public:
   // Takes ownership of the pointers in C.
   MultiplexConsumer(std::vector> C);
+  MultiplexConsumer(std::unique_ptr C);
   ~MultiplexConsumer() override;
 
   // ASTConsumer
@@ -80,7 +81,7 @@ class MultiplexConsumer : public SemaConsumer {
   void InitializeSema(Sema &S) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 1234608bb58647..cbb1cfd4ab02a8 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -14,11 +14,9 @@
 #ifndef LLVM_CLANG_INTERPRETER_INTERPRETER_H
 #define LLVM_CLANG_INTERPRETER_INTERPRETER_H
 
-#include "clang/AST/Decl.h"
 #include "clang/AST/GlobalDecl.h"
 #include "clang/Interpreter/PartialTranslationUnit.h"
 #include "clang/Interpreter/Value.h"
-#include "clang/Sema/Ownership.h"
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
@@ -38,6 +36,9 @@ class ThreadSafeContext;
 namespace clang {
 
 class CompilerInstance;
+class CodeGenerator;
+class CXXRecordDecl;
+class Decl;
 class IncrementalExecutor;
 class IncrementalParser;
 
@@ -77,26 +78,27 @@ class IncrementalCompilerBuilder {
   llvm::StringRef CudaSDKPath;
 };
 
-/// Generate glue code between the Interpreter's built-in runtime and user 
code.
-class RuntimeInterfaceBuilder {
-public:
-  virtual ~RuntimeInterfaceBuilder() = default;
-
-  using TransformExprFunction = ExprResult(RuntimeInterfaceBuilder *Builder,
-   Expr *, ArrayRef);
-  virtual TransformExprFunction *getPrintValueTransformer() = 0;
-};
+class IncrementalAction;
+class InProcessPrintingASTConsumer;
 
 /// Provides top-level interfaces for incremental compilation and execution.
 class Interpreter {
+  friend class Value;
+  friend InProcessPrintingASTConsumer;
+
   std::unique_ptr TSCtx;
+  /// Long-lived, incremental parsing action.
+  std::unique_ptr Act;
   std::unique_ptr IncrParser;
   std::unique_ptr IncrExecutor;
-  std::unique_ptr RuntimeIB;
 
   // An optional parser for CUDA offloading
   std::unique_ptr DeviceParser;
 
+  /// List containing every information about every incrementally parsed piece
+  /// of code.
+  std::list PTUs;
+
   unsigned InitPTUSize = 0;
 
   // This member holds the last result of the value printing. It's a class
@@ -104,15 +106,15 @@ class Interpreter {
   // printing happens, it's in an invalid state.
   Value LastValue;
 
-  // Add

[clang] 4687017 - [clang][bytecode][NFC] Fix CallBI function signature

2024-09-10 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-09-10T13:32:25+02:00
New Revision: 46870175c5425997154245cfa5b1bc31c29bdba4

URL: 
https://github.com/llvm/llvm-project/commit/46870175c5425997154245cfa5b1bc31c29bdba4
DIFF: 
https://github.com/llvm/llvm-project/commit/46870175c5425997154245cfa5b1bc31c29bdba4.diff

LOG: [clang][bytecode][NFC] Fix CallBI function signature

This doesn't modify the PC, so pass OpPC as a copy.

Added: 


Modified: 
clang/lib/AST/ByteCode/Interp.cpp
clang/lib/AST/ByteCode/Interp.h

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index ac02bd6d033487..2fa8b40f6085ad 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1177,16 +1177,16 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const 
Function *Func,
   return true;
 }
 
-bool CallBI(InterpState &S, CodePtr &PC, const Function *Func,
+bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func,
 const CallExpr *CE, uint32_t BuiltinID) {
   if (S.checkingPotentialConstantExpression())
 return false;
-  auto NewFrame = std::make_unique(S, Func, PC);
+  auto NewFrame = std::make_unique(S, Func, OpPC);
 
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame.get();
 
-  if (InterpretBuiltin(S, PC, Func, CE, BuiltinID)) {
+  if (InterpretBuiltin(S, OpPC, Func, CE, BuiltinID)) {
 NewFrame.release();
 return true;
   }

diff  --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index e345b9ead967ce..7b7c7822e4a925 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -154,7 +154,7 @@ bool Call(InterpState &S, CodePtr OpPC, const Function 
*Func,
   uint32_t VarArgSize);
 bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
   uint32_t VarArgSize);
-bool CallBI(InterpState &S, CodePtr &PC, const Function *Func,
+bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func,
 const CallExpr *CE, uint32_t BuiltinID);
 bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,
  const CallExpr *CE);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] issue-63565: community requested small QoL fix for more configurabili… (PR #108005)

2024-09-10 Thread via cfe-commits

https://github.com/MK-Alias created 
https://github.com/llvm/llvm-project/pull/108005

This is a small Quality of Life patch. It adds more configurability to 
`--function-arg-placeholders`.

The current issue for this is: 
[63565](https://github.com/llvm/llvm-project/issues/63565).  I say current, 
because more issues where made on this topic. My original issue was: 
[390](https://github.com/clangd/vscode-clangd/issues/390). Some of my 
motivations can be read in that thread: 
[here](https://github.com/clangd/vscode-clangd/issues/390#issuecomment-1647401973)
 and 
[here](https://github.com/clangd/vscode-clangd/issues/390#issuecomment-1645383861)

You might want to checkout the outputted help text, which is set in 
`ClangdMain.cpp`. It is not bad, but perhaps give it a last critical look!?

I'll be awaiting your reply or merger.

Thanks!


>From 4e9cbd615c56604fbc3c05f677b9da11f30977a2 Mon Sep 17 00:00:00 2001
From: MK-Alias 
Date: Tue, 10 Sep 2024 13:24:46 +0200
Subject: [PATCH] issue-63565: community requested small QoL fix for more
 configurability on --function-arg-placeholders

---
 clang-tools-extra/clangd/CodeComplete.cpp| 32 ++
 clang-tools-extra/clangd/CodeComplete.h  | 18 +--
 clang-tools-extra/clangd/tool/ClangdMain.cpp | 34 +++-
 3 files changed, 60 insertions(+), 24 deletions(-)

diff --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index 89eee392837af4..9fb264ef9160b3 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -350,8 +350,7 @@ struct CodeCompletionBuilder {
 CodeCompletionContext::Kind ContextKind,
 const CodeCompleteOptions &Opts,
 bool IsUsingDeclaration, tok::TokenKind NextTokenKind)
-  : ASTCtx(ASTCtx),
-EnableFunctionArgSnippets(Opts.EnableFunctionArgSnippets),
+  : ASTCtx(ASTCtx), PlaceholderType(Opts.PlaceholderType),
 IsUsingDeclaration(IsUsingDeclaration), NextTokenKind(NextTokenKind) {
 Completion.Deprecated = true; // cleared by any non-deprecated overload.
 add(C, SemaCCS, ContextKind);
@@ -561,6 +560,14 @@ struct CodeCompletionBuilder {
   }
 
   std::string summarizeSnippet() const {
+/// localize PlaceholderType for better readability
+const bool None = PlaceholderType == CodeCompleteOptions::None;
+const bool Open = PlaceholderType == CodeCompleteOptions::OpenDelimiter;
+const bool Delim = PlaceholderType == CodeCompleteOptions::Delimiters;
+const bool Full =
+PlaceholderType == CodeCompleteOptions::FullPlaceholders ||
+(!None && !Open && !Delim); // <-- failsafe
+
 if (IsUsingDeclaration)
   return "";
 auto *Snippet = onlyValue<&BundledEntry::SnippetSuffix>();
@@ -568,7 +575,7 @@ struct CodeCompletionBuilder {
   // All bundles are function calls.
   // FIXME(ibiryukov): sometimes add template arguments to a snippet, e.g.
   // we need to complete 'forward<$1>($0)'.
-  return "($0)";
+  return None ? "" : (Open ? "(" : "($0)");
 
 if (Snippet->empty())
   return "";
@@ -607,7 +614,7 @@ struct CodeCompletionBuilder {
 return "";
   }
 }
-if (EnableFunctionArgSnippets)
+if (Full)
   return *Snippet;
 
 // Replace argument snippets with a simplified pattern.
@@ -622,9 +629,9 @@ struct CodeCompletionBuilder {
 
   bool EmptyArgs = llvm::StringRef(*Snippet).ends_with("()");
   if (Snippet->front() == '<')
-return EmptyArgs ? "<$1>()$0" : "<$1>($0)";
+return None ? "" : (Open ? "<" : (EmptyArgs ? "<$1>()$0" : 
"<$1>($0)"));
   if (Snippet->front() == '(')
-return EmptyArgs ? "()" : "($0)";
+return None ? "" : (Open ? "(" : (EmptyArgs ? "()$0" : "($0)"));
   return *Snippet; // Not an arg snippet?
 }
 // 'CompletionItemKind::Interface' matches template type aliases.
@@ -638,7 +645,7 @@ struct CodeCompletionBuilder {
   // e.g. Foo<${1:class}>.
   if (llvm::StringRef(*Snippet).ends_with("<>"))
 return "<>"; // can happen with defaulted template arguments.
-  return "<$0>";
+  return None ? "" : (Open ? "<" : "<$0>");
 }
 return *Snippet;
   }
@@ -654,7 +661,7 @@ struct CodeCompletionBuilder {
   ASTContext *ASTCtx;
   CodeCompletion Completion;
   llvm::SmallVector Bundled;
-  bool EnableFunctionArgSnippets;
+  CodeCompleteOptions::PlaceholderOption PlaceholderType;
   // No snippets will be generated for using declarations and when the function
   // arguments are already present.
   bool IsUsingDeclaration;
@@ -797,8 +804,8 @@ SpecifiedScope getQueryScopes(CodeCompletionContext 
&CCContext,
   llvm::StringRef SpelledSpecifier = Lexer::getSourceText(
   CharSourceRange::getCharRange(SemaSpecifier->getRange()),
   CCSema.SourceMgr, clang::LangOptions());
-  if (SpelledSpecifier.consume_front("::")) 
-  Scopes.QueryScopes =

[clang-tools-extra] issue-63565: community requested small QoL fix for more configurabili… (PR #108005)

2024-09-10 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/108005
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] issue-63565: community requested small QoL fix for more configurabili… (PR #108005)

2024-09-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: None (MK-Alias)


Changes

This is a small Quality of Life patch. It adds more configurability to 
`--function-arg-placeholders`.

The current issue for this is: 
[63565](https://github.com/llvm/llvm-project/issues/63565).  I say current, 
because more issues where made on this topic. My original issue was: 
[390](https://github.com/clangd/vscode-clangd/issues/390). Some of my 
motivations can be read in that thread: 
[here](https://github.com/clangd/vscode-clangd/issues/390#issuecomment-1647401973)
 and 
[here](https://github.com/clangd/vscode-clangd/issues/390#issuecomment-1645383861)

You might want to checkout the outputted help text, which is set in 
`ClangdMain.cpp`. It is not bad, but perhaps give it a last critical look!?

I'll be awaiting your reply or merger.

Thanks!


---
Full diff: https://github.com/llvm/llvm-project/pull/108005.diff


3 Files Affected:

- (modified) clang-tools-extra/clangd/CodeComplete.cpp (+19-13) 
- (modified) clang-tools-extra/clangd/CodeComplete.h (+15-3) 
- (modified) clang-tools-extra/clangd/tool/ClangdMain.cpp (+26-8) 


``diff
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index 89eee392837af4..9fb264ef9160b3 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -350,8 +350,7 @@ struct CodeCompletionBuilder {
 CodeCompletionContext::Kind ContextKind,
 const CodeCompleteOptions &Opts,
 bool IsUsingDeclaration, tok::TokenKind NextTokenKind)
-  : ASTCtx(ASTCtx),
-EnableFunctionArgSnippets(Opts.EnableFunctionArgSnippets),
+  : ASTCtx(ASTCtx), PlaceholderType(Opts.PlaceholderType),
 IsUsingDeclaration(IsUsingDeclaration), NextTokenKind(NextTokenKind) {
 Completion.Deprecated = true; // cleared by any non-deprecated overload.
 add(C, SemaCCS, ContextKind);
@@ -561,6 +560,14 @@ struct CodeCompletionBuilder {
   }
 
   std::string summarizeSnippet() const {
+/// localize PlaceholderType for better readability
+const bool None = PlaceholderType == CodeCompleteOptions::None;
+const bool Open = PlaceholderType == CodeCompleteOptions::OpenDelimiter;
+const bool Delim = PlaceholderType == CodeCompleteOptions::Delimiters;
+const bool Full =
+PlaceholderType == CodeCompleteOptions::FullPlaceholders ||
+(!None && !Open && !Delim); // <-- failsafe
+
 if (IsUsingDeclaration)
   return "";
 auto *Snippet = onlyValue<&BundledEntry::SnippetSuffix>();
@@ -568,7 +575,7 @@ struct CodeCompletionBuilder {
   // All bundles are function calls.
   // FIXME(ibiryukov): sometimes add template arguments to a snippet, e.g.
   // we need to complete 'forward<$1>($0)'.
-  return "($0)";
+  return None ? "" : (Open ? "(" : "($0)");
 
 if (Snippet->empty())
   return "";
@@ -607,7 +614,7 @@ struct CodeCompletionBuilder {
 return "";
   }
 }
-if (EnableFunctionArgSnippets)
+if (Full)
   return *Snippet;
 
 // Replace argument snippets with a simplified pattern.
@@ -622,9 +629,9 @@ struct CodeCompletionBuilder {
 
   bool EmptyArgs = llvm::StringRef(*Snippet).ends_with("()");
   if (Snippet->front() == '<')
-return EmptyArgs ? "<$1>()$0" : "<$1>($0)";
+return None ? "" : (Open ? "<" : (EmptyArgs ? "<$1>()$0" : 
"<$1>($0)"));
   if (Snippet->front() == '(')
-return EmptyArgs ? "()" : "($0)";
+return None ? "" : (Open ? "(" : (EmptyArgs ? "()$0" : "($0)"));
   return *Snippet; // Not an arg snippet?
 }
 // 'CompletionItemKind::Interface' matches template type aliases.
@@ -638,7 +645,7 @@ struct CodeCompletionBuilder {
   // e.g. Foo<${1:class}>.
   if (llvm::StringRef(*Snippet).ends_with("<>"))
 return "<>"; // can happen with defaulted template arguments.
-  return "<$0>";
+  return None ? "" : (Open ? "<" : "<$0>");
 }
 return *Snippet;
   }
@@ -654,7 +661,7 @@ struct CodeCompletionBuilder {
   ASTContext *ASTCtx;
   CodeCompletion Completion;
   llvm::SmallVector Bundled;
-  bool EnableFunctionArgSnippets;
+  CodeCompleteOptions::PlaceholderOption PlaceholderType;
   // No snippets will be generated for using declarations and when the function
   // arguments are already present.
   bool IsUsingDeclaration;
@@ -797,8 +804,8 @@ SpecifiedScope getQueryScopes(CodeCompletionContext 
&CCContext,
   llvm::StringRef SpelledSpecifier = Lexer::getSourceText(
   CharSourceRange::getCharRange(SemaSpecifier->getRange()),
   CCSema.SourceMgr, clang::LangOptions());
-  if (SpelledSpecifier.consume_front("::")) 
-  Scopes.QueryScopes = {""};
+  if (SpelledSpecifier.consume_front("::"))
+Scopes.QueryScopes = {""};
   Scopes.UnresolvedQualifier = std::string(SpelledSpecifier);
   // Sema excludes the trailing "::".
   if (!Scopes.U

[clang] [Clang][SVE] Change LLVM representation of ACLE tuple types to be struct based. (PR #108008)

2024-09-10 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Paul Walker (paulwalker-arm)


Changes

This implements our original design now that LLVM is comfortable with structs 
and arrays of scalable vector types.  All SVE ACLE intrinsics already use 
struct types so the effect of this change is purely the types used for alloca 
and function parameters.

There should be no C/C++ user visible change with this patch.

---

Patch is 8.10 MiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/108008.diff


110 Files Affected:

- (modified) clang/include/clang/Basic/AArch64SVEACLETypes.def (+114-63) 
- (modified) clang/lib/AST/ASTContext.cpp (+44-118) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+6-10) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+28-56) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (-1) 
- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+24-57) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add.c 
(+56-272) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c (+32-80) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
(+528-528) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c 
(+228-290) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvtl.c (+8-2) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvtn.c 
(+32-88) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_faminmax.c 
(+264-336) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_fmlas16.c 
(+96-288) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_fp_dots.c 
(+24-120) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_frint.c 
(+176-176) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_int_dots.c 
(+96-480) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c 
(+72-18) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c 
(+72-18) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x2.c 
(+72-18) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x4.c 
(+70-28) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_max.c 
(+1056-1200) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_maxnm.c 
(+352-400) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_min.c 
(+1056-1200) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_minnm.c 
(+352-400) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mla.c 
(+24-120) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mlal.c 
(+48-240) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mlall.c 
(+120-600) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mls.c 
(+24-120) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mlsl.c 
(+48-240) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_read.c 
(+577-144) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_sqdmulh.c 
(+352-400) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_sub.c 
(+56-272) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_unpkx2.c 
(+48-12) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_unpkx4.c 
(+156-144) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vdot.c 
(+20-84) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_add.c 
(+352-352) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_qrshr.c (+60-168) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_rshl.c 
(+704-800) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_selx2.c (+216-240) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_selx4.c (+312-432) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_uzpx2.c (+432-384) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_uzpx4.c (+624-672) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_zipx2.c (+432-384) 
- (modified) 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vector_zipx4.c (+624-672) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_write.c 
(+144-576) 
- (modified) clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_movaz.c 
(+724-292) 
- (modified) 
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create2-bfloat.c (+6-6) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create2.c 
(+66-66) 
- (modified) 
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create3-bfloat.c (+8-8) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create3.c 
(+88-88) 
- (modified) 
clang/test/CodeGen/aarch64-sve

[clang] [Clang][SVE] Change LLVM representation of ACLE tuple types to be struct based. (PR #108008)

2024-09-10 Thread Paul Walker via cfe-commits

https://github.com/paulwalker-arm edited 
https://github.com/llvm/llvm-project/pull/108008
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][SVE] Change LLVM representation of ACLE tuple types to be struct based. (PR #108008)

2024-09-10 Thread Paul Walker via cfe-commits

https://github.com/paulwalker-arm edited 
https://github.com/llvm/llvm-project/pull/108008
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][SVE] Change LLVM representation of ACLE tuple types to be struct based. (PR #108008)

2024-09-10 Thread Paul Walker via cfe-commits

https://github.com/paulwalker-arm edited 
https://github.com/llvm/llvm-project/pull/108008
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [lldb] [llvm] [SystemZ][z/OS] Propagate IsText parameter to open text files as text (PR #107906)

2024-09-10 Thread Abhina Sree via cfe-commits

https://github.com/abhina-sree updated 
https://github.com/llvm/llvm-project/pull/107906

>From 758745c955471b0ad65cd3a33381f753e2b63797 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Mon, 9 Sep 2024 15:32:09 -0400
Subject: [PATCH 1/2] Propagate IsText parameter to openFileForRead function

---
 clang-tools-extra/clangd/FS.cpp   |  4 +--
 clang-tools-extra/clangd/Preamble.cpp |  4 +--
 .../clangd/support/ThreadsafeFS.cpp   |  2 +-
 .../clangd/unittests/ClangdTests.cpp  |  2 +-
 clang/include/clang/Basic/FileManager.h   |  8 +++---
 .../DependencyScanningFilesystem.h|  2 +-
 clang/lib/Basic/FileManager.cpp   | 12 -
 clang/lib/Basic/SourceManager.cpp | 14 --
 clang/lib/Serialization/ASTReader.cpp |  3 ++-
 .../DependencyScanningFilesystem.cpp  |  5 ++--
 clang/unittests/Driver/DistroTest.cpp |  4 +--
 clang/unittests/Driver/ToolChainTest.cpp  |  2 +-
 clang/unittests/Frontend/PCHPreambleTest.cpp  |  6 ++---
 .../DependencyScannerTest.cpp |  4 +--
 llvm/include/llvm/Support/AutoConvert.h   |  6 +
 llvm/include/llvm/Support/VirtualFileSystem.h | 21 ---
 llvm/lib/Support/AutoConvert.cpp  | 26 +++
 llvm/lib/Support/FileCollector.cpp|  4 +--
 llvm/lib/Support/VirtualFileSystem.cpp| 21 ---
 .../Support/VirtualFileSystemTest.cpp |  6 ++---
 20 files changed, 103 insertions(+), 53 deletions(-)

diff --git a/clang-tools-extra/clangd/FS.cpp b/clang-tools-extra/clangd/FS.cpp
index 5729b9341d9d4b..bd3c6440c24b0f 100644
--- a/clang-tools-extra/clangd/FS.cpp
+++ b/clang-tools-extra/clangd/FS.cpp
@@ -64,8 +64,8 @@ PreambleFileStatusCache::getProducingFS(
 : ProxyFileSystem(std::move(FS)), StatCache(StatCache) {}
 
 llvm::ErrorOr>
-openFileForRead(const llvm::Twine &Path) override {
-  auto File = getUnderlyingFS().openFileForRead(Path);
+openFileForRead(const llvm::Twine &Path, bool IsText = true) override {
+  auto File = getUnderlyingFS().openFileForRead(Path, IsText);
   if (!File || !*File)
 return File;
   // Eagerly stat opened file, as the followup `status` call on the file
diff --git a/clang-tools-extra/clangd/Preamble.cpp 
b/clang-tools-extra/clangd/Preamble.cpp
index dd13b1a9e5613d..e970d01f3729f3 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -479,9 +479,9 @@ class TimerFS : public llvm::vfs::ProxyFileSystem {
   : ProxyFileSystem(std::move(FS)) {}
 
   llvm::ErrorOr>
-  openFileForRead(const llvm::Twine &Path) override {
+  openFileForRead(const llvm::Twine &Path, bool IsText = true) override {
 WallTimerRegion T(Timer);
-auto FileOr = getUnderlyingFS().openFileForRead(Path);
+auto FileOr = getUnderlyingFS().openFileForRead(Path, IsText);
 if (!FileOr)
   return FileOr;
 return std::make_unique(Timer, std::move(FileOr.get()));
diff --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp 
b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
index 7398e4258527ba..bc0b984e577cb8 100644
--- a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
+++ b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
@@ -29,7 +29,7 @@ class VolatileFileSystem : public llvm::vfs::ProxyFileSystem {
   : ProxyFileSystem(std::move(FS)) {}
 
   llvm::ErrorOr>
-  openFileForRead(const llvm::Twine &InPath) override {
+  openFileForRead(const llvm::Twine &InPath, bool IsText = true) override {
 llvm::SmallString<128> Path;
 InPath.toVector(Path);
 
diff --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp 
b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
index 643b8e9f12d751..e86385c2072b34 100644
--- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -1010,7 +1010,7 @@ TEST(ClangdTests, PreambleVFSStatCache) {
 : ProxyFileSystem(std::move(FS)), CountStats(CountStats) {}
 
 llvm::ErrorOr>
-openFileForRead(const Twine &Path) override {
+openFileForRead(const Twine &Path, bool IsText = true) override {
   ++CountStats[llvm::sys::path::filename(Path.str())];
   return ProxyFileSystem::openFileForRead(Path);
 }
diff --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 527bbef24793ee..67a69fb79ccefe 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -286,21 +286,21 @@ class FileManager : public RefCountedBase {
   /// MemoryBuffer if successful, otherwise returning null.
   llvm::ErrorOr>
   getBufferForFile(FileEntryRef Entry, bool isVolatile = false,
-   bool RequiresNullTerminator = true,
+   bool RequiresNullTerminator = true, bool IsText = true,
std::optional MaybeLimit = std::nullopt);
   llvm::Error

[clang] [APINotes] Avoid repeated hash lookups (NFC) (PR #107959)

2024-09-10 Thread Egor Zhdan via cfe-commits

https://github.com/egorzhdan approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/107959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6a56f15 - [clang][bytecode][NFC] Fix a commented-out test

2024-09-10 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-09-10T14:05:46+02:00
New Revision: 6a56f15211f034ad668d24dfec5d7f722e33a7a2

URL: 
https://github.com/llvm/llvm-project/commit/6a56f15211f034ad668d24dfec5d7f722e33a7a2
DIFF: 
https://github.com/llvm/llvm-project/commit/6a56f15211f034ad668d24dfec5d7f722e33a7a2.diff

LOG: [clang][bytecode][NFC] Fix a commented-out test

Added: 


Modified: 
clang/test/AST/ByteCode/cxx20.cpp

Removed: 




diff  --git a/clang/test/AST/ByteCode/cxx20.cpp 
b/clang/test/AST/ByteCode/cxx20.cpp
index 77a967d42c4efe..9bbc3dbe0073d3 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -641,7 +641,7 @@ namespace ThreeWayCmp {
   constexpr const int *pa2 = &a[2];
   constexpr const int *pb1 = &b[1];
   static_assert(pa1 <=> pb1 != 0, ""); // both-error {{not an integral 
constant expression}} \
-   // both-note {{has unspecified value}} \
+   // both-note {{has unspecified value}}
   static_assert(pa1 <=> pa1 == 0, "");
   static_assert(pa1 <=> pa2 == -1, "");
   static_assert(pa2 <=> pa1 == 1, "");



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Introduce FunctionParmPackDecl for expanded lambda captures (PR #107995)

2024-09-10 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/107995

>From c97f213bc412dd2a4d6ee5c8e58a82f04dbbd03b Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 10 Sep 2024 17:23:55 +0800
Subject: [PATCH 1/2] [Clang] Introduce FunctionParmPackDecl for expanded
 lambda captures

---
 clang/docs/ReleaseNotes.rst   |  2 +-
 clang/include/clang/AST/DeclTemplate.h| 37 +++
 clang/include/clang/AST/RecursiveASTVisitor.h |  2 +
 clang/include/clang/Basic/DeclNodes.td|  1 +
 clang/include/clang/Sema/Template.h   |  3 ++
 .../include/clang/Serialization/ASTBitCodes.h |  5 ++-
 clang/lib/AST/DeclBase.cpp|  1 +
 clang/lib/AST/DeclTemplate.cpp| 37 +++
 clang/lib/CodeGen/CGDecl.cpp  |  1 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 25 -
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  5 +++
 clang/lib/Sema/TreeTransform.h| 14 +--
 clang/lib/Serialization/ASTCommon.cpp |  1 +
 clang/lib/Serialization/ASTReaderDecl.cpp | 11 ++
 clang/lib/Serialization/ASTWriterDecl.cpp | 10 +
 .../SemaCXX/fold_lambda_with_variadics.cpp| 31 
 clang/tools/libclang/CIndex.cpp   |  1 +
 17 files changed, 157 insertions(+), 30 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 250821a9f9c45c..f39c39f8646d08 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -344,7 +344,7 @@ Bug Fixes to C++ Support
   module imports in those situations. (#GH60336)
 - Fix init-capture packs having a size of one before being instantiated. 
(#GH63677)
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
-  (#GH99877).
+  (#GH99877), (#GH18873).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
 - Fixed an assertion failure when selecting a function from an overload set 
that includes a
   specialization of a conversion function template.
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 687715a22e9fd3..3730f5bee09d2a 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -3220,6 +3220,43 @@ class ImplicitConceptSpecializationDecl final
   friend class ASTDeclReader;
 };
 
+class FunctionParmPackDecl final
+: public Decl,
+  private llvm::TrailingObjects {
+  friend TrailingObjects;
+  friend class ASTDeclReader;
+
+  /// The function parameter pack which was referenced.
+  NamedDecl *Pattern;
+
+  unsigned NumExpansions;
+
+  FunctionParmPackDecl(DeclContext *DC, SourceLocation StartLoc,
+   NamedDecl *Pattern, ArrayRef ExpandedParams);
+
+  void setExpandedParams(ArrayRef ExpandedParams);
+
+public:
+  static FunctionParmPackDecl *Create(ASTContext &C, DeclContext *DC,
+  SourceLocation StartLoc,
+  NamedDecl *Pattern,
+  ArrayRef ExpandedParams);
+
+  static FunctionParmPackDecl *
+  CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumExpansions);
+
+  ArrayRef getExpandedParams() const {
+return ArrayRef(getTrailingObjects(), NumExpansions);
+  }
+
+  unsigned getNumExpansions() const { return NumExpansions; }
+
+  NamedDecl *getPattern() const { return Pattern; }
+
+  static bool classofKind(Kind K) { return K == FunctionParmPack; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+};
+
 /// A template parameter object.
 ///
 /// Template parameter objects represent values of class type used as template
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 3389670a2ab9d9..3297e9eb009678 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2353,6 +2353,8 @@ DEF_TRAVERSE_DECL(ImplicitConceptSpecializationDecl, {
   TRY_TO(TraverseTemplateArguments(D->getTemplateArguments()));
 })
 
+DEF_TRAVERSE_DECL(FunctionParmPackDecl, {})
+
 #undef DEF_TRAVERSE_DECL
 
 // - Stmt traversal -
diff --git a/clang/include/clang/Basic/DeclNodes.td 
b/clang/include/clang/Basic/DeclNodes.td
index 48396e85c5adac..694d3d8b79a183 100644
--- a/clang/include/clang/Basic/DeclNodes.td
+++ b/clang/include/clang/Basic/DeclNodes.td
@@ -91,6 +91,7 @@ def Named : DeclNode;
   def ObjCProperty : DeclNode;
   def ObjCCompatibleAlias : DeclNode;
 def ImplicitConceptSpecialization : DeclNode;
+def FunctionParmPack : DeclNode;
 def LinkageSpec : DeclNode, DeclContext;
 def Export : DeclNode, DeclContext;
 def ObjCPropertyImpl : DeclNode;
diff --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index 0340c23fd170d6..5de4bf0148652c 

[clang] [clang-tools-extra] [libcxx] [C++17] Support __GCC_[CON|DE]STRUCTIVE_SIZE (PR #89446)

2024-09-10 Thread Levi Zim via cfe-commits

kxxt wrote:

> Here are the values that I found for GCC that don't match the defaults.
> Platform  ConstructiveDestructive Link
> ARM64 64  256 https://godbolt.org/z/G7arf9nPP
> AVR   32  32  https://godbolt.org/z/Yq64f9Koj
> BPF   32  32  https://godbolt.org/z/zezK71zoe
> M68K  32  32  https://godbolt.org/z/h9f4vaYcs
> mips  32  32  https://godbolt.org/z/v3nfPMx9b
> mips6432  32  https://godbolt.org/z/7G66rc4nY
> power 32  32  https://godbolt.org/z/bWjdosE3f
> power64   128 128 https://godbolt.org/z/jT86TMYTK
> RISC-V 32-bit 32  32  https://godbolt.org/z/neErxEbWP
> RISV-V 64-bit 32  32  https://godbolt.org/z/nG5zjjxdo
> s390x 256 256 https://godbolt.org/z/j34f3eEMz
> sparc 32  32  https://godbolt.org/z/96hscbesM
> 
> Note, this is testing default configuration with no CPU tuning. I'll nab the 
> values from here that I can map to our targets but target owners should 
> validate these values and let me know if anything looks amiss.

FYI [the value 32 is the default value set by GCC and might be 
wrong](https://gcc.gnu.org/pipermail/libstdc++/2024-September/059490.html). I 
have submitted [a bug to gcc about the wrong cacheline size 32 for riscv64 
target](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116662).

https://github.com/llvm/llvm-project/pull/89446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility to AMDGPU. (PR #107997)

2024-09-10 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu approved this pull request.


https://github.com/llvm/llvm-project/pull/107997
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [libcxx] [C++17] Support __GCC_[CON|DE]STRUCTIVE_SIZE (PR #89446)

2024-09-10 Thread Andrew Pinski via cfe-commits

pinskia wrote:

https://github.com/itanium-cxx-abi/cxx-abi/issues/74

https://github.com/llvm/llvm-project/pull/89446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Split FeatureLS64 to LS64_ACCDATA and LS64_V. (PR #101712)

2024-09-10 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

I am abandoning this PR in favor of 
https://github.com/ARM-software/acle/pull/346

https://github.com/llvm/llvm-project/pull/101712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Split FeatureLS64 to LS64_ACCDATA and LS64_V. (PR #101712)

2024-09-10 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/101712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [ARM][AArch64] Split FEAT_SHA1 from FEAT_SHA256. (PR #99816)

2024-09-10 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

I am abandoning this PR in favor of 
https://github.com/ARM-software/acle/pull/346

https://github.com/llvm/llvm-project/pull/99816
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clangd] show lambda name instead of operator() in signature help (PR #101857)

2024-09-10 Thread Timothy Akintilo via cfe-commits


@@ -876,6 +876,11 @@ class Sema;
 /// function pointer or reference (C++ [over.call.object]).
 FunctionDecl *Function;
 
+/// LambdaName - When the OverloadCandidate is for a
+/// lambda's operator(), points to the declaration of
+/// the lambda variable.
+VarDecl *LambdaName{nullptr};

tilobyte wrote:

Wait I think I understand now, you mean the signature help when immediately 
invoking the lambdas within the `bar` function call? E.g., `bar([]{...}(^), 
...)`

https://github.com/llvm/llvm-project/pull/101857
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [ARM][AArch64] Split FEAT_SHA1 from FEAT_SHA256. (PR #99816)

2024-09-10 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/99816
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HIP] Target-dependent overload resolution in declarators and specifiers (PR #103031)

2024-09-10 Thread Yaxun Liu via cfe-commits


@@ -0,0 +1,703 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only 
-verify=expected,onhost %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only -fcuda-is-device 
-verify=expected,ondevice %s
+
+
+// Tests to ensure that functions with host and device overloads in that are
+// called outside of function bodies and variable initializers, e.g., in
+// template arguments are resolved with respect to the declaration to which 
they
+// belong.
+
+// Opaque types used for tests:
+struct DeviceTy {};
+struct HostTy {};
+struct HostDeviceTy {};
+struct TemplateTy {};
+
+struct TrueTy { static const bool value = true; };
+struct FalseTy { static const bool value = false; };
+
+// Select one of two types based on a boolean condition.
+template  struct select_type {};
+template  struct select_type { typedef T 
type; };
+template  struct select_type { typedef F 
type; };
+
+template  struct check : public select_type { };
+
+// Check if two types are the same.
+template struct is_same : public FalseTy { };
+template struct is_same : public TrueTy { };
+
+// A static assertion that fails at compile time if the expression E does not
+// have type T.
+#define ASSERT_HAS_TYPE(E, T) static_assert(is_same::value);
+
+
+// is_on_device() is true when called in a device context and false if called 
in a host context.
+__attribute__((host)) constexpr bool is_on_device(void) { return false; }
+__attribute__((device)) constexpr bool is_on_device(void) { return true; }
+
+
+// this type depends on whether it occurs in host or device code
+#define targetdep_t select_type::type
+
+// Defines and typedefs with different values in host and device compilation.
+#ifdef __CUDA_ARCH__
+#define CurrentTarget DEVICE
+typedef DeviceTy CurrentTargetTy;
+typedef DeviceTy TemplateIfHostTy;
+#else
+#define CurrentTarget HOST
+typedef HostTy CurrentTargetTy;
+typedef TemplateTy TemplateIfHostTy;
+#endif
+
+
+
+// targetdep_t in function declarations should depend on the target of the
+// declared function.
+__attribute__((device)) targetdep_t decl_ret_early_device(void);
+ASSERT_HAS_TYPE(decl_ret_early_device(), DeviceTy)
+
+__attribute__((host)) targetdep_t decl_ret_early_host(void);
+ASSERT_HAS_TYPE(decl_ret_early_host(), HostTy)
+
+__attribute__((host,device)) targetdep_t decl_ret_early_host_device(void);
+ASSERT_HAS_TYPE(decl_ret_early_host_device(), CurrentTargetTy)
+
+// If the function target is specified too late and can therefore not be
+// considered for overload resolution in targetdep_t, warn.
+targetdep_t __attribute__((device)) decl_ret_late_device(void); // 
expected-warning {{target attribute has been ignored for overload resolution}}
+ASSERT_HAS_TYPE(decl_ret_late_device(), HostTy)
+
+// No warning necessary if the ignored attribute doesn't change the result.
+targetdep_t __attribute__((host)) decl_ret_late_host(void);
+ASSERT_HAS_TYPE(decl_ret_late_host(), HostTy)
+
+targetdep_t __attribute__((host,device)) decl_ret_late_host_device(void); // 
expected-warning {{target attribute has been ignored for overload resolution}}
+ASSERT_HAS_TYPE(decl_ret_late_host_device(), HostTy)
+
+// An odd way of writing this, but it's possible.
+__attribute__((device)) targetdep_t __attribute__((host)) 
decl_ret_early_device_late_host(void); // expected-warning {{target attribute 
has been ignored for overload resolution}}
+ASSERT_HAS_TYPE(decl_ret_early_device_late_host(), DeviceTy)
+
+
+// The same for function definitions and parameter types:
+__attribute__((device)) targetdep_t ret_early_device(targetdep_t x) {
+  ASSERT_HAS_TYPE(ret_early_device({}), DeviceTy)
+  ASSERT_HAS_TYPE(x, DeviceTy)
+  return {};
+}
+
+__attribute__((host)) targetdep_t ret_early_host(targetdep_t x) {
+  ASSERT_HAS_TYPE(ret_early_host({}), HostTy)
+  ASSERT_HAS_TYPE(x, HostTy)
+  return {};
+}
+
+__attribute__((host, device)) targetdep_t ret_early_hostdevice(targetdep_t x) {
+  ASSERT_HAS_TYPE(ret_early_hostdevice({}), CurrentTargetTy)
+  ASSERT_HAS_TYPE(x, CurrentTargetTy)
+  return {};
+}
+
+// The parameter is still after the attribute, so it needs no warning.
+targetdep_t __attribute__((device)) // expected-warning {{target attribute has 
been ignored for overload resolution}}
+ret_late_device(targetdep_t x) {
+  ASSERT_HAS_TYPE(ret_late_device({}), HostTy)
+  ASSERT_HAS_TYPE(x, DeviceTy)
+  return {};
+}
+
+targetdep_t __attribute__((host, device)) // expected-warning {{target 
attribute has been ignored for overload resolution}}
+ret_late_hostdevice(targetdep_t x) {
+  ASSERT_HAS_TYPE(ret_late_hostdevice({}), HostTy)
+  ASSERT_HAS_TYPE(x, CurrentTargetTy)
+  return {};
+}
+
+targetdep_t __attribute__((host)) ret_late_host(targetdep_t x) {
+  ASSERT_HAS_TYPE(ret_late_host({}), HostTy)
+  ASSERT_HAS_TYPE(x, HostTy)
+  return {};
+}
+
+__attribute__((device)) targetdep_t __attribute__((host)) // expected-warning 
{{target attribute has been ignored for overload resolution}}
+ret_early_device_late_host(targetdep_t x) 

[clang] [clang][Sema] Fix wrong assumption in `tryDiagnoseOverloadedCast` (PR #108021)

2024-09-10 Thread Alejandro Álvarez Ayllón via cfe-commits

https://github.com/alejandro-alvarez-sonarsource created 
https://github.com/llvm/llvm-project/pull/108021

A constructor may have failed to be used due to a broken templated dependent 
parameter. The `InitializationSequence` itself can succeed.

Due to the assumption that it is in a failed state, it can either cause an 
assertion failure, or undefined behavior in release mode, since 
`sequence.Failure` is not initialized.

From b414b6e184fc566efd6a2dbe631ee68a25b461a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 
Date: Fri, 16 Jun 2023 18:01:33 +0200
Subject: [PATCH] [clang][Sema] Fix wrong assumption in
 `tryDiagnoseOverloadedCast`

A constructor may have failed to be used due to a broken templated
dependent parameter. The `InitializationSequence` itself can
succeed.

Due to the assumption that it is in a failed state, it can
either cause an assertion failure, or undefined behavior in release
mode, since `sequence.Failure` is not initialized.
---
 clang/lib/Sema/SemaCast.cpp   |  7 -
 .../cxx-bad-cast-diagnose-broken-template.cpp | 31 +++
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Parser/cxx-bad-cast-diagnose-broken-template.cpp

diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index f01b22a72915c8..6ac6201843476b 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -446,7 +446,12 @@ static bool tryDiagnoseOverloadedCast(Sema &S, CastType CT,
 : InitializationKind::CreateCast(/*type range?*/ range);
   InitializationSequence sequence(S, entity, initKind, src);
 
-  assert(sequence.Failed() && "initialization succeeded on second try?");
+  // It could happen that a constructor failed to be used because
+  // it requires a temporary of a broken type. Still, it will be found when
+  // looking for a match.
+  if (!sequence.Failed())
+return false;
+
   switch (sequence.getFailureKind()) {
   default: return false;
 
diff --git a/clang/test/Parser/cxx-bad-cast-diagnose-broken-template.cpp 
b/clang/test/Parser/cxx-bad-cast-diagnose-broken-template.cpp
new file mode 100644
index 00..f9fc3e6082da10
--- /dev/null
+++ b/clang/test/Parser/cxx-bad-cast-diagnose-broken-template.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
+
+template< typename>
+struct IsConstCharArray
+{
+  static const bool value = false;
+};
+
+template< int N >
+struct IsConstCharArray< const char[ N ] >
+{
+  typedef char CharType;
+  static const bool value = true;
+  static const missing_int_t length = N - 1; // expected-error {{unknown type 
name 'missing_int_t'}}
+};
+
+class String {
+public:
+  template 
+  String(T& str, typename IsConstCharArray::CharType = 0);
+};
+
+
+class Exception {
+public:
+  Exception(String const&);
+};
+
+void foo() {
+  throw Exception("some error"); // expected-error {{functional-style cast 
from 'const char[11]' to 'Exception' is not allowed}}
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Fix assertion in `tryDiagnoseOverloadedCast` (PR #108021)

2024-09-10 Thread Alejandro Álvarez Ayllón via cfe-commits

https://github.com/alejandro-alvarez-sonarsource edited 
https://github.com/llvm/llvm-project/pull/108021
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Fix assertion in `tryDiagnoseOverloadedCast` (PR #108021)

2024-09-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alejandro Álvarez Ayllón (alejandro-alvarez-sonarsource)


Changes

A constructor may have failed to be used due to a broken templated dependent 
parameter. The `InitializationSequence` itself can succeed.

Due to the assumption that it is in a failed state, it can either cause an 
assertion failure, or undefined behavior in release mode, since 
`sequence.Failure` is not initialized.

---
Full diff: https://github.com/llvm/llvm-project/pull/108021.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaCast.cpp (+6-1) 
- (added) clang/test/Parser/cxx-bad-cast-diagnose-broken-template.cpp (+31) 


``diff
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index f01b22a72915c8..6ac6201843476b 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -446,7 +446,12 @@ static bool tryDiagnoseOverloadedCast(Sema &S, CastType CT,
 : InitializationKind::CreateCast(/*type range?*/ range);
   InitializationSequence sequence(S, entity, initKind, src);
 
-  assert(sequence.Failed() && "initialization succeeded on second try?");
+  // It could happen that a constructor failed to be used because
+  // it requires a temporary of a broken type. Still, it will be found when
+  // looking for a match.
+  if (!sequence.Failed())
+return false;
+
   switch (sequence.getFailureKind()) {
   default: return false;
 
diff --git a/clang/test/Parser/cxx-bad-cast-diagnose-broken-template.cpp 
b/clang/test/Parser/cxx-bad-cast-diagnose-broken-template.cpp
new file mode 100644
index 00..f9fc3e6082da10
--- /dev/null
+++ b/clang/test/Parser/cxx-bad-cast-diagnose-broken-template.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
+
+template< typename>
+struct IsConstCharArray
+{
+  static const bool value = false;
+};
+
+template< int N >
+struct IsConstCharArray< const char[ N ] >
+{
+  typedef char CharType;
+  static const bool value = true;
+  static const missing_int_t length = N - 1; // expected-error {{unknown type 
name 'missing_int_t'}}
+};
+
+class String {
+public:
+  template 
+  String(T& str, typename IsConstCharArray::CharType = 0);
+};
+
+
+class Exception {
+public:
+  Exception(String const&);
+};
+
+void foo() {
+  throw Exception("some error"); // expected-error {{functional-style cast 
from 'const char[11]' to 'Exception' is not allowed}}
+}

``




https://github.com/llvm/llvm-project/pull/108021
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Resolve FIXME in altivec.h (PR #78905)

2024-09-10 Thread Rose Silicon via cfe-commits

https://github.com/RSilicon closed 
https://github.com/llvm/llvm-project/pull/78905
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][Clang][SVE] Refactor AArch64SVEACLETypes.def to enabled more uses. (PR #107599)

2024-09-10 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm approved this pull request.

Looks like a nice improvement to the code.

https://github.com/llvm/llvm-project/pull/107599
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC] Expand isClassLayoutKnownStatically to base classes as long as the implementation of it is known (PR #85465)

2024-09-10 Thread Rose Silicon via cfe-commits

https://github.com/RSilicon closed 
https://github.com/llvm/llvm-project/pull/85465
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC] Defer to the LLVM backend for unaligned atomic load and stores (PR #79191)

2024-09-10 Thread Rose Silicon via cfe-commits

https://github.com/RSilicon closed 
https://github.com/llvm/llvm-project/pull/79191
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Move 'alpha.core.PointerSub' checker into 'core.PointerSub' (PR #107596)

2024-09-10 Thread Balazs Benics via cfe-commits

https://github.com/steakhal approved this pull request.

> > I'm not satisfied with the quality of the reports. The report refers to 
> > `Subtraction of two pointers that do not point into the same array is 
> > undefined behavior` without pointing out where the two pointers point to 
> > (and/or where are they declared, or set to point to different objects). 
> > Without improving the diagnostics, I don't think we should move this out of 
> > alpha.
> 
> For this purpose the report notes were added. In the CodeChecker interface 
> the arrow beneath "Notes" can be expanded to see these notes. Sure it can be 
> even more exact if all the super-regions were pointed out but in the current 
> reports it is probably not difficult to recognize what the different regions 
> are (different variables or different members of a struct or a variable and a 
> member of the same struct as the variable).

I see! Thanks. In that case, I don't oppose.

https://github.com/llvm/llvm-project/pull/107596
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Compute switch capacity based on number of branch-afters and fixups (PR #86815)

2024-09-10 Thread Rose Silicon via cfe-commits

https://github.com/RSilicon closed 
https://github.com/llvm/llvm-project/pull/86815
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC] Set visibility of IvarOffsetGV when it is created in ObjCIvarOffsetVariable (PR #83726)

2024-09-10 Thread Rose Silicon via cfe-commits

https://github.com/RSilicon closed 
https://github.com/llvm/llvm-project/pull/83726
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [FMV][AArch64] Unify ls64, ls64_v and ls64_accdata. (PR #108024)

2024-09-10 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/108024

Originally I tried spliting these features in the compiler with 
https://github.com/llvm/llvm-project/pull/101712, but I realized that there's 
no way to preserve backwards compatibility, therefore we decided to lump those 
features in the ACLE specification too 
https://github.com/ARM-software/acle/pull/346. Since there are no hardware 
implementations out there which implement ls64 without ls64_v or ls64_accdata, 
this shouldn't be a regression for feature detection.

>From b6abb4f0fcf50d7498a6f0d0ef8b75808c8b1eb1 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Tue, 10 Sep 2024 14:02:17 +0100
Subject: [PATCH] [FMV][AArch64] Unify ls64, ls64_v and ls64_accdata.

Originally I tried spliting these features in the compiler with
https://github.com/llvm/llvm-project/pull/101712, but I realized
that there's no way to preserve backwards compatibility, therefore
we decided to lump those features in the ACLE specification too
https://github.com/ARM-software/acle/pull/346. Since there are no
hardware implementations out there which implement ls64 without
ls64_v or ls64_accdata, this shouldn't be a regression for feature
detection.
---
 clang/test/CodeGen/aarch64-cpu-supports.c |   6 +-
 clang/test/CodeGen/aarch64-fmv-dependencies.c |  10 +-
 .../test/CodeGen/attr-target-clones-aarch64.c |   8 +-
 clang/test/CodeGen/attr-target-version.c  | 142 +-
 .../CodeGenCXX/attr-target-clones-aarch64.cpp |  63 
 clang/test/CodeGenCXX/attr-target-version.cpp |   4 +-
 clang/test/CodeGenCXX/fmv-namespace.cpp   |   4 +-
 clang/test/Sema/attr-target-clones-aarch64.c  |   4 +-
 .../builtins/cpu_model/AArch64CPUFeatures.inc |   2 -
 .../builtins/cpu_model/aarch64/fmv/mrs.inc|   6 -
 .../llvm/TargetParser/AArch64CPUFeatures.inc  |   2 -
 llvm/lib/Target/AArch64/AArch64FMV.td |   4 +-
 12 files changed, 119 insertions(+), 136 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-cpu-supports.c 
b/clang/test/CodeGen/aarch64-cpu-supports.c
index c54b7475a3fd5f..45689d74e8da23 100644
--- a/clang/test/CodeGen/aarch64-cpu-supports.c
+++ b/clang/test/CodeGen/aarch64-cpu-supports.c
@@ -26,8 +26,8 @@
 // CHECK-NEXT:br label [[RETURN]]
 // CHECK:   if.end2:
 // CHECK-NEXT:[[TMP8:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP9:%.*]] = and i64 [[TMP8]], 166633186212708352
-// CHECK-NEXT:[[TMP10:%.*]] = icmp eq i64 [[TMP9]], 166633186212708352
+// CHECK-NEXT:[[TMP9:%.*]] = and i64 [[TMP8]], 42784196460019712
+// CHECK-NEXT:[[TMP10:%.*]] = icmp eq i64 [[TMP9]], 42784196460019712
 // CHECK-NEXT:[[TMP11:%.*]] = and i1 true, [[TMP10]]
 // CHECK-NEXT:br i1 [[TMP11]], label [[IF_THEN3:%.*]], label 
[[IF_END4:%.*]]
 // CHECK:   if.then3:
@@ -52,7 +52,7 @@ int main(void) {
   if (__builtin_cpu_supports("sve2-pmull128+memtag"))
 return 2;
 
-  if (__builtin_cpu_supports("sme2+ls64_v+wfxt"))
+  if (__builtin_cpu_supports("sme2+ls64+wfxt"))
 return 3;
 
   if (__builtin_cpu_supports("avx2"))
diff --git a/clang/test/CodeGen/aarch64-fmv-dependencies.c 
b/clang/test/CodeGen/aarch64-fmv-dependencies.c
index e39c7adbe4a9b0..f2eec11baed379 100644
--- a/clang/test/CodeGen/aarch64-fmv-dependencies.c
+++ b/clang/test/CodeGen/aarch64-fmv-dependencies.c
@@ -66,15 +66,9 @@ __attribute__((target_version("i8mm"))) int fmv(void) { 
return 0; }
 // CHECK: define dso_local i32 @fmv._Mjscvt() #[[jscvt:[0-9]+]] {
 __attribute__((target_version("jscvt"))) int fmv(void) { return 0; }
 
-// CHECK: define dso_local i32 @fmv._Mls64() #[[ATTR0:[0-9]+]] {
+// CHECK: define dso_local i32 @fmv._Mls64() #[[ls64:[0-9]+]] {
 __attribute__((target_version("ls64"))) int fmv(void) { return 0; }
 
-// CHECK: define dso_local i32 @fmv._Mls64_accdata() #[[ls64_accdata:[0-9]+]] {
-__attribute__((target_version("ls64_accdata"))) int fmv(void) { return 0; }
-
-// CHECK: define dso_local i32 @fmv._Mls64_v() #[[ATTR0:[0-9]+]] {
-__attribute__((target_version("ls64_v"))) int fmv(void) { return 0; }
-
 // CHECK: define dso_local i32 @fmv._Mlse() #[[lse:[0-9]+]] {
 __attribute__((target_version("lse"))) int fmv(void) { return 0; }
 
@@ -210,7 +204,7 @@ int caller() {
 // CHECK: attributes #[[frintts]] = { {{.*}} 
"target-features"="+fp-armv8,+fptoint,+neon,+outline-atomics,+v8a"
 // CHECK: attributes #[[i8mm]] = { {{.*}} 
"target-features"="+fp-armv8,+i8mm,+neon,+outline-atomics,+v8a"
 // CHECK: attributes #[[jscvt]] = { {{.*}} 
"target-features"="+fp-armv8,+jsconv,+neon,+outline-atomics,+v8a"
-// CHECK: attributes #[[ls64_accdata]] = { {{.*}} 
"target-features"="+fp-armv8,+ls64,+neon,+outline-atomics,+v8a"
+// CHECK: attributes #[[ls64]] = { {{.*}} 
"target-features"="+fp-armv8,+ls64,+neon,+outline-atomics,+v8a"
 // CHECK: attributes #[[lse]] = { {{.*}} 
"target-features"="+fp-armv8,+lse,+neon,+outline-atomics,+v8a"
 // CHECK: attributes #[[memtag2]] = { {{.*}} 
"target-features"

[clang] [compiler-rt] [llvm] [FMV][AArch64] Unify ls64, ls64_v and ls64_accdata. (PR #108024)

2024-09-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alexandros Lamprineas (labrinea)


Changes

Originally I tried spliting these features in the compiler with 
https://github.com/llvm/llvm-project/pull/101712, but I realized that there's 
no way to preserve backwards compatibility, therefore we decided to lump those 
features in the ACLE specification too 
https://github.com/ARM-software/acle/pull/346. Since there are no hardware 
implementations out there which implement ls64 without ls64_v or ls64_accdata, 
this shouldn't be a regression for feature detection.

---

Patch is 46.52 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/108024.diff


12 Files Affected:

- (modified) clang/test/CodeGen/aarch64-cpu-supports.c (+3-3) 
- (modified) clang/test/CodeGen/aarch64-fmv-dependencies.c (+2-8) 
- (modified) clang/test/CodeGen/attr-target-clones-aarch64.c (+4-4) 
- (modified) clang/test/CodeGen/attr-target-version.c (+72-70) 
- (modified) clang/test/CodeGenCXX/attr-target-clones-aarch64.cpp (+31-32) 
- (modified) clang/test/CodeGenCXX/attr-target-version.cpp (+2-2) 
- (modified) clang/test/CodeGenCXX/fmv-namespace.cpp (+2-2) 
- (modified) clang/test/Sema/attr-target-clones-aarch64.c (+2-2) 
- (modified) compiler-rt/lib/builtins/cpu_model/AArch64CPUFeatures.inc (-2) 
- (modified) compiler-rt/lib/builtins/cpu_model/aarch64/fmv/mrs.inc (-6) 
- (modified) llvm/include/llvm/TargetParser/AArch64CPUFeatures.inc (-2) 
- (modified) llvm/lib/Target/AArch64/AArch64FMV.td (+1-3) 


``diff
diff --git a/clang/test/CodeGen/aarch64-cpu-supports.c 
b/clang/test/CodeGen/aarch64-cpu-supports.c
index c54b7475a3fd5f..45689d74e8da23 100644
--- a/clang/test/CodeGen/aarch64-cpu-supports.c
+++ b/clang/test/CodeGen/aarch64-cpu-supports.c
@@ -26,8 +26,8 @@
 // CHECK-NEXT:br label [[RETURN]]
 // CHECK:   if.end2:
 // CHECK-NEXT:[[TMP8:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP9:%.*]] = and i64 [[TMP8]], 166633186212708352
-// CHECK-NEXT:[[TMP10:%.*]] = icmp eq i64 [[TMP9]], 166633186212708352
+// CHECK-NEXT:[[TMP9:%.*]] = and i64 [[TMP8]], 42784196460019712
+// CHECK-NEXT:[[TMP10:%.*]] = icmp eq i64 [[TMP9]], 42784196460019712
 // CHECK-NEXT:[[TMP11:%.*]] = and i1 true, [[TMP10]]
 // CHECK-NEXT:br i1 [[TMP11]], label [[IF_THEN3:%.*]], label 
[[IF_END4:%.*]]
 // CHECK:   if.then3:
@@ -52,7 +52,7 @@ int main(void) {
   if (__builtin_cpu_supports("sve2-pmull128+memtag"))
 return 2;
 
-  if (__builtin_cpu_supports("sme2+ls64_v+wfxt"))
+  if (__builtin_cpu_supports("sme2+ls64+wfxt"))
 return 3;
 
   if (__builtin_cpu_supports("avx2"))
diff --git a/clang/test/CodeGen/aarch64-fmv-dependencies.c 
b/clang/test/CodeGen/aarch64-fmv-dependencies.c
index e39c7adbe4a9b0..f2eec11baed379 100644
--- a/clang/test/CodeGen/aarch64-fmv-dependencies.c
+++ b/clang/test/CodeGen/aarch64-fmv-dependencies.c
@@ -66,15 +66,9 @@ __attribute__((target_version("i8mm"))) int fmv(void) { 
return 0; }
 // CHECK: define dso_local i32 @fmv._Mjscvt() #[[jscvt:[0-9]+]] {
 __attribute__((target_version("jscvt"))) int fmv(void) { return 0; }
 
-// CHECK: define dso_local i32 @fmv._Mls64() #[[ATTR0:[0-9]+]] {
+// CHECK: define dso_local i32 @fmv._Mls64() #[[ls64:[0-9]+]] {
 __attribute__((target_version("ls64"))) int fmv(void) { return 0; }
 
-// CHECK: define dso_local i32 @fmv._Mls64_accdata() #[[ls64_accdata:[0-9]+]] {
-__attribute__((target_version("ls64_accdata"))) int fmv(void) { return 0; }
-
-// CHECK: define dso_local i32 @fmv._Mls64_v() #[[ATTR0:[0-9]+]] {
-__attribute__((target_version("ls64_v"))) int fmv(void) { return 0; }
-
 // CHECK: define dso_local i32 @fmv._Mlse() #[[lse:[0-9]+]] {
 __attribute__((target_version("lse"))) int fmv(void) { return 0; }
 
@@ -210,7 +204,7 @@ int caller() {
 // CHECK: attributes #[[frintts]] = { {{.*}} 
"target-features"="+fp-armv8,+fptoint,+neon,+outline-atomics,+v8a"
 // CHECK: attributes #[[i8mm]] = { {{.*}} 
"target-features"="+fp-armv8,+i8mm,+neon,+outline-atomics,+v8a"
 // CHECK: attributes #[[jscvt]] = { {{.*}} 
"target-features"="+fp-armv8,+jsconv,+neon,+outline-atomics,+v8a"
-// CHECK: attributes #[[ls64_accdata]] = { {{.*}} 
"target-features"="+fp-armv8,+ls64,+neon,+outline-atomics,+v8a"
+// CHECK: attributes #[[ls64]] = { {{.*}} 
"target-features"="+fp-armv8,+ls64,+neon,+outline-atomics,+v8a"
 // CHECK: attributes #[[lse]] = { {{.*}} 
"target-features"="+fp-armv8,+lse,+neon,+outline-atomics,+v8a"
 // CHECK: attributes #[[memtag2]] = { {{.*}} 
"target-features"="+fp-armv8,+mte,+neon,+outline-atomics,+v8a"
 // CHECK: attributes #[[mops]] = { {{.*}} 
"target-features"="+fp-armv8,+mops,+neon,+outline-atomics,+v8a"
diff --git a/clang/test/CodeGen/attr-target-clones-aarch64.c 
b/clang/test/CodeGen/attr-target-clones-aarch64.c
index 274e05de594b8e..c79b1e0714a00d 100644
--- a/clang/test/CodeGen/attr-target-clones-aarch64.c
+++ b/clang/test/CodeGen/attr-target-clones-aarch64.c
@@ -336,8 +336,8 @@

[clang-tools-extra] [Docs][clang-tidy] disclose Windows linetab bug on clang-query tab auto-complete (PR #107956)

2024-09-10 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman edited 
https://github.com/llvm/llvm-project/pull/107956
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [Docs][clang-tidy] disclose Windows linetab bug on clang-query tab auto-complete (PR #107956)

2024-09-10 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for the improvements!

https://github.com/llvm/llvm-project/pull/107956
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [Docs][clang-tidy] disclose Windows linetab bug on clang-query tab auto-complete (PR #107956)

2024-09-10 Thread Aaron Ballman via cfe-commits


@@ -346,13 +346,13 @@ matching expressions to simplify your matcher.
 
 Alternatively, pressing the tab key after a previous matcher's open 
parentheses would also 
 show which matchers can be chained with the previous matcher, though some 
matchers that work 
-may not be listed.
+may not be listed. Note that this suggestion feature currently does not work 
on Windows.
 
 Just like breaking up a huge function into smaller chunks with 
intention-revealing names 
 can help you understand a complex algorithm, breaking up a matcher into 
smaller matchers 
 with intention-revealing names can help you understand a complicated matcher.  
 
-Once you have a working clang-query matcher, the C++ API matchers will be the 
same or similar 
+Once you have a working :program:`clang-query` matcher, the C++ API matchers 
will be the same or similar 

AaronBallman wrote:

Can you re-wrap this to 80-columns?

https://github.com/llvm/llvm-project/pull/107956
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [Docs][clang-tidy] disclose Windows linetab bug on clang-query tab auto-complete (PR #107956)

2024-09-10 Thread Aaron Ballman via cfe-commits


@@ -346,13 +346,13 @@ matching expressions to simplify your matcher.
 
 Alternatively, pressing the tab key after a previous matcher's open 
parentheses would also 
 show which matchers can be chained with the previous matcher, though some 
matchers that work 
-may not be listed.
+may not be listed. Note that this suggestion feature currently does not work 
on Windows.

AaronBallman wrote:

```suggestion
may not be listed. Note that tab completion does not currently work on Windows.
```

https://github.com/llvm/llvm-project/pull/107956
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC] Move warning from CodeGen to Sema. (PR #107397)

2024-09-10 Thread Aaron Ballman via cfe-commits


@@ -6784,6 +6784,10 @@ def warn_arc_lifetime_result_type : Warning<
   "ARC %select{unused|__unsafe_unretained|__strong|__weak|__autoreleasing}0 "
   "lifetime qualifier on return type is ignored">,
   InGroup;
+def warn_next_larger_fp_type_same_size_than_fp : Warning<
+  "higher precision floating-point type requested by user size has the same 
size"

AaronBallman wrote:

Could we diagnose from the driver or when we see a pragma requesting the 
higher-precision type? That would also reduce the chattiness of the diagnostic, 
I expect.

https://github.com/llvm/llvm-project/pull/107397
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5dd1c82 - [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility to AMDGPU. (#107997)

2024-09-10 Thread via cfe-commits

Author: Amit Kumar Pandey
Date: 2024-09-10T19:11:51+05:30
New Revision: 5dd1c82778f418b3de832dc4af3cf5449f2f18ed

URL: 
https://github.com/llvm/llvm-project/commit/5dd1c82778f418b3de832dc4af3cf5449f2f18ed
DIFF: 
https://github.com/llvm/llvm-project/commit/5dd1c82778f418b3de832dc4af3cf5449f2f18ed.diff

LOG: [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility to AMDGPU. 
(#107997)

HIPAMDToolChain and AMDGPUOpenMPToolChain both depends on the
"shouldSkipSanitizeOption" api to sanitize/not sanitize device code.

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/AMDGPU.h
clang/lib/Driver/ToolChains/HIPAMD.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index a788aba57546c8..74f70573c5feb8 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -1054,3 +1054,39 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList &DriverArgs,
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
 }
+
+bool AMDGPUToolChain::shouldSkipSanitizeOption(
+const ToolChain &TC, const llvm::opt::ArgList &DriverArgs,
+StringRef TargetID, const llvm::opt::Arg *A) const {
+  // For actions without targetID, do nothing.
+  if (TargetID.empty())
+return false;
+  Option O = A->getOption();
+  if (!O.matches(options::OPT_fsanitize_EQ))
+return false;
+
+  if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
+  options::OPT_fno_gpu_sanitize, true))
+return true;
+
+  auto &Diags = TC.getDriver().getDiags();
+
+  // For simplicity, we only allow -fsanitize=address
+  SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
+  if (K != SanitizerKind::Address)
+return true;
+
+  llvm::StringMap FeatureMap;
+  auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
+
+  assert(OptionalGpuArch && "Invalid Target ID");
+  (void)OptionalGpuArch;
+  auto Loc = FeatureMap.find("xnack");
+  if (Loc == FeatureMap.end() || !Loc->second) {
+Diags.Report(
+clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
+<< A->getAsString(DriverArgs) << TargetID << "xnack+";
+return true;
+  }
+  return false;
+}
\ No newline at end of file

diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.h 
b/clang/lib/Driver/ToolChains/AMDGPU.h
index 7e70dae8ce152e..a9b4552a1f91a4 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -97,6 +97,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public 
Generic_ELF {
   /// Needed for translating LTO options.
   const char *getDefaultLinker() const override { return "ld.lld"; }
 
+  /// Should skip sanitize options.
+  bool shouldSkipSanitizeOption(const ToolChain &TC,
+const llvm::opt::ArgList &DriverArgs,
+StringRef TargetID,
+const llvm::opt::Arg *A) const;
+
   /// Uses amdgpu-arch tool to get arch of the system GPU. Will return error
   /// if unable to find one.
   virtual Expected>

diff  --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index cbb8fab69a316d..bae05cc0bb7353 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -36,43 +36,6 @@ using namespace llvm::opt;
 #define NULL_FILE "/dev/null"
 #endif
 
-static bool shouldSkipSanitizeOption(const ToolChain &TC,
- const llvm::opt::ArgList &DriverArgs,
- StringRef TargetID,
- const llvm::opt::Arg *A) {
-  // For actions without targetID, do nothing.
-  if (TargetID.empty())
-return false;
-  Option O = A->getOption();
-  if (!O.matches(options::OPT_fsanitize_EQ))
-return false;
-
-  if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
-  options::OPT_fno_gpu_sanitize, true))
-return true;
-
-  auto &Diags = TC.getDriver().getDiags();
-
-  // For simplicity, we only allow -fsanitize=address
-  SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
-  if (K != SanitizerKind::Address)
-return true;
-
-  llvm::StringMap FeatureMap;
-  auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
-
-  assert(OptionalGpuArch && "Invalid Target ID");
-  (void)OptionalGpuArch;
-  auto Loc = FeatureMap.find("xnack");
-  if (Loc == FeatureMap.end() || !Loc->second) {
-Diags.Report(
-clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
-<< A->getAsString(DriverArgs) << TargetID << "xnack+";
-return true;
-  }
-  return false;
-}
-
 void AMDGCN::Linker::constructLlvmLinkC

[clang] [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility to AMDGPU. (PR #107997)

2024-09-10 Thread Amit Kumar Pandey via cfe-commits

https://github.com/ampandey-1995 closed 
https://github.com/llvm/llvm-project/pull/107997
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clangd] show lambda name instead of operator() in signature help (PR #101857)

2024-09-10 Thread Erich Keane via cfe-commits


@@ -876,6 +876,11 @@ class Sema;
 /// function pointer or reference (C++ [over.call.object]).
 FunctionDecl *Function;
 
+/// LambdaName - When the OverloadCandidate is for a
+/// lambda's operator(), points to the declaration of
+/// the lambda variable.
+VarDecl *LambdaName{nullptr};

erichkeane wrote:

Yep, exactly.  In the instantiation of 'bar', the various calls to the 'Ls'.  
Also, I was more concerned at one point because i thought this affected 
diagnostics, but I don't see code that does that anymore.

https://github.com/llvm/llvm-project/pull/101857
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][TableGen] Migrate clang-tblgen to use const RecordKeeper (PR #107533)

2024-09-10 Thread Rahul Joshi via cfe-commits

jurahul wrote:

@AaronBallman can you please help find appropriate folks to review this PR?

https://github.com/llvm/llvm-project/pull/107533
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Allow truncation to scalar (PR #104844)

2024-09-10 Thread Chris B via cfe-commits

https://github.com/llvm-beanz updated 
https://github.com/llvm/llvm-project/pull/104844

>From 1a1a92aff834aa2f6f12d3de001714d8338dd274 Mon Sep 17 00:00:00 2001
From: Chris Bieneman 
Date: Tue, 13 Aug 2024 15:51:34 -0500
Subject: [PATCH 1/4] [HLSL] Allow truncation to scalar

HLSL allows implicit conversions to truncate vectors to scalar
pr-values. These conversions are scored as vector truncations and
should warn appropriately.

This change allows forming a truncation cast to a pr-value, but not an
l-value. Truncating a vector to a scalar is performed by loading the
first element of the vector and disregarding the remaining elements.

Fixes #102964
---
 clang/lib/CodeGen/CGExprScalar.cpp| 17 ---
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  5 +-
 clang/lib/Sema/SemaExprCXX.cpp| 49 ++
 clang/lib/Sema/SemaOverload.cpp   | 50 ---
 .../standard_conversion_sequences.hlsl| 24 +
 clang/test/CodeGenHLSL/builtins/dot.hlsl  | 16 --
 clang/test/CodeGenHLSL/builtins/lerp.hlsl | 21 
 clang/test/CodeGenHLSL/builtins/mad.hlsl  | 18 ---
 .../TruncationOverloadResolution.hlsl | 42 ++--
 .../BuiltinVector/ScalarSwizzleErrors.hlsl|  6 ++-
 10 files changed, 141 insertions(+), 107 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 84392745ea6144..2ccdb840579a98 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2692,14 +2692,19 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 return CGF.CGM.createOpenCLIntToSamplerConversion(E, CGF);
 
   case CK_HLSLVectorTruncation: {
-assert(DestTy->isVectorType() && "Expected dest type to be vector type");
+assert((DestTy->isVectorType() || DestTy->isBuiltinType()) &&
+   "Destination type must be a vector or builtin type.");
 Value *Vec = Visit(const_cast(E));
-SmallVector Mask;
-unsigned NumElts = DestTy->castAs()->getNumElements();
-for (unsigned I = 0; I != NumElts; ++I)
-  Mask.push_back(I);
+if (auto *VecTy = DestTy->getAs()) {
+  SmallVector Mask;
+  unsigned NumElts = VecTy->getNumElements();
+  for (unsigned I = 0; I != NumElts; ++I)
+Mask.push_back(I);
 
-return Builder.CreateShuffleVector(Vec, Mask, "trunc");
+  return Builder.CreateShuffleVector(Vec, Mask, "trunc");
+}
+llvm::Value *Zero = llvm::Constant::getNullValue(CGF.SizeTy);
+return Builder.CreateExtractElement(Vec, Zero, "cast.vtrunc");
   }
 
   } // end of switch
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 678cdc77f8a71b..be65e149515b9f 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -673,9 +673,6 @@ float dot(float3, float3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
 float dot(float4, float4);
 
-_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
-double dot(double, double);
-
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
 int dot(int, int);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
@@ -916,7 +913,7 @@ float4 lerp(float4, float4, float4);
 /// \brief Returns the length of the specified floating-point vector.
 /// \param x [in] The vector of floats, or a scalar float.
 ///
-/// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + �).
+/// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).
 
 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 5356bcf172f752..e62e3bcbead3be 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4301,8 +4301,10 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
 // from type to the elements of the to type without resizing the vector.
 static QualType adjustVectorType(ASTContext &Context, QualType FromTy,
  QualType ToType, QualType *ElTy = nullptr) {
-  auto *ToVec = ToType->castAs();
-  QualType ElType = ToVec->getElementType();
+  QualType ElType = ToType;
+  if (auto *ToVec = ToType->getAs())
+ElType = ToVec->getElementType();
+
   if (ElTy)
 *ElTy = ElType;
   if (!FromTy->isVectorType())
@@ -4463,7 +4465,7 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   case ICK_Integral_Conversion: {
 QualType ElTy = ToType;
 QualType StepTy = ToType;
-if (ToType->isVectorType())
+if (FromType->isVectorType() || ToType->isVectorType())
   StepTy = adjustVectorType(Context, FromType, ToType, &ElTy);
 if (ElTy->isBooleanType()) {
   assert(FromType->castAs()->getDecl()->isFixed() &&
@@ -4483,7 +4485,7 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   case ICK_Floating_Promotion:
   case ICK_Floating_Conversion: {
 QualType StepTy = ToType;
-if (ToType->isVectorType

[clang] [HLSL] Allow truncation to scalar (PR #104844)

2024-09-10 Thread Chris B via cfe-commits

llvm-beanz wrote:

> ExprConstant.cpp currently assumes that an CK_HLSLVectorTruncation can't 
> return a scalar type.

Thank you for catching this! I've updated the PR and included a test that 
constant evaluates some vector truncations in static asserts.

https://github.com/llvm/llvm-project/pull/104844
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Introduce FunctionParmPackDecl for expanded lambda captures (PR #107995)

2024-09-10 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

This seems reasonable to me, and the code itself is fine.  I wouldn't mind a 
few of the others getting a chance to make a comment on it, and for me myself 
to consider the implications of it.  So this just needs time to bake in my head.

https://github.com/llvm/llvm-project/pull/107995
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-10 Thread via cfe-commits


@@ -127,57 +138,159 @@ static bool isAnnexKAvailable(std::optional 
&CacheVar, Preprocessor *PP,
   return CacheVar.value();
 }
 
+static std::vector
+parseCheckedFunctions(StringRef Option, StringRef OptionName,
+  ClangTidyContext *Context) {
+  std::vector Functions = utils::options::parseStringList(Option);

EugeneZelenko wrote:

```suggestion
  const std::vector Functions = 
utils::options::parseStringList(Option);
```

https://github.com/llvm/llvm-project/pull/106350
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC] Move warning from CodeGen to Sema. (PR #107397)

2024-09-10 Thread Zahira Ammarguellat via cfe-commits


@@ -6784,6 +6784,10 @@ def warn_arc_lifetime_result_type : Warning<
   "ARC %select{unused|__unsafe_unretained|__strong|__weak|__autoreleasing}0 "
   "lifetime qualifier on return type is ignored">,
   InGroup;
+def warn_next_larger_fp_type_same_size_than_fp : Warning<
+  "higher precision floating-point type requested by user size has the same 
size"

zahiraam wrote:

This warning should trigger only for a division. When an 
`-fcomplex-arithmetic=promoted` is met, we don't have that knowledge. 

https://github.com/llvm/llvm-project/pull/107397
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RFC][BPF] Do atomic_fetch_*() pattern matching with memory ordering (PR #107343)

2024-09-10 Thread via cfe-commits


@@ -152,22 +152,91 @@ static bool hasLiveDefs(const MachineInstr &MI, const 
TargetRegisterInfo *TRI) {
   return false;
 }
 
-void BPFMIPreEmitChecking::processAtomicInsts() {
+bool BPFMIPreEmitChecking::processAtomicInsts() {
+  if (!MF->getSubtarget().getHasJmp32()) {
+// Only check for cpu version 1 and 2.
+for (MachineBasicBlock &MBB : *MF) {
+  for (MachineInstr &MI : MBB) {
+if (MI.getOpcode() != BPF::XADDW && MI.getOpcode() != BPF::XADDD)
+  continue;
+
+LLVM_DEBUG(MI.dump());
+if (hasLiveDefs(MI, TRI)) {
+  DebugLoc Empty;
+  const DebugLoc &DL = MI.getDebugLoc();
+  const Function &F = MF->getFunction();
+  F.getContext().diagnose(DiagnosticInfoUnsupported{
+  F, "Invalid usage of the XADD return value", DL});
+}
+  }
+}
+  }
+
+  // Check return values of atomic_fetch_and_{add,and,or,xor}.
+  // If the return is not used, the atomic_fetch_and_ instruction
+  // is replaced with atomic_ instruction.
+  MachineInstr *ToErase = nullptr;
+  bool Changed = false;
+  const BPFInstrInfo *TII = MF->getSubtarget().getInstrInfo();
   for (MachineBasicBlock &MBB : *MF) {
 for (MachineInstr &MI : MBB) {
-  if (MI.getOpcode() != BPF::XADDW && MI.getOpcode() != BPF::XADDD)
+  if (ToErase) {

yonghong-song wrote:

Will add a comment.
For
> Also, won't delete the last instruction in the basic block, would this be a 
> problem if instruction is used in a later basic block?
I think we should be okay since register definition is preserved. But let me 
double check.

https://github.com/llvm/llvm-project/pull/107343
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   >