[clang] [clang-format] Add BreakBinaryOperations configuration (PR #95013)

2024-08-10 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

Nah, I can't find a better name, which isn't a whole sentence.

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


[clang] 9a227ba - [clang][Interp] Start implementing unions and changing the active member (#102723)

2024-08-10 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-10T09:09:12+02:00
New Revision: 9a227ba3e129eaa89498b97421afefb1e9d681df

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

LOG: [clang][Interp] Start implementing unions and changing the active member 
(#102723)

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/Descriptor.h
clang/lib/AST/Interp/Disasm.cpp
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpBlock.h
clang/lib/AST/Interp/Pointer.cpp
clang/lib/AST/Interp/Pointer.h
clang/test/AST/Interp/unions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 11fe2acf2d7b95..0d72e33c1c7d25 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -4739,7 +4739,8 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
   // Classify the return type.
   ReturnType = this->classify(F->getReturnType());
 
-  auto emitFieldInitializer = [&](const Record::Field *F, unsigned FieldOffset,
+  auto emitFieldInitializer = [&](const Record *R, const Record::Field *F,
+  unsigned FieldOffset,
   const Expr *InitExpr) -> bool {
 // We don't know what to do with these, so just return false.
 if (InitExpr->getType().isNull())
@@ -4751,6 +4752,8 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
 
   if (F->isBitField())
 return this->emitInitThisBitField(*T, F, FieldOffset, InitExpr);
+  if (R->isUnion())
+return this->emitInitThisFieldActive(*T, FieldOffset, InitExpr);
   return this->emitInitThisField(*T, FieldOffset, InitExpr);
 }
 // Non-primitive case. Get a pointer to the field-to-initialize
@@ -4762,7 +4765,7 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
 if (!this->visitInitializer(InitExpr))
   return false;
 
-return this->emitPopPtr(InitExpr);
+return this->emitFinishInitPop(InitExpr);
   };
 
   // Emit custom code if this is a lambda static invoker.
@@ -4786,7 +4789,7 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
   if (const FieldDecl *Member = Init->getMember()) {
 const Record::Field *F = R->getField(Member);
 
-if (!emitFieldInitializer(F, F->Offset, InitExpr))
+if (!emitFieldInitializer(R, F, F->Offset, InitExpr))
   return false;
   } else if (const Type *Base = Init->getBaseClass()) {
 const auto *BaseDecl = Base->getAsCXXRecordDecl();
@@ -4814,11 +4817,11 @@ bool Compiler::visitFunc(const FunctionDecl 
*F) {
 assert(IFD->getChainingSize() >= 2);
 
 unsigned NestedFieldOffset = 0;
+const Record *FieldRecord = nullptr;
 const Record::Field *NestedField = nullptr;
 for (const NamedDecl *ND : IFD->chain()) {
   const auto *FD = cast(ND);
-  const Record *FieldRecord =
-  this->P.getOrCreateRecord(FD->getParent());
+  FieldRecord = this->P.getOrCreateRecord(FD->getParent());
   assert(FieldRecord);
 
   NestedField = FieldRecord->getField(FD);
@@ -4828,7 +4831,8 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
 }
 assert(NestedField);
 
-if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr))
+if (!emitFieldInitializer(FieldRecord, NestedField, NestedFieldOffset,
+  InitExpr))
   return false;
   } else {
 assert(Init->isDelegatingInitializer());

diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index 23dd08ca486275..634413b2f2f52a 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -20,7 +20,7 @@ using namespace clang;
 using namespace clang::interp;
 
 template 
-static void ctorTy(Block *, std::byte *Ptr, bool, bool, bool,
+static void ctorTy(Block *, std::byte *Ptr, bool, bool, bool, bool,
const Descriptor *) {
   new (Ptr) T();
 }
@@ -40,7 +40,7 @@ static void moveTy(Block *, const std::byte *Src, std::byte 
*Dst,
 }
 
 template 
-static void ctorArrayTy(Block *, std::byte *Ptr, bool, bool, bool,
+static void ctorArrayTy(Block *, std::byte *Ptr, bool, bool, bool, bool,
 const Descriptor *D) {
   new (Ptr) InitMapPtr(std::nullopt);
 
@@ -83,7 +83,8 @@ static void moveArrayTy(Block *, const std::byte *Src, 
std::byte *Dst,
 }
 
 static void ctorArrayDesc(Block *B, std::byte *Ptr, bool IsConst,
-  bool IsMutable, bool IsActive, const Descriptor *D) {
+  bool IsMutable, bool IsActive, bool InUnion,
+  const De

[clang] [clang][Interp] Start implementing unions and changing the active member (PR #102723)

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

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


[clang] [X86_64] Fix empty field error in vaarg of C++. (PR #101639)

2024-08-10 Thread Longsheng Mou via cfe-commits

https://github.com/CoTinker updated 
https://github.com/llvm/llvm-project/pull/101639

>From 328ae6052894eb45c4e7541dadf63a3a04540cda Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 2 Aug 2024 16:36:31 +0800
Subject: [PATCH 1/2] [X86_64] Fix empty field error in vaarg of C++.

Such struct types:
```
struct {
  struct{} a;
  long long b;
};

stuct {
  struct{} a;
  double b;
};
```
For such structures, Lo is NoClass and Hi is Integer/SSE. And when
this structure argument is passed, the high part is passed at
offset 8 in memory. So we should do special handling for these types
in EmitVAArg.
---
 clang/lib/CodeGen/Targets/X86.cpp  |  38 +++--
 clang/test/CodeGenCXX/x86_64-vaarg.cpp | 211 -
 2 files changed, 231 insertions(+), 18 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 26ff4e4ac0a3b5..0347bd01f82ef3 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -3124,26 +3124,40 @@ RValue X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
 CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
 
 RegAddr = Tmp.withElementType(LTy);
-  } else if (neededInt) {
-RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, 
gp_offset),
-  LTy, CharUnits::fromQuantity(8));
-
+  } else if (neededInt || neededSSE == 1) {
 // Copy to a temporary if necessary to ensure the appropriate alignment.
 auto TInfo = getContext().getTypeInfoInChars(Ty);
 uint64_t TySize = TInfo.Width.getQuantity();
 CharUnits TyAlign = TInfo.Align;
 
-// Copy into a temporary if the type is more aligned than the
-// register save area.
-if (TyAlign.getQuantity() > 8) {
+llvm::Value *GpOrFpOffset = neededInt ? gp_offset : fp_offset;
+uint64_t Alignment = neededInt ? 8 : 16;
+if (auto Offset = AI.getDirectOffset()) {
   Address Tmp = CGF.CreateMemTemp(Ty);
-  CGF.Builder.CreateMemCpy(Tmp, RegAddr, TySize, false);
-  RegAddr = Tmp;
+  llvm::Type *TyHi = AI.getCoerceToType();
+  llvm::Value *Addr =
+  CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, GpOrFpOffset);
+  llvm::Value *Src = CGF.Builder.CreateAlignedLoad(TyHi, Addr, TyAlign);
+  llvm::Value *PtrOffset = llvm::ConstantInt::get(CGF.Int32Ty, Offset);
+  Address Dst = Address(
+  CGF.Builder.CreateGEP(CGF.Int8Ty, Tmp.getBasePointer(), PtrOffset),
+  LTy, TyAlign);
+  CGF.Builder.CreateStore(Src, Dst);
+  RegAddr = Tmp.withElementType(LTy);
+} else {
+  RegAddr =
+  Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, GpOrFpOffset),
+  LTy, CharUnits::fromQuantity(Alignment));
+
+  // Copy into a temporary if the type is more aligned than the
+  // register save area.
+  if (neededInt && TyAlign.getQuantity() > 8) {
+Address Tmp = CGF.CreateMemTemp(Ty);
+CGF.Builder.CreateMemCpy(Tmp, RegAddr, TySize, false);
+RegAddr = Tmp;
+  }
 }
 
-  } else if (neededSSE == 1) {
-RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, 
fp_offset),
-  LTy, CharUnits::fromQuantity(16));
   } else {
 assert(neededSSE == 2 && "Invalid number of needed registers!");
 // SSE registers are spaced 16 bytes apart in the register save
diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
index c4616a97e20555..1703b74ad10a2f 100644
--- a/clang/test/CodeGenCXX/x86_64-vaarg.cpp
+++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
@@ -29,6 +29,7 @@ typedef struct {
 // CHECK-NEXT:[[RETVAL:%.*]] = alloca [[STRUCT_S1:%.*]], align 8
 // CHECK-NEXT:[[Z_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:[[LIST:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:[[TMP:%.*]] = alloca [[STRUCT_S1]], align 8
 // CHECK-NEXT:store i32 [[Z:%.*]], ptr [[Z_ADDR]], align 4
 // CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x 
%struct.__va_list_tag], ptr [[LIST]], i64 0, i64 0
 // CHECK-NEXT:call void @llvm.va_start.p0(ptr [[ARRAYDECAY]])
@@ -41,8 +42,11 @@ typedef struct {
 // CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds 
[[STRUCT___VA_LIST_TAG]], ptr [[ARRAYDECAY1]], i32 0, i32 3
 // CHECK-NEXT:[[REG_SAVE_AREA:%.*]] = load ptr, ptr [[TMP0]], align 16
 // CHECK-NEXT:[[TMP1:%.*]] = getelementptr i8, ptr [[REG_SAVE_AREA]], i32 
[[FP_OFFSET]]
-// CHECK-NEXT:[[TMP2:%.*]] = add i32 [[FP_OFFSET]], 16
-// CHECK-NEXT:store i32 [[TMP2]], ptr [[FP_OFFSET_P]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = load double, ptr [[TMP1]], align 8
+// CHECK-NEXT:[[TMP3:%.*]] = getelementptr i8, ptr [[TMP]], i32 8
+// CHECK-NEXT:store double [[TMP2]], ptr [[TMP3]], align 8
+// CHECK-NEXT:[[TMP4:%.*]] = add i32 [[FP_OFFSET]], 16
+// CHECK-NEXT:store i32 [[TMP4]], ptr [[FP_OFFSET_P]], align 4
 // CHECK-NEXT:br label [[VAARG_END:

[clang] Improve instructions in Clang Format Vim Integration Document (PR #102730)

2024-08-10 Thread via cfe-commits

https://github.com/cuppajoeman created 
https://github.com/llvm/llvm-project/pull/102730

added a link to where you can download the file.

>From b42951aac97b2660bcadb1028e623f9e70981cde Mon Sep 17 00:00:00 2001
From: cuppajoeman 
Date: Sat, 10 Aug 2024 03:25:15 -0400
Subject: [PATCH] update to show where you can actually get the mentioned file

---
 clang/docs/ClangFormat.rst | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index dbd9c91ae508e5..e30dea3568fcf3 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -164,7 +164,8 @@ Vim Integration
 There is an integration for :program:`vim` which lets you run the
 :program:`clang-format` standalone tool on your current buffer, optionally
 selecting regions to reformat. The integration has the form of a `python`-file
-which can be found under `clang/tools/clang-format/clang-format.py`.
+which can be found under `clang/tools/clang-format/clang-format.py 
+`_.
 
 This can be integrated by adding the following to your `.vimrc`:
 

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


[clang] Improve instructions in Clang Format Vim Integration Document (PR #102730)

2024-08-10 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] Improve instructions in Clang Format Vim Integration Document (PR #102730)

2024-08-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: ccn (cuppajoeman)


Changes

added a link to where you can download the file.

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


1 Files Affected:

- (modified) clang/docs/ClangFormat.rst (+2-1) 


``diff
diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index dbd9c91ae508e5..e30dea3568fcf3 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -164,7 +164,8 @@ Vim Integration
 There is an integration for :program:`vim` which lets you run the
 :program:`clang-format` standalone tool on your current buffer, optionally
 selecting regions to reformat. The integration has the form of a `python`-file
-which can be found under `clang/tools/clang-format/clang-format.py`.
+which can be found under `clang/tools/clang-format/clang-format.py 
+`_.
 
 This can be integrated by adding the following to your `.vimrc`:
 

``




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


[clang] [clang][Interp] Start implementing unions and changing the active member (PR #102723)

2024-08-10 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-windows` running 
on `sanitizer-windows` while building `clang` at step 4 "annotate".

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

Here is the relevant piece of the build log for the reference:
```
Step 4 (annotate) failure: 'python 
../llvm-zorg/zorg/buildbot/builders/annotated/sanitizer-windows.py ...' 
(failure)
...
[27/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Program.cpp.obj
[28/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Function.cpp.obj
[29/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\State.cpp.obj
[30/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\MemberPointer.cpp.obj
[31/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpFrame.cpp.obj
[32/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\EvaluationResult.cpp.obj
[33/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ExprConstant.cpp.obj
[34/39] Linking CXX executable bin\lld.exe
[35/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ASTContext.cpp.obj
[36/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Disasm.cpp.obj
command timed out: 1200 seconds without output running ['python', 
'../llvm-zorg/zorg/buildbot/builders/annotated/sanitizer-windows.py', 
'--jobs=16'], attempting to kill
program finished with exit code 1
elapsedTime=1286.09
Step 7 (stage 1 build) failure: stage 1 build (failure)
@@@BUILD_STEP stage 1 build@@@
Running: ninja -j 16 compiler-rt
[1/2] Building CXX object 
projects\compiler-rt\lib\asan\CMakeFiles\RTAsan_dynamic_version_script_dummy.x86_64.dir\dummy.cpp.obj
[2/2] Linking CXX shared library 
lib\clang\20\lib\windows\clang_rt.asan_dynamic-x86_64.dll
Running: ninja -j 16 clang lld
[1/39] Generating VCSRevision.h
[2/39] Generating VCSVersion.inc
[3/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\PrimType.cpp.obj
[4/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpStack.cpp.obj
[5/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Descriptor.cpp.obj
[6/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpState.cpp.obj
[7/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\DynamicAllocator.cpp.obj
[8/39] Building CXX object 
tools\clang\lib\Basic\CMakeFiles\obj.clangBasic.dir\Version.cpp.obj
[9/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\ByteCodeEmitter.cpp.obj
[10/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Pointer.cpp.obj
[11/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Context.cpp.obj
[12/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpBuiltin.cpp.obj
[13/39] Building CXX object 
lib\Object\CMakeFiles\LLVMObject.dir\IRSymtab.cpp.obj
[14/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Compiler.cpp.obj
[15/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\EvalEmitter.cpp.obj
[16/39] Linking CXX static library lib\LLVMObject.lib
[17/39] Linking CXX static library lib\clangBasic.lib
[18/39] Generating VCSVersion.inc
[19/39] Building CXX object 
lib\CodeGen\AsmPrinter\CMakeFiles\LLVMAsmPrinter.dir\AsmPrinter.cpp.obj
[20/39] Building CXX object 
tools\lld\Common\CMakeFiles\lldCommon.dir\Version.cpp.obj
[21/39] Linking CXX static library lib\lldCommon.lib
[22/39] Linking CXX static library lib\LLVMAsmPrinter.lib
[23/39] Building CXX object lib\LTO\CMakeFiles\LLVMLTO.dir\LTO.cpp.obj
[24/39] Linking CXX static library lib\LLVMLTO.lib
[25/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpBlock.cpp.obj
[26/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Record.cpp.obj
[27/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Program.cpp.obj
[28/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\Function.cpp.obj
[29/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\State.cpp.obj
[30/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\MemberPointer.cpp.obj
[31/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\InterpFrame.cpp.obj
[32/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Interp\EvaluationResult.cpp.obj
[33/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ExprConstant.cpp.obj
[34/39] Linking CXX executable bin\lld.exe
[35/39] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ASTContext.cpp.ob

[clang] [Clang][Concepts] Fix a constraint comparison regression for out-of-line ClassTemplateDecls (PR #102587)

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


@@ -599,3 +599,39 @@ template 
 unsigned long DerivedCollection::index() {}
 
 } // namespace GH72557
+
+namespace GH102320 {
+
+template 
+concept Constrained = true;
+
+template  class C {
+  template > class D;
+  template 
+requires Constrained
+  class E;
+};
+
+template  template > class C::D {};
+
+template 
+template 
+  requires Constrained
+class C::E {};
+
+#if 0
+// FIXME: Is it conforming? Only Clang rejects it in every released version.
+template <>
+template  T>
+class C::D {};
+#endif
+

zyn0217 wrote:

Actually there seems to be a slight discrepancy among the four compilers here:
https://gcc.godbolt.org/z/nxPoeGE5b
w/o constraints, MSVC and Clang reject such a pattern, while GCC and EDG accept 
it.
w/ constraints, only Clang complains. So I'm unclear about what is supposed to 
happen here.
@cor3ntin do you have any ideas?

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


[clang] [llvm] Add normalize builtins and normalize HLSL function to DirectX and SPIR-V backend (PR #102683)

2024-08-10 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/102683

>From 547b4da91b20811db156a8c73fcb2f381cfed7bd Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 9 Aug 2024 10:48:10 -0700
Subject: [PATCH 1/8] suboptimal expansion of normalize done

---
 clang/include/clang/Basic/Builtins.td |   6 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  23 
 clang/lib/CodeGen/CGHLSLRuntime.h |   1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  32 +
 clang/lib/Sema/SemaHLSL.cpp   |  12 ++
 .../test/CodeGenHLSL/builtins/normalize.hlsl  |  73 +++
 .../SemaHLSL/BuiltIns/normalize-errors.hlsl   |  31 +
 llvm/include/llvm/IR/IntrinsicsDirectX.td |   1 +
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |   1 +
 .../Target/DirectX/DXILIntrinsicExpansion.cpp |  51 
 llvm/test/CodeGen/DirectX/normalize.ll| 116 ++
 llvm/test/CodeGen/DirectX/normalize_error.ll  |  10 ++
 12 files changed, 357 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/normalize.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/normalize-errors.hlsl
 create mode 100644 llvm/test/CodeGen/DirectX/normalize.ll
 create mode 100644 llvm/test/CodeGen/DirectX/normalize_error.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index b025a7681bfac3..0a874d8638df43 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4725,6 +4725,12 @@ def HLSLMad : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLNormalize : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_normalize"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 def HLSLRcp : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_elementwise_rcp"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7fe80b0cbdfbfa..2507c858d77209 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18584,6 +18584,29 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 CGM.getHLSLRuntime().getLengthIntrinsic(), ArrayRef{X},
 nullptr, "hlsl.length");
   }
+  case Builtin::BI__builtin_hlsl_normalize: {
+Value *X = EmitScalarExpr(E->getArg(0));
+
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+   "normalize operand must have a float representation");
+
+// scalar inputs should expect a scalar return type
+if (!E->getArg(0)->getType()->isVectorType())
+  return Builder.CreateIntrinsic(
+  /*ReturnType=*/X->getType()->getScalarType(),
+  CGM.getHLSLRuntime().getNormalizeIntrinsic(), ArrayRef{X},
+  nullptr, "hlsl.normalize");
+
+// construct a vector return type for vector inputs
+auto *XVecTy = E->getArg(0)->getType()->getAs();
+llvm::Type *retType = X->getType()->getScalarType();
+retType = llvm::VectorType::get(
+retType, ElementCount::getFixed(XVecTy->getNumElements()));
+
+return Builder.CreateIntrinsic(
+/*ReturnType=*/retType, CGM.getHLSLRuntime().getNormalizeIntrinsic(),
+ArrayRef{X}, nullptr, "hlsl.normalize");
+  }
   case Builtin::BI__builtin_hlsl_elementwise_frac: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 if (!E->getArg(0)->getType()->hasFloatingRepresentation())
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 527e73a0e21fc4..80ca432f4b509c 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -77,6 +77,7 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(Normalize, normalize)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Rsqrt, rsqrt)
   GENERATE_HLSL_INTRINSIC_FUNCTION(ThreadId, thread_id)
 
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index e35a5262f92809..678cdc77f8a71b 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1352,6 +1352,38 @@ double3 min(double3, double3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_min)
 double4 min(double4, double4);
 
+//===--===//
+// normalize builtins
+//===--===//
+
+/// \fn T normalize(T x)
+/// \brief Returns the normalized unit vector of the specified floating-point
+/// vector. \param x [in] The vector of floats.
+///
+/// Normalize is based on the following formula: x / length(x).
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_normalize)
+half normalize(half);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTI

[clang] [Clang][CodeGen] Fix bad codegen when building Clang with latest MSVC (PR #102681)

2024-08-10 Thread David Chisnall via cfe-commits

davidchisnall wrote:

The new version is probably slightly more readable than mine, but I don’t 
really understand how it would affect codegen with UT C. No objections.

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


[clang] [lld] [llvm] [mlir] [NFC][IWYU] Update Support library with IWYU. (PR #102707)

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

nikic wrote:

Build fails with:
```

CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/c++ 
-DGTEST_HAS_RTTI=0 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/tmp/llvm-project-build-stage1/lib/Support 
-I/var/llvm-compile-time-tracker/llvm-project/llvm/lib/Support 
-I/tmp/llvm-project-build-stage1/include 
-I/var/llvm-compile-time-tracker/llvm-project/llvm/include -fPIC 
-fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time 
-fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings 
-Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long 
-Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess 
-Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17  -fno-exceptions 
-funwind-tables -fno-rtti -MD -MT 
lib/Support/CMakeFiles/LLVMSupport.dir/VirtualFileSystem.cpp.o -MF 
lib/Support/CMakeFiles/LLVMSupport.dir/VirtualFileSystem.cpp.o.d -o 
lib/Support/CMakeFiles/LLVMSupport.dir/VirtualFileSystem.cpp.o -c 
/var/llvm-compile-time-tracker/llvm-project/llvm/lib/Support/VirtualFileSystem.cpp
/var/llvm-compile-time-tracker/llvm-project/llvm/lib/Support/VirtualFileSystem.cpp:1257:5:
 error: qualified name does not name a class before ‘:’ token
 1257 | : public llvm::vfs::detail::DirIterImpl {
  | ^
/var/llvm-compile-time-tracker/llvm-project/llvm/lib/Support/VirtualFileSystem.cpp:1257:5:
 error: expected ‘{’ before ‘:’ token
/var/llvm-compile-time-tracker/llvm-project/llvm/lib/Support/VirtualFileSystem.cpp:1257:5:
 error: expected unqualified-id before ‘:’ token
```

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


[clang] [lld] [llvm] [mlir] [NFC][IWYU] Update Support library with IWYU. (PR #102707)

2024-08-10 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

Hi, thanks for trying to cleanup the codebase.

Can you provide more context on the motivation / what you're trying to achieve 
here? 

Did you know that LLVM intentionally does not follow IWYU and favors forward 
declarations: 
https://llvm.org/docs/CodingStandards.html#include-as-little-as-possible

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


[clang] [Clang][Concepts] Fix a constraint comparison regression for out-of-line ClassTemplateDecls (PR #102587)

2024-08-10 Thread via cfe-commits


@@ -599,3 +599,39 @@ template 
 unsigned long DerivedCollection::index() {}
 
 } // namespace GH72557
+
+namespace GH102320 {
+
+template 
+concept Constrained = true;
+
+template  class C {
+  template > class D;
+  template 
+requires Constrained
+  class E;
+};
+
+template  template > class C::D {};
+
+template 
+template 
+  requires Constrained
+class C::E {};
+
+#if 0
+// FIXME: Is it conforming? Only Clang rejects it in every released version.
+template <>
+template  T>
+class C::D {};
+#endif
+

cor3ntin wrote:

@zyn0217 I need more time to think about the concept case, but the first case 
looks definitively like a bug. The following looks related 
https://github.com/llvm/llvm-project/issues/53139

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


[clang] Improve instructions in Clang Format Vim Integration Document (PR #102730)

2024-08-10 Thread via cfe-commits

https://github.com/cuppajoeman updated 
https://github.com/llvm/llvm-project/pull/102730

>From b42951aac97b2660bcadb1028e623f9e70981cde Mon Sep 17 00:00:00 2001
From: cuppajoeman 
Date: Sat, 10 Aug 2024 03:25:15 -0400
Subject: [PATCH 1/2] update to show where you can actually get the mentioned
 file

---
 clang/docs/ClangFormat.rst | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index dbd9c91ae508e5..e30dea3568fcf3 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -164,7 +164,8 @@ Vim Integration
 There is an integration for :program:`vim` which lets you run the
 :program:`clang-format` standalone tool on your current buffer, optionally
 selecting regions to reformat. The integration has the form of a `python`-file
-which can be found under `clang/tools/clang-format/clang-format.py`.
+which can be found under `clang/tools/clang-format/clang-format.py 
+`_.
 
 This can be integrated by adding the following to your `.vimrc`:
 

>From ad13f76f0c2a5e22fddcde2b60644a74bfbd5ff0 Mon Sep 17 00:00:00 2001
From: cuppajoeman 
Date: Sat, 10 Aug 2024 04:47:17 -0400
Subject: [PATCH 2/2] add python version checks

---
 clang/docs/ClangFormat.rst | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index e30dea3568fcf3..c6eac07acbba67 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -199,7 +199,11 @@ your `.vimrc`:
 
   function! Formatonsave()
 let l:formatdiff = 1
-pyf /clang-format.py
+if has('python')
+  pyf /clang-format.py
+elseif has('python3')
+  py3f /clang-format.py
+endif
   endfunction
   autocmd BufWritePre *.h,*.cc,*.cpp call Formatonsave()
 

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


[clang] [clang][Interp] Improve "in call to" call argument printing (PR #102735)

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

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

Always go through toAPValue() first and pretty-print that. In the future, I 
think we could get rid of the individual toDiagnosticString() implementations. 
This way we also get the correct printing for floats.

>From 1dcd3954524332178dc572a93f5806e79d79f24e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 10 Aug 2024 11:03:06 +0200
Subject: [PATCH] [clang][Interp] Improve "in call to" call argument printing

Always go through toAPValue() first and pretty-print that. In the
future, I think we could get rid of the individual toDiagnosticString()
implementations. This way we also get the correct printing for floats.
---
 clang/lib/AST/Interp/InterpFrame.cpp  |  5 +++--
 .../test/AST/Interp/constexpr-frame-describe.cpp  | 15 +++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index 27108f957305f3..4530f28d694e84 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -102,8 +102,9 @@ void InterpFrame::popArgs() {
 }
 
 template 
-static void print(llvm::raw_ostream &OS, const T &V, ASTContext &, QualType) {
-  OS << V;
+static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx,
+  QualType Ty) {
+  V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty);
 }
 
 template <>
diff --git a/clang/test/AST/Interp/constexpr-frame-describe.cpp 
b/clang/test/AST/Interp/constexpr-frame-describe.cpp
index e039fd61ae9812..a0ae046fc01786 100644
--- a/clang/test/AST/Interp/constexpr-frame-describe.cpp
+++ b/clang/test/AST/Interp/constexpr-frame-describe.cpp
@@ -81,3 +81,18 @@ static_assert(bar.fail2()); // both-error 
{{constant expression}} \
 static_assert(bar.fail3(3, 4UL, bar, &bar)); // both-error {{constant 
expression}} \
  // expected-note {{in call to 
'bar.fail3, const Bar *>(3, 4, &bar, &bar)'}} 
\
  // ref-note {{in call to 
'bar.fail3, const Bar *>(3, 4, {}, &bar)'}}
+
+
+
+/// FIXME: Bound member pointer printing doesn't work right, see the last 
parameter to MemPtr().
+struct MemPtrTest {
+  int n;
+  void f();
+};
+MemPtrTest mpt; // both-note {{here}}
+constexpr int MemPtr(int (MemPtrTest::*a), void (MemPtrTest::*b)(), int &c) {
+  return c; // both-note {{read of non-constexpr variable 'mpt'}}
+}
+static_assert(MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.*&MemPtrTest::n), 
""); // both-error {{constant expression}} \
+   
 // expected-note {{in call to 'MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt)'}} \
+   
 // ref-note {{in call to 'MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.n)'}}

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


[clang] [clang][Interp] Improve "in call to" call argument printing (PR #102735)

2024-08-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Always go through toAPValue() first and pretty-print that. In the future, I 
think we could get rid of the individual toDiagnosticString() implementations. 
This way we also get the correct printing for floats.

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/InterpFrame.cpp (+3-2) 
- (modified) clang/test/AST/Interp/constexpr-frame-describe.cpp (+15) 


``diff
diff --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index 27108f957305f..4530f28d694e8 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -102,8 +102,9 @@ void InterpFrame::popArgs() {
 }
 
 template 
-static void print(llvm::raw_ostream &OS, const T &V, ASTContext &, QualType) {
-  OS << V;
+static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx,
+  QualType Ty) {
+  V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty);
 }
 
 template <>
diff --git a/clang/test/AST/Interp/constexpr-frame-describe.cpp 
b/clang/test/AST/Interp/constexpr-frame-describe.cpp
index e039fd61ae981..a0ae046fc0178 100644
--- a/clang/test/AST/Interp/constexpr-frame-describe.cpp
+++ b/clang/test/AST/Interp/constexpr-frame-describe.cpp
@@ -81,3 +81,18 @@ static_assert(bar.fail2()); // both-error 
{{constant expression}} \
 static_assert(bar.fail3(3, 4UL, bar, &bar)); // both-error {{constant 
expression}} \
  // expected-note {{in call to 
'bar.fail3, const Bar *>(3, 4, &bar, &bar)'}} 
\
  // ref-note {{in call to 
'bar.fail3, const Bar *>(3, 4, {}, &bar)'}}
+
+
+
+/// FIXME: Bound member pointer printing doesn't work right, see the last 
parameter to MemPtr().
+struct MemPtrTest {
+  int n;
+  void f();
+};
+MemPtrTest mpt; // both-note {{here}}
+constexpr int MemPtr(int (MemPtrTest::*a), void (MemPtrTest::*b)(), int &c) {
+  return c; // both-note {{read of non-constexpr variable 'mpt'}}
+}
+static_assert(MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.*&MemPtrTest::n), 
""); // both-error {{constant expression}} \
+   
 // expected-note {{in call to 'MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt)'}} \
+   
 // ref-note {{in call to 'MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.n)'}}

``




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


[clang] [llvm] [Sanitizer] Make sanitizer passes idempotent (PR #99439)

2024-08-10 Thread via cfe-commits

https://github.com/skc7 updated https://github.com/llvm/llvm-project/pull/99439

>From b7c0520ab9ea9d00fe5008717d2af04d494942eb Mon Sep 17 00:00:00 2001
From: skc7 
Date: Thu, 18 Jul 2024 11:49:24 +0530
Subject: [PATCH] [Sanitizer] Make sanitizer passes idempotent.

---
 clang/test/CodeGenObjC/no-sanitize.m  |  2 +-
 .../include/llvm/Transforms/Instrumentation.h |  4 ++
 .../Instrumentation/AddressSanitizer.cpp  |  5 ++
 .../Instrumentation/DataFlowSanitizer.cpp |  3 +
 .../Instrumentation/HWAddressSanitizer.cpp|  4 ++
 .../Instrumentation/Instrumentation.cpp   | 35 
 .../Instrumentation/MemorySanitizer.cpp   |  4 ++
 .../Instrumentation/ThreadSanitizer.cpp   |  3 +
 .../AddressSanitizer/asan-pass-second-run.ll  | 55 +++
 .../AddressSanitizer/missing_dbg.ll   |  2 +-
 .../dfsan-pass-second-run.ll  | 17 ++
 .../hwasan-pass-second-run.ll | 41 ++
 .../MemorySanitizer/msan-pass-second-run.ll   | 43 +++
 .../ThreadSanitizer/tsan-pass-second-run.ll   | 28 ++
 14 files changed, 244 insertions(+), 2 deletions(-)
 create mode 100644 
llvm/test/Instrumentation/AddressSanitizer/asan-pass-second-run.ll
 create mode 100644 
llvm/test/Instrumentation/DataFlowSanitizer/dfsan-pass-second-run.ll
 create mode 100644 
llvm/test/Instrumentation/HWAddressSanitizer/hwasan-pass-second-run.ll
 create mode 100644 
llvm/test/Instrumentation/MemorySanitizer/msan-pass-second-run.ll
 create mode 100644 
llvm/test/Instrumentation/ThreadSanitizer/tsan-pass-second-run.ll

diff --git a/clang/test/CodeGenObjC/no-sanitize.m 
b/clang/test/CodeGenObjC/no-sanitize.m
index abaf6fab26ab61..b5c6a5ad745f3e 100644
--- a/clang/test/CodeGenObjC/no-sanitize.m
+++ b/clang/test/CodeGenObjC/no-sanitize.m
@@ -2,7 +2,7 @@
 
 @interface I0 @end
 @implementation I0
-// CHECK-NOT: sanitize_address
+// CHECK-NOT: Function Attrs: sanitize_address
 - (void) im0: (int) a0 __attribute__((no_sanitize("address"))) {
   int (^blockName)(void) = ^int(void) { return 0; };
 }
diff --git a/llvm/include/llvm/Transforms/Instrumentation.h 
b/llvm/include/llvm/Transforms/Instrumentation.h
index 969c2cd12f3f08..885d3249fb4f83 100644
--- a/llvm/include/llvm/Transforms/Instrumentation.h
+++ b/llvm/include/llvm/Transforms/Instrumentation.h
@@ -30,6 +30,10 @@ class Triple;
 class OptimizationRemarkEmitter;
 class Comdat;
 class CallBase;
+class Module;
+
+/// Check if module has flag attached, if not add the flag.
+bool checkIfAlreadyInstrumented(Module &M, StringRef Flag);
 
 /// Instrumentation passes often insert conditional checks into entry blocks.
 /// Call this function before splitting the entry block to move instructions
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 9fb1df7ab2b79c..9416c8d87dd9dc 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1251,6 +1251,11 @@ AddressSanitizerPass::AddressSanitizerPass(
 
 PreservedAnalyses AddressSanitizerPass::run(Module &M,
 ModuleAnalysisManager &MAM) {
+  // Return early if nosanitize_address module flag is present for the module.
+  // This implies that asan pass has already run before.
+  if (checkIfAlreadyInstrumented(M, "nosanitize_address"))
+return PreservedAnalyses::all();
+
   ModuleAddressSanitizer ModuleSanitizer(
   M, Options.InsertVersionCheck, Options.CompileKernel, Options.Recover,
   UseGlobalGC, UseOdrIndicator, DestructorKind, ConstructorKind);
diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
index 113d39b4f2af7b..b4b5f67d2e62da 100644
--- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -3473,6 +3473,9 @@ void DFSanVisitor::visitPHINode(PHINode &PN) {
 
 PreservedAnalyses DataFlowSanitizerPass::run(Module &M,
  ModuleAnalysisManager &AM) {
+  // Return early if nosanitize_dataflow module flag is present for the module.
+  if (checkIfAlreadyInstrumented(M, "nosanitize_dataflow"))
+return PreservedAnalyses::all();
   auto GetTLI = [&](Function &F) -> TargetLibraryInfo & {
 auto &FAM =
 AM.getResult(M).getManager();
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index 812874ff3c1739..95433a216b168d 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -57,6 +57,7 @@
 #include "llvm/Support/RandomNumberGenerator.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Triple.h"
+#include "llvm/Transforms/Instrumentation.h"
 #include "llvm/Transforms/I

[clang] [llvm] [Sanitizer] Make sanitizer passes idempotent (PR #99439)

2024-08-10 Thread via cfe-commits


@@ -12,12 +12,47 @@
 
//===--===//
 
 #include "llvm/Transforms/Instrumentation.h"
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/DiagnosticPrinter.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
 #include "llvm/TargetParser/Triple.h"
 
 using namespace llvm;
 
+static cl::opt ClIgnoreRedundantInstrumentation(
+"ignore-redundant-instrumentation",
+cl::desc("Ignore redundant instrumentation"), cl::Hidden, cl::init(false));
+
+namespace {
+/// Diagnostic information for IR instrumentation reporting.
+class DiagnosticInfoInstrumentation : public DiagnosticInfo {
+  const Twine &Msg;
+
+public:
+  DiagnosticInfoInstrumentation(const Twine &DiagMsg,
+DiagnosticSeverity Severity = DS_Warning)
+  : DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {}
+  void print(DiagnosticPrinter &DP) const override { DP << Msg; }
+};
+} // namespace
+
+/// Check if module has flag attached, if not add the flag.
+bool llvm::checkIfAlreadyInstrumented(Module &M, StringRef Flag) {

skc7 wrote:

Thanks for the suggestion. Have updated the patch in the latest commit. 
Using DS_Error, causes second run of the pass to abort with error. So retained 
DS_Warning, so this returns true without abort and sanitizer passes return 
without doing second instrumentation. 

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


[clang] [llvm] [Sanitizer] Make sanitizer passes idempotent (PR #99439)

2024-08-10 Thread via cfe-commits

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


[clang] [clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854) (PR #96301)

2024-08-10 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/96301

>From 1a25f021b797e5591f1ae324c8a8b5244047d5f4 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Fri, 21 Jun 2024 18:26:36 +0530
Subject: [PATCH] [clang] Allow class with anonymous union member to be
 const-default-constructible even if a union member has a default member
 initializer (#95854)

Resolves #95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member 
initializer.
  This is valid as per ``8.3`` in `Draft C++ Standard 
`_.
  The ``allowConstDefaultInit`` member function in ``CXXRecordDecl`` needs
  special-case unions to handle the rule. (#GH95854).

```
struct A {
  union {
int n = 0;
int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
---
 clang/docs/ReleaseNotes.rst   | 88 +++
 clang/include/clang/AST/DeclCXX.h |  3 +-
 clang/lib/AST/DeclCXX.cpp |  9 +++-
 clang/test/SemaCXX/GH95854.cpp| 21 
 4 files changed, 119 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/GH95854.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 351b41b1c0c588..2927888b31f47c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -192,6 +192,94 @@ Bug Fixes in This Version
 - Fixed a crash when diagnosing format strings and encountering an empty
   delimited escape sequence (e.g., ``"\o{}"``). #GH102218
 
+- Fixed missing warnings when comparing mismatched enumeration constants
+  in C (#GH29217)
+
+- Clang now accepts elaborated-type-specifiers that explicitly specialize
+  a member class template for an implicit instantiation of a class template.
+
+- Fixed missing warnings when doing bool-like conversions in C23 (#GH79435).
+- Clang's ``-Wshadow`` no longer warns when an init-capture is named the same 
as
+  a class field unless the lambda can capture this.
+  Fixes (#GH71976)
+
+- Clang now accepts qualified partial/explicit specializations of variable 
templates that
+  are not nominable in the lookup context of the specialization.
+
+- Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
+  for logical operators in C23.
+  Fixes (#GH64356).
+
+- ``__is_trivially_relocatable`` no longer returns ``false`` for 
volatile-qualified types.
+  Fixes (#GH77091).
+
+- Clang no longer produces a false-positive `-Wunused-variable` warning
+  for variables created through copy initialization having side-effects in 
C++17 and later.
+  Fixes (#GH64356) (#GH79518).
+
+- Fix value of predefined macro ``__FUNCTION__`` in MSVC compatibility mode.
+  Fixes (#GH66114).
+
+- Clang now emits errors for explicit specializations/instatiations of lambda 
call
+  operator.
+  Fixes (#GH83267).
+
+- Fix crash on ill-formed partial specialization with CRTP.
+  Fixes (#GH89374).
+
+- Clang now correctly generates overloads for bit-precise integer types for
+  builtin operators in C++. Fixes #GH82998.
+
+- Fix crash when destructor definition is preceded with an equals sign.
+  Fixes (#GH89544).
+
+- When performing mixed arithmetic between ``_Complex`` floating-point types 
and integers,
+  Clang now correctly promotes the integer to its corresponding real 
floating-point
+  type only rather than to the complex type (e.g. ``_Complex float / int`` is 
now evaluated
+  as ``_Complex float / float`` rather than ``_Complex float / _Complex 
float``), as mandated
+  by the C standard. This significantly improves codegen of `*` and `/` 
especially.
+  Fixes #GH31205.
+
+- Fixes an assertion failure on invalid code when trying to define member
+  functions in lambdas.
+
+- Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
+  incorrect constraint substitution. (#GH86769).
+
+- Fixed an assertion failure on invalid InitListExpr in C89 mode (#GH88008).
+
+- Fixed missing destructor calls when we branch from middle of an expression.
+  This could happen through a branch in stmt-expr or in an expression 
containing a coroutine
+  suspension. Fixes (#GH63818) (#GH88478).
+
+- Clang will no longer diagnose an erroneous non-dependent ``switch`` condition
+  during instantiation, and instead will only diagnose it once, during checking
+  of the function template.
+
+- Clang now allows the value of unroll count to be zero in ``#pragma GCC 
unroll`` and ``#pragma unroll``.
+  The values of 0 and 1 block any unrolling of the loop. This keeps the same 
behavior with GCC.
+  Fixes (`#88624 `_).
+
+- Clang will no longer emit a duplicate -Wunused-value warning for an 
expression
+  `(A, B)` which evaluates to glvalue `B` that can be converted to non 
ODR-use. (#GH45783)
+
+- Clang now correctly disallows VLA type compound literals, e.g. 
``(int[size]){}``,
+  

[clang] 979abf1 - [clang][Interp] Improve "in call to" call argument printing (#102735)

2024-08-10 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-10T11:40:04+02:00
New Revision: 979abf142f606bf43a5500e59d72f1286a7180c7

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

LOG: [clang][Interp] Improve "in call to" call argument printing (#102735)

Always go through toAPValue() first and pretty-print that. In the
future, I think we could get rid of the individual toDiagnosticString()
implementations. This way we also get the correct printing for floats.

Added: 


Modified: 
clang/lib/AST/Interp/InterpFrame.cpp
clang/test/AST/Interp/constexpr-frame-describe.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index 27108f957305f..4530f28d694e8 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -102,8 +102,9 @@ void InterpFrame::popArgs() {
 }
 
 template 
-static void print(llvm::raw_ostream &OS, const T &V, ASTContext &, QualType) {
-  OS << V;
+static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx,
+  QualType Ty) {
+  V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty);
 }
 
 template <>

diff  --git a/clang/test/AST/Interp/constexpr-frame-describe.cpp 
b/clang/test/AST/Interp/constexpr-frame-describe.cpp
index e039fd61ae981..a0ae046fc0178 100644
--- a/clang/test/AST/Interp/constexpr-frame-describe.cpp
+++ b/clang/test/AST/Interp/constexpr-frame-describe.cpp
@@ -81,3 +81,18 @@ static_assert(bar.fail2()); // both-error 
{{constant expression}} \
 static_assert(bar.fail3(3, 4UL, bar, &bar)); // both-error {{constant 
expression}} \
  // expected-note {{in call to 
'bar.fail3, const Bar *>(3, 4, &bar, &bar)'}} 
\
  // ref-note {{in call to 
'bar.fail3, const Bar *>(3, 4, {}, &bar)'}}
+
+
+
+/// FIXME: Bound member pointer printing doesn't work right, see the last 
parameter to MemPtr().
+struct MemPtrTest {
+  int n;
+  void f();
+};
+MemPtrTest mpt; // both-note {{here}}
+constexpr int MemPtr(int (MemPtrTest::*a), void (MemPtrTest::*b)(), int &c) {
+  return c; // both-note {{read of non-constexpr variable 'mpt'}}
+}
+static_assert(MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.*&MemPtrTest::n), 
""); // both-error {{constant expression}} \
+   
 // expected-note {{in call to 'MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt)'}} \
+   
 // ref-note {{in call to 'MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.n)'}}



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


[clang] [clang][Interp] Improve "in call to" call argument printing (PR #102735)

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

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

2024-08-10 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/99473

>From d6903daf0da6979822b8981ea3641455ff6d06f8 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH 1/6] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 clang/include/clang/AST/DeclID.h  |   5 +-
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   7 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 ++
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 160 +-
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/lib/Serialization/ASTWriter.cpp |   2 +
 clang/test/SemaCXX/type-trait-common-type.cpp | 126 ++
 libcxx/include/__type_traits/common_type.h|  16 +-
 libcxx/include/module.modulemap   |   2 +
 16 files changed, 404 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 608bd90fcc3ff9..d02e742297898c 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager &SourceMgr;
@@ -1107,6 +,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1984,6 +1989,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = &Idents.get("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60d..875e9a72b39512 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,13 +84,16 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 18,
 };
 
 /// The number of declaration IDs that are predefined.
 ///
 /// For more information about predefined declarations, see the
 /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-const unsigned int NUM_PREDEF_DECL_IDS = 18;
+const unsigned int NUM_PREDEF_DECL_IDS = 19;
 
 /// GlobalDeclID means DeclID in the current ASTContext and LocalDeclID means
 /// DeclID specific to a certain ModuleFile. Specially, in ASTWriter, the
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index e85ec5b2dca14e..4353b72f713838 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe461..5c7945c4c5c583 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualTy

[clang] [Clang] Add [[clang::diagnose_specializations]] (PR #101469)

2024-08-10 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/101469

>From 82ab798fc72c6de64ae527d96393f0dc67307e98 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 1 Aug 2024 12:30:22 +0200
Subject: [PATCH 1/5] [Clang] Add [[clang::diagnose_specializations]]

---
 clang/include/clang/Basic/Attr.td | 13 ++-
 clang/include/clang/Basic/AttrDocs.td | 14 ++--
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/Sema/SemaDeclAttr.cpp   |  9 +
 clang/lib/Sema/SemaTemplate.cpp   |  6 
 .../SemaCXX/attr-diagnose-specializations.cpp | 34 +++
 7 files changed, 76 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/SemaCXX/attr-diagnose-specializations.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8ac2079099c854..e074cc8b285a95 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -103,6 +103,9 @@ def NonParmVar : SubsetSubjecthasLocalStorage()}],
 "variables with non-local storage">;
+def VarTmpl : SubsetSubjectgetDescribedVarTemplate()}],
+"variable template">;
+
 def NonBitField : SubsetSubjectisBitField()}],
 "non-bit-field non-static data members">;
@@ -3327,6 +3330,14 @@ def DiagnoseIf : InheritableAttr {
   let Documentation = [DiagnoseIfDocs];
 }
 
+def DiagnoseSpecializations : InheritableAttr {
+  let Spellings = [Clang<"diagnose_specializations", /*AllowInC*/0>];
+  let Subjects = SubjectList<[ClassTmpl, VarTmpl]>;
+  let Documentation = [DiagnoseSpecializationsDocs];
+  let MeaningfulToClassTemplateDefinition = 1;
+  let TemplateDependent = 1;
+}
+
 def ArcWeakrefUnavailable : InheritableAttr {
   let Spellings = [Clang<"objc_arc_weak_reference_unavailable">];
   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
@@ -4581,7 +4592,7 @@ def HLSLResource : InheritableAttr {
   let Spellings = [];
   let Subjects = SubjectList<[Struct]>;
   let LangOpts = [HLSL];
-  let Args = [
+  let Args = [
 EnumArgument<
 "ResourceKind", "llvm::hlsl::ResourceKind",
 /*is_string=*/0,
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 94c284fc731589..4ca67a63714d4b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -975,6 +975,15 @@ Query for this feature with 
``__has_attribute(diagnose_if)``.
   }];
 }
 
+def DiagnoseSpecializationsDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+``clang::diagnose_specializations`` can be appied to class templates which
+should not be specialized by users. This is primarily used to diagnose user
+specializations of standard library type traits.
+  }];
+}
+
 def PassObjectSizeDocs : Documentation {
   let Category = DocCatVariable; // Technically it's a parameter doc, but eh.
   let Heading = "pass_object_size, pass_dynamic_object_size";
@@ -7388,10 +7397,10 @@ def HLSLLoopHintDocs : Documentation {
   let Content = [{
 The ``[loop]`` directive allows loop optimization hints to be
 specified for the subsequent loop. The directive allows unrolling to
-be disabled and is not compatible with [unroll(x)]. 
+be disabled and is not compatible with [unroll(x)].
 
 Specifying the parameter, ``[loop]``, directs the
-unroller to not unroll the loop. 
+unroller to not unroll the loop.
 
 .. code-block:: hlsl
 
@@ -8306,4 +8315,3 @@ Declares that a function potentially allocates heap 
memory, and prevents any pot
 of ``nonallocating`` by the compiler.
   }];
 }
-
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 19c3f1e0433496..d6f6111f708684 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -472,6 +472,7 @@ def ExpansionToDefined : DiagGroup<"expansion-to-defined">;
 def FlagEnum : DiagGroup<"flag-enum">;
 def IncrementBool : DiagGroup<"increment-bool", [DeprecatedIncrementBool]>;
 def InfiniteRecursion : DiagGroup<"infinite-recursion">;
+def InvalidSpecialization : DiagGroup<"invalid-specialization">;
 def PureVirtualCallFromCtorDtor: 
DiagGroup<"call-to-pure-virtual-from-ctor-dtor">;
 def GNUImaginaryConstant : DiagGroup<"gnu-imaginary-constant">;
 def IgnoredGCH : DiagGroup<"ignored-gch">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9a..5972d630347ec4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5407,6 +5407,9 @@ def note_dependent_function_template_spec_discard_reason 
: Note<
   "candidate ignored: %select{not a function template|"
   "not a member of the enclosing %select{class template|"
   "namespace; did y

[clang] [Driver] Have getTargetSubDirPath better match get_compiler_rt_target (PR #100091)

2024-08-10 Thread Tobias Hieta via cfe-commits

tru wrote:

Do we still need to fix this for 19.1.0-final?

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


[clang] [clang][Interp] Do not call dtors of union members (PR #102739)

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

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

None

>From f4ccc8a5d705bcc0eb6a573f24b0bc3e80aa7b5e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 10 Aug 2024 11:21:25 +0200
Subject: [PATCH] [clang][Interp] Do not call dtors of union members

---
 clang/lib/AST/Interp/Compiler.cpp | 25 -
 clang/test/AST/Interp/unions.cpp  | 46 +++
 2 files changed, 58 insertions(+), 13 deletions(-)

diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 0d72e33c1c7d2..d0e4d409b6580 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -5552,22 +5552,21 @@ bool Compiler::emitComplexComparison(const 
Expr *LHS, const Expr *RHS,
 template 
 bool Compiler::emitRecordDestruction(const Record *R) {
   assert(R);
-  // First, destroy all fields.
-  for (const Record::Field &Field : llvm::reverse(R->fields())) {
-const Descriptor *D = Field.Desc;
-if (!D->isPrimitive() && !D->isPrimitiveArray()) {
-  if (!this->emitGetPtrField(Field.Offset, SourceInfo{}))
-return false;
-  if (!this->emitDestruction(D))
-return false;
-  if (!this->emitPopPtr(SourceInfo{}))
-return false;
+  if (!R->isUnion()) {
+// First, destroy all fields.
+for (const Record::Field &Field : llvm::reverse(R->fields())) {
+  const Descriptor *D = Field.Desc;
+  if (!D->isPrimitive() && !D->isPrimitiveArray()) {
+if (!this->emitGetPtrField(Field.Offset, SourceInfo{}))
+  return false;
+if (!this->emitDestruction(D))
+  return false;
+if (!this->emitPopPtr(SourceInfo{}))
+  return false;
+  }
 }
   }
 
-  // FIXME: Unions need to be handled differently here. We don't want to
-  //   call the destructor of its members.
-
   // Now emit the destructor and recurse into base classes.
   if (const CXXDestructorDecl *Dtor = R->getDestructor();
   Dtor && !Dtor->isTrivial()) {
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index d615b3584b30b..b0b279831405d 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -152,4 +152,50 @@ namespace IndirectFieldDecl {
   };
   static_assert(C().a == 1, "");
 }
+
+namespace UnionDtor {
+
+  union U {
+int *I;
+constexpr U(int *I) : I(I) {}
+constexpr ~U() {
+  *I = 10;
+}
+  };
+
+  constexpr int foo() {
+int a = 100;
+{
+  U u(&a);
+}
+return a;
+  }
+  static_assert(foo() == 10);
+}
+
+namespace UnionMemberDtor {
+  class UM {
+  public:
+int &I;
+constexpr UM(int &I) : I(I) {}
+constexpr ~UM() { I = 200; }
+  };
+
+  union U {
+UM um;
+constexpr U(int &I) : um(I) {}
+constexpr ~U() {
+}
+  };
+
+  constexpr int foo() {
+int a = 100;
+{
+  U u(a);
+}
+
+return a;
+  }
+  static_assert(foo() == 100);
+}
 #endif

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


[clang] [Clang] Add [[clang::diagnose_specializations]] (PR #101469)

2024-08-10 Thread Mital Ashok via cfe-commits


@@ -5408,7 +5408,10 @@ def note_dependent_function_template_spec_discard_reason 
: Note<
   "not a member of the enclosing %select{class template|"
   "namespace; did you mean to explicitly qualify the specialization?}1}0">;
 def warn_invalid_specialization : Warning<
-  "%0 should not be specialized">,
+  "%0 cannot be specialized">,

MitalAshok wrote:

```suggestion
  "%0 cannot be specialized%select{|: %2}1">,
```

And then change the diagnostics to `Diag(Loc, 
diag::warn_invalid_specialization) << VarOrClassTemplate << !Message.empty() << 
Message;`

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


[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

2024-08-10 Thread via cfe-commits

https://github.com/TsXor updated 
https://github.com/llvm/llvm-project/pull/102410

>From 4858eef099dbca66b2e3d36fc17aef574c1f3d58 Mon Sep 17 00:00:00 2001
From: TsXor 
Date: Thu, 8 Aug 2024 09:25:52 +0800
Subject: [PATCH 1/2] fix error handling of TranslationUnit.reparse

---
 clang/bindings/python/clang/cindex.py | 42 +++
 clang/docs/ReleaseNotes.rst   |  3 ++
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 2038ef6045c7df..e4591828f91968 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -149,8 +149,8 @@ def b(x: str | bytes) -> bytes:
 # this by marshalling object arguments as void**.
 c_object_p: TType[_Pointer[Any]] = POINTER(c_void_p)
 
-### Exception Classes ###
 
+### Exception Classes ###
 
 class TranslationUnitLoadError(Exception):
 """Represents an error that occurred when loading a TranslationUnit.
@@ -161,7 +161,35 @@ class TranslationUnitLoadError(Exception):
 FIXME: Make libclang expose additional error information in this scenario.
 """
 
-pass
+# A generic error code, no further details are available.
+#
+# Errors of this kind can get their own specific error codes in future
+# libclang versions.
+ERROR_FAILURE = 1
+
+# libclang crashed while performing the requested operation.
+ERROR_CRASHED = 2
+
+# The function detected that the arguments violate the function
+# contract.
+ERROR_INVALID_ARGUMENTS = 3
+
+# An AST deserialization error has occurred.
+ERROR_AST_READ_ERROR = 4
+
+def __init__(self, enumeration: int | None, message: str):
+if enumeration is not None:
+assert isinstance(enumeration, int)
+
+if enumeration < 1 or enumeration > 4:
+raise Exception(
+"Encountered undefined CXError "
+"constant: %d. Please file a bug to have this "
+"value supported." % enumeration
+)
+
+self.error_code = enumeration
+Exception.__init__(self, "Error %d: %s" % (enumeration or 0, message))
 
 
 class TranslationUnitSaveError(Exception):
@@ -3094,7 +3122,8 @@ def from_source(
 )
 
 if not ptr:
-raise TranslationUnitLoadError("Error parsing translation unit.")
+# FIXME: use clang_parseTranslationUnit2 to preserve error code
+raise TranslationUnitLoadError(None, "Error parsing translation 
unit.")
 
 return cls(ptr, index=index)
 
@@ -3118,7 +3147,8 @@ def from_ast_file(cls, filename, index=None):
 
 ptr = conf.lib.clang_createTranslationUnit(index, os.fspath(filename))
 if not ptr:
-raise TranslationUnitLoadError(filename)
+# FIXME: use clang_createTranslationUnit2 to preserve error code
+raise TranslationUnitLoadError(None, filename)
 
 return cls(ptr=ptr, index=index)
 
@@ -3263,9 +3293,11 @@ def reparse(self, unsaved_files=None, options=0):
 unsaved_files = []
 
 unsaved_files_array = self.process_unsaved_files(unsaved_files)
-ptr = conf.lib.clang_reparseTranslationUnit(
+result = conf.lib.clang_reparseTranslationUnit(
 self, len(unsaved_files), unsaved_files_array, options
 )
+if result != 0:
+raise TranslationUnitLoadError(result, 'Error reparsing 
TranslationUnit.')
 
 def save(self, filename):
 """Saves the TranslationUnit to a file.
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba70b138a04c4a..33a8c493e5e998 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -59,6 +59,9 @@ Clang Python Bindings Potentially Breaking Changes
 - Calling a property on the `CompletionChunk` or `CompletionString` class
   statically now leads to an error, instead of returning a `CachedProperty` 
object
   that is used internally. Properties are only available on instances.
+- `TranslationUnitLoadError` now contains an optional error code in 
`error_code`
+  attribute. Also, `TranslationUnit.reparse` will throw 
`TranslationUnitLoadError`
+  when operation fails.
 
 What's New in Clang |release|?
 ==

>From 260247b4701e2ff6171b193cd2cdcd5b77fac124 Mon Sep 17 00:00:00 2001
From: TsXor 
Date: Sat, 10 Aug 2024 19:20:56 +0800
Subject: [PATCH 2/2] preserve error code in TU parsing APIs

---
 clang/bindings/python/clang/cindex.py | 51 ---
 1 file changed, 31 insertions(+), 20 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index e4591828f91968..63d23f55a5a742 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -177,16 +177,15 @@ class TranslationUnitLoadError(Exception):
 # An AST deserialization error has occurred.

[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

2024-08-10 Thread via cfe-commits

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


[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

2024-08-10 Thread via cfe-commits

https://github.com/TsXor commented:

`CXError` is merged into `TranslationUnitLoadError`, and error code is 
preserved in another commit.

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


[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

2024-08-10 Thread via cfe-commits


@@ -152,6 +152,41 @@ def b(x: str | bytes) -> bytes:
 ### Exception Classes ###
 
 
+class CXError(Exception):

TsXor wrote:

I looked at C header and found that `clang_parseTranslationUnit` and 
`clang_createTranslationUnit` actually swallows error code. To be unified, we 
should use `clang_parseTranslationUnit2` and `clang_createTranslationUnit2` 
which outputs value with pointers and return error code.

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


[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

2024-08-10 Thread via cfe-commits

https://github.com/TsXor updated 
https://github.com/llvm/llvm-project/pull/102410

>From 4858eef099dbca66b2e3d36fc17aef574c1f3d58 Mon Sep 17 00:00:00 2001
From: TsXor 
Date: Thu, 8 Aug 2024 09:25:52 +0800
Subject: [PATCH 1/2] fix error handling of TranslationUnit.reparse

---
 clang/bindings/python/clang/cindex.py | 42 +++
 clang/docs/ReleaseNotes.rst   |  3 ++
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 2038ef6045c7df..e4591828f91968 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -149,8 +149,8 @@ def b(x: str | bytes) -> bytes:
 # this by marshalling object arguments as void**.
 c_object_p: TType[_Pointer[Any]] = POINTER(c_void_p)
 
-### Exception Classes ###
 
+### Exception Classes ###
 
 class TranslationUnitLoadError(Exception):
 """Represents an error that occurred when loading a TranslationUnit.
@@ -161,7 +161,35 @@ class TranslationUnitLoadError(Exception):
 FIXME: Make libclang expose additional error information in this scenario.
 """
 
-pass
+# A generic error code, no further details are available.
+#
+# Errors of this kind can get their own specific error codes in future
+# libclang versions.
+ERROR_FAILURE = 1
+
+# libclang crashed while performing the requested operation.
+ERROR_CRASHED = 2
+
+# The function detected that the arguments violate the function
+# contract.
+ERROR_INVALID_ARGUMENTS = 3
+
+# An AST deserialization error has occurred.
+ERROR_AST_READ_ERROR = 4
+
+def __init__(self, enumeration: int | None, message: str):
+if enumeration is not None:
+assert isinstance(enumeration, int)
+
+if enumeration < 1 or enumeration > 4:
+raise Exception(
+"Encountered undefined CXError "
+"constant: %d. Please file a bug to have this "
+"value supported." % enumeration
+)
+
+self.error_code = enumeration
+Exception.__init__(self, "Error %d: %s" % (enumeration or 0, message))
 
 
 class TranslationUnitSaveError(Exception):
@@ -3094,7 +3122,8 @@ def from_source(
 )
 
 if not ptr:
-raise TranslationUnitLoadError("Error parsing translation unit.")
+# FIXME: use clang_parseTranslationUnit2 to preserve error code
+raise TranslationUnitLoadError(None, "Error parsing translation 
unit.")
 
 return cls(ptr, index=index)
 
@@ -3118,7 +3147,8 @@ def from_ast_file(cls, filename, index=None):
 
 ptr = conf.lib.clang_createTranslationUnit(index, os.fspath(filename))
 if not ptr:
-raise TranslationUnitLoadError(filename)
+# FIXME: use clang_createTranslationUnit2 to preserve error code
+raise TranslationUnitLoadError(None, filename)
 
 return cls(ptr=ptr, index=index)
 
@@ -3263,9 +3293,11 @@ def reparse(self, unsaved_files=None, options=0):
 unsaved_files = []
 
 unsaved_files_array = self.process_unsaved_files(unsaved_files)
-ptr = conf.lib.clang_reparseTranslationUnit(
+result = conf.lib.clang_reparseTranslationUnit(
 self, len(unsaved_files), unsaved_files_array, options
 )
+if result != 0:
+raise TranslationUnitLoadError(result, 'Error reparsing 
TranslationUnit.')
 
 def save(self, filename):
 """Saves the TranslationUnit to a file.
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba70b138a04c4a..33a8c493e5e998 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -59,6 +59,9 @@ Clang Python Bindings Potentially Breaking Changes
 - Calling a property on the `CompletionChunk` or `CompletionString` class
   statically now leads to an error, instead of returning a `CachedProperty` 
object
   that is used internally. Properties are only available on instances.
+- `TranslationUnitLoadError` now contains an optional error code in 
`error_code`
+  attribute. Also, `TranslationUnit.reparse` will throw 
`TranslationUnitLoadError`
+  when operation fails.
 
 What's New in Clang |release|?
 ==

>From c168a55356d94ffcccbd960b189b5b15feb272cb Mon Sep 17 00:00:00 2001
From: TsXor 
Date: Sat, 10 Aug 2024 19:20:56 +0800
Subject: [PATCH 2/2] preserve error code in TU parsing APIs

---
 clang/bindings/python/clang/cindex.py | 51 ---
 clang/docs/ReleaseNotes.rst   |  2 +-
 2 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index e4591828f91968..63d23f55a5a742 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -177,16 +177,15 @@ class TranslationUnitLoadError(Exception):
 #

[clang] [clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854) (PR #96301)

2024-08-10 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/96301

>From 7efe2bd186cb0a97b8f8b66b9c69da92c79fc60a Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Fri, 21 Jun 2024 18:26:36 +0530
Subject: [PATCH] [clang] Allow class with anonymous union member to be
 const-default-constructible even if a union member has a default member
 initializer (#95854)

Resolves #95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member 
initializer.
  This is valid as per ``8.3`` in `Draft C++ Standard 
`_.
  The ``allowConstDefaultInit`` member function in ``CXXRecordDecl`` needs
  special-case unions to handle the rule. (#GH95854).

```
struct A {
  union {
int n = 0;
int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
---
 clang/docs/ReleaseNotes.rst   |  5 +
 clang/include/clang/AST/DeclCXX.h |  3 ++-
 clang/lib/AST/DeclCXX.cpp |  9 -
 clang/test/SemaCXX/GH95854.cpp| 21 +
 4 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/GH95854.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 351b41b1c0c588..890b9054b84401 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,6 +217,11 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
+- Clang incorrectly considers a class with an anonymous union member to not be
+  const-default-constructible even if a union member has a default member 
initializer.
+  This is valid as per ``8.3`` in `Draft C++ Standard 
`_.
+  The ``allowConstDefaultInit`` member function in ``CXXRecordDecl`` needs
+  special-case unions to handle the rule. (#GH95854).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index bf6a5ce92d438d..9988a4c84ad008 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1395,7 +1395,8 @@ class CXXRecordDecl : public RecordDecl {
   bool allowConstDefaultInit() const {
 return !data().HasUninitializedFields ||
!(data().HasDefaultedDefaultConstructor ||
- needsImplicitDefaultConstructor());
+ needsImplicitDefaultConstructor()) ||
+   (isUnion() && isEmpty());
   }
 
   /// Determine whether this class has a destructor which has no
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 9a3ede426e9143..e8597adcf6fd4a 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1057,6 +1057,9 @@ void CXXRecordDecl::addedMember(Decl *D) {
 if (isUnion() && !Field->isAnonymousStructOrUnion())
   data().HasVariantMembers = true;
 
+if (isUnion() && IsFirstField)
+  data().HasUninitializedFields = true;
+
 // C++0x [class]p9:
 //   A POD struct is a class that is both a trivial class and a
 //   standard-layout class, and has no non-static data members of type
@@ -1125,7 +1128,11 @@ void CXXRecordDecl::addedMember(Decl *D) {
 data().DefaultedCopyConstructorIsDeleted = true;
 }
 
-if (!Field->hasInClassInitializer() && !Field->isMutable()) {
+if (isUnion() && !Field->isMutable()) {
+  if (Field->hasInClassInitializer()) {
+data().HasUninitializedFields = false;
+  }
+} else if (!Field->hasInClassInitializer() && !Field->isMutable()) {
   if (CXXRecordDecl *FieldType = T->getAsCXXRecordDecl()) {
 if (FieldType->hasDefinition() && !FieldType->allowConstDefaultInit())
   data().HasUninitializedFields = true;
diff --git a/clang/test/SemaCXX/GH95854.cpp b/clang/test/SemaCXX/GH95854.cpp
new file mode 100644
index 00..62ae549f2496f0
--- /dev/null
+++ b/clang/test/SemaCXX/GH95854.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
+//
+// -expected-no-diagnostics
+
+struct A {
+  union {
+int n = 0;
+int m;
+  };
+};
+const A a;
+
+struct B {
+  union {
+struct {
+  int n = 5;
+  int m;
+};
+  };
+};
+const B b; // expected-error {{default initialization of an object of const 
type 'const B' without a user-provided default constructor}}

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


[clang] [clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854) (PR #96301)

2024-08-10 Thread Rajveer Singh Bharadwaj via cfe-commits

Rajveer100 wrote:

@zygoloid 
Could you review this?

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


[clang] 86691f8 - [clang][Interp] Do not call dtors of union members (#102739)

2024-08-10 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-10T13:45:30+02:00
New Revision: 86691f8d7e86176db7409ccafb7a79964221720a

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

LOG: [clang][Interp] Do not call dtors of union members (#102739)

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/test/AST/Interp/unions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 0d72e33c1c7d2..d0e4d409b6580 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -5552,22 +5552,21 @@ bool Compiler::emitComplexComparison(const 
Expr *LHS, const Expr *RHS,
 template 
 bool Compiler::emitRecordDestruction(const Record *R) {
   assert(R);
-  // First, destroy all fields.
-  for (const Record::Field &Field : llvm::reverse(R->fields())) {
-const Descriptor *D = Field.Desc;
-if (!D->isPrimitive() && !D->isPrimitiveArray()) {
-  if (!this->emitGetPtrField(Field.Offset, SourceInfo{}))
-return false;
-  if (!this->emitDestruction(D))
-return false;
-  if (!this->emitPopPtr(SourceInfo{}))
-return false;
+  if (!R->isUnion()) {
+// First, destroy all fields.
+for (const Record::Field &Field : llvm::reverse(R->fields())) {
+  const Descriptor *D = Field.Desc;
+  if (!D->isPrimitive() && !D->isPrimitiveArray()) {
+if (!this->emitGetPtrField(Field.Offset, SourceInfo{}))
+  return false;
+if (!this->emitDestruction(D))
+  return false;
+if (!this->emitPopPtr(SourceInfo{}))
+  return false;
+  }
 }
   }
 
-  // FIXME: Unions need to be handled 
diff erently here. We don't want to
-  //   call the destructor of its members.
-
   // Now emit the destructor and recurse into base classes.
   if (const CXXDestructorDecl *Dtor = R->getDestructor();
   Dtor && !Dtor->isTrivial()) {

diff  --git a/clang/test/AST/Interp/unions.cpp 
b/clang/test/AST/Interp/unions.cpp
index d615b3584b30b..b0b279831405d 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -152,4 +152,50 @@ namespace IndirectFieldDecl {
   };
   static_assert(C().a == 1, "");
 }
+
+namespace UnionDtor {
+
+  union U {
+int *I;
+constexpr U(int *I) : I(I) {}
+constexpr ~U() {
+  *I = 10;
+}
+  };
+
+  constexpr int foo() {
+int a = 100;
+{
+  U u(&a);
+}
+return a;
+  }
+  static_assert(foo() == 10);
+}
+
+namespace UnionMemberDtor {
+  class UM {
+  public:
+int &I;
+constexpr UM(int &I) : I(I) {}
+constexpr ~UM() { I = 200; }
+  };
+
+  union U {
+UM um;
+constexpr U(int &I) : um(I) {}
+constexpr ~U() {
+}
+  };
+
+  constexpr int foo() {
+int a = 100;
+{
+  U u(a);
+}
+
+return a;
+  }
+  static_assert(foo() == 100);
+}
 #endif



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


[clang] [clang][Interp] Do not call dtors of union members (PR #102739)

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

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


[clang] [clang][Interp] Handle nested unions (PR #102743)

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

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

None

>From 8d950c9e1a98bc5dd7134b6bd476cca96916c621 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 10 Aug 2024 12:47:38 +0200
Subject: [PATCH] [clang][Interp] Handle nested unions

---
 clang/lib/AST/Interp/Interp.cpp  | 26 ---
 clang/lib/AST/Interp/Pointer.cpp |  2 +-
 clang/test/AST/Interp/unions.cpp | 55 
 3 files changed, 70 insertions(+), 13 deletions(-)

diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 588680adb4616..89ac693893113 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -125,18 +125,15 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
   if (Ptr.isActive())
 return true;
 
-  // Get the inactive field descriptor.
-  const FieldDecl *InactiveField = Ptr.getField();
-  assert(InactiveField);
-
-  // Walk up the pointer chain to find the closest union.
   Pointer U = Ptr.getBase();
-  while (!U.getFieldDesc()->isUnion())
+  Pointer C = Ptr;
+  while (!U.isRoot() && U.inUnion() && !U.isActive()) {
+C = U;
 U = U.getBase();
-
-  // Find the active field of the union.
-  const Record *R = U.getRecord();
-  assert(R && R->isUnion() && "Not a union");
+  }
+  // Get the inactive field descriptor.
+  const FieldDecl *InactiveField = C.getField();
+  assert(InactiveField);
 
   // Consider:
   // union U {
@@ -148,10 +145,15 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
   //
   // When activating x, we will also activate a. If we now try to read
   // from y, we will get to CheckActive, because y is not active. In that
-  // case we return here and let later code handle this.
-  if (!llvm::is_contained(R->getDecl()->fields(), InactiveField))
+  // case, our U will be a (not a union). We return here and let later code
+  // handle this.
+  if (!U.getFieldDesc()->isUnion())
 return true;
 
+  // Find the active field of the union.
+  const Record *R = U.getRecord();
+  assert(R && R->isUnion() && "Not a union");
+
   const FieldDecl *ActiveField = nullptr;
   for (unsigned I = 0, N = R->getNumFields(); I < N; ++I) {
 const Pointer &Field = U.atField(R->getField(I)->Offset);
diff --git a/clang/lib/AST/Interp/Pointer.cpp b/clang/lib/AST/Interp/Pointer.cpp
index f1f7a27c1400d..466e61666c76e 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -413,7 +413,7 @@ void Pointer::activate() const {
   }
 
   Pointer B = getBase();
-  while (!B.getFieldDesc()->isUnion()) {
+  while (!B.isRoot() && B.inUnion()) {
 // FIXME: Need to de-activate other fields of parent records.
 B.getInlineDesc()->IsActive = true;
 assert(B.isActive());
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index b0b279831405d..a51f30cd9185b 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -198,4 +198,59 @@ namespace UnionMemberDtor {
   }
   static_assert(foo() == 100);
 }
+
+namespace Nested {
+  union U {
+int a;
+int b;
+  };
+
+  union U2 {
+U u;
+U u2;
+int x;
+int y;
+  };
+
+ constexpr int foo() { // ref-error {{constexpr function never produces a 
constant expression}}
+U2 u;
+u.u.a = 10;
+int a = u.y; // both-note {{read of member 'y' of union with active member 
'u' is not allowed in a constant expression}} \
+ // ref-note {{read of member 'y' of union with active member 
'u' is not allowed in a constant expression}}
+
+return 1;
+  }
+  static_assert(foo() == 1); // both-error {{not an integral constant 
expression}} \
+ // both-note {{in call to}}
+
+ constexpr int foo2() {
+U2 u;
+u.u.a = 10;
+return u.u.a;
+  }
+  static_assert(foo2() == 10);
+
+ constexpr int foo3() { // ref-error {{constexpr function never produces a 
constant expression}}
+U2 u;
+u.u.a = 10;
+int a = u.u.b; // both-note {{read of member 'b' of union with active 
member 'a' is not allowed in a constant expression}} \
+   // ref-note {{read of member 'b' of union with active 
member 'a' is not allowed in a constant expression}}
+
+return 1;
+  }
+  static_assert(foo3() == 1); // both-error {{not an integral constant 
expression}} \
+  // both-note {{in call to}}
+
+  constexpr int foo4() { // ref-error {{constexpr function never produces a 
constant expression}}
+U2 u;
+
+u.x = 10;
+
+return u.u.a;// both-note {{read of member 'u' of union with active member 
'x' is not allowed in a constant expression}} \
+ // ref-note {{read of member 'u' of union with active member 
'x' is not allowed in a constant expression}}
+  }
+  static_assert(foo4() == 1); // both-error {{not an integral constant 
expression}} \
+  // both-note {{in c

[clang] [analyzer] Model overflow builtins (PR #102602)

2024-08-10 Thread Pavel Skripkin via cfe-commits


@@ -50,6 +101,44 @@ class BuiltinFunctionChecker : public Checker {
 
 } // namespace
 
+void BuiltinFunctionChecker::HandleOverflowBuiltin(const CallEvent &Call,
+   CheckerContext &C,
+   BinaryOperator::Opcode Op,
+   QualType ResultType) const {
+  // All __builtin_*_overflow functions take 3 argumets.
+  assert(Call.getNumArgs() == 3);
+
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  const Expr *CE = Call.getOriginExpr();
+
+  SVal Arg1 = Call.getArgSVal(0);
+  SVal Arg2 = Call.getArgSVal(1);
+
+  SVal RetVal = SVB.evalBinOp(State, Op, Arg1, Arg2, ResultType);
+
+  // TODO: Handle overflows with values that known to overflow. Like INT_MAX + 
1
+  // should not produce state for non-overflow case and threat it as

pskrgag wrote:

... which turns out to be bad idea, since it depends on `{i,u}128` support.

Will redo with Min/Max

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


[clang] [clang][Interp] Do not call dtors of union members (PR #102739)

2024-08-10 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clangd-ubuntu-tsan` 
running on `clangd-ubuntu-clang` while building `clang` at step 5 
"build-clangd-clangd-index-server-clangd-indexer".

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

Here is the relevant piece of the build log for the reference:
```
Step 5 (build-clangd-clangd-index-server-clangd-indexer) failure: build 
(failure)

```

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


[clang] 3b57f6b - [clang][Interp] Handle nested unions (#102743)

2024-08-10 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-10T14:16:47+02:00
New Revision: 3b57f6b4c76d9b54b1c42591fdddf0ddc86dc964

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

LOG: [clang][Interp] Handle nested unions (#102743)

Added: 


Modified: 
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Pointer.cpp
clang/test/AST/Interp/unions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 588680adb4616..89ac693893113 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -125,18 +125,15 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
   if (Ptr.isActive())
 return true;
 
-  // Get the inactive field descriptor.
-  const FieldDecl *InactiveField = Ptr.getField();
-  assert(InactiveField);
-
-  // Walk up the pointer chain to find the closest union.
   Pointer U = Ptr.getBase();
-  while (!U.getFieldDesc()->isUnion())
+  Pointer C = Ptr;
+  while (!U.isRoot() && U.inUnion() && !U.isActive()) {
+C = U;
 U = U.getBase();
-
-  // Find the active field of the union.
-  const Record *R = U.getRecord();
-  assert(R && R->isUnion() && "Not a union");
+  }
+  // Get the inactive field descriptor.
+  const FieldDecl *InactiveField = C.getField();
+  assert(InactiveField);
 
   // Consider:
   // union U {
@@ -148,10 +145,15 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
   //
   // When activating x, we will also activate a. If we now try to read
   // from y, we will get to CheckActive, because y is not active. In that
-  // case we return here and let later code handle this.
-  if (!llvm::is_contained(R->getDecl()->fields(), InactiveField))
+  // case, our U will be a (not a union). We return here and let later code
+  // handle this.
+  if (!U.getFieldDesc()->isUnion())
 return true;
 
+  // Find the active field of the union.
+  const Record *R = U.getRecord();
+  assert(R && R->isUnion() && "Not a union");
+
   const FieldDecl *ActiveField = nullptr;
   for (unsigned I = 0, N = R->getNumFields(); I < N; ++I) {
 const Pointer &Field = U.atField(R->getField(I)->Offset);

diff  --git a/clang/lib/AST/Interp/Pointer.cpp 
b/clang/lib/AST/Interp/Pointer.cpp
index f1f7a27c1400d..466e61666c76e 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -413,7 +413,7 @@ void Pointer::activate() const {
   }
 
   Pointer B = getBase();
-  while (!B.getFieldDesc()->isUnion()) {
+  while (!B.isRoot() && B.inUnion()) {
 // FIXME: Need to de-activate other fields of parent records.
 B.getInlineDesc()->IsActive = true;
 assert(B.isActive());

diff  --git a/clang/test/AST/Interp/unions.cpp 
b/clang/test/AST/Interp/unions.cpp
index b0b279831405d..a51f30cd9185b 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -198,4 +198,59 @@ namespace UnionMemberDtor {
   }
   static_assert(foo() == 100);
 }
+
+namespace Nested {
+  union U {
+int a;
+int b;
+  };
+
+  union U2 {
+U u;
+U u2;
+int x;
+int y;
+  };
+
+ constexpr int foo() { // ref-error {{constexpr function never produces a 
constant expression}}
+U2 u;
+u.u.a = 10;
+int a = u.y; // both-note {{read of member 'y' of union with active member 
'u' is not allowed in a constant expression}} \
+ // ref-note {{read of member 'y' of union with active member 
'u' is not allowed in a constant expression}}
+
+return 1;
+  }
+  static_assert(foo() == 1); // both-error {{not an integral constant 
expression}} \
+ // both-note {{in call to}}
+
+ constexpr int foo2() {
+U2 u;
+u.u.a = 10;
+return u.u.a;
+  }
+  static_assert(foo2() == 10);
+
+ constexpr int foo3() { // ref-error {{constexpr function never produces a 
constant expression}}
+U2 u;
+u.u.a = 10;
+int a = u.u.b; // both-note {{read of member 'b' of union with active 
member 'a' is not allowed in a constant expression}} \
+   // ref-note {{read of member 'b' of union with active 
member 'a' is not allowed in a constant expression}}
+
+return 1;
+  }
+  static_assert(foo3() == 1); // both-error {{not an integral constant 
expression}} \
+  // both-note {{in call to}}
+
+  constexpr int foo4() { // ref-error {{constexpr function never produces a 
constant expression}}
+U2 u;
+
+u.x = 10;
+
+return u.u.a;// both-note {{read of member 'u' of union with active member 
'x' is not allowed in a constant expression}} \
+ // ref-note {{read of member 'u' of union with active member 
'x' is not allowed in a constant expression}}
+  }
+  static_assert(foo4() == 1); // both-error {{not an integral const

[clang] [clang][Interp] Handle nested unions (PR #102743)

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

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


[clang] [clang][Interp] Don't zero-init unions (PR #102744)

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

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

Zero-initializing them would accidentally activate the members.

>From b0697976fe655ad9c08e95bc7095d28cda16dfda Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 10 Aug 2024 13:48:47 +0200
Subject: [PATCH] [clang][Interp] Don't zero-init unions

Zero-initializing them would accidentally activate the members.
---
 clang/lib/AST/Interp/Compiler.cpp |  2 +-
 clang/test/AST/Interp/unions.cpp  | 15 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index d0e4d409b6580..45999e120b312 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -2523,7 +2523,7 @@ bool Compiler::VisitCXXConstructExpr(const 
CXXConstructExpr *E) {
 if (E->requiresZeroInitialization()) {
   const Record *R = getRecord(E->getType());
 
-  if (!this->visitZeroRecordInitializer(R, E))
+  if (!R->isUnion() && !this->visitZeroRecordInitializer(R, E))
 return false;
 
   // If the constructor is trivial anyway, we're done.
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index a51f30cd9185b..40edebe5de407 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -253,4 +253,19 @@ namespace Nested {
   // both-note {{in call to}}
 
 }
+
+
+namespace Zeroing {
+  struct non_trivial_constructor {
+  constexpr non_trivial_constructor() : x(100) {}
+  int x;
+  };
+  union U2 {
+  int a{1000};
+  non_trivial_constructor b;
+  };
+
+  static_assert(U2().b.x == 100, ""); // both-error {{not an integral constant 
expression}} \
+  // both-note {{read of member 'b' of 
union with active member 'a'}}
+}
 #endif

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


[clang] [clang][Interp] Do not call dtors of union members (PR #102739)

2024-08-10 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

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

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

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)
...
[373/378] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[374/378] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o
[375/378] Generating Msan-x86_64-with-call-Test
[376/378] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64.o
[377/378] Generating Msan-x86_64-Test
[377/378] Running compiler_rt regression tests
llvm-lit: 
/home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/discovery.py:276:
 warning: input 
'/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/rtsan/X86_64LinuxConfig'
 contained no tests
llvm-lit: 
/home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 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: 4495 of 10175 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60
FAIL: SanitizerCommon-lsan-i386-Linux :: Linux/soft_rss_limit_mb_test.cpp (2939 
of 4495)
 TEST 'SanitizerCommon-lsan-i386-Linux :: 
Linux/soft_rss_limit_mb_test.cpp' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang  
--driver-mode=g++ -gline-tables-only -fsanitize=leak  -m32 -funwind-tables  
-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O2 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp
 -o 
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
+ /home/b/sanitizer-x86_64-linux/build/build_default/./bin/clang 
--driver-mode=g++ -gline-tables-only -fsanitize=leak -m32 -funwind-tables 
-I/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test -ldl -O2 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp
 -o 
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
RUN: at line 5: env 
LSAN_OPTIONS=soft_rss_limit_mb=220:quarantine_size=1:allocator_may_return_null=1
  
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
 2>&1 | FileCheck 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp
 -check-prefix=CHECK_MAY_RETURN_1
+ env 
LSAN_OPTIONS=soft_rss_limit_mb=220:quarantine_size=1:allocator_may_return_null=1
 
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/lsan-i386-Linux/Linux/Output/soft_rss_limit_mb_test.cpp.tmp
+ FileCheck 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp
 -check-prefix=CHECK_MAY_RETURN_1
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp:68:24:
 error: CHECK_MAY_RETURN_1: expected string not found in input
// CHECK_MAY_RETURN_1: allocating 512 times
   ^
:52:44: note: scanning from here
Some of the malloc calls returned non-null: 256
   ^
:53:14: note: possible intended match here
==2043716==LeakSanitizer: soft rss limit unexhausted (220Mb vs 3Mb)
 ^

Input file: 
Check file: 
/home/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cpp

-dump-input=help explains the following input dump.

Input was:
<<
.
.
.
   47:  [256] 
   48:  [320] 
   49:  [384] 
   50:  [448] 
   51: Some of the malloc calls returned null: 256 
   52: Some of the malloc calls returned non-null: 256 
check:68'0X error: no match 
found
   53: ==2043716==LeakSanitizer: soft rss limit unexhausted (220Mb vs 
3Mb) 
Step 11 (test compiler-rt debug) failure: test compiler-rt debug (failure)
...
[373/378] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[374/378] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.

[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)

2024-08-10 Thread Vlad Serebrennikov via cfe-commits


@@ -386,6 +386,10 @@ def __contains__(self, other):
 # same file, in between lines
 if self.start.line < other.line < self.end.line:
 return True
+# between columns in one-liner range
+elif self.start.line == other.line == self.end.line:

Endilll wrote:

> On C++ side, in SourceLocation.h we implement operator==, operator<= both as 
> direct comparisons on the raw encoding (SourceLocation::getRawEncoding()). 
> This is not file-sensitive.*

I believe raw encoding is file-sensitive.

If you say that `clang_equalLocations` is file-sensitive, then 
`SourceLocation::operator==` is file-sensitive, too. If you look at how 
`CXSourceLocation` are initialized, `int_data` is raw encoding, and 
`ptr_data[0]` is `SourceManager` (`ptr_data[1]` seems to be a dead weight).

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


[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)

2024-08-10 Thread Vlad Serebrennikov via cfe-commits


@@ -386,6 +386,10 @@ def __contains__(self, other):
 # same file, in between lines
 if self.start.line < other.line < self.end.line:
 return True
+# between columns in one-liner range
+elif self.start.line == other.line == self.end.line:

Endilll wrote:

As I understand it, raw encoding can be thought of as an offset in preprocessed 
source where `#include`s and macros are substituted, but macro definitions are 
kept intact for source location purposes.

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


[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)

2024-08-10 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang][Interp] Don't zero-init unions (PR #102744)

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

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

>From 40e78a52c9cbbce88f8a5609eccb20d4aa16ce5e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 10 Aug 2024 13:48:47 +0200
Subject: [PATCH] [clang][Interp] Only zero-init first union member

---
 clang/lib/AST/Interp/Compiler.cpp | 21 ++-
 clang/test/AST/Interp/records.cpp |  8 +++---
 clang/test/AST/Interp/unions.cpp  | 45 +++
 3 files changed, 56 insertions(+), 18 deletions(-)

diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index d0e4d409b65807..6c4d607706c6b9 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -1386,18 +1386,8 @@ bool Compiler::visitInitList(ArrayRef Inits,
 
 if (R->isUnion()) {
   if (Inits.size() == 0) {
-// Zero-initialize the first union field.
-if (R->getNumFields() == 0)
-  return this->emitFinishInit(E);
-const Record::Field *FieldToInit = R->getField(0u);
-QualType FieldType = FieldToInit->Desc->getType();
-if (std::optional T = classify(FieldType)) {
-  if (!this->visitZeroInitializer(*T, FieldType, E))
-return false;
-  if (!this->emitInitField(*T, FieldToInit->Offset, E))
-return false;
-}
-// FIXME: Non-primitive case?
+if (!this->visitZeroRecordInitializer(R, E))
+  return false;
   } else {
 const Expr *Init = Inits[0];
 const FieldDecl *FToInit = nullptr;
@@ -3374,6 +3364,8 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
 return false;
   if (!this->emitInitField(T, Field.Offset, E))
 return false;
+  if (R->isUnion())
+break;
   continue;
 }
 
@@ -3409,8 +3401,11 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
   assert(false);
 }
 
-if (!this->emitPopPtr(E))
+if (!this->emitFinishInitPop(E))
   return false;
+
+if (R->isUnion())
+  break;
   }
 
   for (const Record::Base &B : R->bases()) {
diff --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 9c8c1c344e1e8d..343665003c23ec 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -964,8 +964,6 @@ namespace TemporaryObjectExpr {
 static_assert(foo(F()) == 0, "");
   }
 
-  /// FIXME: This needs support for unions on the new interpreter.
-  /// We diagnose an uninitialized object in c++14.
 #if __cplusplus > 201402L
   namespace Unions {
 struct F {
@@ -978,10 +976,10 @@ namespace TemporaryObjectExpr {
 };
 
 constexpr int foo(F f) {
-  return f.i + f.U.f; // ref-note {{read of member 'f' of union with 
active member 'a'}}
+  return f.i + f.U.f; // both-note {{read of member 'f' of union with 
active member 'a'}}
 }
-static_assert(foo(F()) == 0, ""); // ref-error {{not an integral constant 
expression}} \
-  // ref-note {{in call to}}
+static_assert(foo(F()) == 0, ""); // both-error {{not an integral constant 
expression}} \
+  // both-note {{in call to}}
   }
 #endif
 
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index a51f30cd9185b4..6f6bc3d6891b4b 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -253,4 +253,49 @@ namespace Nested {
   // both-note {{in call to}}
 
 }
+
+
+namespace Zeroing {
+  struct non_trivial_constructor {
+  constexpr non_trivial_constructor() : x(100) {}
+  int x;
+  };
+  union U2 {
+  int a{1000};
+  non_trivial_constructor b;
+  };
+
+  static_assert(U2().b.x == 100, ""); // both-error {{not an integral constant 
expression}} \
+  // both-note {{read of member 'b' of 
union with active member 'a'}}
+
+  union { int a; int b; } constexpr u1{};
+  static_assert(u1.a == 0, "");
+  static_assert(u1.b == 0, ""); // both-error {{not an integral constant 
expression}} \
+// both-note {{read of member 'b' of union 
with active member 'a'}}
+
+  union U { int a; int b; } constexpr u2 = U();
+  static_assert(u2.a == 0, "");
+  static_assert(u2.b == 0, ""); // both-error {{not an integral constant 
expression}} \
+// both-note {{read of member 'b' of union 
with active member 'a'}}
+
+
+  struct F {int x; int y; };
+  union { F a; int b; } constexpr u3{};
+  static_assert(u3.a.x == 0, "");
+
+  union U4 { F a; int b; } constexpr u4 = U4();
+  static_assert(u4.a.x == 0, "");
+
+  union { int a[5]; int b; } constexpr u5{};
+  static_assert(u5.a[0] == 0, "");
+  static_assert(u5.a[4] == 0, "");
+  static_assert(u5.b == 0, ""); // both-error {{not an integral constant 
expression}} \
+// both-note {{read of member 'b' of un

[clang] [clang][Interp] Only zero-init first union member (PR #102744)

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

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


[clang] [clang][Interp] Only zero-init first union member (PR #102744)

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

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


[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)

2024-08-10 Thread Jannick Kremer via cfe-commits


@@ -386,6 +386,10 @@ def __contains__(self, other):
 # same file, in between lines
 if self.start.line < other.line < self.end.line:
 return True
+# between columns in one-liner range
+elif self.start.line == other.line == self.end.line:

DeinAlptraum wrote:

Okay, that was my mistake: when testing this, I created two separate TUs for 
the two files, and _that_ is apparently where it's sensitive. So no issue on 
the C-side here after al.

Going back to the Python bindings: we are now left with a pre-existing 
`SourceLocation.__eq__` that _is_ file-sensitive, and in order to have a clean 
implementation, we would like a `SourceLocation.__le__` / 
`SourceLOcation.__lt__` that is _not_ file-sensitive, so it can be used for 
`SourceRange.__contains__`. 
Exposing something like this would be ugly due to inconsistency. So I guess it 
would be the easiest to implement such an `operator<=` function just locally 
inside `SourceRange.__contains__` to simplify the logic there, and not expose 
any new functionality at all. What do you think?

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


[clang] [Clang][Sema][OpenMP] Allow `thread_limit` to accept multiple expressions (PR #102715)

2024-08-10 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev approved this pull request.

LG

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


[clang] [Clang][OpenMP] Fix the wrong transform of `num_teams` claused introduced in #99732 (PR #102716)

2024-08-10 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev commented:

A test is required

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


[clang] [ASTDump] TextNodeDumper learned to dump builtin name for AtomicExpr (PR #102748)

2024-08-10 Thread via cfe-commits

https://github.com/Enna1 created 
https://github.com/llvm/llvm-project/pull/102748

In 4198576157bfd0d08c08b784220d6132b709ae2c, we add support for dumping builtin 
name for AtomicExpr in JSON dump. This change syncs `TextNodeDumper` with 
`JSONNodeDumper`, makes `TextNodeDumper` learned to dump builtin name for 
AtomicExpr.

>From e620ac09ec73d5bab8259164241c80eec559db10 Mon Sep 17 00:00:00 2001
From: "xumingjie.enna1" 
Date: Sat, 10 Aug 2024 20:42:37 +0800
Subject: [PATCH] [ASTDump] TextNodeDumper learned to dump builtin name for
 AtomicExpr

In 4198576157bfd0d08c08b784220d6132b709ae2c, we add support for dumping builtin 
name for AtomicExpr in JSON dump.
This change syncs `TextNodeDumper` with `JSONNodeDumper`, makes 
`TextNodeDumper` learned to dump builtin name for AtomicExpr.
---
 clang/include/clang/AST/TextNodeDumper.h | 1 +
 clang/lib/AST/TextNodeDumper.cpp | 4 
 clang/test/AST/atomic-expr.cpp   | 8 
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 39dd1f515c9eb3..88d5535829910f 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -410,6 +410,7 @@ class TextNodeDumper
   void VisitOpenACCConstructStmt(const OpenACCConstructStmt *S);
   void VisitOpenACCLoopConstruct(const OpenACCLoopConstruct *S);
   void VisitEmbedExpr(const EmbedExpr *S);
+  void VisitAtomicExpr(const AtomicExpr *AE);
 };
 
 } // namespace clang
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 388c927c9aa558..d50d4c7028c697 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -2892,3 +2892,7 @@ void TextNodeDumper::VisitEmbedExpr(const EmbedExpr *S) {
   AddChild("begin", [=] { OS << S->getStartingElementPos(); });
   AddChild("number of elements", [=] { OS << S->getDataElementCount(); });
 }
+
+void TextNodeDumper::VisitAtomicExpr(const AtomicExpr *AE) {
+  OS << ' ' << AE->getOpAsString();
+}
diff --git a/clang/test/AST/atomic-expr.cpp b/clang/test/AST/atomic-expr.cpp
index bdb7bcb00569a1..d9d632ffc5917b 100644
--- a/clang/test/AST/atomic-expr.cpp
+++ b/clang/test/AST/atomic-expr.cpp
@@ -25,14 +25,14 @@ void useage(){
 }
 
 // CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}} <{{[^,]+}}, line:{{.*}}:1> 
line:{{.*}}:6 pr43370
-// CHECK: AtomicExpr
+// CHECK: AtomicExpr 0x{{[0-9a-f]+}} <{{.*}}> 'void' __atomic_store_n
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
 // CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int[2]' lvalue Var 
0x{{[0-9a-f]+}} 'arr' 'int[2]'
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
 // CHECK:FunctionDecl 0x{{[0-9a-f]+}}  
line:{{.*}}:6 used pr43370
-// CHECK: AtomicExpr
+// CHECK: AtomicExpr 0x{{[0-9a-f]+}} <{{.*}}> 'void' __atomic_store_n
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
 // CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int[2]' lvalue Var 
0x{{[0-9a-f]+}} 'arr' 'int[2]'
@@ -40,7 +40,7 @@ void useage(){
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
 
 // CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}}  
line:{{.*}}:6 foo
-// CHECK: AtomicExpr
+// CHECK: AtomicExpr 0x{{[0-9a-f]+}} <{{.*}}> 'bool' 
__atomic_compare_exchange_n
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
 // CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:37> 'int[2]' lvalue Var 
0x{{[0-9a-f]+}} 'arr' 'int[2]'
@@ -53,7 +53,7 @@ void useage(){
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:50> 'int' 0
 // CHECK:FunctionDecl 0x{{[0-9a-f]+}}  
line:{{.*}}:6 used foo
-// CHECK: AtomicExpr
+// CHECK: AtomicExpr 0x{{[0-9a-f]+}} <{{.*}}> 'bool' 
__atomic_compare_exchange_n
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
 // CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:37> 'int[2]' lvalue Var 
0x{{[0-9a-f]+}} 'arr' 'int[2]'

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


[clang] ac47edd - [clang][Interp] Only zero-init first union member (#102744)

2024-08-10 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-10T15:25:08+02:00
New Revision: ac47edd8a9dadc15aa7b6557e3ac03512aa1cf6f

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

LOG: [clang][Interp] Only zero-init first union member (#102744)

Zero-initializing all of them accidentally left the last member active.
Only initialize the first one.

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/test/AST/Interp/records.cpp
clang/test/AST/Interp/unions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index d0e4d409b6580..6c4d607706c6b 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -1386,18 +1386,8 @@ bool Compiler::visitInitList(ArrayRef Inits,
 
 if (R->isUnion()) {
   if (Inits.size() == 0) {
-// Zero-initialize the first union field.
-if (R->getNumFields() == 0)
-  return this->emitFinishInit(E);
-const Record::Field *FieldToInit = R->getField(0u);
-QualType FieldType = FieldToInit->Desc->getType();
-if (std::optional T = classify(FieldType)) {
-  if (!this->visitZeroInitializer(*T, FieldType, E))
-return false;
-  if (!this->emitInitField(*T, FieldToInit->Offset, E))
-return false;
-}
-// FIXME: Non-primitive case?
+if (!this->visitZeroRecordInitializer(R, E))
+  return false;
   } else {
 const Expr *Init = Inits[0];
 const FieldDecl *FToInit = nullptr;
@@ -3374,6 +3364,8 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
 return false;
   if (!this->emitInitField(T, Field.Offset, E))
 return false;
+  if (R->isUnion())
+break;
   continue;
 }
 
@@ -3409,8 +3401,11 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
   assert(false);
 }
 
-if (!this->emitPopPtr(E))
+if (!this->emitFinishInitPop(E))
   return false;
+
+if (R->isUnion())
+  break;
   }
 
   for (const Record::Base &B : R->bases()) {

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 9c8c1c344e1e8..343665003c23e 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -964,8 +964,6 @@ namespace TemporaryObjectExpr {
 static_assert(foo(F()) == 0, "");
   }
 
-  /// FIXME: This needs support for unions on the new interpreter.
-  /// We diagnose an uninitialized object in c++14.
 #if __cplusplus > 201402L
   namespace Unions {
 struct F {
@@ -978,10 +976,10 @@ namespace TemporaryObjectExpr {
 };
 
 constexpr int foo(F f) {
-  return f.i + f.U.f; // ref-note {{read of member 'f' of union with 
active member 'a'}}
+  return f.i + f.U.f; // both-note {{read of member 'f' of union with 
active member 'a'}}
 }
-static_assert(foo(F()) == 0, ""); // ref-error {{not an integral constant 
expression}} \
-  // ref-note {{in call to}}
+static_assert(foo(F()) == 0, ""); // both-error {{not an integral constant 
expression}} \
+  // both-note {{in call to}}
   }
 #endif
 

diff  --git a/clang/test/AST/Interp/unions.cpp 
b/clang/test/AST/Interp/unions.cpp
index a51f30cd9185b..6f6bc3d6891b4 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -253,4 +253,49 @@ namespace Nested {
   // both-note {{in call to}}
 
 }
+
+
+namespace Zeroing {
+  struct non_trivial_constructor {
+  constexpr non_trivial_constructor() : x(100) {}
+  int x;
+  };
+  union U2 {
+  int a{1000};
+  non_trivial_constructor b;
+  };
+
+  static_assert(U2().b.x == 100, ""); // both-error {{not an integral constant 
expression}} \
+  // both-note {{read of member 'b' of 
union with active member 'a'}}
+
+  union { int a; int b; } constexpr u1{};
+  static_assert(u1.a == 0, "");
+  static_assert(u1.b == 0, ""); // both-error {{not an integral constant 
expression}} \
+// both-note {{read of member 'b' of union 
with active member 'a'}}
+
+  union U { int a; int b; } constexpr u2 = U();
+  static_assert(u2.a == 0, "");
+  static_assert(u2.b == 0, ""); // both-error {{not an integral constant 
expression}} \
+// both-note {{read of member 'b' of union 
with active member 'a'}}
+
+
+  struct F {int x; int y; };
+  union { F a; int b; } constexpr u3{};
+  static_assert(u3.a.x == 0, "");
+
+  union U4 { F a; int b; } constexpr u4 = U4();
+  static_assert(u4.a.x == 0, "");
+
+  union { int a[5]; int b; } constexpr u5{};
+  static_assert(u5.a[0] == 0, "");
+  static_assert(u5.a[4] == 

[clang] [clang][Interp] Only zero-init first union member (PR #102744)

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

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


[clang] [clang][Interp] Ignore unnamed bitfields when zeroing records (PR #102749)

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

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

Including unions, where this is more important.

>From e2a9a796b2beb2dcee0f8ec974cc548427091af4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 10 Aug 2024 15:19:55 +0200
Subject: [PATCH] [clang][Interp] Ignore unnamed bitfields when zeroing records

Including unions, where this is more important.
---
 clang/lib/AST/Interp/Compiler.cpp | 3 +++
 clang/test/AST/Interp/unions.cpp  | 8 
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 6c4d607706c6b..1fa7a98fb 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -3356,6 +3356,9 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
   assert(R);
   // Fields
   for (const Record::Field &Field : R->fields()) {
+if (Field.Decl->isUnnamedBitField())
+  continue;
+
 const Descriptor *D = Field.Desc;
 if (D->isPrimitive()) {
   QualType QT = D->getType();
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index 6f6bc3d6891b4..1f52950b1e09b 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -297,5 +297,13 @@ namespace Zeroing {
   static_assert(u6.a[4] == 0, "");
   static_assert(u6.b == 0, ""); // both-error {{not an integral constant 
expression}} \
 // both-note {{read of member 'b' of union 
with active member 'a'}}
+
+  union UnionWithUnnamedBitfield {
+int : 3;
+int n;
+  };
+  static_assert(UnionWithUnnamedBitfield().n == 0, "");
+  static_assert(UnionWithUnnamedBitfield{}.n == 0, "");
+  static_assert(UnionWithUnnamedBitfield{1}.n == 1, "");
 }
 #endif

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


[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)

2024-08-10 Thread Vlad Serebrennikov via cfe-commits


@@ -386,6 +386,10 @@ def __contains__(self, other):
 # same file, in between lines
 if self.start.line < other.line < self.end.line:
 return True
+# between columns in one-liner range
+elif self.start.line == other.line == self.end.line:

Endilll wrote:

> and in order to have a clean implementation, we would like a 
> SourceLocation.__le__ / SourceLOcation.__lt__ that is not file-sensitive

I'm against anything non file-sensitive, because that's buggy and is going to 
surprise everyone. I'm less concerned with cleanliness of implementation in the 
face of this concern.

At this point I'm even more concerned by amount of places that interpret raw 
encoding of `SourceLocation`, even though (in my understanding) `SourceManager` 
is the only entity that should do so. I'd like to hear from Aaron on Monday on 
this. After that it should be more clear how we should proceed on all three 
levels of our API.

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


[clang] [Clang][OpenMP] Fix the wrong transform of `num_teams` claused introduced in #99732 (PR #102716)

2024-08-10 Thread Shilei Tian via cfe-commits

shiltian wrote:

> A test is required

I literally don't know how to test this TBH. I think our current OpenMP tests 
generally don't cover this at all.

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


[clang] 1c26992 - [Clang][Sema][OpenMP] Allow `thread_limit` to accept multiple expressions (#102715)

2024-08-10 Thread via cfe-commits

Author: Shilei Tian
Date: 2024-08-10T09:54:58-04:00
New Revision: 1c269929d03e4a664a1f05d494b8fefe291ef8c0

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

LOG: [Clang][Sema][OpenMP] Allow `thread_limit` to accept multiple expressions 
(#102715)

Added: 


Modified: 
clang/docs/OpenMPSupport.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Sema/SemaOpenMP.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/target_teams_ast_print.cpp
clang/test/OpenMP/target_teams_distribute_num_teams_messages.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_num_teams_messages.cpp
clang/test/OpenMP/teams_num_teams_messages.cpp
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index 3fc74cdd07f71c..cdbd69520e5bb5 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -363,7 +363,8 @@ considered for standardization. Please post on the
 | device extension | `'ompx_bare' clause on 'target teams' 
construct   | :good:`prototyped`   | 
#66844, #70612 |
 |  | 
`_  
  |  |  
  |
 
+--+---+--++
-| device extension | Multi-dim 'num_teams' clause on 'target teams 
ompx_bare' construct| :good:`partial`  | #99732, 
#101407|
+| device extension | Multi-dim 'num_teams' and 'thread_limit' 
clause on 'target teams ompx_bare'   | :good:`partial`  | #99732, 
#101407, #102715   |
+|  | construct 
|  |
|
 
+--+---+--++
 
 .. _Discourse forums (Runtimes - OpenMP category): 
https://discourse.llvm.org/c/runtimes/openmp/35

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 351b41b1c0c588..602f3edaf121cb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -360,8 +360,9 @@ Improvements
 
 - Improve the handling of mapping array-section for struct containing nested 
structs with user defined mappers
 
-- `num_teams` now accepts multiple expressions when it is used along in 
``target teams ompx_bare`` construct.
-  This allows the target region to be launched with multi-dim grid on GPUs.
+- `num_teams` and `thead_limit` now accept multiple expressions when it is used
+  along in ``target teams ompx_bare`` construct. This allows the target region
+  to be launched with multi-dim grid on GPUs.
 
 Additional Information
 ==

diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 1e830b14727c19..c1b9e0dbafb6c3 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -6462,44 +6462,55 @@ class OMPNumTeamsClause final
 /// \endcode
 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
 /// with single expression 'n'.
-class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit {
-  friend class OMPClauseReader;
+///
+/// When 'ompx_bare' clause exists on a 'target' directive, 'thread_limit'
+/// clause can accept up to three expressions.
+///
+/// \code
+/// #pragma omp target teams ompx_bare thread_limit(x, y, z)
+/// \endcode
+class OMPThreadLimitClause final
+: public OMPVarListClause,
+  public OMPClauseWithPreInit,
+  private llvm::TrailingObjects {
+  friend OMPVarListClause;
+  friend TrailingObjects;
 
   /// Location of '('.
   SourceLocation LParenLoc;
 
-  /// ThreadLimit number.
-  Stmt *ThreadLimit = nullptr;
+  OMPThreadLimitClause(

[clang] [Clang][Sema][OpenMP] Allow `thread_limit` to accept multiple expressions (PR #102715)

2024-08-10 Thread Shilei Tian via cfe-commits

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


[clang] [llvm] [Clang][OMPX] Add the code generation for multi-dim `thread_limit` clause (PR #102717)

2024-08-10 Thread Shilei Tian via cfe-commits

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


[clang] 8d908b8 - [clang][Interp] Ignore unnamed bitfields when zeroing records (#102749)

2024-08-10 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-10T15:56:19+02:00
New Revision: 8d908b8cc5f4b3aeb2303437a9c2d35654279fd9

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

LOG: [clang][Interp] Ignore unnamed bitfields when zeroing records (#102749)

Including unions, where this is more important.

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/test/AST/Interp/unions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 6c4d607706c6b..1fa7a98fb 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -3356,6 +3356,9 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
   assert(R);
   // Fields
   for (const Record::Field &Field : R->fields()) {
+if (Field.Decl->isUnnamedBitField())
+  continue;
+
 const Descriptor *D = Field.Desc;
 if (D->isPrimitive()) {
   QualType QT = D->getType();

diff  --git a/clang/test/AST/Interp/unions.cpp 
b/clang/test/AST/Interp/unions.cpp
index 6f6bc3d6891b4..1f52950b1e09b 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -297,5 +297,13 @@ namespace Zeroing {
   static_assert(u6.a[4] == 0, "");
   static_assert(u6.b == 0, ""); // both-error {{not an integral constant 
expression}} \
 // both-note {{read of member 'b' of union 
with active member 'a'}}
+
+  union UnionWithUnnamedBitfield {
+int : 3;
+int n;
+  };
+  static_assert(UnionWithUnnamedBitfield().n == 0, "");
+  static_assert(UnionWithUnnamedBitfield{}.n == 0, "");
+  static_assert(UnionWithUnnamedBitfield{1}.n == 1, "");
 }
 #endif



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


[clang] [clang][Interp] Ignore unnamed bitfields when zeroing records (PR #102749)

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

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


[clang] [clang][Interp] Fix activating via indirect field initializers (PR #102753)

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

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

Pointer::activate() propagates up anyway, so that is handled. But we need to 
call activate() in any case since the parent might not be a union, but the 
activate() is still needed. Always call it and hope that the InUnion flag takes 
care of the potential performance problems.

>From 082892fff50e3e971c2b1a9394a3a088f697ed0b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 10 Aug 2024 15:45:14 +0200
Subject: [PATCH] [clang][Interp] Fix activating via indirect field
 initializers

Pointer::activate() propagates up anyway, so that is handled. But
we need to call activate() in any case since the parent might not
be a union, but the activate() is still needed. Always call it and
hope that the InUnion flag takes care of the potential performance
problems.
---
 clang/lib/AST/Interp/Compiler.cpp | 14 ---
 clang/lib/AST/Interp/Interp.h | 26 +---
 clang/lib/AST/Interp/Opcodes.td   |  4 ---
 clang/test/AST/Interp/unions.cpp  | 41 +++
 4 files changed, 47 insertions(+), 38 deletions(-)

diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 1fa7a98fb3..5bed71392740eb 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -4737,8 +4737,7 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
   // Classify the return type.
   ReturnType = this->classify(F->getReturnType());
 
-  auto emitFieldInitializer = [&](const Record *R, const Record::Field *F,
-  unsigned FieldOffset,
+  auto emitFieldInitializer = [&](const Record::Field *F, unsigned FieldOffset,
   const Expr *InitExpr) -> bool {
 // We don't know what to do with these, so just return false.
 if (InitExpr->getType().isNull())
@@ -4750,8 +4749,6 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
 
   if (F->isBitField())
 return this->emitInitThisBitField(*T, F, FieldOffset, InitExpr);
-  if (R->isUnion())
-return this->emitInitThisFieldActive(*T, FieldOffset, InitExpr);
   return this->emitInitThisField(*T, FieldOffset, InitExpr);
 }
 // Non-primitive case. Get a pointer to the field-to-initialize
@@ -4787,7 +4784,7 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
   if (const FieldDecl *Member = Init->getMember()) {
 const Record::Field *F = R->getField(Member);
 
-if (!emitFieldInitializer(R, F, F->Offset, InitExpr))
+if (!emitFieldInitializer(F, F->Offset, InitExpr))
   return false;
   } else if (const Type *Base = Init->getBaseClass()) {
 const auto *BaseDecl = Base->getAsCXXRecordDecl();
@@ -4815,11 +4812,11 @@ bool Compiler::visitFunc(const FunctionDecl 
*F) {
 assert(IFD->getChainingSize() >= 2);
 
 unsigned NestedFieldOffset = 0;
-const Record *FieldRecord = nullptr;
 const Record::Field *NestedField = nullptr;
 for (const NamedDecl *ND : IFD->chain()) {
   const auto *FD = cast(ND);
-  FieldRecord = this->P.getOrCreateRecord(FD->getParent());
+  const Record *FieldRecord =
+  this->P.getOrCreateRecord(FD->getParent());
   assert(FieldRecord);
 
   NestedField = FieldRecord->getField(FD);
@@ -4829,8 +4826,7 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
 }
 assert(NestedField);
 
-if (!emitFieldInitializer(FieldRecord, NestedField, NestedFieldOffset,
-  InitExpr))
+if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr))
   return false;
   } else {
 assert(Init->isDelegatingInitializer());
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 196fc15a77519b..af33d507ef8d73 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1391,6 +1391,7 @@ bool InitThisField(InterpState &S, CodePtr OpPC, uint32_t 
I) {
 return false;
   const Pointer &Field = This.atField(I);
   Field.deref() = S.Stk.pop();
+  Field.activate();
   Field.initialize();
   return true;
 }
@@ -1413,20 +1414,6 @@ bool InitThisBitField(InterpState &S, CodePtr OpPC, 
const Record::Field *F,
   return true;
 }
 
-template ::T>
-bool InitThisFieldActive(InterpState &S, CodePtr OpPC, uint32_t I) {
-  if (S.checkingPotentialConstantExpression())
-return false;
-  const Pointer &This = S.Current->getThis();
-  if (!CheckThis(S, OpPC, This))
-return false;
-  const Pointer &Field = This.atField(I);
-  Field.deref() = S.Stk.pop();
-  Field.activate();
-  Field.initialize();
-  return true;
-}
-
 /// 1) Pops the value from the stack
 /// 2) Peeks a pointer from the stack
 /// 3) Pushes the value to field I of the pointer on the stack
@@ -1451,17 +1438,6 @@ bool InitBitField(InterpState &S, CodePtr OpPC, const 
Record::Field *F) {
   return tr

[clang] [Clang][OpenMP] Fix the wrong transform of `num_teams` claused introduced in #99732 (PR #102716)

2024-08-10 Thread Alexey Bataev via cfe-commits

alexey-bataev wrote:

> > A test is required
> 
> 
> 
> I literally don't know how to test this TBH. I think our current OpenMP tests 
> generally don't cover this at all.

They do. To test this, you need to use clause in the template and check that 
template params successfully replaced upon instantiation.

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


[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)

2024-08-10 Thread Jannick Kremer via cfe-commits

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


[clang] [SPARC][clang] Add -m(no-)v8plus flags handling (PR #98713)

2024-08-10 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.


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


[clang] [SPARC][Driver] Add -m(no-)v8plus flags handling (PR #98713)

2024-08-10 Thread Sergei Barannikov via cfe-commits

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


[clang] 9d6cec5 - [clang][Interp] Fix activating via indirect field initializers (#102753)

2024-08-10 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-10T16:32:15+02:00
New Revision: 9d6cec5f349d4e26ac8610565dbbe4678a965278

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

LOG: [clang][Interp] Fix activating via indirect field initializers (#102753)

Pointer::activate() propagates up anyway, so that is handled. But we
need to call activate() in any case since the parent might not be a
union, but the activate() is still needed. Always call it and hope that
the InUnion flag takes care of the potential performance problems.

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/unions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 1fa7a98fb..5bed71392740e 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -4737,8 +4737,7 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
   // Classify the return type.
   ReturnType = this->classify(F->getReturnType());
 
-  auto emitFieldInitializer = [&](const Record *R, const Record::Field *F,
-  unsigned FieldOffset,
+  auto emitFieldInitializer = [&](const Record::Field *F, unsigned FieldOffset,
   const Expr *InitExpr) -> bool {
 // We don't know what to do with these, so just return false.
 if (InitExpr->getType().isNull())
@@ -4750,8 +4749,6 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
 
   if (F->isBitField())
 return this->emitInitThisBitField(*T, F, FieldOffset, InitExpr);
-  if (R->isUnion())
-return this->emitInitThisFieldActive(*T, FieldOffset, InitExpr);
   return this->emitInitThisField(*T, FieldOffset, InitExpr);
 }
 // Non-primitive case. Get a pointer to the field-to-initialize
@@ -4787,7 +4784,7 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
   if (const FieldDecl *Member = Init->getMember()) {
 const Record::Field *F = R->getField(Member);
 
-if (!emitFieldInitializer(R, F, F->Offset, InitExpr))
+if (!emitFieldInitializer(F, F->Offset, InitExpr))
   return false;
   } else if (const Type *Base = Init->getBaseClass()) {
 const auto *BaseDecl = Base->getAsCXXRecordDecl();
@@ -4815,11 +4812,11 @@ bool Compiler::visitFunc(const FunctionDecl 
*F) {
 assert(IFD->getChainingSize() >= 2);
 
 unsigned NestedFieldOffset = 0;
-const Record *FieldRecord = nullptr;
 const Record::Field *NestedField = nullptr;
 for (const NamedDecl *ND : IFD->chain()) {
   const auto *FD = cast(ND);
-  FieldRecord = this->P.getOrCreateRecord(FD->getParent());
+  const Record *FieldRecord =
+  this->P.getOrCreateRecord(FD->getParent());
   assert(FieldRecord);
 
   NestedField = FieldRecord->getField(FD);
@@ -4829,8 +4826,7 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
 }
 assert(NestedField);
 
-if (!emitFieldInitializer(FieldRecord, NestedField, NestedFieldOffset,
-  InitExpr))
+if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr))
   return false;
   } else {
 assert(Init->isDelegatingInitializer());

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 196fc15a77519..af33d507ef8d7 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1391,6 +1391,7 @@ bool InitThisField(InterpState &S, CodePtr OpPC, uint32_t 
I) {
 return false;
   const Pointer &Field = This.atField(I);
   Field.deref() = S.Stk.pop();
+  Field.activate();
   Field.initialize();
   return true;
 }
@@ -1413,20 +1414,6 @@ bool InitThisBitField(InterpState &S, CodePtr OpPC, 
const Record::Field *F,
   return true;
 }
 
-template ::T>
-bool InitThisFieldActive(InterpState &S, CodePtr OpPC, uint32_t I) {
-  if (S.checkingPotentialConstantExpression())
-return false;
-  const Pointer &This = S.Current->getThis();
-  if (!CheckThis(S, OpPC, This))
-return false;
-  const Pointer &Field = This.atField(I);
-  Field.deref() = S.Stk.pop();
-  Field.activate();
-  Field.initialize();
-  return true;
-}
-
 /// 1) Pops the value from the stack
 /// 2) Peeks a pointer from the stack
 /// 3) Pushes the value to field I of the pointer on the stack
@@ -1451,17 +1438,6 @@ bool InitBitField(InterpState &S, CodePtr OpPC, const 
Record::Field *F) {
   return true;
 }
 
-template ::T>
-bool InitFieldActive(InterpState &S, CodePtr OpPC, uint32_t I) {
-  const T &Value = S.Stk.pop();
-  const Pointer &Ptr = S.Stk.pop();
-  const Pointer &Field = Ptr.atField(I);
-  Field.deref() = Value;
-  Field.

[clang] [clang][Interp] Fix activating via indirect field initializers (PR #102753)

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

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


[clang] [clang][Interp] Do not call dtors of union members (PR #102739)

2024-08-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


2 Files Affected:

- (modified) clang/lib/AST/Interp/Compiler.cpp (+12-13) 
- (modified) clang/test/AST/Interp/unions.cpp (+46) 


``diff
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 0d72e33c1c7d2..d0e4d409b6580 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -5552,22 +5552,21 @@ bool Compiler::emitComplexComparison(const 
Expr *LHS, const Expr *RHS,
 template 
 bool Compiler::emitRecordDestruction(const Record *R) {
   assert(R);
-  // First, destroy all fields.
-  for (const Record::Field &Field : llvm::reverse(R->fields())) {
-const Descriptor *D = Field.Desc;
-if (!D->isPrimitive() && !D->isPrimitiveArray()) {
-  if (!this->emitGetPtrField(Field.Offset, SourceInfo{}))
-return false;
-  if (!this->emitDestruction(D))
-return false;
-  if (!this->emitPopPtr(SourceInfo{}))
-return false;
+  if (!R->isUnion()) {
+// First, destroy all fields.
+for (const Record::Field &Field : llvm::reverse(R->fields())) {
+  const Descriptor *D = Field.Desc;
+  if (!D->isPrimitive() && !D->isPrimitiveArray()) {
+if (!this->emitGetPtrField(Field.Offset, SourceInfo{}))
+  return false;
+if (!this->emitDestruction(D))
+  return false;
+if (!this->emitPopPtr(SourceInfo{}))
+  return false;
+  }
 }
   }
 
-  // FIXME: Unions need to be handled differently here. We don't want to
-  //   call the destructor of its members.
-
   // Now emit the destructor and recurse into base classes.
   if (const CXXDestructorDecl *Dtor = R->getDestructor();
   Dtor && !Dtor->isTrivial()) {
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index d615b3584b30b..b0b279831405d 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -152,4 +152,50 @@ namespace IndirectFieldDecl {
   };
   static_assert(C().a == 1, "");
 }
+
+namespace UnionDtor {
+
+  union U {
+int *I;
+constexpr U(int *I) : I(I) {}
+constexpr ~U() {
+  *I = 10;
+}
+  };
+
+  constexpr int foo() {
+int a = 100;
+{
+  U u(&a);
+}
+return a;
+  }
+  static_assert(foo() == 10);
+}
+
+namespace UnionMemberDtor {
+  class UM {
+  public:
+int &I;
+constexpr UM(int &I) : I(I) {}
+constexpr ~UM() { I = 200; }
+  };
+
+  union U {
+UM um;
+constexpr U(int &I) : um(I) {}
+constexpr ~U() {
+}
+  };
+
+  constexpr int foo() {
+int a = 100;
+{
+  U u(a);
+}
+
+return a;
+  }
+  static_assert(foo() == 100);
+}
 #endif

``




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


[clang] [clang][Interp] Handle nested unions (PR #102743)

2024-08-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


3 Files Affected:

- (modified) clang/lib/AST/Interp/Interp.cpp (+14-12) 
- (modified) clang/lib/AST/Interp/Pointer.cpp (+1-1) 
- (modified) clang/test/AST/Interp/unions.cpp (+55) 


``diff
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 588680adb4616..89ac693893113 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -125,18 +125,15 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
   if (Ptr.isActive())
 return true;
 
-  // Get the inactive field descriptor.
-  const FieldDecl *InactiveField = Ptr.getField();
-  assert(InactiveField);
-
-  // Walk up the pointer chain to find the closest union.
   Pointer U = Ptr.getBase();
-  while (!U.getFieldDesc()->isUnion())
+  Pointer C = Ptr;
+  while (!U.isRoot() && U.inUnion() && !U.isActive()) {
+C = U;
 U = U.getBase();
-
-  // Find the active field of the union.
-  const Record *R = U.getRecord();
-  assert(R && R->isUnion() && "Not a union");
+  }
+  // Get the inactive field descriptor.
+  const FieldDecl *InactiveField = C.getField();
+  assert(InactiveField);
 
   // Consider:
   // union U {
@@ -148,10 +145,15 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
   //
   // When activating x, we will also activate a. If we now try to read
   // from y, we will get to CheckActive, because y is not active. In that
-  // case we return here and let later code handle this.
-  if (!llvm::is_contained(R->getDecl()->fields(), InactiveField))
+  // case, our U will be a (not a union). We return here and let later code
+  // handle this.
+  if (!U.getFieldDesc()->isUnion())
 return true;
 
+  // Find the active field of the union.
+  const Record *R = U.getRecord();
+  assert(R && R->isUnion() && "Not a union");
+
   const FieldDecl *ActiveField = nullptr;
   for (unsigned I = 0, N = R->getNumFields(); I < N; ++I) {
 const Pointer &Field = U.atField(R->getField(I)->Offset);
diff --git a/clang/lib/AST/Interp/Pointer.cpp b/clang/lib/AST/Interp/Pointer.cpp
index f1f7a27c1400d..466e61666c76e 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -413,7 +413,7 @@ void Pointer::activate() const {
   }
 
   Pointer B = getBase();
-  while (!B.getFieldDesc()->isUnion()) {
+  while (!B.isRoot() && B.inUnion()) {
 // FIXME: Need to de-activate other fields of parent records.
 B.getInlineDesc()->IsActive = true;
 assert(B.isActive());
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index b0b279831405d..a51f30cd9185b 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -198,4 +198,59 @@ namespace UnionMemberDtor {
   }
   static_assert(foo() == 100);
 }
+
+namespace Nested {
+  union U {
+int a;
+int b;
+  };
+
+  union U2 {
+U u;
+U u2;
+int x;
+int y;
+  };
+
+ constexpr int foo() { // ref-error {{constexpr function never produces a 
constant expression}}
+U2 u;
+u.u.a = 10;
+int a = u.y; // both-note {{read of member 'y' of union with active member 
'u' is not allowed in a constant expression}} \
+ // ref-note {{read of member 'y' of union with active member 
'u' is not allowed in a constant expression}}
+
+return 1;
+  }
+  static_assert(foo() == 1); // both-error {{not an integral constant 
expression}} \
+ // both-note {{in call to}}
+
+ constexpr int foo2() {
+U2 u;
+u.u.a = 10;
+return u.u.a;
+  }
+  static_assert(foo2() == 10);
+
+ constexpr int foo3() { // ref-error {{constexpr function never produces a 
constant expression}}
+U2 u;
+u.u.a = 10;
+int a = u.u.b; // both-note {{read of member 'b' of union with active 
member 'a' is not allowed in a constant expression}} \
+   // ref-note {{read of member 'b' of union with active 
member 'a' is not allowed in a constant expression}}
+
+return 1;
+  }
+  static_assert(foo3() == 1); // both-error {{not an integral constant 
expression}} \
+  // both-note {{in call to}}
+
+  constexpr int foo4() { // ref-error {{constexpr function never produces a 
constant expression}}
+U2 u;
+
+u.x = 10;
+
+return u.u.a;// both-note {{read of member 'u' of union with active member 
'x' is not allowed in a constant expression}} \
+ // ref-note {{read of member 'u' of union with active member 
'x' is not allowed in a constant expression}}
+  }
+  static_assert(foo4() == 1); // both-error {{not an integral constant 
expression}} \
+  // both-note {{in call to}}
+
+}
 #endif

``




https://github.com/llvm/llvm-project/pull/102743
___
cfe-commits mailing list
c

[clang] [clang][Interp] Only zero-init first union member (PR #102744)

2024-08-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Zero-initializing all of them accidentally left the last member active. Only 
initialize the first one.

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


3 Files Affected:

- (modified) clang/lib/AST/Interp/Compiler.cpp (+8-13) 
- (modified) clang/test/AST/Interp/records.cpp (+3-5) 
- (modified) clang/test/AST/Interp/unions.cpp (+45) 


``diff
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index d0e4d409b6580..6c4d607706c6b 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -1386,18 +1386,8 @@ bool Compiler::visitInitList(ArrayRef Inits,
 
 if (R->isUnion()) {
   if (Inits.size() == 0) {
-// Zero-initialize the first union field.
-if (R->getNumFields() == 0)
-  return this->emitFinishInit(E);
-const Record::Field *FieldToInit = R->getField(0u);
-QualType FieldType = FieldToInit->Desc->getType();
-if (std::optional T = classify(FieldType)) {
-  if (!this->visitZeroInitializer(*T, FieldType, E))
-return false;
-  if (!this->emitInitField(*T, FieldToInit->Offset, E))
-return false;
-}
-// FIXME: Non-primitive case?
+if (!this->visitZeroRecordInitializer(R, E))
+  return false;
   } else {
 const Expr *Init = Inits[0];
 const FieldDecl *FToInit = nullptr;
@@ -3374,6 +3364,8 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
 return false;
   if (!this->emitInitField(T, Field.Offset, E))
 return false;
+  if (R->isUnion())
+break;
   continue;
 }
 
@@ -3409,8 +3401,11 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
   assert(false);
 }
 
-if (!this->emitPopPtr(E))
+if (!this->emitFinishInitPop(E))
   return false;
+
+if (R->isUnion())
+  break;
   }
 
   for (const Record::Base &B : R->bases()) {
diff --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 9c8c1c344e1e8..343665003c23e 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -964,8 +964,6 @@ namespace TemporaryObjectExpr {
 static_assert(foo(F()) == 0, "");
   }
 
-  /// FIXME: This needs support for unions on the new interpreter.
-  /// We diagnose an uninitialized object in c++14.
 #if __cplusplus > 201402L
   namespace Unions {
 struct F {
@@ -978,10 +976,10 @@ namespace TemporaryObjectExpr {
 };
 
 constexpr int foo(F f) {
-  return f.i + f.U.f; // ref-note {{read of member 'f' of union with 
active member 'a'}}
+  return f.i + f.U.f; // both-note {{read of member 'f' of union with 
active member 'a'}}
 }
-static_assert(foo(F()) == 0, ""); // ref-error {{not an integral constant 
expression}} \
-  // ref-note {{in call to}}
+static_assert(foo(F()) == 0, ""); // both-error {{not an integral constant 
expression}} \
+  // both-note {{in call to}}
   }
 #endif
 
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index a51f30cd9185b..6f6bc3d6891b4 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -253,4 +253,49 @@ namespace Nested {
   // both-note {{in call to}}
 
 }
+
+
+namespace Zeroing {
+  struct non_trivial_constructor {
+  constexpr non_trivial_constructor() : x(100) {}
+  int x;
+  };
+  union U2 {
+  int a{1000};
+  non_trivial_constructor b;
+  };
+
+  static_assert(U2().b.x == 100, ""); // both-error {{not an integral constant 
expression}} \
+  // both-note {{read of member 'b' of 
union with active member 'a'}}
+
+  union { int a; int b; } constexpr u1{};
+  static_assert(u1.a == 0, "");
+  static_assert(u1.b == 0, ""); // both-error {{not an integral constant 
expression}} \
+// both-note {{read of member 'b' of union 
with active member 'a'}}
+
+  union U { int a; int b; } constexpr u2 = U();
+  static_assert(u2.a == 0, "");
+  static_assert(u2.b == 0, ""); // both-error {{not an integral constant 
expression}} \
+// both-note {{read of member 'b' of union 
with active member 'a'}}
+
+
+  struct F {int x; int y; };
+  union { F a; int b; } constexpr u3{};
+  static_assert(u3.a.x == 0, "");
+
+  union U4 { F a; int b; } constexpr u4 = U4();
+  static_assert(u4.a.x == 0, "");
+
+  union { int a[5]; int b; } constexpr u5{};
+  static_assert(u5.a[0] == 0, "");
+  static_assert(u5.a[4] == 0, "");
+  static_assert(u5.b == 0, ""); // both-error {{not an integral constant 
expression}} \
+// both-note {{read of member 'b' of union 
with active member 'a'}}
+
+  union U6 { int a[5]; int b; } constexpr 

[clang] [ASTDump] TextNodeDumper learned to dump builtin name for AtomicExpr (PR #102748)

2024-08-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Enna1 (Enna1)


Changes

In 4198576157bfd0d08c08b784220d6132b709ae2c, we add support for dumping builtin 
name for AtomicExpr in JSON dump. This change syncs `TextNodeDumper` with 
`JSONNodeDumper`, makes `TextNodeDumper` learned to dump builtin name for 
AtomicExpr.

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


3 Files Affected:

- (modified) clang/include/clang/AST/TextNodeDumper.h (+1) 
- (modified) clang/lib/AST/TextNodeDumper.cpp (+4) 
- (modified) clang/test/AST/atomic-expr.cpp (+4-4) 


``diff
diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 39dd1f515c9eb3..88d5535829910f 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -410,6 +410,7 @@ class TextNodeDumper
   void VisitOpenACCConstructStmt(const OpenACCConstructStmt *S);
   void VisitOpenACCLoopConstruct(const OpenACCLoopConstruct *S);
   void VisitEmbedExpr(const EmbedExpr *S);
+  void VisitAtomicExpr(const AtomicExpr *AE);
 };
 
 } // namespace clang
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 388c927c9aa558..d50d4c7028c697 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -2892,3 +2892,7 @@ void TextNodeDumper::VisitEmbedExpr(const EmbedExpr *S) {
   AddChild("begin", [=] { OS << S->getStartingElementPos(); });
   AddChild("number of elements", [=] { OS << S->getDataElementCount(); });
 }
+
+void TextNodeDumper::VisitAtomicExpr(const AtomicExpr *AE) {
+  OS << ' ' << AE->getOpAsString();
+}
diff --git a/clang/test/AST/atomic-expr.cpp b/clang/test/AST/atomic-expr.cpp
index bdb7bcb00569a1..d9d632ffc5917b 100644
--- a/clang/test/AST/atomic-expr.cpp
+++ b/clang/test/AST/atomic-expr.cpp
@@ -25,14 +25,14 @@ void useage(){
 }
 
 // CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}} <{{[^,]+}}, line:{{.*}}:1> 
line:{{.*}}:6 pr43370
-// CHECK: AtomicExpr
+// CHECK: AtomicExpr 0x{{[0-9a-f]+}} <{{.*}}> 'void' __atomic_store_n
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
 // CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int[2]' lvalue Var 
0x{{[0-9a-f]+}} 'arr' 'int[2]'
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
 // CHECK:FunctionDecl 0x{{[0-9a-f]+}}  
line:{{.*}}:6 used pr43370
-// CHECK: AtomicExpr
+// CHECK: AtomicExpr 0x{{[0-9a-f]+}} <{{.*}}> 'void' __atomic_store_n
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
 // CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int[2]' lvalue Var 
0x{{[0-9a-f]+}} 'arr' 'int[2]'
@@ -40,7 +40,7 @@ void useage(){
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
 
 // CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}}  
line:{{.*}}:6 foo
-// CHECK: AtomicExpr
+// CHECK: AtomicExpr 0x{{[0-9a-f]+}} <{{.*}}> 'bool' 
__atomic_compare_exchange_n
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
 // CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:37> 'int[2]' lvalue Var 
0x{{[0-9a-f]+}} 'arr' 'int[2]'
@@ -53,7 +53,7 @@ void useage(){
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:50> 'int' 0
 // CHECK:FunctionDecl 0x{{[0-9a-f]+}}  
line:{{.*}}:6 used foo
-// CHECK: AtomicExpr
+// CHECK: AtomicExpr 0x{{[0-9a-f]+}} <{{.*}}> 'bool' 
__atomic_compare_exchange_n
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
 // CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:37> 'int[2]' lvalue Var 
0x{{[0-9a-f]+}} 'arr' 'int[2]'

``




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


[clang] [clang][Interp] Ignore unnamed bitfields when zeroing records (PR #102749)

2024-08-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Including unions, where this is more important.

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/Compiler.cpp (+3) 
- (modified) clang/test/AST/Interp/unions.cpp (+8) 


``diff
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 6c4d607706c6b..1fa7a98fb 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -3356,6 +3356,9 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
   assert(R);
   // Fields
   for (const Record::Field &Field : R->fields()) {
+if (Field.Decl->isUnnamedBitField())
+  continue;
+
 const Descriptor *D = Field.Desc;
 if (D->isPrimitive()) {
   QualType QT = D->getType();
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index 6f6bc3d6891b4..1f52950b1e09b 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -297,5 +297,13 @@ namespace Zeroing {
   static_assert(u6.a[4] == 0, "");
   static_assert(u6.b == 0, ""); // both-error {{not an integral constant 
expression}} \
 // both-note {{read of member 'b' of union 
with active member 'a'}}
+
+  union UnionWithUnnamedBitfield {
+int : 3;
+int n;
+  };
+  static_assert(UnionWithUnnamedBitfield().n == 0, "");
+  static_assert(UnionWithUnnamedBitfield{}.n == 0, "");
+  static_assert(UnionWithUnnamedBitfield{1}.n == 1, "");
 }
 #endif

``




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


[clang] [clang][Interp] Fix activating via indirect field initializers (PR #102753)

2024-08-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Pointer::activate() propagates up anyway, so that is handled. But we need to 
call activate() in any case since the parent might not be a union, but the 
activate() is still needed. Always call it and hope that the InUnion flag takes 
care of the potential performance problems.

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


4 Files Affected:

- (modified) clang/lib/AST/Interp/Compiler.cpp (+5-9) 
- (modified) clang/lib/AST/Interp/Interp.h (+1-25) 
- (modified) clang/lib/AST/Interp/Opcodes.td (-4) 
- (modified) clang/test/AST/Interp/unions.cpp (+41) 


``diff
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 1fa7a98fb..5bed71392740e 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -4737,8 +4737,7 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
   // Classify the return type.
   ReturnType = this->classify(F->getReturnType());
 
-  auto emitFieldInitializer = [&](const Record *R, const Record::Field *F,
-  unsigned FieldOffset,
+  auto emitFieldInitializer = [&](const Record::Field *F, unsigned FieldOffset,
   const Expr *InitExpr) -> bool {
 // We don't know what to do with these, so just return false.
 if (InitExpr->getType().isNull())
@@ -4750,8 +4749,6 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
 
   if (F->isBitField())
 return this->emitInitThisBitField(*T, F, FieldOffset, InitExpr);
-  if (R->isUnion())
-return this->emitInitThisFieldActive(*T, FieldOffset, InitExpr);
   return this->emitInitThisField(*T, FieldOffset, InitExpr);
 }
 // Non-primitive case. Get a pointer to the field-to-initialize
@@ -4787,7 +4784,7 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
   if (const FieldDecl *Member = Init->getMember()) {
 const Record::Field *F = R->getField(Member);
 
-if (!emitFieldInitializer(R, F, F->Offset, InitExpr))
+if (!emitFieldInitializer(F, F->Offset, InitExpr))
   return false;
   } else if (const Type *Base = Init->getBaseClass()) {
 const auto *BaseDecl = Base->getAsCXXRecordDecl();
@@ -4815,11 +4812,11 @@ bool Compiler::visitFunc(const FunctionDecl 
*F) {
 assert(IFD->getChainingSize() >= 2);
 
 unsigned NestedFieldOffset = 0;
-const Record *FieldRecord = nullptr;
 const Record::Field *NestedField = nullptr;
 for (const NamedDecl *ND : IFD->chain()) {
   const auto *FD = cast(ND);
-  FieldRecord = this->P.getOrCreateRecord(FD->getParent());
+  const Record *FieldRecord =
+  this->P.getOrCreateRecord(FD->getParent());
   assert(FieldRecord);
 
   NestedField = FieldRecord->getField(FD);
@@ -4829,8 +4826,7 @@ bool Compiler::visitFunc(const FunctionDecl *F) {
 }
 assert(NestedField);
 
-if (!emitFieldInitializer(FieldRecord, NestedField, NestedFieldOffset,
-  InitExpr))
+if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr))
   return false;
   } else {
 assert(Init->isDelegatingInitializer());
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 196fc15a77519..af33d507ef8d7 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1391,6 +1391,7 @@ bool InitThisField(InterpState &S, CodePtr OpPC, uint32_t 
I) {
 return false;
   const Pointer &Field = This.atField(I);
   Field.deref() = S.Stk.pop();
+  Field.activate();
   Field.initialize();
   return true;
 }
@@ -1413,20 +1414,6 @@ bool InitThisBitField(InterpState &S, CodePtr OpPC, 
const Record::Field *F,
   return true;
 }
 
-template ::T>
-bool InitThisFieldActive(InterpState &S, CodePtr OpPC, uint32_t I) {
-  if (S.checkingPotentialConstantExpression())
-return false;
-  const Pointer &This = S.Current->getThis();
-  if (!CheckThis(S, OpPC, This))
-return false;
-  const Pointer &Field = This.atField(I);
-  Field.deref() = S.Stk.pop();
-  Field.activate();
-  Field.initialize();
-  return true;
-}
-
 /// 1) Pops the value from the stack
 /// 2) Peeks a pointer from the stack
 /// 3) Pushes the value to field I of the pointer on the stack
@@ -1451,17 +1438,6 @@ bool InitBitField(InterpState &S, CodePtr OpPC, const 
Record::Field *F) {
   return true;
 }
 
-template ::T>
-bool InitFieldActive(InterpState &S, CodePtr OpPC, uint32_t I) {
-  const T &Value = S.Stk.pop();
-  const Pointer &Ptr = S.Stk.pop();
-  const Pointer &Field = Ptr.atField(I);
-  Field.deref() = Value;
-  Field.activate();
-  Field.initialize();
-  return true;
-}
-
 
//===--===//
 // GetPtr Local/Param/Global/Field/This
 
//===---

[clang] [clang][llvm-lit] Rewrite constexpr vectors test to use element access (PR #102757)

2024-08-10 Thread Amr Hesham via cfe-commits

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

Currently the constexpr vectors lit test depend on CHECK to compare the vector 
values and IR, but after vector element access feature is implemented.

This patch rewrite all tests in constexpr vectors to depend on static asserts 
and element access feature

fixes: #102463

>From f847471e0d8b0a140c4e05109d73ff889906a384 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sat, 10 Aug 2024 16:54:33 +0200
Subject: [PATCH] [clang][llvm-lit] Rewrite constexpr vectors test to use
 element access

Currently the constexpr vectors lit test depend on CHECK to compare
the vector values and IR, but after vector element access feature is
implemented.

This patch rewrite all tests in constexpr vectors to depend on static
asserts and element access feature
---
 clang/test/SemaCXX/constexpr-vectors.cpp | 539 ++-
 1 file changed, 331 insertions(+), 208 deletions(-)

diff --git a/clang/test/SemaCXX/constexpr-vectors.cpp 
b/clang/test/SemaCXX/constexpr-vectors.cpp
index 99b045f888d87c..6c04e99b021769 100644
--- a/clang/test/SemaCXX/constexpr-vectors.cpp
+++ b/clang/test/SemaCXX/constexpr-vectors.cpp
@@ -1,10 +1,6 @@
-// RUN: %clang_cc1 -std=c++14 -Wno-unused-value %s -disable-llvm-passes 
-triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++17 -fsyntax-only -verify
 
-// FIXME: Unfortunately there is no good way to validate that our values are
-// correct since Vector types don't have operator [] implemented for constexpr.
-// Instead, we need to use filecheck to ensure the emitted IR is correct. Once
-// someone implements array subscript operator for these types as constexpr,
-// this test should modified to jsut use static asserts.
+// expected-no-diagnostics
 
 using FourCharsVecSize __attribute__((vector_size(4))) = char;
 using FourIntsVecSize __attribute__((vector_size(16))) = int;
@@ -150,564 +146,691 @@ constexpr auto CmpBinOr(T t, U u) {
   return t;
 }
 
+constexpr auto CmpF(float t, float u) {
+  return __builtin_fabs(t - u) < 0.0001;
+}
+
 // Only int vs float makes a difference here, so we only need to test 1 of 
each.
 // Test Char to make sure the mixed-nature of shifts around char is evident.
 void CharUsage() {
   constexpr auto a = FourCharsVecSize{6, 3, 2, 1} +
- FourCharsVecSize{12, 15, 5, 7};
-  // CHECK: store <4 x i8> 
+FourCharsVecSize{12, 15, 5, 7};
+  static_assert(a[0] == 18 && a[1] == 18 && a[2] == 7 && a[3] == 8);
+  
   constexpr auto b = FourCharsVecSize{19, 15, 13, 12} -
  FourCharsVecSize{13, 14, 5, 3};
-  // CHECK: store <4 x i8> 
+  static_assert(b[0] == 6 && b[1] == 1 && b[2] == 8 && b[3] == 9);
+  
   constexpr auto c = FourCharsVecSize{8, 4, 2, 1} *
  FourCharsVecSize{3, 4, 5, 6};
-  // CHECK: store <4 x i8> 
+  static_assert(c[0] == 24 && c[1] == 16 && c[2] == 10 && c[3] == 6);
+
   constexpr auto d = FourCharsVecSize{12, 12, 10, 10} /
  FourCharsVecSize{6, 4, 5, 2};
-  // CHECK: store <4 x i8> 
+  static_assert(d[0] == 2 && d[1] == 3 && d[2] == 2 && d[3] == 5);
+
   constexpr auto e = FourCharsVecSize{12, 12, 10, 10} %
  FourCharsVecSize{6, 4, 4, 3};
-  // CHECK: store <4 x i8> 
+  static_assert(e[0] == 0 && e[1] == 0 && e[2] == 2 && e[3] == 1);
 
   constexpr auto f = FourCharsVecSize{6, 3, 2, 1} + 3;
-  // CHECK: store <4 x i8> 
+  static_assert(f[0] == 9 && f[1] == 6 && f[2] == 5 && f[3] == 4);
+  
   constexpr auto g = FourCharsVecSize{19, 15, 12, 10} - 3;
-  // CHECK: store <4 x i8> 
+  static_assert(g[0] == 16 && g[1] == 12 && g[2] == 9 && g[3] == 7);  
+
   constexpr auto h = FourCharsVecSize{8, 4, 2, 1} * 3;
-  // CHECK: store <4 x i8> 
+  static_assert(h[0] == 24 && h[1] == 12 && h[2] == 6 && h[3] == 3);
+ 
   constexpr auto j = FourCharsVecSize{12, 15, 18, 21} / 3;
-  // CHECK: store <4 x i8> 
+  static_assert(j[0] == 4 && j[1] == 5 && j[2] == 6 && j[3] == 7);
+
   constexpr auto k = FourCharsVecSize{12, 17, 19, 22} % 3;
-  // CHECK: store <4 x i8> 
+  static_assert(k[0] == 0 && k[1] == 2 && k[2] == 1 && k[3] == 1);
 
   constexpr auto l = 3 + FourCharsVecSize{6, 3, 2, 1};
-  // CHECK: store <4 x i8> 
+  static_assert(l[0] == 9 && l[1] == 6 && l[2] == 5 && l[3] == 4);
+
   constexpr auto m = 20 - FourCharsVecSize{19, 15, 12, 10};
-  // CHECK: store <4 x i8> 
+  static_assert(m[0] == 1 && m[1] == 5 && m[2] == 8 && m[3] == 10);
+ 
   constexpr auto n = 3 * FourCharsVecSize{8, 4, 2, 1};
-  // CHECK: store <4 x i8> 
+  static_assert(n[0] == 24 && n[1] == 12 && n[2] == 6 && n[3] == 3);
+
   constexpr auto o = 100 / FourCharsVecSize{12, 15, 18, 21};
-  // CHECK: store <4 x i8> 
+  static_assert(o[0] == 8 && o[1] == 6 && o[2] == 5 && o[3] == 4);
+
   constexpr auto p = 100 % FourCharsVecSize{12, 15, 18, 21};
-  // CHECK: store <4 x i8> 
+  static_assert(p[0] == 4 && p[1] == 10 && p[2] == 10 && p[3] == 16);
 
  

[clang] [clang][llvm-lit] Rewrite constexpr vectors test to use element access (PR #102757)

2024-08-10 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [clang][llvm-lit] Rewrite constexpr vectors test to use element access (PR #102757)

2024-08-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)


Changes

Currently the constexpr vectors lit test depend on CHECK to compare the vector 
values and IR, but after vector element access feature is implemented.

This patch rewrite all tests in constexpr vectors to depend on static asserts 
and element access feature

fixes: #102463

---

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


1 Files Affected:

- (modified) clang/test/SemaCXX/constexpr-vectors.cpp (+331-208) 


``diff
diff --git a/clang/test/SemaCXX/constexpr-vectors.cpp 
b/clang/test/SemaCXX/constexpr-vectors.cpp
index 99b045f888d87c..6c04e99b021769 100644
--- a/clang/test/SemaCXX/constexpr-vectors.cpp
+++ b/clang/test/SemaCXX/constexpr-vectors.cpp
@@ -1,10 +1,6 @@
-// RUN: %clang_cc1 -std=c++14 -Wno-unused-value %s -disable-llvm-passes 
-triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++17 -fsyntax-only -verify
 
-// FIXME: Unfortunately there is no good way to validate that our values are
-// correct since Vector types don't have operator [] implemented for constexpr.
-// Instead, we need to use filecheck to ensure the emitted IR is correct. Once
-// someone implements array subscript operator for these types as constexpr,
-// this test should modified to jsut use static asserts.
+// expected-no-diagnostics
 
 using FourCharsVecSize __attribute__((vector_size(4))) = char;
 using FourIntsVecSize __attribute__((vector_size(16))) = int;
@@ -150,564 +146,691 @@ constexpr auto CmpBinOr(T t, U u) {
   return t;
 }
 
+constexpr auto CmpF(float t, float u) {
+  return __builtin_fabs(t - u) < 0.0001;
+}
+
 // Only int vs float makes a difference here, so we only need to test 1 of 
each.
 // Test Char to make sure the mixed-nature of shifts around char is evident.
 void CharUsage() {
   constexpr auto a = FourCharsVecSize{6, 3, 2, 1} +
- FourCharsVecSize{12, 15, 5, 7};
-  // CHECK: store <4 x i8> 
+FourCharsVecSize{12, 15, 5, 7};
+  static_assert(a[0] == 18 && a[1] == 18 && a[2] == 7 && a[3] == 8);
+  
   constexpr auto b = FourCharsVecSize{19, 15, 13, 12} -
  FourCharsVecSize{13, 14, 5, 3};
-  // CHECK: store <4 x i8> 
+  static_assert(b[0] == 6 && b[1] == 1 && b[2] == 8 && b[3] == 9);
+  
   constexpr auto c = FourCharsVecSize{8, 4, 2, 1} *
  FourCharsVecSize{3, 4, 5, 6};
-  // CHECK: store <4 x i8> 
+  static_assert(c[0] == 24 && c[1] == 16 && c[2] == 10 && c[3] == 6);
+
   constexpr auto d = FourCharsVecSize{12, 12, 10, 10} /
  FourCharsVecSize{6, 4, 5, 2};
-  // CHECK: store <4 x i8> 
+  static_assert(d[0] == 2 && d[1] == 3 && d[2] == 2 && d[3] == 5);
+
   constexpr auto e = FourCharsVecSize{12, 12, 10, 10} %
  FourCharsVecSize{6, 4, 4, 3};
-  // CHECK: store <4 x i8> 
+  static_assert(e[0] == 0 && e[1] == 0 && e[2] == 2 && e[3] == 1);
 
   constexpr auto f = FourCharsVecSize{6, 3, 2, 1} + 3;
-  // CHECK: store <4 x i8> 
+  static_assert(f[0] == 9 && f[1] == 6 && f[2] == 5 && f[3] == 4);
+  
   constexpr auto g = FourCharsVecSize{19, 15, 12, 10} - 3;
-  // CHECK: store <4 x i8> 
+  static_assert(g[0] == 16 && g[1] == 12 && g[2] == 9 && g[3] == 7);  
+
   constexpr auto h = FourCharsVecSize{8, 4, 2, 1} * 3;
-  // CHECK: store <4 x i8> 
+  static_assert(h[0] == 24 && h[1] == 12 && h[2] == 6 && h[3] == 3);
+ 
   constexpr auto j = FourCharsVecSize{12, 15, 18, 21} / 3;
-  // CHECK: store <4 x i8> 
+  static_assert(j[0] == 4 && j[1] == 5 && j[2] == 6 && j[3] == 7);
+
   constexpr auto k = FourCharsVecSize{12, 17, 19, 22} % 3;
-  // CHECK: store <4 x i8> 
+  static_assert(k[0] == 0 && k[1] == 2 && k[2] == 1 && k[3] == 1);
 
   constexpr auto l = 3 + FourCharsVecSize{6, 3, 2, 1};
-  // CHECK: store <4 x i8> 
+  static_assert(l[0] == 9 && l[1] == 6 && l[2] == 5 && l[3] == 4);
+
   constexpr auto m = 20 - FourCharsVecSize{19, 15, 12, 10};
-  // CHECK: store <4 x i8> 
+  static_assert(m[0] == 1 && m[1] == 5 && m[2] == 8 && m[3] == 10);
+ 
   constexpr auto n = 3 * FourCharsVecSize{8, 4, 2, 1};
-  // CHECK: store <4 x i8> 
+  static_assert(n[0] == 24 && n[1] == 12 && n[2] == 6 && n[3] == 3);
+
   constexpr auto o = 100 / FourCharsVecSize{12, 15, 18, 21};
-  // CHECK: store <4 x i8> 
+  static_assert(o[0] == 8 && o[1] == 6 && o[2] == 5 && o[3] == 4);
+
   constexpr auto p = 100 % FourCharsVecSize{12, 15, 18, 21};
-  // CHECK: store <4 x i8> 
+  static_assert(p[0] == 4 && p[1] == 10 && p[2] == 10 && p[3] == 16);
 
   constexpr auto q = FourCharsVecSize{6, 3, 2, 1} << FourCharsVecSize{1, 1, 2, 
2};
-  // CHECK: store <4 x i8> 
+  static_assert(q[0] == 12 && q[1] == 6 && q[2] == 8 && q[3] == 4);
+
   constexpr auto r = FourCharsVecSize{19, 15, 12, 10} >>
  FourCharsVecSize{1, 1, 2, 2};
-  // CHECK: store <4 x i8> 
+  static_assert(r[0] == 9 && r[1] == 7 && r[2] == 3 &&

[clang] ac83582 - [Serialization] Fix a warning

2024-08-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-08-10T09:21:02-07:00
New Revision: ac83582a2e7301f7088d14a4c352438e9f62bcf0

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

LOG: [Serialization] Fix a warning

This patch fixes:

  clang/lib/Serialization/ASTReader.cpp:11484:13: error: unused
  variable '_' [-Werror,-Wunused-variable]

Added: 


Modified: 
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index e1d554ee7db22..8ff7c82950dba 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -11481,8 +11481,10 @@ void 
OMPClauseReader::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
   unsigned NumVars = C->varlist_size();
   SmallVector Vars;
   Vars.reserve(NumVars);
-  for (auto _ : llvm::seq(NumVars))
+  for (auto _ : llvm::seq(NumVars)) {
+(void)_;
 Vars.push_back(Record.readSubExpr());
+  }
   C->setVarRefs(Vars);
 }
 



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


[clang] [Clang][Sema][OpenMP] Allow `thread_limit` to accept multiple expressions (PR #102715)

2024-08-10 Thread Kazu Hirata via cfe-commits

kazutakahirata wrote:

I've fixed a warning with ac83582a2e7301f7088d14a4c352438e9f62bcf0.  We should 
probably use `for (unsigned I = 0; I != NumVars; ++I)` because the use of `_` 
requires `(void)_;` and curly braces (or `[[maybe_unused]]`).  Will post a 
patch shortly.


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


[clang-tools-extra] [clang-tidy] Fix modernize-use-std-format lit test signature (PR #102759)

2024-08-10 Thread Mike Crowe via cfe-commits

https://github.com/mikecrowe created 
https://github.com/llvm/llvm-project/pull/102759

My fix for my original fix of issue #92896 in
666d224248707f373577b5b049b5b022916c modified the function signature for 
fmt::sprintf to more accurately match the real implementation in libfmt but 
failed to do the same for absl::StrFormat. The latter fix applied equally well 
to absl::StrFormat so it's important that its test verifies that the bug is 
fixed too.

>From c00bc97964b2565f3fa606aa0bb46deb6b5056a2 Mon Sep 17 00:00:00 2001
From: Mike Crowe 
Date: Sat, 10 Aug 2024 17:13:04 +0100
Subject: [PATCH] [clang-tidy] Fix modernize-use-std-format lit test signature

My fix for my original fix of issue #92896 in
666d224248707f373577b5b049b5b022916c modified the function signature
for fmt::sprintf to more accurately match the real implementation in
libfmt but failed to do the same for absl::StrFormat. The latter fix
applied equally well to absl::StrFormat so it's important that its test
verifies that the bug is fixed too.
---
 .../test/clang-tidy/checkers/modernize/use-std-format.cpp| 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
index e8dea1dce2c972..800a95062e8f1a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
@@ -11,9 +11,8 @@
 
 namespace absl
 {
-// Use const char * for the format since the real type is hard to mock up.
-template 
-std::string StrFormat(const char *format, const Args&... args);
+template 
+std::string StrFormat(const S &format, const Args&... args);
 } // namespace absl
 
 template 

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


[clang-tools-extra] [clang-tidy] Fix modernize-use-std-format lit test signature (PR #102759)

2024-08-10 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang-tidy

Author: Mike Crowe (mikecrowe)


Changes

My fix for my original fix of issue #92896 in
666d224248707f373577b5b049b5b022916c modified the function signature for 
fmt::sprintf to more accurately match the real implementation in libfmt but 
failed to do the same for absl::StrFormat. The latter fix applied equally well 
to absl::StrFormat so it's important that its test verifies that the bug is 
fixed too.

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


1 Files Affected:

- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp (+2-3) 


``diff
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
index e8dea1dce2c972..800a95062e8f1a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
@@ -11,9 +11,8 @@
 
 namespace absl
 {
-// Use const char * for the format since the real type is hard to mock up.
-template 
-std::string StrFormat(const char *format, const Args&... args);
+template 
+std::string StrFormat(const S &format, const Args&... args);
 } // namespace absl
 
 template 

``




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


[clang] [clang-format] Adjust requires clause wrapping (#101550) (PR #102078)

2024-08-10 Thread Nathan Sidwell via cfe-commits

https://github.com/urnathan updated 
https://github.com/llvm/llvm-project/pull/102078

>From 193e704ea21251ea639bfb733671b4047c93c4ea Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Sun, 4 Aug 2024 19:15:20 -0400
Subject: [PATCH 1/3] [clang-format] Adjust requires clause wrapping (#101550)

Adjust line wrapping after a requires clause to permit a following '{'
on the same line with OwnLine and WithPreceeding RequiresClausePositioning.

Thus, instead of:
```
bool Foo ()
  requires(true)
{
  return true;
}
```

we have:
```
bool Foo ()
  requires(true) {
  return true;
}
```

If the function body is empty, we'll get:
```
bool Foo ()
  requires(true) {}
```

I attempted to get a line break between the open and close braces, but
failed. Perhaps that's fine -- it's rare and only happens in the empty
body case.
---
 clang/lib/Format/TokenAnnotator.cpp   |  3 +-
 clang/unittests/Format/FormatTest.cpp | 53 +--
 2 files changed, 19 insertions(+), 37 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 4ed3e9d0e8e855..04ac0e2b90c609 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5682,7 +5682,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
(Style.BreakTemplateDeclarations == FormatStyle::BTDS_Leave &&
 Right.NewlinesBefore > 0);
   }
-  if (Left.ClosesRequiresClause && Right.isNot(tok::semi)) {
+  if (Left.ClosesRequiresClause && Right.isNot(tok::semi) &&
+  Right.isNot(tok::l_brace)) {
 switch (Style.RequiresClausePosition) {
 case FormatStyle::RCPS_OwnLine:
 case FormatStyle::RCPS_WithPreceding:
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 2a754a29e81e73..792c1971dae499 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4325,8 +4325,7 @@ TEST_F(FormatTest, FormatsNamespaces) {
Style);
   verifyFormat("template \n"
"constexpr void foo()\n"
-   "  requires(I == 42)\n"
-   "{}\n"
+   "  requires(I == 42) {}\n"
"namespace ns {\n"
"void foo() {}\n"
"} // namespace ns",
@@ -17041,12 +17040,10 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   EXPECT_FALSE(
   SpaceAfterRequires.SpaceBeforeParensOptions.AfterRequiresInExpression);
   verifyFormat("void f(auto x)\n"
-   "  requires requires(int i) { x + i; }\n"
-   "{}",
+   "  requires requires(int i) { x + i; } {}",
SpaceAfterRequires);
   verifyFormat("void f(auto x)\n"
-   "  requires(requires(int i) { x + i; })\n"
-   "{}",
+   "  requires(requires(int i) { x + i; }) {}",
SpaceAfterRequires);
   verifyFormat("if (requires(int i) { x + i; })\n"
"  return;",
@@ -17059,12 +17056,10 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
 
   SpaceAfterRequires.SpaceBeforeParensOptions.AfterRequiresInClause = true;
   verifyFormat("void f(auto x)\n"
-   "  requires requires(int i) { x + i; }\n"
-   "{}",
+   "  requires requires(int i) { x + i; } {}",
SpaceAfterRequires);
   verifyFormat("void f(auto x)\n"
-   "  requires (requires(int i) { x + i; })\n"
-   "{}",
+   "  requires (requires(int i) { x + i; }) {}",
SpaceAfterRequires);
   verifyFormat("if (requires(int i) { x + i; })\n"
"  return;",
@@ -17078,12 +17073,10 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   SpaceAfterRequires.SpaceBeforeParensOptions.AfterRequiresInClause = false;
   SpaceAfterRequires.SpaceBeforeParensOptions.AfterRequiresInExpression = true;
   verifyFormat("void f(auto x)\n"
-   "  requires requires (int i) { x + i; }\n"
-   "{}",
+   "  requires requires (int i) { x + i; } {}",
SpaceAfterRequires);
   verifyFormat("void f(auto x)\n"
-   "  requires(requires (int i) { x + i; })\n"
-   "{}",
+   "  requires(requires (int i) { x + i; }) {}",
SpaceAfterRequires);
   verifyFormat("if (requires (int i) { x + i; })\n"
"  return;",
@@ -17096,12 +17089,10 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
 
   SpaceAfterRequires.SpaceBeforeParensOptions.AfterRequiresInClause = true;
   verifyFormat("void f(auto x)\n"
-   "  requires requires (int i) { x + i; }\n"
-   "{}",
+   "  requires requires (int i) { x + i; } {}",
SpaceAfterRequires);
   verifyFormat("void f(auto x)\n"
-   "  requires (requires (int i) { x + i; })\n"
-   "{}",
+   "  requires (requires (int i) { x + i; }) {}",
SpaceAfterRequires);
   verifyForma

[clang] [clang-format] Adjust requires clause wrapping (#101550) (PR #102078)

2024-08-10 Thread Nathan Sidwell via cfe-commits


@@ -5682,12 +5683,15 @@ bool TokenAnnotator::mustBreakBefore(const 
AnnotatedLine &Line,
(Style.BreakTemplateDeclarations == FormatStyle::BTDS_Leave &&
 Right.NewlinesBefore > 0);
   }
-  if (Left.ClosesRequiresClause && Right.isNot(tok::semi) &&
-  Right.isNot(tok::l_brace)) {
+  if (Left.ClosesRequiresClause && Right.isNot(tok::semi)) {
 switch (Style.RequiresClausePosition) {
 case FormatStyle::RCPS_OwnLine:
 case FormatStyle::RCPS_WithPreceding:
   return true;
+case FormatStyle::RCPS_OwnLineWithBrace:
+  if (Right.isNot(tok::l_brace))
+return true;
+  break;

urnathan wrote:

I originally made the return conditional to match the ';' control flow.  But 
sure, direct return in both cases works too.

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


[clang] [clang-format] Adjust requires clause wrapping (#101550) (PR #102078)

2024-08-10 Thread Nathan Sidwell via cfe-commits

urnathan wrote:

Thanks for the comments, I think this addresses them

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


[clang] [Serialization] Use traditional for loops (NFC) (PR #102761)

2024-08-10 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/102761

The use of _ requires either:

- (void)_ and curly braces, or
- [[maybe_unused]].

For simple repetitions like these, we can use traditional for loops
for readable warning-free code.


>From 68c22e9e8010c65eaff27a57d4cc5d4d84b3895a Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sat, 10 Aug 2024 09:26:13 -0700
Subject: [PATCH] [Serialization] Use traditional for loops (NFC)

The use of _ requires either:

- (void)_ and curly braces, or
- [[maybe_unused]].

For simple repetitions like these, we can use traditional for loops
for readable warning-free code.
---
 clang/lib/Serialization/ASTReader.cpp | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 8ff7c82950dba..5f9cfa3cf4bfa 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -11468,10 +11468,8 @@ void 
OMPClauseReader::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
   unsigned NumVars = C->varlist_size();
   SmallVector Vars;
   Vars.reserve(NumVars);
-  for ([[maybe_unused]] auto _ : llvm::seq(NumVars)) {
-(void)_;
+  for (unsigned I = 0; I != NumVars; ++I)
 Vars.push_back(Record.readSubExpr());
-  }
   C->setVarRefs(Vars);
 }
 
@@ -11481,10 +11479,8 @@ void 
OMPClauseReader::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
   unsigned NumVars = C->varlist_size();
   SmallVector Vars;
   Vars.reserve(NumVars);
-  for (auto _ : llvm::seq(NumVars)) {
-(void)_;
+  for (unsigned I = 0; I != NumVars; ++I)
 Vars.push_back(Record.readSubExpr());
-  }
   C->setVarRefs(Vars);
 }
 

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


[clang] [Serialization] Use traditional for loops (NFC) (PR #102761)

2024-08-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Kazu Hirata (kazutakahirata)


Changes

The use of _ requires either:

- (void)_ and curly braces, or
- [[maybe_unused]].

For simple repetitions like these, we can use traditional for loops
for readable warning-free code.


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


1 Files Affected:

- (modified) clang/lib/Serialization/ASTReader.cpp (+2-6) 


``diff
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 8ff7c82950dba..5f9cfa3cf4bfa 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -11468,10 +11468,8 @@ void 
OMPClauseReader::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
   unsigned NumVars = C->varlist_size();
   SmallVector Vars;
   Vars.reserve(NumVars);
-  for ([[maybe_unused]] auto _ : llvm::seq(NumVars)) {
-(void)_;
+  for (unsigned I = 0; I != NumVars; ++I)
 Vars.push_back(Record.readSubExpr());
-  }
   C->setVarRefs(Vars);
 }
 
@@ -11481,10 +11479,8 @@ void 
OMPClauseReader::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
   unsigned NumVars = C->varlist_size();
   SmallVector Vars;
   Vars.reserve(NumVars);
-  for (auto _ : llvm::seq(NumVars)) {
-(void)_;
+  for (unsigned I = 0; I != NumVars; ++I)
 Vars.push_back(Record.readSubExpr());
-  }
   C->setVarRefs(Vars);
 }
 

``




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


[clang] [clang][Interp] Handle union copy/move ctors (PR #102762)

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

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

They don't have a body and we need to implement them ourselves. Use the Memcpy 
op to do that.

>From 7c0b32dd559dd5a42ae72d8546c179565be6afc0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 10 Aug 2024 18:47:59 +0200
Subject: [PATCH] [clang][Interp] Handle union copy/move ctors

They don't have a body and we need to implement them ourselves.
Use the Memcpy op to do that.
---
 clang/lib/AST/Interp/Compiler.cpp  | 16 
 clang/lib/AST/Interp/InterpBuiltin.cpp | 26 +-
 clang/test/AST/Interp/unions.cpp   | 11 +++
 3 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 5bed71392740eb..ad1a2f96b95903 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -4775,6 +4775,22 @@ bool Compiler::visitFunc(const FunctionDecl *F) 
{
 if (!R)
   return false;
 
+if (R->isUnion() && Ctor->isCopyOrMoveConstructor()) {
+  // union copy and move ctors are special.
+  assert(cast(Ctor->getBody())->body_empty());
+  if (!this->emitThis(Ctor))
+return false;
+
+  auto PVD = Ctor->getParamDecl(0);
+  ParamOffset PO = this->Params[PVD]; // Must exist.
+
+  if (!this->emitGetParam(PT_Ptr, PO.Offset, Ctor))
+return false;
+
+  return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
+ this->emitRetVoid(Ctor);
+}
+
 InitLinkScope InitScope(this, InitLink::This());
 for (const auto *Init : Ctor->inits()) {
   // Scope needed for the initializers.
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index d7538c76e91d92..1841a2a4714d89 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -1658,18 +1658,34 @@ bool DoMemcpy(InterpState &S, CodePtr OpPC, const 
Pointer &Src, Pointer &Dest) {
   }
 
   if (DestDesc->isRecord()) {
-assert(SrcDesc->isRecord());
-assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
-const Record *R = DestDesc->ElemRecord;
-for (const Record::Field &F : R->fields()) {
+auto copyField = [&](const Record::Field &F, bool Activate) -> bool {
   Pointer DestField = Dest.atField(F.Offset);
   if (std::optional FT = S.Ctx.classify(F.Decl->getType())) {
 TYPE_SWITCH(*FT, {
   DestField.deref() = Src.atField(F.Offset).deref();
   DestField.initialize();
+  if (Activate)
+DestField.activate();
 });
+return true;
+  }
+  return Invalid(S, OpPC);
+};
+
+assert(SrcDesc->isRecord());
+assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
+const Record *R = DestDesc->ElemRecord;
+for (const Record::Field &F : R->fields()) {
+  if (R->isUnion()) {
+// For unions, only copy the active field.
+const Pointer &SrcField = Src.atField(F.Offset);
+if (SrcField.isActive()) {
+  if (!copyField(F, /*Activate=*/true))
+return false;
+}
   } else {
-return Invalid(S, OpPC);
+if (!copyField(F, /*Activate=*/false))
+  return false;
   }
 }
 return true;
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index 4607df6c1d6444..4c60c2c0810d4c 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -346,5 +346,16 @@ namespace IndirectField {
   static_assert(s2.f == 7, "");
 }
 
+namespace CopyCtor {
+  union U {
+int a;
+int b;
+  };
 
+  constexpr U x = {42};
+  constexpr U y = x;
+  static_assert(y.a == 42, "");
+  static_assert(y.b == 42, ""); // both-error {{constant expression}} \
+// both-note {{'b' of union with active member 
'a'}}
+}
 #endif

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


[clang] [clang][Interp] Handle union copy/move ctors (PR #102762)

2024-08-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

They don't have a body and we need to implement them ourselves. Use the Memcpy 
op to do that.

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


3 Files Affected:

- (modified) clang/lib/AST/Interp/Compiler.cpp (+16) 
- (modified) clang/lib/AST/Interp/InterpBuiltin.cpp (+21-5) 
- (modified) clang/test/AST/Interp/unions.cpp (+11) 


``diff
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 5bed71392740e..ad1a2f96b9590 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -4775,6 +4775,22 @@ bool Compiler::visitFunc(const FunctionDecl *F) 
{
 if (!R)
   return false;
 
+if (R->isUnion() && Ctor->isCopyOrMoveConstructor()) {
+  // union copy and move ctors are special.
+  assert(cast(Ctor->getBody())->body_empty());
+  if (!this->emitThis(Ctor))
+return false;
+
+  auto PVD = Ctor->getParamDecl(0);
+  ParamOffset PO = this->Params[PVD]; // Must exist.
+
+  if (!this->emitGetParam(PT_Ptr, PO.Offset, Ctor))
+return false;
+
+  return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
+ this->emitRetVoid(Ctor);
+}
+
 InitLinkScope InitScope(this, InitLink::This());
 for (const auto *Init : Ctor->inits()) {
   // Scope needed for the initializers.
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index d7538c76e91d9..1841a2a4714d8 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -1658,18 +1658,34 @@ bool DoMemcpy(InterpState &S, CodePtr OpPC, const 
Pointer &Src, Pointer &Dest) {
   }
 
   if (DestDesc->isRecord()) {
-assert(SrcDesc->isRecord());
-assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
-const Record *R = DestDesc->ElemRecord;
-for (const Record::Field &F : R->fields()) {
+auto copyField = [&](const Record::Field &F, bool Activate) -> bool {
   Pointer DestField = Dest.atField(F.Offset);
   if (std::optional FT = S.Ctx.classify(F.Decl->getType())) {
 TYPE_SWITCH(*FT, {
   DestField.deref() = Src.atField(F.Offset).deref();
   DestField.initialize();
+  if (Activate)
+DestField.activate();
 });
+return true;
+  }
+  return Invalid(S, OpPC);
+};
+
+assert(SrcDesc->isRecord());
+assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
+const Record *R = DestDesc->ElemRecord;
+for (const Record::Field &F : R->fields()) {
+  if (R->isUnion()) {
+// For unions, only copy the active field.
+const Pointer &SrcField = Src.atField(F.Offset);
+if (SrcField.isActive()) {
+  if (!copyField(F, /*Activate=*/true))
+return false;
+}
   } else {
-return Invalid(S, OpPC);
+if (!copyField(F, /*Activate=*/false))
+  return false;
   }
 }
 return true;
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index 4607df6c1d644..4c60c2c0810d4 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -346,5 +346,16 @@ namespace IndirectField {
   static_assert(s2.f == 7, "");
 }
 
+namespace CopyCtor {
+  union U {
+int a;
+int b;
+  };
 
+  constexpr U x = {42};
+  constexpr U y = x;
+  static_assert(y.a == 42, "");
+  static_assert(y.b == 42, ""); // both-error {{constant expression}} \
+// both-note {{'b' of union with active member 
'a'}}
+}
 #endif

``




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


[clang] [Serialization] Use traditional for loops (NFC) (PR #102761)

2024-08-10 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev approved this pull request.

LG

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


[clang] [Serialization] Use traditional for loops (NFC) (PR #102761)

2024-08-10 Thread Kazu Hirata via cfe-commits

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


[clang] 4ce2f98 - [Serialization] Use traditional for loops (NFC) (#102761)

2024-08-10 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-08-10T10:49:39-07:00
New Revision: 4ce2f988b28445dadd067e6990aa6fb3db81a184

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

LOG: [Serialization] Use traditional for loops (NFC) (#102761)

The use of _ requires either:

- (void)_ and curly braces, or
- [[maybe_unused]].

For simple repetitions like these, we can use traditional for loops
for readable warning-free code.

Added: 


Modified: 
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 8ff7c82950dba..5f9cfa3cf4bfa 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -11468,10 +11468,8 @@ void 
OMPClauseReader::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
   unsigned NumVars = C->varlist_size();
   SmallVector Vars;
   Vars.reserve(NumVars);
-  for ([[maybe_unused]] auto _ : llvm::seq(NumVars)) {
-(void)_;
+  for (unsigned I = 0; I != NumVars; ++I)
 Vars.push_back(Record.readSubExpr());
-  }
   C->setVarRefs(Vars);
 }
 
@@ -11481,10 +11479,8 @@ void 
OMPClauseReader::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) {
   unsigned NumVars = C->varlist_size();
   SmallVector Vars;
   Vars.reserve(NumVars);
-  for (auto _ : llvm::seq(NumVars)) {
-(void)_;
+  for (unsigned I = 0; I != NumVars; ++I)
 Vars.push_back(Record.readSubExpr());
-  }
   C->setVarRefs(Vars);
 }
 



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


[clang] 496b224 - [clang][Interp] Handle union copy/move ctors (#102762)

2024-08-10 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-10T19:54:07+02:00
New Revision: 496b224dc2fabe7c9f72e02fb5096f2b0fdd9e9b

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

LOG: [clang][Interp] Handle union copy/move ctors (#102762)

They don't have a body and we need to implement them ourselves. Use the
Memcpy op to do that.

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/unions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 5bed71392740e..ad1a2f96b9590 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -4775,6 +4775,22 @@ bool Compiler::visitFunc(const FunctionDecl *F) 
{
 if (!R)
   return false;
 
+if (R->isUnion() && Ctor->isCopyOrMoveConstructor()) {
+  // union copy and move ctors are special.
+  assert(cast(Ctor->getBody())->body_empty());
+  if (!this->emitThis(Ctor))
+return false;
+
+  auto PVD = Ctor->getParamDecl(0);
+  ParamOffset PO = this->Params[PVD]; // Must exist.
+
+  if (!this->emitGetParam(PT_Ptr, PO.Offset, Ctor))
+return false;
+
+  return this->emitMemcpy(Ctor) && this->emitPopPtr(Ctor) &&
+ this->emitRetVoid(Ctor);
+}
+
 InitLinkScope InitScope(this, InitLink::This());
 for (const auto *Init : Ctor->inits()) {
   // Scope needed for the initializers.

diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index d7538c76e91d9..1841a2a4714d8 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -1658,18 +1658,34 @@ bool DoMemcpy(InterpState &S, CodePtr OpPC, const 
Pointer &Src, Pointer &Dest) {
   }
 
   if (DestDesc->isRecord()) {
-assert(SrcDesc->isRecord());
-assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
-const Record *R = DestDesc->ElemRecord;
-for (const Record::Field &F : R->fields()) {
+auto copyField = [&](const Record::Field &F, bool Activate) -> bool {
   Pointer DestField = Dest.atField(F.Offset);
   if (std::optional FT = S.Ctx.classify(F.Decl->getType())) {
 TYPE_SWITCH(*FT, {
   DestField.deref() = Src.atField(F.Offset).deref();
   DestField.initialize();
+  if (Activate)
+DestField.activate();
 });
+return true;
+  }
+  return Invalid(S, OpPC);
+};
+
+assert(SrcDesc->isRecord());
+assert(SrcDesc->ElemRecord == DestDesc->ElemRecord);
+const Record *R = DestDesc->ElemRecord;
+for (const Record::Field &F : R->fields()) {
+  if (R->isUnion()) {
+// For unions, only copy the active field.
+const Pointer &SrcField = Src.atField(F.Offset);
+if (SrcField.isActive()) {
+  if (!copyField(F, /*Activate=*/true))
+return false;
+}
   } else {
-return Invalid(S, OpPC);
+if (!copyField(F, /*Activate=*/false))
+  return false;
   }
 }
 return true;

diff  --git a/clang/test/AST/Interp/unions.cpp 
b/clang/test/AST/Interp/unions.cpp
index 4607df6c1d644..4c60c2c0810d4 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -346,5 +346,16 @@ namespace IndirectField {
   static_assert(s2.f == 7, "");
 }
 
+namespace CopyCtor {
+  union U {
+int a;
+int b;
+  };
 
+  constexpr U x = {42};
+  constexpr U y = x;
+  static_assert(y.a == 42, "");
+  static_assert(y.b == 42, ""); // both-error {{constant expression}} \
+// both-note {{'b' of union with active member 
'a'}}
+}
 #endif



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


[clang] [Clang][CodeGen] Fix bad codegen when building Clang with latest MSVC (PR #102681)

2024-08-10 Thread Saleem Abdulrasool via cfe-commits

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


[clang] [clang][Interp] Handle union copy/move ctors (PR #102762)

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

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


[clang-tools-extra] [clang-tidy] Fix modernize-use-std-format lit test signature (PR #102759)

2024-08-10 Thread Piotr Zegar via cfe-commits

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


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


[clang] [APINotes] Support C++ tag conformances to Swift protocols (PR #102664)

2024-08-10 Thread Saleem Abdulrasool via cfe-commits

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


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


[clang] [APINotes] Support C++ tag conformances to Swift protocols (PR #102664)

2024-08-10 Thread Saleem Abdulrasool via cfe-commits


@@ -572,6 +572,13 @@ class TagTableInfo
 ReleaseOpLength - 1);
   Data += ReleaseOpLength - 1;
 }
+unsigned ConformsToLength =
+endian::readNext(Data);
+if (ConformsToLength > 0) {

compnerd wrote:

```suggestion
if (unsigned ConformsToLength =
endian::readNext(Data)) {
```

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


  1   2   >