[clang-tools-extra] [clangd] Guard against trivial FunctionProtoTypeLoc when creating inlay hints (PR #143087)

2025-06-07 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/143087

>From 26071d82cd4084b969e6cb2d0eac046c950c982a Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Fri, 6 Jun 2025 03:56:59 -0400
Subject: [PATCH] [clangd] Guard against trivial FunctionProtoTypeLoc when
 creating inlay hints

Fixes https://github.com/llvm/llvm-project/issues/142608
---
 clang-tools-extra/clangd/InlayHints.cpp   | 7 ++-
 clang-tools-extra/clangd/unittests/InlayHintTests.cpp | 5 +
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 1b1bcf78c9855..a2b856ad30519 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -33,6 +33,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
+#include "llvm/ADT/identity.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -368,7 +369,11 @@ static FunctionProtoTypeLoc getPrototypeLoc(Expr *Fn) {
   }
 
   if (auto F = Target.getAs()) {
-return F;
+// In some edge cases the AST can contain a "trivial" FunctionProtoTypeLoc
+// which has null parameters. Avoid these as they don't contain useful
+// information.
+if (llvm::all_of(F.getParams(), llvm::identity()))
+  return F;
   }
 
   return {};
diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 77d78b8777fe3..8ed8401f9fce9 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -997,11 +997,16 @@ TEST(ParameterHints, FunctionPointer) {
 f3_t f3;
 using f4_t = void(__stdcall *)(int param);
 f4_t f4;
+__attribute__((noreturn)) f4_t f5;
 void bar() {
   f1($f1[[42]]);
   f2($f2[[42]]);
   f3($f3[[42]]);
   f4($f4[[42]]);
+  // This one runs into an edge case in clang's type model
+  // and we can't extract the parameter name. But at least
+  // we shouldn't crash.
+  f5(42);
 }
   )cpp",
   ExpectedHint{"param: ", "f1"}, ExpectedHint{"param: ", "f2"},

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


[clang] [clang-format][NFC] Clean up fillRanges() in ClangFormat.cpp (PR #143236)

2025-06-07 Thread Björn Schäpers via cfe-commits

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


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


[clang-tools-extra] [clangd] Guard against trivial FunctionProtoTypeLoc when creating inlay hints (PR #143087)

2025-06-07 Thread Nathan Ridge via cfe-commits


@@ -368,6 +368,14 @@ static FunctionProtoTypeLoc getPrototypeLoc(Expr *Fn) {
   }
 
   if (auto F = Target.getAs()) {
+// In some edge cases the AST can contain a "trivial" FunctionProtoTypeLoc

HighCommander4 wrote:

Thanks for the reminder about this. Now that we've upstreamed 
`HeuristicResolver`, it's a good place for a unified implementation of this 
sort of thing. I'll do that in 
https://github.com/llvm/llvm-project/issues/143240.

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


[clang] [libcxx] [libc++] fix _Atomic c11 compare exchange does not update expected results (PR #78707)

2025-06-07 Thread via cfe-commits

https://github.com/huixie90 updated 
https://github.com/llvm/llvm-project/pull/78707

>From 904f24aa69b5df2e52a9f19c3e96fa94b47aec82 Mon Sep 17 00:00:00 2001
From: Hui 
Date: Fri, 19 Jan 2024 12:33:43 +
Subject: [PATCH 1/2] [libc++] fix _Atomic c11 compare exchange does not update
 expected results

---
 clang/lib/CodeGen/CGAtomic.cpp | 59 +-
 1 file changed, 36 insertions(+), 23 deletions(-)

diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 51f0799a792fd..033a12ef93848 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -376,6 +376,7 @@ bool AtomicInfo::emitMemSetZeroIfNecessary() const {
 static void emitAtomicCmpXchg(CodeGenFunction &CGF, AtomicExpr *E, bool IsWeak,
   Address Dest, Address Ptr,
   Address Val1, Address Val2,
+  Address ExpectedResult,
   uint64_t Size,
   llvm::AtomicOrdering SuccessOrder,
   llvm::AtomicOrdering FailureOrder,
@@ -411,7 +412,15 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 
   CGF.Builder.SetInsertPoint(StoreExpectedBB);
   // Update the memory at Expected with Old's value.
-  CGF.Builder.CreateStore(Old, Val1);
+
+  llvm::Type *ExpectedType = ExpectedResult.getElementType();
+  uint64_t OriginalSizeInBits = 
CGF.CGM.getDataLayout().getTypeSizeInBits(ExpectedType);
+  if (OriginalSizeInBits / 8 == Size) {
+CGF.Builder.CreateStore(Old, ExpectedResult);
+  } else {
+// How to just store N bytes to ExpectedResult ?
+CGF.Builder.CreateStore(Old, ExpectedResult);
+  }
   // Finally, branch to the exit point.
   CGF.Builder.CreateBr(ContinueBB);
 
@@ -426,6 +435,7 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 static void emitAtomicCmpXchgFailureSet(CodeGenFunction &CGF, AtomicExpr *E,
 bool IsWeak, Address Dest, Address Ptr,
 Address Val1, Address Val2,
+Address ExpectedResult,
 llvm::Value *FailureOrderVal,
 uint64_t Size,
 llvm::AtomicOrdering SuccessOrder,
@@ -456,7 +466,7 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 // success argument". This condition has been lifted and the only
 // precondition is 31.7.2.18. Effectively treat this as a DR and skip
 // language version checks.
-emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, 
SuccessOrder,
+emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
   FailureOrder, Scope);
 return;
   }
@@ -481,17 +491,17 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 
   // Emit all the different atomics
   CGF.Builder.SetInsertPoint(MonotonicBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult,
 Size, SuccessOrder, llvm::AtomicOrdering::Monotonic, 
Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(AcquireBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, SuccessOrder,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
 llvm::AtomicOrdering::Acquire, Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(SeqCstBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, SuccessOrder,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
 llvm::AtomicOrdering::SequentiallyConsistent, Scope);
   CGF.Builder.CreateBr(ContBB);
 
@@ -524,6 +534,7 @@ static llvm::Value *EmitPostAtomicMinMax(CGBuilderTy 
&Builder,
 
 static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr *E, Address Dest,
  Address Ptr, Address Val1, Address Val2,
+ Address ExpectedResult,
  llvm::Value *IsWeak, llvm::Value *FailureOrder,
  uint64_t Size, llvm::AtomicOrdering Order,
  llvm::SyncScope::ID Scope) {
@@ -540,13 +551,13 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
   case AtomicExpr::AO__hip_atomic_compare_exchange_strong:
   case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
 emitAtomicCmpXchgFailureSet(CGF, E, false, Dest, Ptr, Val1, Val2,
-FailureOrder, Size, Order, Scope);
+ExpectedResult, FailureOrder, Size, Order, 
Scope);
 return;
   case AtomicExpr::AO__c11_atomic_com

[clang] [libcxx] [clang] [libc++] fix _Atomic c11 compare exchange does not update expected results (PR #78707)

2025-06-07 Thread via cfe-commits

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


[clang] [libcxx] [clang] [libc++] fix _Atomic c11 compare exchange does not update expected results (PR #78707)

2025-06-07 Thread via cfe-commits

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


[clang] [libcxx] [clang] [libc++] fix _Atomic c11 compare exchange does not update expected results (PR #78707)

2025-06-07 Thread via cfe-commits

https://github.com/huixie90 updated 
https://github.com/llvm/llvm-project/pull/78707

>From 904f24aa69b5df2e52a9f19c3e96fa94b47aec82 Mon Sep 17 00:00:00 2001
From: Hui 
Date: Fri, 19 Jan 2024 12:33:43 +
Subject: [PATCH 1/2] [libc++] fix _Atomic c11 compare exchange does not update
 expected results

---
 clang/lib/CodeGen/CGAtomic.cpp | 59 +-
 1 file changed, 36 insertions(+), 23 deletions(-)

diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 51f0799a792fd..033a12ef93848 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -376,6 +376,7 @@ bool AtomicInfo::emitMemSetZeroIfNecessary() const {
 static void emitAtomicCmpXchg(CodeGenFunction &CGF, AtomicExpr *E, bool IsWeak,
   Address Dest, Address Ptr,
   Address Val1, Address Val2,
+  Address ExpectedResult,
   uint64_t Size,
   llvm::AtomicOrdering SuccessOrder,
   llvm::AtomicOrdering FailureOrder,
@@ -411,7 +412,15 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 
   CGF.Builder.SetInsertPoint(StoreExpectedBB);
   // Update the memory at Expected with Old's value.
-  CGF.Builder.CreateStore(Old, Val1);
+
+  llvm::Type *ExpectedType = ExpectedResult.getElementType();
+  uint64_t OriginalSizeInBits = 
CGF.CGM.getDataLayout().getTypeSizeInBits(ExpectedType);
+  if (OriginalSizeInBits / 8 == Size) {
+CGF.Builder.CreateStore(Old, ExpectedResult);
+  } else {
+// How to just store N bytes to ExpectedResult ?
+CGF.Builder.CreateStore(Old, ExpectedResult);
+  }
   // Finally, branch to the exit point.
   CGF.Builder.CreateBr(ContinueBB);
 
@@ -426,6 +435,7 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 static void emitAtomicCmpXchgFailureSet(CodeGenFunction &CGF, AtomicExpr *E,
 bool IsWeak, Address Dest, Address Ptr,
 Address Val1, Address Val2,
+Address ExpectedResult,
 llvm::Value *FailureOrderVal,
 uint64_t Size,
 llvm::AtomicOrdering SuccessOrder,
@@ -456,7 +466,7 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 // success argument". This condition has been lifted and the only
 // precondition is 31.7.2.18. Effectively treat this as a DR and skip
 // language version checks.
-emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, 
SuccessOrder,
+emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
   FailureOrder, Scope);
 return;
   }
@@ -481,17 +491,17 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 
   // Emit all the different atomics
   CGF.Builder.SetInsertPoint(MonotonicBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult,
 Size, SuccessOrder, llvm::AtomicOrdering::Monotonic, 
Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(AcquireBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, SuccessOrder,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
 llvm::AtomicOrdering::Acquire, Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(SeqCstBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, SuccessOrder,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
 llvm::AtomicOrdering::SequentiallyConsistent, Scope);
   CGF.Builder.CreateBr(ContBB);
 
@@ -524,6 +534,7 @@ static llvm::Value *EmitPostAtomicMinMax(CGBuilderTy 
&Builder,
 
 static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr *E, Address Dest,
  Address Ptr, Address Val1, Address Val2,
+ Address ExpectedResult,
  llvm::Value *IsWeak, llvm::Value *FailureOrder,
  uint64_t Size, llvm::AtomicOrdering Order,
  llvm::SyncScope::ID Scope) {
@@ -540,13 +551,13 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
   case AtomicExpr::AO__hip_atomic_compare_exchange_strong:
   case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
 emitAtomicCmpXchgFailureSet(CGF, E, false, Dest, Ptr, Val1, Val2,
-FailureOrder, Size, Order, Scope);
+ExpectedResult, FailureOrder, Size, Order, 
Scope);
 return;
   case AtomicExpr::AO__c11_atomic_com

[clang] [libcxx] [clang] [libc++] fix _Atomic c11 compare exchange does not update expected results (PR #78707)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Hui (huixie90)


Changes

fixes #30023

---

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGAtomic.cpp (+69-23) 
- (added) clang/test/CodeGenCXX/builtin-atomic-compare_exchange.cpp (+126) 
- (added) libcxx/test/std/atomics/atomics.types.generic/30023.pass.cpp (+65) 


``diff
diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 51f0799a792fd..9eee834a520e0 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -376,6 +376,7 @@ bool AtomicInfo::emitMemSetZeroIfNecessary() const {
 static void emitAtomicCmpXchg(CodeGenFunction &CGF, AtomicExpr *E, bool IsWeak,
   Address Dest, Address Ptr,
   Address Val1, Address Val2,
+  Address ExpectedResult,
   uint64_t Size,
   llvm::AtomicOrdering SuccessOrder,
   llvm::AtomicOrdering FailureOrder,
@@ -411,7 +412,48 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 
   CGF.Builder.SetInsertPoint(StoreExpectedBB);
   // Update the memory at Expected with Old's value.
-  CGF.Builder.CreateStore(Old, Val1);
+llvm::Type *ExpectedType = ExpectedResult.getElementType();
+const llvm::DataLayout &DL = CGF.CGM.getDataLayout();
+uint64_t ExpectedSizeInBytes = DL.getTypeStoreSize(ExpectedType);
+
+if (ExpectedSizeInBytes == Size) {
+  // Sizes match: store directly
+  CGF.Builder.CreateStore(Old, ExpectedResult);
+
+} else {
+  // store only the first ExpectedSizeInBytes bytes of Old
+  llvm::Type *OldType = Old->getType();
+
+  llvm::Align SrcAlignLLVM = DL.getABITypeAlign(OldType);
+  llvm::Align DstAlignLLVM = DL.getABITypeAlign(ExpectedType);
+
+  clang::CharUnits SrcAlign = 
clang::CharUnits::fromQuantity(SrcAlignLLVM.value());
+  clang::CharUnits DstAlign = 
clang::CharUnits::fromQuantity(DstAlignLLVM.value());
+
+  // Allocate temporary storage for Old value
+  llvm::AllocaInst *Alloca = CGF.CreateTempAlloca(OldType, "old.tmp");
+
+  // Wrap into clang::CodeGen::Address with proper type and alignment
+  Address OldStorage(Alloca, OldType, SrcAlign);
+
+  // Store Old into this temporary
+  CGF.Builder.CreateStore(Old, OldStorage);
+
+  // Bitcast pointers to i8*
+  llvm::Type *I8PtrTy = llvm::PointerType::getUnqual(CGF.getLLVMContext());
+
+  llvm::Value *SrcPtr = CGF.Builder.CreateBitCast(OldStorage.getBasePointer(), 
I8PtrTy);
+  llvm::Value *DstPtr = 
CGF.Builder.CreateBitCast(ExpectedResult.getBasePointer(), I8PtrTy);
+
+  // Perform memcpy for first ExpectedSizeInBytes bytes
+  CGF.Builder.CreateMemCpy(
+DstPtr, DstAlignLLVM,
+SrcPtr, SrcAlignLLVM,
+llvm::ConstantInt::get(CGF.IntPtrTy, ExpectedSizeInBytes),
+/*isVolatile=*/false);
+}
+
+  
   // Finally, branch to the exit point.
   CGF.Builder.CreateBr(ContinueBB);
 
@@ -426,6 +468,7 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 static void emitAtomicCmpXchgFailureSet(CodeGenFunction &CGF, AtomicExpr *E,
 bool IsWeak, Address Dest, Address Ptr,
 Address Val1, Address Val2,
+Address ExpectedResult,
 llvm::Value *FailureOrderVal,
 uint64_t Size,
 llvm::AtomicOrdering SuccessOrder,
@@ -456,7 +499,7 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 // success argument". This condition has been lifted and the only
 // precondition is 31.7.2.18. Effectively treat this as a DR and skip
 // language version checks.
-emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, 
SuccessOrder,
+emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
   FailureOrder, Scope);
 return;
   }
@@ -481,17 +524,17 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 
   // Emit all the different atomics
   CGF.Builder.SetInsertPoint(MonotonicBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult,
 Size, SuccessOrder, llvm::AtomicOrdering::Monotonic, 
Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(AcquireBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, SuccessOrder,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
 llvm::AtomicOrdering::Acquire, Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(SeqCstBB);
-  emitAtomicCmpX

[clang] [libcxx] [clang] [libc++] fix _Atomic c11 compare exchange does not update expected results (PR #78707)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Hui (huixie90)


Changes

fixes #30023

---

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGAtomic.cpp (+69-23) 
- (added) clang/test/CodeGenCXX/builtin-atomic-compare_exchange.cpp (+126) 
- (added) libcxx/test/std/atomics/atomics.types.generic/30023.pass.cpp (+65) 


``diff
diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 51f0799a792fd..9eee834a520e0 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -376,6 +376,7 @@ bool AtomicInfo::emitMemSetZeroIfNecessary() const {
 static void emitAtomicCmpXchg(CodeGenFunction &CGF, AtomicExpr *E, bool IsWeak,
   Address Dest, Address Ptr,
   Address Val1, Address Val2,
+  Address ExpectedResult,
   uint64_t Size,
   llvm::AtomicOrdering SuccessOrder,
   llvm::AtomicOrdering FailureOrder,
@@ -411,7 +412,48 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 
   CGF.Builder.SetInsertPoint(StoreExpectedBB);
   // Update the memory at Expected with Old's value.
-  CGF.Builder.CreateStore(Old, Val1);
+llvm::Type *ExpectedType = ExpectedResult.getElementType();
+const llvm::DataLayout &DL = CGF.CGM.getDataLayout();
+uint64_t ExpectedSizeInBytes = DL.getTypeStoreSize(ExpectedType);
+
+if (ExpectedSizeInBytes == Size) {
+  // Sizes match: store directly
+  CGF.Builder.CreateStore(Old, ExpectedResult);
+
+} else {
+  // store only the first ExpectedSizeInBytes bytes of Old
+  llvm::Type *OldType = Old->getType();
+
+  llvm::Align SrcAlignLLVM = DL.getABITypeAlign(OldType);
+  llvm::Align DstAlignLLVM = DL.getABITypeAlign(ExpectedType);
+
+  clang::CharUnits SrcAlign = 
clang::CharUnits::fromQuantity(SrcAlignLLVM.value());
+  clang::CharUnits DstAlign = 
clang::CharUnits::fromQuantity(DstAlignLLVM.value());
+
+  // Allocate temporary storage for Old value
+  llvm::AllocaInst *Alloca = CGF.CreateTempAlloca(OldType, "old.tmp");
+
+  // Wrap into clang::CodeGen::Address with proper type and alignment
+  Address OldStorage(Alloca, OldType, SrcAlign);
+
+  // Store Old into this temporary
+  CGF.Builder.CreateStore(Old, OldStorage);
+
+  // Bitcast pointers to i8*
+  llvm::Type *I8PtrTy = llvm::PointerType::getUnqual(CGF.getLLVMContext());
+
+  llvm::Value *SrcPtr = CGF.Builder.CreateBitCast(OldStorage.getBasePointer(), 
I8PtrTy);
+  llvm::Value *DstPtr = 
CGF.Builder.CreateBitCast(ExpectedResult.getBasePointer(), I8PtrTy);
+
+  // Perform memcpy for first ExpectedSizeInBytes bytes
+  CGF.Builder.CreateMemCpy(
+DstPtr, DstAlignLLVM,
+SrcPtr, SrcAlignLLVM,
+llvm::ConstantInt::get(CGF.IntPtrTy, ExpectedSizeInBytes),
+/*isVolatile=*/false);
+}
+
+  
   // Finally, branch to the exit point.
   CGF.Builder.CreateBr(ContinueBB);
 
@@ -426,6 +468,7 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 static void emitAtomicCmpXchgFailureSet(CodeGenFunction &CGF, AtomicExpr *E,
 bool IsWeak, Address Dest, Address Ptr,
 Address Val1, Address Val2,
+Address ExpectedResult,
 llvm::Value *FailureOrderVal,
 uint64_t Size,
 llvm::AtomicOrdering SuccessOrder,
@@ -456,7 +499,7 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 // success argument". This condition has been lifted and the only
 // precondition is 31.7.2.18. Effectively treat this as a DR and skip
 // language version checks.
-emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, 
SuccessOrder,
+emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
   FailureOrder, Scope);
 return;
   }
@@ -481,17 +524,17 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 
   // Emit all the different atomics
   CGF.Builder.SetInsertPoint(MonotonicBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult,
 Size, SuccessOrder, llvm::AtomicOrdering::Monotonic, 
Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(AcquireBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, SuccessOrder,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
 llvm::AtomicOrdering::Acquire, Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(SeqCstBB);
-  emitAtomicCmpXc

[clang] [libcxx] [clang] [libc++] fix _Atomic c11 compare exchange does not update expected results (PR #78707)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Hui (huixie90)


Changes

fixes #30023

---

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGAtomic.cpp (+69-23) 
- (added) clang/test/CodeGenCXX/builtin-atomic-compare_exchange.cpp (+126) 
- (added) libcxx/test/std/atomics/atomics.types.generic/30023.pass.cpp (+65) 


``diff
diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 51f0799a792fd..9eee834a520e0 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -376,6 +376,7 @@ bool AtomicInfo::emitMemSetZeroIfNecessary() const {
 static void emitAtomicCmpXchg(CodeGenFunction &CGF, AtomicExpr *E, bool IsWeak,
   Address Dest, Address Ptr,
   Address Val1, Address Val2,
+  Address ExpectedResult,
   uint64_t Size,
   llvm::AtomicOrdering SuccessOrder,
   llvm::AtomicOrdering FailureOrder,
@@ -411,7 +412,48 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 
   CGF.Builder.SetInsertPoint(StoreExpectedBB);
   // Update the memory at Expected with Old's value.
-  CGF.Builder.CreateStore(Old, Val1);
+llvm::Type *ExpectedType = ExpectedResult.getElementType();
+const llvm::DataLayout &DL = CGF.CGM.getDataLayout();
+uint64_t ExpectedSizeInBytes = DL.getTypeStoreSize(ExpectedType);
+
+if (ExpectedSizeInBytes == Size) {
+  // Sizes match: store directly
+  CGF.Builder.CreateStore(Old, ExpectedResult);
+
+} else {
+  // store only the first ExpectedSizeInBytes bytes of Old
+  llvm::Type *OldType = Old->getType();
+
+  llvm::Align SrcAlignLLVM = DL.getABITypeAlign(OldType);
+  llvm::Align DstAlignLLVM = DL.getABITypeAlign(ExpectedType);
+
+  clang::CharUnits SrcAlign = 
clang::CharUnits::fromQuantity(SrcAlignLLVM.value());
+  clang::CharUnits DstAlign = 
clang::CharUnits::fromQuantity(DstAlignLLVM.value());
+
+  // Allocate temporary storage for Old value
+  llvm::AllocaInst *Alloca = CGF.CreateTempAlloca(OldType, "old.tmp");
+
+  // Wrap into clang::CodeGen::Address with proper type and alignment
+  Address OldStorage(Alloca, OldType, SrcAlign);
+
+  // Store Old into this temporary
+  CGF.Builder.CreateStore(Old, OldStorage);
+
+  // Bitcast pointers to i8*
+  llvm::Type *I8PtrTy = llvm::PointerType::getUnqual(CGF.getLLVMContext());
+
+  llvm::Value *SrcPtr = CGF.Builder.CreateBitCast(OldStorage.getBasePointer(), 
I8PtrTy);
+  llvm::Value *DstPtr = 
CGF.Builder.CreateBitCast(ExpectedResult.getBasePointer(), I8PtrTy);
+
+  // Perform memcpy for first ExpectedSizeInBytes bytes
+  CGF.Builder.CreateMemCpy(
+DstPtr, DstAlignLLVM,
+SrcPtr, SrcAlignLLVM,
+llvm::ConstantInt::get(CGF.IntPtrTy, ExpectedSizeInBytes),
+/*isVolatile=*/false);
+}
+
+  
   // Finally, branch to the exit point.
   CGF.Builder.CreateBr(ContinueBB);
 
@@ -426,6 +468,7 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 static void emitAtomicCmpXchgFailureSet(CodeGenFunction &CGF, AtomicExpr *E,
 bool IsWeak, Address Dest, Address Ptr,
 Address Val1, Address Val2,
+Address ExpectedResult,
 llvm::Value *FailureOrderVal,
 uint64_t Size,
 llvm::AtomicOrdering SuccessOrder,
@@ -456,7 +499,7 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 // success argument". This condition has been lifted and the only
 // precondition is 31.7.2.18. Effectively treat this as a DR and skip
 // language version checks.
-emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, 
SuccessOrder,
+emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
   FailureOrder, Scope);
 return;
   }
@@ -481,17 +524,17 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 
   // Emit all the different atomics
   CGF.Builder.SetInsertPoint(MonotonicBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult,
 Size, SuccessOrder, llvm::AtomicOrdering::Monotonic, 
Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(AcquireBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, SuccessOrder,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
 llvm::AtomicOrdering::Acquire, Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(SeqCstBB);
-  emitAto

[clang] [clang-format][NFC] Clean up fillRanges() in ClangFormat.cpp (PR #143236)

2025-06-07 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/143236

>From 1ece3adee540295efbe04fc74876efd39549e577 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 6 Jun 2025 23:10:18 -0700
Subject: [PATCH 1/2] [clang-format][NFC] Clean up fillRanges() in
 ClangFormat.cpp

---
 clang/tools/clang-format/ClangFormat.cpp | 43 
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index b22d3aaf3183b..441ed442a30a9 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -244,17 +244,17 @@ static bool fillRanges(MemoryBuffer *Code,
   DiagnosticsEngine Diagnostics(
   IntrusiveRefCntPtr(new DiagnosticIDs), DiagOpts);
   SourceManager Sources(Diagnostics, Files);
-  FileID ID = createInMemoryFile("", *Code, Sources, Files,
- InMemoryFileSystem.get());
+  const auto ID = createInMemoryFile("", *Code, Sources, Files,
+ InMemoryFileSystem.get());
   if (!LineRanges.empty()) {
 if (!Offsets.empty() || !Lengths.empty()) {
   errs() << "error: cannot use -lines with -offset/-length\n";
   return true;
 }
 
-for (unsigned i = 0, e = LineRanges.size(); i < e; ++i) {
+for (const auto &LineRange : LineRanges) {
   unsigned FromLine, ToLine;
-  if (parseLineRange(LineRanges[i], FromLine, ToLine)) {
+  if (parseLineRange(LineRange, FromLine, ToLine)) {
 errs() << "error: invalid : pair\n";
 return true;
   }
@@ -266,12 +266,12 @@ static bool fillRanges(MemoryBuffer *Code,
 errs() << "error: start line should not exceed end line\n";
 return true;
   }
-  SourceLocation Start = Sources.translateLineCol(ID, FromLine, 1);
-  SourceLocation End = Sources.translateLineCol(ID, ToLine, UINT_MAX);
+  const auto Start = Sources.translateLineCol(ID, FromLine, 1);
+  const auto End = Sources.translateLineCol(ID, ToLine, UINT_MAX);
   if (Start.isInvalid() || End.isInvalid())
 return true;
-  unsigned Offset = Sources.getFileOffset(Start);
-  unsigned Length = Sources.getFileOffset(End) - Offset;
+  const auto Offset = Sources.getFileOffset(Start);
+  const auto Length = Sources.getFileOffset(End) - Offset;
   Ranges.push_back(tooling::Range(Offset, Length));
 }
 return false;
@@ -284,27 +284,28 @@ static bool fillRanges(MemoryBuffer *Code,
 errs() << "error: number of -offset and -length arguments must match.\n";
 return true;
   }
-  for (unsigned i = 0, e = Offsets.size(); i != e; ++i) {
-if (Offsets[i] >= Code->getBufferSize()) {
-  errs() << "error: offset " << Offsets[i] << " is outside the file\n";
+  for (unsigned I = 0, E = Offsets.size(), Size = Lengths.size(); I < E; ++I) {
+auto Offset = Offsets[I];
+if (Offset >= Code->getBufferSize()) {
+  errs() << "error: offset " << Offset << " is outside the file\n";
   return true;
 }
-SourceLocation Start =
-Sources.getLocForStartOfFile(ID).getLocWithOffset(Offsets[i]);
+const auto Start =
+Sources.getLocForStartOfFile(ID).getLocWithOffset(Offset);
 SourceLocation End;
-if (i < Lengths.size()) {
-  if (Offsets[i] + Lengths[i] > Code->getBufferSize()) {
-errs() << "error: invalid length " << Lengths[i]
-   << ", offset + length (" << Offsets[i] + Lengths[i]
-   << ") is outside the file.\n";
+if (I < Size) {
+  const auto L = Lengths[I];
+  if (Offset + L > Code->getBufferSize()) {
+errs() << "error: invalid length " << L << ", offset + length ("
+   << Offset + L << ") is outside the file.\n";
 return true;
   }
-  End = Start.getLocWithOffset(Lengths[i]);
+  End = Start.getLocWithOffset(L);
 } else {
   End = Sources.getLocForEndOfFile(ID);
 }
-unsigned Offset = Sources.getFileOffset(Start);
-unsigned Length = Sources.getFileOffset(End) - Offset;
+Offset = Sources.getFileOffset(Start);
+const auto Length = Sources.getFileOffset(End) - Offset;
 Ranges.push_back(tooling::Range(Offset, Length));
   }
   return false;

>From e9a71f2972824a90ab6da6279599ca4d79376f55 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 7 Jun 2025 00:31:21 -0700
Subject: [PATCH 2/2] More cleanup: - Don't recalculate Offset for -offset. -
 Calculate Length only if -length is unspecified.

---
 clang/tools/clang-format/ClangFormat.cpp | 19 +++
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 441ed442a30a9..03a3cbbe2a9f7 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -285,27 +285,22 @@ static bool fillRanges(MemoryBuffer *Code,
 return true;
   }
   for (unsign

[clang-tools-extra] [clangd] Guard against trivial FunctionProtoTypeLoc when creating inlay hints (PR #143087)

2025-06-07 Thread Nathan Ridge via cfe-commits


@@ -368,6 +368,14 @@ static FunctionProtoTypeLoc getPrototypeLoc(Expr *Fn) {
   }
 
   if (auto F = Target.getAs()) {
+// In some edge cases the AST can contain a "trivial" FunctionProtoTypeLoc
+// which has null parameters. Avoid these as they don't contain useful
+// information.
+for (const auto *Param : F.getParams()) {

HighCommander4 wrote:

My impression from having read some of the related code is that it's a known 
deficiency that having null parameters can sometimes happen.

`TypeLoc` has a method named 
[`initialize()`](https://searchfox.org/llvm/rev/269c29ae67e54bd3243535a7c58d0f30d1eb9036/clang/include/clang/AST/TypeLoc.h#201),
 which is described as follows:

```c++
  /// Initializes this to state that every location in this
  /// type is the given location.
  ///
  /// This method exists to provide a simple transition for code that
  /// relies on location-less types.
  void initialize(ASTContext &Context, SourceLocation Loc) const {
```

The implementation of `initialize` for `FunctionTypeLoc` [does set the 
parameters to 
null](https://searchfox.org/llvm/rev/269c29ae67e54bd3243535a7c58d0f30d1eb9036/clang/include/clang/AST/TypeLoc.h#1579).

And there are various places in the code where we call `initialize`. In 
addition to the `noreturn` scenario exercised in this patch's testcase, which 
will be improved in https://github.com/llvm/llvm-project/pull/143143, another 
notable call site is 
[`ASTContext::getTrivialTypeSourceInfo`](https://searchfox.org/llvm/rev/269c29ae67e54bd3243535a7c58d0f30d1eb9036/clang/lib/AST/ASTContext.cpp#3132).
 That in turn has [many 
callers](https://searchfox.org/llvm/search?q=symbol:_ZNK5clang10ASTContext24getTrivialTypeSourceInfoENS_8QualTypeENS_14SourceLocationE&redirect=false),
 including [this 
one](https://searchfox.org/llvm/rev/269c29ae67e54bd3243535a7c58d0f30d1eb9036/clang/lib/Sema/SemaType.cpp#5679)
 used to handle an invalid declarator.

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


[clang] [libcxx] [clang] [libc++] fix _Atomic c11 compare exchange does not update expected results (PR #78707)

2025-06-07 Thread via cfe-commits

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


[clang] [WebKit checkers] Add an annotation for pointer conversion. (PR #141277)

2025-06-07 Thread Ziqing Luo via cfe-commits

https://github.com/ziqingluo-90 approved this pull request.

LGTM

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


[clang] [WebKit checkers] Treat passing of a member variable which is capable of CheckedPtr as safe. (PR #142485)

2025-06-07 Thread Ziqing Luo via cfe-commits

https://github.com/ziqingluo-90 approved this pull request.

LGTM

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-07 Thread via cfe-commits

github-actions[bot] wrote:



@egorshamshura 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/142341
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Non-polymorphic trivially relocatable types can have [[trivial_abi]] (PR #143111)

2025-06-07 Thread Corentin Jabot via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/143111

>From d4e5db938e4af98dda2dd4b518273fe339c64bfa Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Fri, 6 Jun 2025 13:09:40 +0200
Subject: [PATCH 1/2] [Clang] Non-polymorphic trivially relocatable types can
 have [[trivial_abi]]

Use the definition of trivially relocatable types to short circuit
some checks for trivial_abi.

Note that this is mostly a no-op as there is a lot of overlap between
trivial_abi and trivial relocatability (ie I can't envision a scenario in
which there would be a trivially relocatable type that would not be
eligible for trivial_abi based on its special member function...
which is good!)

Note that for bases and members we need to check CanPassInRegister
rather than just relocation. So we do these checks first,
which leads to better diagnostics.
---
 clang/include/clang/Sema/Sema.h   |  1 +
 clang/lib/Sema/SemaDeclCXX.cpp| 49 ---
 clang/lib/Sema/SemaTypeTraits.cpp | 12 +++---
 clang/test/SemaCXX/attr-trivial-abi.cpp   | 16 +---
 clang/test/SemaObjCXX/attr-trivial-abi.mm |  3 +-
 5 files changed, 46 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 65c84c0c40f60..88db3f5de7486 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8680,6 +8680,7 @@ class Sema final : public SemaBase {
   // FIXME: This is in Sema because it requires
   // overload resolution, can we move to ASTContext?
   bool IsCXXTriviallyRelocatableType(QualType T);
+  bool IsCXXTriviallyRelocatableType(const CXXRecordDecl &RD);
 
    Determines if a type is replaceable
   /// according to the C++26 rules.
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 55e078f3180a2..190544e9e1cd3 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -10572,29 +10572,6 @@ void 
Sema::checkIllFormedTrivialABIStruct(CXXRecordDecl &RD) {
 RD.dropAttr();
   };
 
-  // Ill-formed if the copy and move constructors are deleted.
-  auto HasNonDeletedCopyOrMoveConstructor = [&]() {
-// If the type is dependent, then assume it might have
-// implicit copy or move ctor because we won't know yet at this point.
-if (RD.isDependentType())
-  return true;
-if (RD.needsImplicitCopyConstructor() &&
-!RD.defaultedCopyConstructorIsDeleted())
-  return true;
-if (RD.needsImplicitMoveConstructor() &&
-!RD.defaultedMoveConstructorIsDeleted())
-  return true;
-for (const CXXConstructorDecl *CD : RD.ctors())
-  if (CD->isCopyOrMoveConstructor() && !CD->isDeleted())
-return true;
-return false;
-  };
-
-  if (!HasNonDeletedCopyOrMoveConstructor()) {
-PrintDiagAndRemoveAttr(0);
-return;
-  }
-
   // Ill-formed if the struct has virtual functions.
   if (RD.isPolymorphic()) {
 PrintDiagAndRemoveAttr(1);
@@ -10638,6 +10615,32 @@ void 
Sema::checkIllFormedTrivialABIStruct(CXXRecordDecl &RD) {
 return;
   }
   }
+
+  if (IsCXXTriviallyRelocatableType(RD))
+return;
+
+  // Ill-formed if the copy and move constructors are deleted.
+  auto HasNonDeletedCopyOrMoveConstructor = [&]() {
+// If the type is dependent, then assume it might have
+// implicit copy or move ctor because we won't know yet at this point.
+if (RD.isDependentType())
+  return true;
+if (RD.needsImplicitCopyConstructor() &&
+!RD.defaultedCopyConstructorIsDeleted())
+  return true;
+if (RD.needsImplicitMoveConstructor() &&
+!RD.defaultedMoveConstructorIsDeleted())
+  return true;
+for (const CXXConstructorDecl *CD : RD.ctors())
+  if (CD->isCopyOrMoveConstructor() && !CD->isDeleted())
+return true;
+return false;
+  };
+
+  if (!HasNonDeletedCopyOrMoveConstructor()) {
+PrintDiagAndRemoveAttr(0);
+return;
+  }
 }
 
 void Sema::checkIncorrectVTablePointerAuthenticationAttribute(
diff --git a/clang/lib/Sema/SemaTypeTraits.cpp 
b/clang/lib/Sema/SemaTypeTraits.cpp
index b849bbe94af62..865a460a97458 100644
--- a/clang/lib/Sema/SemaTypeTraits.cpp
+++ b/clang/lib/Sema/SemaTypeTraits.cpp
@@ -295,13 +295,13 @@ Sema::CheckCXX2CRelocatableAndReplaceable(const 
CXXRecordDecl *D) {
   return Info;
 }
 
-static bool IsCXXTriviallyRelocatableType(Sema &S, const CXXRecordDecl *RD) {
+bool Sema::IsCXXTriviallyRelocatableType(const CXXRecordDecl &RD) {
   if (std::optional Info =
-  S.getASTContext().getRelocationInfoForCXXRecord(RD))
+  getASTContext().getRelocationInfoForCXXRecord(&RD))
 return Info->IsRelocatable;
   ASTContext::CXXRecordDeclRelocationInfo Info =
-  S.CheckCXX2CRelocatableAndReplaceable(RD);
-  S.getASTContext().setRelocationInfoForCXXRecord(RD, Info);
+  CheckCXX2CRelocatableAndReplaceable(&RD);
+  getASTContext().setRelocationInfoForCXXRecord(&RD, Info);
   return Info.IsRelocatable;
 }

[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-06-07 Thread Corentin Jabot via cfe-commits

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


[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-06-07 Thread Corentin Jabot via cfe-commits

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


[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-06-07 Thread Corentin Jabot via cfe-commits

cor3ntin wrote:

Do you need us to merge this for you?

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


[clang] [clang] Fix static_cast bypassing access control (PR #132285)

2025-06-07 Thread Corentin Jabot via cfe-commits

cor3ntin wrote:

@offsetof Do you need us to merge that for you?

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


[clang] eec9431 - [Clang] Added explanation why a is trivial copyable evaluated to false. (#142341)

2025-06-07 Thread via cfe-commits

Author: Shamshura Egor
Date: 2025-06-07T09:55:40+02:00
New Revision: eec9431d37e22a627c78e2f345d41a9a40e0c1c0

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

LOG: [Clang] Added explanation why a is trivial copyable evaluated to false. 
(#142341)

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaTypeTraits.cpp
clang/test/SemaCXX/type-traits-unsatisfied-diags-std.cpp
clang/test/SemaCXX/type-traits-unsatisfied-diags.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8ba3bb099d741..e963612f387ef 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1764,7 +1764,8 @@ def err_user_defined_msg_constexpr : Error<
 
 // Type traits explanations
 def note_unsatisfied_trait : Note<"%0 is not %enum_select{"
-  "%TriviallyRelocatable{trivially 
relocatable}"
+  "%TriviallyRelocatable{trivially 
relocatable}|"
+  "%TriviallyCopyable{trivially copyable}"
   "}1">;
 
 def note_unsatisfied_trait_reason
@@ -1774,8 +1775,10 @@ def note_unsatisfied_trait_reason
"%HasArcLifetime{has an ARC lifetime qualifier}|"
"%VLA{is a variably-modified type}|"
"%VBase{has a virtual base %1}|"
-   "%NRBase{has a non-trivially-relocatable base %1}|"
-   "%NRField{has a non-trivially-relocatable member %1 of type %2}|"
+   "%NTRBase{has a non-trivially-relocatable base %1}|"
+   "%NTRField{has a non-trivially-relocatable member %1 of type %2}|"
+   "%NTCBase{has a non-trivially-copyable base %1}|"
+   "%NTCField{has a non-trivially-copyable member %1 of type %2}|"
"%DeletedDtr{has a %select{deleted|user-provided}1 destructor}|"
"%UserProvidedCtr{has a user provided %select{copy|move}1 "
"constructor}|"

diff  --git a/clang/lib/Sema/SemaTypeTraits.cpp 
b/clang/lib/Sema/SemaTypeTraits.cpp
index b849bbe94af62..330f2aa750a09 100644
--- a/clang/lib/Sema/SemaTypeTraits.cpp
+++ b/clang/lib/Sema/SemaTypeTraits.cpp
@@ -11,8 +11,10 @@
 
//===--===//
 
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticParse.h"
 #include "clang/Basic/DiagnosticSema.h"
+#include "clang/Basic/TypeTraits.h"
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Lookup.h"
@@ -1938,6 +1940,7 @@ static std::optional 
StdNameToTypeTrait(StringRef Name) {
   return llvm::StringSwitch>(Name)
   .Case("is_trivially_relocatable",
 TypeTrait::UTT_IsCppTriviallyRelocatable)
+  .Case("is_trivially_copyable", TypeTrait::UTT_IsTriviallyCopyable)
   .Default(std::nullopt);
 }
 
@@ -2013,15 +2016,15 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema 
&SemaRef,
   << B.getSourceRange();
 if (!SemaRef.IsCXXTriviallyRelocatableType(B.getType()))
   SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
-  << diag::TraitNotSatisfiedReason::NRBase << B.getType()
+  << diag::TraitNotSatisfiedReason::NTRBase << B.getType()
   << B.getSourceRange();
   }
   for (const FieldDecl *Field : D->fields()) {
 if (!Field->getType()->isReferenceType() &&
 !SemaRef.IsCXXTriviallyRelocatableType(Field->getType()))
   SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
-  << diag::TraitNotSatisfiedReason::NRField << Field << 
Field->getType()
-  << Field->getSourceRange();
+  << diag::TraitNotSatisfiedReason::NTRField << Field
+  << Field->getType() << Field->getSourceRange();
   }
   if (D->hasDeletedDestructor())
 SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
@@ -2099,6 +2102,82 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema 
&SemaRef,
   SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
 }
 
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+   SourceLocation Loc,
+   const CXXRecordDecl *D) {
+  for (const CXXBaseSpecifier &B : D->bases()) {
+assert(B.getType()->getAsCXXRecordDecl() && "invalid base?");
+if (B.isVirtual())
+  SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+  << diag::TraitNotSatisfiedReason::VBase << B.getType()
+  << B.getSourceRange();
+if (!B.getType().isTriviallyCopyableType(D->getASTContext())) {
+  SemaRef.Diag(Loc, diag::note_unsati

[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-07 Thread Corentin Jabot via cfe-commits

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


[clang] [Clang][Parse][NFC] Use `llvm::function_ref<>` instead of `std::optional>` (PR #142906)

2025-06-07 Thread Corentin Jabot via cfe-commits

cor3ntin wrote:

Do you want me to merge this?

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


[clang] [libclang/python] Derive library function types from annotations (PR #142120)

2025-06-07 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> e.g. Python int maps to both c_int and c_uint

Good example, thank you. So the crux of the issue is that we need to 
reconstruct one kind of function prototype from another. On the one hand, type 
annotations are consumed (mostly) statically, while ctypes prototype is 
consumed dynamically, so it makes sense to write in the source what is consumed 
statically. But ctypes prototypes has more information, which we can't recover 
from type annotations.

Sadness

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


[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-06-07 Thread Imad Aldij via cfe-commits

imdj wrote:

> Do you need us to merge this for you?

Yeah, I don't think I have access

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


[clang] [Clang] Clarify the `[[trivial_abi]]` documentation. (PR #143243)

2025-06-07 Thread Corentin Jabot via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/143243

Fixes #36667

>From 9b6128211ea4a442ecded830c77c60387245bb89 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Sat, 7 Jun 2025 10:24:26 +0200
Subject: [PATCH] [Clang] Clarify the `[[trivial_abi]]` documentation.

Fixes #36667
---
 clang/include/clang/Basic/AttrDocs.td | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 40b9f8142bb69..19d5a76246bf0 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4431,7 +4431,11 @@ destroy the object before returning. The lifetime of the 
copy of the parameter
 in the caller ends without a destructor call when the call begins.
 
 If a type is trivial for the purpose of calls, it is assumed to be trivially
-relocatable for the purpose of ``__is_trivially_relocatable``.
+relocatable for the purpose of ``__is_trivially_relocatable`` and
+``__builtin_is_cpp_trivially_relocatable``.
+The copy constructor of a an object of such type might not be called
+when the object is passed to a function. Therefore, the ``trivial_abi``
+attribute should not be applied to objects that contain pointer to themselves.
 
 Attribute ``trivial_abi`` has no effect in the following cases:
 

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


[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)

2025-06-07 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-aarch64-linux` 
running on `sanitizer-buildbot8` while building `clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
[182/186] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.aarch64-with-call.o
[183/186] Generating Msan-aarch64-with-call-Test
[184/186] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.aarch64.o
[185/186] Generating Msan-aarch64-Test
[185/186] Running compiler_rt regression tests
llvm-lit: 
/home/b/sanitizer-aarch64-linux/build/llvm-project/llvm/utils/lit/lit/discovery.py:276:
 warning: input 
'/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/interception/Unit'
 contained no tests
llvm-lit: 
/home/b/sanitizer-aarch64-linux/build/llvm-project/llvm/utils/lit/lit/discovery.py:276:
 warning: input 
'/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/Unit'
 contained no tests
llvm-lit: 
/home/b/sanitizer-aarch64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:73:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 5924 tests, 72 workers --
Testing:  0.. 10.. 20..
FAIL: HWAddressSanitizer-aarch64 :: 
TestCases/hwasan_symbolize_stack_overflow.cpp (1711 of 5924)
 TEST 'HWAddressSanitizer-aarch64 :: 
TestCases/hwasan_symbolize_stack_overflow.cpp' FAILED 
Exit Code: 1

Command Output (stderr):
--
rm -rf 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/hwasan/AARCH64/TestCases/Output/hwasan_symbolize_stack_overflow.cpp.tmp;
 mkdir 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/hwasan/AARCH64/TestCases/Output/hwasan_symbolize_stack_overflow.cpp.tmp
 # RUN: at line 1
+ rm -rf 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/hwasan/AARCH64/TestCases/Output/hwasan_symbolize_stack_overflow.cpp.tmp
+ mkdir 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/hwasan/AARCH64/TestCases/Output/hwasan_symbolize_stack_overflow.cpp.tmp
/home/b/sanitizer-aarch64-linux/build/build_default/./bin/clang
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   
-gline-tables-only -fsanitize=hwaddress -fuse-ld=lld -mllvm -hwasan-globals 
-mllvm -hwasan-use-short-granules -mllvm -hwasan-instrument-landing-pads=0 
-mllvm -hwasan-instrument-personality-functions -Wl,--build-id -g 
/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/hwasan/TestCases/hwasan_symbolize_stack_overflow.cpp
 -o 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/hwasan/AARCH64/TestCases/Output/hwasan_symbolize_stack_overflow.cpp.tmp/hwasan_overflow
 # RUN: at line 2
+ /home/b/sanitizer-aarch64-linux/build/build_default/./bin/clang 
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta 
-gline-tables-only -fsanitize=hwaddress -fuse-ld=lld -mllvm -hwasan-globals 
-mllvm -hwasan-use-short-granules -mllvm -hwasan-instrument-landing-pads=0 
-mllvm -hwasan-instrument-personality-functions -Wl,--build-id -g 
/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/hwasan/TestCases/hwasan_symbolize_stack_overflow.cpp
 -o 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/hwasan/AARCH64/TestCases/Output/hwasan_symbolize_stack_overflow.cpp.tmp/hwasan_overflow
env 
HWASAN_OPTIONS=disable_allocator_tagging=1:random_tags=0:fail_without_syscall_abi=0:symbolize=0
 not  
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/hwasan/AARCH64/TestCases/Output/hwasan_symbolize_stack_overflow.cpp.tmp/hwasan_overflow
 16 2>&1 | 
/home/b/sanitizer-aarch64-linux/build/build_default/bin/hwasan_symbolize 
--symbols 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/hwasan/AARCH64/TestCases/Output/hwasan_symbolize_stack_overflow.cpp.tmp
 --index | FileCheck 
/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/hwasan/TestCases/hwasan_symbolize_stack_overflow.cpp
 --check-prefixes=CHECK,AFTER0 # RUN: at line 3
+ env 
HWASAN_OPTIONS=disable_allocator_tagging=1:random_tags=0:fail_without_syscall_abi=0:symbolize=0
 not 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/hwasan/AARCH64/TestCases/Output/hwasan_symbolize_stack_overflow.cpp.tmp/hwasan_overflow
 16
+ /home/b/sanitizer-aarch64-linux/build/build_defaul

[clang] [clang] fix infinite recursion (PR #143244)

2025-06-07 Thread Zhikai Zeng via cfe-commits

https://github.com/Backl1ght created 
https://github.com/llvm/llvm-project/pull/143244

fix https://github.com/llvm/llvm-project/issues/141789

The direct cause of infinite recursion is  that `T` is changing from `struct X` 
and  `S` infinitely,  this pr add a check that if  `T` visited before then 
return false directly.

```plaintext
/home/backlight/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:7196] 
FD->getType().getAsString()=struct X, T.getAsString()=S, 
FD->getType().getCanonicalType().getUnqualifiedType().getAsString()=struct X, 
CanUnqualT.getAsString()=struct S, 
/home/backlight/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:7196] 
FD->getType().getAsString()=S, T.getAsString()=struct X, 
FD->getType().getCanonicalType().getUnqualifiedType().getAsString()=struct 
S, CanUnqualT.getAsString()=struct X,
```

https://github.com/llvm/llvm-project/pull/104829 fix similar infinite 
recursion, but I think it is no longer needed so I kind of revert it.

>From a52a1254a9eea86f332ff2c31c3f33dd57b8a288 Mon Sep 17 00:00:00 2001
From: Backl1ght 
Date: Sat, 7 Jun 2025 16:15:04 +0800
Subject: [PATCH] add visit check

---
 clang/lib/Sema/SemaDeclCXX.cpp  | 14 ++
 clang/test/SemaCXX/gh102293.cpp | 17 +
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 5ef2ae3ee857f..9f66c194a45dd 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7172,7 +7172,10 @@ void Sema::CheckCompletedCXXClass(Scope *S, 
CXXRecordDecl *Record) {
 // "effectively constexpr" for better compatibility.
 // See https://github.com/llvm/llvm-project/issues/102293 for more info.
 if (isa(M)) {
-  auto Check = [](QualType T, auto &&Check) -> bool {
+  llvm::DenseSet Visited;
+  auto Check = [&Visited](QualType T, auto &&Check) -> bool {
+if (!Visited.insert(T).second)
+  return false;
 const CXXRecordDecl *RD =
 T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
 if (!RD || !RD->isCompleteDefinition())
@@ -7181,16 +7184,11 @@ void Sema::CheckCompletedCXXClass(Scope *S, 
CXXRecordDecl *Record) {
 if (!RD->hasConstexprDestructor())
   return false;
 
-QualType CanUnqualT = T.getCanonicalType().getUnqualifiedType();
 for (const CXXBaseSpecifier &B : RD->bases())
-  if (B.getType().getCanonicalType().getUnqualifiedType() !=
-  CanUnqualT &&
-  !Check(B.getType(), Check))
+  if (!Check(B.getType(), Check))
 return false;
 for (const FieldDecl *FD : RD->fields())
-  if (FD->getType().getCanonicalType().getUnqualifiedType() !=
-  CanUnqualT &&
-  !Check(FD->getType(), Check))
+  if (!Check(FD->getType(), Check))
 return false;
 return true;
   };
diff --git a/clang/test/SemaCXX/gh102293.cpp b/clang/test/SemaCXX/gh102293.cpp
index d4218cc13dcec..fe417e697841b 100644
--- a/clang/test/SemaCXX/gh102293.cpp
+++ b/clang/test/SemaCXX/gh102293.cpp
@@ -45,3 +45,20 @@ class quux : quux { // expected-error {{base class has 
incomplete type}} \
   virtual int c();
 };
 }
+
+// Ensure we don't get infinite recursion from the check, however. See GH141789
+namespace GH141789 {
+template 
+struct S {
+  Ty t; // expected-error {{field has incomplete type 'GH141789::X'}}
+};
+
+struct T {
+  ~T();
+};
+
+struct X { // expected-note {{definition of 'GH141789::X' is not complete 
until the closing '}'}}
+  S next; // expected-note {{in instantiation of template class 
'GH141789::S' requested here}}
+  T m;
+};
+}

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


[clang] [clang] fix infinite recursion (PR #143244)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Zhikai Zeng (Backl1ght)


Changes

fix https://github.com/llvm/llvm-project/issues/141789

The direct cause of infinite recursion is  that `T` is changing from `struct X` 
and  `S` infinitely,  this pr add a check that if  `T` visited before 
then return false directly.

```plaintext
/home/backlight/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:7196] 
FD->getType().getAsString()=struct X, T.getAsString()=S, 
FD->getType().getCanonicalType().getUnqualifiedType().getAsString()=struct 
X, CanUnqualT.getAsString()=struct S, 
/home/backlight/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:7196] 
FD->getType().getAsString()=S, T.getAsString()=struct X, 
FD->getType().getCanonicalType().getUnqualifiedType().getAsString()=struct 
S, CanUnqualT.getAsString()=struct X,
```

https://github.com/llvm/llvm-project/pull/104829 fix similar infinite 
recursion, but I think it is no longer needed so I kind of revert it.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+6-8) 
- (modified) clang/test/SemaCXX/gh102293.cpp (+17) 


``diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 5ef2ae3ee857f..9f66c194a45dd 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7172,7 +7172,10 @@ void Sema::CheckCompletedCXXClass(Scope *S, 
CXXRecordDecl *Record) {
 // "effectively constexpr" for better compatibility.
 // See https://github.com/llvm/llvm-project/issues/102293 for more info.
 if (isa(M)) {
-  auto Check = [](QualType T, auto &&Check) -> bool {
+  llvm::DenseSet Visited;
+  auto Check = [&Visited](QualType T, auto &&Check) -> bool {
+if (!Visited.insert(T).second)
+  return false;
 const CXXRecordDecl *RD =
 T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
 if (!RD || !RD->isCompleteDefinition())
@@ -7181,16 +7184,11 @@ void Sema::CheckCompletedCXXClass(Scope *S, 
CXXRecordDecl *Record) {
 if (!RD->hasConstexprDestructor())
   return false;
 
-QualType CanUnqualT = T.getCanonicalType().getUnqualifiedType();
 for (const CXXBaseSpecifier &B : RD->bases())
-  if (B.getType().getCanonicalType().getUnqualifiedType() !=
-  CanUnqualT &&
-  !Check(B.getType(), Check))
+  if (!Check(B.getType(), Check))
 return false;
 for (const FieldDecl *FD : RD->fields())
-  if (FD->getType().getCanonicalType().getUnqualifiedType() !=
-  CanUnqualT &&
-  !Check(FD->getType(), Check))
+  if (!Check(FD->getType(), Check))
 return false;
 return true;
   };
diff --git a/clang/test/SemaCXX/gh102293.cpp b/clang/test/SemaCXX/gh102293.cpp
index d4218cc13dcec..fe417e697841b 100644
--- a/clang/test/SemaCXX/gh102293.cpp
+++ b/clang/test/SemaCXX/gh102293.cpp
@@ -45,3 +45,20 @@ class quux : quux { // expected-error {{base class has 
incomplete type}} \
   virtual int c();
 };
 }
+
+// Ensure we don't get infinite recursion from the check, however. See GH141789
+namespace GH141789 {
+template 
+struct S {
+  Ty t; // expected-error {{field has incomplete type 'GH141789::X'}}
+};
+
+struct T {
+  ~T();
+};
+
+struct X { // expected-note {{definition of 'GH141789::X' is not complete 
until the closing '}'}}
+  S next; // expected-note {{in instantiation of template class 
'GH141789::S' requested here}}
+  T m;
+};
+}

``




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


[clang] [libclang/python] Derive library function types from annotations (PR #142120)

2025-06-07 Thread Jannick Kremer via cfe-commits

DeinAlptraum wrote:

Yup that summarizes it pretty well.
So I don't see this having more than a very limited use, and for that it's not 
worth the various overheads and intransparencies it introduces. Shall I close 
this?

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


[clang] [C++20][Modules] Fix false compilation error with constexpr (PR #143168)

2025-06-07 Thread Corentin Jabot via cfe-commits

cor3ntin wrote:

This change needs a release note.
Please add an entry to `clang/docs/ReleaseNotes.rst` in the section the most 
adapted to the change, and referencing any Github issue this change fixes. 
Thanks!

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


[clang] [clang] fix infinite recursion (PR #143244)

2025-06-07 Thread Zhikai Zeng via cfe-commits

https://github.com/Backl1ght updated 
https://github.com/llvm/llvm-project/pull/143244

>From a52a1254a9eea86f332ff2c31c3f33dd57b8a288 Mon Sep 17 00:00:00 2001
From: Backl1ght 
Date: Sat, 7 Jun 2025 16:15:04 +0800
Subject: [PATCH] add visit check

---
 clang/lib/Sema/SemaDeclCXX.cpp  | 14 ++
 clang/test/SemaCXX/gh102293.cpp | 17 +
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 5ef2ae3ee857f..9f66c194a45dd 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7172,7 +7172,10 @@ void Sema::CheckCompletedCXXClass(Scope *S, 
CXXRecordDecl *Record) {
 // "effectively constexpr" for better compatibility.
 // See https://github.com/llvm/llvm-project/issues/102293 for more info.
 if (isa(M)) {
-  auto Check = [](QualType T, auto &&Check) -> bool {
+  llvm::DenseSet Visited;
+  auto Check = [&Visited](QualType T, auto &&Check) -> bool {
+if (!Visited.insert(T).second)
+  return false;
 const CXXRecordDecl *RD =
 T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
 if (!RD || !RD->isCompleteDefinition())
@@ -7181,16 +7184,11 @@ void Sema::CheckCompletedCXXClass(Scope *S, 
CXXRecordDecl *Record) {
 if (!RD->hasConstexprDestructor())
   return false;
 
-QualType CanUnqualT = T.getCanonicalType().getUnqualifiedType();
 for (const CXXBaseSpecifier &B : RD->bases())
-  if (B.getType().getCanonicalType().getUnqualifiedType() !=
-  CanUnqualT &&
-  !Check(B.getType(), Check))
+  if (!Check(B.getType(), Check))
 return false;
 for (const FieldDecl *FD : RD->fields())
-  if (FD->getType().getCanonicalType().getUnqualifiedType() !=
-  CanUnqualT &&
-  !Check(FD->getType(), Check))
+  if (!Check(FD->getType(), Check))
 return false;
 return true;
   };
diff --git a/clang/test/SemaCXX/gh102293.cpp b/clang/test/SemaCXX/gh102293.cpp
index d4218cc13dcec..fe417e697841b 100644
--- a/clang/test/SemaCXX/gh102293.cpp
+++ b/clang/test/SemaCXX/gh102293.cpp
@@ -45,3 +45,20 @@ class quux : quux { // expected-error {{base class has 
incomplete type}} \
   virtual int c();
 };
 }
+
+// Ensure we don't get infinite recursion from the check, however. See GH141789
+namespace GH141789 {
+template 
+struct S {
+  Ty t; // expected-error {{field has incomplete type 'GH141789::X'}}
+};
+
+struct T {
+  ~T();
+};
+
+struct X { // expected-note {{definition of 'GH141789::X' is not complete 
until the closing '}'}}
+  S next; // expected-note {{in instantiation of template class 
'GH141789::S' requested here}}
+  T m;
+};
+}

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


[clang] [Clang] Clarify the `[[trivial_abi]]` documentation. (PR #143243)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Corentin Jabot (cor3ntin)


Changes

Fixes #36667

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


1 Files Affected:

- (modified) clang/include/clang/Basic/AttrDocs.td (+5-1) 


``diff
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 40b9f8142bb69..19d5a76246bf0 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4431,7 +4431,11 @@ destroy the object before returning. The lifetime of the 
copy of the parameter
 in the caller ends without a destructor call when the call begins.
 
 If a type is trivial for the purpose of calls, it is assumed to be trivially
-relocatable for the purpose of ``__is_trivially_relocatable``.
+relocatable for the purpose of ``__is_trivially_relocatable`` and
+``__builtin_is_cpp_trivially_relocatable``.
+The copy constructor of a an object of such type might not be called
+when the object is passed to a function. Therefore, the ``trivial_abi``
+attribute should not be applied to objects that contain pointer to themselves.
 
 Attribute ``trivial_abi`` has no effect in the following cases:
 

``




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


[clang] [alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS (PR #141293)

2025-06-07 Thread Ziqing Luo via cfe-commits


@@ -142,6 +144,8 @@ class RawPtrRefMemberChecker
 if (auto *ID = dyn_cast(CD)) {
   for (auto *Ivar : ID->ivars())
 visitIvarDecl(CD, Ivar);
+  for (auto *PropImpl : ID->property_impls())
+visitPropImpl(CD, PropImpl);

ziqingluo-90 wrote:

`visitPropImpl` populates `IvarDeclsToIgnore`.   Should it be called before 
`visitIvarDecl`?

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


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2025-06-07 Thread Corentin Jabot via cfe-commits

cor3ntin wrote:

We implemented `__builtin_is_cpp_trivially_relocatable`, so I think this can be 
closed

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


[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-06-07 Thread Corentin Jabot via cfe-commits

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


[clang] bc93131 - [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (#132919)

2025-06-07 Thread via cfe-commits

Author: Imad Aldij
Date: 2025-06-07T11:31:04+02:00
New Revision: bc931318a2880360f3970e1e6906adc9c90eb698

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

LOG: [Clang] Implement CWG2517 Useless restriction on use of parameter in 
constraint-expression (#132919)

Remove `[expr.prim.req.nested]` check which restrict that local
parameters in constraint-expressions can only appear as unevaluated
operands. This change makes the treatment of examples like `requires`
expressions and other constant expression contexts uniform, consistent
with the adoption of P2280.

References: https://cplusplus.github.io/CWG/issues/2517.html
Fixes  #132825

-

Co-authored-by: cor3ntin 

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/CXX/drs/cwg25xx.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9ab69320f0368..74a205a85da5c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -153,6 +153,8 @@ Resolutions to C++ Defect Reports
 - Bumped the ``__cpp_constexpr`` feature-test macro to ``202002L`` in C++20 
mode as indicated in
   `P2493R0 `_.
 
+- Implemented `CWG2517 Useless restriction on use of parameter in `
+  `constraint-expression `_.
 - Implemented `CWG3005 Function parameters should never be name-independent 
`_.
 
 C Language Changes

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e963612f387ef..5f44d503580b9 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3108,8 +3108,6 @@ def 
err_reference_to_function_with_unsatisfied_constraints : Error<
   "invalid reference to function %0: constraints not satisfied">;
 def err_requires_expr_local_parameter_default_argument : Error<
   "default arguments not allowed for parameters of a requires expression">;
-def err_requires_expr_parameter_referenced_in_evaluated_context : Error<
-  "constraint variable %0 cannot be used in an evaluated context">;
 def note_expr_requirement_expr_substitution_error : Note<
   "%select{and|because}0 '%1' would be invalid: %2">;
 def note_expr_requirement_expr_unknown_substitution_error : Note<

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9c322deb55e00..c7abbbd6993de 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -397,17 +397,6 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, 
ArrayRef Locs,
   targetDiag(*Locs.begin(), diag::err_thread_unsupported);
   }
 
-  if (isa(D) && isa(D->getDeclContext()) &&
-  !isUnevaluatedContext()) {
-// C++ [expr.prim.req.nested] p3
-//   A local parameter shall only appear as an unevaluated operand
-//   (Clause 8) within the constraint-expression.
-Diag(Loc, 
diag::err_requires_expr_parameter_referenced_in_evaluated_context)
-<< D;
-Diag(D->getLocation(), diag::note_entity_declared_at) << D;
-return true;
-  }
-
   return false;
 }
 

diff  --git a/clang/test/CXX/drs/cwg25xx.cpp b/clang/test/CXX/drs/cwg25xx.cpp
index d9a7d2bbb2671..5c2948f67d0ee 100644
--- a/clang/test/CXX/drs/cwg25xx.cpp
+++ b/clang/test/CXX/drs/cwg25xx.cpp
@@ -32,6 +32,26 @@ enum E2 : S::I { e };
 #endif
 } // namespace cwg2516
 
+namespace cwg2517 { // cwg2517: 21
+#if __cplusplus >= 202002L
+template
+concept LargeArray = requires (ArrayType my_array) {
+  requires my_array.size() > 5;
+};
+
+struct Big {
+  constexpr int size() const { return 100; }
+};
+
+struct Small {
+  constexpr int size() const { return 3; }
+};
+
+static_assert(LargeArray);
+static_assert(!LargeArray);
+#endif
+} // namespace cwg2517
+
 namespace cwg2518 { // cwg2518: 17
 
 #if __cplusplus >= 201103L

diff  --git 
a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
index 19145f68b2f75..033ae349a02e5 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -41,9 +41,17 @@ namespace std_example {
   template
   concept C2 = requires (T a) {
   requires sizeof(a) == 4; // OK
-  requires a == 0; // expected-note{{because 'a == 0' would be invalid: 
constraint variable 'a' cannot be used in an evaluated context}}
+  requires a == 0; // expected-error{{sub

[clang] [Cygwin] va_list must be treated like normal Windows (PR #143115)

2025-06-07 Thread Tomohiro Kashiwada via cfe-commits

https://github.com/kikairoya updated 
https://github.com/llvm/llvm-project/pull/143115

>From c64472a188825a1d814ea0523a6097d25949d6fb Mon Sep 17 00:00:00 2001
From: kikairoya 
Date: Sun, 25 May 2025 14:07:29 +0900
Subject: [PATCH 1/2] [Cygwin] va_list must be treated like normal Windows

Handling of va_list on Cygwin environment must be matched to normal
Windows environment.
A new test file is added as existing test contains a unsupported
functionality.
---
 clang/lib/Basic/Targets/X86.h   |  3 ++
 clang/test/CodeGen/X86/cygwin-varargs.c | 37 +
 2 files changed, 40 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/cygwin-varargs.c

diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 780385f9c9bc5..92aa9b5dc92cb 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -979,6 +979,9 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : 
public X86_64TargetInfo {
 if (Opts.CPlusPlus)
   Builder.defineMacro("_GNU_SOURCE");
   }
+  BuiltinVaListKind getBuiltinVaListKind() const override {
+return TargetInfo::CharPtrBuiltinVaList;
+  }
 };
 
 class LLVM_LIBRARY_VISIBILITY DarwinX86_64TargetInfo
diff --git a/clang/test/CodeGen/X86/cygwin-varargs.c 
b/clang/test/CodeGen/X86/cygwin-varargs.c
new file mode 100644
index 0..1d2b9af8a0225
--- /dev/null
+++ b/clang/test/CodeGen/X86/cygwin-varargs.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm < %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-cygwin -emit-llvm < %s | FileCheck %s
+
+// copy ms_abi block only from ../ms_abi.c
+
+struct foo {
+  int x;
+  float y;
+  char z;
+};
+// CHECK: %[[STRUCT_FOO:.*]] = type { i32, float, i8 }
+
+void f(int a, ...) {
+  // CHECK-LABEL: define dso_local void @f
+  __builtin_va_list ap;
+  __builtin_va_start(ap, a);
+  // CHECK: %[[AP:.*]] = alloca ptr
+  // CHECK: call void @llvm.va_start
+  int b = __builtin_va_arg(ap, int);
+  // CHECK: %[[AP_CUR:.*]] = load ptr, ptr %[[AP]]
+  // CHECK-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, ptr %[[AP_CUR]], 
i64 8
+  // CHECK-NEXT: store ptr %[[AP_NEXT]], ptr %[[AP]]
+  double _Complex c = __builtin_va_arg(ap, double _Complex);
+  // CHECK: %[[AP_CUR2:.*]] = load ptr, ptr %[[AP]]
+  // CHECK-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, ptr 
%[[AP_CUR2]], i64 8
+  // CHECK-NEXT: store ptr %[[AP_NEXT2]], ptr %[[AP]]
+  // CHECK-NEXT: load ptr, ptr %[[AP_CUR2]]
+  struct foo d = __builtin_va_arg(ap, struct foo);
+  // CHECK: %[[AP_CUR3:.*]] = load ptr, ptr %[[AP]]
+  // CHECK-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, ptr 
%[[AP_CUR3]], i64 8
+  // CHECK-NEXT: store ptr %[[AP_NEXT3]], ptr %[[AP]]
+  __builtin_va_list ap2;
+  __builtin_va_copy(ap2, ap);
+  // CHECK: call void @llvm.va_copy
+  __builtin_va_end(ap);
+  // CHECK: call void @llvm.va_end
+}

>From ac40213cffd5f34d35ec737a82585623756af2a1 Mon Sep 17 00:00:00 2001
From: Tomohiro Kashiwada 
Date: Sat, 7 Jun 2025 15:41:43 +0900
Subject: [PATCH 2/2] Update clang/lib/Basic/Targets/X86.h

Co-authored-by: jeremyd2019 
---
 clang/lib/Basic/Targets/X86.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 92aa9b5dc92cb..92e8edfec0151 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -979,6 +979,7 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : 
public X86_64TargetInfo {
 if (Opts.CPlusPlus)
   Builder.defineMacro("_GNU_SOURCE");
   }
+
   BuiltinVaListKind getBuiltinVaListKind() const override {
 return TargetInfo::CharPtrBuiltinVaList;
   }

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


[clang] [CIR] Upstream CreateOp for ComplexType with folder (PR #143192)

2025-06-07 Thread Henrich Lauko via cfe-commits


@@ -2226,4 +2226,36 @@ def VecTernaryOp : CIR_Op<"vec.ternary",
   let hasVerifier = 1;
 }
 
+//===--===//
+// ComplexCreateOp
+//===--===//
+
+def ComplexCreateOp : CIR_Op<"complex.create", [Pure, SameTypeOperands]> {
+  let summary = "Create a complex value from its real and imaginary parts";
+  let description = [{
+The `cir.complex.create` operation takes two operands that represent the
+real and imaginary part of a complex number, and yields the complex number.
+
+```mlir
+%0 = cir.const #cir.fp<1.00e+00> : !cir.double
+%1 = cir.const #cir.fp<2.00e+00> : !cir.double
+%2 = cir.complex.create %0, %1 : !cir.complex

xlauko wrote:

this does not match assemblyFormat
```suggestion
%2 = cir.complex.create %0, %1 : !cir.double -> !cir.complex
```

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


[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-06-07 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-aarch64-linux-bootstrap-msan` running on `sanitizer-buildbot10` 
while building `clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build2_msan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build2_msan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build2_msan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build2_msan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build2_msan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build2_msan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build2_msan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/main.py:73:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 84792 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70
FAIL: LLVM :: Other/spirv-sim/wave-get-lane-index.spv (62523 of 84792)
 TEST 'LLVM :: Other/spirv-sim/wave-get-lane-index.spv' 
FAILED 
Exit Code: 139

Command Output (stderr):
--
RUN: at line 1 has no command after substitutions
'/usr/bin/python3' 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/spirv-sim/spirv-sim.py
 --function=simple --wave=4 --expects=0,1,2,3 -i 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/test/Other/spirv-sim/wave-get-lane-index.spv
 # RUN: at line 2
+ /usr/bin/python3 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/spirv-sim/spirv-sim.py
 --function=simple --wave=4 --expects=0,1,2,3 -i 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/test/Other/spirv-sim/wave-get-lane-index.spv
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm_build2_msan/test/Other/spirv-sim/Output/wave-get-lane-index.spv.script:
 line 2: 966784 Segmentation fault  (core dumped) '/usr/bin/python3' 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/utils/spirv-sim/spirv-sim.py
 --function=simple --wave=4 --expects=0,1,2,3 -i 
/home/b/sanitizer-aarch64-linux-bootstrap-msan/build/llvm-project/llvm/test/Other/spirv-sim/wave-get-lane-index.spv

--


Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Slowest Tests:
--
24.27s: Clang :: Driver/fsanitize.c
23.48s: LLVM :: tools/llvm-reduce/parallel-workitem-kill.ll
16.53s: Clang :: Preprocessor/riscv-target-features.c
15.28s: Clang :: Driver/arm-cortex-cpus-2.c
14.93s: Clang :: Driver/arm-cortex-cpus-1.c
14.13s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp
13.41s: Clang :: OpenMP/target_update_codegen.cpp
11.76s: Clang :: Preprocessor/aarch64-target-features.c
11.49s: Clang :: Preprocessor/arm-target-features.c
11.42s: LLVM :: CodeGen/AMDGPU/amdgcn.bitcast.1024bit.ll
10.07s: Clang :: Driver/linux-ld.c
10.01s: LLVM-Unit :: 
Support/./SupportTests/ProgramEnvTest/TestExecuteNoWaitDetached
9.87s: LLVM :: CodeGen/RISCV/attributes.ll
9.75s: Clang :: Preprocessor/predefined-arch-macros.c
9.38s: Clang :: Driver/clang_f_opts.c
9.02s: Clang :: Driver/cl-options.c
8.82s: LLVM :: CodeGen/ARM/build-attributes.ll
8.80s: Clang :: Driver/x86-target-features.c
8.19s: Clang :: Analysis/a_flaky_crash.cpp
7.32s: Clang :: Preprocessor/predefined-macros-no-warnings.c

Tests Times:
Step 14 (stage3/msan check) failure: stage3/msan check (fa

[clang] [clang-format] Add options to control wrapped lambda brace indent. (PR #143249)

2025-06-07 Thread via cfe-commits

https://github.com/rmarker created 
https://github.com/llvm/llvm-project/pull/143249

Adds options to customise how wrapped lambda braces are indented when using 
custom brace wrapping.

`IndentBraces` was recently updated to also indent wrapped lambda braces. This 
has been changed to be controlled separately to allow the old behaviour to be 
maintained. Ideally before a release is made with the new behaviour.

In order to further increase flexibility, the indentation can be controlled 
separately for both nested and unnested lambdas.

Resolves #143248

>From 212f9142a084c4d7bb11423565fb1f0eae93c35f Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Sat, 7 Jun 2025 20:29:18 +0930
Subject: [PATCH] [clang-format] Add options to control wrapped lambda brace
 indent.

Adds options to customise how wrapped lambda braces are indented when
using custom brace wrapping.
IndentBraces was recently changed to also indent wrapped lambda braces.
This has been changed to be controlled separately to allow the old
behaviour to be maintained.
Especially before a release is made with the new behaviour.
In order to further increase flexibility, the indentation can be
controlled separately for both nested and unnested lambdas.
---
 clang/docs/ClangFormatStyleOptions.rst | 34 ++
 clang/docs/ReleaseNotes.rst|  2 +
 clang/include/clang/Format/Format.h| 32 +
 clang/lib/Format/ContinuationIndenter.cpp  | 17 +++--
 clang/lib/Format/Format.cpp| 10 +++
 clang/unittests/Format/ConfigParseTest.cpp |  2 +
 clang/unittests/Format/FormatTest.cpp  | 78 ++
 7 files changed, 170 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 83716cc049ee3..5294c77020945 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2541,6 +2541,40 @@ the configuration (without a prefix: ``Auto``).
 
   * ``bool IndentBraces`` Indent the wrapped braces themselves.
 
+  * ``bool IndentBracesLambdaNested`` Indent nested wrapped lambda braces.
+
+.. code-block:: c++
+
+  false:
+  function(
+  []()
+  {
+return true;
+  });
+
+  true:
+  function(
+  []()
+{
+  return true;
+});
+
+  * ``bool IndentBracesLambdaUnnested`` Indent unnested wrapped lambda braces.
+
+.. code-block:: c++
+
+  false:
+  auto foo = []()
+  {
+return true;
+  };
+
+  true:
+  auto foo = []()
+{
+  return true;
+};
+
   * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put 
on a single line.
 This option is used only if the opening brace of the function has
 already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9ab69320f0368..03e33c4fcdc49 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -988,6 +988,8 @@ clang-format
   ``enum`` enumerator lists.
 - Add ``OneLineFormatOffRegex`` option for turning formatting off for one line.
 - Add ``SpaceAfterOperatorKeyword`` option.
+- Add ``IndentBracesLambdaNested`` and ``IndentBracesLambdaUnnested`` to
+  ``BraceWrapping`` options for controlling wrapped lambda brace indentation.
 
 clang-refactor
 --
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 127b1d08919de..86291d6fa845c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1547,6 +1547,38 @@ struct FormatStyle {
 bool BeforeWhile;
 /// Indent the wrapped braces themselves.
 bool IndentBraces;
+/// Indent nested wrapped lambda braces.
+/// \code
+///   false:
+///   function(
+///   []()
+///   {
+/// return true;
+///   });
+///
+///   true:
+///   function(
+///   []()
+/// {
+///   return true;
+/// });
+/// \endcode
+bool IndentBracesLambdaNested;
+/// Indent unnested wrapped lambda braces.
+/// \code
+///   false:
+///   auto foo = []()
+///   {
+/// return true;
+///   };
+///
+///   true:
+///   auto foo = []()
+/// {
+///   return true;
+/// };
+/// \endcode
+bool IndentBracesLambdaUnnested;
 /// If ``false``, empty function body can be put on a single line.
 /// This option is used only if the opening brace of the function has
 /// already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 4e4e48f90a89f..d37b075da61ae 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1334,12 +1334,15 @@ unsigned C

[clang] [clang-format] Add options to control wrapped lambda brace indent. (PR #143249)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (rmarker)


Changes

Adds options to customise how wrapped lambda braces are indented when using 
custom brace wrapping.

`IndentBraces` was recently updated to also indent wrapped lambda braces. This 
has been changed to be controlled separately to allow the old behaviour to be 
maintained. Ideally before a release is made with the new behaviour.

In order to further increase flexibility, the indentation can be controlled 
separately for both nested and unnested lambdas.

Resolves #143248

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


7 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+34) 
- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Format/Format.h (+32) 
- (modified) clang/lib/Format/ContinuationIndenter.cpp (+12-5) 
- (modified) clang/lib/Format/Format.cpp (+10) 
- (modified) clang/unittests/Format/ConfigParseTest.cpp (+2) 
- (modified) clang/unittests/Format/FormatTest.cpp (+78) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 83716cc049ee3..5294c77020945 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2541,6 +2541,40 @@ the configuration (without a prefix: ``Auto``).
 
   * ``bool IndentBraces`` Indent the wrapped braces themselves.
 
+  * ``bool IndentBracesLambdaNested`` Indent nested wrapped lambda braces.
+
+.. code-block:: c++
+
+  false:
+  function(
+  []()
+  {
+return true;
+  });
+
+  true:
+  function(
+  []()
+{
+  return true;
+});
+
+  * ``bool IndentBracesLambdaUnnested`` Indent unnested wrapped lambda braces.
+
+.. code-block:: c++
+
+  false:
+  auto foo = []()
+  {
+return true;
+  };
+
+  true:
+  auto foo = []()
+{
+  return true;
+};
+
   * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put 
on a single line.
 This option is used only if the opening brace of the function has
 already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9ab69320f0368..03e33c4fcdc49 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -988,6 +988,8 @@ clang-format
   ``enum`` enumerator lists.
 - Add ``OneLineFormatOffRegex`` option for turning formatting off for one line.
 - Add ``SpaceAfterOperatorKeyword`` option.
+- Add ``IndentBracesLambdaNested`` and ``IndentBracesLambdaUnnested`` to
+  ``BraceWrapping`` options for controlling wrapped lambda brace indentation.
 
 clang-refactor
 --
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 127b1d08919de..86291d6fa845c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1547,6 +1547,38 @@ struct FormatStyle {
 bool BeforeWhile;
 /// Indent the wrapped braces themselves.
 bool IndentBraces;
+/// Indent nested wrapped lambda braces.
+/// \code
+///   false:
+///   function(
+///   []()
+///   {
+/// return true;
+///   });
+///
+///   true:
+///   function(
+///   []()
+/// {
+///   return true;
+/// });
+/// \endcode
+bool IndentBracesLambdaNested;
+/// Indent unnested wrapped lambda braces.
+/// \code
+///   false:
+///   auto foo = []()
+///   {
+/// return true;
+///   };
+///
+///   true:
+///   auto foo = []()
+/// {
+///   return true;
+/// };
+/// \endcode
+bool IndentBracesLambdaUnnested;
 /// If ``false``, empty function body can be put on a single line.
 /// This option is used only if the opening brace of the function has
 /// already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 4e4e48f90a89f..d37b075da61ae 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1334,12 +1334,15 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Style.IndentWidth;
   }
 
-  if (Style.BraceWrapping.BeforeLambdaBody &&
-  Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
+  if (Style.BraceWrapping.BeforeLambdaBody && Current.is(TT_LambdaLBrace)) {
+const auto Nested = Current.NestingLevel != 0;
 const auto From = Style.LambdaBodyIndentation == FormatStyle::LBI_Signature
   ? CurrentState.Indent
   : State.FirstIndent;
-return From + Style.IndentWidth;
+const auto Indent =
+(Style.BraceWrappin

[clang] [clang-format] Add options to control wrapped lambda brace indent. (PR #143249)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (rmarker)


Changes

Adds options to customise how wrapped lambda braces are indented when using 
custom brace wrapping.

`IndentBraces` was recently updated to also indent wrapped lambda braces. This 
has been changed to be controlled separately to allow the old behaviour to be 
maintained. Ideally before a release is made with the new behaviour.

In order to further increase flexibility, the indentation can be controlled 
separately for both nested and unnested lambdas.

Resolves #143248

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


7 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+34) 
- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Format/Format.h (+32) 
- (modified) clang/lib/Format/ContinuationIndenter.cpp (+12-5) 
- (modified) clang/lib/Format/Format.cpp (+10) 
- (modified) clang/unittests/Format/ConfigParseTest.cpp (+2) 
- (modified) clang/unittests/Format/FormatTest.cpp (+78) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 83716cc049ee3..5294c77020945 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2541,6 +2541,40 @@ the configuration (without a prefix: ``Auto``).
 
   * ``bool IndentBraces`` Indent the wrapped braces themselves.
 
+  * ``bool IndentBracesLambdaNested`` Indent nested wrapped lambda braces.
+
+.. code-block:: c++
+
+  false:
+  function(
+  []()
+  {
+return true;
+  });
+
+  true:
+  function(
+  []()
+{
+  return true;
+});
+
+  * ``bool IndentBracesLambdaUnnested`` Indent unnested wrapped lambda braces.
+
+.. code-block:: c++
+
+  false:
+  auto foo = []()
+  {
+return true;
+  };
+
+  true:
+  auto foo = []()
+{
+  return true;
+};
+
   * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put 
on a single line.
 This option is used only if the opening brace of the function has
 already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9ab69320f0368..03e33c4fcdc49 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -988,6 +988,8 @@ clang-format
   ``enum`` enumerator lists.
 - Add ``OneLineFormatOffRegex`` option for turning formatting off for one line.
 - Add ``SpaceAfterOperatorKeyword`` option.
+- Add ``IndentBracesLambdaNested`` and ``IndentBracesLambdaUnnested`` to
+  ``BraceWrapping`` options for controlling wrapped lambda brace indentation.
 
 clang-refactor
 --
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 127b1d08919de..86291d6fa845c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1547,6 +1547,38 @@ struct FormatStyle {
 bool BeforeWhile;
 /// Indent the wrapped braces themselves.
 bool IndentBraces;
+/// Indent nested wrapped lambda braces.
+/// \code
+///   false:
+///   function(
+///   []()
+///   {
+/// return true;
+///   });
+///
+///   true:
+///   function(
+///   []()
+/// {
+///   return true;
+/// });
+/// \endcode
+bool IndentBracesLambdaNested;
+/// Indent unnested wrapped lambda braces.
+/// \code
+///   false:
+///   auto foo = []()
+///   {
+/// return true;
+///   };
+///
+///   true:
+///   auto foo = []()
+/// {
+///   return true;
+/// };
+/// \endcode
+bool IndentBracesLambdaUnnested;
 /// If ``false``, empty function body can be put on a single line.
 /// This option is used only if the opening brace of the function has
 /// already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 4e4e48f90a89f..d37b075da61ae 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1334,12 +1334,15 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Style.IndentWidth;
   }
 
-  if (Style.BraceWrapping.BeforeLambdaBody &&
-  Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
+  if (Style.BraceWrapping.BeforeLambdaBody && Current.is(TT_LambdaLBrace)) {
+const auto Nested = Current.NestingLevel != 0;
 const auto From = Style.LambdaBodyIndentation == FormatStyle::LBI_Signature
   ? CurrentState.Indent
   : State.FirstIndent;
-return From + Style.IndentWidth;
+const auto Indent =
+(Style.Brace

[clang] [Clang][Parse][NFC] Use `llvm::function_ref<>` instead of `std::optional>` (PR #142906)

2025-06-07 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

Yes. I still don't have commit access. Thank you!

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


[clang] [CIR] Upstream CreateOp for ComplexType with folder (PR #143192)

2025-06-07 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/143192

>From 0ee92db03198e2364ade53e5c0bbd0f844fe634f Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Fri, 6 Jun 2025 20:56:49 +0200
Subject: [PATCH 1/3] [CIR] Upstream CreateOp for ComplexType with folder

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 32 
 .../include/clang/CIR/Dialect/IR/CIRTypes.td  |  3 +-
 clang/include/clang/CIR/MissingFeatures.h |  1 -
 clang/lib/CIR/CodeGen/CIRGenBuilder.h |  6 ++
 clang/lib/CIR/CodeGen/CIRGenDecl.cpp  | 12 ++-
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  | 11 +++
 clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp   | 81 +++
 clang/lib/CIR/CodeGen/CIRGenFunction.h|  9 +++
 clang/lib/CIR/CodeGen/CMakeLists.txt  |  1 +
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   | 28 +++
 .../Dialect/Transforms/CIRCanonicalize.cpp|  3 +-
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 48 ++-
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.h   | 10 +++
 clang/test/CIR/CodeGen/complex.cpp| 56 +
 .../CIR/Transforms/complex-create-fold.cir| 30 +++
 15 files changed, 322 insertions(+), 9 deletions(-)
 create mode 100644 clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
 create mode 100644 clang/test/CIR/Transforms/complex-create-fold.cir

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index bd847731193ab..5f72545ea020d 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2226,4 +2226,36 @@ def VecTernaryOp : CIR_Op<"vec.ternary",
   let hasVerifier = 1;
 }
 
+//===--===//
+// ComplexCreateOp
+//===--===//
+
+def ComplexCreateOp : CIR_Op<"complex.create", [Pure, SameTypeOperands]> {
+  let summary = "Create a complex value from its real and imaginary parts";
+  let description = [{
+The `cir.complex.create` operation takes two operands that represent the
+real and imaginary part of a complex number, and yields the complex number.
+
+```mlir
+%0 = cir.const #cir.fp<1.00e+00> : !cir.double
+%1 = cir.const #cir.fp<2.00e+00> : !cir.double
+%2 = cir.complex.create %0, %1 : !cir.complex
+```
+  }];
+
+  let results = (outs CIR_ComplexType:$result);
+  let arguments = (ins
+CIR_AnyIntOrFloatType:$real,
+CIR_AnyIntOrFloatType:$imag
+  );
+
+  let assemblyFormat = [{
+$real `,` $imag
+`:` qualified(type($real)) `->` qualified(type($result)) attr-dict
+  }];
+
+  let hasVerifier = 1;
+  let hasFolder = 1;
+}
+
 #endif // CLANG_CIR_DIALECT_IR_CIROPS_TD
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index fb96976075130..41d7d725a09e0 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -600,7 +600,8 @@ def CIRRecordType : Type<
 
 def CIR_AnyType : AnyTypeOf<[
   CIR_VoidType, CIR_BoolType, CIR_ArrayType, CIR_VectorType, CIR_IntType,
-  CIR_AnyFloatType, CIR_PointerType, CIR_FuncType, CIR_RecordType
+  CIR_AnyFloatType, CIR_PointerType, CIR_FuncType, CIR_RecordType,
+  CIR_ComplexType
 ]>;
 
 #endif // MLIR_CIR_DIALECT_CIR_TYPES
diff --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index f1e0c15d41f64..473e4dc7a81a4 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -233,7 +233,6 @@ struct MissingFeatures {
   // Future CIR operations
   static bool awaitOp() { return false; }
   static bool callOp() { return false; }
-  static bool complexCreateOp() { return false; }
   static bool complexImagOp() { return false; }
   static bool complexRealOp() { return false; }
   static bool ifOp() { return false; }
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index 5f33ae1af35ee..308b51be6c30b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -323,6 +323,12 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
 return CIRBaseBuilderTy::createStore(loc, val, dst.getPointer(), align);
   }
 
+  mlir::Value createComplexCreate(mlir::Location loc, mlir::Value real,
+  mlir::Value imag) {
+auto resultComplexTy = cir::ComplexType::get(real.getType());
+return create(loc, resultComplexTy, real, imag);
+  }
+
   /// Create a cir.ptr_stride operation to get access to an array element.
   /// \p idx is the index of the element to access, \p shouldDecay is true if
   /// the result should decay to a pointer to the element type.
diff --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp 
b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
index 80b0172090aa3..3e2c96c5aaeaf 100644
--- a/clang/li

[clang] bf51d58 - [CIR] Upstream ShuffleOp for VectorType (#142288)

2025-06-07 Thread via cfe-commits

Author: Amr Hesham
Date: 2025-06-07T13:56:36+02:00
New Revision: bf51d583e44de6c01617740caff154d0c56309d6

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

LOG: [CIR] Upstream ShuffleOp for VectorType (#142288)

This change adds support for the Shuffle op for VectorType

Issue https://github.com/llvm/llvm-project/issues/136487

Added: 


Modified: 
clang/include/clang/CIR/Dialect/IR/CIRAttrConstraints.td
clang/include/clang/CIR/Dialect/IR/CIROps.td
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
clang/lib/CIR/Dialect/IR/CIRDialect.cpp
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h
clang/test/CIR/CodeGen/vector-ext.cpp
clang/test/CIR/CodeGen/vector.cpp
clang/test/CIR/IR/invalid-vector.cir

Removed: 




diff  --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrConstraints.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrConstraints.td
index 382117938b2fe..a8c81dbd71a09 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrConstraints.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrConstraints.td
@@ -1,4 +1,3 @@
-
 
//===--===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
@@ -39,4 +38,11 @@ def CIR_AnyIntOrFloatAttr : AnyAttrOf<[CIR_AnyIntAttr, 
CIR_AnyFPAttr],
   string cppType = "::mlir::TypedAttr";
 }
 
-#endif // CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD
+//===--===//
+// ArrayAttr constraints
+//===--===//
+
+def CIR_IntArrayAttr : TypedArrayAttrBase;
+
+#endif // CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD
\ No newline at end of file

diff  --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index bd847731193ab..8b584e81b8a2b 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -17,6 +17,7 @@
 include "clang/CIR/Dialect/IR/CIRDialect.td"
 include "clang/CIR/Dialect/IR/CIRTypes.td"
 include "clang/CIR/Dialect/IR/CIRAttrs.td"
+include "clang/CIR/Dialect/IR/CIRAttrConstraints.td"
 
 include "clang/CIR/Interfaces/CIROpInterfaces.td"
 include "clang/CIR/Interfaces/CIRLoopOpInterface.td"
@@ -2155,6 +2156,52 @@ def VecCmpOp : CIR_Op<"vec.cmp", [Pure, 
SameTypeOperands]> {
   }];
 }
 
+//===--===//
+// VecShuffleOp
+//===--===//
+
+// TODO: Create an interface that both VecShuffleOp and VecShuffleDynamicOp
+// implement.  This could be useful for passes that don't care how the vector
+// shuffle was specified.
+
+def VecShuffleOp : CIR_Op<"vec.shuffle",
+   [Pure, AllTypesMatch<["vec1", "vec2"]>]> {
+  let summary = "Combine two vectors using indices passed as constant 
integers";
+  let description = [{
+The `cir.vec.shuffle` operation implements the documented form of Clang's
+`__builtin_shufflevector`, where the indices of the shuffled result are
+integer constants.
+
+The two input vectors, which must have the same type, are concatenated.
+Each of the integer constant arguments is interpreted as an index into that
+concatenated vector, with a value of -1 meaning that the result value
+doesn't matter. The result vector, which must have the same element type as
+the input vectors and the same number of elements as the list of integer
+constant indices, is constructed by taking the elements at the given
+indices from the concatenated vector. The size of the result vector does
+not have to match the size of the individual input vectors or of the
+concatenated vector.
+
+```mlir
+%new_vec = cir.vec.shuffle(%vec_1, %vec_2 : !cir.vector<2 x !s32i>)
+[#cir.int<3> : !s64i, #cir.int<1> : !s64i] : !cir.vector<2 x !s32i>
+```
+  }];
+
+  let arguments = (ins
+CIR_VectorType:$vec1,
+CIR_VectorType:$vec2,
+CIR_IntArrayAttr:$indices
+  );
+
+  let results = (outs CIR_VectorType:$result);
+  let assemblyFormat = [{
+`(` $vec1 `,` $vec2 `:` qualified(type($vec1)) `)` $indices `:`
+ qualified(type($result)) attr-dict
+  }];
+  let hasVerifier = 1;
+}
+
 
//===--===//
 // VecShuffleDynamicOp
 
//===--===//

diff  --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index a7899fccc47fb..899622d5df74d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

[clang] [CIR] Upstream ShuffleOp for VectorType (PR #142288)

2025-06-07 Thread Amr Hesham via cfe-commits

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


[clang] 995d74f - [CIR] Implement folder for VecTernaryOp (#142946)

2025-06-07 Thread via cfe-commits

Author: Amr Hesham
Date: 2025-06-07T13:58:54+02:00
New Revision: 995d74f8663edb2e20f2d2672556582a6f4cc3f1

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

LOG: [CIR] Implement folder for VecTernaryOp (#142946)

This change adds a folder for the VecTernaryOp

Issue https://github.com/llvm/llvm-project/issues/136487

Added: 
clang/test/CIR/Transforms/vector-ternary-fold.cir

Modified: 
clang/include/clang/CIR/Dialect/IR/CIROps.td
clang/lib/CIR/Dialect/IR/CIRDialect.cpp
clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp

Removed: 




diff  --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 8b584e81b8a2b..038a59b8ff4eb 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2270,7 +2270,9 @@ def VecTernaryOp : CIR_Op<"vec.ternary",
 `(` $cond `,` $lhs`,` $rhs `)` `:` qualified(type($cond)) `,`
 qualified(type($lhs)) attr-dict
   }];
+
   let hasVerifier = 1;
+  let hasFolder = 1;
 }
 
 #endif // CLANG_CIR_DIALECT_IR_CIROPS_TD

diff  --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 7f09830576181..bfd3a0a62a8e7 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1664,6 +1664,38 @@ LogicalResult cir::VecTernaryOp::verify() {
   return success();
 }
 
+OpFoldResult cir::VecTernaryOp::fold(FoldAdaptor adaptor) {
+  mlir::Attribute cond = adaptor.getCond();
+  mlir::Attribute lhs = adaptor.getLhs();
+  mlir::Attribute rhs = adaptor.getRhs();
+
+  if (!mlir::isa_and_nonnull(cond) ||
+  !mlir::isa_and_nonnull(lhs) ||
+  !mlir::isa_and_nonnull(rhs))
+return {};
+  auto condVec = mlir::cast(cond);
+  auto lhsVec = mlir::cast(lhs);
+  auto rhsVec = mlir::cast(rhs);
+
+  mlir::ArrayAttr condElts = condVec.getElts();
+
+  SmallVector elements;
+  elements.reserve(condElts.size());
+
+  for (const auto &[idx, condAttr] :
+   llvm::enumerate(condElts.getAsRange())) {
+if (condAttr.getSInt()) {
+  elements.push_back(lhsVec.getElts()[idx]);
+} else {
+  elements.push_back(rhsVec.getElts()[idx]);
+}
+  }
+
+  cir::VectorType vecTy = getLhs().getType();
+  return cir::ConstVectorAttr::get(
+  vecTy, mlir::ArrayAttr::get(getContext(), elements));
+}
+
 
//===--===//
 // TableGen'd op method definitions
 
//===--===//

diff  --git a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp 
b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
index 7d03e374c27e8..33881c69eec5f 100644
--- a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
@@ -138,10 +138,11 @@ void CIRCanonicalizePass::runOnOperation() {
 assert(!cir::MissingFeatures::complexRealOp());
 assert(!cir::MissingFeatures::complexImagOp());
 assert(!cir::MissingFeatures::callOp());
-// CastOp, UnaryOp, VecExtractOp and VecShuffleDynamicOp are here to 
perform
-// a manual `fold` in applyOpPatternsGreedily.
+
+// Many operations are here to perform a manual `fold` in
+// applyOpPatternsGreedily.
 if (isa(op))
+VecExtractOp, VecShuffleDynamicOp, VecTernaryOp>(op))
   ops.push_back(op);
   });
 

diff  --git a/clang/test/CIR/Transforms/vector-ternary-fold.cir 
b/clang/test/CIR/Transforms/vector-ternary-fold.cir
new file mode 100644
index 0..f2e18576da74b
--- /dev/null
+++ b/clang/test/CIR/Transforms/vector-ternary-fold.cir
@@ -0,0 +1,20 @@
+// RUN: cir-opt %s -cir-canonicalize -o - | FileCheck %s
+
+!s32i = !cir.int
+
+module {
+  cir.func @vector_ternary_fold_test() -> !cir.vector<4 x !s32i> {
+%cond = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<0> : 
!s32i, #cir.int<1> : !s32i, #cir.int<0> : !s32i]> : !cir.vector<4 x !s32i>
+%lhs = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<2> : 
!s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i]> : !cir.vector<4 x !s32i>
+%rhs = cir.const #cir.const_vector<[#cir.int<5> : !s32i, #cir.int<6> : 
!s32i, #cir.int<7> : !s32i, #cir.int<8> : !s32i]> : !cir.vector<4 x !s32i>
+%res = cir.vec.ternary(%cond, %lhs, %rhs) : !cir.vector<4 x !s32i>, 
!cir.vector<4 x !s32i>
+cir.return %res : !cir.vector<4 x !s32i>
+  }
+
+  // [1, 0, 1, 0] ? [1, 2, 3, 4] : [5, 6, 7, 8] Will be fold to [1, 6, 3, 8]
+  // CHECK: cir.func @vector_ternary_fold_test() -> !cir.vector<4 x !s32i> {
+  // CHECK-NEXT: %[[RES:.*]] = cir.const #cir.const_vector<[#cir.int<1> : 
!s32i, #cir.int<6> : !s32i, #cir.int<3> : !s32i, #cir.int<8> : !s32i]> : 
!cir.vector<4 x !s32i>
+  // CHECK-NEXT

[clang] [CIR] Implement folder for VecTernaryOp (PR #142946)

2025-06-07 Thread Amr Hesham via cfe-commits

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in Stmt (PR #143250)

2025-06-07 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul created 
https://github.com/llvm/llvm-project/pull/143250

None

>From 2aa08553460c49ab6ac1ea572d637ce0c1286d44 Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Sat, 7 Jun 2025 04:21:23 -0700
Subject: [PATCH] [NFC][Clang] Adopt simplified `getTrailingObjects` in Stmt

---
 clang/include/clang/AST/Stmt.h | 111 +
 clang/lib/AST/Stmt.cpp |   8 +--
 2 files changed, 47 insertions(+), 72 deletions(-)

diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 48a6aea4f4b6a..6c4bd6f6946ba 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1953,10 +1953,6 @@ class CaseStmt final
 return NumMandatoryStmtPtr + caseStmtIsGNURange();
   }
 
-  unsigned numTrailingObjects(OverloadToken) const {
-return caseStmtIsGNURange();
-  }
-
   unsigned lhsOffset() const { return LhsOffset; }
   unsigned rhsOffset() const { return LhsOffset + caseStmtIsGNURange(); }
   unsigned subStmtOffset() const { return rhsOffset() + SubStmtOffsetFromRhs; }
@@ -2228,10 +2224,8 @@ class AttributedStmt final
 std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr);
   }
 
-  const Attr *const *getAttrArrayPtr() const {
-return getTrailingObjects();
-  }
-  const Attr **getAttrArrayPtr() { return getTrailingObjects(); }
+  const Attr *const *getAttrArrayPtr() const { return getTrailingObjects(); }
+  const Attr **getAttrArrayPtr() { return getTrailingObjects(); }
 
 public:
   static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
@@ -2543,7 +2537,7 @@ class SwitchStmt final : public Stmt,
   SourceLocation LParenLoc;
   SourceLocation RParenLoc;
 
-  unsigned numTrailingObjects(OverloadToken) const {
+  unsigned numTrailingStatements() const {
 return NumMandatoryStmtPtr + hasInitStorage() + hasVarStorage();
   }
 
@@ -2579,40 +2573,34 @@ class SwitchStmt final : public Stmt,
   bool hasVarStorage() const { return SwitchStmtBits.HasVar; }
 
   Expr *getCond() {
-return reinterpret_cast(getTrailingObjects()[condOffset()]);
+return reinterpret_cast(getTrailingObjects()[condOffset()]);
   }
 
   const Expr *getCond() const {
-return reinterpret_cast(getTrailingObjects()[condOffset()]);
+return reinterpret_cast(getTrailingObjects()[condOffset()]);
   }
 
   void setCond(Expr *Cond) {
-getTrailingObjects()[condOffset()] = reinterpret_cast(Cond);
+getTrailingObjects()[condOffset()] = reinterpret_cast(Cond);
   }
 
-  Stmt *getBody() { return getTrailingObjects()[bodyOffset()]; }
-  const Stmt *getBody() const {
-return getTrailingObjects()[bodyOffset()];
-  }
+  Stmt *getBody() { return getTrailingObjects()[bodyOffset()]; }
+  const Stmt *getBody() const { return getTrailingObjects()[bodyOffset()]; }
 
-  void setBody(Stmt *Body) {
-getTrailingObjects()[bodyOffset()] = Body;
-  }
+  void setBody(Stmt *Body) { getTrailingObjects()[bodyOffset()] = Body; }
 
   Stmt *getInit() {
-return hasInitStorage() ? getTrailingObjects()[initOffset()]
-: nullptr;
+return hasInitStorage() ? getTrailingObjects()[initOffset()] : nullptr;
   }
 
   const Stmt *getInit() const {
-return hasInitStorage() ? getTrailingObjects()[initOffset()]
-: nullptr;
+return hasInitStorage() ? getTrailingObjects()[initOffset()] : nullptr;
   }
 
   void setInit(Stmt *Init) {
 assert(hasInitStorage() &&
"This switch statement has no storage for an init statement!");
-getTrailingObjects()[initOffset()] = Init;
+getTrailingObjects()[initOffset()] = Init;
   }
 
   /// Retrieve the variable declared in this "switch" statement, if any.
@@ -2636,20 +2624,20 @@ class SwitchStmt final : public Stmt,
   /// If this SwitchStmt has a condition variable, return the faux DeclStmt
   /// associated with the creation of that condition variable.
   DeclStmt *getConditionVariableDeclStmt() {
-return hasVarStorage() ? static_cast(
- getTrailingObjects()[varOffset()])
-   : nullptr;
+return hasVarStorage()
+   ? static_cast(getTrailingObjects()[varOffset()])
+   : nullptr;
   }
 
   const DeclStmt *getConditionVariableDeclStmt() const {
-return hasVarStorage() ? static_cast(
- getTrailingObjects()[varOffset()])
-   : nullptr;
+return hasVarStorage()
+   ? static_cast(getTrailingObjects()[varOffset()])
+   : nullptr;
   }
 
   void setConditionVariableDeclStmt(DeclStmt *CondVar) {
 assert(hasVarStorage());
-getTrailingObjects()[varOffset()] = CondVar;
+getTrailingObjects()[varOffset()] = CondVar;
   }
 
   SwitchCase *getSwitchCaseList() { return FirstCase; }
@@ -2693,15 +2681,13 @@ class SwitchStmt final : public Stmt,
 
   // Iterators
   child_range children() {
-return child_range(getTrailingObjects(),
-   getTr

[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in StmtCXX (PR #143251)

2025-06-07 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul created 
https://github.com/llvm/llvm-project/pull/143251

None

>From 9449af262b9116249d1626ad802abefa85f6faf7 Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Sat, 7 Jun 2025 04:23:38 -0700
Subject: [PATCH] [NFC][Clang] Adopt simplified `getTrailingObjects` in StmtCXX

---
 clang/include/clang/AST/StmtCXX.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/StmtCXX.h 
b/clang/include/clang/AST/StmtCXX.h
index a15a445fbea40..5d68d3ef64a20 100644
--- a/clang/include/clang/AST/StmtCXX.h
+++ b/clang/include/clang/AST/StmtCXX.h
@@ -80,8 +80,8 @@ class CXXTryStmt final : public Stmt,
   CXXTryStmt(EmptyShell Empty, unsigned numHandlers)
 : Stmt(CXXTryStmtClass), NumHandlers(numHandlers) { }
 
-  Stmt *const *getStmts() const { return getTrailingObjects(); }
-  Stmt **getStmts() { return getTrailingObjects(); }
+  Stmt *const *getStmts() const { return getTrailingObjects(); }
+  Stmt **getStmts() { return getTrailingObjects(); }
 
 public:
   static CXXTryStmt *Create(const ASTContext &C, SourceLocation tryLoc,
@@ -339,9 +339,9 @@ class CoroutineBodyStmt final
   friend class ASTReader;
   friend TrailingObjects;
 
-  Stmt **getStoredStmts() { return getTrailingObjects(); }
+  Stmt **getStoredStmts() { return getTrailingObjects(); }
 
-  Stmt *const *getStoredStmts() const { return getTrailingObjects(); }
+  Stmt *const *getStoredStmts() const { return getTrailingObjects(); }
 
 public:
 

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in ExprConcepts (PR #143252)

2025-06-07 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul created 
https://github.com/llvm/llvm-project/pull/143252

None

>From d9a1f7f86516f2727839bf290f8de72eca260dcd Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Fri, 6 Jun 2025 20:49:18 -0700
Subject: [PATCH] [NFC][Clang] Adopt simplified `getTrailingObjects` in
 ExprConcepts

---
 clang/include/clang/AST/ExprConcepts.h | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/AST/ExprConcepts.h 
b/clang/include/clang/AST/ExprConcepts.h
index f988d40cf73c3..8df5cdcaa9d75 100644
--- a/clang/include/clang/AST/ExprConcepts.h
+++ b/clang/include/clang/AST/ExprConcepts.h
@@ -514,10 +514,6 @@ class RequiresExpr final : public Expr,
 return NumLocalParameters;
   }
 
-  unsigned numTrailingObjects(OverloadToken) const {
-return NumRequirements;
-  }
-
   RequiresExpr(ASTContext &C, SourceLocation RequiresKWLoc,
RequiresExprBodyDecl *Body, SourceLocation LParenLoc,
ArrayRef LocalParameters,
@@ -540,13 +536,13 @@ class RequiresExpr final : public Expr,
  unsigned NumRequirements);
 
   ArrayRef getLocalParameters() const {
-return {getTrailingObjects(), NumLocalParameters};
+return getTrailingObjects(NumLocalParameters);
   }
 
   RequiresExprBodyDecl *getBody() const { return Body; }
 
   ArrayRef getRequirements() const {
-return {getTrailingObjects(), NumRequirements};
+return getTrailingObjects(NumRequirements);
   }
 
   /// \brief Whether or not the requires clause is satisfied.

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


[clang] [NFC][Clang][CIR] Adopt simpified `getTrailingObjects` in CIRGenFunct… (PR #143253)

2025-06-07 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul created 
https://github.com/llvm/llvm-project/pull/143253

…ionInfo

>From 302e09ec58534feb3f7aac0ce0d6edbfb69412dd Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Sat, 7 Jun 2025 04:57:31 -0700
Subject: [PATCH] [NFC][Clang][CIR] Adopt simpified `getTrailingObjects` in
 CIRGenFunctionInfo

---
 clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h 
b/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
index 9886574fd463b..4f5754cb43986 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
@@ -76,10 +76,8 @@ class CIRGenFunctionInfo final
 
   unsigned numArgs;
 
-  CanQualType *getArgTypes() { return getTrailingObjects(); }
-  const CanQualType *getArgTypes() const {
-return getTrailingObjects();
-  }
+  CanQualType *getArgTypes() { return getTrailingObjects(); }
+  const CanQualType *getArgTypes() const { return getTrailingObjects(); }
 
   CIRGenFunctionInfo() : required(RequiredArgs::All) {}
 

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


[clang] [NFC][Clang] Adopt simpified `getTrailingObjects` in CIRGenFunctionInfo (PR #143253)

2025-06-07 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in ExprObjC (PR #143254)

2025-06-07 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul created 
https://github.com/llvm/llvm-project/pull/143254

None

>From 8417ea58f74422823dd1863ccaefb7f8c538ab79 Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Sat, 7 Jun 2025 04:03:13 -0700
Subject: [PATCH] [NFC][Clang] Adopt simplified `getTrailingObjects` in
 ExprObjC

---
 clang/include/clang/AST/ExprObjC.h | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/ExprObjC.h 
b/clang/include/clang/AST/ExprObjC.h
index f87fa85569c44..3d9b3c4585e8a 100644
--- a/clang/include/clang/AST/ExprObjC.h
+++ b/clang/include/clang/AST/ExprObjC.h
@@ -217,12 +217,10 @@ class ObjCArrayLiteral final
   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
 
   /// Retrieve elements of array of literals.
-  Expr **getElements() { return getTrailingObjects(); }
+  Expr **getElements() { return getTrailingObjects(); }
 
   /// Retrieve elements of array of literals.
-  const Expr * const *getElements() const {
-return getTrailingObjects();
-  }
+  const Expr *const *getElements() const { return getTrailingObjects(); }
 
   /// getNumElements - Return number of elements of objective-c array literal.
   unsigned getNumElements() const { return NumElements; }

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in ParsedTemplate (PR #143255)

2025-06-07 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul created 
https://github.com/llvm/llvm-project/pull/143255

None

>From 849a5bbe098f77cc7dd6336fa40d78a1d16bd6e8 Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Sat, 7 Jun 2025 04:54:29 -0700
Subject: [PATCH] [NFC][Clang] Adopt simplified `getTrailingObjects` in
 ParsedTemplate

---
 clang/include/clang/Sema/ParsedAttr.h | 3 ---
 clang/include/clang/Sema/ParsedTemplate.h | 4 +---
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/clang/include/clang/Sema/ParsedAttr.h 
b/clang/include/clang/Sema/ParsedAttr.h
index 428d3111de80d..9e050ab9a620e 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -130,9 +130,6 @@ class ParsedAttr final
   size_t numTrailingObjects(OverloadToken) const {
 return HasParsedType;
   }
-  size_t numTrailingObjects(OverloadToken) const {
-return IsProperty;
-  }
 
 private:
   IdentifierInfo *MacroII = nullptr;
diff --git a/clang/include/clang/Sema/ParsedTemplate.h 
b/clang/include/clang/Sema/ParsedTemplate.h
index cff7f04666358..3a8050f9a0a3d 100644
--- a/clang/include/clang/Sema/ParsedTemplate.h
+++ b/clang/include/clang/Sema/ParsedTemplate.h
@@ -190,9 +190,7 @@ namespace clang {
 bool ArgsInvalid;
 
 /// Retrieves a pointer to the template arguments
-ParsedTemplateArgument *getTemplateArgs() {
-  return getTrailingObjects();
-}
+ParsedTemplateArgument *getTemplateArgs() { return getTrailingObjects(); }
 
 /// Creates a new TemplateIdAnnotation with NumArgs arguments and
 /// appends it to List.

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in StmtObjC (PR #143256)

2025-06-07 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul created 
https://github.com/llvm/llvm-project/pull/143256

None

>From 5b5740335314911c2be2560cd8176d0ea2fbe6e8 Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Sat, 7 Jun 2025 04:27:17 -0700
Subject: [PATCH] [NFC][Clang] Adopt simplified `getTrailingObjects` in
 StmtObjC

---
 clang/include/clang/AST/StmtObjC.h | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/AST/StmtObjC.h 
b/clang/include/clang/AST/StmtObjC.h
index 03bc61f54cdf5..af95d65fa2a3c 100644
--- a/clang/include/clang/AST/StmtObjC.h
+++ b/clang/include/clang/AST/StmtObjC.h
@@ -166,7 +166,8 @@ class ObjCAtTryStmt final
 : public Stmt,
   private llvm::TrailingObjects {
   friend TrailingObjects;
-  size_t numTrailingObjects(OverloadToken) const {
+
+  size_t numTrailingStatements() const {
 return 1 + NumCatchStmts + HasFinally;
   }
 
@@ -185,8 +186,8 @@ class ObjCAtTryStmt final
   /// The order of the statements in memory follows the order in the source,
   /// with the \@try body first, followed by the \@catch statements (if any)
   /// and, finally, the \@finally (if it exists).
-  Stmt **getStmts() { return getTrailingObjects(); }
-  Stmt *const *getStmts() const { return getTrailingObjects(); }
+  Stmt **getStmts() { return getTrailingObjects(); }
+  Stmt *const *getStmts() const { return getTrailingObjects(); }
 
   ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
 Stmt **CatchStmts, unsigned NumCatchStmts,
@@ -262,8 +263,7 @@ class ObjCAtTryStmt final
   }
 
   child_range children() {
-return child_range(
-getStmts(), getStmts() + numTrailingObjects(OverloadToken()));
+return child_range(getStmts(), getStmts() + numTrailingStatements());
   }
 
   const_child_range children() const {

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in TemplateBase (PR #143257)

2025-06-07 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul created 
https://github.com/llvm/llvm-project/pull/143257

None

>From 63bfd66cce5aeeea0bc6810a59deff3a7cac12da Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Sat, 7 Jun 2025 04:35:32 -0700
Subject: [PATCH] [NFC][Clang] Adopt simplified `getTrailingObjects` in
 TemplateBase

---
 clang/include/clang/AST/TemplateBase.h | 2 +-
 clang/lib/AST/TemplateBase.cpp | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/TemplateBase.h 
b/clang/include/clang/AST/TemplateBase.h
index 279feb858e665..84a342ec053a1 100644
--- a/clang/include/clang/AST/TemplateBase.h
+++ b/clang/include/clang/AST/TemplateBase.h
@@ -704,7 +704,7 @@ struct ASTTemplateArgumentListInfo final
 
   /// Retrieve the template arguments
   const TemplateArgumentLoc *getTemplateArgs() const {
-return getTrailingObjects();
+return getTrailingObjects();
   }
   unsigned getNumTemplateArgs() const { return NumTemplateArgs; }
 
diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 8ecd3c7aaca0d..7c89dea4629cc 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -726,7 +726,7 @@ ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
   RAngleLoc = Info.getRAngleLoc();
   NumTemplateArgs = Info.size();
 
-  TemplateArgumentLoc *ArgBuffer = getTrailingObjects();
+  TemplateArgumentLoc *ArgBuffer = getTrailingObjects();
   for (unsigned i = 0; i != NumTemplateArgs; ++i)
 new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]);
 }
@@ -737,7 +737,7 @@ ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
   RAngleLoc = Info->getRAngleLoc();
   NumTemplateArgs = Info->getNumTemplateArgs();
 
-  TemplateArgumentLoc *ArgBuffer = getTrailingObjects();
+  TemplateArgumentLoc *ArgBuffer = getTrailingObjects();
   for (unsigned i = 0; i != NumTemplateArgs; ++i)
 new (&ArgBuffer[i]) TemplateArgumentLoc((*Info)[i]);
 }

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


[clang] [clang-format][NFC] Clean up fillRanges() in ClangFormat.cpp (PR #143236)

2025-06-07 Thread Björn Schäpers via cfe-commits


@@ -284,27 +284,23 @@ static bool fillRanges(MemoryBuffer *Code,
 errs() << "error: number of -offset and -length arguments must match.\n";
 return true;
   }
-  for (unsigned i = 0, e = Offsets.size(); i != e; ++i) {
-if (Offsets[i] >= Code->getBufferSize()) {
-  errs() << "error: offset " << Offsets[i] << " is outside the file\n";
+  for (unsigned I = 0, E = Offsets.size(), Size = Lengths.size(); I < E; ++I) {
+const auto Offset = Offsets[I];
+if (Offset >= Code->getBufferSize()) {
+  errs() << "error: offset " << Offset << " is outside the file\n";
   return true;
 }
-SourceLocation Start =
-Sources.getLocForStartOfFile(ID).getLocWithOffset(Offsets[i]);
-SourceLocation End;
-if (i < Lengths.size()) {
-  if (Offsets[i] + Lengths[i] > Code->getBufferSize()) {
-errs() << "error: invalid length " << Lengths[i]
-   << ", offset + length (" << Offsets[i] + Lengths[i]
-   << ") is outside the file.\n";
+unsigned Length;
+if (I < Size) {
+  Length = Lengths[I];
+  if (Offset + Length > Code->getBufferSize()) {
+errs() << "error: invalid length " << Length << ", offset + length ("
+   << Offset + Length << ") is outside the file.\n";
 return true;
   }
-  End = Start.getLocWithOffset(Lengths[i]);
 } else {
-  End = Sources.getLocForEndOfFile(ID);
+  Length = Sources.getFileOffset(Sources.getLocForEndOfFile(ID)) - Offset;
 }
-unsigned Offset = Sources.getFileOffset(Start);

HazardyKnusperkeks wrote:

So basically `Start` was computed based on `Offset[i]` and then recalculated to 
`Offset` which has the same value? Or are there corner cases, where this yields 
a different value?

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


[clang] [clang-format][NFC] Clean up fillRanges() in ClangFormat.cpp (PR #143236)

2025-06-07 Thread Björn Schäpers via cfe-commits


@@ -284,27 +284,23 @@ static bool fillRanges(MemoryBuffer *Code,
 errs() << "error: number of -offset and -length arguments must match.\n";

HazardyKnusperkeks wrote:

Is it maybe worth handling the `Offsets.empty() && Lengths.empty()` case by its 
own, and then dropping the `if (I < Size)`?

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


[clang] [clang-format] Add options to control wrapped lambda brace indent. (PR #143249)

2025-06-07 Thread Björn Schäpers via cfe-commits


@@ -1334,12 +1334,15 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Style.IndentWidth;
   }
 
-  if (Style.BraceWrapping.BeforeLambdaBody &&
-  Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
+  if (Style.BraceWrapping.BeforeLambdaBody && Current.is(TT_LambdaLBrace)) {
+const auto Nested = Current.NestingLevel != 0;

HazardyKnusperkeks wrote:

```suggestion
const auto Nested = Current.NestingLevel > 0;
```
Should be the same, but can't let people wonder if `NestingLevel` can be 
negative.

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


[clang] [clang-format] Add options to control wrapped lambda brace indent. (PR #143249)

2025-06-07 Thread Björn Schäpers via cfe-commits


@@ -1334,12 +1334,15 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Style.IndentWidth;
   }
 
-  if (Style.BraceWrapping.BeforeLambdaBody &&
-  Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
+  if (Style.BraceWrapping.BeforeLambdaBody && Current.is(TT_LambdaLBrace)) {
+const auto Nested = Current.NestingLevel != 0;
 const auto From = Style.LambdaBodyIndentation == FormatStyle::LBI_Signature
   ? CurrentState.Indent
   : State.FirstIndent;
-return From + Style.IndentWidth;
+const auto Indent =
+(Style.BraceWrapping.IndentBracesLambdaNested && Nested) ||
+(Style.BraceWrapping.IndentBracesLambdaUnnested && !Nested);
+return From + (Indent * Style.IndentWidth);

HazardyKnusperkeks wrote:

Before it didn't return if `IndentBraces` was `false`. Should we keep that 
behavior?

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


[clang] [clang-format] Add options to control wrapped lambda brace indent. (PR #143249)

2025-06-07 Thread Björn Schäpers via cfe-commits


@@ -1547,6 +1547,38 @@ struct FormatStyle {
 bool BeforeWhile;
 /// Indent the wrapped braces themselves.
 bool IndentBraces;
+/// Indent nested wrapped lambda braces.

HazardyKnusperkeks wrote:

I think a better name is in order, when reading nested lambda, I thought of a 
lambda within a lambda.

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


[clang] [clang-format] Add options to control wrapped lambda brace indent. (PR #143249)

2025-06-07 Thread Björn Schäpers via cfe-commits


@@ -1334,12 +1334,15 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Style.IndentWidth;
   }
 
-  if (Style.BraceWrapping.BeforeLambdaBody &&
-  Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
+  if (Style.BraceWrapping.BeforeLambdaBody && Current.is(TT_LambdaLBrace)) {
+const auto Nested = Current.NestingLevel != 0;
 const auto From = Style.LambdaBodyIndentation == FormatStyle::LBI_Signature
   ? CurrentState.Indent
   : State.FirstIndent;
-return From + Style.IndentWidth;
+const auto Indent =
+(Style.BraceWrapping.IndentBracesLambdaNested && Nested) ||
+(Style.BraceWrapping.IndentBracesLambdaUnnested && !Nested);

HazardyKnusperkeks wrote:

```suggestion
const auto Indent = Nested ?
Style.BraceWrapping.IndentBracesLambdaNested :
Style.BraceWrapping.IndentBracesLambdaUnnested;
```
Way clearer.

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in AST/Type (PR #143258)

2025-06-07 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul created 
https://github.com/llvm/llvm-project/pull/143258

None

>From 95ce93cf1aac15b9896fda30c74d392b7acf3e6f Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Sat, 7 Jun 2025 04:47:42 -0700
Subject: [PATCH] [NFC][Clang] Adopt simplified `getTrailingObjects` in
 AST/Type

---
 clang/include/clang/AST/Type.h | 29 ++---
 clang/lib/AST/Type.cpp | 13 ++---
 2 files changed, 16 insertions(+), 26 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a6c26a07800c3..7fff819cba25d 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -5352,10 +5352,6 @@ class FunctionProtoType final
 return getNumFunctionEffects();
   }
 
-  unsigned numTrailingObjects(OverloadToken) const {
-return getNumFunctionEffectConditions();
-  }
-
   /// Determine whether there are any argument types that
   /// contain an unexpanded parameter pack.
   static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
@@ -5686,8 +5682,8 @@ class FunctionProtoType final
 if (hasExtraBitfields()) {
   const auto *Bitfields = getTrailingObjects();
   if (Bitfields->NumFunctionEffects > 0)
-return {getTrailingObjects(),
-Bitfields->NumFunctionEffects};
+return getTrailingObjects(
+Bitfields->NumFunctionEffects);
 }
 return {};
   }
@@ -5706,8 +5702,8 @@ class FunctionProtoType final
 if (hasExtraBitfields()) {
   const auto *Bitfields = getTrailingObjects();
   if (Bitfields->EffectsHaveConditions)
-return {getTrailingObjects(),
-Bitfields->NumFunctionEffects};
+return getTrailingObjects(
+Bitfields->NumFunctionEffects);
 }
 return {};
   }
@@ -5721,8 +5717,7 @@ class FunctionProtoType final
 ? Bitfields->NumFunctionEffects
 : 0;
 return FunctionEffectsRef(
-{getTrailingObjects(),
- Bitfields->NumFunctionEffects},
+getTrailingObjects(Bitfields->NumFunctionEffects),
 {NumConds ? getTrailingObjects() : nullptr,
  NumConds});
   }
@@ -6063,8 +6058,6 @@ class PackIndexingType final
 
   static TypeDependence computeDependence(QualType Pattern, Expr *IndexExpr,
   ArrayRef Expansions = {});
-
-  unsigned numTrailingObjects(OverloadToken) const { return Size; }
 };
 
 /// A unary type transform, which is a type constructed from another.
@@ -6491,8 +6484,7 @@ class HLSLInlineSpirvType final
 for (size_t I = 0; I < NumOperands; I++) {
   // Since Operands are stored as a trailing object, they have not been
   // initialized yet. Call the constructor manually.
-  auto *Operand =
-  new (&getTrailingObjects()[I]) SpirvOperand();
+  auto *Operand = new (&getTrailingObjects()[I]) SpirvOperand();
   *Operand = Operands[I];
 }
   }
@@ -6502,7 +6494,7 @@ class HLSLInlineSpirvType final
   uint32_t getSize() const { return Size; }
   uint32_t getAlignment() const { return Alignment; }
   ArrayRef getOperands() const {
-return {getTrailingObjects(), NumOperands};
+return getTrailingObjects(NumOperands);
   }
 
   bool isSugared() const { return false; }
@@ -6602,7 +6594,7 @@ class SubstTemplateTypeParmType final
   /// parameter.
   QualType getReplacementType() const {
 return SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType
-   ? *getTrailingObjects()
+   ? *getTrailingObjects()
: getCanonicalTypeInternal();
   }
 
@@ -7164,7 +7156,7 @@ class ElaboratedType final
 ElaboratedTypeBits.HasOwnedTagDecl = false;
 if (OwnedTagDecl) {
   ElaboratedTypeBits.HasOwnedTagDecl = true;
-  *getTrailingObjects() = OwnedTagDecl;
+  *getTrailingObjects() = OwnedTagDecl;
 }
   }
 
@@ -7184,8 +7176,7 @@ class ElaboratedType final
   /// Return the (re)declaration of this type owned by this occurrence of this
   /// type, or nullptr if there is none.
   TagDecl *getOwnedTagDecl() const {
-return ElaboratedTypeBits.HasOwnedTagDecl ? *getTrailingObjects()
-  : nullptr;
+return ElaboratedTypeBits.HasOwnedTagDecl ? *getTrailingObjects() : 
nullptr;
   }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 5bb39b12693fb..800cd2a91ec26 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -4019,12 +4019,11 @@ TypedefType::TypedefType(TypeClass tc, const 
TypedefNameDecl *D,
   assert(!isa(can) && "Invalid canonical type");
   TypedefBits.hasTypeDifferentFromDecl = !Underlying.isNull();
   if (!typeMatchesDecl())
-*getTrailingObjects() = Underlying;
+*getTrailingObjects() = Underlying;
 }
 
 QualType TypedefType::desugar() const {
-  return typeMatchesDecl() ? Decl->getU

[clang] [clang-format] Add options to control wrapped lambda brace indent. (PR #143249)

2025-06-07 Thread via cfe-commits


@@ -1334,12 +1334,15 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Style.IndentWidth;
   }
 
-  if (Style.BraceWrapping.BeforeLambdaBody &&
-  Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
+  if (Style.BraceWrapping.BeforeLambdaBody && Current.is(TT_LambdaLBrace)) {
+const auto Nested = Current.NestingLevel != 0;
 const auto From = Style.LambdaBodyIndentation == FormatStyle::LBI_Signature
   ? CurrentState.Indent
   : State.FirstIndent;
-return From + Style.IndentWidth;
+const auto Indent =
+(Style.BraceWrapping.IndentBracesLambdaNested && Nested) ||
+(Style.BraceWrapping.IndentBracesLambdaUnnested && !Nested);
+return From + (Indent * Style.IndentWidth);

rmarker wrote:

I don't think so. The indentation consideration has been moved from 
`IndentBraces` to `IndentBracesLambdaNested` and `IndentBracesLambdaUnnested`.
Also, either way, if it were to continue, it would just return in the next 
condition below.
When I looked into it, it appeared that the result would be the same. I.e. 
returning either `State.FirstIndent` or `CurrentState.Indent`, just without the 
possibility of indenting.
I figure that just having it all handled here makes things simpler.

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


[clang] [clang-format] Add options to control wrapped lambda brace indent. (PR #143249)

2025-06-07 Thread via cfe-commits

https://github.com/rmarker updated 
https://github.com/llvm/llvm-project/pull/143249

>From 212f9142a084c4d7bb11423565fb1f0eae93c35f Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Sat, 7 Jun 2025 20:29:18 +0930
Subject: [PATCH 1/2] [clang-format] Add options to control wrapped lambda
 brace indent.

Adds options to customise how wrapped lambda braces are indented when
using custom brace wrapping.
IndentBraces was recently changed to also indent wrapped lambda braces.
This has been changed to be controlled separately to allow the old
behaviour to be maintained.
Especially before a release is made with the new behaviour.
In order to further increase flexibility, the indentation can be
controlled separately for both nested and unnested lambdas.
---
 clang/docs/ClangFormatStyleOptions.rst | 34 ++
 clang/docs/ReleaseNotes.rst|  2 +
 clang/include/clang/Format/Format.h| 32 +
 clang/lib/Format/ContinuationIndenter.cpp  | 17 +++--
 clang/lib/Format/Format.cpp| 10 +++
 clang/unittests/Format/ConfigParseTest.cpp |  2 +
 clang/unittests/Format/FormatTest.cpp  | 78 ++
 7 files changed, 170 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 83716cc049ee3..5294c77020945 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2541,6 +2541,40 @@ the configuration (without a prefix: ``Auto``).
 
   * ``bool IndentBraces`` Indent the wrapped braces themselves.
 
+  * ``bool IndentBracesLambdaNested`` Indent nested wrapped lambda braces.
+
+.. code-block:: c++
+
+  false:
+  function(
+  []()
+  {
+return true;
+  });
+
+  true:
+  function(
+  []()
+{
+  return true;
+});
+
+  * ``bool IndentBracesLambdaUnnested`` Indent unnested wrapped lambda braces.
+
+.. code-block:: c++
+
+  false:
+  auto foo = []()
+  {
+return true;
+  };
+
+  true:
+  auto foo = []()
+{
+  return true;
+};
+
   * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put 
on a single line.
 This option is used only if the opening brace of the function has
 already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9ab69320f0368..03e33c4fcdc49 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -988,6 +988,8 @@ clang-format
   ``enum`` enumerator lists.
 - Add ``OneLineFormatOffRegex`` option for turning formatting off for one line.
 - Add ``SpaceAfterOperatorKeyword`` option.
+- Add ``IndentBracesLambdaNested`` and ``IndentBracesLambdaUnnested`` to
+  ``BraceWrapping`` options for controlling wrapped lambda brace indentation.
 
 clang-refactor
 --
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 127b1d08919de..86291d6fa845c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1547,6 +1547,38 @@ struct FormatStyle {
 bool BeforeWhile;
 /// Indent the wrapped braces themselves.
 bool IndentBraces;
+/// Indent nested wrapped lambda braces.
+/// \code
+///   false:
+///   function(
+///   []()
+///   {
+/// return true;
+///   });
+///
+///   true:
+///   function(
+///   []()
+/// {
+///   return true;
+/// });
+/// \endcode
+bool IndentBracesLambdaNested;
+/// Indent unnested wrapped lambda braces.
+/// \code
+///   false:
+///   auto foo = []()
+///   {
+/// return true;
+///   };
+///
+///   true:
+///   auto foo = []()
+/// {
+///   return true;
+/// };
+/// \endcode
+bool IndentBracesLambdaUnnested;
 /// If ``false``, empty function body can be put on a single line.
 /// This option is used only if the opening brace of the function has
 /// already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 4e4e48f90a89f..d37b075da61ae 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1334,12 +1334,15 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Style.IndentWidth;
   }
 
-  if (Style.BraceWrapping.BeforeLambdaBody &&
-  Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
+  if (Style.BraceWrapping.BeforeLambdaBody && Current.is(TT_LambdaLBrace)) {
+const auto Nested = Current.NestingLevel != 0;
 const auto From = Style.LambdaBodyIndentation == FormatStyle::LBI_Signature
   ? Current

[clang] [clang-format] Add options to control wrapped lambda brace indent. (PR #143249)

2025-06-07 Thread via cfe-commits


@@ -1334,12 +1334,15 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Style.IndentWidth;
   }
 
-  if (Style.BraceWrapping.BeforeLambdaBody &&
-  Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
+  if (Style.BraceWrapping.BeforeLambdaBody && Current.is(TT_LambdaLBrace)) {
+const auto Nested = Current.NestingLevel != 0;

rmarker wrote:

Good idea.

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


[clang] [CIR] Implement folder for VecShuffleOp (PR #143260)

2025-06-07 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper created 
https://github.com/llvm/llvm-project/pull/143260

This change adds a folder for the VecShuffleOp

Issue https://github.com/llvm/llvm-project/issues/136487

>From 14ffd458c4896bd4d5fb73f97c5745db70c8360e Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sat, 7 Jun 2025 14:43:16 +0200
Subject: [PATCH] [CIR] Implement folder for VecShuffleOp

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  2 +
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   | 38 --
 .../Dialect/Transforms/CIRCanonicalize.cpp|  2 +-
 .../CIR/Transforms/vector-shuffle-fold.cir| 39 +++
 4 files changed, 77 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/CIR/Transforms/vector-shuffle-fold.cir

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 038a59b8ff4eb..568861cea9f92 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2199,7 +2199,9 @@ def VecShuffleOp : CIR_Op<"vec.shuffle",
 `(` $vec1 `,` $vec2 `:` qualified(type($vec1)) `)` $indices `:`
  qualified(type($result)) attr-dict
   }];
+
   let hasVerifier = 1;
+  let hasFolder = 1;
 }
 
 
//===--===//
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index bfd3a0a62a8e7..0eae0494eafd5 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1580,9 +1580,42 @@ OpFoldResult cir::VecExtractOp::fold(FoldAdaptor 
adaptor) {
 }
 
 
//===--===//
-// VecShuffle
+// VecShuffleOp
 
//===--===//
 
+OpFoldResult cir::VecShuffleOp::fold(FoldAdaptor adaptor) {
+  mlir::Attribute vec1 = adaptor.getVec1();
+  mlir::Attribute vec2 = adaptor.getVec2();
+
+  if (!mlir::isa_and_nonnull(vec1) ||
+  !mlir::isa_and_nonnull(vec2)) {
+return {};
+  }
+
+  auto vec1Attr = mlir::cast(vec1);
+  auto vec2Attr = mlir::cast(vec2);
+
+  mlir::ArrayAttr vec1Elts = vec1Attr.getElts();
+  mlir::ArrayAttr vec2Elts = vec2Attr.getElts();
+  mlir::ArrayAttr indicesElts = adaptor.getIndices();
+
+  SmallVector elements;
+  elements.reserve(indicesElts.size());
+
+  uint64_t vec1Size = vec1Elts.size();
+  for (const auto &idxAttr : indicesElts.getAsRange()) {
+uint64_t idxValue = idxAttr.getUInt();
+if (idxValue < vec1Size) {
+  elements.push_back(vec1Elts[idxValue]);
+} else {
+  elements.push_back(vec2Elts[idxValue - vec1Size]);
+}
+  }
+
+  return cir::ConstVectorAttr::get(
+  getType(), mlir::ArrayAttr::get(getContext(), elements));
+}
+
 LogicalResult cir::VecShuffleOp::verify() {
   // The number of elements in the indices array must match the number of
   // elements in the result type.
@@ -1613,7 +1646,6 @@ OpFoldResult cir::VecShuffleDynamicOp::fold(FoldAdaptor 
adaptor) {
   mlir::isa_and_nonnull(indices)) {
 auto vecAttr = mlir::cast(vec);
 auto indicesAttr = mlir::cast(indices);
-auto vecTy = mlir::cast(vecAttr.getType());
 
 mlir::ArrayAttr vecElts = vecAttr.getElts();
 mlir::ArrayAttr indicesElts = indicesAttr.getElts();
@@ -1631,7 +1663,7 @@ OpFoldResult cir::VecShuffleDynamicOp::fold(FoldAdaptor 
adaptor) {
 }
 
 return cir::ConstVectorAttr::get(
-vecTy, mlir::ArrayAttr::get(getContext(), elements));
+getType(), mlir::ArrayAttr::get(getContext(), elements));
   }
 
   return {};
diff --git a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp 
b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
index 33881c69eec5f..29f9942638964 100644
--- a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
@@ -142,7 +142,7 @@ void CIRCanonicalizePass::runOnOperation() {
 // Many operations are here to perform a manual `fold` in
 // applyOpPatternsGreedily.
 if (isa(op))
+VecExtractOp, VecShuffleOp, VecShuffleDynamicOp, VecTernaryOp>(op))
   ops.push_back(op);
   });
 
diff --git a/clang/test/CIR/Transforms/vector-shuffle-fold.cir 
b/clang/test/CIR/Transforms/vector-shuffle-fold.cir
new file mode 100644
index 0..a6b43b6f2951d
--- /dev/null
+++ b/clang/test/CIR/Transforms/vector-shuffle-fold.cir
@@ -0,0 +1,39 @@
+// RUN: cir-opt %s -cir-canonicalize -o - -split-input-file | FileCheck %s
+
+!s32i = !cir.int
+!s64i = !cir.int
+
+module  {
+  cir.func @fold_shuffle_vector_op_test() -> !cir.vector<4 x !s32i> {
+%vec_1 = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<3> : 
!s32i, #cir.int<5> : !s32i, #cir.int<7> : !s32i]> : !cir.vector<4 x !s32i>
+%vec_2 = cir.const #cir.const_vector<[#cir.int<2> : !s32i, #cir.int<4> : 
!s32i, #cir.int<6> : !s32i, #cir.int<8> : !s32i]> : !cir.vector<4 x !s32i>
+%new_vec = cir.vec.

[clang] [clang-format] Add options to control wrapped lambda brace indent. (PR #143249)

2025-06-07 Thread via cfe-commits


@@ -1334,12 +1334,15 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Style.IndentWidth;
   }
 
-  if (Style.BraceWrapping.BeforeLambdaBody &&
-  Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
+  if (Style.BraceWrapping.BeforeLambdaBody && Current.is(TT_LambdaLBrace)) {
+const auto Nested = Current.NestingLevel != 0;
 const auto From = Style.LambdaBodyIndentation == FormatStyle::LBI_Signature
   ? CurrentState.Indent
   : State.FirstIndent;
-return From + Style.IndentWidth;
+const auto Indent =
+(Style.BraceWrapping.IndentBracesLambdaNested && Nested) ||
+(Style.BraceWrapping.IndentBracesLambdaUnnested && !Nested);

rmarker wrote:

Much nicer.

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


[clang] [CIR] Implement folder for VecShuffleOp (PR #143260)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)


Changes

This change adds a folder for the VecShuffleOp

Issue https://github.com/llvm/llvm-project/issues/136487

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


4 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+2) 
- (modified) clang/lib/CIR/Dialect/IR/CIRDialect.cpp (+35-3) 
- (modified) clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp (+1-1) 
- (added) clang/test/CIR/Transforms/vector-shuffle-fold.cir (+39) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 038a59b8ff4eb..568861cea9f92 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2199,7 +2199,9 @@ def VecShuffleOp : CIR_Op<"vec.shuffle",
 `(` $vec1 `,` $vec2 `:` qualified(type($vec1)) `)` $indices `:`
  qualified(type($result)) attr-dict
   }];
+
   let hasVerifier = 1;
+  let hasFolder = 1;
 }
 
 
//===--===//
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index bfd3a0a62a8e7..0eae0494eafd5 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1580,9 +1580,42 @@ OpFoldResult cir::VecExtractOp::fold(FoldAdaptor 
adaptor) {
 }
 
 
//===--===//
-// VecShuffle
+// VecShuffleOp
 
//===--===//
 
+OpFoldResult cir::VecShuffleOp::fold(FoldAdaptor adaptor) {
+  mlir::Attribute vec1 = adaptor.getVec1();
+  mlir::Attribute vec2 = adaptor.getVec2();
+
+  if (!mlir::isa_and_nonnull(vec1) ||
+  !mlir::isa_and_nonnull(vec2)) {
+return {};
+  }
+
+  auto vec1Attr = mlir::cast(vec1);
+  auto vec2Attr = mlir::cast(vec2);
+
+  mlir::ArrayAttr vec1Elts = vec1Attr.getElts();
+  mlir::ArrayAttr vec2Elts = vec2Attr.getElts();
+  mlir::ArrayAttr indicesElts = adaptor.getIndices();
+
+  SmallVector elements;
+  elements.reserve(indicesElts.size());
+
+  uint64_t vec1Size = vec1Elts.size();
+  for (const auto &idxAttr : indicesElts.getAsRange()) {
+uint64_t idxValue = idxAttr.getUInt();
+if (idxValue < vec1Size) {
+  elements.push_back(vec1Elts[idxValue]);
+} else {
+  elements.push_back(vec2Elts[idxValue - vec1Size]);
+}
+  }
+
+  return cir::ConstVectorAttr::get(
+  getType(), mlir::ArrayAttr::get(getContext(), elements));
+}
+
 LogicalResult cir::VecShuffleOp::verify() {
   // The number of elements in the indices array must match the number of
   // elements in the result type.
@@ -1613,7 +1646,6 @@ OpFoldResult cir::VecShuffleDynamicOp::fold(FoldAdaptor 
adaptor) {
   mlir::isa_and_nonnull(indices)) {
 auto vecAttr = mlir::cast(vec);
 auto indicesAttr = mlir::cast(indices);
-auto vecTy = mlir::cast(vecAttr.getType());
 
 mlir::ArrayAttr vecElts = vecAttr.getElts();
 mlir::ArrayAttr indicesElts = indicesAttr.getElts();
@@ -1631,7 +1663,7 @@ OpFoldResult cir::VecShuffleDynamicOp::fold(FoldAdaptor 
adaptor) {
 }
 
 return cir::ConstVectorAttr::get(
-vecTy, mlir::ArrayAttr::get(getContext(), elements));
+getType(), mlir::ArrayAttr::get(getContext(), elements));
   }
 
   return {};
diff --git a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp 
b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
index 33881c69eec5f..29f9942638964 100644
--- a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
@@ -142,7 +142,7 @@ void CIRCanonicalizePass::runOnOperation() {
 // Many operations are here to perform a manual `fold` in
 // applyOpPatternsGreedily.
 if (isa(op))
+VecExtractOp, VecShuffleOp, VecShuffleDynamicOp, VecTernaryOp>(op))
   ops.push_back(op);
   });
 
diff --git a/clang/test/CIR/Transforms/vector-shuffle-fold.cir 
b/clang/test/CIR/Transforms/vector-shuffle-fold.cir
new file mode 100644
index 0..a6b43b6f2951d
--- /dev/null
+++ b/clang/test/CIR/Transforms/vector-shuffle-fold.cir
@@ -0,0 +1,39 @@
+// RUN: cir-opt %s -cir-canonicalize -o - -split-input-file | FileCheck %s
+
+!s32i = !cir.int
+!s64i = !cir.int
+
+module  {
+  cir.func @fold_shuffle_vector_op_test() -> !cir.vector<4 x !s32i> {
+%vec_1 = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<3> : 
!s32i, #cir.int<5> : !s32i, #cir.int<7> : !s32i]> : !cir.vector<4 x !s32i>
+%vec_2 = cir.const #cir.const_vector<[#cir.int<2> : !s32i, #cir.int<4> : 
!s32i, #cir.int<6> : !s32i, #cir.int<8> : !s32i]> : !cir.vector<4 x !s32i>
+%new_vec = cir.vec.shuffle(%vec_1, %vec_2 : !cir.vector<4 x !s32i>) 
[#cir.int<0> : !s64i, #cir.int<4> : !s64i,
+  #cir.int<1> : !s64i, #cir.int<5> : !s64i] : !cir.vector<4 x !s32i>
+cir.return %new_ve

[clang] [clang-format] Add options to control wrapped lambda brace indent. (PR #143249)

2025-06-07 Thread via cfe-commits


@@ -1547,6 +1547,38 @@ struct FormatStyle {
 bool BeforeWhile;
 /// Indent the wrapped braces themselves.
 bool IndentBraces;
+/// Indent nested wrapped lambda braces.

rmarker wrote:

Hmm, yeah, I based the name off of the description in the code. I.e. that it 
uses `Current.NestingLevel`.
I hadn't thought about the lambda in lambda.
Do you have any ideas of something clearer?
Maybe `IndentBracesLambdaTopLevel` for the unnested and then just 
`IndentBracesLambda` for the others? (I cannot think of an immediately obvious 
name for the nested case).

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


[clang] [CIR] Extend VecShuffleOp verifier to catch invalid index (PR #143262)

2025-06-07 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper created 
https://github.com/llvm/llvm-project/pull/143262

Extend the verifier to catch index larger than the size of vector elements in 
VecShuffleOp

Issue https://github.com/llvm/llvm-project/issues/136487

>From 5f98861a88e544ec80bbaf5fe0ffb650c2d71e67 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sat, 7 Jun 2025 14:57:53 +0200
Subject: [PATCH] [CIR] Extend VecShuffleOp verifier to catch invalid index

---
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp  |  8 
 .../IR/invalid-vector-shuffle-wrong-index.cir| 16 
 2 files changed, 24 insertions(+)
 create mode 100644 clang/test/CIR/IR/invalid-vector-shuffle-wrong-index.cir

diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index bfd3a0a62a8e7..b0678ee737a62 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1599,6 +1599,14 @@ LogicalResult cir::VecShuffleOp::verify() {
  << " and " << getResult().getType() << " don't match";
   }
 
+  const uint64_t maxValidIndex =
+  getVec1().getType().getSize() + getVec2().getType().getSize() - 1;
+  for (const auto &idxAttr : getIndices().getAsRange()) {
+if (idxAttr.getUInt() > maxValidIndex)
+  return emitOpError() << ": index for __builtin_shufflevector must be "
+  "less than the total number of vector elements";
+  }
+
   return success();
 }
 
diff --git a/clang/test/CIR/IR/invalid-vector-shuffle-wrong-index.cir 
b/clang/test/CIR/IR/invalid-vector-shuffle-wrong-index.cir
new file mode 100644
index 0..375b2d3dc563e
--- /dev/null
+++ b/clang/test/CIR/IR/invalid-vector-shuffle-wrong-index.cir
@@ -0,0 +1,16 @@
+// RUN: cir-opt %s -verify-diagnostics -split-input-file
+
+!s32i = !cir.int
+!s64i = !cir.int
+
+module  {
+  cir.func @fold_shuffle_vector_op_test() -> !cir.vector<4 x !s32i> {
+%vec_1 = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<3> : 
!s32i, #cir.int<5> : !s32i, #cir.int<7> : !s32i]> : !cir.vector<4 x !s32i>
+%vec_2 = cir.const #cir.const_vector<[#cir.int<2> : !s32i, #cir.int<4> : 
!s32i, #cir.int<6> : !s32i, #cir.int<8> : !s32i]> : !cir.vector<4 x !s32i>
+
+// expected-error @below {{index for __builtin_shufflevector must be less 
than the total number of vector elements}}
+%new_vec = cir.vec.shuffle(%vec_1, %vec_2 : !cir.vector<4 x !s32i>) 
[#cir.int<9> : !s64i, #cir.int<4> : !s64i,
+  #cir.int<1> : !s64i, #cir.int<5> : !s64i] : !cir.vector<4 x !s32i>
+cir.return %new_vec : !cir.vector<4 x !s32i>
+  }
+}

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


[clang] [CIR] Extend VecShuffleOp verifier to catch invalid index (PR #143262)

2025-06-07 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clangir

Author: Amr Hesham (AmrDeveloper)


Changes

Extend the verifier to catch index larger than the size of vector elements in 
VecShuffleOp

Issue https://github.com/llvm/llvm-project/issues/136487

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


2 Files Affected:

- (modified) clang/lib/CIR/Dialect/IR/CIRDialect.cpp (+8) 
- (added) clang/test/CIR/IR/invalid-vector-shuffle-wrong-index.cir (+16) 


``diff
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index bfd3a0a62a8e7..b0678ee737a62 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1599,6 +1599,14 @@ LogicalResult cir::VecShuffleOp::verify() {
  << " and " << getResult().getType() << " don't match";
   }
 
+  const uint64_t maxValidIndex =
+  getVec1().getType().getSize() + getVec2().getType().getSize() - 1;
+  for (const auto &idxAttr : getIndices().getAsRange()) {
+if (idxAttr.getUInt() > maxValidIndex)
+  return emitOpError() << ": index for __builtin_shufflevector must be "
+  "less than the total number of vector elements";
+  }
+
   return success();
 }
 
diff --git a/clang/test/CIR/IR/invalid-vector-shuffle-wrong-index.cir 
b/clang/test/CIR/IR/invalid-vector-shuffle-wrong-index.cir
new file mode 100644
index 0..375b2d3dc563e
--- /dev/null
+++ b/clang/test/CIR/IR/invalid-vector-shuffle-wrong-index.cir
@@ -0,0 +1,16 @@
+// RUN: cir-opt %s -verify-diagnostics -split-input-file
+
+!s32i = !cir.int
+!s64i = !cir.int
+
+module  {
+  cir.func @fold_shuffle_vector_op_test() -> !cir.vector<4 x !s32i> {
+%vec_1 = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<3> : 
!s32i, #cir.int<5> : !s32i, #cir.int<7> : !s32i]> : !cir.vector<4 x !s32i>
+%vec_2 = cir.const #cir.const_vector<[#cir.int<2> : !s32i, #cir.int<4> : 
!s32i, #cir.int<6> : !s32i, #cir.int<8> : !s32i]> : !cir.vector<4 x !s32i>
+
+// expected-error @below {{index for __builtin_shufflevector must be less 
than the total number of vector elements}}
+%new_vec = cir.vec.shuffle(%vec_1, %vec_2 : !cir.vector<4 x !s32i>) 
[#cir.int<9> : !s64i, #cir.int<4> : !s64i,
+  #cir.int<1> : !s64i, #cir.int<5> : !s64i] : !cir.vector<4 x !s32i>
+cir.return %new_vec : !cir.vector<4 x !s32i>
+  }
+}

``




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


[clang] [libclang/python] Add missing enum variants (PR #143264)

2025-06-07 Thread Jannick Kremer via cfe-commits

https://github.com/DeinAlptraum created 
https://github.com/llvm/llvm-project/pull/143264

Add tests to ensure that all C-enum variants are defined on Python side.

>From cee0067c7a0b35d2e1f15fd3fa698ec2afd6de88 Mon Sep 17 00:00:00 2001
From: Jannick Kremer 
Date: Sat, 7 Jun 2025 21:57:17 +0900
Subject: [PATCH] [libclang/python] Add missing enum variants

Add tests to ensure that all C-enum variants are defined on Python side.
---
 .../python/tests/cindex/test_enums.py | 49 ++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/clang/bindings/python/tests/cindex/test_enums.py 
b/clang/bindings/python/tests/cindex/test_enums.py
index 9e7f44fcf7867..54c0c77e4df29 100644
--- a/clang/bindings/python/tests/cindex/test_enums.py
+++ b/clang/bindings/python/tests/cindex/test_enums.py
@@ -1,4 +1,5 @@
 import unittest
+from pathlib import Path
 
 from clang.cindex import (
 AccessSpecifier,
@@ -12,6 +13,7 @@
 TemplateArgumentKind,
 TLSKind,
 TokenKind,
+TranslationUnit,
 TypeKind,
 )
 
@@ -44,8 +46,53 @@ def test_from_id(self):
 
 def test_duplicate_ids(self):
 """Check that no two kinds have the same id"""
-# for enum in self.enums:
 for enum in self.enums:
 num_declared_variants = len(enum._member_map_.keys())
 num_unique_variants = len(list(enum))
 self.assertEqual(num_declared_variants, num_unique_variants)
+
+def test_all_variants(self):
+"""Check that all libclang enum values are also defined in cindex"""
+cenum_to_pythonenum = {
+"CX_CXXAccessSpecifier": AccessSpecifier,
+"CXAvailabilityKind": AvailabilityKind,
+"CXBinaryOperatorKind": BinaryOperator,
+"CXCursorKind": CursorKind,
+"CXCursor_ExceptionSpecificationKind": ExceptionSpecificationKind,
+"CXLinkageKind": LinkageKind,
+"CXRefQualifierKind": RefQualifierKind,
+"CX_StorageClass": StorageClass,
+"CXTemplateArgumentKind": TemplateArgumentKind,
+"CXTLSKind": TLSKind,
+"CXTokenKind": TokenKind,
+"CXTypeKind": TypeKind,
+}
+
+indexheader = (
+Path(__file__).parent.parent.parent.parent.parent
+/ "include/clang-c/Index.h"
+)
+tu = TranslationUnit.from_source(indexheader, ["-x", "c++"])
+
+enum_variant_map = {}
+# For all enums in self.enums, extract all enum variants defined in 
Index.h
+for cursor in tu.cursor.walk_preorder():
+type_class = cenum_to_pythonenum.get(cursor.type.spelling)
+if (
+cursor.kind == CursorKind.ENUM_CONSTANT_DECL
+and type_class in self.enums
+):
+if type_class not in enum_variant_map:
+enum_variant_map[type_class] = []
+enum_variant_map[type_class].append(cursor.enum_value)
+
+for enum in self.enums:
+with self.subTest(enum):
+python_kinds = set([kind.value for kind in enum])
+c_kinds = set(enum_variant_map[enum])
+missing_python_kinds = c_kinds - python_kinds
+self.assertEqual(
+missing_python_kinds,
+set(),
+f"Please ensure these variants are defined inside {enum} 
in cindex.py.",
+)

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


[clang] [libclang/python] Add missing enum variants (PR #143264)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)


Changes

Add tests to ensure that all C-enum variants are defined on Python side.

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


1 Files Affected:

- (modified) clang/bindings/python/tests/cindex/test_enums.py (+48-1) 


``diff
diff --git a/clang/bindings/python/tests/cindex/test_enums.py 
b/clang/bindings/python/tests/cindex/test_enums.py
index 9e7f44fcf7867..54c0c77e4df29 100644
--- a/clang/bindings/python/tests/cindex/test_enums.py
+++ b/clang/bindings/python/tests/cindex/test_enums.py
@@ -1,4 +1,5 @@
 import unittest
+from pathlib import Path
 
 from clang.cindex import (
 AccessSpecifier,
@@ -12,6 +13,7 @@
 TemplateArgumentKind,
 TLSKind,
 TokenKind,
+TranslationUnit,
 TypeKind,
 )
 
@@ -44,8 +46,53 @@ def test_from_id(self):
 
 def test_duplicate_ids(self):
 """Check that no two kinds have the same id"""
-# for enum in self.enums:
 for enum in self.enums:
 num_declared_variants = len(enum._member_map_.keys())
 num_unique_variants = len(list(enum))
 self.assertEqual(num_declared_variants, num_unique_variants)
+
+def test_all_variants(self):
+"""Check that all libclang enum values are also defined in cindex"""
+cenum_to_pythonenum = {
+"CX_CXXAccessSpecifier": AccessSpecifier,
+"CXAvailabilityKind": AvailabilityKind,
+"CXBinaryOperatorKind": BinaryOperator,
+"CXCursorKind": CursorKind,
+"CXCursor_ExceptionSpecificationKind": ExceptionSpecificationKind,
+"CXLinkageKind": LinkageKind,
+"CXRefQualifierKind": RefQualifierKind,
+"CX_StorageClass": StorageClass,
+"CXTemplateArgumentKind": TemplateArgumentKind,
+"CXTLSKind": TLSKind,
+"CXTokenKind": TokenKind,
+"CXTypeKind": TypeKind,
+}
+
+indexheader = (
+Path(__file__).parent.parent.parent.parent.parent
+/ "include/clang-c/Index.h"
+)
+tu = TranslationUnit.from_source(indexheader, ["-x", "c++"])
+
+enum_variant_map = {}
+# For all enums in self.enums, extract all enum variants defined in 
Index.h
+for cursor in tu.cursor.walk_preorder():
+type_class = cenum_to_pythonenum.get(cursor.type.spelling)
+if (
+cursor.kind == CursorKind.ENUM_CONSTANT_DECL
+and type_class in self.enums
+):
+if type_class not in enum_variant_map:
+enum_variant_map[type_class] = []
+enum_variant_map[type_class].append(cursor.enum_value)
+
+for enum in self.enums:
+with self.subTest(enum):
+python_kinds = set([kind.value for kind in enum])
+c_kinds = set(enum_variant_map[enum])
+missing_python_kinds = c_kinds - python_kinds
+self.assertEqual(
+missing_python_kinds,
+set(),
+f"Please ensure these variants are defined inside {enum} 
in cindex.py.",
+)

``




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


[clang] [Clang] Explain why a type is not replaceable. (PR #143265)

2025-06-07 Thread Corentin Jabot via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/143265

As a drive by fix the definition of replaceable, that did not correctly 
implement https://eel.is/c++draft/class.prop#6.3

>From 7f626192c2636805c890098c6d6bf0e7bef11725 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Sat, 7 Jun 2025 15:14:43 +0200
Subject: [PATCH] [Clang] Explain why a type is not replaceable.

As a drive by fix the definition of replaceable,
that did not correctly implement
https://eel.is/c++draft/class.prop#6.3
---
 .../clang/Basic/DiagnosticSemaKinds.td|  20 ++-
 clang/lib/Sema/SemaTypeTraits.cpp | 159 ++
 .../SemaCXX/cxx2c-trivially-relocatable.cpp   |  25 +++
 .../type-traits-unsatisfied-diags-std.cpp |  21 +++
 .../SemaCXX/type-traits-unsatisfied-diags.cpp | 131 +++
 5 files changed, 321 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5f44d503580b9..f77ddbcff8ec0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1763,27 +1763,39 @@ def err_user_defined_msg_constexpr : Error<
   "constant expression">;
 
 // Type traits explanations
-def note_unsatisfied_trait : Note<"%0 is not %enum_select{"
-  "%TriviallyRelocatable{trivially 
relocatable}|"
-  "%TriviallyCopyable{trivially copyable}"
-  "}1">;
+def note_unsatisfied_trait
+: Note<"%0 is not %enum_select{"
+   "%TriviallyRelocatable{trivially relocatable}|"
+   "%Replaceable{replaceable}|"
+   "%TriviallyCopyable{trivially copyable}"
+   "}1">;
 
 def note_unsatisfied_trait_reason
 : Note<"because it "
"%enum_select{"
"%Ref{is a reference type}|"
+   "%Const{is const}|"
+   "%Volatile{is volatile}|"
"%HasArcLifetime{has an ARC lifetime qualifier}|"
"%VLA{is a variably-modified type}|"
"%VBase{has a virtual base %1}|"
+   "%NotScalarOrClass{not %select{a|an array of objects of}1 scalar or 
"
+   "class type}|"
"%NTRBase{has a non-trivially-relocatable base %1}|"
"%NTRField{has a non-trivially-relocatable member %1 of type %2}|"
+   "%NonReplaceableBase{has a non-replaceable base %1}|"
+   "%NonReplaceableField{has a non-replaceable member %1 of type %2}|"
"%NTCBase{has a non-trivially-copyable base %1}|"
"%NTCField{has a non-trivially-copyable member %1 of type %2}|"
"%DeletedDtr{has a %select{deleted|user-provided}1 destructor}|"
"%UserProvidedCtr{has a user provided %select{copy|move}1 "
"constructor}|"
+   "%DeletedCtr{has a deleted %select{copy|move}1 "
+   "constructor}|"
"%UserProvidedAssign{has a user provided %select{copy|move}1 "
"assignment operator}|"
+   "%DeletedAssign{has a deleted %select{copy|move}1 "
+   "assignment operator}|"
"%UnionWithUserDeclaredSMF{is a union with a user-declared "
"%sub{select_special_member_kind}1}"
"}0">;
diff --git a/clang/lib/Sema/SemaTypeTraits.cpp 
b/clang/lib/Sema/SemaTypeTraits.cpp
index 330f2aa750a09..eba4dbb457ae6 100644
--- a/clang/lib/Sema/SemaTypeTraits.cpp
+++ b/clang/lib/Sema/SemaTypeTraits.cpp
@@ -104,6 +104,7 @@ static CXXMethodDecl *LookupSpecialMemberFromXValue(Sema 
&SemaRef,
   OverloadCandidateSet::iterator Best;
   switch (OCS.BestViableFunction(SemaRef, LookupLoc, Best)) {
   case OR_Success:
+  case OR_Deleted:
 return cast(Best->Function);
   default:
 return nullptr;
@@ -120,7 +121,8 @@ static bool hasSuitableConstructorForRelocation(Sema 
&SemaRef,
 
   CXXMethodDecl *Decl =
   LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/false);
-  return Decl && Decl->isUserProvided() == AllowUserDefined;
+  return Decl && Decl->isUserProvided() == AllowUserDefined &&
+ !Decl->isDeleted();
 }
 
 static bool hasSuitableMoveAssignmentOperatorForRelocation(
@@ -135,7 +137,8 @@ static bool hasSuitableMoveAssignmentOperatorForRelocation(
   if (!Decl)
 return false;
 
-  return Decl && Decl->isUserProvided() == AllowUserDefined;
+  return Decl && Decl->isUserProvided() == AllowUserDefined &&
+ !Decl->isDeleted();
 }
 
 // [C++26][class.prop]
@@ -1940,6 +1943,7 @@ static std::optional 
StdNameToTypeTrait(StringRef Name) {
   return llvm::StringSwitch>(Name)
   .Case("is_trivially_relocatable",
 TypeTrait::UTT_IsCppTriviallyRelocatable)
+  .Case("is_replaceable", TypeTrait::UTT_IsReplaceable)
   .Case("is_trivially_copyable", TypeTrait::UTT_IsTriviallyCopyable)
   .Default(std::nullopt);
 }
@@ -2005,35 +2009,8 @@ static ExtractedTypeTraitInfo 
ExtractTypeTraitFromExpression(const Expr *E) {
   r

[clang] [Clang] Explain why a type is not replaceable. (PR #143265)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Corentin Jabot (cor3ntin)


Changes

As a drive by fix the definition of replaceable, that did not correctly 
implement https://eel.is/c++draft/class.prop#6.3

---

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


5 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+16-4) 
- (modified) clang/lib/Sema/SemaTypeTraits.cpp (+128-31) 
- (modified) clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp (+25) 
- (modified) clang/test/SemaCXX/type-traits-unsatisfied-diags-std.cpp (+21) 
- (modified) clang/test/SemaCXX/type-traits-unsatisfied-diags.cpp (+131) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5f44d503580b9..f77ddbcff8ec0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1763,27 +1763,39 @@ def err_user_defined_msg_constexpr : Error<
   "constant expression">;
 
 // Type traits explanations
-def note_unsatisfied_trait : Note<"%0 is not %enum_select{"
-  "%TriviallyRelocatable{trivially 
relocatable}|"
-  "%TriviallyCopyable{trivially copyable}"
-  "}1">;
+def note_unsatisfied_trait
+: Note<"%0 is not %enum_select{"
+   "%TriviallyRelocatable{trivially relocatable}|"
+   "%Replaceable{replaceable}|"
+   "%TriviallyCopyable{trivially copyable}"
+   "}1">;
 
 def note_unsatisfied_trait_reason
 : Note<"because it "
"%enum_select{"
"%Ref{is a reference type}|"
+   "%Const{is const}|"
+   "%Volatile{is volatile}|"
"%HasArcLifetime{has an ARC lifetime qualifier}|"
"%VLA{is a variably-modified type}|"
"%VBase{has a virtual base %1}|"
+   "%NotScalarOrClass{not %select{a|an array of objects of}1 scalar or 
"
+   "class type}|"
"%NTRBase{has a non-trivially-relocatable base %1}|"
"%NTRField{has a non-trivially-relocatable member %1 of type %2}|"
+   "%NonReplaceableBase{has a non-replaceable base %1}|"
+   "%NonReplaceableField{has a non-replaceable member %1 of type %2}|"
"%NTCBase{has a non-trivially-copyable base %1}|"
"%NTCField{has a non-trivially-copyable member %1 of type %2}|"
"%DeletedDtr{has a %select{deleted|user-provided}1 destructor}|"
"%UserProvidedCtr{has a user provided %select{copy|move}1 "
"constructor}|"
+   "%DeletedCtr{has a deleted %select{copy|move}1 "
+   "constructor}|"
"%UserProvidedAssign{has a user provided %select{copy|move}1 "
"assignment operator}|"
+   "%DeletedAssign{has a deleted %select{copy|move}1 "
+   "assignment operator}|"
"%UnionWithUserDeclaredSMF{is a union with a user-declared "
"%sub{select_special_member_kind}1}"
"}0">;
diff --git a/clang/lib/Sema/SemaTypeTraits.cpp 
b/clang/lib/Sema/SemaTypeTraits.cpp
index 330f2aa750a09..eba4dbb457ae6 100644
--- a/clang/lib/Sema/SemaTypeTraits.cpp
+++ b/clang/lib/Sema/SemaTypeTraits.cpp
@@ -104,6 +104,7 @@ static CXXMethodDecl *LookupSpecialMemberFromXValue(Sema 
&SemaRef,
   OverloadCandidateSet::iterator Best;
   switch (OCS.BestViableFunction(SemaRef, LookupLoc, Best)) {
   case OR_Success:
+  case OR_Deleted:
 return cast(Best->Function);
   default:
 return nullptr;
@@ -120,7 +121,8 @@ static bool hasSuitableConstructorForRelocation(Sema 
&SemaRef,
 
   CXXMethodDecl *Decl =
   LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/false);
-  return Decl && Decl->isUserProvided() == AllowUserDefined;
+  return Decl && Decl->isUserProvided() == AllowUserDefined &&
+ !Decl->isDeleted();
 }
 
 static bool hasSuitableMoveAssignmentOperatorForRelocation(
@@ -135,7 +137,8 @@ static bool hasSuitableMoveAssignmentOperatorForRelocation(
   if (!Decl)
 return false;
 
-  return Decl && Decl->isUserProvided() == AllowUserDefined;
+  return Decl && Decl->isUserProvided() == AllowUserDefined &&
+ !Decl->isDeleted();
 }
 
 // [C++26][class.prop]
@@ -1940,6 +1943,7 @@ static std::optional 
StdNameToTypeTrait(StringRef Name) {
   return llvm::StringSwitch>(Name)
   .Case("is_trivially_relocatable",
 TypeTrait::UTT_IsCppTriviallyRelocatable)
+  .Case("is_replaceable", TypeTrait::UTT_IsReplaceable)
   .Case("is_trivially_copyable", TypeTrait::UTT_IsTriviallyCopyable)
   .Default(std::nullopt);
 }
@@ -2005,35 +2009,8 @@ static ExtractedTypeTraitInfo 
ExtractTypeTraitFromExpression(const Expr *E) {
   return std::nullopt;
 }
 
-static void DiagnoseNonTriviallyRelocatableReason(Sema &SemaRef,
-  SourceLocation Loc,
-  

[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in Stmt (PR #143250)

2025-06-07 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in StmtCXX (PR #143251)

2025-06-07 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in Stmt (PR #143250)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rahul Joshi (jurahul)


Changes



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


2 Files Affected:

- (modified) clang/include/clang/AST/Stmt.h (+43-68) 
- (modified) clang/lib/AST/Stmt.cpp (+4-4) 


``diff
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 48a6aea4f4b6a..6c4bd6f6946ba 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1953,10 +1953,6 @@ class CaseStmt final
 return NumMandatoryStmtPtr + caseStmtIsGNURange();
   }
 
-  unsigned numTrailingObjects(OverloadToken) const {
-return caseStmtIsGNURange();
-  }
-
   unsigned lhsOffset() const { return LhsOffset; }
   unsigned rhsOffset() const { return LhsOffset + caseStmtIsGNURange(); }
   unsigned subStmtOffset() const { return rhsOffset() + SubStmtOffsetFromRhs; }
@@ -2228,10 +2224,8 @@ class AttributedStmt final
 std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr);
   }
 
-  const Attr *const *getAttrArrayPtr() const {
-return getTrailingObjects();
-  }
-  const Attr **getAttrArrayPtr() { return getTrailingObjects(); }
+  const Attr *const *getAttrArrayPtr() const { return getTrailingObjects(); }
+  const Attr **getAttrArrayPtr() { return getTrailingObjects(); }
 
 public:
   static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
@@ -2543,7 +2537,7 @@ class SwitchStmt final : public Stmt,
   SourceLocation LParenLoc;
   SourceLocation RParenLoc;
 
-  unsigned numTrailingObjects(OverloadToken) const {
+  unsigned numTrailingStatements() const {
 return NumMandatoryStmtPtr + hasInitStorage() + hasVarStorage();
   }
 
@@ -2579,40 +2573,34 @@ class SwitchStmt final : public Stmt,
   bool hasVarStorage() const { return SwitchStmtBits.HasVar; }
 
   Expr *getCond() {
-return reinterpret_cast(getTrailingObjects()[condOffset()]);
+return reinterpret_cast(getTrailingObjects()[condOffset()]);
   }
 
   const Expr *getCond() const {
-return reinterpret_cast(getTrailingObjects()[condOffset()]);
+return reinterpret_cast(getTrailingObjects()[condOffset()]);
   }
 
   void setCond(Expr *Cond) {
-getTrailingObjects()[condOffset()] = reinterpret_cast(Cond);
+getTrailingObjects()[condOffset()] = reinterpret_cast(Cond);
   }
 
-  Stmt *getBody() { return getTrailingObjects()[bodyOffset()]; }
-  const Stmt *getBody() const {
-return getTrailingObjects()[bodyOffset()];
-  }
+  Stmt *getBody() { return getTrailingObjects()[bodyOffset()]; }
+  const Stmt *getBody() const { return getTrailingObjects()[bodyOffset()]; }
 
-  void setBody(Stmt *Body) {
-getTrailingObjects()[bodyOffset()] = Body;
-  }
+  void setBody(Stmt *Body) { getTrailingObjects()[bodyOffset()] = Body; }
 
   Stmt *getInit() {
-return hasInitStorage() ? getTrailingObjects()[initOffset()]
-: nullptr;
+return hasInitStorage() ? getTrailingObjects()[initOffset()] : nullptr;
   }
 
   const Stmt *getInit() const {
-return hasInitStorage() ? getTrailingObjects()[initOffset()]
-: nullptr;
+return hasInitStorage() ? getTrailingObjects()[initOffset()] : nullptr;
   }
 
   void setInit(Stmt *Init) {
 assert(hasInitStorage() &&
"This switch statement has no storage for an init statement!");
-getTrailingObjects()[initOffset()] = Init;
+getTrailingObjects()[initOffset()] = Init;
   }
 
   /// Retrieve the variable declared in this "switch" statement, if any.
@@ -2636,20 +2624,20 @@ class SwitchStmt final : public Stmt,
   /// If this SwitchStmt has a condition variable, return the faux DeclStmt
   /// associated with the creation of that condition variable.
   DeclStmt *getConditionVariableDeclStmt() {
-return hasVarStorage() ? static_cast(
- getTrailingObjects()[varOffset()])
-   : nullptr;
+return hasVarStorage()
+   ? static_cast(getTrailingObjects()[varOffset()])
+   : nullptr;
   }
 
   const DeclStmt *getConditionVariableDeclStmt() const {
-return hasVarStorage() ? static_cast(
- getTrailingObjects()[varOffset()])
-   : nullptr;
+return hasVarStorage()
+   ? static_cast(getTrailingObjects()[varOffset()])
+   : nullptr;
   }
 
   void setConditionVariableDeclStmt(DeclStmt *CondVar) {
 assert(hasVarStorage());
-getTrailingObjects()[varOffset()] = CondVar;
+getTrailingObjects()[varOffset()] = CondVar;
   }
 
   SwitchCase *getSwitchCaseList() { return FirstCase; }
@@ -2693,15 +2681,13 @@ class SwitchStmt final : public Stmt,
 
   // Iterators
   child_range children() {
-return child_range(getTrailingObjects(),
-   getTrailingObjects() +
-   numTrailingObjects(OverloadToken()));
+return child_range(getTrailingObjects(),
+   getTrailingObjects(

[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in StmtCXX (PR #143251)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rahul Joshi (jurahul)


Changes



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


1 Files Affected:

- (modified) clang/include/clang/AST/StmtCXX.h (+4-4) 


``diff
diff --git a/clang/include/clang/AST/StmtCXX.h 
b/clang/include/clang/AST/StmtCXX.h
index a15a445fbea40..5d68d3ef64a20 100644
--- a/clang/include/clang/AST/StmtCXX.h
+++ b/clang/include/clang/AST/StmtCXX.h
@@ -80,8 +80,8 @@ class CXXTryStmt final : public Stmt,
   CXXTryStmt(EmptyShell Empty, unsigned numHandlers)
 : Stmt(CXXTryStmtClass), NumHandlers(numHandlers) { }
 
-  Stmt *const *getStmts() const { return getTrailingObjects(); }
-  Stmt **getStmts() { return getTrailingObjects(); }
+  Stmt *const *getStmts() const { return getTrailingObjects(); }
+  Stmt **getStmts() { return getTrailingObjects(); }
 
 public:
   static CXXTryStmt *Create(const ASTContext &C, SourceLocation tryLoc,
@@ -339,9 +339,9 @@ class CoroutineBodyStmt final
   friend class ASTReader;
   friend TrailingObjects;
 
-  Stmt **getStoredStmts() { return getTrailingObjects(); }
+  Stmt **getStoredStmts() { return getTrailingObjects(); }
 
-  Stmt *const *getStoredStmts() const { return getTrailingObjects(); }
+  Stmt *const *getStoredStmts() const { return getTrailingObjects(); }
 
 public:
 

``




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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in ExprConcepts (PR #143252)

2025-06-07 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in ExprConcepts (PR #143252)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rahul Joshi (jurahul)


Changes



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


1 Files Affected:

- (modified) clang/include/clang/AST/ExprConcepts.h (+2-6) 


``diff
diff --git a/clang/include/clang/AST/ExprConcepts.h 
b/clang/include/clang/AST/ExprConcepts.h
index f988d40cf73c3..8df5cdcaa9d75 100644
--- a/clang/include/clang/AST/ExprConcepts.h
+++ b/clang/include/clang/AST/ExprConcepts.h
@@ -514,10 +514,6 @@ class RequiresExpr final : public Expr,
 return NumLocalParameters;
   }
 
-  unsigned numTrailingObjects(OverloadToken) const {
-return NumRequirements;
-  }
-
   RequiresExpr(ASTContext &C, SourceLocation RequiresKWLoc,
RequiresExprBodyDecl *Body, SourceLocation LParenLoc,
ArrayRef LocalParameters,
@@ -540,13 +536,13 @@ class RequiresExpr final : public Expr,
  unsigned NumRequirements);
 
   ArrayRef getLocalParameters() const {
-return {getTrailingObjects(), NumLocalParameters};
+return getTrailingObjects(NumLocalParameters);
   }
 
   RequiresExprBodyDecl *getBody() const { return Body; }
 
   ArrayRef getRequirements() const {
-return {getTrailingObjects(), NumRequirements};
+return getTrailingObjects(NumRequirements);
   }
 
   /// \brief Whether or not the requires clause is satisfied.

``




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


[clang] [clang-format] Add options to control wrapped lambda brace indent. (PR #143249)

2025-06-07 Thread via cfe-commits


@@ -1547,6 +1547,38 @@ struct FormatStyle {
 bool BeforeWhile;
 /// Indent the wrapped braces themselves.
 bool IndentBraces;
+/// Indent nested wrapped lambda braces.

rmarker wrote:

Maybe `IndentBracesLambdaScoped` could work? Or `IndentBracesLambdaInner`? 
Could be paired with `IndentBracesLambdaOuter`.

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in ExprObjC (PR #143254)

2025-06-07 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in ParsedTemplate (PR #143255)

2025-06-07 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in ExprObjC (PR #143254)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rahul Joshi (jurahul)


Changes



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


1 Files Affected:

- (modified) clang/include/clang/AST/ExprObjC.h (+2-4) 


``diff
diff --git a/clang/include/clang/AST/ExprObjC.h 
b/clang/include/clang/AST/ExprObjC.h
index f87fa85569c44..3d9b3c4585e8a 100644
--- a/clang/include/clang/AST/ExprObjC.h
+++ b/clang/include/clang/AST/ExprObjC.h
@@ -217,12 +217,10 @@ class ObjCArrayLiteral final
   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
 
   /// Retrieve elements of array of literals.
-  Expr **getElements() { return getTrailingObjects(); }
+  Expr **getElements() { return getTrailingObjects(); }
 
   /// Retrieve elements of array of literals.
-  const Expr * const *getElements() const {
-return getTrailingObjects();
-  }
+  const Expr *const *getElements() const { return getTrailingObjects(); }
 
   /// getNumElements - Return number of elements of objective-c array literal.
   unsigned getNumElements() const { return NumElements; }

``




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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in TemplateBase (PR #143257)

2025-06-07 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in ParsedTemplate (PR #143255)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rahul Joshi (jurahul)


Changes



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


2 Files Affected:

- (modified) clang/include/clang/Sema/ParsedAttr.h (-3) 
- (modified) clang/include/clang/Sema/ParsedTemplate.h (+1-3) 


``diff
diff --git a/clang/include/clang/Sema/ParsedAttr.h 
b/clang/include/clang/Sema/ParsedAttr.h
index 428d3111de80d..9e050ab9a620e 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -130,9 +130,6 @@ class ParsedAttr final
   size_t numTrailingObjects(OverloadToken) const {
 return HasParsedType;
   }
-  size_t numTrailingObjects(OverloadToken) const {
-return IsProperty;
-  }
 
 private:
   IdentifierInfo *MacroII = nullptr;
diff --git a/clang/include/clang/Sema/ParsedTemplate.h 
b/clang/include/clang/Sema/ParsedTemplate.h
index cff7f04666358..3a8050f9a0a3d 100644
--- a/clang/include/clang/Sema/ParsedTemplate.h
+++ b/clang/include/clang/Sema/ParsedTemplate.h
@@ -190,9 +190,7 @@ namespace clang {
 bool ArgsInvalid;
 
 /// Retrieves a pointer to the template arguments
-ParsedTemplateArgument *getTemplateArgs() {
-  return getTrailingObjects();
-}
+ParsedTemplateArgument *getTemplateArgs() { return getTrailingObjects(); }
 
 /// Creates a new TemplateIdAnnotation with NumArgs arguments and
 /// appends it to List.

``




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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in AST/Type (PR #143258)

2025-06-07 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in StmtObjC (PR #143256)

2025-06-07 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in TemplateBase (PR #143257)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rahul Joshi (jurahul)


Changes



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


2 Files Affected:

- (modified) clang/include/clang/AST/TemplateBase.h (+1-1) 
- (modified) clang/lib/AST/TemplateBase.cpp (+2-2) 


``diff
diff --git a/clang/include/clang/AST/TemplateBase.h 
b/clang/include/clang/AST/TemplateBase.h
index 279feb858e665..84a342ec053a1 100644
--- a/clang/include/clang/AST/TemplateBase.h
+++ b/clang/include/clang/AST/TemplateBase.h
@@ -704,7 +704,7 @@ struct ASTTemplateArgumentListInfo final
 
   /// Retrieve the template arguments
   const TemplateArgumentLoc *getTemplateArgs() const {
-return getTrailingObjects();
+return getTrailingObjects();
   }
   unsigned getNumTemplateArgs() const { return NumTemplateArgs; }
 
diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 8ecd3c7aaca0d..7c89dea4629cc 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -726,7 +726,7 @@ ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
   RAngleLoc = Info.getRAngleLoc();
   NumTemplateArgs = Info.size();
 
-  TemplateArgumentLoc *ArgBuffer = getTrailingObjects();
+  TemplateArgumentLoc *ArgBuffer = getTrailingObjects();
   for (unsigned i = 0; i != NumTemplateArgs; ++i)
 new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]);
 }
@@ -737,7 +737,7 @@ ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
   RAngleLoc = Info->getRAngleLoc();
   NumTemplateArgs = Info->getNumTemplateArgs();
 
-  TemplateArgumentLoc *ArgBuffer = getTrailingObjects();
+  TemplateArgumentLoc *ArgBuffer = getTrailingObjects();
   for (unsigned i = 0; i != NumTemplateArgs; ++i)
 new (&ArgBuffer[i]) TemplateArgumentLoc((*Info)[i]);
 }

``




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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in AST/Type (PR #143258)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rahul Joshi (jurahul)


Changes



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


2 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+10-19) 
- (modified) clang/lib/AST/Type.cpp (+6-7) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a6c26a07800c3..7fff819cba25d 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -5352,10 +5352,6 @@ class FunctionProtoType final
 return getNumFunctionEffects();
   }
 
-  unsigned numTrailingObjects(OverloadToken) const {
-return getNumFunctionEffectConditions();
-  }
-
   /// Determine whether there are any argument types that
   /// contain an unexpanded parameter pack.
   static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
@@ -5686,8 +5682,8 @@ class FunctionProtoType final
 if (hasExtraBitfields()) {
   const auto *Bitfields = getTrailingObjects();
   if (Bitfields->NumFunctionEffects > 0)
-return {getTrailingObjects(),
-Bitfields->NumFunctionEffects};
+return getTrailingObjects(
+Bitfields->NumFunctionEffects);
 }
 return {};
   }
@@ -5706,8 +5702,8 @@ class FunctionProtoType final
 if (hasExtraBitfields()) {
   const auto *Bitfields = getTrailingObjects();
   if (Bitfields->EffectsHaveConditions)
-return {getTrailingObjects(),
-Bitfields->NumFunctionEffects};
+return getTrailingObjects(
+Bitfields->NumFunctionEffects);
 }
 return {};
   }
@@ -5721,8 +5717,7 @@ class FunctionProtoType final
 ? Bitfields->NumFunctionEffects
 : 0;
 return FunctionEffectsRef(
-{getTrailingObjects(),
- Bitfields->NumFunctionEffects},
+getTrailingObjects(Bitfields->NumFunctionEffects),
 {NumConds ? getTrailingObjects() : nullptr,
  NumConds});
   }
@@ -6063,8 +6058,6 @@ class PackIndexingType final
 
   static TypeDependence computeDependence(QualType Pattern, Expr *IndexExpr,
   ArrayRef Expansions = {});
-
-  unsigned numTrailingObjects(OverloadToken) const { return Size; }
 };
 
 /// A unary type transform, which is a type constructed from another.
@@ -6491,8 +6484,7 @@ class HLSLInlineSpirvType final
 for (size_t I = 0; I < NumOperands; I++) {
   // Since Operands are stored as a trailing object, they have not been
   // initialized yet. Call the constructor manually.
-  auto *Operand =
-  new (&getTrailingObjects()[I]) SpirvOperand();
+  auto *Operand = new (&getTrailingObjects()[I]) SpirvOperand();
   *Operand = Operands[I];
 }
   }
@@ -6502,7 +6494,7 @@ class HLSLInlineSpirvType final
   uint32_t getSize() const { return Size; }
   uint32_t getAlignment() const { return Alignment; }
   ArrayRef getOperands() const {
-return {getTrailingObjects(), NumOperands};
+return getTrailingObjects(NumOperands);
   }
 
   bool isSugared() const { return false; }
@@ -6602,7 +6594,7 @@ class SubstTemplateTypeParmType final
   /// parameter.
   QualType getReplacementType() const {
 return SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType
-   ? *getTrailingObjects()
+   ? *getTrailingObjects()
: getCanonicalTypeInternal();
   }
 
@@ -7164,7 +7156,7 @@ class ElaboratedType final
 ElaboratedTypeBits.HasOwnedTagDecl = false;
 if (OwnedTagDecl) {
   ElaboratedTypeBits.HasOwnedTagDecl = true;
-  *getTrailingObjects() = OwnedTagDecl;
+  *getTrailingObjects() = OwnedTagDecl;
 }
   }
 
@@ -7184,8 +7176,7 @@ class ElaboratedType final
   /// Return the (re)declaration of this type owned by this occurrence of this
   /// type, or nullptr if there is none.
   TagDecl *getOwnedTagDecl() const {
-return ElaboratedTypeBits.HasOwnedTagDecl ? *getTrailingObjects()
-  : nullptr;
+return ElaboratedTypeBits.HasOwnedTagDecl ? *getTrailingObjects() : 
nullptr;
   }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 5bb39b12693fb..800cd2a91ec26 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -4019,12 +4019,11 @@ TypedefType::TypedefType(TypeClass tc, const 
TypedefNameDecl *D,
   assert(!isa(can) && "Invalid canonical type");
   TypedefBits.hasTypeDifferentFromDecl = !Underlying.isNull();
   if (!typeMatchesDecl())
-*getTrailingObjects() = Underlying;
+*getTrailingObjects() = Underlying;
 }
 
 QualType TypedefType::desugar() const {
-  return typeMatchesDecl() ? Decl->getUnderlyingType()
-   : *getTrailingObjects();
+  return typeMatchesDecl() ? Decl->getUnderlyingType() : *getTrailingObjects();
 }
 
 UsingType::UsingType(const

[clang] [NFC][Clang] Adopt simpified `getTrailingObjects` in CIRGenFunctionInfo (PR #143253)

2025-06-07 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Adopt simpified `getTrailingObjects` in CIRGenFunctionInfo (PR #143253)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Rahul Joshi (jurahul)


Changes



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


1 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h (+2-4) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h 
b/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
index 9886574fd463b..4f5754cb43986 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
@@ -76,10 +76,8 @@ class CIRGenFunctionInfo final
 
   unsigned numArgs;
 
-  CanQualType *getArgTypes() { return getTrailingObjects(); }
-  const CanQualType *getArgTypes() const {
-return getTrailingObjects();
-  }
+  CanQualType *getArgTypes() { return getTrailingObjects(); }
+  const CanQualType *getArgTypes() const { return getTrailingObjects(); }
 
   CIRGenFunctionInfo() : required(RequiredArgs::All) {}
 

``




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


[clang] [NFC][Clang] Adopt simpified `getTrailingObjects` in CIRGenFunctionInfo (PR #143253)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rahul Joshi (jurahul)


Changes



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


1 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h (+2-4) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h 
b/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
index 9886574fd463b..4f5754cb43986 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
@@ -76,10 +76,8 @@ class CIRGenFunctionInfo final
 
   unsigned numArgs;
 
-  CanQualType *getArgTypes() { return getTrailingObjects(); }
-  const CanQualType *getArgTypes() const {
-return getTrailingObjects();
-  }
+  CanQualType *getArgTypes() { return getTrailingObjects(); }
+  const CanQualType *getArgTypes() const { return getTrailingObjects(); }
 
   CIRGenFunctionInfo() : required(RequiredArgs::All) {}
 

``




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


[clang] [NFC][Clang] Adopt simpified `getTrailingObjects` in CIRGenFunctionInfo (PR #143253)

2025-06-07 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Adopt simplified `getTrailingObjects` in StmtObjC (PR #143256)

2025-06-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rahul Joshi (jurahul)


Changes



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


1 Files Affected:

- (modified) clang/include/clang/AST/StmtObjC.h (+5-5) 


``diff
diff --git a/clang/include/clang/AST/StmtObjC.h 
b/clang/include/clang/AST/StmtObjC.h
index 03bc61f54cdf5..af95d65fa2a3c 100644
--- a/clang/include/clang/AST/StmtObjC.h
+++ b/clang/include/clang/AST/StmtObjC.h
@@ -166,7 +166,8 @@ class ObjCAtTryStmt final
 : public Stmt,
   private llvm::TrailingObjects {
   friend TrailingObjects;
-  size_t numTrailingObjects(OverloadToken) const {
+
+  size_t numTrailingStatements() const {
 return 1 + NumCatchStmts + HasFinally;
   }
 
@@ -185,8 +186,8 @@ class ObjCAtTryStmt final
   /// The order of the statements in memory follows the order in the source,
   /// with the \@try body first, followed by the \@catch statements (if any)
   /// and, finally, the \@finally (if it exists).
-  Stmt **getStmts() { return getTrailingObjects(); }
-  Stmt *const *getStmts() const { return getTrailingObjects(); }
+  Stmt **getStmts() { return getTrailingObjects(); }
+  Stmt *const *getStmts() const { return getTrailingObjects(); }
 
   ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
 Stmt **CatchStmts, unsigned NumCatchStmts,
@@ -262,8 +263,7 @@ class ObjCAtTryStmt final
   }
 
   child_range children() {
-return child_range(
-getStmts(), getStmts() + numTrailingObjects(OverloadToken()));
+return child_range(getStmts(), getStmts() + numTrailingStatements());
   }
 
   const_child_range children() const {

``




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


  1   2   3   >