[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-11-22 Thread Chris Copeland via cfe-commits


@@ -16,7 +16,7 @@
 
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-flto=thin -c -o %t.call_thin.bc -DCALL_LIB
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-flto=thin -c -o %t.define_thin.bc -DDEFINE_LIB
-// RUN: llvm-lto2 run -o %t.lto_thin -save-temps %t.call_thin.bc 
%t.define_thin.bc \
+// RUN: llvm-lto2 run --mcpu=cortex-m33 --float-abi=hard -o %t.lto_thin 
-save-temps %t.call_thin.bc %t.define_thin.bc \

chrisnc wrote:

I dug into this further as promised, and the error goes away for this test if 
you just remove the call to `printf` from the test, which the test expects to 
replace with a call to putchar. This means that the `llvm-lto2` invocation is 
eventually creating a new subtarget in which the target features and ABI are 
not inherited from the settings of either input file, and because the ones it 
lands on are incompatible, an error is raised. Pre-existing functions that were 
generated with a specific ABI and features are preserved as you would expect.

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


[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-11-22 Thread Chris Copeland via cfe-commits

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


[clang] [llvm] [IR] Add TargetExtType::CanBeLocal property (PR #99016)

2024-11-22 Thread Jay Foad via cfe-commits


@@ -838,12 +838,14 @@ static TargetTypeInfo getTargetTypeInfo(const 
TargetExtType *Ty) {
 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::CanBeGlobal);

jayfoad wrote:

I'm now using the newly added `amdgcn.named.barrier` for testing.

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


[libcxx] [libcxxabi] [libunwind] [llvm] [runtimes] Probe for -nostdlib++ and -nostdinc++ with the C compiler (PR #108357)

2024-11-22 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> > > Actually this PR is the case of 
> > > https://lab.llvm.org/buildbot/#/builders/164/builds/3908, not #113491
> > 
> > 
> > Sorry about that.
> > Are you able to dig up any of the cmake configure logs from these builds, 
> > so that we can figure out how this ends up breaking things? Because as in 
> > most of these cases, the visible output in the buildbot logs mostly say 
> > that some configure checks end up going the wrong way, but we can't really 
> > see why.
> 
> @vitalybuka Are you able to pull out some details to help figure out what 
> this really broke here?

Ping @vitalybuka - can you help out with retrying this PR and providing some 
details about what went wrong, so that we can have a path towards merging this 
again?

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


[clang] 294c5cb - [IR] Add TargetExtType::CanBeLocal property (#99016)

2024-11-22 Thread via cfe-commits

Author: Jay Foad
Date: 2024-11-22T10:02:43Z
New Revision: 294c5cb2bea88fa048e00757188749f074c5b09f

URL: 
https://github.com/llvm/llvm-project/commit/294c5cb2bea88fa048e00757188749f074c5b09f
DIFF: 
https://github.com/llvm/llvm-project/commit/294c5cb2bea88fa048e00757188749f074c5b09f.diff

LOG: [IR] Add TargetExtType::CanBeLocal property (#99016)

Add a property to allow marking target extension types that cannot be
used in an alloca instruction or byval argument, similar to CanBeGlobal
for global variables.

-

Co-authored-by: Nikita Popov 

Added: 


Modified: 
clang/test/CodeGen/amdgpu-barrier-type-debug-info.c
llvm/include/llvm/IR/DerivedTypes.h
llvm/include/llvm/IR/Type.h
llvm/lib/IR/Type.cpp
llvm/lib/IR/Verifier.cpp
llvm/test/Assembler/target-type-properties.ll

Removed: 




diff  --git a/clang/test/CodeGen/amdgpu-barrier-type-debug-info.c 
b/clang/test/CodeGen/amdgpu-barrier-type-debug-info.c
index f595f1b222c4f6..4eafbba0ad9a0e 100644
--- a/clang/test/CodeGen/amdgpu-barrier-type-debug-info.c
+++ b/clang/test/CodeGen/amdgpu-barrier-type-debug-info.c
@@ -4,5 +4,5 @@
 // CHECK: name: "__amdgpu_named_workgroup_barrier_t",{{.*}}baseType: 
![[BT:[0-9]+]]
 // CHECK: [[BT]] = !DIBasicType(name: "__amdgpu_named_workgroup_barrier_t", 
size: 128, encoding: DW_ATE_unsigned)
 void test_locals(void) {
-  __amdgpu_named_workgroup_barrier_t k0;
+  __amdgpu_named_workgroup_barrier_t *k0;
 }

diff  --git a/llvm/include/llvm/IR/DerivedTypes.h 
b/llvm/include/llvm/IR/DerivedTypes.h
index 65f9810776024e..b44f4f8c8687dc 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -228,6 +228,8 @@ class StructType : public Type {
 SCDB_NotContainsScalableVector = 32,
 SCDB_ContainsNonGlobalTargetExtType = 64,
 SCDB_NotContainsNonGlobalTargetExtType = 128,
+SCDB_ContainsNonLocalTargetExtType = 64,
+SCDB_NotContainsNonLocalTargetExtType = 128,
   };
 
   /// For a named struct that actually has a name, this is a pointer to the
@@ -302,6 +304,12 @@ class StructType : public Type {
   containsNonGlobalTargetExtType(SmallPtrSetImpl &Visited) const;
   using Type::containsNonGlobalTargetExtType;
 
+  /// Return true if this type is or contains a target extension type that
+  /// disallows being used as a local.
+  bool
+  containsNonLocalTargetExtType(SmallPtrSetImpl &Visited) const;
+  using Type::containsNonLocalTargetExtType;
+
   /// Returns true if this struct contains homogeneous scalable vector types.
   /// Note that the definition of homogeneous scalable vector type is not
   /// recursive here. That means the following structure will return false
@@ -798,6 +806,9 @@ class TargetExtType : public Type {
 HasZeroInit = 1U << 0,
 /// This type may be used as the value type of a global variable.
 CanBeGlobal = 1U << 1,
+/// This type may be allocated on the stack, either as the allocated type
+/// of an alloca instruction or as a byval function parameter.
+CanBeLocal = 1U << 2,
   };
 
   /// Returns true if the target extension type contains the given property.

diff  --git a/llvm/include/llvm/IR/Type.h b/llvm/include/llvm/IR/Type.h
index 000fdee45bb861..6dadf158a739fc 100644
--- a/llvm/include/llvm/IR/Type.h
+++ b/llvm/include/llvm/IR/Type.h
@@ -215,6 +215,12 @@ class Type {
   containsNonGlobalTargetExtType(SmallPtrSetImpl &Visited) const;
   bool containsNonGlobalTargetExtType() const;
 
+  /// Return true if this type is or contains a target extension type that
+  /// disallows being used as a local.
+  bool
+  containsNonLocalTargetExtType(SmallPtrSetImpl &Visited) const;
+  bool containsNonLocalTargetExtType() const;
+
   /// Return true if this is a FP type or a vector of FP.
   bool isFPOrFPVectorTy() const { return getScalarType()->isFloatingPointTy(); 
}
 

diff  --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 75f4751ea4f148..ac6b8b4c197002 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -88,6 +88,22 @@ bool Type::containsNonGlobalTargetExtType() const {
   return containsNonGlobalTargetExtType(Visited);
 }
 
+bool Type::containsNonLocalTargetExtType(
+SmallPtrSetImpl &Visited) const {
+  if (const auto *ATy = dyn_cast(this))
+return ATy->getElementType()->containsNonLocalTargetExtType(Visited);
+  if (const auto *STy = dyn_cast(this))
+return STy->containsNonLocalTargetExtType(Visited);
+  if (auto *TT = dyn_cast(this))
+return !TT->hasProperty(TargetExtType::CanBeLocal);
+  return false;
+}
+
+bool Type::containsNonLocalTargetExtType() const {
+  SmallPtrSet Visited;
+  return containsNonLocalTargetExtType(Visited);
+}
+
 const fltSemantics &Type::getFltSemantics() const {
   switch (getTypeID()) {
   case HalfTyID: return APFloat::IEEEhalf();
@@ -469,6 +485,34 @@ bool StructType::containsNonGlobalTargetExtType(
   return false;
 }
 
+bool StructType::containsNonLocalTargetE

[clang] [llvm] [IR] Add TargetExtType::CanBeLocal property (PR #99016)

2024-11-22 Thread Jay Foad via cfe-commits

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


[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)

2024-11-22 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building 
`clang,llvm` at step 10 "Add check check-offload".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/73/builds/8976


Here is the relevant piece of the build log for the reference

```
Step 10 (Add check check-offload) failure: 1200 seconds without output running 
[b'ninja', b'-j 32', b'check-offload'], attempting to kill
...
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug53727.cpp 
(947 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug47654.cpp 
(948 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49779.cpp 
(949 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/test_libc.cpp 
(950 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/wtime.c (951 
of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: offloading/bug49021.cpp (952 
of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: 
offloading/std_complex_arithmetic.cpp (953 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: 
offloading/complex_reduction.cpp (954 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49021.cpp 
(955 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: 
offloading/std_complex_arithmetic.cpp (956 of 960)
command timed out: 1200 seconds without output running [b'ninja', b'-j 32', 
b'check-offload'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1238.823334

```



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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Gábor Horváth via cfe-commits

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Gábor Horváth via cfe-commits


@@ -7,3 +7,106 @@ struct S {
 };
 
 // CHECK: CXXMethodDecl {{.*}}clang::lifetime_capture_by(a, b, global)
+
+// 
+// Infer annotation for STL container methods.
+// 
+namespace __gnu_cxx {
+template 
+struct basic_iterator {};
+}
+
+namespace std {
+template class allocator {};
+template >
+struct vector {
+  typedef __gnu_cxx::basic_iterator iterator;
+  iterator begin();
+
+  vector();
+
+  void push_back(const T&);
+  void push_back(T&&);
+
+  void insert(iterator, T&&);
+};
+} // namespace std
+struct [[gsl::Pointer()]] View {};
+std::vector views;
+// CHECK:   ClassTemplateSpecializationDecl {{.*}} struct vector definition 
implicit_instantiation
+// CHECK:   TemplateArgument type 'View'
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (const View &)'
+// CHECK:   ParmVarDecl {{.*}} 'const View &'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (View &&)'
+// CHECK:   ParmVarDecl {{.*}} 'View &&'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+
+// CHECK:   CXXMethodDecl {{.*}} insert 'void (iterator, View &&)'
+// CHECK:   ParmVarDecl {{.*}} 'iterator'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK:   ParmVarDecl {{.*}} 'View &&'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+template  struct [[gsl::Pointer()]] ViewTemplate {};
+std::vector> templated_views;
+// CHECK:   ClassTemplateSpecializationDecl {{.*}} struct vector definition 
implicit_instantiation
+// CHECK:   TemplateArgument type 'ViewTemplate'
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (const ViewTemplate 
&)'
+// CHECK:   ParmVarDecl {{.*}} 'const ViewTemplate &'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (ViewTemplate &&)'
+// CHECK:   ParmVarDecl {{.*}} 'ViewTemplate &&'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+
+// CHECK:   CXXMethodDecl {{.*}} insert 'void (iterator, ViewTemplate 
&&)'
+// CHECK:   ParmVarDecl {{.*}} 'iterator'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK:   ParmVarDecl {{.*}} 'ViewTemplate &&'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+std::vector pointers;
+// CHECK:   ClassTemplateSpecializationDecl {{.*}} struct vector definition 
implicit_instantiation
+// CHECK:   TemplateArgument type 'int *'
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (int *const &)'
+// CHECK:   ParmVarDecl {{.*}} 'int *const &'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (int *&&)'
+// CHECK:   ParmVarDecl {{.*}} 'int *&&'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+
+// CHECK:   CXXMethodDecl {{.*}} insert 'void (iterator, int *&&)'
+// CHECK:   ParmVarDecl {{.*}} 'iterator'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK:   ParmVarDecl {{.*}} 'int *&&'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+std::vector ints;
+// CHECK:   ClassTemplateSpecializationDecl {{.*}} struct vector definition 
implicit_instantiation
+// CHECK:   TemplateArgument type 'int'
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (const int &)'
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (int &&)'
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} insert 'void (iterator, int &&)'
+// CHECK:   ParmVarDecl {{.*}} 'iterator'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr

Xazax-hun wrote:

 Nit: missing new line

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits


@@ -268,6 +268,40 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
   }
 }
 
+static bool IsPointerLikeType(QualType QT) {
+  QT = QT.getNonReferenceType();
+  if (QT->isPointerType())
+return true;
+  auto *RD = QT->getAsCXXRecordDecl();
+  if (!RD)
+return false;
+  RD = RD->getCanonicalDecl();
+  if (auto *CTSD = dyn_cast(RD))
+RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();

usx95 wrote:

> Should we do the same thing for the one in CheckExprLifetime.cpp?
Makes a lot of sense. Let me do this separately in parallel though.

That said, your example still doesn't work show the warning with the lines 
removed:
```cpp
   if (auto *CTSD = dyn_cast(RD))
 RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
```

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.

Once @hokein's comments are addressed, it looks good to me. 

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


[clang] [clang] Check specialization for annotation (PR #117315)

2024-11-22 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 created 
https://github.com/llvm/llvm-project/pull/117315

None

>From e30ae8a6e0c1df8e33c2add6502342cb269c1cfd Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Fri, 22 Nov 2024 11:02:49 +
Subject: [PATCH] [clang] Check specialization for annotation

---
 clang/lib/Sema/CheckExprLifetime.cpp | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 8886e5e307ddf8..64dc4794b6235a 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -253,9 +253,12 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path,
   LocalVisitor Visit);
 
 template  static bool isRecordWithAttr(QualType Type) {
-  if (auto *RD = Type->getAsCXXRecordDecl())
-return RD->hasAttr();
-  return false;
+  auto *RD = Type->getAsCXXRecordDecl();
+  if (!RD)
+return false;
+  if (auto *CTSD = dyn_cast(RD))
+RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
+  return RD->hasAttr();
 }
 
 // Decl::isInStdNamespace will return false for iterators in some STL

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


[clang] [clang] Check specialization for annotation (PR #117315)

2024-11-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Utkarsh Saxena (usx95)


Changes



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


1 Files Affected:

- (modified) clang/lib/Sema/CheckExprLifetime.cpp (+6-3) 


``diff
diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 8886e5e307ddf8..64dc4794b6235a 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -253,9 +253,12 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path,
   LocalVisitor Visit);
 
 template  static bool isRecordWithAttr(QualType Type) {
-  if (auto *RD = Type->getAsCXXRecordDecl())
-return RD->hasAttr();
-  return false;
+  auto *RD = Type->getAsCXXRecordDecl();
+  if (!RD)
+return false;
+  if (auto *CTSD = dyn_cast(RD))
+RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
+  return RD->hasAttr();
 }
 
 // Decl::isInStdNamespace will return false for iterators in some STL

``




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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/117122

>From 9a57223b06a8331a0ef123739a430863dee19d98 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 21 Nov 2024 07:00:56 +
Subject: [PATCH 1/3] [clang] Infer lifetime_capture_by for STL containers

---
 clang/include/clang/Sema/Sema.h   |  3 +
 clang/lib/Sema/SemaAttr.cpp   | 34 
 clang/lib/Sema/SemaDecl.cpp   |  2 +
 clang/test/Sema/Inputs/lifetime-analysis.h|  5 ++
 .../warn-lifetime-analysis-capture-by.cpp | 79 +++
 5 files changed, 123 insertions(+)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6ea6c67447b6f0..9bafcfec5d4786 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1757,6 +1757,9 @@ class Sema final : public SemaBase {
   /// Add [[clang:::lifetimebound]] attr for std:: functions and methods.
   void inferLifetimeBoundAttribute(FunctionDecl *FD);
 
+  /// Add [[clang:::lifetime_capture(this)]] to STL container methods.
+  void inferLifetimeCaptureByAttribute(FunctionDecl *FD);
+
   /// Add [[gsl::Pointer]] attributes for std:: types.
   void inferGslPointerAttribute(TypedefNameDecl *TD);
 
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 9fbad7ed67ccbe..507f7c40d58782 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -268,6 +268,40 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
   }
 }
 
+static bool IsPointerLikeType(QualType QT) {
+  QT = QT.getNonReferenceType();
+  if (QT->isPointerType())
+return true;
+  auto *RD = QT->getAsCXXRecordDecl();
+  if (!RD)
+return false;
+  RD = RD->getCanonicalDecl();
+  if (auto *CTSD = dyn_cast(RD))
+RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
+  return RD->hasAttr();
+}
+
+void Sema::inferLifetimeCaptureByAttribute(FunctionDecl *FD) {
+  if (!FD)
+return;
+  auto *MD = dyn_cast(FD);
+  if (!MD || !MD->getIdentifier() || !MD->getParent()->isInStdNamespace())
+return;
+  static const llvm::StringSet<> CapturingMethods{"insert", "push",
+  "push_front", "push_back"};
+  if (!CapturingMethods.contains(MD->getName()))
+return;
+  for (ParmVarDecl *PVD : MD->parameters()) {
+if (PVD->hasAttr())
+  return;
+if (IsPointerLikeType(PVD->getType())) {
+  int CaptureByThis[] = {LifetimeCaptureByAttr::THIS};
+  PVD->addAttr(
+  LifetimeCaptureByAttr::CreateImplicit(Context, CaptureByThis, 1));
+}
+  }
+}
+
 void Sema::inferNullableClassAttribute(CXXRecordDecl *CRD) {
   static const llvm::StringSet<> Nullable{
   "auto_ptr", "shared_ptr", "unique_ptr", "exception_ptr",
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index be570f3a1829d0..5b30d0f2c22d16 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11913,6 +11913,7 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   NamedDecl *OldDecl = nullptr;
   bool MayNeedOverloadableChecks = false;
 
+  inferLifetimeCaptureByAttribute(NewFD);
   // Merge or overload the declaration with an existing declaration of
   // the same name, if appropriate.
   if (!Previous.empty()) {
@@ -16716,6 +16717,7 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) 
{
 
   LazyProcessLifetimeCaptureByParams(FD);
   inferLifetimeBoundAttribute(FD);
+  inferLifetimeCaptureByAttribute(FD);
   AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction(FD);
 
   // If C++ exceptions are enabled but we are told extern "C" functions cannot
diff --git a/clang/test/Sema/Inputs/lifetime-analysis.h 
b/clang/test/Sema/Inputs/lifetime-analysis.h
index 41d1e2f074cc83..5c151385b1fe5a 100644
--- a/clang/test/Sema/Inputs/lifetime-analysis.h
+++ b/clang/test/Sema/Inputs/lifetime-analysis.h
@@ -49,6 +49,11 @@ struct vector {
vector(InputIterator first, InputIterator __last);
 
   T &at(int n);
+
+  void push_back(const T&);
+  void push_back(T&&);
+  
+  void insert(iterator, T&&);
 };
 
 template
diff --git a/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp 
b/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp
index b3fde386b8616c..462cb2d3f3fd6e 100644
--- a/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp
+++ b/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp
@@ -366,3 +366,82 @@ void use() {
   capture3(std::string(), x3); // expected-warning {{object whose reference is 
captured by 'x3' will be destroyed at the end of the full-expression}}
 }
 } // namespace temporary_views
+
+// 
+// Inferring annotation for STL containers
+// 
+namespace inferred_capture_by {
+const std::string* getLifetimeBoundPointer(const std::string &s 
[[clang::lifetimebound]

[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits


@@ -268,6 +268,40 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
   }
 }
 
+static bool IsPointerLikeType(QualType QT) {
+  QT = QT.getNonReferenceType();
+  if (QT->isPointerType())
+return true;
+  auto *RD = QT->getAsCXXRecordDecl();
+  if (!RD)
+return false;
+  RD = RD->getCanonicalDecl();
+  if (auto *CTSD = dyn_cast(RD))
+RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();

usx95 wrote:

Maybe a better fix would be to propagate this change to the template 
specialization in clang.

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang] Warn const integer-overflow of member in temporary struct bound to rvalue reference (PR #117225)

2024-11-22 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/117225

>From 08e1a3388e9d98f2469687d2367472342b05c47e Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Thu, 21 Nov 2024 13:05:20 -0600
Subject: [PATCH 1/2] [clang] Warn const integer-overflow of member in
 temporary struct bound to rvalue reference

Fixes #46755
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/lib/Sema/SemaChecking.cpp | 3 ++-
 clang/test/SemaCXX/integer-overflow.cpp | 6 ++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8c81de341937ca..8820ba0fb24b38 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -578,6 +578,9 @@ Improvements to Clang's diagnostics
 
 - Clang now omits shadowing warnings for parameter names in explicit object 
member functions (#GH95707).
 
+- For an rvalue reference bound to a temporary struct with an integer member, 
Clang will detect constant integer overflow
+  in the initializer for the integer member (#GH46755).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2fd990750ed212..e36cb318c61885 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12048,7 +12048,8 @@ void Sema::CheckForIntOverflow (const Expr *E) {
  New && New->isArray()) {
   if (auto ArraySize = New->getArraySize())
 Exprs.push_back(*ArraySize);
-}
+} else if (const auto *Mte = dyn_cast(OriginalE))
+  Exprs.push_back(Mte->getSubExpr());
   } while (!Exprs.empty());
 }
 
diff --git a/clang/test/SemaCXX/integer-overflow.cpp 
b/clang/test/SemaCXX/integer-overflow.cpp
index d1cc8bee566f6b..73a4e88ee6c098 100644
--- a/clang/test/SemaCXX/integer-overflow.cpp
+++ b/clang/test/SemaCXX/integer-overflow.cpp
@@ -246,4 +246,10 @@ int m() {
 return 0;
 }
 }
+
+namespace GH46755 {
+void f() {
+struct { int v; } &&r = {512 * 1024 * 1024 * 1024}; // expected-warning 
{{overflow in expression; result is 0 with type 'int'}}
+}
+}
 #endif

>From 636b14f273fe266651ad933276afb8ab9caf0dfb Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Fri, 22 Nov 2024 04:27:59 -0500
Subject: [PATCH 2/2] Rename var: Mte -> MTE

Co-authored-by: Sirraide 
---
 clang/lib/Sema/SemaChecking.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index e36cb318c61885..a49605e4867651 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12048,8 +12048,8 @@ void Sema::CheckForIntOverflow (const Expr *E) {
  New && New->isArray()) {
   if (auto ArraySize = New->getArraySize())
 Exprs.push_back(*ArraySize);
-} else if (const auto *Mte = dyn_cast(OriginalE))
-  Exprs.push_back(Mte->getSubExpr());
+} else if (const auto *MTE = dyn_cast(OriginalE))
+  Exprs.push_back(MTE->getSubExpr());
   } while (!Exprs.empty());
 }
 

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


[clang] 1d46020 - [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (#116762)

2024-11-22 Thread via cfe-commits

Author: tangaac
Date: 2024-11-22T17:34:15+08:00
New Revision: 1d4602070f96c9a6921d51a3b907f90cd2e3ae32

URL: 
https://github.com/llvm/llvm-project/commit/1d4602070f96c9a6921d51a3b907f90cd2e3ae32
DIFF: 
https://github.com/llvm/llvm-project/commit/1d4602070f96c9a6921d51a3b907f90cd2e3ae32.diff

LOG: [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 
0x700. (#116762)

Two options for clang
-mld-seq-sa: Do not generate load-load barrier instructions (dbar 0x700)
-mno-ld-seq-sa: Generate load-load barrier instructions (dbar 0x700)
The default is -mno-ld-seq-sa

Added: 
clang/test/Driver/loongarch-mld-seq-sa.c

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/LoongArch.cpp
clang/lib/Basic/Targets/LoongArch.h
clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
clang/test/Driver/loongarch-march.c
clang/test/Preprocessor/init-loongarch.c
llvm/include/llvm/TargetParser/LoongArchTargetParser.def
llvm/include/llvm/TargetParser/LoongArchTargetParser.h
llvm/lib/Target/LoongArch/LoongArch.td
llvm/lib/Target/LoongArch/LoongArchExpandAtomicPseudoInsts.cpp
llvm/lib/TargetParser/Host.cpp
llvm/lib/TargetParser/LoongArchTargetParser.cpp
llvm/test/CodeGen/LoongArch/ir-instruction/atomic-cmpxchg.ll

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 01a3ad0943b4cc..e5f2fec88706d8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5413,6 +5413,10 @@ def mlam_bh : Flag<["-"], "mlam-bh">, 
Group,
   HelpText<"Enable amswap[_db].{b/h} and amadd[_db].{b/h}">;
 def mno_lam_bh : Flag<["-"], "mno-lam-bh">, Group,
   HelpText<"Disable amswap[_db].{b/h} and amadd[_db].{b/h}">;
+def mld_seq_sa : Flag<["-"], "mld-seq-sa">, Group,
+  HelpText<"Do not generate load-load barrier instructions (dbar 0x700)">;
+def mno_ld_seq_sa : Flag<["-"], "mno-ld-seq-sa">, 
Group,
+  HelpText<"Generate load-load barrier instructions (dbar 0x700)">;
 def mannotate_tablejump : Flag<["-"], "mannotate-tablejump">, 
Group,
   HelpText<"Enable annotate table jump instruction to correlate it with the 
jump table.">;
 def mno_annotate_tablejump : Flag<["-"], "mno-annotate-tablejump">, 
Group,

diff  --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index 07b22b35f603ce..3f2d7317532aaf 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -205,7 +205,7 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
   // TODO: As more features of the V1.1 ISA are supported, a unified "v1.1"
   // arch feature set will be used to include all sub-features belonging to
   // the V1.1 ISA version.
-  if (HasFeatureFrecipe && HasFeatureLAM_BH)
+  if (HasFeatureFrecipe && HasFeatureLAM_BH && HasFeatureLD_SEQ_SA)
 Builder.defineMacro("__loongarch_arch",
 Twine('"') + "la64v1.1" + Twine('"'));
   else
@@ -239,6 +239,9 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
   if (HasFeatureLAM_BH)
 Builder.defineMacro("__loongarch_lam_bh", Twine(1));
 
+  if (HasFeatureLD_SEQ_SA)
+Builder.defineMacro("__loongarch_ld_seq_sa", Twine(1));
+
   StringRef ABI = getABI();
   if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
 Builder.defineMacro("__loongarch_lp64");
@@ -317,6 +320,8 @@ bool LoongArchTargetInfo::handleTargetFeatures(
   HasFeatureFrecipe = true;
 else if (Feature == "+lam-bh")
   HasFeatureLAM_BH = true;
+else if (Feature == "+ld-seq-sa")
+  HasFeatureLD_SEQ_SA = true;
   }
   return true;
 }

diff  --git a/clang/lib/Basic/Targets/LoongArch.h 
b/clang/lib/Basic/Targets/LoongArch.h
index 3585e9f7968b4b..e5eae7a8fcf677 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -31,6 +31,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
   bool HasFeatureLASX;
   bool HasFeatureFrecipe;
   bool HasFeatureLAM_BH;
+  bool HasFeatureLD_SEQ_SA;
 
 public:
   LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
@@ -41,6 +42,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
 HasFeatureLASX = false;
 HasFeatureFrecipe = false;
 HasFeatureLAM_BH = false;
+HasFeatureLD_SEQ_SA = false;
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::IEEEquad();

diff  --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 987db4638fca88..67b71a3ec623e4 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -274,6 +274,15 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 else
   Features.push_back("-lam-bh")

[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)

2024-11-22 Thread Lu Weining via cfe-commits

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


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


[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)

2024-11-22 Thread Lu Weining via cfe-commits

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Haojian Wu via cfe-commits


@@ -268,6 +268,40 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
   }
 }
 
+static bool IsPointerLikeType(QualType QT) {
+  QT = QT.getNonReferenceType();
+  if (QT->isPointerType())
+return true;
+  auto *RD = QT->getAsCXXRecordDecl();
+  if (!RD)
+return false;
+  RD = RD->getCanonicalDecl();
+  if (auto *CTSD = dyn_cast(RD))
+RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();

hokein wrote:

Thanks for the example. I think I understand what’s happening here.

The primary template Span is annotated with the gsl::Pointer attribute, so all 
its specializations should inherit this attribute.

However, in this example, at the point where we infer the `lifetime_capture_by` 
attribute for `vector`'s method, we don’t yet have a fully completed 
`ClassTemplateSpecializationDecl` for `Span` (and therefore, no 
`PointerAttr`). This is likely because the instantiation of `Span` isn’t 
required for the statement `std::vector> spans;`.

I think the following case would work without this special handling.
```
void use() {
  Span abc({}); // trigger an instantiation of `Span`.
  std::vector> spans;
  spans.push_back(std::vector{1, 2, 3}); // warning.
}
```

I don’t have a better suggestion for addressing this issue directly. However, I 
think we should have a comment explaining it. (Should we do the same thing for 
the one in `CheckExprLifetime.cpp`?)


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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Haojian Wu via cfe-commits


@@ -7,3 +7,106 @@ struct S {
 };
 
 // CHECK: CXXMethodDecl {{.*}}clang::lifetime_capture_by(a, b, global)
+
+// 
+// Infer annotation for STL container methods.
+// 
+namespace __gnu_cxx {
+template 
+struct basic_iterator {};
+}
+
+namespace std {
+template class allocator {};
+template >
+struct vector {
+  typedef __gnu_cxx::basic_iterator iterator;
+  iterator begin();
+
+  vector();
+
+  void push_back(const T&);
+  void push_back(T&&);
+
+  void insert(iterator, T&&);
+};
+} // namespace std
+struct [[gsl::Pointer()]] View {};
+std::vector views;
+// CHECK:   ClassTemplateSpecializationDecl {{.*}} struct vector definition 
implicit_instantiation
+// CHECK:   TemplateArgument type 'View'
+// CHECK-NOT:   LifetimeCaptureByAttr

hokein wrote:

Is the `LifetimeCaptureByAttr` attached to the primary template 
`push_back(const T&)`?

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


[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-11-22 Thread Chris Copeland via cfe-commits

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


[clang] [HLSL] Implement RWBuffer::operator[] via __builtin_hlsl_resource_getpointer (PR #117017)

2024-11-22 Thread Justin Bogner via cfe-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/117017

>From a4e932c29bddb78bd287cabca2e9ea0da6c96337 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Wed, 13 Nov 2024 17:04:30 -0800
Subject: [PATCH 1/3] [HLSL] Implement RWBuffer::operator[] via
 __builtin_hlsl_resource_getpointer

This introduces `__builtin_hlsl_resource_getpointer`, which lowers to
`llvm.dx.resource.getpointer` and is used to implement indexing into resources.

This will only work through the backend for typed buffers at this point, but
the changes to structured buffers should be correct as far as the frontend is
concerned.

Note: We probably want this to return a reference in the HLSL device address
space, but for now we're just using address space 0. Creating a device address
space and updating this code can be done later as necessary.

Fixes #95956
---
 clang/include/clang/Basic/Builtins.td |  6 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  1 +
 clang/lib/AST/Type.cpp|  4 +-
 clang/lib/CodeGen/CGBuiltin.cpp   | 10 
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 56 ++-
 clang/lib/Sema/SemaExpr.cpp   |  3 +
 clang/lib/Sema/SemaHLSL.cpp   | 19 +++
 clang/test/AST/HLSL/RWBuffer-AST.hlsl | 18 +-
 .../test/AST/HLSL/RWStructuredBuffer-AST.hlsl | 20 ++-
 ...RasterizerOrderedStructuredBuffer-AST.hlsl | 22 +++-
 clang/test/AST/HLSL/StructuredBuffer-AST.hlsl | 20 ++-
 .../builtins/RWBuffer-constructor.hlsl|  4 +-
 .../builtins/RWBuffer-elementtype.hlsl| 54 +-
 .../builtins/RWBuffer-subscript.hlsl  | 13 ++---
 .../RWStructuredBuffer-elementtype.hlsl   | 28 +-
 ...erOrderedStructuredBuffer-elementtype.hlsl | 30 +-
 .../StructuredBuffer-elementtype.hlsl | 28 +-
 .../StructuredBuffers-constructors.hlsl   | 16 +++---
 .../StructuredBuffers-subscripts.hlsl | 19 ---
 .../CodeGenHLSL/builtins/hlsl_resource_t.hlsl | 13 ++---
 .../implicit-norecurse-attrib.hlsl|  2 +-
 21 files changed, 248 insertions(+), 138 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 83e5b52b4e3a9e..a1b20082b6c1f2 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4738,6 +4738,12 @@ def GetDeviceSideMangledName : LangBuiltin<"CUDA_LANG"> {
 }
 
 // HLSL
+def HLSLTypedBufferPointer : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_resource_getpointer"];
+  let Attributes = [NoThrow];
+  let Prototype = "void(...)";
+}
+
 def HLSLAll : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_all"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dfb90501ce72d7..b69e0b84cc3034 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12487,6 +12487,7 @@ def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;
 def err_hlsl_missing_resource_class : Error<"HLSL resource needs to have 
[[hlsl::resource_class()]] attribute">;
 def err_hlsl_attribute_needs_intangible_type: Error<"attribute %0 can be used 
only on HLSL intangible type %1">;
+def err_hlsl_builtin_requires_resource: Error<"operand must be of 
__hlsl_resource_t type">;
 
 def err_hlsl_operator_unsupported : Error<
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index b70f86ef31442d..9d50151a541641 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -4723,7 +4723,9 @@ LinkageInfo LinkageComputer::computeTypeLinkageInfo(const 
Type *T) {
   case Type::Pipe:
 return computeTypeLinkageInfo(cast(T)->getElementType());
   case Type::HLSLAttributedResource:
-llvm_unreachable("not yet implemented");
+return computeTypeLinkageInfo(cast(T)
+  ->getContainedType()
+  ->getCanonicalTypeInternal());
   }
 
   llvm_unreachable("unhandled type class");
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 0916e14f182ddd..e4690346417630 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19008,6 +19008,16 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 return nullptr;
 
   switch (BuiltinID) {
+  case Builtin::BI__builtin_hlsl_resource_getpointer: {
+Value *HandleOp = EmitScalarExpr(E->getArg(0));
+Value *IndexOp = EmitScalarExpr(E->getArg(1));
+
+// TODO: Map to an hlsl_device address space.
+llvm::Type *RetTy = llvm::PointerType::getUnqual(getLLVMContext());
+
+return Builder.CreateIntrinsic(RetTy, Intrinsic::dx_resource_getpointer,
+   

[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-11-22 Thread via cfe-commits

workingjubilee wrote:

> I agree but was having trouble putting it into words. I don't have a 
> reference I can put my hands on, but we have generally considered the llvm 
> error messages to be a poor substitute to those produced by clang and have 
> often gone the other way, converting llvm errors to clang errors.

I am not exactly sure how LLVM developers are imagining that frontend 
developers determine that they should diagnose a situation and provide a 
friendlier error? The primary motivation we have is that we notice that LLVM 
vomits up a nasty stacktrace in some situation, and then we figure it out and 
cover up the sewer hole that people could otherwise fallthrough to.

I suppose this also works if LLVM developers use their mystical powers to 
instantly transmit an awareness of all the situations every frontend developer 
should be diagnosing and erroring on. Was there a psychic mind meld I missed? 
Because I had to spend an entire night and day going over all the edge cases 
for the interrupt ABIs that we "support" in Rust, instead of merely possessing 
mystical knowledge about which cases the frontend should catch and error on.

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


[clang] [HLSL] Implement RWBuffer::operator[] via __builtin_hlsl_resource_getpointer (PR #117017)

2024-11-22 Thread Justin Bogner via cfe-commits


@@ -12487,6 +12487,7 @@ def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;
 def err_hlsl_missing_resource_class : Error<"HLSL resource needs to have 
[[hlsl::resource_class()]] attribute">;
 def err_hlsl_attribute_needs_intangible_type: Error<"attribute %0 can be used 
only on HLSL intangible type %1">;
+def err_hlsl_builtin_requires_resource: Error<"operand must be of 
__hlsl_resource_t type">;

bogner wrote:

Good to know. I really need to review that PR, sorry!

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


[clang] [HLSL] Implement RWBuffer::operator[] via __builtin_hlsl_resource_getpointer (PR #117017)

2024-11-22 Thread Justin Bogner via cfe-commits


@@ -4738,6 +4738,12 @@ def GetDeviceSideMangledName : LangBuiltin<"CUDA_LANG"> {
 }
 
 // HLSL
+def HLSLTypedBufferPointer : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_resource_getpointer"];

bogner wrote:

All buffer types, the name was leftover from an earlier revision. Fixed!

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


[clang] [clang] Warn const integer-overflow of member in temporary struct bound to rvalue reference (PR #117225)

2024-11-22 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/117225

>From 08e1a3388e9d98f2469687d2367472342b05c47e Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Thu, 21 Nov 2024 13:05:20 -0600
Subject: [PATCH 1/2] [clang] Warn const integer-overflow of member in
 temporary struct bound to rvalue reference

Fixes #46755
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/lib/Sema/SemaChecking.cpp | 3 ++-
 clang/test/SemaCXX/integer-overflow.cpp | 6 ++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8c81de341937ca..8820ba0fb24b38 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -578,6 +578,9 @@ Improvements to Clang's diagnostics
 
 - Clang now omits shadowing warnings for parameter names in explicit object 
member functions (#GH95707).
 
+- For an rvalue reference bound to a temporary struct with an integer member, 
Clang will detect constant integer overflow
+  in the initializer for the integer member (#GH46755).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2fd990750ed212..e36cb318c61885 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12048,7 +12048,8 @@ void Sema::CheckForIntOverflow (const Expr *E) {
  New && New->isArray()) {
   if (auto ArraySize = New->getArraySize())
 Exprs.push_back(*ArraySize);
-}
+} else if (const auto *Mte = dyn_cast(OriginalE))
+  Exprs.push_back(Mte->getSubExpr());
   } while (!Exprs.empty());
 }
 
diff --git a/clang/test/SemaCXX/integer-overflow.cpp 
b/clang/test/SemaCXX/integer-overflow.cpp
index d1cc8bee566f6b..73a4e88ee6c098 100644
--- a/clang/test/SemaCXX/integer-overflow.cpp
+++ b/clang/test/SemaCXX/integer-overflow.cpp
@@ -246,4 +246,10 @@ int m() {
 return 0;
 }
 }
+
+namespace GH46755 {
+void f() {
+struct { int v; } &&r = {512 * 1024 * 1024 * 1024}; // expected-warning 
{{overflow in expression; result is 0 with type 'int'}}
+}
+}
 #endif

>From 636b14f273fe266651ad933276afb8ab9caf0dfb Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Fri, 22 Nov 2024 04:27:59 -0500
Subject: [PATCH 2/2] Rename var: Mte -> MTE

Co-authored-by: Sirraide 
---
 clang/lib/Sema/SemaChecking.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index e36cb318c61885..a49605e4867651 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12048,8 +12048,8 @@ void Sema::CheckForIntOverflow (const Expr *E) {
  New && New->isArray()) {
   if (auto ArraySize = New->getArraySize())
 Exprs.push_back(*ArraySize);
-} else if (const auto *Mte = dyn_cast(OriginalE))
-  Exprs.push_back(Mte->getSubExpr());
+} else if (const auto *MTE = dyn_cast(OriginalE))
+  Exprs.push_back(MTE->getSubExpr());
   } while (!Exprs.empty());
 }
 

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Haojian Wu via cfe-commits


@@ -7,3 +7,106 @@ struct S {
 };
 
 // CHECK: CXXMethodDecl {{.*}}clang::lifetime_capture_by(a, b, global)
+
+// 
+// Infer annotation for STL container methods.
+// 
+namespace __gnu_cxx {
+template 
+struct basic_iterator {};
+}
+
+namespace std {
+template class allocator {};
+template >
+struct vector {
+  typedef __gnu_cxx::basic_iterator iterator;
+  iterator begin();
+
+  vector();
+
+  void push_back(const T&);
+  void push_back(T&&);
+
+  void insert(iterator, T&&);
+};
+} // namespace std
+struct [[gsl::Pointer()]] View {};
+std::vector views;
+// CHECK:   ClassTemplateSpecializationDecl {{.*}} struct vector definition 
implicit_instantiation
+// CHECK:   TemplateArgument type 'View'
+// CHECK-NOT:   LifetimeCaptureByAttr

hokein wrote:

> That would add the annotation to all of its specializations which is not 
> something we want.

Can you give a counter example? 

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits

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


[clang] c11b6b1 - [RISCV] Support __builtin_cpu_is

2024-11-22 Thread via cfe-commits

Author: Pengcheng Wang
Date: 2024-11-22T20:04:57+08:00
New Revision: c11b6b1b8af7454b35eef342162dc2cddf54b4de

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

LOG: [RISCV] Support __builtin_cpu_is

We have defined `__riscv_cpu_model` variable in #101449. It contains
`mvendorid`, `marchid` and `mimpid` fields which are read via system
call `sys_riscv_hwprobe`.

We can support `__builtin_cpu_is` via comparing values in compiler's
CPU definitions and `__riscv_cpu_model`.

This depends on #116202.

Reviewers: lenary, BeMg, kito-cheng, preames, lukel97

Reviewed By: lenary

Pull Request: https://github.com/llvm/llvm-project/pull/116231

Added: 
clang/test/CodeGen/RISCV/builtin-cpu-is-error.c
clang/test/CodeGen/RISCV/builtin-cpu-is.c

Modified: 
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/Basic/Targets/RISCV.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CodeGenFunction.h
llvm/include/llvm/TargetParser/RISCVTargetParser.h
llvm/lib/TargetParser/RISCVTargetParser.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index c61ee7ee203923..2384b322c50f92 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -512,3 +512,10 @@ bool RISCVTargetInfo::validateGlobalRegisterVariable(
   }
   return false;
 }
+
+bool RISCVTargetInfo::validateCpuIs(StringRef CPUName) const {
+  assert(getTriple().isOSLinux() &&
+ "__builtin_cpu_is() is only supported for Linux.");
+
+  return llvm::RISCV::hasValidCPUModel(CPUName);
+}

diff  --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 3b418585ab4a39..3544ea64cb5e77 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -128,8 +128,10 @@ class RISCVTargetInfo : public TargetInfo {
   }
 
   bool supportsCpuSupports() const override { return getTriple().isOSLinux(); }
+  bool supportsCpuIs() const override { return getTriple().isOSLinux(); }
   bool supportsCpuInit() const override { return getTriple().isOSLinux(); }
   bool validateCpuSupports(StringRef Feature) const override;
+  bool validateCpuIs(StringRef CPUName) const override;
   bool isValidFeatureName(StringRef Name) const override;
 
   bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index ff7132fd8bc1e7..caf5e40429838b 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -66,6 +66,7 @@
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/TargetParser/X86TargetParser.h"
 #include 
 #include 
@@ -22693,6 +22694,47 @@ Value 
*CodeGenFunction::EmitHexagonBuiltinExpr(unsigned BuiltinID,
   return nullptr;
 }
 
+Value *CodeGenFunction::EmitRISCVCpuIs(const CallExpr *E) {
+  const Expr *CPUExpr = E->getArg(0)->IgnoreParenCasts();
+  StringRef CPUStr = cast(CPUExpr)->getString();
+  return EmitRISCVCpuIs(CPUStr);
+}
+
+Value *CodeGenFunction::EmitRISCVCpuIs(StringRef CPUStr) {
+  llvm::Type *Int32Ty = Builder.getInt32Ty();
+  llvm::Type *Int64Ty = Builder.getInt64Ty();
+  llvm::StructType *StructTy = llvm::StructType::get(Int32Ty, Int64Ty, 
Int64Ty);
+  llvm::Constant *RISCVCPUModel =
+  CGM.CreateRuntimeVariable(StructTy, "__riscv_cpu_model");
+  cast(RISCVCPUModel)->setDSOLocal(true);
+
+  auto loadRISCVCPUID = [&](unsigned Index) {
+Value *Ptr = Builder.CreateStructGEP(StructTy, RISCVCPUModel, Index);
+Value *CPUID = Builder.CreateAlignedLoad(StructTy->getTypeAtIndex(Index),
+ Ptr, llvm::MaybeAlign());
+return CPUID;
+  };
+
+  const llvm::RISCV::CPUModel CPUModel = llvm::RISCV::getCPUModel(CPUStr);
+
+  // Compare mvendorid.
+  Value *VendorID = loadRISCVCPUID(0);
+  Value *Result =
+  Builder.CreateICmpEQ(VendorID, Builder.getInt32(CPUModel.MVendorID));
+
+  // Compare marchid.
+  Value *ArchID = loadRISCVCPUID(1);
+  Result = Builder.CreateAnd(
+  Result, Builder.CreateICmpEQ(ArchID, 
Builder.getInt64(CPUModel.MArchID)));
+
+  // Compare mimpid.
+  Value *ImpID = loadRISCVCPUID(2);
+  Result = Builder.CreateAnd(
+  Result, Builder.CreateICmpEQ(ImpID, Builder.getInt64(CPUModel.MImpID)));
+
+  return Result;
+}
+
 Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
  const CallExpr *E,
  ReturnValueSlot ReturnValue) {
@@ -22701,6 +22743,8 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned 
BuiltinID,
 return EmitRISCVCpuSupports(E);
   if (BuiltinID == Bu

[clang] [llvm] [RISCV] Support __builtin_cpu_is (PR #116231)

2024-11-22 Thread Pengcheng Wang via cfe-commits

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


[clang] [llvm] [RISCV] Support __builtin_cpu_is (PR #116231)

2024-11-22 Thread Pengcheng Wang via cfe-commits

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


[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

2024-11-22 Thread Roger Sanders via cfe-commits

RogerSanders wrote:

I'd like to see this change make it into the repo, as I'm in a similar 
situation with a 6+ million line codebase. What's the next steps to advance 
this?

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


[clang] [analyzer] Print the PostInitializer target in exploded-graph-rewriter (PR #116034)

2024-11-22 Thread Balazs Benics via cfe-commits

steakhal wrote:

Ping @NagyDonat 

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


[clang] [clang] Warn const integer-overflow of member in temporary struct bound to rvalue reference (PR #117225)

2024-11-22 Thread Youngsuk Kim via cfe-commits

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


[clang] ef20644 - [clang] Warn const integer-overflow of member in temporary struct bound to rvalue reference (#117225)

2024-11-22 Thread via cfe-commits

Author: Youngsuk Kim
Date: 2024-11-22T04:51:09-05:00
New Revision: ef206446f2bbcb1bacc73d7611a96c457f59499f

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

LOG: [clang] Warn const integer-overflow of member in temporary struct bound to 
rvalue reference (#117225)

Fixes #46755

-

Co-authored-by: Sirraide 

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/integer-overflow.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4847437ef1f8bd..54145b28154eb4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -580,6 +580,9 @@ Improvements to Clang's diagnostics
 
 - Improved error recovery for function call arguments with trailing commas 
(#GH100921).
 
+- For an rvalue reference bound to a temporary struct with an integer member, 
Clang will detect constant integer overflow
+  in the initializer for the integer member (#GH46755).
+
 Improvements to Clang's time-trace
 --
 

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2fd990750ed212..a49605e4867651 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12048,7 +12048,8 @@ void Sema::CheckForIntOverflow (const Expr *E) {
  New && New->isArray()) {
   if (auto ArraySize = New->getArraySize())
 Exprs.push_back(*ArraySize);
-}
+} else if (const auto *MTE = dyn_cast(OriginalE))
+  Exprs.push_back(MTE->getSubExpr());
   } while (!Exprs.empty());
 }
 

diff  --git a/clang/test/SemaCXX/integer-overflow.cpp 
b/clang/test/SemaCXX/integer-overflow.cpp
index d1cc8bee566f6b..73a4e88ee6c098 100644
--- a/clang/test/SemaCXX/integer-overflow.cpp
+++ b/clang/test/SemaCXX/integer-overflow.cpp
@@ -246,4 +246,10 @@ int m() {
 return 0;
 }
 }
+
+namespace GH46755 {
+void f() {
+struct { int v; } &&r = {512 * 1024 * 1024 * 1024}; // expected-warning 
{{overflow in expression; result is 0 with type 'int'}}
+}
+}
 #endif



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


[clang] [clang] Allow delayed function instantiation at TU end if initial instantiation fails (PR #117167)

2024-11-22 Thread via cfe-commits

https://github.com/StefanPaulet updated 
https://github.com/llvm/llvm-project/pull/117167

>From 54199baf4a6a205e0b85f9f528a90b8170a960fa Mon Sep 17 00:00:00 2001
From: StefanPaulet 
Date: Thu, 21 Nov 2024 15:32:56 +0200
Subject: [PATCH 1/3] [clang] Allow delayed function instantiation at TU end if
 initial instantiation fails

---
 clang/include/clang/Sema/Sema.h   | 11 +---
 clang/lib/Sema/Sema.cpp   |  2 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 14 +-
 .../instantiate-function-delayed.cpp  | 26 +++
 4 files changed, 42 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/SemaTemplate/instantiate-function-delayed.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6ea6c67447b6f0..ce27260bc78801 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13523,7 +13523,9 @@ class Sema final : public SemaBase {
   S.PendingLocalImplicitInstantiations);
 }
 
-void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/true); }
+void perform(bool AtEndOfTU = false) {
+  S.PerformPendingInstantiations(/*LocalOnly=*/true, AtEndOfTU);
+}
 
 ~LocalEagerInstantiationScope() {
   assert(S.PendingLocalImplicitInstantiations.empty() &&
@@ -13568,10 +13570,10 @@ class Sema final : public SemaBase {
   S.SavedVTableUses.back().swap(S.VTableUses);
 }
 
-void perform() {
+void perform(bool AtEndOfTU = false) {
   if (Enabled) {
 S.DefineUsedVTables();
-S.PerformPendingInstantiations();
+S.PerformPendingInstantiations(false, AtEndOfTU);
   }
 }
 
@@ -13790,7 +13792,8 @@ class Sema final : public SemaBase {
 
   /// Performs template instantiation for all implicit template
   /// instantiations we have seen until this point.
-  void PerformPendingInstantiations(bool LocalOnly = false);
+  void PerformPendingInstantiations(bool LocalOnly = false,
+bool AtEndOfTU = false);
 
   TemplateParameterList *
   SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 942e7ece4283e3..c97a253239df2b 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1138,7 +1138,7 @@ void 
Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
 
   {
 llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
-PerformPendingInstantiations();
+PerformPendingInstantiations(false, true);
   }
 
   emitDeferredDiags();
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 10efde7c3fe540..0f9a39062750bc 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5267,9 +5267,9 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 
   // This class may have local implicit instantiations that need to be
   // instantiation within this scope.
-  LocalInstantiations.perform();
+  LocalInstantiations.perform(AtEndOfTU);
   Scope.Exit();
-  GlobalInstantiations.perform();
+  GlobalInstantiations.perform(AtEndOfTU);
 }
 
 VarTemplateSpecializationDecl *Sema::BuildVarTemplateInstantiation(
@@ -5612,9 +5612,9 @@ void Sema::InstantiateVariableDefinition(SourceLocation 
PointOfInstantiation,
 
   // This variable may have local implicit instantiations that need to be
   // instantiated within this scope.
-  LocalInstantiations.perform();
+  LocalInstantiations.perform(AtEndOfTU);
   Local.Exit();
-  GlobalInstantiations.perform();
+  GlobalInstantiations.perform(AtEndOfTU);
 }
   } else {
 assert(Var->isStaticDataMember() && PatternDecl->isStaticDataMember() &&
@@ -6448,7 +6448,7 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, 
NamedDecl *D,
   return D;
 }
 
-void Sema::PerformPendingInstantiations(bool LocalOnly) {
+void Sema::PerformPendingInstantiations(bool LocalOnly, bool AtEndOfTU) {
   std::deque delayedPCHInstantiations;
   while (!PendingLocalImplicitInstantiations.empty() ||
  (!LocalOnly && !PendingInstantiations.empty())) {
@@ -6476,9 +6476,11 @@ void Sema::PerformPendingInstantiations(bool LocalOnly) {
 });
   } else {
 InstantiateFunctionDefinition(/*FIXME:*/ Inst.second, Function, true,
-  DefinitionRequired, true);
+  DefinitionRequired, AtEndOfTU);
 if (Function->isDefined())
   Function->setInstantiationIsPending(false);
+else if (!AtEndOfTU)
+  LateParsedInstantiations.push_back(Inst);
   }
   // Definition of a PCH-ed template declaration may be available only in 
the TU.
   if (!LocalOnly && LangOpts.PCHInstantiateTemplates &&
diff --git a/clang/test/SemaTemplate/instantiate-function-delayed.cpp 
b/clang/t

[clang] [llvm] [llvm][NFC] `APFloat`: Add missing semantics to enum (PR #117291)

2024-11-22 Thread Durgadoss R via cfe-commits

durga4github wrote:

Hi @matthias-springer ,

Can we split this into at least two separate PRs?

One for the first two items in the commit message.
And one (or two) PRs for the rest of the changes.


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


[clang] [clang] Allow delayed function instantiation at TU end if initial instantiation fails (PR #117167)

2024-11-22 Thread via cfe-commits

https://github.com/StefanPaulet updated 
https://github.com/llvm/llvm-project/pull/117167

>From d4ab1ecd5672f7bd3e90230b1739deb981e6353c Mon Sep 17 00:00:00 2001
From: StefanPaulet 
Date: Thu, 21 Nov 2024 15:32:56 +0200
Subject: [PATCH] [clang] Allow delayed function instantiation at TU end if
 initial instantiation fails

---
 clang/include/clang/Sema/Sema.h   | 11 +---
 clang/lib/Sema/Sema.cpp   |  3 ++-
 clang/lib/Sema/SemaExpr.cpp   |  3 +--
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 11 
 .../instantiate-function-delayed.cpp  | 26 +++
 5 files changed, 42 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/SemaTemplate/instantiate-function-delayed.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6ea6c67447b6f0..fd1008efcecc4a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -865,6 +865,8 @@ class Sema final : public SemaBase {
   /// checks.
   const TranslationUnitKind TUKind;
 
+  bool AtEndOfTU = false;
+
   /// Translation Unit Scope - useful to Objective-C actions that need
   /// to lookup file scope declarations in the "ordinary" C decl namespace.
   /// For example, user-defined classes, built-in "id" type, etc.
@@ -13523,7 +13525,9 @@ class Sema final : public SemaBase {
   S.PendingLocalImplicitInstantiations);
 }
 
-void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/true); }
+void perform() {
+  S.PerformPendingInstantiations(/*LocalOnly=*/true);
+}
 
 ~LocalEagerInstantiationScope() {
   assert(S.PendingLocalImplicitInstantiations.empty() &&
@@ -13571,7 +13575,7 @@ class Sema final : public SemaBase {
 void perform() {
   if (Enabled) {
 S.DefineUsedVTables();
-S.PerformPendingInstantiations();
+S.PerformPendingInstantiations(false);
   }
 }
 
@@ -13682,8 +13686,7 @@ class Sema final : public SemaBase {
   void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
  FunctionDecl *Function,
  bool Recursive = false,
- bool DefinitionRequired = false,
- bool AtEndOfTU = false);
+ bool DefinitionRequired = false);
   VarTemplateSpecializationDecl *BuildVarTemplateInstantiation(
   VarTemplateDecl *VarTemplate, VarDecl *FromVar,
   const TemplateArgumentList *PartialSpecArgs,
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 942e7ece4283e3..f53ea801a8d1ff 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1138,7 +1138,7 @@ void 
Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
 
   {
 llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
-PerformPendingInstantiations();
+PerformPendingInstantiations(/*LocalOnly=*/false);
   }
 
   emitDeferredDiags();
@@ -1160,6 +1160,7 @@ void 
Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
 void Sema::ActOnEndOfTranslationUnit() {
   assert(DelayedDiagnostics.getCurrentPool() == nullptr
  && "reached end of translation unit with a pool attached?");
+  AtEndOfTU = true;
 
   // If code completion is enabled, don't perform any end-of-translation-unit
   // work.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6c7472ce92703b..bfab8286769424 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -21054,8 +21054,7 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
   // precedes this use.
   InstantiateFunctionDefinition(E->getBeginLoc(), FD,
 /*Recursive=*/false,
-/*DefinitionRequired=*/true,
-/*AtEndOfTU=*/false);
+/*DefinitionRequired=*/true);
 }
 // Produce a properly-typed reference to the function.
 CXXScopeSpec SS;
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 10efde7c3fe540..bb2f19d6e44179 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -513,7 +513,7 @@ static void instantiateOMPDeclareVariantAttr(
   return;
 S.InstantiateFunctionDefinition(
 New->getLocation(), SubstFD, /* Recursive */ true,
-/* DefinitionRequired */ false, /* AtEndOfTU */ false);
+/* DefinitionRequired */ false);
 SubstFD->setInstantiationIsPending(!SubstFD->isDefined());
 E = DeclRefExpr::Create(S.Context, NestedNameSpecifierLoc(),
 SourceLocation(), SubstFD,
@@ -4932,8 +4932,7 @@ FunctionDecl *Sema::InstantiateFunctionDeclaration(
 void Sema::Inst

[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits


@@ -268,6 +268,40 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
   }
 }
 
+static bool IsPointerLikeType(QualType QT) {
+  QT = QT.getNonReferenceType();
+  if (QT->isPointerType())
+return true;
+  auto *RD = QT->getAsCXXRecordDecl();
+  if (!RD)
+return false;
+  RD = RD->getCanonicalDecl();
+  if (auto *CTSD = dyn_cast(RD))
+RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();

usx95 wrote:

Hmm. It can reproduce with `` include but not with handcrafted `vector` 
in lit tests. 

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits

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


[clang] [SYCL] change sycl version accrodnig to standard (PR #114790)

2024-11-22 Thread via cfe-commits

https://github.com/dklochkov-emb updated 
https://github.com/llvm/llvm-project/pull/114790

>From dafdcfe5832f842aae275d9c644c8a9d722c7acb Mon Sep 17 00:00:00 2001
From: "Klochkov, Denis" 
Date: Mon, 4 Nov 2024 04:58:30 -0800
Subject: [PATCH] [SYCL] change sycl version accrodnig to standard

[SYCL] make sycl version long integer
---
 clang/lib/Frontend/InitPreprocessor.cpp | 2 +-
 clang/test/Preprocessor/sycl-macro.cpp  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 9a0fdb175ff29e..a90807d6fa6f0b 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -587,7 +587,7 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo &TI,
 if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017)
   Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
 else if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2020)
-  Builder.defineMacro("SYCL_LANGUAGE_VERSION", "202001");
+  Builder.defineMacro("SYCL_LANGUAGE_VERSION", "202012L");
   }
 
   // Not "standard" per se, but available even with the -undef flag.
diff --git a/clang/test/Preprocessor/sycl-macro.cpp 
b/clang/test/Preprocessor/sycl-macro.cpp
index eecddaa09d1c33..a509086f99e413 100644
--- a/clang/test/Preprocessor/sycl-macro.cpp
+++ b/clang/test/Preprocessor/sycl-macro.cpp
@@ -10,5 +10,5 @@
 // CHECK-NOT:#define __SYCL_DEVICE_ONLY__ 1
 // CHECK-NOT:#define CL_SYCL_LANGUAGE_VERSION 121
 // CHECK-SYCL-STD:#define CL_SYCL_LANGUAGE_VERSION 121
-// CHECK-SYCL-STD-2020:#define SYCL_LANGUAGE_VERSION 202001
+// CHECK-SYCL-STD-2020:#define SYCL_LANGUAGE_VERSION 202012
 // CHECK-SYCL:#define __SYCL_DEVICE_ONLY__ 1

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


[clang-tools-extra] 5518bb2 - [clangd] Check getFunctionTypeLoc() for validity in InlayHintVisitor (#117296)

2024-11-22 Thread via cfe-commits

Author: Nathan Ridge
Date: 2024-11-22T03:11:07-05:00
New Revision: 5518bb215b51cc339c3ecac064032f6791ae6476

URL: 
https://github.com/llvm/llvm-project/commit/5518bb215b51cc339c3ecac064032f6791ae6476
DIFF: 
https://github.com/llvm/llvm-project/commit/5518bb215b51cc339c3ecac064032f6791ae6476.diff

LOG: [clangd] Check getFunctionTypeLoc() for validity in InlayHintVisitor 
(#117296)

Fixes https://github.com/clangd/clangd/issues/2223

Added: 


Modified: 
clang-tools-extra/clangd/InlayHints.cpp
clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index c4053fced81d6f..fefffeb4efc1a2 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -626,10 +626,15 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 
   bool VisitLambdaExpr(LambdaExpr *E) {
 FunctionDecl *D = E->getCallOperator();
-if (!E->hasExplicitResultType())
-  addReturnTypeHint(D, E->hasExplicitParameters()
-   ? D->getFunctionTypeLoc().getRParenLoc()
-   : E->getIntroducerRange().getEnd());
+if (!E->hasExplicitResultType()) {
+  SourceLocation TypeHintLoc;
+  if (!E->hasExplicitParameters())
+TypeHintLoc = E->getIntroducerRange().getEnd();
+  else if (auto FTL = D->getFunctionTypeLoc())
+TypeHintLoc = FTL.getRParenLoc();
+  if (TypeHintLoc.isValid())
+addReturnTypeHint(D, TypeHintLoc);
+}
 return true;
   }
 

diff  --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 73dd273d6c39d4..77d78b8777fe30 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1576,6 +1576,22 @@ TEST(TypeHints, Aliased) {
   EXPECT_THAT(hintsOfKind(AST, InlayHintKind::Type), IsEmpty());
 }
 
+TEST(TypeHints, CallingConvention) {
+  // Check that we don't crash for lambdas without a FunctionTypeLoc
+  // https://github.com/clangd/clangd/issues/2223
+  std::string Code = R"cpp(
+void test() {
+  []() __cdecl {};
+}
+  )cpp";
+  TestTU TU = TestTU::withCode(Code);
+  TU.ExtraArgs.push_back("--target=x86_64-w64-mingw32");
+  TU.PredefineMacros = true; // for the __cdecl
+  auto AST = TU.build();
+
+  EXPECT_THAT(hintsOfKind(AST, InlayHintKind::Type), IsEmpty());
+}
+
 TEST(TypeHints, Decltype) {
   assertTypeHints(R"cpp(
 $a[[decltype(0)]] a;



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


[clang] [HLSL] Get the index for resource bindings from the slot (PR #117303)

2024-11-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Justin Bogner (bogner)


Changes

Resource bindings are indexed from the beginning of the binding space, not from 
the binding itself. This means that we need to populate the index for non-array 
resources with the same value as the slot number (and arrays, when we implement 
them, will be the sum of the slot number and the access index).

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


4 Files Affected:

- (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl (+1-1) 
- (modified) 
clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl (+10-10) 
- (added) clang/test/CodeGenHLSL/resource-bindings.hlsl (+19) 


``diff
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 7ba0d615018181..b4e17466087b16 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -588,7 +588,7 @@ llvm::Function 
*CGHLSLRuntime::createResourceBindingInitFn() {
   auto *Slot = llvm::ConstantInt::get(CGM.IntTy, RBA->getSlotNumber());
   // FIXME: resource arrays are not yet implemented
   auto *Range = llvm::ConstantInt::get(CGM.IntTy, 1);
-  auto *Index = llvm::ConstantInt::get(CGM.IntTy, 0);
+  auto *Index = llvm::ConstantInt::get(CGM.IntTy, RBA->getSlotNumber());
   // FIXME: NonUniformResourceIndex bit is not yet implemented
   auto *NonUniform = llvm::ConstantInt::get(Int1Ty, false);
   llvm::Value *Args[] = {Space, Slot, Range, Index, NonUniform};
diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl
index 3949f7b943cfe0..a820d782896aaf 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl
@@ -19,7 +19,7 @@ RWBuffer Buf : register(u5, space3);
 
 // CHECK: define internal void @_init_resource_bindings() {
 // CHECK-NEXT: entry:
-// CHECK-DXIL-NEXT: %Buf_h = call target("dx.TypedBuffer", float, 1, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_f32_1_0_0t(i32 3, i32 5, i32 1, i32 
0, i1 false)
+// CHECK-DXIL-NEXT: %Buf_h = call target("dx.TypedBuffer", float, 1, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_f32_1_0_0t(i32 3, i32 5, i32 1, i32 
5, i1 false)
 // CHECK-DXIL-NEXT: store target("dx.TypedBuffer", float, 1, 0, 0) %Buf_h, ptr 
@Buf, align 4
 // CHECK-SPIRV-NEXT: %Buf_h = call target("dx.TypedBuffer", float, 1, 0, 0) 
@llvm.spv.handle.fromBinding.tdx.TypedBuffer_f32_1_0_0t(i32 3, i32 5, i32 1, 
i32 0, i1 false)
 // CHECK-SPIRV-NEXT: store target("dx.TypedBuffer", float, 1, 0, 0) %Buf_h, 
ptr @Buf, align 4
diff --git 
a/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl 
b/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl
index 2e141b9279fa61..d7478c2981a85d 100644
--- a/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl
@@ -37,24 +37,24 @@ RasterizerOrderedStructuredBuffer Buf5 : 
register(u1, space2);
 
 // CHECK: define internal void @_init_resource_bindings() {
 // CHECK-NEXT: entry:
-// CHECK-DXIL-NEXT: %Buf_h = call target("dx.RawBuffer", float, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_0_0t(i32 0, i32 10, i32 1, i32 0, 
i1 false)
+// CHECK-DXIL-NEXT: %Buf_h = call target("dx.RawBuffer", float, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_0_0t(i32 0, i32 10, i32 1, i32 
10, i1 false)
 // CHECK-DXIL-NEXT: store target("dx.RawBuffer", float, 0, 0) %Buf_h, ptr 
@Buf, align 4
-// CHECK-DXIL-NEXT: %Buf2_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 1, i32 5, i32 1, i32 0, 
i1 false)
+// CHECK-DXIL-NEXT: %Buf2_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 1, i32 5, i32 1, i32 5, 
i1 false)
 // CHECK-DXIL-NEXT: store target("dx.RawBuffer", float, 1, 0) %Buf2_h, ptr 
@Buf2, align 4
-// CHECK-DXIL-NEXT: %Buf3_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 0, i32 3, i32 1, i32 0, 
i1 false)
+// CHECK-DXIL-NEXT: %Buf3_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 0, i32 3, i32 1, i32 3, 
i1 false)
 // CHECK-DXIL-NEXT: store target("dx.RawBuffer", float, 1, 0) %Buf3_h, ptr 
@Buf3, align 4
-// CHECK-DXIL-NEXT: %Buf4_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 0, i32 4, i32 1, i32 0, 
i1 false)
+// CHECK-DXIL-NEXT: %Buf4_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 0, i32 4, i32 1, i32 4, 
i1 false)
 // CHECK-DXIL-NEXT: store target("dx.RawBuffer", float, 1, 0) %Buf4_h, ptr 
@Buf4, align 4
-// CHECK-DXIL-NEXT: %Buf5_h = ca

[clang] [clang][bytecode][NFC] Avoid a getSource() call (PR #117311)

2024-11-22 Thread Timm Baeder via cfe-commits

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

This is only needed when we actually emit a diagnostic, so move the getSource() 
after the early return.

>From bf0c37684268d7afa41beb6035aa137d633ea596 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 22 Nov 2024 10:56:47 +0100
Subject: [PATCH] [clang][bytecode][NFC] Avoid a getSource() call

This is only needed when we actually emit a diagnostic, so move the
getSource() after the early return.
---
 clang/lib/AST/ByteCode/Interp.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 4af1d6f40e9017..329f1584be34bf 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1481,11 +1481,12 @@ bool CheckNewTypeMismatch(InterpState &S, CodePtr OpPC, 
const Expr *E,
 
 bool InvalidNewDeleteExpr(InterpState &S, CodePtr OpPC, const Expr *E) {
   assert(E);
-  const auto &Loc = S.Current->getSource(OpPC);
 
   if (S.getLangOpts().CPlusPlus26)
 return true;
 
+  const auto &Loc = S.Current->getSource(OpPC);
+
   if (const auto *NewExpr = dyn_cast(E)) {
 const FunctionDecl *OperatorNew = NewExpr->getOperatorNew();
 

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


[clang] [clang][bytecode][NFC] Avoid a getSource() call (PR #117311)

2024-11-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

This is only needed when we actually emit a diagnostic, so move the getSource() 
after the early return.

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


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.cpp (+2-1) 


``diff
diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 4af1d6f40e9017..329f1584be34bf 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1481,11 +1481,12 @@ bool CheckNewTypeMismatch(InterpState &S, CodePtr OpPC, 
const Expr *E,
 
 bool InvalidNewDeleteExpr(InterpState &S, CodePtr OpPC, const Expr *E) {
   assert(E);
-  const auto &Loc = S.Current->getSource(OpPC);
 
   if (S.getLangOpts().CPlusPlus26)
 return true;
 
+  const auto &Loc = S.Current->getSource(OpPC);
+
   if (const auto *NewExpr = dyn_cast(E)) {
 const FunctionDecl *OperatorNew = NewExpr->getOperatorNew();
 

``




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


[clang] [clang][bytecode] Support ImplicitValueInitExpr for multi-dim arrays (PR #117312)

2024-11-22 Thread Timm Baeder via cfe-commits

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

The attached test case from https://github.com/llvm/llvm-project/issues/117294 
used to cause an assertion because we called classifPrim() on an array type.

The new result doesn't crash but isn't exactly perfect either. Since the 
problem arises when evaluating an ImplicitValueInitExpr, we have no proper 
source location to point to. Point to the caller instead.

>From a1c94470dc152ecfe005bbc08e3b0641e9b957a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 22 Nov 2024 11:12:46 +0100
Subject: [PATCH] [clang][bytecode] Support ImplicitValueInitExpr for multi-dim
 arrays

The attached test case from https://github.com/llvm/llvm-project/issues/117294
used to cause an assertion because we called classifPrim() on an array
type.

The new result doesn't crash but isn't exactly perfect either. Since
the problem arises when evaluating an ImplicitValueInitExpr, we have
no proper source location to point to. Point to the caller instead.
---
 clang/lib/AST/ByteCode/Compiler.cpp   | 79 +++
 clang/lib/AST/ByteCode/Compiler.h |  1 +
 clang/lib/AST/ByteCode/InterpFrame.cpp|  7 +-
 clang/test/AST/ByteCode/placement-new.cpp | 16 -
 4 files changed, 73 insertions(+), 30 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 7cf2519d6a71fb..eb619e65a7bfce 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1642,22 +1642,8 @@ bool Compiler::VisitImplicitValueInitExpr(
   if (QT->isIncompleteArrayType())
 return true;
 
-  if (QT->isArrayType()) {
-const ArrayType *AT = QT->getAsArrayTypeUnsafe();
-assert(AT);
-const auto *CAT = cast(AT);
-size_t NumElems = CAT->getZExtSize();
-PrimType ElemT = classifyPrim(CAT->getElementType());
-
-for (size_t I = 0; I != NumElems; ++I) {
-  if (!this->visitZeroInitializer(ElemT, CAT->getElementType(), E))
-return false;
-  if (!this->emitInitElem(ElemT, I, E))
-return false;
-}
-
-return true;
-  }
+  if (QT->isArrayType())
+return this->visitZeroArrayInitializer(QT, E);
 
   if (const auto *ComplexTy = E->getType()->getAs()) {
 assert(Initializing);
@@ -3916,18 +3902,9 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
   return false;
   }
 } else if (D->isCompositeArray()) {
-  const Record *ElemRecord = D->ElemDesc->ElemRecord;
-  assert(D->ElemDesc->ElemRecord);
-  for (uint32_t I = 0, N = D->getNumElems(); I != N; ++I) {
-if (!this->emitConstUint32(I, E))
-  return false;
-if (!this->emitArrayElemPtr(PT_Uint32, E))
-  return false;
-if (!this->visitZeroRecordInitializer(ElemRecord, E))
-  return false;
-if (!this->emitPopPtr(E))
-  return false;
-  }
+  // Can't be a vector or complex field.
+  if (!this->visitZeroArrayInitializer(D->getType(), E))
+return false;
 } else if (D->isRecord()) {
   if (!this->visitZeroRecordInitializer(D->ElemRecord, E))
 return false;
@@ -3958,6 +3935,52 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
   return true;
 }
 
+template 
+bool Compiler::visitZeroArrayInitializer(QualType T, const Expr *E) {
+  assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
+  const ArrayType *AT = T->getAsArrayTypeUnsafe();
+  QualType ElemType = AT->getElementType();
+  size_t NumElems = cast(AT)->getZExtSize();
+
+  if (std::optional ElemT = classify(ElemType)) {
+for (size_t I = 0; I != NumElems; ++I) {
+  if (!this->visitZeroInitializer(*ElemT, ElemType, E))
+return false;
+  if (!this->emitInitElem(*ElemT, I, E))
+return false;
+}
+return true;
+  } else if (ElemType->isRecordType()) {
+const Record *R = getRecord(ElemType);
+
+for (size_t I = 0; I != NumElems; ++I) {
+  if (!this->emitConstUint32(I, E))
+return false;
+  if (!this->emitArrayElemPtr(PT_Uint32, E))
+return false;
+  if (!this->visitZeroRecordInitializer(R, E))
+return false;
+  if (!this->emitPopPtr(E))
+return false;
+}
+return true;
+  } else if (ElemType->isArrayType()) {
+for (size_t I = 0; I != NumElems; ++I) {
+  if (!this->emitConstUint32(I, E))
+return false;
+  if (!this->emitArrayElemPtr(PT_Uint32, E))
+return false;
+  if (!this->visitZeroArrayInitializer(ElemType, E))
+return false;
+  if (!this->emitPopPtr(E))
+return false;
+}
+return true;
+  }
+
+  return false;
+}
+
 template 
 template 
 bool Compiler::emitConst(T Value, PrimType Ty, const Expr *E) {
diff --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index d1b624daba6b99..2a94f5ec76b6c5 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/

[clang] [clang][bytecode] Support ImplicitValueInitExpr for multi-dim arrays (PR #117312)

2024-11-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

The attached test case from https://github.com/llvm/llvm-project/issues/117294 
used to cause an assertion because we called classifPrim() on an array type.

The new result doesn't crash but isn't exactly perfect either. Since the 
problem arises when evaluating an ImplicitValueInitExpr, we have no proper 
source location to point to. Point to the caller instead.

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


4 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+51-28) 
- (modified) clang/lib/AST/ByteCode/Compiler.h (+1) 
- (modified) clang/lib/AST/ByteCode/InterpFrame.cpp (+6-1) 
- (modified) clang/test/AST/ByteCode/placement-new.cpp (+15-1) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 7cf2519d6a71fb..eb619e65a7bfce 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1642,22 +1642,8 @@ bool Compiler::VisitImplicitValueInitExpr(
   if (QT->isIncompleteArrayType())
 return true;
 
-  if (QT->isArrayType()) {
-const ArrayType *AT = QT->getAsArrayTypeUnsafe();
-assert(AT);
-const auto *CAT = cast(AT);
-size_t NumElems = CAT->getZExtSize();
-PrimType ElemT = classifyPrim(CAT->getElementType());
-
-for (size_t I = 0; I != NumElems; ++I) {
-  if (!this->visitZeroInitializer(ElemT, CAT->getElementType(), E))
-return false;
-  if (!this->emitInitElem(ElemT, I, E))
-return false;
-}
-
-return true;
-  }
+  if (QT->isArrayType())
+return this->visitZeroArrayInitializer(QT, E);
 
   if (const auto *ComplexTy = E->getType()->getAs()) {
 assert(Initializing);
@@ -3916,18 +3902,9 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
   return false;
   }
 } else if (D->isCompositeArray()) {
-  const Record *ElemRecord = D->ElemDesc->ElemRecord;
-  assert(D->ElemDesc->ElemRecord);
-  for (uint32_t I = 0, N = D->getNumElems(); I != N; ++I) {
-if (!this->emitConstUint32(I, E))
-  return false;
-if (!this->emitArrayElemPtr(PT_Uint32, E))
-  return false;
-if (!this->visitZeroRecordInitializer(ElemRecord, E))
-  return false;
-if (!this->emitPopPtr(E))
-  return false;
-  }
+  // Can't be a vector or complex field.
+  if (!this->visitZeroArrayInitializer(D->getType(), E))
+return false;
 } else if (D->isRecord()) {
   if (!this->visitZeroRecordInitializer(D->ElemRecord, E))
 return false;
@@ -3958,6 +3935,52 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
   return true;
 }
 
+template 
+bool Compiler::visitZeroArrayInitializer(QualType T, const Expr *E) {
+  assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
+  const ArrayType *AT = T->getAsArrayTypeUnsafe();
+  QualType ElemType = AT->getElementType();
+  size_t NumElems = cast(AT)->getZExtSize();
+
+  if (std::optional ElemT = classify(ElemType)) {
+for (size_t I = 0; I != NumElems; ++I) {
+  if (!this->visitZeroInitializer(*ElemT, ElemType, E))
+return false;
+  if (!this->emitInitElem(*ElemT, I, E))
+return false;
+}
+return true;
+  } else if (ElemType->isRecordType()) {
+const Record *R = getRecord(ElemType);
+
+for (size_t I = 0; I != NumElems; ++I) {
+  if (!this->emitConstUint32(I, E))
+return false;
+  if (!this->emitArrayElemPtr(PT_Uint32, E))
+return false;
+  if (!this->visitZeroRecordInitializer(R, E))
+return false;
+  if (!this->emitPopPtr(E))
+return false;
+}
+return true;
+  } else if (ElemType->isArrayType()) {
+for (size_t I = 0; I != NumElems; ++I) {
+  if (!this->emitConstUint32(I, E))
+return false;
+  if (!this->emitArrayElemPtr(PT_Uint32, E))
+return false;
+  if (!this->visitZeroArrayInitializer(ElemType, E))
+return false;
+  if (!this->emitPopPtr(E))
+return false;
+}
+return true;
+  }
+
+  return false;
+}
+
 template 
 template 
 bool Compiler::emitConst(T Value, PrimType Ty, const Expr *E) {
diff --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index d1b624daba6b99..2a94f5ec76b6c5 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -325,6 +325,7 @@ class Compiler : public ConstStmtVisitor, 
bool>,
   /// Emits a zero initializer.
   bool visitZeroInitializer(PrimType T, QualType QT, const Expr *E);
   bool visitZeroRecordInitializer(const Record *R, const Expr *E);
+  bool visitZeroArrayInitializer(QualType T, const Expr *E);
 
   /// Emits an APSInt constant.
   bool emitConst(const llvm::APSInt &Value, PrimType Ty, const Expr *E);
diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp 
b/clang/lib/AST/ByteCode/InterpFrame.cpp
index 7f02464a1c0f14

[clang] [Clang] Enable -fpointer-tbaa by default. (PR #117244)

2024-11-22 Thread Florian Hahn via cfe-commits

fhahn wrote:

> This seems reasonable to me. Since it's standards-compliant, has a specific 
> opt-out flag, and is overridden by the general `-fno-strict-aliasing` flag, I 
> don't see any need for the RFC process. Still, you should definitely wait for 
> more feedback, especially from @AaronBallman.
> 
> This is not a prerequisite for landing the patch — or a requirement at all, 
> for that matter — but I think it'd be great if you could make a sort of 
> capstone post on the forums talking about this work and your performance 
> analysis in more detail.

Thanks @rjmccall, I'll try to write something up, although it might take a few 
weeks.

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits


@@ -7,3 +7,106 @@ struct S {
 };
 
 // CHECK: CXXMethodDecl {{.*}}clang::lifetime_capture_by(a, b, global)
+
+// 
+// Infer annotation for STL container methods.
+// 
+namespace __gnu_cxx {
+template 
+struct basic_iterator {};
+}
+
+namespace std {
+template class allocator {};
+template >
+struct vector {
+  typedef __gnu_cxx::basic_iterator iterator;
+  iterator begin();
+
+  vector();
+
+  void push_back(const T&);
+  void push_back(T&&);
+
+  void insert(iterator, T&&);
+};
+} // namespace std
+struct [[gsl::Pointer()]] View {};
+std::vector views;
+// CHECK:   ClassTemplateSpecializationDecl {{.*}} struct vector definition 
implicit_instantiation
+// CHECK:   TemplateArgument type 'View'
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (const View &)'
+// CHECK:   ParmVarDecl {{.*}} 'const View &'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (View &&)'
+// CHECK:   ParmVarDecl {{.*}} 'View &&'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+
+// CHECK:   CXXMethodDecl {{.*}} insert 'void (iterator, View &&)'
+// CHECK:   ParmVarDecl {{.*}} 'iterator'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK:   ParmVarDecl {{.*}} 'View &&'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+template  struct [[gsl::Pointer()]] ViewTemplate {};
+std::vector> templated_views;
+// CHECK:   ClassTemplateSpecializationDecl {{.*}} struct vector definition 
implicit_instantiation
+// CHECK:   TemplateArgument type 'ViewTemplate'
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (const ViewTemplate 
&)'
+// CHECK:   ParmVarDecl {{.*}} 'const ViewTemplate &'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (ViewTemplate &&)'
+// CHECK:   ParmVarDecl {{.*}} 'ViewTemplate &&'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+
+// CHECK:   CXXMethodDecl {{.*}} insert 'void (iterator, ViewTemplate 
&&)'
+// CHECK:   ParmVarDecl {{.*}} 'iterator'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK:   ParmVarDecl {{.*}} 'ViewTemplate &&'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+std::vector pointers;
+// CHECK:   ClassTemplateSpecializationDecl {{.*}} struct vector definition 
implicit_instantiation
+// CHECK:   TemplateArgument type 'int *'
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (int *const &)'
+// CHECK:   ParmVarDecl {{.*}} 'int *const &'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (int *&&)'
+// CHECK:   ParmVarDecl {{.*}} 'int *&&'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+
+// CHECK:   CXXMethodDecl {{.*}} insert 'void (iterator, int *&&)'
+// CHECK:   ParmVarDecl {{.*}} 'iterator'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK:   ParmVarDecl {{.*}} 'int *&&'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+std::vector ints;
+// CHECK:   ClassTemplateSpecializationDecl {{.*}} struct vector definition 
implicit_instantiation
+// CHECK:   TemplateArgument type 'int'
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (const int &)'
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} push_back 'void (int &&)'
+// CHECK-NOT:   LifetimeCaptureByAttr
+
+// CHECK:   CXXMethodDecl {{.*}} insert 'void (iterator, int &&)'
+// CHECK:   ParmVarDecl {{.*}} 'iterator'
+// CHECK:   LifetimeCaptureByAttr {{.*}} Implicit
+// CHECK-NOT:   LifetimeCaptureByAttr

usx95 wrote:

Done.

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/117122

>From 9a57223b06a8331a0ef123739a430863dee19d98 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 21 Nov 2024 07:00:56 +
Subject: [PATCH 1/4] [clang] Infer lifetime_capture_by for STL containers

---
 clang/include/clang/Sema/Sema.h   |  3 +
 clang/lib/Sema/SemaAttr.cpp   | 34 
 clang/lib/Sema/SemaDecl.cpp   |  2 +
 clang/test/Sema/Inputs/lifetime-analysis.h|  5 ++
 .../warn-lifetime-analysis-capture-by.cpp | 79 +++
 5 files changed, 123 insertions(+)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6ea6c67447b6f0..9bafcfec5d4786 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1757,6 +1757,9 @@ class Sema final : public SemaBase {
   /// Add [[clang:::lifetimebound]] attr for std:: functions and methods.
   void inferLifetimeBoundAttribute(FunctionDecl *FD);
 
+  /// Add [[clang:::lifetime_capture(this)]] to STL container methods.
+  void inferLifetimeCaptureByAttribute(FunctionDecl *FD);
+
   /// Add [[gsl::Pointer]] attributes for std:: types.
   void inferGslPointerAttribute(TypedefNameDecl *TD);
 
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 9fbad7ed67ccbe..507f7c40d58782 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -268,6 +268,40 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
   }
 }
 
+static bool IsPointerLikeType(QualType QT) {
+  QT = QT.getNonReferenceType();
+  if (QT->isPointerType())
+return true;
+  auto *RD = QT->getAsCXXRecordDecl();
+  if (!RD)
+return false;
+  RD = RD->getCanonicalDecl();
+  if (auto *CTSD = dyn_cast(RD))
+RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
+  return RD->hasAttr();
+}
+
+void Sema::inferLifetimeCaptureByAttribute(FunctionDecl *FD) {
+  if (!FD)
+return;
+  auto *MD = dyn_cast(FD);
+  if (!MD || !MD->getIdentifier() || !MD->getParent()->isInStdNamespace())
+return;
+  static const llvm::StringSet<> CapturingMethods{"insert", "push",
+  "push_front", "push_back"};
+  if (!CapturingMethods.contains(MD->getName()))
+return;
+  for (ParmVarDecl *PVD : MD->parameters()) {
+if (PVD->hasAttr())
+  return;
+if (IsPointerLikeType(PVD->getType())) {
+  int CaptureByThis[] = {LifetimeCaptureByAttr::THIS};
+  PVD->addAttr(
+  LifetimeCaptureByAttr::CreateImplicit(Context, CaptureByThis, 1));
+}
+  }
+}
+
 void Sema::inferNullableClassAttribute(CXXRecordDecl *CRD) {
   static const llvm::StringSet<> Nullable{
   "auto_ptr", "shared_ptr", "unique_ptr", "exception_ptr",
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index be570f3a1829d0..5b30d0f2c22d16 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11913,6 +11913,7 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   NamedDecl *OldDecl = nullptr;
   bool MayNeedOverloadableChecks = false;
 
+  inferLifetimeCaptureByAttribute(NewFD);
   // Merge or overload the declaration with an existing declaration of
   // the same name, if appropriate.
   if (!Previous.empty()) {
@@ -16716,6 +16717,7 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) 
{
 
   LazyProcessLifetimeCaptureByParams(FD);
   inferLifetimeBoundAttribute(FD);
+  inferLifetimeCaptureByAttribute(FD);
   AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction(FD);
 
   // If C++ exceptions are enabled but we are told extern "C" functions cannot
diff --git a/clang/test/Sema/Inputs/lifetime-analysis.h 
b/clang/test/Sema/Inputs/lifetime-analysis.h
index 41d1e2f074cc83..5c151385b1fe5a 100644
--- a/clang/test/Sema/Inputs/lifetime-analysis.h
+++ b/clang/test/Sema/Inputs/lifetime-analysis.h
@@ -49,6 +49,11 @@ struct vector {
vector(InputIterator first, InputIterator __last);
 
   T &at(int n);
+
+  void push_back(const T&);
+  void push_back(T&&);
+  
+  void insert(iterator, T&&);
 };
 
 template
diff --git a/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp 
b/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp
index b3fde386b8616c..462cb2d3f3fd6e 100644
--- a/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp
+++ b/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp
@@ -366,3 +366,82 @@ void use() {
   capture3(std::string(), x3); // expected-warning {{object whose reference is 
captured by 'x3' will be destroyed at the end of the full-expression}}
 }
 } // namespace temporary_views
+
+// 
+// Inferring annotation for STL containers
+// 
+namespace inferred_capture_by {
+const std::string* getLifetimeBoundPointer(const std::string &s 
[[clang::lifetimebound]

[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits


@@ -7,3 +7,106 @@ struct S {
 };
 
 // CHECK: CXXMethodDecl {{.*}}clang::lifetime_capture_by(a, b, global)
+
+// 
+// Infer annotation for STL container methods.
+// 
+namespace __gnu_cxx {
+template 
+struct basic_iterator {};
+}
+
+namespace std {
+template class allocator {};
+template >
+struct vector {
+  typedef __gnu_cxx::basic_iterator iterator;
+  iterator begin();
+
+  vector();
+
+  void push_back(const T&);
+  void push_back(T&&);
+
+  void insert(iterator, T&&);
+};
+} // namespace std
+struct [[gsl::Pointer()]] View {};
+std::vector views;
+// CHECK:   ClassTemplateSpecializationDecl {{.*}} struct vector definition 
implicit_instantiation
+// CHECK:   TemplateArgument type 'View'
+// CHECK-NOT:   LifetimeCaptureByAttr

usx95 wrote:

No. That would add the annotation to all of its specializations which is not 
something we want.

Tested: Added an extra `// CHECK-NOT:   LifetimeCaptureByAttr` before the 
beginning of the tests as well.

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


[clang] [clang] Allow delayed function instantiation at TU end if initial instantiation fails (PR #117167)

2024-11-22 Thread via cfe-commits

https://github.com/StefanPaulet updated 
https://github.com/llvm/llvm-project/pull/117167

>From 54199baf4a6a205e0b85f9f528a90b8170a960fa Mon Sep 17 00:00:00 2001
From: StefanPaulet 
Date: Thu, 21 Nov 2024 15:32:56 +0200
Subject: [PATCH 1/4] [clang] Allow delayed function instantiation at TU end if
 initial instantiation fails

---
 clang/include/clang/Sema/Sema.h   | 11 +---
 clang/lib/Sema/Sema.cpp   |  2 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 14 +-
 .../instantiate-function-delayed.cpp  | 26 +++
 4 files changed, 42 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/SemaTemplate/instantiate-function-delayed.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6ea6c67447b6f0..ce27260bc78801 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13523,7 +13523,9 @@ class Sema final : public SemaBase {
   S.PendingLocalImplicitInstantiations);
 }
 
-void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/true); }
+void perform(bool AtEndOfTU = false) {
+  S.PerformPendingInstantiations(/*LocalOnly=*/true, AtEndOfTU);
+}
 
 ~LocalEagerInstantiationScope() {
   assert(S.PendingLocalImplicitInstantiations.empty() &&
@@ -13568,10 +13570,10 @@ class Sema final : public SemaBase {
   S.SavedVTableUses.back().swap(S.VTableUses);
 }
 
-void perform() {
+void perform(bool AtEndOfTU = false) {
   if (Enabled) {
 S.DefineUsedVTables();
-S.PerformPendingInstantiations();
+S.PerformPendingInstantiations(false, AtEndOfTU);
   }
 }
 
@@ -13790,7 +13792,8 @@ class Sema final : public SemaBase {
 
   /// Performs template instantiation for all implicit template
   /// instantiations we have seen until this point.
-  void PerformPendingInstantiations(bool LocalOnly = false);
+  void PerformPendingInstantiations(bool LocalOnly = false,
+bool AtEndOfTU = false);
 
   TemplateParameterList *
   SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 942e7ece4283e3..c97a253239df2b 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1138,7 +1138,7 @@ void 
Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
 
   {
 llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
-PerformPendingInstantiations();
+PerformPendingInstantiations(false, true);
   }
 
   emitDeferredDiags();
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 10efde7c3fe540..0f9a39062750bc 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5267,9 +5267,9 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 
   // This class may have local implicit instantiations that need to be
   // instantiation within this scope.
-  LocalInstantiations.perform();
+  LocalInstantiations.perform(AtEndOfTU);
   Scope.Exit();
-  GlobalInstantiations.perform();
+  GlobalInstantiations.perform(AtEndOfTU);
 }
 
 VarTemplateSpecializationDecl *Sema::BuildVarTemplateInstantiation(
@@ -5612,9 +5612,9 @@ void Sema::InstantiateVariableDefinition(SourceLocation 
PointOfInstantiation,
 
   // This variable may have local implicit instantiations that need to be
   // instantiated within this scope.
-  LocalInstantiations.perform();
+  LocalInstantiations.perform(AtEndOfTU);
   Local.Exit();
-  GlobalInstantiations.perform();
+  GlobalInstantiations.perform(AtEndOfTU);
 }
   } else {
 assert(Var->isStaticDataMember() && PatternDecl->isStaticDataMember() &&
@@ -6448,7 +6448,7 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, 
NamedDecl *D,
   return D;
 }
 
-void Sema::PerformPendingInstantiations(bool LocalOnly) {
+void Sema::PerformPendingInstantiations(bool LocalOnly, bool AtEndOfTU) {
   std::deque delayedPCHInstantiations;
   while (!PendingLocalImplicitInstantiations.empty() ||
  (!LocalOnly && !PendingInstantiations.empty())) {
@@ -6476,9 +6476,11 @@ void Sema::PerformPendingInstantiations(bool LocalOnly) {
 });
   } else {
 InstantiateFunctionDefinition(/*FIXME:*/ Inst.second, Function, true,
-  DefinitionRequired, true);
+  DefinitionRequired, AtEndOfTU);
 if (Function->isDefined())
   Function->setInstantiationIsPending(false);
+else if (!AtEndOfTU)
+  LateParsedInstantiations.push_back(Inst);
   }
   // Definition of a PCH-ed template declaration may be available only in 
the TU.
   if (!LocalOnly && LangOpts.PCHInstantiateTemplates &&
diff --git a/clang/test/SemaTemplate/instantiate-function-delayed.cpp 
b/clang/t

[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Haojian Wu via cfe-commits


@@ -268,6 +268,40 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
   }
 }
 
+static bool IsPointerLikeType(QualType QT) {
+  QT = QT.getNonReferenceType();
+  if (QT->isPointerType())
+return true;
+  auto *RD = QT->getAsCXXRecordDecl();
+  if (!RD)
+return false;
+  RD = RD->getCanonicalDecl();
+  if (auto *CTSD = dyn_cast(RD))
+RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();

hokein wrote:

hmm, this is strange. I tested it locally, it works for me.

```
$ cat /t/t6.cpp
#include 

template
struct [[gsl::Pointer]] Span {
  Span(const std::vector &V);
};

void use() {
  Span pp(std::vector{});
  std::vector> spans;
  spans.push_back(std::vector()); // warning.
}
$ ./bin/clang -Xclang -fsyntax-only -Wdangling-capture /t/t6.cpp

 <<<

/t/t6.cpp:9:16: warning: object backing the pointer will be destroyed at the 
end of the full-expression [-Wdangling-gsl]
9 |   Span pp(std::vector{});
  |^~
/t/t6.cpp:11:19: warning: object whose reference is captured by 'spans' will be 
destroyed at the end of the full-expression [-Wdangling-capture]
   11 |   spans.push_back(std::vector()); // warning.
  |   ^~
2 warnings generated.
/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

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


[clang-tools-extra] [clangd] Check getFunctionTypeLoc() for validity in InlayHintVisitor (PR #117296)

2024-11-22 Thread Nathan Ridge via cfe-commits

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


[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-11-22 Thread Chris Copeland via cfe-commits

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


[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)

2024-11-22 Thread Lu Weining via cfe-commits


@@ -2011,8 +2011,9 @@ const StringMap sys::getHostCPUFeatures() {
 const StringMap sys::getHostCPUFeatures() {
   unsigned long hwcap = getauxval(AT_HWCAP);
   bool HasFPU = hwcap & (1UL << 3); // HWCAP_LOONGARCH_FPU
-  uint32_t cpucfg2 = 0x2;
+  uint32_t cpucfg2 = 0x2, cpucfg3 = 0x3;

SixWeining wrote:

```suggestion
  const uint32_t cpucfg2 = 0x2, cpucfg3 = 0x3;
```

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


[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)

2024-11-22 Thread Lu Weining via cfe-commits

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

LGTM except a nit.

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


[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)

2024-11-22 Thread Lu Weining via cfe-commits

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


[clang] [clang][bytecode] Fix bitcasting from null pointers (PR #116999)

2024-11-22 Thread Timm Baeder via cfe-commits

tbaederr wrote:

This needs to incorporate the resolution from 
https://github.com/llvm/llvm-project/issues/117166, but that doesn't work 
properly without https://github.com/llvm/llvm-project/pull/116843 mergged first.

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


[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-11-22 Thread Chris Copeland via cfe-commits

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/117122

>From 9a57223b06a8331a0ef123739a430863dee19d98 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 21 Nov 2024 07:00:56 +
Subject: [PATCH 1/2] [clang] Infer lifetime_capture_by for STL containers

---
 clang/include/clang/Sema/Sema.h   |  3 +
 clang/lib/Sema/SemaAttr.cpp   | 34 
 clang/lib/Sema/SemaDecl.cpp   |  2 +
 clang/test/Sema/Inputs/lifetime-analysis.h|  5 ++
 .../warn-lifetime-analysis-capture-by.cpp | 79 +++
 5 files changed, 123 insertions(+)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6ea6c67447b6f0..9bafcfec5d4786 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1757,6 +1757,9 @@ class Sema final : public SemaBase {
   /// Add [[clang:::lifetimebound]] attr for std:: functions and methods.
   void inferLifetimeBoundAttribute(FunctionDecl *FD);
 
+  /// Add [[clang:::lifetime_capture(this)]] to STL container methods.
+  void inferLifetimeCaptureByAttribute(FunctionDecl *FD);
+
   /// Add [[gsl::Pointer]] attributes for std:: types.
   void inferGslPointerAttribute(TypedefNameDecl *TD);
 
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 9fbad7ed67ccbe..507f7c40d58782 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -268,6 +268,40 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
   }
 }
 
+static bool IsPointerLikeType(QualType QT) {
+  QT = QT.getNonReferenceType();
+  if (QT->isPointerType())
+return true;
+  auto *RD = QT->getAsCXXRecordDecl();
+  if (!RD)
+return false;
+  RD = RD->getCanonicalDecl();
+  if (auto *CTSD = dyn_cast(RD))
+RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
+  return RD->hasAttr();
+}
+
+void Sema::inferLifetimeCaptureByAttribute(FunctionDecl *FD) {
+  if (!FD)
+return;
+  auto *MD = dyn_cast(FD);
+  if (!MD || !MD->getIdentifier() || !MD->getParent()->isInStdNamespace())
+return;
+  static const llvm::StringSet<> CapturingMethods{"insert", "push",
+  "push_front", "push_back"};
+  if (!CapturingMethods.contains(MD->getName()))
+return;
+  for (ParmVarDecl *PVD : MD->parameters()) {
+if (PVD->hasAttr())
+  return;
+if (IsPointerLikeType(PVD->getType())) {
+  int CaptureByThis[] = {LifetimeCaptureByAttr::THIS};
+  PVD->addAttr(
+  LifetimeCaptureByAttr::CreateImplicit(Context, CaptureByThis, 1));
+}
+  }
+}
+
 void Sema::inferNullableClassAttribute(CXXRecordDecl *CRD) {
   static const llvm::StringSet<> Nullable{
   "auto_ptr", "shared_ptr", "unique_ptr", "exception_ptr",
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index be570f3a1829d0..5b30d0f2c22d16 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11913,6 +11913,7 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   NamedDecl *OldDecl = nullptr;
   bool MayNeedOverloadableChecks = false;
 
+  inferLifetimeCaptureByAttribute(NewFD);
   // Merge or overload the declaration with an existing declaration of
   // the same name, if appropriate.
   if (!Previous.empty()) {
@@ -16716,6 +16717,7 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) 
{
 
   LazyProcessLifetimeCaptureByParams(FD);
   inferLifetimeBoundAttribute(FD);
+  inferLifetimeCaptureByAttribute(FD);
   AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction(FD);
 
   // If C++ exceptions are enabled but we are told extern "C" functions cannot
diff --git a/clang/test/Sema/Inputs/lifetime-analysis.h 
b/clang/test/Sema/Inputs/lifetime-analysis.h
index 41d1e2f074cc83..5c151385b1fe5a 100644
--- a/clang/test/Sema/Inputs/lifetime-analysis.h
+++ b/clang/test/Sema/Inputs/lifetime-analysis.h
@@ -49,6 +49,11 @@ struct vector {
vector(InputIterator first, InputIterator __last);
 
   T &at(int n);
+
+  void push_back(const T&);
+  void push_back(T&&);
+  
+  void insert(iterator, T&&);
 };
 
 template
diff --git a/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp 
b/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp
index b3fde386b8616c..462cb2d3f3fd6e 100644
--- a/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp
+++ b/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp
@@ -366,3 +366,82 @@ void use() {
   capture3(std::string(), x3); // expected-warning {{object whose reference is 
captured by 'x3' will be destroyed at the end of the full-expression}}
 }
 } // namespace temporary_views
+
+// 
+// Inferring annotation for STL containers
+// 
+namespace inferred_capture_by {
+const std::string* getLifetimeBoundPointer(const std::string &s 
[[clang::lifetimebound]

[clang] [HLSL] Get the index for resource bindings from the slot (PR #117303)

2024-11-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Justin Bogner (bogner)


Changes

Resource bindings are indexed from the beginning of the binding space, not from 
the binding itself. This means that we need to populate the index for non-array 
resources with the same value as the slot number (and arrays, when we implement 
them, will be the sum of the slot number and the access index).

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


4 Files Affected:

- (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl (+1-1) 
- (modified) 
clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl (+10-10) 
- (added) clang/test/CodeGenHLSL/resource-bindings.hlsl (+19) 


``diff
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 7ba0d615018181..b4e17466087b16 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -588,7 +588,7 @@ llvm::Function 
*CGHLSLRuntime::createResourceBindingInitFn() {
   auto *Slot = llvm::ConstantInt::get(CGM.IntTy, RBA->getSlotNumber());
   // FIXME: resource arrays are not yet implemented
   auto *Range = llvm::ConstantInt::get(CGM.IntTy, 1);
-  auto *Index = llvm::ConstantInt::get(CGM.IntTy, 0);
+  auto *Index = llvm::ConstantInt::get(CGM.IntTy, RBA->getSlotNumber());
   // FIXME: NonUniformResourceIndex bit is not yet implemented
   auto *NonUniform = llvm::ConstantInt::get(Int1Ty, false);
   llvm::Value *Args[] = {Space, Slot, Range, Index, NonUniform};
diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl
index 3949f7b943cfe0..a820d782896aaf 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl
@@ -19,7 +19,7 @@ RWBuffer Buf : register(u5, space3);
 
 // CHECK: define internal void @_init_resource_bindings() {
 // CHECK-NEXT: entry:
-// CHECK-DXIL-NEXT: %Buf_h = call target("dx.TypedBuffer", float, 1, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_f32_1_0_0t(i32 3, i32 5, i32 1, i32 
0, i1 false)
+// CHECK-DXIL-NEXT: %Buf_h = call target("dx.TypedBuffer", float, 1, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_f32_1_0_0t(i32 3, i32 5, i32 1, i32 
5, i1 false)
 // CHECK-DXIL-NEXT: store target("dx.TypedBuffer", float, 1, 0, 0) %Buf_h, ptr 
@Buf, align 4
 // CHECK-SPIRV-NEXT: %Buf_h = call target("dx.TypedBuffer", float, 1, 0, 0) 
@llvm.spv.handle.fromBinding.tdx.TypedBuffer_f32_1_0_0t(i32 3, i32 5, i32 1, 
i32 0, i1 false)
 // CHECK-SPIRV-NEXT: store target("dx.TypedBuffer", float, 1, 0, 0) %Buf_h, 
ptr @Buf, align 4
diff --git 
a/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl 
b/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl
index 2e141b9279fa61..d7478c2981a85d 100644
--- a/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl
@@ -37,24 +37,24 @@ RasterizerOrderedStructuredBuffer Buf5 : 
register(u1, space2);
 
 // CHECK: define internal void @_init_resource_bindings() {
 // CHECK-NEXT: entry:
-// CHECK-DXIL-NEXT: %Buf_h = call target("dx.RawBuffer", float, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_0_0t(i32 0, i32 10, i32 1, i32 0, 
i1 false)
+// CHECK-DXIL-NEXT: %Buf_h = call target("dx.RawBuffer", float, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_0_0t(i32 0, i32 10, i32 1, i32 
10, i1 false)
 // CHECK-DXIL-NEXT: store target("dx.RawBuffer", float, 0, 0) %Buf_h, ptr 
@Buf, align 4
-// CHECK-DXIL-NEXT: %Buf2_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 1, i32 5, i32 1, i32 0, 
i1 false)
+// CHECK-DXIL-NEXT: %Buf2_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 1, i32 5, i32 1, i32 5, 
i1 false)
 // CHECK-DXIL-NEXT: store target("dx.RawBuffer", float, 1, 0) %Buf2_h, ptr 
@Buf2, align 4
-// CHECK-DXIL-NEXT: %Buf3_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 0, i32 3, i32 1, i32 0, 
i1 false)
+// CHECK-DXIL-NEXT: %Buf3_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 0, i32 3, i32 1, i32 3, 
i1 false)
 // CHECK-DXIL-NEXT: store target("dx.RawBuffer", float, 1, 0) %Buf3_h, ptr 
@Buf3, align 4
-// CHECK-DXIL-NEXT: %Buf4_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 0, i32 4, i32 1, i32 0, 
i1 false)
+// CHECK-DXIL-NEXT: %Buf4_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 0, i32 4, i32 1, i32 4, 
i1 false)
 // CHECK-DXIL-NEXT: store target("dx.RawBuffer", float, 1, 0) %Buf4_h, ptr 
@Buf4, align 4
-// CHECK-DXIL-NEXT: %Buf5_h = cal

[clang] [HLSL] Get the index for resource bindings from the slot (PR #117303)

2024-11-22 Thread Justin Bogner via cfe-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/117303

Resource bindings are indexed from the beginning of the binding space, not from 
the binding itself. This means that we need to populate the index for non-array 
resources with the same value as the slot number (and arrays, when we implement 
them, will be the sum of the slot number and the access index).

>From 05f412f47b8d30ff1db9372225001c75289bed44 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Thu, 21 Nov 2024 23:18:13 -0800
Subject: [PATCH] [HLSL] Get the index for resource bindings from the slot

Resource bindings are indexed from the beginning of the binding space, not from
the binding itself. This means that we need to populate the index for non-array
resources with the same value as the slot number (and arrays, when we implement
them, will be the sum of the slot number and the access index).
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  2 +-
 .../builtins/RWBuffer-constructor.hlsl|  2 +-
 .../StructuredBuffers-constructors.hlsl   | 20 +--
 clang/test/CodeGenHLSL/resource-bindings.hlsl | 19 ++
 4 files changed, 31 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/resource-bindings.hlsl

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 7ba0d615018181..b4e17466087b16 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -588,7 +588,7 @@ llvm::Function 
*CGHLSLRuntime::createResourceBindingInitFn() {
   auto *Slot = llvm::ConstantInt::get(CGM.IntTy, RBA->getSlotNumber());
   // FIXME: resource arrays are not yet implemented
   auto *Range = llvm::ConstantInt::get(CGM.IntTy, 1);
-  auto *Index = llvm::ConstantInt::get(CGM.IntTy, 0);
+  auto *Index = llvm::ConstantInt::get(CGM.IntTy, RBA->getSlotNumber());
   // FIXME: NonUniformResourceIndex bit is not yet implemented
   auto *NonUniform = llvm::ConstantInt::get(Int1Ty, false);
   llvm::Value *Args[] = {Space, Slot, Range, Index, NonUniform};
diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl
index 3949f7b943cfe0..a820d782896aaf 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl
@@ -19,7 +19,7 @@ RWBuffer Buf : register(u5, space3);
 
 // CHECK: define internal void @_init_resource_bindings() {
 // CHECK-NEXT: entry:
-// CHECK-DXIL-NEXT: %Buf_h = call target("dx.TypedBuffer", float, 1, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_f32_1_0_0t(i32 3, i32 5, i32 1, i32 
0, i1 false)
+// CHECK-DXIL-NEXT: %Buf_h = call target("dx.TypedBuffer", float, 1, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_f32_1_0_0t(i32 3, i32 5, i32 1, i32 
5, i1 false)
 // CHECK-DXIL-NEXT: store target("dx.TypedBuffer", float, 1, 0, 0) %Buf_h, ptr 
@Buf, align 4
 // CHECK-SPIRV-NEXT: %Buf_h = call target("dx.TypedBuffer", float, 1, 0, 0) 
@llvm.spv.handle.fromBinding.tdx.TypedBuffer_f32_1_0_0t(i32 3, i32 5, i32 1, 
i32 0, i1 false)
 // CHECK-SPIRV-NEXT: store target("dx.TypedBuffer", float, 1, 0, 0) %Buf_h, 
ptr @Buf, align 4
diff --git 
a/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl 
b/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl
index 2e141b9279fa61..d7478c2981a85d 100644
--- a/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl
@@ -37,24 +37,24 @@ RasterizerOrderedStructuredBuffer Buf5 : 
register(u1, space2);
 
 // CHECK: define internal void @_init_resource_bindings() {
 // CHECK-NEXT: entry:
-// CHECK-DXIL-NEXT: %Buf_h = call target("dx.RawBuffer", float, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_0_0t(i32 0, i32 10, i32 1, i32 0, 
i1 false)
+// CHECK-DXIL-NEXT: %Buf_h = call target("dx.RawBuffer", float, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_0_0t(i32 0, i32 10, i32 1, i32 
10, i1 false)
 // CHECK-DXIL-NEXT: store target("dx.RawBuffer", float, 0, 0) %Buf_h, ptr 
@Buf, align 4
-// CHECK-DXIL-NEXT: %Buf2_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 1, i32 5, i32 1, i32 0, 
i1 false)
+// CHECK-DXIL-NEXT: %Buf2_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 1, i32 5, i32 1, i32 5, 
i1 false)
 // CHECK-DXIL-NEXT: store target("dx.RawBuffer", float, 1, 0) %Buf2_h, ptr 
@Buf2, align 4
-// CHECK-DXIL-NEXT: %Buf3_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 0, i32 3, i32 1, i32 0, 
i1 false)
+// CHECK-DXIL-NEXT: %Buf3_h = call target("dx.RawBuffer", float, 1, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 0, i32 3, i32 1, i32 3, 
i1 false)
 // CHECK-DXIL-NEXT: store target("dx.RawBuffer", float, 1,

[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-11-22 Thread Chris Copeland via cfe-commits

chrisnc wrote:

> One use case I'd want to keep working is where we have two functions in the 
> same object that are hardfp with hardware registers, and soft (with or 
> without hardware registers). Something like:
> 
> ```
> __attribute__((target("arch=cortex-m33"))) __attribute__((pcs("aapcs-vfp"))) 
> float f1(float a, float b) {
>   return a + b;
> }
> 
> __attribute__((target("arch=cortex-m0"))) __attribute__((pcs("aapcs"))) float 
> f2(float a, float b) {
>   return a + b;
> }
> ```
> 
> There are some source files that do run-time selection based on hardware 
> detection.

I can confirm that this does not emit an error.
The way this change is implemented, each function will be checked for 
consistency of ABI + features, and both of these are fine, so there's no issue.

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits


@@ -268,6 +268,40 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
   }
 }
 
+static bool IsPointerLikeType(QualType QT) {
+  QT = QT.getNonReferenceType();
+  if (QT->isPointerType())
+return true;
+  auto *RD = QT->getAsCXXRecordDecl();
+  if (!RD)
+return false;
+  RD = RD->getCanonicalDecl();
+  if (auto *CTSD = dyn_cast(RD))
+RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();

usx95 wrote:

We fail to detect pointer types which are templates:
```cpp
template  struct [[gsl::Pointer()]] ViewTemplate {};
std::vector> templated_views;
```

```cpp
template
struct [[gsl::Pointer]] Span {
  Span(const std::vector &V);
};

void use() {
  std::vector> spans;
  spans.push_back(std::vector{1, 2, 3}); // warning.
}
```


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


[clang] b36fcf4 - [RISCV] Rename variable CPUModel to Model

2024-11-22 Thread Wang Pengcheng via cfe-commits

Author: Wang Pengcheng
Date: 2024-11-22T20:12:28+08:00
New Revision: b36fcf4f493ad9d30455e178076d91be99f3a7d8

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

LOG: [RISCV] Rename variable CPUModel to Model

The variable name can't be the same as the struct name or we will
have "error: declaration of ‘llvm::RISCV::CPUModel 
llvm::RISCV::CPUInfo::CPUModel’
changes meaning of ‘CPUModel’ [-fpermissive]".

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
llvm/include/llvm/TargetParser/RISCVTargetParser.h
llvm/lib/TargetParser/RISCVTargetParser.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index caf5e40429838b..4b96bdb709c777 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -22715,22 +22715,22 @@ Value *CodeGenFunction::EmitRISCVCpuIs(StringRef 
CPUStr) {
 return CPUID;
   };
 
-  const llvm::RISCV::CPUModel CPUModel = llvm::RISCV::getCPUModel(CPUStr);
+  const llvm::RISCV::CPUModel Model = llvm::RISCV::getCPUModel(CPUStr);
 
   // Compare mvendorid.
   Value *VendorID = loadRISCVCPUID(0);
   Value *Result =
-  Builder.CreateICmpEQ(VendorID, Builder.getInt32(CPUModel.MVendorID));
+  Builder.CreateICmpEQ(VendorID, Builder.getInt32(Model.MVendorID));
 
   // Compare marchid.
   Value *ArchID = loadRISCVCPUID(1);
   Result = Builder.CreateAnd(
-  Result, Builder.CreateICmpEQ(ArchID, 
Builder.getInt64(CPUModel.MArchID)));
+  Result, Builder.CreateICmpEQ(ArchID, Builder.getInt64(Model.MArchID)));
 
   // Compare mimpid.
   Value *ImpID = loadRISCVCPUID(2);
   Result = Builder.CreateAnd(
-  Result, Builder.CreateICmpEQ(ImpID, Builder.getInt64(CPUModel.MImpID)));
+  Result, Builder.CreateICmpEQ(ImpID, Builder.getInt64(Model.MImpID)));
 
   return Result;
 }

diff  --git a/llvm/include/llvm/TargetParser/RISCVTargetParser.h 
b/llvm/include/llvm/TargetParser/RISCVTargetParser.h
index 71035dbe10e5e0..c237e1ddd6b381 100644
--- a/llvm/include/llvm/TargetParser/RISCVTargetParser.h
+++ b/llvm/include/llvm/TargetParser/RISCVTargetParser.h
@@ -43,7 +43,7 @@ struct CPUInfo {
   StringLiteral DefaultMarch;
   bool FastScalarUnalignedAccess;
   bool FastVectorUnalignedAccess;
-  CPUModel CPUModel;
+  CPUModel Model;
   bool is64Bit() const { return DefaultMarch.starts_with("rv64"); }
 };
 

diff  --git a/llvm/lib/TargetParser/RISCVTargetParser.cpp 
b/llvm/lib/TargetParser/RISCVTargetParser.cpp
index 3442f74fb7f249..625645a99e12fc 100644
--- a/llvm/lib/TargetParser/RISCVTargetParser.cpp
+++ b/llvm/lib/TargetParser/RISCVTargetParser.cpp
@@ -58,16 +58,15 @@ bool hasFastVectorUnalignedAccess(StringRef CPU) {
 }
 
 bool hasValidCPUModel(StringRef CPU) {
-  const CPUModel CPUModel = getCPUModel(CPU);
-  return CPUModel.MVendorID != 0 && CPUModel.MArchID != 0 &&
- CPUModel.MImpID != 0;
+  const CPUModel Model = getCPUModel(CPU);
+  return Model.MVendorID != 0 && Model.MArchID != 0 && Model.MImpID != 0;
 }
 
 CPUModel getCPUModel(StringRef CPU) {
   const CPUInfo *Info = getCPUInfoByName(CPU);
   if (!Info)
 return {0, 0, 0};
-  return Info->CPUModel;
+  return Info->Model;
 }
 
 bool parseCPU(StringRef CPU, bool IsRV64) {



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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Utkarsh Saxena via cfe-commits


@@ -7,3 +7,106 @@ struct S {
 };
 
 // CHECK: CXXMethodDecl {{.*}}clang::lifetime_capture_by(a, b, global)
+
+// 
+// Infer annotation for STL container methods.
+// 
+namespace __gnu_cxx {
+template 
+struct basic_iterator {};
+}
+
+namespace std {
+template class allocator {};
+template >
+struct vector {
+  typedef __gnu_cxx::basic_iterator iterator;
+  iterator begin();
+
+  vector();
+
+  void push_back(const T&);
+  void push_back(T&&);
+
+  void insert(iterator, T&&);
+};
+} // namespace std
+struct [[gsl::Pointer()]] View {};
+std::vector views;
+// CHECK:   ClassTemplateSpecializationDecl {{.*}} struct vector definition 
implicit_instantiation
+// CHECK:   TemplateArgument type 'View'
+// CHECK-NOT:   LifetimeCaptureByAttr

usx95 wrote:

Well this is along the lines of not having capture by on values and only for 
view types. For example:
```
  std::vector strings;
  strings.push_back(std::string());
  strings.insert(strings.begin(), std::string());
```

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


[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-11-22 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

I have managed to get a small example, but it only crashes for me if I run it 
directly through our internal build system (not even if I use the exact same 
Clang binary).

There are a few things that might affect that:
- the names of the modules used internally are different; I have simplified 
them to save some typing,
- the flags we pass are different, but most of them should not matter (various 
macros only used internally, etc).

I suspect there are some hash tables somewhere and the order of something gets 
affected by those two factors above or something else and we end up loosing the 
repro.
I will need a little more time to produce the exact same command lines and 
module map inputs and reduce them further, but I wanted to share the actual 
code that produces the "inline function not defined" error; just in case folks 
would have ideas on what might go wrong in those examples before I get a full 
repro.

[friends.tgz](https://github.com/user-attachments/files/17869931/friends.tgz)



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


[clang] [llvm] Codegen changes for strict modifier with grainsize/num_tasks of taskloop construct (PR #117196)

2024-11-22 Thread CHANDRA GHALE via cfe-commits

https://github.com/chandraghale updated 
https://github.com/llvm/llvm-project/pull/117196

>From d19f41d39237b3d4fd2923f037743ddd495d5c9f Mon Sep 17 00:00:00 2001
From: Chandra Ghale 
Date: Thu, 21 Nov 2024 11:15:11 -0600
Subject: [PATCH 1/3] Initial Codegen changes for strict modifier with
 grainsize/num_tasks of taskloop construct

---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp |  28 ++
 clang/lib/CodeGen/CGOpenMPRuntime.h   |   1 +
 clang/lib/CodeGen/CGStmtOpenMP.cpp|   2 +
 .../taskloop_strictmodifier_codegen.cpp   | 256 ++
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |   3 +
 5 files changed, 290 insertions(+)
 create mode 100644 clang/test/OpenMP/taskloop_strictmodifier_codegen.cpp

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index cc389974e04081..361550d2f102b4 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -4666,6 +4666,33 @@ void CGOpenMPRuntime::emitTaskLoopCall(CodeGenFunction 
&CGF, SourceLocation Loc,
CGF.getContext().VoidPtrTy);
   }
   enum { NoSchedule = 0, Grainsize = 1, NumTasks = 2 };
+  if( Data.HasModifier ){
+llvm::Value *TaskArgs[] = {
+  UpLoc,
+  ThreadID,
+  Result.NewTask,
+  IfVal,
+  LBLVal.getPointer(CGF),
+  UBLVal.getPointer(CGF),
+  CGF.EmitLoadOfScalar(StLVal, Loc),
+  llvm::ConstantInt::getSigned(
+  CGF.IntTy, 1), // Always 1 because taskgroup emitted by the compiler
+  llvm::ConstantInt::getSigned(
+  CGF.IntTy, Data.Schedule.getPointer()
+ ? Data.Schedule.getInt() ? NumTasks : Grainsize
+ : NoSchedule),
+  Data.Schedule.getPointer()
+  ? CGF.Builder.CreateIntCast(Data.Schedule.getPointer(), CGF.Int64Ty,
+  /*isSigned=*/false)
+  : llvm::ConstantInt::get(CGF.Int64Ty, /*V=*/0),
+  llvm::ConstantInt::get(CGF.Int32Ty, 1), //strict modifier enabled
+  Result.TaskDupFn ? CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
+ Result.TaskDupFn, CGF.VoidPtrTy)
+   : llvm::ConstantPointerNull::get(CGF.VoidPtrTy)};
+  CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
+  CGM.getModule(), OMPRTL___kmpc_taskloop_5),
+  TaskArgs);
+   } else {
   llvm::Value *TaskArgs[] = {
   UpLoc,
   ThreadID,
@@ -4690,6 +4717,7 @@ void CGOpenMPRuntime::emitTaskLoopCall(CodeGenFunction 
&CGF, SourceLocation Loc,
   CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
   CGM.getModule(), OMPRTL___kmpc_taskloop),
   TaskArgs);
+  }
 }
 
 /// Emit reduction operation for each element of array (required for
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.h 
b/clang/lib/CodeGen/CGOpenMPRuntime.h
index 5e7715743afb58..56d502d92806eb 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.h
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.h
@@ -122,6 +122,7 @@ struct OMPTaskDataTy final {
   bool IsReductionWithTaskMod = false;
   bool IsWorksharingReduction = false;
   bool HasNowaitClause = false;
+  bool HasModifier = false;
 };
 
 /// Class intended to support codegen of all kind of the reduction clauses.
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 390516fea38498..88c862d2975174 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -7831,10 +7831,12 @@ void 
CodeGenFunction::EmitOMPTaskLoopBasedDirective(const OMPLoopDirective &S) {
 // grainsize clause
 Data.Schedule.setInt(/*IntVal=*/false);
 Data.Schedule.setPointer(EmitScalarExpr(Clause->getGrainsize()));
+Data.HasModifier = (Clause->getModifier() == OMPC_GRAINSIZE_strict) ? true 
: false;
   } else if (const auto *Clause = S.getSingleClause()) {
 // num_tasks clause
 Data.Schedule.setInt(/*IntVal=*/true);
 Data.Schedule.setPointer(EmitScalarExpr(Clause->getNumTasks()));
+Data.HasModifier = (Clause->getModifier() == OMPC_NUMTASKS_strict) ? true 
: false;
   }
 
   auto &&BodyGen = [CS, &S](CodeGenFunction &CGF, PrePostActionTy &) {
diff --git a/clang/test/OpenMP/taskloop_strictmodifier_codegen.cpp 
b/clang/test/OpenMP/taskloop_strictmodifier_codegen.cpp
new file mode 100644
index 00..d84ff181f66156
--- /dev/null
+++ b/clang/test/OpenMP/taskloop_strictmodifier_codegen.cpp
@@ -0,0 +1,256 @@
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -x c++ 
-emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-apple-darwin10 -emit-pch -o 
%t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-apple-darwin10 -include-pch 
%t -verify %s -emit-llvm -o - | FileCheck %s
+
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -x c++ 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// 

[clang] f849034 - [AMDGPU] Do not allow the region address space to be converted to generic (#117171)

2024-11-22 Thread via cfe-commits

Author: Joseph Huber
Date: 2024-11-22T07:13:49-06:00
New Revision: f84903486cd174e39fb36fa88c98c9563b671c7e

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

LOG: [AMDGPU] Do not allow the region address space to be converted to generic 
(#117171)

Summary:
Previous changes relaxed the address space rules based on what the
target says about them. This accidentally included the AS(2) region as
convertible to generic. Simply check for AS(2) and reject it.

Added: 


Modified: 
clang/lib/Basic/Targets/AMDGPU.h
clang/test/Sema/amdgcn-address-spaces.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index db7a095ba2a4fe..ea4189cdea47da 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -120,7 +120,8 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   toTargetAddressSpace(A) == llvm::AMDGPUAS::FLAT_ADDRESS)) &&
 isTargetAddressSpace(B) &&
 toTargetAddressSpace(B) >= llvm::AMDGPUAS::FLAT_ADDRESS &&
-toTargetAddressSpace(B) <= llvm::AMDGPUAS::PRIVATE_ADDRESS);
+toTargetAddressSpace(B) <= llvm::AMDGPUAS::PRIVATE_ADDRESS &&
+toTargetAddressSpace(B) != llvm::AMDGPUAS::REGION_ADDRESS);
   }
 
   uint64_t getMaxPointerWidth() const override {

diff  --git a/clang/test/Sema/amdgcn-address-spaces.c 
b/clang/test/Sema/amdgcn-address-spaces.c
index 50c12993ac69b8..70545db920c807 100644
--- a/clang/test/Sema/amdgcn-address-spaces.c
+++ b/clang/test/Sema/amdgcn-address-spaces.c
@@ -9,7 +9,7 @@
 #define _AS999 __attribute__((address_space(999)))
 
 void *p1(void _AS1 *p) { return p; }
-void *p2(void _AS2 *p) { return p; }
+void *p2(void _AS2 *p) { return p; } // expected-error {{returning '_AS2 void 
*' from a function with result type 'void *' changes address space of pointer}}
 void *p3(void _AS3 *p) { return p; }
 void *p4(void _AS4 *p) { return p; }
 void *p5(void _AS5 *p) { return p; }



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


[clang] [AMDGPU] Do not allow the region address space to be converted to generic (PR #117171)

2024-11-22 Thread Joseph Huber via cfe-commits

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


[clang] [AMDGPU] Do not allow the region address space to be converted to generic (PR #117171)

2024-11-22 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> Should also forbid the buffers (probably should forbid using the buffers at 
> all)

I think the logic currently allows 0, 1, 3, 4, and 5.

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


[clang-tools-extra] [clang-tidy] New option `CompilationArgsToRemoveRegex` to remove arguments from the command line (PR #111453)

2024-11-22 Thread Aaron Ballman via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


AaronBallman wrote:

> I too have the feeling that this feature is a responsibility of the build 
> system, not of clang-tidy. What do you think @AaronBallman ?

If I understand correctly, this situation is when CMake is configured for 
another compiler (e.g., GCC) but is also instructed to run clang-tidy, but then 
CMake hands clang-tidy the command line arguments it was handing to GCC, and 
clang-tidy is giving hard errors for the unknown command line arguments.

Clang itself ignores some unknown command line options while erring on others 
(it seems to be `-` vs `--` which decides this): 
https://godbolt.org/z/f1T8hjP69 Would it make sense for clang-tidy to follow 
suit and ignore unknown options specified with `-`? That would help in the 
modules case, but wouldn't help for the CUDA case mentioned in the issue.

CC @MaskRay @jansvoboda11 for additional opinions (and why does clang warn in 
some cases but err in others, is that intentional?)


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


[clang] [Clang] Add Doug Wyatt and myself as maintainers for function effect analysis (PR #117324)

2024-11-22 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/117324

>From 8d1e4b65069c81ffdb05ffdd5308b4dd44451155 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Fri, 22 Nov 2024 13:46:56 +0100
Subject: [PATCH 1/3] [Clang] Add myself and Doug Wyatt as maintainers for
 function effect analysis

---
 clang/Maintainers.rst | 8 
 1 file changed, 8 insertions(+)

diff --git a/clang/Maintainers.rst b/clang/Maintainers.rst
index b601f4da0b3a93..602ecd9961b80d 100644
--- a/clang/Maintainers.rst
+++ b/clang/Maintainers.rst
@@ -176,6 +176,14 @@ Thread Safety Analysis
 | aaron.puchert\@sap.com (email), aaronpuchert (GitHub), aaronpuchert 
(Discourse)
 
 
+Function Effect Analysis
+
+| Doug Wyatt
+| dwyatt\@apple.com (email), dougsonos (GitHub)
+
+| Sirraide
+| aeternalmail\@gmail.com (email), Sirraide (GitHub), Ætérnal (Discord), 
Sirraide (Discourse)
+
 Tools
 -
 These maintainers are responsible for user-facing tools under the Clang

>From 3faa36019da0707c56dcc2b789d831d13ca2d539 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Fri, 22 Nov 2024 13:53:11 +0100
Subject: [PATCH 2/3] =?UTF-8?q?Add=20Doug=E2=80=99s=20discourse=20name=20a?=
 =?UTF-8?q?s=20well?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 clang/Maintainers.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/Maintainers.rst b/clang/Maintainers.rst
index 602ecd9961b80d..dab33ab7c9aa1c 100644
--- a/clang/Maintainers.rst
+++ b/clang/Maintainers.rst
@@ -179,7 +179,7 @@ Thread Safety Analysis
 Function Effect Analysis
 
 | Doug Wyatt
-| dwyatt\@apple.com (email), dougsonos (GitHub)
+| dwyatt\@apple.com (email), dougsonos (GitHub), dougsonos (Discourse)
 
 | Sirraide
 | aeternalmail\@gmail.com (email), Sirraide (GitHub), Ætérnal (Discord), 
Sirraide (Discourse)

>From eb0d1c848ce1a3631b65f00c171f602182890d5f Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Fri, 22 Nov 2024 14:27:43 +0100
Subject: [PATCH 3/3] Update clang/Maintainers.rst

Co-authored-by: Aaron Ballman 
---
 clang/Maintainers.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/Maintainers.rst b/clang/Maintainers.rst
index dab33ab7c9aa1c..7396211715a80a 100644
--- a/clang/Maintainers.rst
+++ b/clang/Maintainers.rst
@@ -184,6 +184,7 @@ Function Effect Analysis
 | Sirraide
 | aeternalmail\@gmail.com (email), Sirraide (GitHub), Ætérnal (Discord), 
Sirraide (Discourse)
 
+
 Tools
 -
 These maintainers are responsible for user-facing tools under the Clang

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


[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)

2024-11-22 Thread via cfe-commits

https://github.com/higher-performance updated 
https://github.com/llvm/llvm-project/pull/102040

>From e98e6f210f02af0813393d88e1bc4f02c0682e5f Mon Sep 17 00:00:00 2001
From: higher-performance 
Date: Mon, 5 Aug 2024 15:04:19 -0400
Subject: [PATCH 01/11] Add Clang attribute to ensure that fields are
 initialized explicitly

---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |  9 
 clang/include/clang/AST/DeclCXX.h |  5 ++
 clang/include/clang/Basic/Attr.td |  8 
 clang/include/clang/Basic/AttrDocs.td | 29 
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/lib/AST/DeclCXX.cpp | 24 ++
 clang/lib/Sema/SemaDeclAttr.cpp   |  7 +++
 clang/lib/Sema/SemaInit.cpp   | 15 ++
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/SemaCXX/uninitialized.cpp  | 46 +++
 11 files changed, 152 insertions(+)

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index 6620840df0ced2..54f28046c63ebb 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -119,6 +119,15 @@ FIELD(HasInitMethod, 1, NO_MERGE)
 /// within anonymous unions or structs.
 FIELD(HasInClassInitializer, 1, NO_MERGE)
 
+/// Custom attribute that is True if any field is marked as requiring explicit
+/// initialization with [[clang::requires_explicit_initialization]] in a type
+/// without a user-provided default constructor, or if this is the case for any
+/// base classes and/or member variables whose types are aggregates.
+///
+/// In this case, default-construction is diagnosed, as it would not explicitly
+/// initialize the field.
+FIELD(HasUninitializedExplicitInitFields, 1, NO_MERGE)
+
 /// True if any field is of reference type, and does not have an
 /// in-class initializer.
 ///
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 2693cc0e95b4b2..7a9c28b6af9d9e 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1152,6 +1152,11 @@ class CXXRecordDecl : public RecordDecl {
   /// structs).
   bool hasInClassInitializer() const { return data().HasInClassInitializer; }
 
+  bool hasUninitializedExplicitInitFields() const {
+return !isUnion() && !hasUserProvidedDefaultConstructor() &&
+   data().HasUninitializedExplicitInitFields;
+  }
+
   /// Whether this class or any of its subobjects has any members of
   /// reference type which would make value-initialization ill-formed.
   ///
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 6035a563d5fce7..2878ed0a9fec1b 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1885,6 +1885,14 @@ def Leaf : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def ExplicitInit : InheritableAttr {
+  let Spellings = [Clang<"requires_explicit_initialization", 0>];
+  let Subjects = SubjectList<[Field], ErrorDiag>;
+  let Documentation = [ExplicitInitDocs];
+  let LangOpts = [CPlusPlus];
+  let SimpleHandler = 1;
+}
+
 def LifetimeBound : DeclOrTypeAttr {
   let Spellings = [Clang<"lifetimebound", 0>];
   let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 94d6d15365cef6..fb5def41deadc8 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1599,6 +1599,35 @@ is not specified.
   }];
 }
 
+def ExplicitInitDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+The ``clang::requires_explicit_initialization`` attribute indicates that the
+field of an aggregate must be initialized explicitly by users when the class
+is constructed. Its usage is invalid on non-aggregates.
+
+Example usage:
+
+.. code-block:: c++
+
+  struct some_aggregate {
+int x;
+int y [[clang::requires_explicit_initialization]];
+  };
+
+  some_aggregate create() {
+return {.x = 1};  // error: y is not initialized explicitly
+  }
+
+This attribute is *not* a memory safety feature, and is *not* intended to guard
+against use of uninitialized memory.
+Rather, its intended use is in structs that represent "parameter objects", to
+allow extending them while ensuring that callers do not forget to specify
+values for newly added fields ("parameters").
+
+  }];
+}
+
 def NoUniqueAddressDocs : Documentation {
   let Category = DocCatField;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index df9bf94b5d0398..a18072e7dd5cc8 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -790,6 +790,7 @@ def Trigraphs

[clang] [clang] Infer lifetime_capture_by for STL containers (PR #117122)

2024-11-22 Thread Haojian Wu via cfe-commits

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


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


[clang] Added more descriptive message (issue 116808) (PR #117201)

2024-11-22 Thread via cfe-commits

github-actions[bot] wrote:



@tlemy Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] 61f1dc0 - Added more descriptive message (issue 116808) (#117201)

2024-11-22 Thread via cfe-commits

Author: tlemy
Date: 2024-11-22T12:24:17-05:00
New Revision: 61f1dc05a88de38afcb337ef194cfdb7dc798197

URL: 
https://github.com/llvm/llvm-project/commit/61f1dc05a88de38afcb337ef194cfdb7dc798197
DIFF: 
https://github.com/llvm/llvm-project/commit/61f1dc05a88de38afcb337ef194cfdb7dc798197.diff

LOG: Added more descriptive message (issue 116808) (#117201)

The dialogue messages were changed to be more descriptive.

Fixes #116808

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/test/CXX/class.access/class.friend/p11.cpp
clang/test/SemaCXX/function-redecl.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 157d77b38b354e..eb05a6a77978af 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1728,9 +1728,9 @@ def err_introducing_special_friend : Error<
 def err_tagless_friend_type_template : Error<
   "friend type templates must use an elaborated type">;
 def err_no_matching_local_friend : Error<
-  "no matching function found in local scope">;
+  "cannot define friend function in a local class definition">;
 def err_no_matching_local_friend_suggest : Error<
-  "no matching function %0 found in local scope; did you mean %3?">;
+  "cannot define friend function %0 in a local class definition; did you mean 
%3?">;
 def err_partial_specialization_friend : Error<
   "partial specialization cannot be declared as a friend">;
 def err_qualified_friend_def : Error<

diff  --git a/clang/test/CXX/class.access/class.friend/p11.cpp 
b/clang/test/CXX/class.access/class.friend/p11.cpp
index 71f11bdf9e0736..bc2bc073f51a73 100644
--- a/clang/test/CXX/class.access/class.friend/p11.cpp
+++ b/clang/test/CXX/class.access/class.friend/p11.cpp
@@ -12,7 +12,7 @@ namespace test0 {
 namespace test1 {
   void foo() {
 class A {
-  friend void bar(); // expected-error {{no matching function found in 
local scope}}
+  friend void bar(); // expected-error {{cannot define friend function in 
a local class definition}}
 };
   }
 }
@@ -22,7 +22,7 @@ namespace test2 {
 
   void foo() { // expected-note 2{{'::test2::foo' declared here}}
 struct S1 {
-  friend void foo(); // expected-error {{no matching function 'foo' found 
in local scope; did you mean '::test2::foo'?}}
+  friend void foo(); // expected-error {{cannot define friend function 
'foo' in a local class definition; did you mean '::test2::foo'?}}
 };
 
 void foo(); // expected-note {{local declaration nearly matches}}
@@ -32,24 +32,24 @@ namespace test2 {
 
 {
   struct S2 {
-friend void foo(); // expected-error {{no matching function found in 
local scope}}
+friend void foo(); // expected-error {{cannot define friend function 
in a local class definition}}
   };
 }
 
 {
   int foo;
   struct S3 {
-friend void foo(); // expected-error {{no matching function 'foo' 
found in local scope; did you mean '::test2::foo'?}}
+friend void foo(); // expected-error {{cannot define friend function 
'foo' in a local class definition; did you mean '::test2::foo'?}}
   };
 }
 
 struct S4 {
-  friend void bar(); // expected-error {{no matching function 'bar' found 
in local scope; did you mean '::test2::bar'?}}
+  friend void bar(); // expected-error {{cannot define friend function 
'bar' in a local class definition; did you mean '::test2::bar'?}}
 };
 
 { void bar(); }
 struct S5 {
-  friend void bar(); // expected-error {{no matching function 'bar' found 
in local scope; did you mean '::test2::bar'?}}
+  friend void bar(); // expected-error {{cannot define friend function 
'bar' in a local class definition; did you mean '::test2::bar'?}}
 };
 
 {
@@ -76,7 +76,7 @@ namespace test2 {
 
 struct S9 {
   struct Inner {
-friend void baz(); // expected-error {{no matching function 'baz' 
found in local scope; did you mean 'bar'?}}
+friend void baz(); // expected-error {{cannot define friend function 
'baz' in a local class definition; did you mean 'bar'?}}
   };
 };
 
@@ -84,8 +84,8 @@ namespace test2 {
   void quux() {}
   void foo() {
 struct Inner1 {
-  friend void bar(); // expected-error {{no matching function 'bar' 
found in local scope; did you mean '::test2::bar'?}}
-  friend void quux(); // expected-error {{no matching function found 
in local scope}}
+  friend void bar(); // expected-error {{cannot define friend function 
'bar' in a local class definition; did you mean '::test2::bar'?}}
+  friend void quux(); // expected-error {{cannot define friend 
function in a local class definition}}
 };
 
 void bar();

diff  --git a/clang/test/SemaCXX/function-redecl.cpp 
b/clang/test/SemaCXX/funct

[clang] Added more descriptive message (issue 116808) (PR #117201)

2024-11-22 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


[clang] Added more descriptive message (issue 116808) (PR #117201)

2024-11-22 Thread Aaron Ballman via cfe-commits

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


[clang] [llvm] [clang] Implement pragma clang section on COFF targets (PR #112714)

2024-11-22 Thread Vinicius Tadeu Zein via cfe-commits


@@ -1677,6 +1677,22 @@ MCSection 
*TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
   Name == getInstrProfSectionName(IPSK_covname, Triple::COFF,
   /*AddSegmentInfo=*/false))
 Kind = SectionKind::getMetadata();
+
+  const GlobalVariable *GV = dyn_cast(GO);
+  if (GV && GV->hasImplicitSection()) {
+auto Attrs = GV->getAttributes();
+if (Attrs.hasAttribute("bss-section") && Kind.isBSS()) {

vtz wrote:

Done

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


[clang] b71038a - [AIX] Fix AIX BuildBot failure as AIX linker doesn't support version script. (#117342)

2024-11-22 Thread via cfe-commits

Author: Daniel Chen
Date: 2024-11-22T12:26:44-05:00
New Revision: b71038a69ee95f5dd740f99a1cb7aefde0859562

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

LOG: [AIX] Fix AIX BuildBot failure as AIX linker doesn't support version 
script. (#117342)

AIX BuildBot failed due to
https://github.com/llvm/llvm-project/pull/116556 as AIX linker does not
support version script.
This PR is to fix the failure

This PR is on behalf of gniko...@ca.ibm.com

Added: 


Modified: 
clang/tools/clang-shlib/CMakeLists.txt

Removed: 




diff  --git a/clang/tools/clang-shlib/CMakeLists.txt 
b/clang/tools/clang-shlib/CMakeLists.txt
index 31484ec49c7739..2d97347ea7f828 100644
--- a/clang/tools/clang-shlib/CMakeLists.txt
+++ b/clang/tools/clang-shlib/CMakeLists.txt
@@ -48,11 +48,13 @@ add_clang_library(clang-cpp
   ${_OBJECTS}
   LINK_LIBS
   ${_DEPS})
+# AIX linker does not support version script
+if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+  configure_file(simple_version_script.map.in simple_version_script.map)
 
-configure_file(simple_version_script.map.in simple_version_script.map)
-
-if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
-  target_link_options(clang-cpp PRIVATE 
LINKER:--version-script,${CMAKE_CURRENT_BINARY_DIR}/simple_version_script.map)
+  if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+target_link_options(clang-cpp PRIVATE 
LINKER:--version-script,${CMAKE_CURRENT_BINARY_DIR}/simple_version_script.map)
+  endif()
 endif()
 
 # Optimize function calls for default visibility definitions to avoid PLT and



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


[clang] [libcxx] [clang] Warn about memset/memcpy to NonTriviallyCopyable types (PR #111434)

2024-11-22 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

CC @serge-sans-paille on the request for a separate flag

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


[clang] [clang][codegen] Mention the invariant that LLVM demangler should be … (PR #117346)

2024-11-22 Thread James Y Knight via cfe-commits


@@ -2047,6 +2047,14 @@ StringRef CodeGenModule::getMangledName(GlobalDecl GD) {
  GD.getWithKernelReferenceKind(KernelReferenceKind::Kernel),
  ND));
 
+  // This invariant should hold true in the future.
+  // Prior work:
+  // 
https://discourse.llvm.org/t/rfc-clang-diagnostic-for-demangling-failures/82835/8
+  // https://github.com/llvm/llvm-project/issues/111345
+  // assert(llvm::isMangledName(MangledName) &&

jyknight wrote:

isMangledName doesn't seem to exist?

But, also, we'd only want to validate output actually produced by Clang 
`mangleCXXName`, and not e.g. a user-written `void f() asm("_ZGARBAGE"); void 
f() {}`

Maybe we want:`if ((MangledName.startswith("_Z") || 
MangledName.startswith("?")) & !GD->hasAttr())`?

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


[clang] [clang] Allow delayed function instantiation at TU end if initial instantiation fails (PR #117167)

2024-11-22 Thread via cfe-commits

StefanPaulet wrote:

@erichkeane 

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


[clang] [Clang] Add Doug Wyatt and myself as maintainers for function effect analysis (PR #117324)

2024-11-22 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


[clang] [Clang] Add Doug Wyatt and myself as maintainers for function effect analysis (PR #117324)

2024-11-22 Thread Aaron Ballman via cfe-commits


@@ -176,6 +176,14 @@ Thread Safety Analysis
 | aaron.puchert\@sap.com (email), aaronpuchert (GitHub), aaronpuchert 
(Discourse)
 
 
+Function Effect Analysis
+
+| Doug Wyatt
+| dwyatt\@apple.com (email), dougsonos (GitHub), dougsonos (Discourse)
+
+| Sirraide
+| aeternalmail\@gmail.com (email), Sirraide (GitHub), Ætérnal (Discord), 
Sirraide (Discourse)
+

AaronBallman wrote:

```suggestion


```
I was going with two lines of vertical separation for readability when the file 
isn't rendered to HTML.

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


[clang] [Clang] Add Doug Wyatt and myself as maintainers for function effect analysis (PR #117324)

2024-11-22 Thread Aaron Ballman via cfe-commits

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


[clang] clang: Relax LangOpts checks when lexing quoted numbers during preprocessing (PR #95798)

2024-11-22 Thread Aaron Ballman via cfe-commits


@@ -2068,7 +2068,8 @@ bool Lexer::LexNumericConstant(Token &Result, const char 
*CurPtr) {
   }
 
   // If we have a digit separator, continue.
-  if (C == '\'' && (LangOpts.CPlusPlus14 || LangOpts.C23)) {
+  if (C == '\'' &&
+  (LangOpts.CPlusPlus14 || LangOpts.C23 || ParsingPreprocessorDirective)) {

AaronBallman wrote:

> Sure, but we don't have to expose that language extension to users, it can 
> remain internal to the compiler.

This still doesn't address my concerns from earlier about how it impacts 
maintenance of Clang itself:

> I don't think per-feature LangOptions is viable. There's digit separators, 
> hex float support, binary literal support, different literal suffixes, 
> various keywords, etc and that doesn't seem likely to scale well. Also, it 
> makes it seem like we support a la carte language features when we don't -- 
> we intentionally don't want to let users disable standard features (in 
> general; exceptions exist) and so that approach gives the impression 
> contributors need to check both language mode and feature availability which 
> is a maintenance concern.

How do we avoid this situation, as that's my primary concern.

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


[clang] [analyzer] Print the PostInitializer target in exploded-graph-rewriter (PR #116034)

2024-11-22 Thread Donát Nagy via cfe-commits

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

Sorry for missing this review, I didn't noticed that this is distinct from the 
similar `CallEnter` change.

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


[clang] [Clang] Add Doug Wyatt and myself as maintainers for function effect analysis (PR #117324)

2024-11-22 Thread via cfe-commits

https://github.com/Sirraide created 
https://github.com/llvm/llvm-project/pull/117324

Doug implemented quite literally all of it and has been continuously improving 
the implementation by handling more language constructs we had initially 
missed. I spent a lot of time reviewing the implementation of the attributes as 
well as the analysis pass, so in other words, the two of us are probably best 
equipped to answer any questions that might arise wrt this part of Clang.

@dougsonos I hope you’re fine w/ me nominating you, because I’m familiar w/ the 
implementation, but not so much realtime processing and its requirements... 
Also, can you check if I found the right email?

>From 8d1e4b65069c81ffdb05ffdd5308b4dd44451155 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Fri, 22 Nov 2024 13:46:56 +0100
Subject: [PATCH 1/2] [Clang] Add myself and Doug Wyatt as maintainers for
 function effect analysis

---
 clang/Maintainers.rst | 8 
 1 file changed, 8 insertions(+)

diff --git a/clang/Maintainers.rst b/clang/Maintainers.rst
index b601f4da0b3a93..602ecd9961b80d 100644
--- a/clang/Maintainers.rst
+++ b/clang/Maintainers.rst
@@ -176,6 +176,14 @@ Thread Safety Analysis
 | aaron.puchert\@sap.com (email), aaronpuchert (GitHub), aaronpuchert 
(Discourse)
 
 
+Function Effect Analysis
+
+| Doug Wyatt
+| dwyatt\@apple.com (email), dougsonos (GitHub)
+
+| Sirraide
+| aeternalmail\@gmail.com (email), Sirraide (GitHub), Ætérnal (Discord), 
Sirraide (Discourse)
+
 Tools
 -
 These maintainers are responsible for user-facing tools under the Clang

>From 3faa36019da0707c56dcc2b789d831d13ca2d539 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Fri, 22 Nov 2024 13:53:11 +0100
Subject: [PATCH 2/2] =?UTF-8?q?Add=20Doug=E2=80=99s=20discourse=20name=20a?=
 =?UTF-8?q?s=20well?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 clang/Maintainers.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/Maintainers.rst b/clang/Maintainers.rst
index 602ecd9961b80d..dab33ab7c9aa1c 100644
--- a/clang/Maintainers.rst
+++ b/clang/Maintainers.rst
@@ -179,7 +179,7 @@ Thread Safety Analysis
 Function Effect Analysis
 
 | Doug Wyatt
-| dwyatt\@apple.com (email), dougsonos (GitHub)
+| dwyatt\@apple.com (email), dougsonos (GitHub), dougsonos (Discourse)
 
 | Sirraide
 | aeternalmail\@gmail.com (email), Sirraide (GitHub), Ætérnal (Discord), 
Sirraide (Discourse)

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


[clang] [Clang] Add Doug Wyatt and myself as maintainers for function effect analysis (PR #117324)

2024-11-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Sirraide)


Changes

Doug implemented quite literally all of it and has been continuously improving 
the implementation by handling more language constructs we had initially 
missed. I spent a lot of time reviewing the implementation of the attributes as 
well as the analysis pass, so in other words, the two of us are probably best 
equipped to answer any questions that might arise wrt this part of Clang.

@dougsonos I hope you’re fine w/ me nominating you, because I’m 
familiar w/ the implementation, but not so much realtime processing and its 
requirements... Also, can you check if I found the right email?

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


1 Files Affected:

- (modified) clang/Maintainers.rst (+8) 


``diff
diff --git a/clang/Maintainers.rst b/clang/Maintainers.rst
index b601f4da0b3a93..dab33ab7c9aa1c 100644
--- a/clang/Maintainers.rst
+++ b/clang/Maintainers.rst
@@ -176,6 +176,14 @@ Thread Safety Analysis
 | aaron.puchert\@sap.com (email), aaronpuchert (GitHub), aaronpuchert 
(Discourse)
 
 
+Function Effect Analysis
+
+| Doug Wyatt
+| dwyatt\@apple.com (email), dougsonos (GitHub), dougsonos (Discourse)
+
+| Sirraide
+| aeternalmail\@gmail.com (email), Sirraide (GitHub), Ætérnal (Discord), 
Sirraide (Discourse)
+
 Tools
 -
 These maintainers are responsible for user-facing tools under the Clang

``




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


[clang-tools-extra] [clang-tidy] Enhance modernize-use-starts-ends-with to handle substr patterns (PR #116033)

2024-11-22 Thread Helmut Januschka via cfe-commits

https://github.com/hjanuschka updated 
https://github.com/llvm/llvm-project/pull/116033

>From 23b4bcdf52041aad1c5581e0f7dc01028770a154 Mon Sep 17 00:00:00 2001
From: Helmut Januschka 
Date: Wed, 13 Nov 2024 12:52:36 +0100
Subject: [PATCH 1/9] [clang-tidy] Enhance modernize-use-starts-ends-with with
 substr detection

Enhances the modernize-use-starts-ends-with check to detect substr-based
patterns that can be replaced with starts_with() (C++20). This improves code
readability and efficiency by avoiding temporary string creation.

New patterns detected:
  str.substr(0, n) == "foo"   -> str.starts_with("foo")
  "foo" == str.substr(0, n)   -> str.starts_with("foo")
  str.substr(0, n) != "foo"   -> !str.starts_with("foo")
  str.substr(0, strlen("foo")) == "foo" -> str.starts_with("foo")
  str.substr(0, prefix.size()) == "foo" -> str.starts_with("foo")

The enhancement:
- Integrates with existing starts_with patterns
- Handles substr with zero first argument
- Supports length via literals, strlen(), and size()/length()
- Validates string literal length matches
- Handles both == and != operators

Part of modernize-use-starts-ends-with check.
---
 .../modernize/UseStartsEndsWithCheck.cpp  | 114 ++---
 .../modernize/UseStartsEndsWithCheck.h|   1 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +-
 .../checks/modernize/use-starts-ends-with.rst |  34 ++--
 .../clang-tidy/checkers/Inputs/Headers/string |   2 +
 .../modernize/use-starts-ends-with.cpp| 159 --
 6 files changed, 216 insertions(+), 99 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp
index 1231f954298adc..12ff31dfa03541 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp
@@ -30,6 +30,17 @@ struct NotLengthExprForStringNode {
IntegerLiteralSizeNode->getValue().getZExtValue();
   }
 
+  if (const auto *DeclRefNode = Node.get()) {
+if (const auto *VD = dyn_cast(DeclRefNode->getDecl())) {
+  if (VD->hasInit() && VD->getType().isConstQualified()) {
+if (const auto *Init = dyn_cast(VD->getInit())) {
+  return StringLiteralNode->getLength() !=
+ Init->getValue().getZExtValue();
+}
+  }
+}
+  }
+
   if (const auto *StrlenNode = Node.get()) {
 if (StrlenNode->getDirectCallee()->getName() != "strlen" ||
 StrlenNode->getNumArgs() != 1) {
@@ -171,10 +182,64 @@ void UseStartsEndsWithCheck::registerMatchers(MatchFinder 
*Finder) {
  hasRHS(lengthExprForStringNode("needle")
   .bind("expr"),
   this);
+
+  Finder->addMatcher(
+  cxxOperatorCallExpr(
+  hasAnyOperatorName("==", "!="),
+  anyOf(
+  hasOperands(
+  cxxMemberCallExpr(
+  argumentCountIs(2), hasArgument(0, ZeroLiteral),
+  hasArgument(1, lengthExprForStringNode("needle")),
+  callee(
+  cxxMethodDecl(hasName("substr"),
+ofClass(OnClassWithStartsWithFunction))
+  .bind("find_fun")))
+  .bind("find_expr"),
+  expr().bind("needle")),
+  hasOperands(expr().bind("needle"),
+  cxxMemberCallExpr(
+  argumentCountIs(2), hasArgument(0, ZeroLiteral),
+  hasArgument(1, 
lengthExprForStringNode("needle")),
+  callee(cxxMethodDecl(
+ hasName("substr"),
+ 
ofClass(OnClassWithStartsWithFunction))
+ .bind("find_fun")))
+  .bind("find_expr"
+  .bind("expr"),
+  this);
+}
+
+bool UseStartsEndsWithCheck::isNegativeComparison(const Expr* ComparisonExpr) {
+  // Handle direct != operator
+  if (const auto *BO = llvm::dyn_cast(ComparisonExpr)) {
+return BO->getOpcode() == BO_NE;
+  }
+  
+  // Handle operator!= call
+  if (const auto *Op = llvm::dyn_cast(ComparisonExpr)) {
+return Op->getOperator() == OO_ExclaimEqual;
+  }
+  
+  // Handle rewritten !(expr == expr)
+  if (const auto *UO = llvm::dyn_cast(ComparisonExpr)) {
+if (UO->getOpcode() == UO_LNot) {
+  if (const auto *InnerBO = 
+  llvm::dyn_cast(UO->getSubExpr()->IgnoreParens())) {
+return InnerBO->getOpcode() == BO_EQ;
+  }
+  if (const auto *InnerOp = 
+  
llvm::dyn_cast(UO->getSubExpr()->IgnoreParens())) {
+return InnerOp->getOperator() == OO_EqualEqual;
+  }
+}
+  }
+  
+  return false;
 }
 
 void UseStartsEndsWithCheck::check(const 

[clang-tools-extra] [clang-tidy] Enhance modernize-use-starts-ends-with to handle substr patterns (PR #116033)

2024-11-22 Thread Helmut Januschka via cfe-commits


@@ -183,40 +210,45 @@ void UseStartsEndsWithCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto *EndsWithFunction =
   Result.Nodes.getNodeAs("ends_with_fun");
   assert(bool(StartsWithFunction) != bool(EndsWithFunction));
+
   const CXXMethodDecl *ReplacementFunction =
   StartsWithFunction ? StartsWithFunction : EndsWithFunction;
 
-  if (ComparisonExpr->getBeginLoc().isMacroID())
+  if (ComparisonExpr->getBeginLoc().isMacroID() ||
+  FindExpr->getBeginLoc().isMacroID())
 return;
 
-  const bool Neg = ComparisonExpr->getOpcode() == BO_NE;
+  const bool Neg = isNegativeComparison(ComparisonExpr);
 
-  auto Diagnostic =
-  diag(FindExpr->getExprLoc(), "use %0 instead of %1() %select{==|!=}2 0")
-  << ReplacementFunction->getName() << FindFun->getName() << Neg;
+  // Retrieve the source text of the search expression.
+  const auto SearchExprText = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(SearchExpr->getSourceRange()),
+  *Result.SourceManager, Result.Context->getLangOpts());
 
-  // Remove possible arguments after search expression and ' [!=]= .+' suffix.
-  Diagnostic << FixItHint::CreateReplacement(
-  CharSourceRange::getTokenRange(
-  Lexer::getLocForEndOfToken(SearchExpr->getEndLoc(), 0,
- *Result.SourceManager, getLangOpts()),
-  ComparisonExpr->getEndLoc()),
-  ")");
+  auto Diag = diag(FindExpr->getExprLoc(),
+   FindFun->getName() == "substr"

hjanuschka wrote:

see discussion below about output formating

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


[clang-tools-extra] [clang-tidy] New option `CompilationArgsToRemoveRegex` to remove arguments from the command line (PR #111453)

2024-11-22 Thread Carlos Galvez via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

I too have the feeling that this feature is a responsibility of the build 
system, not of clang-tidy. What do you think @AaronBallman ?

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


[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)

2024-11-22 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

There's still a failure being caught by precommit CI that is related:
```
 TEST 'Clang :: SemaCXX/uninitialized.cpp' FAILED 

Exit Code: 1
Command Output (stderr):
--
RUN: at line 1: 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-mqg5l-1/llvm-project/github-pull-requests/build/bin/clang
 -cc1 -internal-isystem 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-mqg5l-1/llvm-project/github-pull-requests/build/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -Wall -Wuninitialized -Wno-unused-value 
-Wno-unused-lambda-capture -Wno-uninitialized-const-reference -std=c++1z 
-verify 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-mqg5l-1/llvm-project/github-pull-requests/clang/test/SemaCXX/uninitialized.cpp
+ 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-mqg5l-1/llvm-project/github-pull-requests/build/bin/clang
 -cc1 -internal-isystem 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-mqg5l-1/llvm-project/github-pull-requests/build/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -Wall -Wuninitialized -Wno-unused-value 
-Wno-unused-lambda-capture -Wno-uninitialized-const-reference -std=c++1z 
-verify 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-mqg5l-1/llvm-project/github-pull-requests/clang/test/SemaCXX/uninitialized.cpp
error: 'expected-warning' diagnostics expected but not seen:
  File 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-mqg5l-1/llvm-project/github-pull-requests/clang/test/SemaCXX/uninitialized.cpp
 Line 1517 (directive at 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-mqg5l-1/llvm-project/github-pull-requests/clang/test/SemaCXX/uninitialized.cpp:1519):
 explicit initialization of field 'c1' will not be enforced in C++20 and later 
because 'C' has a user-declared constructor, making the type no longer an 
aggregate
1 error generated.
--

```

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


  1   2   3   4   5   >