[clang] [serialization] no transitive decl change (PR #91914)

2024-05-12 Thread Chuanqi Xu via cfe-commits

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


[clang] [serialization] no transitive decl change (PR #91914)

2024-05-12 Thread Chuanqi Xu via cfe-commits

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


[clang] [serialization] no transitive decl change (PR #91914)

2024-05-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)


Changes

Following of https://github.com/llvm/llvm-project/pull/86912

 Motivation Example

The motivation of the patch series is that, for a module interface unit `X`, 
when the dependent modules of `X` changes, if the changes is not relevant with 
`X`, we hope the BMI of `X` won't change. For the specific patch, we hope if 
the changes was about irrelevant declaration changes, we hope the BMI of `X` 
won't change. **However**, I found the patch itself is not very useful in 
practice, since the adding or removing declarations, will change the state of 
identifiers and types in most cases.

That said, for the most simple example,

```
// partA.cppm
export module m:partA;

// partA.v1.cppm
export module m:partA;
export void a() {}

// partB.cppm
export module m:partB;
export void b() {}

// m.cppm
export module m;
export import :partA;
export import :partB;

// onlyUseB;
export module onlyUseB;
import m;
export inline void onluUseB() {
b();
}
```

the BMI of `onlyUseB` will change after we change the implementation of 
`partA.cppm` to `partA.v1.cppm`. Since `partA.v1.cppm` introduces new 
identifiers and types (the function prototype).

So in this patch, we have to write the tests as:

```
// partA.cppm
export module m:partA;
export int getA() { ... }
export int getA2(int) { ... }

// partA.v1.cppm
export module m:partA;
export int getA() { ... }
export int getA(int) { ... }
export int getA2(int) { ... }

// partB.cppm
export module m:partB;
export void b() {}

// m.cppm
export module m;
export import :partA;
export import :partB;

// onlyUseB;
export module onlyUseB;
import m;
export inline void onluUseB() {
b();
}
```

so that the new introduced declaration `int getA(int)` doesn't introduce new 
identifiers and types, then the BMI of `onlyUseB` can keep unchanged.

While it looks not so great, the patch should be the base of the patch to erase 
the transitive change for identifiers and types since I don't know how can we 
introduce new types and identifiers without introducing new declarations.

 Design details

The design of the patch is similar to 
https://github.com/llvm/llvm-project/pull/86912, which extends the 32-bit 
DeclID to 64-bit and use the higher bits to store the module file index and the 
lower bits to store the Local Decl ID. 

A slight difference is that we only use 48 bits to store the new DeclID since 
we try to use the higher 16 bits to store the module ID in the prefix of Decl 
class. Previously, we use 32 bits to store the module ID and 32 bits to store 
the DeclID. I don't want to allocate additional space so I tried to make the 
additional space the same as 64 bits. An potential interesting thing here is 
about the relationship between the module ID and the module file index. I feel 
we can get the module file index by the module ID. But I didn't prove it or 
implement it. Since I want to make the patch itself as small as possible. We 
can make it in the future if we want.

Another change in the patch is the new concept Decl Index, which means the 
index of the very big array `DeclsLoaded` in ASTReader. Previously, the index 
of a loaded declaration is simply the Decl ID minus PREDEFINED_DECL_NUMs. So 
there are some places they got used ambiguously. But this patch tried to split 
these two concepts.

 Overhead

As https://github.com/llvm/llvm-project/pull/86912 did, the change will 
increase the on-disk PCM file sizes. As the declaration ID may be the most IDs 
in the PCM file, this can have the biggest impact on the size. In my 
experiments, this change will bring 6.6% increase of the on-disk PCM size. No 
compile-time performance regression observed. Given the benefits in the 
motivation example, I think the cost is worthwhile.

---

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


12 Files Affected:

- (modified) clang/include/clang/AST/DeclBase.h (+3-14) 
- (modified) clang/include/clang/AST/DeclID.h (+22-1) 
- (modified) clang/include/clang/Serialization/ASTBitCodes.h (+6) 
- (modified) clang/include/clang/Serialization/ASTReader.h (+16-20) 
- (modified) clang/include/clang/Serialization/ModuleFile.h (+3-15) 
- (modified) clang/include/clang/Serialization/ModuleManager.h (+1-1) 
- (modified) clang/lib/AST/DeclBase.cpp (+27-7) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+85-74) 
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+5-7) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+1-6) 
- (modified) clang/lib/Serialization/ModuleFile.cpp (+1-2) 
- (added) clang/test/Modules/no-transitive-decls-change.cppm (+112) 


``diff
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index e43e812cd9455..4bdf27aa99405 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -701,10 +701,7 @@ class alignas(8) Decl 

[clang] [serialization] no transitive decl change (PR #91914)

2024-05-12 Thread Chuanqi Xu via cfe-commits

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


[clang] [serialization] no transitive decl change (PR #91914)

2024-05-12 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/91914

Following of https://github.com/llvm/llvm-project/pull/86912

 Motivation Example

The motivation of the patch series is that, for a module interface unit `X`, 
when the dependent modules of `X` changes, if the changes is not relevant with 
`X`, we hope the BMI of `X` won't change. For the specific patch, we hope if 
the changes was about irrelevant declaration changes, we hope the BMI of `X` 
won't change. **However**, I found the patch itself is not very useful in 
practice, since the adding or removing declarations, will change the state of 
identifiers and types in most cases.

That said, for the most simple example,

```
// partA.cppm
export module m:partA;

// partA.v1.cppm
export module m:partA;
export void a() {}

// partB.cppm
export module m:partB;
export void b() {}

// m.cppm
export module m;
export import :partA;
export import :partB;

// onlyUseB;
export module onlyUseB;
import m;
export inline void onluUseB() {
b();
}
```

the BMI of `onlyUseB` will change after we change the implementation of 
`partA.cppm` to `partA.v1.cppm`. Since `partA.v1.cppm` introduces new 
identifiers and types (the function prototype).

So in this patch, we have to write the tests as:

```
// partA.cppm
export module m:partA;
export int getA() { ... }
export int getA2(int) { ... }

// partA.v1.cppm
export module m:partA;
export int getA() { ... }
export int getA(int) { ... }
export int getA2(int) { ... }

// partB.cppm
export module m:partB;
export void b() {}

// m.cppm
export module m;
export import :partA;
export import :partB;

// onlyUseB;
export module onlyUseB;
import m;
export inline void onluUseB() {
b();
}
```

so that the new introduced declaration `int getA(int)` doesn't introduce new 
identifiers and types, then the BMI of `onlyUseB` can keep unchanged.

While it looks not so great, the patch should be the base of the patch to erase 
the transitive change for identifiers and types since I don't know how can we 
introduce new types and identifiers without introducing new declarations.

 Design details

The design of the patch is similar to 
https://github.com/llvm/llvm-project/pull/86912, which extends the 32-bit 
DeclID to 64-bit and use the higher bits to store the module file index and the 
lower bits to store the Local Decl ID. 

A slight difference is that we only use 48 bits to store the new DeclID since 
we try to use the higher 16 bits to store the module ID in the prefix of Decl 
class. Previously, we use 32 bits to store the module ID and 32 bits to store 
the DeclID. I don't want to allocate additional space so I tried to make the 
additional space the same as 64 bits. An potential interesting thing here is 
about the relationship between the module ID and the module file index. I feel 
we can get the module file index by the module ID. But I didn't prove it or 
implement it. Since I want to make the patch itself as small as possible. We 
can make it in the future if we want.

Another change in the patch is the new concept Decl Index, which means the 
index of the very big array `DeclsLoaded` in ASTReader. Previously, the index 
of a loaded declaration is simply the Decl ID minus PREDEFINED_DECL_NUMs. So 
there are some places they got used ambiguously. But this patch tried to split 
these two concepts.

 Overhead

As https://github.com/llvm/llvm-project/pull/86912 did, the change will 
increase the on-disk PCM file sizes. As the declaration ID may be the most IDs 
in the PCM file, this can have the biggest impact on the size. In my 
experiments, this change will bring 6.6% increase of the on-disk PCM size. No 
compile-time performance regression observed. Given the benefits in the 
motivation example, I think the cost is worthwhile.

>From ea53cb5687dd5f3597457fb4d2d62c52c2cb2771 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Fri, 10 May 2024 15:36:31 +0800
Subject: [PATCH] [serialization] no transitive decl change

---
 clang/include/clang/AST/DeclBase.h|  17 +-
 clang/include/clang/AST/DeclID.h  |  23 ++-
 .../include/clang/Serialization/ASTBitCodes.h |   6 +
 clang/include/clang/Serialization/ASTReader.h |  36 ++--
 .../include/clang/Serialization/ModuleFile.h  |  18 +-
 .../clang/Serialization/ModuleManager.h   |   2 +-
 clang/lib/AST/DeclBase.cpp|  34 +++-
 clang/lib/Serialization/ASTReader.cpp | 159 ++
 clang/lib/Serialization/ASTReaderDecl.cpp |  12 +-
 clang/lib/Serialization/ASTWriter.cpp |   7 +-
 clang/lib/Serialization/ModuleFile.cpp|   3 +-
 .../Modules/no-transitive-decls-change.cppm   | 112 
 12 files changed, 282 insertions(+), 147 deletions(-)
 create mode 100644 clang/test/Modules/no-transitive-decls-change.cppm

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index e43e812cd9455..4bdf27aa99405 100644
--- 

[clang] [clang][Interp] Member Pointers (PR #91303)

2024-05-12 Thread Timm Baeder via cfe-commits

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

>From a1cefd4b17bb540568472e753b7d4684a99bdda9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 10 Apr 2024 16:42:36 +0200
Subject: [PATCH] Memberpointers

---
 clang/lib/AST/CMakeLists.txt  |   1 +
 clang/lib/AST/Interp/ByteCodeExprGen.cpp  | 103 +-
 clang/lib/AST/Interp/Context.cpp  |  15 +-
 clang/lib/AST/Interp/Context.h|   2 +
 clang/lib/AST/Interp/Descriptor.cpp   |   1 +
 clang/lib/AST/Interp/Disasm.cpp   |   3 +
 clang/lib/AST/Interp/Interp.cpp   |  30 ++-
 clang/lib/AST/Interp/Interp.h |  99 ++
 clang/lib/AST/Interp/InterpFrame.cpp  |   1 +
 clang/lib/AST/Interp/InterpStack.cpp  |   1 +
 clang/lib/AST/Interp/InterpStack.h|   3 +
 clang/lib/AST/Interp/MemberPointer.cpp|  73 +++
 clang/lib/AST/Interp/MemberPointer.h  | 112 +++
 clang/lib/AST/Interp/Opcodes.td   |  18 +-
 clang/lib/AST/Interp/Pointer.cpp  |   1 +
 clang/lib/AST/Interp/Pointer.h|   1 +
 clang/lib/AST/Interp/PrimType.cpp |   1 +
 clang/lib/AST/Interp/PrimType.h   |   8 +-
 clang/test/AST/Interp/eval-order.cpp  |   4 +-
 clang/test/AST/Interp/literals.cpp|   7 +-
 clang/test/AST/Interp/memberpointers.cpp  | 184 ++
 .../mangle-ms-templates-memptrs.cpp   |   2 +-
 .../CodeGenCXX/pointers-to-data-members.cpp   |   2 +-
 clang/test/SemaCXX/attr-weak.cpp  |   1 +
 .../SemaCXX/nullptr_in_arithmetic_ops.cpp |   2 +-
 clang/unittests/AST/Interp/toAPValue.cpp  |  46 +
 26 files changed, 692 insertions(+), 29 deletions(-)
 create mode 100644 clang/lib/AST/Interp/MemberPointer.cpp
 create mode 100644 clang/lib/AST/Interp/MemberPointer.h
 create mode 100644 clang/test/AST/Interp/memberpointers.cpp

diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index 3faefb54f599f..a5d3dacfc1a84 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -87,6 +87,7 @@ add_clang_library(clangAST
   Interp/Record.cpp
   Interp/Source.cpp
   Interp/State.cpp
+  Interp/MemberPointer.cpp
   Interp/InterpShared.cpp
   ItaniumCXXABI.cpp
   ItaniumMangle.cpp
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 630fdb60c3518..326eb6bf5d5c6 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -100,6 +100,35 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
 return this->emitMemcpy(CE);
   }
 
+  case CK_DerivedToBaseMemberPointer: {
+assert(classifyPrim(CE->getType()) == PT_MemberPtr);
+assert(classifyPrim(SubExpr->getType()) == PT_MemberPtr);
+const auto *FromMP = SubExpr->getType()->getAs();
+const auto *ToMP = CE->getType()->getAs();
+
+unsigned DerivedOffset = collectBaseOffset(QualType(ToMP->getClass(), 0),
+   QualType(FromMP->getClass(), 
0));
+
+if (!this->visit(SubExpr))
+  return false;
+
+return this->emitGetMemberPtrBasePop(DerivedOffset, CE);
+  }
+
+  case CK_BaseToDerivedMemberPointer: {
+assert(classifyPrim(CE) == PT_MemberPtr);
+assert(classifyPrim(SubExpr) == PT_MemberPtr);
+const auto *FromMP = SubExpr->getType()->getAs();
+const auto *ToMP = CE->getType()->getAs();
+
+unsigned DerivedOffset = collectBaseOffset(QualType(FromMP->getClass(), 0),
+   QualType(ToMP->getClass(), 0));
+
+if (!this->visit(SubExpr))
+  return false;
+return this->emitGetMemberPtrBasePop(-DerivedOffset, CE);
+  }
+
   case CK_UncheckedDerivedToBase:
   case CK_DerivedToBase: {
 if (!this->visit(SubExpr))
@@ -187,7 +216,8 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 return this->emitCastFloatingIntegral(*ToT, CE);
   }
 
-  case CK_NullToPointer: {
+  case CK_NullToPointer:
+  case CK_NullToMemberPointer: {
 if (DiscardResult)
   return true;
 
@@ -326,7 +356,8 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 return this->emitCast(*FromT, *ToT, CE);
   }
 
-  case CK_PointerToBoolean: {
+  case CK_PointerToBoolean:
+  case CK_MemberPointerToBoolean: {
 PrimType PtrT = classifyPrim(SubExpr->getType());
 
 // Just emit p != nullptr for this.
@@ -534,8 +565,23 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   BO->isComparisonOp())
 return this->emitComplexComparison(LHS, RHS, BO);
 
-  if (BO->isPtrMemOp())
-return this->visit(RHS);
+  if (BO->isPtrMemOp()) {
+if (!this->visit(LHS))
+  return false;
+
+if (!this->visit(RHS))
+  return false;
+
+if (!this->emitToMemberPtr(BO))
+  return false;
+
+if (classifyPrim(BO) == PT_MemberPtr)
+  

[clang] [clang][Interp] Member Pointers (PR #91303)

2024-05-12 Thread Timm Baeder via cfe-commits

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

>From c8bddc0573c62f288314b4407ba500dcc9b84425 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 10 Apr 2024 16:42:36 +0200
Subject: [PATCH] Memberpointers

---
 clang/lib/AST/CMakeLists.txt  |   1 +
 clang/lib/AST/Interp/ByteCodeExprGen.cpp  | 103 +-
 clang/lib/AST/Interp/Context.cpp  |  15 +-
 clang/lib/AST/Interp/Context.h|   2 +
 clang/lib/AST/Interp/Descriptor.cpp   |   1 +
 clang/lib/AST/Interp/Disasm.cpp   |   3 +
 clang/lib/AST/Interp/Interp.cpp   |  30 ++-
 clang/lib/AST/Interp/Interp.h |  99 ++
 clang/lib/AST/Interp/InterpFrame.cpp  |   1 +
 clang/lib/AST/Interp/InterpStack.cpp  |   1 +
 clang/lib/AST/Interp/InterpStack.h|   3 +
 clang/lib/AST/Interp/MemberPointer.cpp|  67 +++
 clang/lib/AST/Interp/MemberPointer.h  | 112 +++
 clang/lib/AST/Interp/Opcodes.td   |  18 +-
 clang/lib/AST/Interp/Pointer.cpp  |   1 +
 clang/lib/AST/Interp/Pointer.h|   1 +
 clang/lib/AST/Interp/PrimType.cpp |   1 +
 clang/lib/AST/Interp/PrimType.h   |   8 +-
 clang/test/AST/Interp/eval-order.cpp  |   4 +-
 clang/test/AST/Interp/literals.cpp|   7 +-
 clang/test/AST/Interp/memberpointers.cpp  | 184 ++
 .../mangle-ms-templates-memptrs.cpp   |   2 +-
 .../CodeGenCXX/pointers-to-data-members.cpp   |   2 +-
 clang/test/SemaCXX/attr-weak.cpp  |   1 +
 .../SemaCXX/nullptr_in_arithmetic_ops.cpp |   2 +-
 clang/unittests/AST/Interp/toAPValue.cpp  |  46 +
 26 files changed, 686 insertions(+), 29 deletions(-)
 create mode 100644 clang/lib/AST/Interp/MemberPointer.cpp
 create mode 100644 clang/lib/AST/Interp/MemberPointer.h
 create mode 100644 clang/test/AST/Interp/memberpointers.cpp

diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index 3faefb54f599f..a5d3dacfc1a84 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -87,6 +87,7 @@ add_clang_library(clangAST
   Interp/Record.cpp
   Interp/Source.cpp
   Interp/State.cpp
+  Interp/MemberPointer.cpp
   Interp/InterpShared.cpp
   ItaniumCXXABI.cpp
   ItaniumMangle.cpp
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 630fdb60c3518..326eb6bf5d5c6 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -100,6 +100,35 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
 return this->emitMemcpy(CE);
   }
 
+  case CK_DerivedToBaseMemberPointer: {
+assert(classifyPrim(CE->getType()) == PT_MemberPtr);
+assert(classifyPrim(SubExpr->getType()) == PT_MemberPtr);
+const auto *FromMP = SubExpr->getType()->getAs();
+const auto *ToMP = CE->getType()->getAs();
+
+unsigned DerivedOffset = collectBaseOffset(QualType(ToMP->getClass(), 0),
+   QualType(FromMP->getClass(), 
0));
+
+if (!this->visit(SubExpr))
+  return false;
+
+return this->emitGetMemberPtrBasePop(DerivedOffset, CE);
+  }
+
+  case CK_BaseToDerivedMemberPointer: {
+assert(classifyPrim(CE) == PT_MemberPtr);
+assert(classifyPrim(SubExpr) == PT_MemberPtr);
+const auto *FromMP = SubExpr->getType()->getAs();
+const auto *ToMP = CE->getType()->getAs();
+
+unsigned DerivedOffset = collectBaseOffset(QualType(FromMP->getClass(), 0),
+   QualType(ToMP->getClass(), 0));
+
+if (!this->visit(SubExpr))
+  return false;
+return this->emitGetMemberPtrBasePop(-DerivedOffset, CE);
+  }
+
   case CK_UncheckedDerivedToBase:
   case CK_DerivedToBase: {
 if (!this->visit(SubExpr))
@@ -187,7 +216,8 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 return this->emitCastFloatingIntegral(*ToT, CE);
   }
 
-  case CK_NullToPointer: {
+  case CK_NullToPointer:
+  case CK_NullToMemberPointer: {
 if (DiscardResult)
   return true;
 
@@ -326,7 +356,8 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 return this->emitCast(*FromT, *ToT, CE);
   }
 
-  case CK_PointerToBoolean: {
+  case CK_PointerToBoolean:
+  case CK_MemberPointerToBoolean: {
 PrimType PtrT = classifyPrim(SubExpr->getType());
 
 // Just emit p != nullptr for this.
@@ -534,8 +565,23 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   BO->isComparisonOp())
 return this->emitComplexComparison(LHS, RHS, BO);
 
-  if (BO->isPtrMemOp())
-return this->visit(RHS);
+  if (BO->isPtrMemOp()) {
+if (!this->visit(LHS))
+  return false;
+
+if (!this->visit(RHS))
+  return false;
+
+if (!this->emitToMemberPtr(BO))
+  return false;
+
+if (classifyPrim(BO) == PT_MemberPtr)
+  

[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)

2024-05-12 Thread via cfe-commits

dyung wrote:

Hi @owenca, this change is causing a test failure in the sanitizer bot 
(https://lab.llvm.org/buildbot/#/builders/5/builds/43303), that is still 
failing as of your most recent fix de641e2 
(https://lab.llvm.org/buildbot/#/builders/5/builds/43334). Can you please 
revert if you need time to investigate so that we can get the sanitizer bot 
back to green?

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


[clang] [clang-tools-extra] [flang] [lld] [llvm] [mlir] [polly] [test]: fix filecheck annotation typos (PR #91854)

2024-05-12 Thread Fangrui Song via cfe-commits


@@ -45,10 +45,10 @@
 # RUN: ld.lld -Ttext 0x201000 %t.o -o %t4
 # RUN: llvm-readelf -S -l %t4 | FileCheck %s --check-prefix=USER3
 # USER3: .text   PROGBITS 00201000 001000 01
-# USER3-NEX: .rodata PROGBITS 00202000 002000 08
-# USER3-NEX: .aw PROGBITS 00203000 003000 08
-# USER3-NEX: .data   PROGBITS 00203008 003008 08
-# USER3-NEX: .bssNOBITS   00203010 003010 08
+# USER3-NEXT: .rodata PROGBITS 00202000 002000 08

MaskRay wrote:

The test would fail.

I fixed this by adding `-z separate-loadable-segments`.

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


[clang] Reland "[Win32][ELF] Make CodeView a DebugInfoFormat only for COFF format", second try (PR #88245)

2024-05-12 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

Ping?

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


[clang-tools-extra] [clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-12 Thread via cfe-commits

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


[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-12 Thread via cfe-commits

JoverZhang wrote:

> Please add an entry to the release notes here:
> 
> https://github.com/llvm/llvm-project/blob/502e77df1fc4aa859db6709e14e93af6207e4dc4/clang-tools-extra/docs/ReleaseNotes.rst?plain=1#L176
> 
> 
> do note that the entries are sorted by their check names.
> Otherwise looks good.

Okay, I added.

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


[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-12 Thread via cfe-commits

https://github.com/JoverZhang updated 
https://github.com/llvm/llvm-project/pull/91588

>From 19bf94ca3c093a6904482eab599f8366cad1384e Mon Sep 17 00:00:00 2001
From: Jover Zhang 
Date: Thu, 9 May 2024 20:56:51 +0800
Subject: [PATCH 1/3] [clang-tidy] Ignore `if consteval` in else-after-return

---
 .../clang-tidy/readability/ElseAfterReturnCheck.cpp   | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
index 1e85caf688355..3ee09b2e6442c 100644
--- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -317,6 +317,10 @@ void ElseAfterReturnCheck::check(const 
MatchFinder::MatchResult ) {
 return;
   }
 
+  if (If->isConsteval()) {
+return;
+  }
+
   DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
<< ControlFlowInterruptor << SourceRange(ElseLoc);
   removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc);

>From 2a394ddde92b23f9407ca74e597b569bb01da35f Mon Sep 17 00:00:00 2001
From: Jover Zhang 
Date: Sun, 12 May 2024 22:40:14 +0800
Subject: [PATCH 2/3] Add test case

---
 .../readability/ElseAfterReturnCheck.cpp|  8 ++--
 .../else-after-return-if-consteval.cpp  | 17 +
 2 files changed, 19 insertions(+), 6 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
index 3ee09b2e6442c..2b185e7594add 100644
--- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -113,7 +113,7 @@ static bool containsDeclInScope(const Stmt *Node) {
 }
 
 static void removeElseAndBrackets(DiagnosticBuilder , ASTContext ,
-   const Stmt *Else, SourceLocation ElseLoc) {
+  const Stmt *Else, SourceLocation ElseLoc) {
   auto Remap = [&](SourceLocation Loc) {
 return Context.getSourceManager().getExpansionLoc(Loc);
   };
@@ -172,7 +172,7 @@ void ElseAfterReturnCheck::registerMatchers(MatchFinder 
*Finder) {
   breakStmt().bind(InterruptingStr), 
cxxThrowExpr().bind(InterruptingStr)));
   Finder->addMatcher(
   compoundStmt(
-  forEach(ifStmt(unless(isConstexpr()),
+  forEach(ifStmt(unless(isConstexpr()), unless(isConsteval()),
  hasThen(stmt(
  anyOf(InterruptsControlFlow,
compoundStmt(has(InterruptsControlFlow),
@@ -317,10 +317,6 @@ void ElseAfterReturnCheck::check(const 
MatchFinder::MatchResult ) {
 return;
   }
 
-  if (If->isConsteval()) {
-return;
-  }
-
   DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
<< ControlFlowInterruptor << SourceRange(ElseLoc);
   removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc);
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
new file mode 100644
index 0..6235d8623ca7b
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-else-after-return %t 
+
+// Consteval if is an exception to the rule, we cannot remove the else.
+void f() {
+  if (sizeof(int) > 4) {
+return;
+  } else {
+return;
+  }
+  // CHECK-MESSAGES: [[@LINE-3]]:5: warning: do not use 'else' after 'return'
+
+  if consteval {
+return;
+  } else {
+return;
+  }
+}

>From 1e88302ea84491967ad61e6c32ad87c15e02f3bf Mon Sep 17 00:00:00 2001
From: Jover Zhang 
Date: Mon, 13 May 2024 10:09:04 +0800
Subject: [PATCH 3/3] Add a release note

---
 clang-tools-extra/docs/ReleaseNotes.rst   | 4 
 .../checkers/readability/else-after-return-if-consteval.cpp   | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6a2b8d3b6ded6..aba5102b32efb 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -337,6 +337,10 @@ Changes in existing checks
   ` check by excluding include
   directives that form the filename using macro.
 
+- Improved :doc:`readability-else-after-return
+  ` check to ignore
+  `consteval if` condition, where need to retain the else statement.
+
 - Improved :doc:`readability-identifier-naming
   ` check in 
`GetConfigPerFile`
   mode by resolving symbolic links to header files. Fixed handling of Hungarian
diff --git 

[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-12 Thread via cfe-commits

https://github.com/JoverZhang updated 
https://github.com/llvm/llvm-project/pull/91588

>From 19bf94ca3c093a6904482eab599f8366cad1384e Mon Sep 17 00:00:00 2001
From: Jover Zhang 
Date: Thu, 9 May 2024 20:56:51 +0800
Subject: [PATCH 1/3] [clang-tidy] Ignore `if consteval` in else-after-return

---
 .../clang-tidy/readability/ElseAfterReturnCheck.cpp   | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
index 1e85caf688355..3ee09b2e6442c 100644
--- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -317,6 +317,10 @@ void ElseAfterReturnCheck::check(const 
MatchFinder::MatchResult ) {
 return;
   }
 
+  if (If->isConsteval()) {
+return;
+  }
+
   DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
<< ControlFlowInterruptor << SourceRange(ElseLoc);
   removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc);

>From 2a394ddde92b23f9407ca74e597b569bb01da35f Mon Sep 17 00:00:00 2001
From: Jover Zhang 
Date: Sun, 12 May 2024 22:40:14 +0800
Subject: [PATCH 2/3] Add test case

---
 .../readability/ElseAfterReturnCheck.cpp|  8 ++--
 .../else-after-return-if-consteval.cpp  | 17 +
 2 files changed, 19 insertions(+), 6 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
index 3ee09b2e6442c..2b185e7594add 100644
--- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -113,7 +113,7 @@ static bool containsDeclInScope(const Stmt *Node) {
 }
 
 static void removeElseAndBrackets(DiagnosticBuilder , ASTContext ,
-   const Stmt *Else, SourceLocation ElseLoc) {
+  const Stmt *Else, SourceLocation ElseLoc) {
   auto Remap = [&](SourceLocation Loc) {
 return Context.getSourceManager().getExpansionLoc(Loc);
   };
@@ -172,7 +172,7 @@ void ElseAfterReturnCheck::registerMatchers(MatchFinder 
*Finder) {
   breakStmt().bind(InterruptingStr), 
cxxThrowExpr().bind(InterruptingStr)));
   Finder->addMatcher(
   compoundStmt(
-  forEach(ifStmt(unless(isConstexpr()),
+  forEach(ifStmt(unless(isConstexpr()), unless(isConsteval()),
  hasThen(stmt(
  anyOf(InterruptsControlFlow,
compoundStmt(has(InterruptsControlFlow),
@@ -317,10 +317,6 @@ void ElseAfterReturnCheck::check(const 
MatchFinder::MatchResult ) {
 return;
   }
 
-  if (If->isConsteval()) {
-return;
-  }
-
   DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
<< ControlFlowInterruptor << SourceRange(ElseLoc);
   removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc);
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
new file mode 100644
index 0..6235d8623ca7b
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-else-after-return %t 
+
+// Consteval if is an exception to the rule, we cannot remove the else.
+void f() {
+  if (sizeof(int) > 4) {
+return;
+  } else {
+return;
+  }
+  // CHECK-MESSAGES: [[@LINE-3]]:5: warning: do not use 'else' after 'return'
+
+  if consteval {
+return;
+  } else {
+return;
+  }
+}

>From 1e88302ea84491967ad61e6c32ad87c15e02f3bf Mon Sep 17 00:00:00 2001
From: Jover Zhang 
Date: Mon, 13 May 2024 10:09:04 +0800
Subject: [PATCH 3/3] Add a release note

---
 clang-tools-extra/docs/ReleaseNotes.rst   | 4 
 .../checkers/readability/else-after-return-if-consteval.cpp   | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6a2b8d3b6ded6..aba5102b32efb 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -337,6 +337,10 @@ Changes in existing checks
   ` check by excluding include
   directives that form the filename using macro.
 
+- Improved :doc:`readability-else-after-return
+  ` check to ignore
+  `consteval if` condition, where need to retain the else statement.
+
 - Improved :doc:`readability-identifier-naming
   ` check in 
`GetConfigPerFile`
   mode by resolving symbolic links to header files. Fixed handling of Hungarian
diff --git 

[clang] de641e2 - [clang-format] Fix buildbot failures

2024-05-12 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-05-12T18:56:18-07:00
New Revision: de641e289269061f8bdb138bb5c50e27ef4b354f

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

LOG: [clang-format] Fix buildbot failures

Fix the following buildbot failures by making LangOpts in the unit test
static:
https://lab.llvm.org/buildbot/#/builders/236/builds/11223
https://lab.llvm.org/buildbot/#/builders/239/builds/6968

Added: 


Modified: 
clang/unittests/Format/QualifierFixerTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index 5463bfbb65ca6..fdc392e5d9481 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -1055,7 +1055,7 @@ TEST_F(QualifierFixerTest, IsQualifierType) {
   ConfiguredTokens.push_back(tok::kw_constexpr);
   ConfiguredTokens.push_back(tok::kw_friend);
 
-  LangOptions LangOpts{getFormattingLangOpts()};
+  static const LangOptions LangOpts{getFormattingLangOpts()};
 
   auto Tokens = annotate(
   "const static inline auto restrict int double long constexpr friend");



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


[clang] 626025a - Revert "[clang-format] Fix buildbot failures"

2024-05-12 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-05-12T18:35:35-07:00
New Revision: 626025ac7796b70cde9fc0fd4f688c3441949d04

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

LOG: Revert "[clang-format] Fix buildbot failures"

This reverts commit 0869204cff22831d0bb19a82c99bf85e4deb4ae3, which caused a
buildbot failure:
https://lab.llvm.org/buildbot/#/builders/5/builds/43322

Added: 


Modified: 
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/lib/Format/QualifierAlignmentFixer.h
clang/unittests/Format/QualifierFixerTest.cpp

Removed: 




diff  --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 077ce5e597a22..a904f0b773c6d 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -281,7 +281,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
 
 const FormatToken *LastSimpleTypeSpecifier = TypeToken;
 while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment(),
- )) {
+ LangOpts)) {
   LastSimpleTypeSpecifier = LastSimpleTypeSpecifier->getNextNonComment();
 }
 
@@ -414,7 +414,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeLeft(
 const FormatToken *LastSimpleTypeSpecifier = TypeToken;
 while (isConfiguredQualifierOrType(
 LastSimpleTypeSpecifier->getPreviousNonComment(),
-ConfiguredQualifierTokens, )) {
+ConfiguredQualifierTokens, LangOpts)) {
   LastSimpleTypeSpecifier =
   LastSimpleTypeSpecifier->getPreviousNonComment();
 }
@@ -613,18 +613,16 @@ void prepareLeftRightOrderingForQualifierAlignmentFixer(
 }
 
 bool LeftRightQualifierAlignmentFixer::isQualifierOrType(
-const FormatToken *Tok, const LangOptions *LangOpts) {
-  return Tok &&
- (Tok->isTypeName(LangOpts ? *LangOpts : getFormattingLangOpts()) ||
-  Tok->is(tok::kw_auto) || isQualifier(Tok));
+const FormatToken *Tok, const LangOptions ) {
+  return Tok && (Tok->isTypeName(LangOpts) || Tok->is(tok::kw_auto) ||
+ isQualifier(Tok));
 }
 
 bool LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
 const FormatToken *Tok, const std::vector ,
-const LangOptions *LangOpts) {
-  return Tok &&
- (Tok->isTypeName(LangOpts ? *LangOpts : getFormattingLangOpts()) ||
-  Tok->is(tok::kw_auto) || isConfiguredQualifier(Tok, Qualifiers));
+const LangOptions ) {
+  return Tok && (Tok->isTypeName(LangOpts) || Tok->is(tok::kw_auto) ||
+ isConfiguredQualifier(Tok, Qualifiers));
 }
 
 // If a token is an identifier and it's upper case, it could

diff  --git a/clang/lib/Format/QualifierAlignmentFixer.h 
b/clang/lib/Format/QualifierAlignmentFixer.h
index 97fcb42e4b2e5..710fa2dc00309 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.h
+++ b/clang/lib/Format/QualifierAlignmentFixer.h
@@ -72,11 +72,11 @@ class LeftRightQualifierAlignmentFixer : public 
TokenAnalyzer {
 
   // Is the Token a simple or qualifier type
   static bool isQualifierOrType(const FormatToken *Tok,
-const LangOptions *LangOpts = nullptr);
+const LangOptions );
   static bool
   isConfiguredQualifierOrType(const FormatToken *Tok,
   const std::vector ,
-  const LangOptions *LangOpts = nullptr);
+  const LangOptions );
 
   // Is the Token likely a Macro
   static bool isPossibleMacro(const FormatToken *Tok);

diff  --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index 792d8f3c3a982..5463bfbb65ca6 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -1055,70 +1055,82 @@ TEST_F(QualifierFixerTest, IsQualifierType) {
   ConfiguredTokens.push_back(tok::kw_constexpr);
   ConfiguredTokens.push_back(tok::kw_friend);
 
+  LangOptions LangOpts{getFormattingLangOpts()};
+
   auto Tokens = annotate(
   "const static inline auto restrict int double long constexpr friend");
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
 
   EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
-  Tokens[0], ConfiguredTokens));
+  Tokens[0], ConfiguredTokens, LangOpts));
   EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
-  Tokens[1], ConfiguredTokens));
+  Tokens[1], ConfiguredTokens, LangOpts));
   EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
-  Tokens[2], ConfiguredTokens));
+  Tokens[2], ConfiguredTokens, LangOpts));
   

[clang] [clang] visit constraint of NTTP (PR #91842)

2024-05-12 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/91842

>From 0ebdcec675c39b26b8bee1a8b07c12fae2c58523 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sat, 11 May 2024 14:04:23 +0800
Subject: [PATCH] [clang] visit constraint of NTTP

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/AST/StmtProfile.cpp |  4 
 .../temp.fct/temp.func.order/p6.cpp   |  6 +++---
 clang/test/SemaCXX/PR77377.cpp| 19 +++
 4 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/PR77377.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7c5dcc59c7016..30d359c582d3f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -707,6 +707,7 @@ Bug Fixes to C++ Support
   initialized, rather than evaluating them as a part of the larger manifestly 
constant evaluated
   expression.
 - Fix a bug in access control checking due to dealyed checking of friend 
declaration. Fixes (#GH12361).
+- Fix a bug on template class partial specialization due to traverse of 
constraint of NTTP. Fixes (#GH77377).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 8fb8940142eb0..a23a2efa2389e 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -2257,6 +2257,10 @@ void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
 const SubstNonTypeTemplateParmExpr *E) {
   // Profile exactly as the replacement expression.
   Visit(E->getReplacement());
+  if (auto *NTTP = dyn_cast(E->getParameter());
+  NTTP && NTTP->getPlaceholderTypeConstraint()) {
+Visit(NTTP->getPlaceholderTypeConstraint());
+  }
 }
 
 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
diff --git a/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp 
b/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
index 9f44878da6254..5f9719a2dc561 100644
--- a/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -79,14 +79,14 @@ template struct Y2 {}; // 
expected-note {{partial
 template class U, typename... Z>
 struct Y3 { Y3()=delete; };
 template class U, typename... Z>
-struct Y3 { Y3()=delete; };
+struct Y3 { Y3()=delete; }; // expected-note {{partial 
specialization matches [with T = int, I = 1, W = 1, S = A{}, U = S, Z = ]}}
 template class U, typename... Z>
-struct Y3 {};
+struct Y3 {}; // expected-note {{partial specialization 
matches [with T = int, I = 1, W = 1, S = A{}, U = S, Z = ]}}
 
 void f() {
   Y1 a;
   Y2 b; // expected-error {{ambiguous partial specializations}}
-  Y3 c;
+  Y3 c; // expected-error {{ambiguous partial 
specializations of 'Y3'}}
 }
 
 // Per [temp.func.order]p6.2.2, specifically "if the function parameters that
diff --git a/clang/test/SemaCXX/PR77377.cpp b/clang/test/SemaCXX/PR77377.cpp
new file mode 100644
index 0..ae34809c3903d
--- /dev/null
+++ b/clang/test/SemaCXX/PR77377.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+// expected-no-diagnostics
+
+template
+constexpr bool is_same_v = false;
+
+template
+constexpr bool is_same_v = true;
+
+template
+concept same_as = is_same_v;
+
+template 
+struct A {};
+
+template  auto p>
+struct A {};
+
+A<0> a;

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


[clang] [clang] visit constraint of NTTP (PR #91842)

2024-05-12 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/91842

>From 4133001711b82c93e057e1bd05476c5d052d597f Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sat, 11 May 2024 14:04:23 +0800
Subject: [PATCH] [clang] visit constraint of NTTP

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/AST/StmtProfile.cpp |  4 
 .../temp.fct/temp.func.order/p6.cpp   |  6 +++---
 clang/test/SemaCXX/PR77377.cpp| 19 +++
 4 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/PR77377.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7c5dcc59c7016..30d359c582d3f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -707,6 +707,7 @@ Bug Fixes to C++ Support
   initialized, rather than evaluating them as a part of the larger manifestly 
constant evaluated
   expression.
 - Fix a bug in access control checking due to dealyed checking of friend 
declaration. Fixes (#GH12361).
+- Fix a bug on template class partial specialization due to traverse of 
constraint of NTTP. Fixes (#GH77377).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 8fb8940142eb0..a23a2efa2389e 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -2257,6 +2257,10 @@ void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
 const SubstNonTypeTemplateParmExpr *E) {
   // Profile exactly as the replacement expression.
   Visit(E->getReplacement());
+  if (auto *NTTP = dyn_cast(E->getParameter());
+  NTTP && NTTP->getPlaceholderTypeConstraint()) {
+Visit(NTTP->getPlaceholderTypeConstraint());
+  }
 }
 
 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
diff --git a/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp 
b/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
index 9f44878da6254..5f9719a2dc561 100644
--- a/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -79,14 +79,14 @@ template struct Y2 {}; // 
expected-note {{partial
 template class U, typename... Z>
 struct Y3 { Y3()=delete; };
 template class U, typename... Z>
-struct Y3 { Y3()=delete; };
+struct Y3 { Y3()=delete; }; // expected-note {{partial 
specialization matches [with T = int, I = 1, W = 1, S = A{}, U = S, Z = ]}}
 template class U, typename... Z>
-struct Y3 {};
+struct Y3 {}; // expected-note {{partial specialization 
matches [with T = int, I = 1, W = 1, S = A{}, U = S, Z = ]}}
 
 void f() {
   Y1 a;
   Y2 b; // expected-error {{ambiguous partial specializations}}
-  Y3 c;
+  Y3 c; // expected-error {{ambiguous partial 
specializations of 'Y3'}}
 }
 
 // Per [temp.func.order]p6.2.2, specifically "if the function parameters that
diff --git a/clang/test/SemaCXX/PR77377.cpp b/clang/test/SemaCXX/PR77377.cpp
new file mode 100644
index 0..ae34809c3903d
--- /dev/null
+++ b/clang/test/SemaCXX/PR77377.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+// expected-no-diagnostics
+
+template
+constexpr bool is_same_v = false;
+
+template
+constexpr bool is_same_v = true;
+
+template
+concept same_as = is_same_v;
+
+template 
+struct A {};
+
+template  auto p>
+struct A {};
+
+A<0> a;

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


[clang] 5bde801 - [X86][vectorcall] Pass built types byval when xmm0~6 exhausted (#91846)

2024-05-12 Thread via cfe-commits

Author: Phoebe Wang
Date: 2024-05-13T08:31:49+08:00
New Revision: 5bde8017a1109128d011510dcf4ba79140a224fe

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

LOG: [X86][vectorcall] Pass built types byval when xmm0~6 exhausted (#91846)

This is how MSVC handles it. https://godbolt.org/z/fG386bjnf

Added: 


Modified: 
clang/lib/CodeGen/Targets/X86.cpp
clang/test/CodeGen/vectorcall.c

Removed: 




diff  --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 717a27fc9c574..29d98aad8fcb4 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -792,6 +792,8 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, 
CCState ,
 return ABIArgInfo::getDirect();
   return ABIArgInfo::getExpand();
 }
+if (IsVectorCall && Ty->isBuiltinType())
+  return ABIArgInfo::getDirect();
 return getIndirectResult(Ty, /*ByVal=*/false, State);
   }
 

diff  --git a/clang/test/CodeGen/vectorcall.c b/clang/test/CodeGen/vectorcall.c
index cb53ecc70351d..71dc3b0b9585a 100644
--- a/clang/test/CodeGen/vectorcall.c
+++ b/clang/test/CodeGen/vectorcall.c
@@ -140,4 +140,20 @@ void __vectorcall vectorcall_indirect_vec(
 // X86-SAME: ptr inreg noundef %0,
 // X86-SAME: i32 inreg noundef %edx,
 // X86-SAME: ptr noundef %1)
+
+void __vectorcall vectorcall_indirect_fp(
+double xmm0, double xmm1, double xmm2, double xmm3, double xmm4,
+v4f32 xmm5, v4f32 ecx, int edx, double mem) {
+}
+
+// X86: define dso_local x86_vectorcallcc void 
@"\01vectorcall_indirect_fp@@{{[0-9]+}}"
+// X86-SAME: (double inreg noundef %xmm0,
+// X86-SAME: double inreg noundef %xmm1,
+// X86-SAME: double inreg noundef %xmm2,
+// X86-SAME: double inreg noundef %xmm3,
+// X86-SAME: double inreg noundef %xmm4,
+// X86-SAME: <4 x float> inreg noundef %xmm5,
+// X86-SAME: ptr inreg noundef %0,
+// X86-SAME: i32 inreg noundef %edx,
+// X86-SAME: double noundef %mem)
 #endif



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


[clang] [X86][vectorcall] Pass built types byval when xmm0~6 exhausted (PR #91846)

2024-05-12 Thread Phoebe Wang via cfe-commits

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


[clang] [analyzer] Allow recursive functions to be trivial. (PR #91876)

2024-05-12 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/91876

>From a4b877b240ede15260f08fcb4a4622dd45a13d0a Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sat, 11 May 2024 20:18:52 -0700
Subject: [PATCH 1/4] [analyzer] Allow recursive functions to be trivial.

---
 .../Checkers/WebKit/PtrTypesSemantics.cpp  | 18 +-
 .../Checkers/WebKit/uncounted-obj-arg.cpp  |  6 ++
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index ad493587affa0..dd930ea4b4ab5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -498,22 +498,22 @@ class TrivialFunctionAnalysisVisitor
 
 bool TrivialFunctionAnalysis::isTrivialImpl(
 const Decl *D, TrivialFunctionAnalysis::CacheTy ) {
-  // If the function isn't in the cache, conservatively assume that
-  // it's not trivial until analysis completes. This makes every recursive
-  // function non-trivial. This also guarantees that each function
-  // will be scanned at most once.
-  auto [It, IsNew] = Cache.insert(std::make_pair(D, false));
+  // Treat every recursive function as trivial until otherwise proven.
+  // This guarantees each function is evaluated at most once.
+  auto [It, IsNew] = Cache.insert(std::make_pair(D, true));
   if (!IsNew)
 return It->second;
 
   const Stmt *Body = D->getBody();
-  if (!Body)
-return false;
+  if (!Body) {
+Cache[D] = false;
+return false;
+  }
 
   TrivialFunctionAnalysisVisitor V(Cache);
   bool Result = V.Visit(Body);
-  if (Result)
-Cache[D] = true;
+  if (!Result)
+Cache[D] = false;
 
   return Result;
 }
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 073f3252160ee..39bc76197d204 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -181,6 +181,8 @@ class RefCounted {
   void method();
   void someFunction();
   int otherFunction();
+  unsigned recursiveFunction(int n) { return !n ? 1 : recursiveFunction(n - 
1);  }
+  unsigned recursiveComplexFunction(int n) { return !n ? otherFunction() : 
recursiveComplexFunction(n - 1);  }
 
   int trivial1() { return 123; }
   float trivial2() { return 0.3; }
@@ -417,6 +419,10 @@ class UnrelatedClass {
 RefCounted::singleton().trivial18(); // no-warning
 RefCounted::singleton().someFunction(); // no-warning
 
+getFieldTrivial().recursiveFunction(7); // no-warning
+getFieldTrivial().recursiveComplexFunction(9);
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+
 getFieldTrivial().someFunction();
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
 getFieldTrivial().nonTrivial1();

>From ceb70513d342aadb339fde6cf7ccabc96a243dfd Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sat, 11 May 2024 20:24:10 -0700
Subject: [PATCH 2/4] Fix formatting.

---
 clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index dd930ea4b4ab5..83a0300c627e8 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -507,7 +507,7 @@ bool TrivialFunctionAnalysis::isTrivialImpl(
   const Stmt *Body = D->getBody();
   if (!Body) {
 Cache[D] = false;
-return false;
+return false;
   }
 
   TrivialFunctionAnalysisVisitor V(Cache);

>From 90cf7dde6e71b1d11ee0d88cd8afe0bce47531e1 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 12 May 2024 15:15:33 -0700
Subject: [PATCH 3/4] Fix the TrivialFunctionAnalysis::isTrivialImpl for
 mutually recursive functions.

Instead of assuming every function to be initially trivial, we explicitly track
the set of functions that we're currently visting. When one of the currently 
visited
function is determined to be not trivial, we clear this set to signal that all
mutually recursive functions are non-trivial. We conclude that a function is 
trivial
when Visit() call on the function body returned true **AND** the set still 
contains
the function.

To implement this new algorithm, a new public function, IsFunctionTrivial,
is introduced to TrivialFunctionAnalysisVisitor, and various Visit functions in
TrivialFunctionAnalysisVisitor has been updated to use this function instead of
TrivialFunctionAnalysis::isTrivialImpl, which is now a wrapper for the function.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp | 51 +++
 .../Checkers/WebKit/uncounted-obj-arg.cpp | 20 +++-
 

[clang] [analyzer] Allow recursive functions to be trivial. (PR #91876)

2024-05-12 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/91876

>From a4b877b240ede15260f08fcb4a4622dd45a13d0a Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sat, 11 May 2024 20:18:52 -0700
Subject: [PATCH 1/3] [analyzer] Allow recursive functions to be trivial.

---
 .../Checkers/WebKit/PtrTypesSemantics.cpp  | 18 +-
 .../Checkers/WebKit/uncounted-obj-arg.cpp  |  6 ++
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index ad493587affa0..dd930ea4b4ab5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -498,22 +498,22 @@ class TrivialFunctionAnalysisVisitor
 
 bool TrivialFunctionAnalysis::isTrivialImpl(
 const Decl *D, TrivialFunctionAnalysis::CacheTy ) {
-  // If the function isn't in the cache, conservatively assume that
-  // it's not trivial until analysis completes. This makes every recursive
-  // function non-trivial. This also guarantees that each function
-  // will be scanned at most once.
-  auto [It, IsNew] = Cache.insert(std::make_pair(D, false));
+  // Treat every recursive function as trivial until otherwise proven.
+  // This guarantees each function is evaluated at most once.
+  auto [It, IsNew] = Cache.insert(std::make_pair(D, true));
   if (!IsNew)
 return It->second;
 
   const Stmt *Body = D->getBody();
-  if (!Body)
-return false;
+  if (!Body) {
+Cache[D] = false;
+return false;
+  }
 
   TrivialFunctionAnalysisVisitor V(Cache);
   bool Result = V.Visit(Body);
-  if (Result)
-Cache[D] = true;
+  if (!Result)
+Cache[D] = false;
 
   return Result;
 }
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 073f3252160ee..39bc76197d204 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -181,6 +181,8 @@ class RefCounted {
   void method();
   void someFunction();
   int otherFunction();
+  unsigned recursiveFunction(int n) { return !n ? 1 : recursiveFunction(n - 
1);  }
+  unsigned recursiveComplexFunction(int n) { return !n ? otherFunction() : 
recursiveComplexFunction(n - 1);  }
 
   int trivial1() { return 123; }
   float trivial2() { return 0.3; }
@@ -417,6 +419,10 @@ class UnrelatedClass {
 RefCounted::singleton().trivial18(); // no-warning
 RefCounted::singleton().someFunction(); // no-warning
 
+getFieldTrivial().recursiveFunction(7); // no-warning
+getFieldTrivial().recursiveComplexFunction(9);
+// expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
+
 getFieldTrivial().someFunction();
 // expected-warning@-1{{Call argument for 'this' parameter is uncounted 
and unsafe}}
 getFieldTrivial().nonTrivial1();

>From ceb70513d342aadb339fde6cf7ccabc96a243dfd Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sat, 11 May 2024 20:24:10 -0700
Subject: [PATCH 2/3] Fix formatting.

---
 clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index dd930ea4b4ab5..83a0300c627e8 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -507,7 +507,7 @@ bool TrivialFunctionAnalysis::isTrivialImpl(
   const Stmt *Body = D->getBody();
   if (!Body) {
 Cache[D] = false;
-return false;
+return false;
   }
 
   TrivialFunctionAnalysisVisitor V(Cache);

>From 90cf7dde6e71b1d11ee0d88cd8afe0bce47531e1 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 12 May 2024 15:15:33 -0700
Subject: [PATCH 3/3] Fix the TrivialFunctionAnalysis::isTrivialImpl for
 mutually recursive functions.

Instead of assuming every function to be initially trivial, we explicitly track
the set of functions that we're currently visting. When one of the currently 
visited
function is determined to be not trivial, we clear this set to signal that all
mutually recursive functions are non-trivial. We conclude that a function is 
trivial
when Visit() call on the function body returned true **AND** the set still 
contains
the function.

To implement this new algorithm, a new public function, IsFunctionTrivial,
is introduced to TrivialFunctionAnalysisVisitor, and various Visit functions in
TrivialFunctionAnalysisVisitor has been updated to use this function instead of
TrivialFunctionAnalysis::isTrivialImpl, which is now a wrapper for the function.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp | 51 +++
 .../Checkers/WebKit/uncounted-obj-arg.cpp | 20 +++-
 

[clang] [analyzer] Allow recursive functions to be trivial. (PR #91876)

2024-05-12 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

> You should add a test for mutually recursive functions. I suspect something 
> like this doesn't work:
> 
> ```c++
> int non_trivial();
> int f(bool b) { return g(!b) + non_trivial(); }
> int g(bool b) { return b ? f(b) : 1; }
> 
> getFieldTrivial().f(true);  // expected-warning {{...}}
> getFieldTrivial().g(true);  // expected-warning {{...}}
> ```

Duh, of course. Thanks for pointing out the obvious flaw.

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


[clang] [CodeGen] Revert "Generate assume loads only with -fstrict-vtable-pointers" (PR #91900)

2024-05-12 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/91900

>From d2e06b957cada08371131874219973c7cbd9b196 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Sun, 12 May 2024 16:45:07 -0400
Subject: [PATCH] [CodeGen] Revert "Generate assume loads only with
 -fstrict-vtable-pointers"

This reverts commit 69dc971527faad8ccfa754ce7d855908b7a3f923.

This was supposed to be a temporary measure, but unfortunately as things tend 
to go in software development, temporary measures become permanent.

Anyway, in the 9 years since then, we have greatly improved the way InstCombine 
works with assumes.

So let's not make assumption loads require -fstrict-vtable-pointers.
---
 clang/lib/CodeGen/CGClass.cpp  | 5 +
 clang/test/CodeGenCXX/vtable-assume-load-address-space.cpp | 3 +--
 clang/test/CodeGenCXX/vtable-assume-load.cpp   | 5 ++---
 3 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index b3077292f4a20..70f57ff8688f7 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -2258,12 +2258,9 @@ void CodeGenFunction::EmitCXXConstructorCall(const 
CXXConstructorDecl *D,
   // FIXME: If vtable is used by ctor/dtor, or if vtable is external and we are
   // sure that definition of vtable is not hidden,
   // then we are always safe to refer to it.
-  // FIXME: It looks like InstCombine is very inefficient on dealing with
-  // assumes. Make assumption loads require -fstrict-vtable-pointers 
temporarily.
   if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
   ClassDecl->isDynamicClass() && Type != Ctor_Base &&
-  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl) &&
-  CGM.getCodeGenOpts().StrictVTablePointers)
+  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl))
 EmitVTableAssumptionLoads(ClassDecl, This);
 }
 
diff --git a/clang/test/CodeGenCXX/vtable-assume-load-address-space.cpp 
b/clang/test/CodeGenCXX/vtable-assume-load-address-space.cpp
index d765fe94d9b08..4c3765fa795a2 100644
--- a/clang/test/CodeGenCXX/vtable-assume-load-address-space.cpp
+++ b/clang/test/CodeGenCXX/vtable-assume-load-address-space.cpp
@@ -1,5 +1,4 @@
-// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -std=c++11 -emit-llvm -o %t.ll 
-O1 -disable-llvm-passes -fms-extensions -fstrict-vtable-pointers
-// FIXME: Assume load should not require -fstrict-vtable-pointers
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -std=c++11 -emit-llvm -o %t.ll 
-O1 -disable-llvm-passes -fms-extensions
 
 // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t.ll %s
diff --git a/clang/test/CodeGenCXX/vtable-assume-load.cpp 
b/clang/test/CodeGenCXX/vtable-assume-load.cpp
index 6ce07d0db1b15..c48fc71ccea87 100644
--- a/clang/test/CodeGenCXX/vtable-assume-load.cpp
+++ b/clang/test/CodeGenCXX/vtable-assume-load.cpp
@@ -1,6 +1,5 @@
-// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-passes -fms-extensions -fstrict-vtable-pointers
-// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-passes -fms-extensions -fstrict-vtable-pointers
-// FIXME: Assume load should not require -fstrict-vtable-pointers
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-passes -fms-extensions
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-passes -fms-extensions
 
 // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t.ll %s

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


[clang] [CodeGen] Revert "Generate assume loads only with -fstrict-vtable-pointers" (PR #91900)

2024-05-12 Thread via cfe-commits

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


[clang] [CodeGen] Revert "Generate assume loads only with -fstrict-vtable-pointers" (PR #91900)

2024-05-12 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/91900

>From 74e4d18ffe6efed565a6bd736eb7e289e7ede73b Mon Sep 17 00:00:00 2001
From: Rose 
Date: Sun, 12 May 2024 16:45:07 -0400
Subject: [PATCH] [CodeGen] Revert "Generate assume loads only with
 -fstrict-vtable-pointers"

This reverts commit 69dc971527faad8ccfa754ce7d855908b7a3f923.

This was supposed to be a temporary measure, but unfortunately as things tend 
to go in software development, temporary measures become permanent.

Anyway, in the 9 years since then, we have greatly improved the way InstCombine 
works with assumes.

So let's not make assumption loads require -fstrict-vtable-pointers.
---
 clang/lib/CodeGen/CGClass.cpp| 5 +
 clang/test/CodeGenCXX/vtable-assume-load.cpp | 5 ++---
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index b3077292f4a20..70f57ff8688f7 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -2258,12 +2258,9 @@ void CodeGenFunction::EmitCXXConstructorCall(const 
CXXConstructorDecl *D,
   // FIXME: If vtable is used by ctor/dtor, or if vtable is external and we are
   // sure that definition of vtable is not hidden,
   // then we are always safe to refer to it.
-  // FIXME: It looks like InstCombine is very inefficient on dealing with
-  // assumes. Make assumption loads require -fstrict-vtable-pointers 
temporarily.
   if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
   ClassDecl->isDynamicClass() && Type != Ctor_Base &&
-  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl) &&
-  CGM.getCodeGenOpts().StrictVTablePointers)
+  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl))
 EmitVTableAssumptionLoads(ClassDecl, This);
 }
 
diff --git a/clang/test/CodeGenCXX/vtable-assume-load.cpp 
b/clang/test/CodeGenCXX/vtable-assume-load.cpp
index 6ce07d0db1b15..c48fc71ccea87 100644
--- a/clang/test/CodeGenCXX/vtable-assume-load.cpp
+++ b/clang/test/CodeGenCXX/vtable-assume-load.cpp
@@ -1,6 +1,5 @@
-// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-passes -fms-extensions -fstrict-vtable-pointers
-// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-passes -fms-extensions -fstrict-vtable-pointers
-// FIXME: Assume load should not require -fstrict-vtable-pointers
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-passes -fms-extensions
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-passes -fms-extensions
 
 // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t.ll %s

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


[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-12 Thread Chris Copeland via cfe-commits

chrisnc wrote:

I'd like to also address #47815, but I wasn't able to find the right path to 
answer "is this M-profile" from `TargetInfo`. Would appreciate any suggestions 
on that. I think it may require `dynamic_cast`-ing the `TargetInfo` to an 
`ARMTargetInfo`, and then change one of the methods in there to be public...

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


[clang] [CodeGen] Revert "Generate assume loads only with -fstrict-vtable-pointers" (PR #91900)

2024-05-12 Thread via cfe-commits

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


[clang] Revert "[CodeGen] Emit vtable assumptions without requiring -fstrict-vtable-pointers" (PR #91900)

2024-05-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: AtariDreams (AtariDreams)


Changes

This was supposed to be a temporary measure, but unfortunately as things tend 
to go in software development, temporary measures become permanent.

In the 9 years since then, we have greatly improved the way InstCombine works 
with assumes.

So, let's not make assumption loads require -fstrict-vtable-pointers.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGClass.cpp (+1-4) 
- (modified) clang/test/CodeGenCXX/vtable-assume-load.cpp (+2-3) 


``diff
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index b3077292f4a20..70f57ff8688f7 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -2258,12 +2258,9 @@ void CodeGenFunction::EmitCXXConstructorCall(const 
CXXConstructorDecl *D,
   // FIXME: If vtable is used by ctor/dtor, or if vtable is external and we are
   // sure that definition of vtable is not hidden,
   // then we are always safe to refer to it.
-  // FIXME: It looks like InstCombine is very inefficient on dealing with
-  // assumes. Make assumption loads require -fstrict-vtable-pointers 
temporarily.
   if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
   ClassDecl->isDynamicClass() && Type != Ctor_Base &&
-  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl) &&
-  CGM.getCodeGenOpts().StrictVTablePointers)
+  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl))
 EmitVTableAssumptionLoads(ClassDecl, This);
 }
 
diff --git a/clang/test/CodeGenCXX/vtable-assume-load.cpp 
b/clang/test/CodeGenCXX/vtable-assume-load.cpp
index 6ce07d0db1b15..c48fc71ccea87 100644
--- a/clang/test/CodeGenCXX/vtable-assume-load.cpp
+++ b/clang/test/CodeGenCXX/vtable-assume-load.cpp
@@ -1,6 +1,5 @@
-// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-passes -fms-extensions -fstrict-vtable-pointers
-// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-passes -fms-extensions -fstrict-vtable-pointers
-// FIXME: Assume load should not require -fstrict-vtable-pointers
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-passes -fms-extensions
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-passes -fms-extensions
 
 // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t.ll %s

``




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


[clang] Revert "[CodeGen] Emit vtable assumptions without requiring -fstrict-vtable-pointers" (PR #91900)

2024-05-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: AtariDreams (AtariDreams)


Changes

This was supposed to be a temporary measure, but unfortunately as things tend 
to go in software development, temporary measures become permanent.

In the 9 years since then, we have greatly improved the way InstCombine works 
with assumes.

So, let's not make assumption loads require -fstrict-vtable-pointers.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGClass.cpp (+1-4) 
- (modified) clang/test/CodeGenCXX/vtable-assume-load.cpp (+2-3) 


``diff
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index b3077292f4a20..70f57ff8688f7 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -2258,12 +2258,9 @@ void CodeGenFunction::EmitCXXConstructorCall(const 
CXXConstructorDecl *D,
   // FIXME: If vtable is used by ctor/dtor, or if vtable is external and we are
   // sure that definition of vtable is not hidden,
   // then we are always safe to refer to it.
-  // FIXME: It looks like InstCombine is very inefficient on dealing with
-  // assumes. Make assumption loads require -fstrict-vtable-pointers 
temporarily.
   if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
   ClassDecl->isDynamicClass() && Type != Ctor_Base &&
-  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl) &&
-  CGM.getCodeGenOpts().StrictVTablePointers)
+  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl))
 EmitVTableAssumptionLoads(ClassDecl, This);
 }
 
diff --git a/clang/test/CodeGenCXX/vtable-assume-load.cpp 
b/clang/test/CodeGenCXX/vtable-assume-load.cpp
index 6ce07d0db1b15..c48fc71ccea87 100644
--- a/clang/test/CodeGenCXX/vtable-assume-load.cpp
+++ b/clang/test/CodeGenCXX/vtable-assume-load.cpp
@@ -1,6 +1,5 @@
-// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-passes -fms-extensions -fstrict-vtable-pointers
-// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-passes -fms-extensions -fstrict-vtable-pointers
-// FIXME: Assume load should not require -fstrict-vtable-pointers
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-passes -fms-extensions
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-passes -fms-extensions
 
 // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t.ll %s

``




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


[clang] Revert "[CodeGen] Emit vtable assumptions without requiring -fstrict-vtable-pointers" (PR #91900)

2024-05-12 Thread via cfe-commits

https://github.com/AtariDreams created 
https://github.com/llvm/llvm-project/pull/91900

This was supposed to be a temporary measure, but unfortunately as things tend 
to go in software development, temporary measures become permanent.

In the 9 years since then, we have greatly improved the way InstCombine works 
with assumes.

So, let's not make assumption loads require -fstrict-vtable-pointers.

>From 2c588ae19e197cc3602c756c518681b088805671 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Sun, 12 May 2024 16:45:07 -0400
Subject: [PATCH] [CodeGen] Emit vtable assumptions without requiting
 -fstrict-vtable-pointers

This was supposed to be a temporary measure, but unfortunately as things tend 
to go in software development, temporary measures become permanent.

Anyway, in the 9 years since then, we have greatly improved the way InstCombine 
works with assumes.

So let's not make assumption loads require -fstrict-vtable-pointers

Revert "[CodeGen] Emit vtable assumptions without requiting 
-fstrict-vtable-pointers"

This reverts commit ef6f2c3028f97ce88af91e18c05cd1f857721a3e.

Revert "Generate assume loads only with -fstrict-vtable-pointers"

This reverts commit 69dc971527faad8ccfa754ce7d855908b7a3f923.

This was supposed to be a temporary measure, but unfortunately as things tend 
to go in software development, temporary measures become permanent.

Anyway, in the 9 years since then, we have greatly improved the way InstCombine 
works with assumes.

So let's not make assumption loads require -fstrict-vtable-pointers
---
 clang/lib/CodeGen/CGClass.cpp| 5 +
 clang/test/CodeGenCXX/vtable-assume-load.cpp | 5 ++---
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index b3077292f4a20..70f57ff8688f7 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -2258,12 +2258,9 @@ void CodeGenFunction::EmitCXXConstructorCall(const 
CXXConstructorDecl *D,
   // FIXME: If vtable is used by ctor/dtor, or if vtable is external and we are
   // sure that definition of vtable is not hidden,
   // then we are always safe to refer to it.
-  // FIXME: It looks like InstCombine is very inefficient on dealing with
-  // assumes. Make assumption loads require -fstrict-vtable-pointers 
temporarily.
   if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
   ClassDecl->isDynamicClass() && Type != Ctor_Base &&
-  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl) &&
-  CGM.getCodeGenOpts().StrictVTablePointers)
+  CGM.getCXXABI().canSpeculativelyEmitVTable(ClassDecl))
 EmitVTableAssumptionLoads(ClassDecl, This);
 }
 
diff --git a/clang/test/CodeGenCXX/vtable-assume-load.cpp 
b/clang/test/CodeGenCXX/vtable-assume-load.cpp
index 6ce07d0db1b15..c48fc71ccea87 100644
--- a/clang/test/CodeGenCXX/vtable-assume-load.cpp
+++ b/clang/test/CodeGenCXX/vtable-assume-load.cpp
@@ -1,6 +1,5 @@
-// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-passes -fms-extensions -fstrict-vtable-pointers
-// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-passes -fms-extensions -fstrict-vtable-pointers
-// FIXME: Assume load should not require -fstrict-vtable-pointers
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o %t.ll -O1 
-disable-llvm-passes -fms-extensions
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -emit-llvm -o %t.ms.ll -O1 
-disable-llvm-passes -fms-extensions
 
 // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t.ll %s
 // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t.ll %s

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


[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-12 Thread Chris Copeland via cfe-commits

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


[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-12 Thread Chris Copeland via cfe-commits

https://github.com/chrisnc updated 
https://github.com/llvm/llvm-project/pull/91870

>From b72b63c51b1859e1a7e792eda20549ef93c8d6c0 Mon Sep 17 00:00:00 2001
From: Chris Copeland 
Date: Sat, 11 May 2024 00:15:50 -0700
Subject: [PATCH] [ARM][clang] Fix warning for VFP function calls from
 interrupts.

This warning has two issues:
 - The interrupt attribute doesn't only change how volatile registers
   are treated; it also causes the function to return using an exception
   return instruction. This warning allows calls from one function with
   the interrupt attribute to another, and the diagnostic text suggests
   that not having the attribute on the callee is the problem. Actually
   making such a call will lead to a double exception return, which is
   unpredictable according to the ARM architecture manual section
   B9.1.1, "Restrictions on exception return instructions". Even on
   machines where an exception return from user/system mode is
   tolerated, if the callee's interrupt type is anything other than a
   supervisor call or secure monitor call, it will also return to a
   different address than a normal function would. For example,
   returning from an "IRQ" handler will return to lr - 4, which will
   generally result in calling the same function again.
 - It is part of the -Wextra diagnostic group and can't be individually
   disabled when using -Wextra, which also means the diagnostic text of
   this specific warning appears in the documentation of -Wextra.

This change addresses both issues. Rather than check that the callee has
the interrupt attribute, check that it uses the soft-float feature,
which will prevent use of VFP state. The warning is also given its own
diagnostic group.

Closes #34876.
---
 clang/docs/ReleaseNotes.rst   | 11 +++
 clang/include/clang/Basic/Attr.td |  7 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 ---
 clang/lib/Sema/SemaExpr.cpp   | 19 ++-
 clang/test/Sema/arm-interrupt-attr.c  |  6 +++---
 5 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7c5dcc59c7016..ebf26c3ab4deb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -352,6 +352,10 @@ Modified Compiler Flags
   evaluating to ``true`` and an empty body such as ``while(1);``)
   are considered infinite, even when the ``-ffinite-loop`` flag is set.
 
+- Removed "arm interrupt calling convention" warning that was included in
+  ``-Wextra`` but did not have its own flag. Added
+  ``-Warm-interrupt-vfp-clobber`` that enables the modified warning.
+
 Removed Compiler Flags
 -
 
@@ -484,6 +488,13 @@ Improvements to Clang's diagnostics
}
  };
 
+- On ARM, Clang no longer suggests adding ``__attribute__((interrupt))`` to 
normal
+  functions that are called from interrupt handlers to prevent clobbering VFP
+  registers as part of ``-Wextra``. Following this suggestion leads to
+  unpredictable behavior. Instead, ``-Warm-interrupt-vfp-clobber`` can now be
+  used to detect calling functions that don't have VFP disabled with
+  ``__attribute__((target("soft-float")))`` from an interrupt handler.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..04e3b8f949992 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3090,6 +3090,13 @@ def Target : InheritableAttr {
   }
 }
 
+bool hasFeature(StringRef Feature) const {
+  StringRef Features = getFeaturesStr();
+  SmallVector AttrFeatures;
+  Features.split(AttrFeatures, ",");
+  return Features.contains(Feature);
+}
+
 bool isDefaultVersion() const { return getFeaturesStr() == "default"; }
   }];
 }
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d6863f90edb6e..1c5f5ffb03dc5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -336,9 +336,10 @@ def warn_anyx86_excessive_regsave : Warning<
   " with attribute 'no_caller_saved_registers'"
   " or be compiled with '-mgeneral-regs-only'">,
   InGroup>;
-def warn_arm_interrupt_calling_convention : Warning<
-   "call to function without interrupt attribute could clobber interruptee's 
VFP registers">,
-   InGroup;
+def warn_arm_interrupt_vfp_clobber : Warning<
+   "calling a VFP-enabled function from an interrupt could clobber the "
+   "interruptee's VFP registers">,
+   InGroup>;
 def warn_interrupt_attribute_invalid : Warning<
"%select{MIPS|MSP430|RISC-V}0 'interrupt' attribute only applies to "
"functions that have %select{no parameters|a 'void' return type}1">,
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 

[clang-tools-extra] [flang] [lld] [llvm] Use StringRef::operator== instead of StringRef::equals (NFC) (PR #91864)

2024-05-12 Thread Jakub Kuderski via cfe-commits

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


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


[clang-tools-extra] [flang] [lld] [llvm] Use StringRef::operator== instead of StringRef::equals (NFC) (PR #91864)

2024-05-12 Thread Amir Ayupov via cfe-commits

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

BOLT changes LGTM

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


[clang] [Clang] Add attribute for consteval builtins; Declare constexpr builtins as constexpr in C++ (PR #91894)

2024-05-12 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

Currently, GCC's behaviour for builtin function redeclarations is to just 
ignore `constexpr`: . This is slightly 
stricter, allowing non-`constexpr` redeclarations for `constexpr` builtins but 
still disallowing `constexpr` declarations for non-`constexpr` builtins.

[P2641R4 `std::is_within_lifetime`](https://wg21.link/P2641R4) is most likely 
going to be implemented as a `consteval` builtin, which the attribute allows 
implementing easily as a builtin-function with `getConstexprKind() == 
ConstexprSpecKind::Consteval`.

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


[clang] [Clang] Add __builtin_is_within_lifetime to implement P2641R4's std::is_within_lifetime (PR #91895)

2024-05-12 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

This is on top of #91894

[P2641R4](https://wg21.link/P2641R4)

Currently, this doesn't strictly check "whose complete object's lifetime began 
within `E`". A bunch of the static_asserts I have for objects under 
construction should be ill-formed instead of false, but some of them should be 
true.

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


[clang] [Clang] Add __builtin_is_within_lifetime to implement P2641R4's std::is_within_lifetime (PR #91895)

2024-05-12 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 17daa204feadf9c28fc13b7daa69c3cbe865b238 
253f58f0e34bc6dedbbfe17f68cfe9baa3a9146f -- 
clang/test/SemaCXX/builtin-is-within-lifetime.cpp 
clang/include/clang/Basic/Builtins.h clang/lib/AST/ExprConstant.cpp 
clang/lib/AST/Interp/State.h clang/lib/Sema/SemaChecking.cpp 
clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclCXX.cpp 
clang/lib/Sema/SemaExpr.cpp clang/test/Sema/builtin-redecl.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f3b31d87dd..ffe2f172a9 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1507,7 +1507,8 @@ CallStackFrame::~CallStackFrame() {
 }
 
 static bool isRead(AccessKinds AK) {
-  return AK == AK_Read || AK == AK_ReadObjectRepresentation || AK == 
AK_IsWithinLifetime;
+  return AK == AK_Read || AK == AK_ReadObjectRepresentation ||
+ AK == AK_IsWithinLifetime;
 }
 
 static bool isModification(AccessKinds AK) {
@@ -1535,7 +1536,8 @@ static bool isAnyAccess(AccessKinds AK) {
 
 /// Is this an access per the C++ definition?
 static bool isFormalAccess(AccessKinds AK) {
-  return isAnyAccess(AK) && AK != AK_Construct && AK != AK_Destroy && AK != 
AK_IsWithinLifetime;
+  return isAnyAccess(AK) && AK != AK_Construct && AK != AK_Destroy &&
+ AK != AK_IsWithinLifetime;
 }
 
 /// Is this kind of axcess valid on an indeterminate object value?
@@ -3655,7 +3657,8 @@ struct CompleteObject {
 // In C++14 onwards, it is permitted to read a mutable member whose
 // lifetime began within the evaluation.
 // FIXME: Should we also allow this in C++11?
-if (!Info.getLangOpts().CPlusPlus14 && AK != 
AccessKinds::AK_IsWithinLifetime)
+if (!Info.getLangOpts().CPlusPlus14 &&
+AK != AccessKinds::AK_IsWithinLifetime)
   return false;
 return lifetimeStartedInEvaluation(Info, Base, /*MutableSubobject*/true);
   }
@@ -4093,7 +4096,7 @@ static CompleteObject findCompleteObject(EvalInfo , 
const Expr *E,
 // started in the current evaluation.
 BaseVal = Info.EvaluatingDeclValue;
 if (AK == AccessKinds::AK_IsWithinLifetime)
-  return CompleteObject();  // Not within lifetime
+  return CompleteObject(); // Not within lifetime
   } else if (const ValueDecl *D = LVal.Base.dyn_cast()) {
 // Allow reading from a GUID declaration.
 if (auto *GD = dyn_cast(D)) {
@@ -11508,7 +11511,8 @@ public:
 
   bool ZeroInitialization(const Expr *E) { return Success(0, E); }
 
-  friend std::optional EvaluateBuiltinIsWithinLifetime(IntExprEvaluator 
&, const CallExpr *);
+  friend std::optional EvaluateBuiltinIsWithinLifetime(IntExprEvaluator 
&,
+ const CallExpr *);
 
   
//======//
   //Visitor Methods
@@ -17030,56 +17034,70 @@ bool Expr::tryEvaluateStrLen(uint64_t , 
ASTContext ) const {
 }
 
 namespace {
-  struct IsWithinLifetimeHandler {
-EvalInfo 
-static constexpr AccessKinds AccessKind = AccessKinds::AK_IsWithinLifetime;
-using result_type = std::optional;
-std::optional failed() { return std::nullopt; }
-template
-std::optional found(T , QualType SubobjType) {
-  return true;
-}
-  };
+struct IsWithinLifetimeHandler {
+  EvalInfo 
+  static constexpr AccessKinds AccessKind = AccessKinds::AK_IsWithinLifetime;
+  using result_type = std::optional;
+  std::optional failed() { return std::nullopt; }
+  template 
+  std::optional found(T , QualType SubobjType) {
+return true;
+  }
+};
 
-  std::optional EvaluateBuiltinIsWithinLifetime(IntExprEvaluator , 
const CallExpr *E) {
-EvalInfo& Info = IEE.Info;
-//assert(Info.InConstantContext && "Call to consteval builtin not in 
constant context?");
-assert(E->getBuiltinCallee() == Builtin::BI__builtin_is_within_lifetime);
-const Expr *Arg = E->getArg(0);
-if (Arg->isValueDependent())
-  return std::nullopt;
-LValue Val;
-if (!EvaluatePointer(Arg, Val, Info))
-  return std::nullopt;
+std::optional EvaluateBuiltinIsWithinLifetime(IntExprEvaluator ,
+const CallExpr *E) {
+  EvalInfo  = IEE.Info;
+  // assert(Info.InConstantContext && "Call to consteval builtin not in 
constant
+  // context?");
+  assert(E->getBuiltinCallee() == Builtin::BI__builtin_is_within_lifetime);
+  const Expr *Arg = E->getArg(0);
+  if (Arg->isValueDependent())
+return std::nullopt;
+  LValue Val;
+  if (!EvaluatePointer(Arg, Val, Info))
+return std::nullopt;
 
-auto Error = [&](int Diag) {
-  const auto *Callee = Info.CurrentCall->getCallee();
-  bool CalledFromStd = Callee && 

[clang] [Clang] Add __builtin_is_within_lifetime to implement P2641R4's std::is_within_lifetime (PR #91895)

2024-05-12 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok created 
https://github.com/llvm/llvm-project/pull/91895

None

>From 56aed689dc5825fc5bacc6dfdff58ee0eaf71f82 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 12 May 2024 19:48:24 +0100
Subject: [PATCH 1/2] [Clang] Add attribute for consteval builtins; Declare
 constexpr builtins as constexpr in C++

Also support redeclaring now-constexpr builtins without constexpr
---
 clang/include/clang/Basic/Builtins.h  |  5 +
 clang/include/clang/Basic/BuiltinsBase.td |  2 ++
 clang/lib/Sema/SemaDecl.cpp   | 15 +++
 clang/lib/Sema/SemaDeclCXX.cpp| 18 +-
 clang/lib/Sema/SemaExpr.cpp   |  8 ++--
 clang/test/Sema/builtin-redecl.cpp| 15 ++-
 6 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index f955d21169556..e85ec5b2dca14 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -280,6 +280,11 @@ class Context {
 return strchr(getRecord(ID).Attributes, 'E') != nullptr;
   }
 
+  /// Returns true if this is an immediate (consteval) function
+  bool isImmediate(unsigned ID) const {
+return strchr(getRecord(ID).Attributes, 'G') != nullptr;
+  }
+
 private:
   const Info (unsigned ID) const;
 
diff --git a/clang/include/clang/Basic/BuiltinsBase.td 
b/clang/include/clang/Basic/BuiltinsBase.td
index 724747ec76d73..1196b9e15c10d 100644
--- a/clang/include/clang/Basic/BuiltinsBase.td
+++ b/clang/include/clang/Basic/BuiltinsBase.td
@@ -70,6 +70,8 @@ class VScanfFormat : IndexedAttribute<"S", I>;
 
 // Builtin can be constant evaluated
 def Constexpr : Attribute<"E">;
+// Builtin is immediate and must be constant evaluated. Implies Constexpr.
+def Consteval : Attribute<"EG">;
 
 // Builtin kinds
 // =
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fb913034bd836..6b0a04585928a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2409,10 +2409,17 @@ FunctionDecl *Sema::CreateBuiltin(IdentifierInfo *II, 
QualType Type,
 Parent = CLinkageDecl;
   }
 
-  FunctionDecl *New = FunctionDecl::Create(Context, Parent, Loc, Loc, II, Type,
-   /*TInfo=*/nullptr, SC_Extern,
-   
getCurFPFeatures().isFPConstrained(),
-   false, Type->isFunctionProtoType());
+  ConstexprSpecKind ConstexprKind = ConstexprSpecKind::Unspecified;
+  if (getLangOpts().CPlusPlus && Context.BuiltinInfo.isConstantEvaluated(ID)) {
+ConstexprKind = ConstexprSpecKind::Constexpr;
+if (Context.BuiltinInfo.isImmediate(ID))
+  ConstexprKind = ConstexprSpecKind::Consteval;
+  }
+
+  FunctionDecl *New = FunctionDecl::Create(
+  Context, Parent, Loc, Loc, II, Type, /*TInfo=*/nullptr, SC_Extern,
+  getCurFPFeatures().isFPConstrained(), /*isInlineSpecified=*/false,
+  Type->isFunctionProtoType(), ConstexprKind);
   New->setImplicit();
   New->addAttr(BuiltinAttr::CreateImplicit(Context, ID));
 
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 53238d355ea09..1b558d70f9b48 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -676,11 +676,19 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, 
FunctionDecl *Old,
   // template has a constexpr specifier then all its declarations shall
   // contain the constexpr specifier.
   if (New->getConstexprKind() != Old->getConstexprKind()) {
-Diag(New->getLocation(), diag::err_constexpr_redecl_mismatch)
-<< New << static_cast(New->getConstexprKind())
-<< static_cast(Old->getConstexprKind());
-Diag(Old->getLocation(), diag::note_previous_declaration);
-Invalid = true;
+if (Old->getBuiltinID() &&
+Old->getConstexprKind() == ConstexprSpecKind::Constexpr &&
+New->getConstexprKind() == ConstexprSpecKind::Unspecified) {
+  // Except allow redeclaring a builtin as non-constexpr to match C
+  // redeclarations which will not be constexpr
+  New->setConstexprKind(ConstexprSpecKind::Constexpr);
+} else {
+  Diag(New->getLocation(), diag::err_constexpr_redecl_mismatch)
+  << New << static_cast(New->getConstexprKind())
+  << static_cast(Old->getConstexprKind());
+  Diag(Old->getLocation(), diag::note_previous_declaration);
+  Invalid = true;
+}
   } else if (!Old->getMostRecentDecl()->isInlined() && New->isInlined() &&
  Old->isDefined(Def) &&
  // If a friend function is inlined but does not have 'inline'
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index bb4b116fd73ca..39aa32526d2b1 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7095,8 +7095,12 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, 
NamedDecl *NDecl,
   }
 
   // Bail 

[clang] [Clang] Add attribute for consteval builtins; Declare constexpr builtins as constexpr in C++ (PR #91894)

2024-05-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mital Ashok (MitalAshok)


Changes

Also support redeclaring now-constexpr builtins without constexpr

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


6 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.h (+5) 
- (modified) clang/include/clang/Basic/BuiltinsBase.td (+2) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+11-4) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+13-5) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+6-2) 
- (modified) clang/test/Sema/builtin-redecl.cpp (+10-5) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index f955d21169556..e85ec5b2dca14 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -280,6 +280,11 @@ class Context {
 return strchr(getRecord(ID).Attributes, 'E') != nullptr;
   }
 
+  /// Returns true if this is an immediate (consteval) function
+  bool isImmediate(unsigned ID) const {
+return strchr(getRecord(ID).Attributes, 'G') != nullptr;
+  }
+
 private:
   const Info (unsigned ID) const;
 
diff --git a/clang/include/clang/Basic/BuiltinsBase.td 
b/clang/include/clang/Basic/BuiltinsBase.td
index 724747ec76d73..1196b9e15c10d 100644
--- a/clang/include/clang/Basic/BuiltinsBase.td
+++ b/clang/include/clang/Basic/BuiltinsBase.td
@@ -70,6 +70,8 @@ class VScanfFormat : IndexedAttribute<"S", I>;
 
 // Builtin can be constant evaluated
 def Constexpr : Attribute<"E">;
+// Builtin is immediate and must be constant evaluated. Implies Constexpr.
+def Consteval : Attribute<"EG">;
 
 // Builtin kinds
 // =
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fb913034bd836..6b0a04585928a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2409,10 +2409,17 @@ FunctionDecl *Sema::CreateBuiltin(IdentifierInfo *II, 
QualType Type,
 Parent = CLinkageDecl;
   }
 
-  FunctionDecl *New = FunctionDecl::Create(Context, Parent, Loc, Loc, II, Type,
-   /*TInfo=*/nullptr, SC_Extern,
-   
getCurFPFeatures().isFPConstrained(),
-   false, Type->isFunctionProtoType());
+  ConstexprSpecKind ConstexprKind = ConstexprSpecKind::Unspecified;
+  if (getLangOpts().CPlusPlus && Context.BuiltinInfo.isConstantEvaluated(ID)) {
+ConstexprKind = ConstexprSpecKind::Constexpr;
+if (Context.BuiltinInfo.isImmediate(ID))
+  ConstexprKind = ConstexprSpecKind::Consteval;
+  }
+
+  FunctionDecl *New = FunctionDecl::Create(
+  Context, Parent, Loc, Loc, II, Type, /*TInfo=*/nullptr, SC_Extern,
+  getCurFPFeatures().isFPConstrained(), /*isInlineSpecified=*/false,
+  Type->isFunctionProtoType(), ConstexprKind);
   New->setImplicit();
   New->addAttr(BuiltinAttr::CreateImplicit(Context, ID));
 
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 53238d355ea09..1b558d70f9b48 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -676,11 +676,19 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, 
FunctionDecl *Old,
   // template has a constexpr specifier then all its declarations shall
   // contain the constexpr specifier.
   if (New->getConstexprKind() != Old->getConstexprKind()) {
-Diag(New->getLocation(), diag::err_constexpr_redecl_mismatch)
-<< New << static_cast(New->getConstexprKind())
-<< static_cast(Old->getConstexprKind());
-Diag(Old->getLocation(), diag::note_previous_declaration);
-Invalid = true;
+if (Old->getBuiltinID() &&
+Old->getConstexprKind() == ConstexprSpecKind::Constexpr &&
+New->getConstexprKind() == ConstexprSpecKind::Unspecified) {
+  // Except allow redeclaring a builtin as non-constexpr to match C
+  // redeclarations which will not be constexpr
+  New->setConstexprKind(ConstexprSpecKind::Constexpr);
+} else {
+  Diag(New->getLocation(), diag::err_constexpr_redecl_mismatch)
+  << New << static_cast(New->getConstexprKind())
+  << static_cast(Old->getConstexprKind());
+  Diag(Old->getLocation(), diag::note_previous_declaration);
+  Invalid = true;
+}
   } else if (!Old->getMostRecentDecl()->isInlined() && New->isInlined() &&
  Old->isDefined(Def) &&
  // If a friend function is inlined but does not have 'inline'
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index bb4b116fd73ca..39aa32526d2b1 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7095,8 +7095,12 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, 
NamedDecl *NDecl,
   }
 
   // Bail out early if calling a builtin with custom type checking.
-  if (BuiltinID && Context.BuiltinInfo.hasCustomTypechecking(BuiltinID))
-return CheckBuiltinFunctionCall(FDecl, BuiltinID, TheCall);
+  if (BuiltinID && 

[clang] [Clang] Add attribute for consteval builtins; Declare constexpr builtins as constexpr in C++ (PR #91894)

2024-05-12 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok created 
https://github.com/llvm/llvm-project/pull/91894

Also support redeclaring now-constexpr builtins without constexpr

>From 56aed689dc5825fc5bacc6dfdff58ee0eaf71f82 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 12 May 2024 19:48:24 +0100
Subject: [PATCH] [Clang] Add attribute for consteval builtins; Declare
 constexpr builtins as constexpr in C++

Also support redeclaring now-constexpr builtins without constexpr
---
 clang/include/clang/Basic/Builtins.h  |  5 +
 clang/include/clang/Basic/BuiltinsBase.td |  2 ++
 clang/lib/Sema/SemaDecl.cpp   | 15 +++
 clang/lib/Sema/SemaDeclCXX.cpp| 18 +-
 clang/lib/Sema/SemaExpr.cpp   |  8 ++--
 clang/test/Sema/builtin-redecl.cpp| 15 ++-
 6 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index f955d21169556..e85ec5b2dca14 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -280,6 +280,11 @@ class Context {
 return strchr(getRecord(ID).Attributes, 'E') != nullptr;
   }
 
+  /// Returns true if this is an immediate (consteval) function
+  bool isImmediate(unsigned ID) const {
+return strchr(getRecord(ID).Attributes, 'G') != nullptr;
+  }
+
 private:
   const Info (unsigned ID) const;
 
diff --git a/clang/include/clang/Basic/BuiltinsBase.td 
b/clang/include/clang/Basic/BuiltinsBase.td
index 724747ec76d73..1196b9e15c10d 100644
--- a/clang/include/clang/Basic/BuiltinsBase.td
+++ b/clang/include/clang/Basic/BuiltinsBase.td
@@ -70,6 +70,8 @@ class VScanfFormat : IndexedAttribute<"S", I>;
 
 // Builtin can be constant evaluated
 def Constexpr : Attribute<"E">;
+// Builtin is immediate and must be constant evaluated. Implies Constexpr.
+def Consteval : Attribute<"EG">;
 
 // Builtin kinds
 // =
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fb913034bd836..6b0a04585928a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2409,10 +2409,17 @@ FunctionDecl *Sema::CreateBuiltin(IdentifierInfo *II, 
QualType Type,
 Parent = CLinkageDecl;
   }
 
-  FunctionDecl *New = FunctionDecl::Create(Context, Parent, Loc, Loc, II, Type,
-   /*TInfo=*/nullptr, SC_Extern,
-   
getCurFPFeatures().isFPConstrained(),
-   false, Type->isFunctionProtoType());
+  ConstexprSpecKind ConstexprKind = ConstexprSpecKind::Unspecified;
+  if (getLangOpts().CPlusPlus && Context.BuiltinInfo.isConstantEvaluated(ID)) {
+ConstexprKind = ConstexprSpecKind::Constexpr;
+if (Context.BuiltinInfo.isImmediate(ID))
+  ConstexprKind = ConstexprSpecKind::Consteval;
+  }
+
+  FunctionDecl *New = FunctionDecl::Create(
+  Context, Parent, Loc, Loc, II, Type, /*TInfo=*/nullptr, SC_Extern,
+  getCurFPFeatures().isFPConstrained(), /*isInlineSpecified=*/false,
+  Type->isFunctionProtoType(), ConstexprKind);
   New->setImplicit();
   New->addAttr(BuiltinAttr::CreateImplicit(Context, ID));
 
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 53238d355ea09..1b558d70f9b48 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -676,11 +676,19 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, 
FunctionDecl *Old,
   // template has a constexpr specifier then all its declarations shall
   // contain the constexpr specifier.
   if (New->getConstexprKind() != Old->getConstexprKind()) {
-Diag(New->getLocation(), diag::err_constexpr_redecl_mismatch)
-<< New << static_cast(New->getConstexprKind())
-<< static_cast(Old->getConstexprKind());
-Diag(Old->getLocation(), diag::note_previous_declaration);
-Invalid = true;
+if (Old->getBuiltinID() &&
+Old->getConstexprKind() == ConstexprSpecKind::Constexpr &&
+New->getConstexprKind() == ConstexprSpecKind::Unspecified) {
+  // Except allow redeclaring a builtin as non-constexpr to match C
+  // redeclarations which will not be constexpr
+  New->setConstexprKind(ConstexprSpecKind::Constexpr);
+} else {
+  Diag(New->getLocation(), diag::err_constexpr_redecl_mismatch)
+  << New << static_cast(New->getConstexprKind())
+  << static_cast(Old->getConstexprKind());
+  Diag(Old->getLocation(), diag::note_previous_declaration);
+  Invalid = true;
+}
   } else if (!Old->getMostRecentDecl()->isInlined() && New->isInlined() &&
  Old->isDefined(Def) &&
  // If a friend function is inlined but does not have 'inline'
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index bb4b116fd73ca..39aa32526d2b1 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7095,8 +7095,12 @@ ExprResult 

[clang] [analyzer] Allow recursive functions to be trivial. (PR #91876)

2024-05-12 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

You should add a test for mutually recursive functions. I suspect something 
like this doesn't work:

```c++
int non_trivial();
int f(bool b) { return g(!b) + non_trivial(); }
int g(bool b) { return b ? f(b) : 1; }

getFieldTrivial().f(true);  // expected-warning {{...}}
getFieldTrivial().g(true);  // expected-warning {{...}}
```

Since when analyzing `f`, `f` enters the cache as trivial, `g` is analyzed and 
sees `f` in the cache as trivial, so `g` is marked trivial, but then `f` is 
marked as non-trivial (so `g` should have been marked as non-trivial, but is 
marked trivial).

If that is an issue, one way to do this "properly" would be to create a graph, 
and a function is non-trivial if it has a path to a non-trivial function (this 
might be too expensive to implement directly). Or we could special case simple 
recursion only, by changing `TrivialFunctionAnalysisVisitor` to not call 
`isTrivialImpl` for the current function only.

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


[clang] [llvm] [BPF] Fix linking issues in static map initializers (PR #91310)

2024-05-12 Thread Eli Friedman via cfe-commits


@@ -1950,8 +1950,22 @@ ConstantLValueEmitter::tryEmitBase(const 
APValue::LValueBase ) {
 if (D->hasAttr())
   return CGM.GetWeakRefReference(D).getPointer();
 
-if (auto FD = dyn_cast(D))
-  return CGM.GetAddrOfFunction(FD);
+if (auto FD = dyn_cast(D)) {
+  auto *C = CGM.GetAddrOfFunction(FD);
+
+  // we don't normally emit debug info for extern fns referenced via
+  // variable initialisers; BPF needs it since it generates BTF from
+  // debug info and bpftool demands BTF for every symbol linked
+  if (CGM.getTarget().getTriple().isBPF() && FD->getStorageClass() == 
SC_Extern) {

efriedma-quic wrote:

Looking at the code again, I guess the ultimate question is whether we want to 
emit debug info for all external functions/variables, or only 
functions/variables that are actually referenced.

If we want all functions/variables, we want to extend ExternalDeclarations to 
include them.  Maybe put the code in Sema::ActOnFunctionDeclarator, or 
something like that.

If you just want referenced functions/variables, probably the code should be in 
GetAddrOfFunction() (and something similar for variables).

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


[clang] [Clang] Added check for unexpanded pack in attribute [[assume]] (PR #91893)

2024-05-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Azmat Yusuf (azmat-y)


Changes

Added a check for unexpanded parameter pack in attribute [[assume]]. Tested it 
with expected-error statements from clang fronted. This fixes #91232. 
@Sirraide 

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaStmtAttr.cpp (+5) 
- (modified) clang/test/SemaCXX/cxx23-assume.cpp (+5) 


``diff
diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 1c84830b6ddd2..36f8ecadcfab7 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -670,6 +670,11 @@ ExprResult Sema::ActOnCXXAssumeAttr(Stmt *St, const 
ParsedAttr ,
   }
 
   auto *Assumption = A.getArgAsExpr(0);
+
+  if (DiagnoseUnexpandedParameterPack(Assumption)) {
+return ExprError();
+  }
+
   if (Assumption->getDependence() == ExprDependence::None) {
 ExprResult Res = BuildCXXAssumeExpr(Assumption, A.getAttrName(), Range);
 if (Res.isInvalid())
diff --git a/clang/test/SemaCXX/cxx23-assume.cpp 
b/clang/test/SemaCXX/cxx23-assume.cpp
index 8676970de14f6..e67d72ae0a995 100644
--- a/clang/test/SemaCXX/cxx23-assume.cpp
+++ b/clang/test/SemaCXX/cxx23-assume.cpp
@@ -138,3 +138,8 @@ constexpr int foo() {
 }
 
 static_assert(foo() == 0);
+
+template 
+void f() {
+[[assume(val)]]; // expected-error {{expression contains unexpanded 
parameter pack}}
+}

``




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


[clang] [Clang] Added check for unexpanded pack in attribute [[assume]] (PR #91893)

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


[clang] [Clang] Added check for unexpanded pack in attribute [[assume]] (PR #91893)

2024-05-12 Thread Azmat Yusuf via cfe-commits

https://github.com/azmat-y created 
https://github.com/llvm/llvm-project/pull/91893

Added a check for unexpanded parameter pack in attribute [[assume]]. Tested it 
with expected-error statements from clang fronted. This fixes #91232. @Sirraide 

>From cbb35bd010f2d46ae70367549a2838841a55aeb7 Mon Sep 17 00:00:00 2001
From: Azmat Yusuf 
Date: Sun, 12 May 2024 20:49:14 +0530
Subject: [PATCH] [Clang] Added check for unexpanded pack in attribute
 [[assume]]

---
 clang/lib/Sema/SemaStmtAttr.cpp | 5 +
 clang/test/SemaCXX/cxx23-assume.cpp | 5 +
 2 files changed, 10 insertions(+)

diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 1c84830b6ddd2..36f8ecadcfab7 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -670,6 +670,11 @@ ExprResult Sema::ActOnCXXAssumeAttr(Stmt *St, const 
ParsedAttr ,
   }
 
   auto *Assumption = A.getArgAsExpr(0);
+
+  if (DiagnoseUnexpandedParameterPack(Assumption)) {
+return ExprError();
+  }
+
   if (Assumption->getDependence() == ExprDependence::None) {
 ExprResult Res = BuildCXXAssumeExpr(Assumption, A.getAttrName(), Range);
 if (Res.isInvalid())
diff --git a/clang/test/SemaCXX/cxx23-assume.cpp 
b/clang/test/SemaCXX/cxx23-assume.cpp
index 8676970de14f6..e67d72ae0a995 100644
--- a/clang/test/SemaCXX/cxx23-assume.cpp
+++ b/clang/test/SemaCXX/cxx23-assume.cpp
@@ -138,3 +138,8 @@ constexpr int foo() {
 }
 
 static_assert(foo() == 0);
+
+template 
+void f() {
+[[assume(val)]]; // expected-error {{expression contains unexpanded 
parameter pack}}
+}

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


[clang] [clang-tools-extra] [flang] [lld] [llvm] [mlir] [polly] [test]: fix filecheck annotation typos (PR #91854)

2024-05-12 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm commented:

amdgpu changes lgtm 

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


[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #91879)

2024-05-12 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/91879

>From 6969f06f39363deda92d473ec14a08663c71f3b1 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sun, 12 May 2024 14:42:09 +0800
Subject: [PATCH] [Analyzer][CFG] Correctly handle rebuilted default arg and
 default init expression

Signed-off-by: yronglin 
---
 clang/lib/AST/ParentMap.cpp  | 16 +
 clang/lib/Analysis/CFG.cpp   | 38 +++-
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 35 ++
 3 files changed, 56 insertions(+), 33 deletions(-)

diff --git a/clang/lib/AST/ParentMap.cpp b/clang/lib/AST/ParentMap.cpp
index 3d6a1cc84c7b1..534793b837bbb 100644
--- a/clang/lib/AST/ParentMap.cpp
+++ b/clang/lib/AST/ParentMap.cpp
@@ -97,6 +97,22 @@ static void BuildParentMap(MapTy& M, Stmt* S,
   BuildParentMap(M, SubStmt, OVMode);
 }
 break;
+  case Stmt::CXXDefaultArgExprClass:
+if (auto *Arg = dyn_cast(S)) {
+  if (Arg->hasRewrittenInit()) {
+M[Arg->getExpr()] = S;
+BuildParentMap(M, Arg->getExpr(), OVMode);
+  }
+}
+break;
+  case Stmt::CXXDefaultInitExprClass:
+if (auto *Init = dyn_cast(S)) {
+  if (Init->hasRewrittenInit()) {
+M[Init->getExpr()] = S;
+BuildParentMap(M, Init->getExpr(), OVMode);
+  }
+}
+break;
   default:
 for (Stmt *SubStmt : S->children()) {
   if (SubStmt) {
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 64e6155de090c..2f3f3e92516ba 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -556,6 +556,8 @@ class CFGBuilder {
 
 private:
   // Visitors to walk an AST and construct the CFG.
+  CFGBlock *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Default, AddStmtChoice 
asc);
+  CFGBlock *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Default, AddStmtChoice 
asc);
   CFGBlock *VisitInitListExpr(InitListExpr *ILE, AddStmtChoice asc);
   CFGBlock *VisitAddrLabelExpr(AddrLabelExpr *A, AddStmtChoice asc);
   CFGBlock *VisitAttributedStmt(AttributedStmt *A, AddStmtChoice asc);
@@ -2254,16 +2256,10 @@ CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc,
asc, ExternallyDestructed);
 
 case Stmt::CXXDefaultArgExprClass:
+  return VisitCXXDefaultArgExpr(cast(S), asc);
+
 case Stmt::CXXDefaultInitExprClass:
-  // FIXME: The expression inside a CXXDefaultArgExpr is owned by the
-  // called function's declaration, not by the caller. If we simply add
-  // this expression to the CFG, we could end up with the same Expr
-  // appearing multiple times (PR13385).
-  //
-  // It's likewise possible for multiple CXXDefaultInitExprs for the same
-  // expression to be used in the same function (through aggregate
-  // initialization).
-  return VisitStmt(S, asc);
+  return VisitCXXDefaultInitExpr(cast(S), asc);
 
 case Stmt::CXXBindTemporaryExprClass:
   return VisitCXXBindTemporaryExpr(cast(S), asc);
@@ -2433,6 +2429,30 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) {
   return B;
 }
 
+CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Arg,
+ AddStmtChoice asc) {
+  if (Arg->hasRewrittenInit()) {
+if (asc.alwaysAdd(*this, Arg)) {
+  autoCreateBlock();
+  appendStmt(Block, Arg);
+}
+return VisitStmt(Arg->getExpr(), asc);
+  }
+  return VisitStmt(Arg, asc);
+}
+
+CFGBlock *CFGBuilder::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Init,
+  AddStmtChoice asc) {
+  if (Init->hasRewrittenInit()) {
+if (asc.alwaysAdd(*this, Init)) {
+  autoCreateBlock();
+  appendStmt(Block, Init);
+}
+return VisitStmt(Init->getExpr(), asc);
+  }
+  return VisitStmt(Init, asc);
+}
+
 CFGBlock *CFGBuilder::VisitInitListExpr(InitListExpr *ILE, AddStmtChoice asc) {
   if (asc.alwaysAdd(*this, ILE)) {
 autoCreateBlock();
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 0b1edf3e5c96b..41cb4293a8451 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1964,11 +1964,8 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
 case Stmt::CXXDefaultArgExprClass:
 case Stmt::CXXDefaultInitExprClass: {
   Bldr.takeNodes(Pred);
-  ExplodedNodeSet PreVisit;
-  getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this);
-
-  ExplodedNodeSet Tmp;
-  StmtNodeBuilder Bldr2(PreVisit, Tmp, *currBldrCtx);
+  ExplodedNodeSet CheckedSet;
+  getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, S, *this);
 
   const Expr *ArgE;
   if (const auto *DefE = dyn_cast(S))
@@ -1978,25 +1975,15 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode 
*Pred,
   else
 llvm_unreachable("unknown constant wrapper kind");
 
-  bool IsTemporary = false;

[clang] 17daa20 - [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (#87933)

2024-05-12 Thread via cfe-commits

Author: yronglin
Date: 2024-05-13T01:16:36+08:00
New Revision: 17daa204feadf9c28fc13b7daa69c3cbe865b238

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

LOG: [Clang][CWG1815] Support lifetime extension of temporary created by 
aggregate initialization using a default member initializer (#87933)

This PR complete [DR1815](https://wg21.link/CWG1815) under the guidance
of `FIXME` comments. And reuse `CXXDefaultInitExpr` rewrite machinery to
clone the initializer expression on each use that would lifetime extend
its temporaries.

-

Signed-off-by: yronglin 

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/AST/ast-dump-default-init-json.cpp
clang/test/AST/ast-dump-default-init.cpp
clang/test/Analysis/lifetime-extended-regions.cpp
clang/test/CXX/drs/cwg16xx.cpp
clang/test/CXX/drs/cwg18xx.cpp
clang/test/CXX/special/class.temporary/p6.cpp
clang/test/SemaCXX/constexpr-default-arg.cpp
clang/test/SemaCXX/eval-crashes.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d6863f90edb6e..9e82130c93609 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10035,12 +10035,6 @@ def warn_new_dangling_initializer_list : Warning<
   "the allocated initializer list}0 "
   "will be destroyed at the end of the full-expression">,
   InGroup;
-def warn_unsupported_lifetime_extension : Warning<
-  "lifetime extension of "
-  "%select{temporary|backing array of initializer list}0 created "
-  "by aggregate initialization using a default member initializer "
-  "is not yet supported; lifetime of %select{temporary|backing array}0 "
-  "will end at the end of the full-expression">, InGroup;
 
 // For non-floating point, expressions of the form x == x or x != x
 // should result in a warning, since these always evaluate to a constant.

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c688cb21f2364..bb4b116fd73ca 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5777,10 +5777,9 @@ ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation 
CallLoc,
 Res = Immediate.TransformInitializer(Param->getInit(),
  /*NotCopy=*/false);
   });
-  if (Res.isInvalid())
-return ExprError();
-  Res = ConvertParamDefaultArgument(Param, Res.get(),
-Res.get()->getBeginLoc());
+  if (Res.isUsable())
+Res = ConvertParamDefaultArgument(Param, Res.get(),
+  Res.get()->getBeginLoc());
   if (Res.isInvalid())
 return ExprError();
   Init = Res.get();
@@ -5816,7 +5815,7 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
   Expr *Init = nullptr;
 
   bool NestedDefaultChecking = isCheckingDefaultArgumentOrInitializer();
-
+  bool InLifetimeExtendingContext = isInLifetimeExtendingContext();
   EnterExpressionEvaluationContext EvalContext(
   *this, ExpressionEvaluationContext::PotentiallyEvaluated, Field);
 
@@ -5851,19 +5850,35 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
   ImmediateCallVisitor V(getASTContext());
   if (!NestedDefaultChecking)
 V.TraverseDecl(Field);
-  if (V.HasImmediateCalls) {
+
+  // CWG1815
+  // Support lifetime extension of temporary created by aggregate
+  // initialization using a default member initializer. We should always 
rebuild
+  // the initializer if it contains any temporaries (if the initializer
+  // expression is an ExprWithCleanups). Then make sure the normal lifetime
+  // extension code recurses into the default initializer and does lifetime
+  // extension when warranted.
+  bool ContainsAnyTemporaries =
+  isa_and_present(Field->getInClassInitializer());
+  if (V.HasImmediateCalls || InLifetimeExtendingContext ||
+  ContainsAnyTemporaries) {
 ExprEvalContexts.back().DelayedDefaultInitializationContext = {Loc, Field,
CurContext};
 ExprEvalContexts.back().IsCurrentlyCheckingDefaultArgumentOrInitializer =
 NestedDefaultChecking;
-
+// Pass down lifetime extending flag, and collect temporaries in
+// CreateMaterializeTemporaryExpr when we rewrite the call argument.
+keepInLifetimeExtendingContext();
 EnsureImmediateInvocationInDefaultArgs Immediate(*this);
 ExprResult Res;
+
+// Rebuild CXXDefaultInitExpr might cause diagnostics.
+SFINAETrap 

[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

2024-05-12 Thread via cfe-commits

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


[clang] [X86][vectorcall] Pass built types byval when xmm0~6 exhausted (PR #91846)

2024-05-12 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

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


[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

2024-05-12 Thread via cfe-commits

yronglin wrote:

> > I'd like to proposal a separate PR for static analyzer. #91879 WDYT?
> 
> That sounds good to me.

Thanks for your confirmation! If you don’t have any concerns, I'd like to land 
this PR. 朗

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


[clang] [llvm] [X86][Driver] Do not add `-evex512` for `-march=native` when the target doesn't support AVX512 (PR #91694)

2024-05-12 Thread Mike Lothian via cfe-commits

FireBurn wrote:

No worries, it's fixed now, llvm, nodejs and libreoffice are all compiling fine 
again

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


[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #91879)

2024-05-12 Thread via cfe-commits


@@ -2433,6 +2429,30 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) {
   return B;
 }
 
+CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Arg,
+ AddStmtChoice asc) {
+  if (Arg->hasRewrittenInit()) {
+if (asc.alwaysAdd(*this, Arg)) {
+  autoCreateBlock();
+  appendStmt(Block, Arg);
+}
+return VisitStmt(Arg->getExpr(), asc);
+  }
+  return VisitStmt(Arg, asc);

yronglin wrote:

Thanks a lot for your review!

> I think it'd be useful to keep some of the old comment here: we can't add the 
> default argument if it's not rewritten because we could end up with the same 
> expression appearing multiple times.

Agree 100%, keep the old comment here can make things more clear. 

> Actually, are we safe from that even if the default argument is rewritten? Do 
> we guarantee to recreate all subexpressions in that case?

Not exactly, The rebuild implementation is the following, it's ignores 
`LambdaExpr`, `BlockExpr` and `CXXThisExpr`, And 
`EnsureImmediateInvocationInDefaultArgs`’s name may need to be refine.
https://github.com/llvm/llvm-project/blob/78b3a00418ce6da0426a261a64a77608d0264fe5/clang/lib/Sema/SemaExpr.cpp#L5707-L5723
 

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


[clang] Pass QualifiedRenameRule strings by reference to reduce copies (PR #69848)

2024-05-12 Thread Joe Loser via cfe-commits

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


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


[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

2024-05-12 Thread Richard Smith via cfe-commits

zygoloid wrote:

> I'd like to proposal a separate PR for static analyzer. #91879 WDYT?

That sounds good to me.

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


[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #91879)

2024-05-12 Thread Richard Smith via cfe-commits


@@ -2433,6 +2429,30 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) {
   return B;
 }
 
+CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Arg,
+ AddStmtChoice asc) {
+  if (Arg->hasRewrittenInit()) {
+if (asc.alwaysAdd(*this, Arg)) {
+  autoCreateBlock();
+  appendStmt(Block, Arg);
+}
+return VisitStmt(Arg->getExpr(), asc);
+  }
+  return VisitStmt(Arg, asc);

zygoloid wrote:

Actually, are we safe from that even if the default argument is rewritten? Do 
we guarantee to recreate all subexpressions in that case?

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


[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #91879)

2024-05-12 Thread Richard Smith via cfe-commits


@@ -2433,6 +2429,30 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) {
   return B;
 }
 
+CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Arg,
+ AddStmtChoice asc) {
+  if (Arg->hasRewrittenInit()) {
+if (asc.alwaysAdd(*this, Arg)) {
+  autoCreateBlock();
+  appendStmt(Block, Arg);
+}
+return VisitStmt(Arg->getExpr(), asc);
+  }
+  return VisitStmt(Arg, asc);

zygoloid wrote:

I think it'd be useful to keep some of the old comment here: we can't add the 
default argument if it's not rewritten because we could end up with the same 
expression appearing multiple times.

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


[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-12 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-else-after-return %t 

5chmidti wrote:

While `consteval` was added in C++20, `if consteval` is a C++23 feature. Please 
use `-std=c++23`
https://en.cppreference.com/w/cpp/language/if#Consteval_if

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


[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-12 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti commented:

Please add an entry to the release notes here: 
https://github.com/llvm/llvm-project/blob/502e77df1fc4aa859db6709e14e93af6207e4dc4/clang-tools-extra/docs/ReleaseNotes.rst?plain=1#L176
do note that the entries are sorted by their check names.

Otherwise looks good.

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


[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-12 Thread Julian Schmidt via cfe-commits

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


[clang] [clang] Disallow VLA type compound literals (PR #91891)

2024-05-12 Thread Jim M . R . Teichgräber via cfe-commits

https://github.com/J-MR-T edited https://github.com/llvm/llvm-project/pull/91891
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disallow VLA type compound literals (PR #91891)

2024-05-12 Thread Jim M . R . Teichgräber via cfe-commits

https://github.com/J-MR-T edited https://github.com/llvm/llvm-project/pull/91891
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disallow VLA type compound literals (PR #91891)

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


[clang] [clang] Disallow VLA type compound literals (PR #91891)

2024-05-12 Thread Jim M . R . Teichgräber via cfe-commits

https://github.com/J-MR-T created 
https://github.com/llvm/llvm-project/pull/91891

C99-C23 6.5.2.5 says: The type name shall specify an object type or an array of 
unknown size, but not a variable length array type.

Closes issue #89835 .

I ran `git clang-format`'ed my changes and ran the clang tests, which passed 
after minor adjustments to the new behavior.

I mostly implemented everything as discussed in #89835, with the exception of 
[clang/test/C/C2x/n2900_n3011_2.c](https://github.com/llvm/llvm-project/compare/main...J-MR-T:llvm-project:main#diff-aa2b77ff42fcd2f2c02cc456f5023e923d44e5018dd2af7c046ebdcc8cb00a4a):
 in that file I deleted the part about VLA compound literals, because the file 
relies on LLVM-IR being emitted by clang, and that wouldn't have fit with the 
rest of the file. Adding another RUN line and handling this case independently 
in that file would be an option, but it felt out of place. Of course, I'm still 
open to doing it that way, or preserving the test another way, if that is 
preferred.

As I point out 
[here](https://github.com/llvm/llvm-project/compare/main...J-MR-T:llvm-project:main#diff-3c28567b5e0c77d68f174541a0b77f5a85d093f58b89cd3675ee04a550a44880R7278-R7283),
 the new behavior leads to a confusing reality brought about by the C23 
standard:
```c
int a[size] = {};
```
is valid code, while
```c
int a[size] = (int[size]){};
```
is not. As this seems to be what the standard requests, I implemented it that 
way for now.


Tagging @Sirraide and @AaronBallman as requested :).



From 9aab9284fc094d22e12a2ee1217a3bc99e5837b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jim=20M=2E=20R=2E=20Teichgr=C3=A4ber?=
 
Date: Sun, 12 May 2024 13:33:37 +0200
Subject: [PATCH] [clang] Disallow VLA type compound literals C99-C23 6.5.2.5
 says: The type name shall specify an object type or an array of unknown size,
 but not a variable length array type Issue:
 https://github.com/llvm/llvm-project/issues/89835

---
 .../clang/Basic/DiagnosticSemaKinds.td|  2 ++
 clang/lib/Sema/SemaExpr.cpp   | 19 +--
 clang/test/C/C2x/n2900_n3011.c|  8 +++-
 clang/test/C/C2x/n2900_n3011_2.c  | 16 
 clang/test/Sema/compound-literal.c| 15 +--
 5 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d6863f90edb6e..008d7b2a29cd9 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3371,6 +3371,8 @@ def err_field_with_address_space : Error<
   "field may not be qualified with an address space">;
 def err_compound_literal_with_address_space : Error<
   "compound literal in function scope may not be qualified with an address 
space">;
+def err_compound_literal_with_vla_type : Error<
+  "compound literal has variable-length array type">;
 def err_address_space_mismatch_templ_inst : Error<
   "conflicting address space qualifiers are provided between types %0 and %1">;
 def err_attr_objc_ownership_redundant : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c688cb21f2364..e62e3f3285e5d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7274,12 +7274,19 @@ Sema::BuildCompoundLiteralExpr(SourceLocation 
LParenLoc, TypeSourceInfo *TInfo,
   // init a VLA in C++ in all cases (such as with non-trivial 
constructors).
   // FIXME: should we allow this construct in C++ when it makes sense to do
   // so?
-  std::optional NumInits;
-  if (const auto *ILE = dyn_cast(LiteralExpr))
-NumInits = ILE->getNumInits();
-  if ((LangOpts.CPlusPlus || NumInits.value_or(0)) &&
-  !tryToFixVariablyModifiedVarType(TInfo, literalType, LParenLoc,
-   diag::err_variable_object_no_init))
+  //
+  // But: C99-C23 6.5.2.5 Compound literals constraint 1: The type name
+  // shall specify an object type or an array of unknown size, but not a
+  // variable length array type. This seems odd, as it allows int a[size] =
+  // {}; but forbids int a[size] = (int[size]){}; As this is what the
+  // standard says, this is what's implemented here for C (except for the
+  // extension that permits constant foldable size arrays)
+
+  auto diagID = LangOpts.CPlusPlus
+? diag::err_variable_object_no_init
+: diag::err_compound_literal_with_vla_type;
+  if (!tryToFixVariablyModifiedVarType(TInfo, literalType, LParenLoc,
+   diagID))
 return ExprError();
 }
   } else if (!literalType->isDependentType() &&
diff --git a/clang/test/C/C2x/n2900_n3011.c b/clang/test/C/C2x/n2900_n3011.c
index 4350aa140691b..f0be8b9e41861 100644
--- a/clang/test/C/C2x/n2900_n3011.c
+++ b/clang/test/C/C2x/n2900_n3011.c
@@ 

[clang] [llvm] [X86][Driver] Do not add `-evex512` for `-march=native` when the target doesn't support AVX512 (PR #91694)

2024-05-12 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

> You'll be probably building 18.1.6 with 18.1.5... and that's when you'll 
> notice the issue. I'm just about finished building 18.1.5 with your patch. So 
> hopefully all those issues will be gone. I'll report back

Okay... This is a combined problem which I never thought before. Sorry for the 
inconvenience!

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


[clang] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [mlir] [openmp] [polly] fix(python): fix comparison to None (PR #91857)

2024-05-12 Thread Mircea Trofin via cfe-commits

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

LGTM for the `ctx_profile` part.

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


[clang] [llvm] [X86][Driver] Do not add `-evex512` for `-march=native` when the target doesn't support AVX512 (PR #91694)

2024-05-12 Thread Mike Lothian via cfe-commits

FireBurn wrote:

You'll be probably building 18.1.6 with 18.1.5... and that's when you'll notice 
the issue. I'm just about finished building 18.1.5 with your patch. So 
hopefully all those issues will be gone. I'll report back

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


[clang] [llvm] [X86][Driver] Do not add `-evex512` for `-march=native` when the target doesn't support AVX512 (PR #91694)

2024-05-12 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

@FireBurn Sorry, I just noticed #91719. The above comments were based on the 
issue #91076.

I didn't look at the source, but the command line doesn't have an AVX512 
option. So I'm assuming the code may related function multi-versioning with 
manually specified target attributes regarding to AVX512 features.

The reason is the same as #91719, but the scenarios may be more common in 
practice. The defect in previous patch does expose a known issue with the 
design of EVEX512, which we have noted in 
https://clang.llvm.org/docs/UsersManual.html#x86

In a word, when user uses target attributes with AVX512 features, they should 
add an explicit `evex512` or `no-evex512` for robustness since LLVM 18. Missing 
it may result in some unexpected codegen or error in some corner case.

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


[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-12 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang-tidy

Author: Jover (JoverZhang)


Changes

Fixes #91561.

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


2 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp 
(+2-2) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
 (+17) 


``diff
diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
index 1e85caf688355..2b185e7594add 100644
--- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -113,7 +113,7 @@ static bool containsDeclInScope(const Stmt *Node) {
 }
 
 static void removeElseAndBrackets(DiagnosticBuilder , ASTContext ,
-   const Stmt *Else, SourceLocation ElseLoc) {
+  const Stmt *Else, SourceLocation ElseLoc) {
   auto Remap = [&](SourceLocation Loc) {
 return Context.getSourceManager().getExpansionLoc(Loc);
   };
@@ -172,7 +172,7 @@ void ElseAfterReturnCheck::registerMatchers(MatchFinder 
*Finder) {
   breakStmt().bind(InterruptingStr), 
cxxThrowExpr().bind(InterruptingStr)));
   Finder->addMatcher(
   compoundStmt(
-  forEach(ifStmt(unless(isConstexpr()),
+  forEach(ifStmt(unless(isConstexpr()), unless(isConsteval()),
  hasThen(stmt(
  anyOf(InterruptsControlFlow,
compoundStmt(has(InterruptsControlFlow),
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
new file mode 100644
index 0..6235d8623ca7b
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-else-after-return %t 
+
+// Consteval if is an exception to the rule, we cannot remove the else.
+void f() {
+  if (sizeof(int) > 4) {
+return;
+  } else {
+return;
+  }
+  // CHECK-MESSAGES: [[@LINE-3]]:5: warning: do not use 'else' after 'return'
+
+  if consteval {
+return;
+  } else {
+return;
+  }
+}

``




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


[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-12 Thread via cfe-commits

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


[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-12 Thread via cfe-commits

JoverZhang wrote:

> Thanks for your patch! Would you be able to add a test case for this please?

Yes, thanks. I added a test case.

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


[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-12 Thread via cfe-commits

https://github.com/JoverZhang updated 
https://github.com/llvm/llvm-project/pull/91588

>From 19bf94ca3c093a6904482eab599f8366cad1384e Mon Sep 17 00:00:00 2001
From: Jover Zhang 
Date: Thu, 9 May 2024 20:56:51 +0800
Subject: [PATCH 1/2] [clang-tidy] Ignore `if consteval` in else-after-return

---
 .../clang-tidy/readability/ElseAfterReturnCheck.cpp   | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
index 1e85caf688355..3ee09b2e6442c 100644
--- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -317,6 +317,10 @@ void ElseAfterReturnCheck::check(const 
MatchFinder::MatchResult ) {
 return;
   }
 
+  if (If->isConsteval()) {
+return;
+  }
+
   DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
<< ControlFlowInterruptor << SourceRange(ElseLoc);
   removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc);

>From 2a394ddde92b23f9407ca74e597b569bb01da35f Mon Sep 17 00:00:00 2001
From: Jover Zhang 
Date: Sun, 12 May 2024 22:40:14 +0800
Subject: [PATCH 2/2] Add test case

---
 .../readability/ElseAfterReturnCheck.cpp|  8 ++--
 .../else-after-return-if-consteval.cpp  | 17 +
 2 files changed, 19 insertions(+), 6 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
index 3ee09b2e6442c..2b185e7594add 100644
--- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -113,7 +113,7 @@ static bool containsDeclInScope(const Stmt *Node) {
 }
 
 static void removeElseAndBrackets(DiagnosticBuilder , ASTContext ,
-   const Stmt *Else, SourceLocation ElseLoc) {
+  const Stmt *Else, SourceLocation ElseLoc) {
   auto Remap = [&](SourceLocation Loc) {
 return Context.getSourceManager().getExpansionLoc(Loc);
   };
@@ -172,7 +172,7 @@ void ElseAfterReturnCheck::registerMatchers(MatchFinder 
*Finder) {
   breakStmt().bind(InterruptingStr), 
cxxThrowExpr().bind(InterruptingStr)));
   Finder->addMatcher(
   compoundStmt(
-  forEach(ifStmt(unless(isConstexpr()),
+  forEach(ifStmt(unless(isConstexpr()), unless(isConsteval()),
  hasThen(stmt(
  anyOf(InterruptsControlFlow,
compoundStmt(has(InterruptsControlFlow),
@@ -317,10 +317,6 @@ void ElseAfterReturnCheck::check(const 
MatchFinder::MatchResult ) {
 return;
   }
 
-  if (If->isConsteval()) {
-return;
-  }
-
   DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
<< ControlFlowInterruptor << SourceRange(ElseLoc);
   removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc);
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
new file mode 100644
index 0..6235d8623ca7b
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-else-after-return %t 
+
+// Consteval if is an exception to the rule, we cannot remove the else.
+void f() {
+  if (sizeof(int) > 4) {
+return;
+  } else {
+return;
+  }
+  // CHECK-MESSAGES: [[@LINE-3]]:5: warning: do not use 'else' after 'return'
+
+  if consteval {
+return;
+  } else {
+return;
+  }
+}

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


[clang-tools-extra] [WIP][clang-tidy] Ignore `if consteval` in else-after-return (PR #91588)

2024-05-12 Thread via cfe-commits

https://github.com/JoverZhang updated 
https://github.com/llvm/llvm-project/pull/91588

>From 19bf94ca3c093a6904482eab599f8366cad1384e Mon Sep 17 00:00:00 2001
From: Jover Zhang 
Date: Thu, 9 May 2024 20:56:51 +0800
Subject: [PATCH 1/2] [clang-tidy] Ignore `if consteval` in else-after-return

---
 .../clang-tidy/readability/ElseAfterReturnCheck.cpp   | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
index 1e85caf688355..3ee09b2e6442c 100644
--- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -317,6 +317,10 @@ void ElseAfterReturnCheck::check(const 
MatchFinder::MatchResult ) {
 return;
   }
 
+  if (If->isConsteval()) {
+return;
+  }
+
   DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
<< ControlFlowInterruptor << SourceRange(ElseLoc);
   removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc);

>From 2a394ddde92b23f9407ca74e597b569bb01da35f Mon Sep 17 00:00:00 2001
From: Jover Zhang 
Date: Sun, 12 May 2024 22:40:14 +0800
Subject: [PATCH 2/2] Add test case

---
 .../readability/ElseAfterReturnCheck.cpp|  8 ++--
 .../else-after-return-if-consteval.cpp  | 17 +
 2 files changed, 19 insertions(+), 6 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
index 3ee09b2e6442c..2b185e7594add 100644
--- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -113,7 +113,7 @@ static bool containsDeclInScope(const Stmt *Node) {
 }
 
 static void removeElseAndBrackets(DiagnosticBuilder , ASTContext ,
-   const Stmt *Else, SourceLocation ElseLoc) {
+  const Stmt *Else, SourceLocation ElseLoc) {
   auto Remap = [&](SourceLocation Loc) {
 return Context.getSourceManager().getExpansionLoc(Loc);
   };
@@ -172,7 +172,7 @@ void ElseAfterReturnCheck::registerMatchers(MatchFinder 
*Finder) {
   breakStmt().bind(InterruptingStr), 
cxxThrowExpr().bind(InterruptingStr)));
   Finder->addMatcher(
   compoundStmt(
-  forEach(ifStmt(unless(isConstexpr()),
+  forEach(ifStmt(unless(isConstexpr()), unless(isConsteval()),
  hasThen(stmt(
  anyOf(InterruptsControlFlow,
compoundStmt(has(InterruptsControlFlow),
@@ -317,10 +317,6 @@ void ElseAfterReturnCheck::check(const 
MatchFinder::MatchResult ) {
 return;
   }
 
-  if (If->isConsteval()) {
-return;
-  }
-
   DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
<< ControlFlowInterruptor << SourceRange(ElseLoc);
   removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc);
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
new file mode 100644
index 0..6235d8623ca7b
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-if-consteval.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-else-after-return %t 
+
+// Consteval if is an exception to the rule, we cannot remove the else.
+void f() {
+  if (sizeof(int) > 4) {
+return;
+  } else {
+return;
+  }
+  // CHECK-MESSAGES: [[@LINE-3]]:5: warning: do not use 'else' after 'return'
+
+  if consteval {
+return;
+  } else {
+return;
+  }
+}

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


[clang] [clang][NFC] Remove class layout scissor (PR #89055)

2024-05-12 Thread Nathan Sidwell via cfe-commits

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


[clang] 1d6bf0c - [clang][NFC] Remove class layout scissor (#89055)

2024-05-12 Thread via cfe-commits

Author: Nathan Sidwell
Date: 2024-05-12T09:45:00-04:00
New Revision: 1d6bf0ca29322b08e8b50681d440e7182441b025

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

LOG: [clang][NFC] Remove class layout scissor (#89055)

PR #87090 amended `accumulateBitfields` to do the correct clipping. The scissor 
is no longer necessary and  `checkBitfieldClipping` can compute its location 
directly when needed.

Added: 


Modified: 
clang/lib/CodeGen/CGRecordLayoutBuilder.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp 
b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index 868b1ab98e048..5169be204c14d 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -75,7 +75,7 @@ struct CGRecordLowering {
   // sentinel member type that ensures correct rounding.
   struct MemberInfo {
 CharUnits Offset;
-enum InfoKind { VFPtr, VBPtr, Field, Base, VBase, Scissor } Kind;
+enum InfoKind { VFPtr, VBPtr, Field, Base, VBase } Kind;
 llvm::Type *Data;
 union {
   const FieldDecl *FD;
@@ -197,7 +197,7 @@ struct CGRecordLowering {
  const CXXRecordDecl *Query) const;
   void calculateZeroInit();
   CharUnits calculateTailClippingOffset(bool isNonVirtualBaseType) const;
-  void checkBitfieldClipping() const;
+  void checkBitfieldClipping(bool isNonVirtualBaseType) const;
   /// Determines if we need a packed llvm struct.
   void determinePacked(bool NVBaseType);
   /// Inserts padding everywhere it's needed.
@@ -299,8 +299,8 @@ void CGRecordLowering::lower(bool NVBaseType) {
   accumulateVBases();
   }
   llvm::stable_sort(Members);
+  checkBitfieldClipping(NVBaseType);
   Members.push_back(StorageInfo(Size, getIntNType(8)));
-  checkBitfieldClipping();
   determinePacked(NVBaseType);
   insertPadding();
   Members.pop_back();
@@ -894,8 +894,6 @@ CGRecordLowering::calculateTailClippingOffset(bool 
isNonVirtualBaseType) const {
 }
 
 void CGRecordLowering::accumulateVBases() {
-  Members.push_back(MemberInfo(calculateTailClippingOffset(false),
-   MemberInfo::Scissor, nullptr, RD));
   for (const auto  : RD->vbases()) {
 const CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();
 if (BaseDecl->isEmpty())
@@ -950,18 +948,19 @@ void CGRecordLowering::calculateZeroInit() {
 }
 
 // Verify accumulateBitfields computed the correct storage representations.
-void CGRecordLowering::checkBitfieldClipping() const {
+void CGRecordLowering::checkBitfieldClipping(bool IsNonVirtualBaseType) const {
 #ifndef NDEBUG
+  auto ScissorOffset = calculateTailClippingOffset(IsNonVirtualBaseType);
   auto Tail = CharUnits::Zero();
   for (const auto  : Members) {
-// Only members with data and the scissor can cut into tail padding.
-if (!M.Data && M.Kind != MemberInfo::Scissor)
+// Only members with data could possibly overlap.
+if (!M.Data)
   continue;
 
 assert(M.Offset >= Tail && "Bitfield access unit is not clipped");
-Tail = M.Offset;
-if (M.Data)
-  Tail += getSize(M.Data);
+Tail = M.Offset + getSize(M.Data);
+assert((Tail <= ScissorOffset || M.Offset >= ScissorOffset) &&
+   "Bitfield straddles scissor offset");
   }
 #endif
 }



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


[clang] [llvm] [X86][Driver] Do not add `-evex512` for `-march=native` when the target doesn't support AVX512 (PR #91694)

2024-05-12 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

> @tstellar Can a note be added somewhere about this? Folks upgrading to 
> llvm-18.1.6 will get errors unless they drop -march=native if they were on 
> 18.1.5

Although I agree we should add a note, I don't think this patch affects much. 
The problem only coccurs when combining `-march=native` with AVX512 options on 
a non AVX512 target. This actually is not a valid scenario. The compiled binary 
will contain AVX512 instruction which crashes it on the target. It violates the 
intention of using `-march=native`. I also don't see where the error from with 
18.1.6. If there were errors, it should come from 18.1.5.

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


[clang] [clang-tools-extra] [flang] [lld] [llvm] [mlir] [polly] [test]: fix filecheck annotation typos (PR #91854)

2024-05-12 Thread via cfe-commits


@@ -109,16 +109,16 @@ CHECK-NEXT: 0x000e: [DW_RLE_offset_pair  ]: 
{{.*}}[0x[[RANGELIST_OFFSET_STAR
 CHECK-NEXT: 0x0011: [DW_RLE_end_of_list  ]
 
 CHECK: .debug_names contents:
-CHECK-NEX:T Name Index @ 0x0 {
-CHECK-NEX:T   Header {
-CHECK-NEX:T Length: 0x7C
-CHECK-NEX:T Format: DWARF32
-CHECK-NEX:T Version: 5
-CHECK-NEX:T CU count: 1
-CHECK-NEX:T Local TU count: 0
-CHECK-NEX:T Foreign TU count: 0
-CHECK-NEX:T Bucket count: 3
-CHECK-NEX:T Name count: 3
-CHECK-NEX:T Abbreviations table size: 0xD
-CHECK-NEX:T Augmentation: 'LLVM0700'
-CHECK-NEX:T   }
+CHECK-NEXT: Name Index @ 0x0 {
+CHECK-NEXT:   Header {
+CHECK-NEXT: Length: 0x7C

klensy wrote:

actual `Length: 0x80 `

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


[clang] [clang-tools-extra] [flang] [lld] [llvm] [mlir] [polly] [test]: fix filecheck annotation typos (PR #91854)

2024-05-12 Thread via cfe-commits


@@ -1,6 +1,6 @@
 // RUN: llvm-mc -filetype=asm -triple powerpc-ibm-aix-xcoff %s | FileCheck %s
 
-// CHECK-label:   .csect .text[PR],2

klensy wrote:

actual: `.csect ..text..[PR],5`

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


[clang] [llvm] [X86][Driver] Do not add `-evex512` for `-march=native` when the target doesn't support AVX512 (PR #91694)

2024-05-12 Thread Mike Lothian via cfe-commits

FireBurn wrote:

@tstellar Can a note be added somewhere about this? Folks upgrading to 
llvm-18.1.6 will get errors unless they drop -march=native if they were on 
18.1.5

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


[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-05-12 Thread Alex Voicu via cfe-commits

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


[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-05-12 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx commented:

> Please fix the commit message before you merge; otherwise LGTM 

For the commit message I was thinking something along the following lines: `At 
the moment, Clang is rather liberal in assuming that 0 (and by extension 
unqualified) is always a safe default. This does not work for targets that 
actually use a different value for the default / generic AS (for example, the 
SPIRV that obtains from HIPSPV or SYCL). This patch is a first, fairly safe 
step towards trying to clear things up by querying a modules default AS from 
the target, rather than assuming it's 0, alongside fixing a few places where 
things break / we encode the 0 AS assumption. A bunch of existing tests are 
extended to check for non-zero default AS usage.`

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


[clang] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [mlir] [openmp] [polly] fix(python): fix comparison to None (PR #91857)

2024-05-12 Thread Oleksandr Alex Zinenko via cfe-commits

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

LGTM for the MLIR part. Please seek approval from relevant reviewers for all 
other subprojects.

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


[clang] [clang-tools-extra] [flang] [lld] [llvm] [mlir] [polly] [test]: fix filecheck annotation typos (PR #91854)

2024-05-12 Thread via cfe-commits


@@ -382,7 +382,7 @@ void foo18() {
 // CHECK-NEXT: [[A:%.*a.*]] = getelementptr inbounds [[STRUCT_G]], ptr [[G]], 
i32 0, i32 0
 // CHECK-NEXT: store i32 2, ptr [[A]], align 4
 // CHECK-NEXT: [[F:%.*f.*]] = getelementptr inbounds [[STRUCT_G]], ptr [[G]], 
i32 0, i32 1
-// CHECk-NEXT: call void @{{.*F.*}}(ptr noundef nonnull align 1 
dereferenceable(1)) [[F]], ie32 noundef 1)
+// CHECK-NEXT: call void @_ZN1FC1Ei(ptr noundef nonnull align 1 
dereferenceable(1) [[F]], i32 noundef 1)

klensy wrote:

Added literal function name instead of `@{{.*F.*}}` (FileCheck tried to 
substitute `F` var regex?); wrong parentheses; `ie32` instead of i32; 

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


[clang] [libclc] [llvm] [openmp] [Clang] `__attribute__((assume))` refactor (PR #84934)

2024-05-12 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

> > It has nothing to do with OpenMP. The goal was just to get something in the 
> > llvm IR that we could check for. The `assume` attribute allows us to pass a 
> > string that we can then check in a llvm pass.
> 
> Could you investigate whether 'annotate' would do what you want? IIRC, the 
> point of it is to just pass a string onto the AST/IR.

At the moment, I did not manage to have annotation working. It's because 
annotation is an indirect link to the function. Thus it does not stick around 
when I link modules.

Maybe the easiest way would be to add a real attribute for clspv?

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


[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

2024-05-12 Thread via cfe-commits

yronglin wrote:

@zygoloid IIUC, since `CXXDefaultArgExpr` and `CXXDefaultInitExpr` were not 
added to CFG before and were fall back to constant evaluation in ExprEngine, 
they were not processed correctly in StaticAnalyzer. 

In CFG:
https://github.com/llvm/llvm-project/blob/63224d717108d927e998da8a67050a6cc5dd74a2/clang/lib/Analysis/CFG.cpp#L2256-L2266

In ExprEngine:
https://github.com/llvm/llvm-project/commit/5f6c173e7cb4f6a74c1aec2af3ae478a995c140d
https://github.com/llvm/llvm-project/blob/63224d717108d927e998da8a67050a6cc5dd74a2/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp#L1965-L2004

I'd like to proposal a separate PR for static analyzer. 
https://github.com/llvm/llvm-project/pull/91879

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


[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #91879)

2024-05-12 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 23fe1fc6b78b7643a801ce3eb53d14b47b1dd0ff 
6969f06f39363deda92d473ec14a08663c71f3b1 -- clang/lib/AST/ParentMap.cpp 
clang/lib/Analysis/CFG.cpp clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 2f3f3e9251..12a1634a31 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -556,8 +556,10 @@ public:
 
 private:
   // Visitors to walk an AST and construct the CFG.
-  CFGBlock *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Default, AddStmtChoice 
asc);
-  CFGBlock *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Default, AddStmtChoice 
asc);
+  CFGBlock *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Default,
+   AddStmtChoice asc);
+  CFGBlock *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Default,
+AddStmtChoice asc);
   CFGBlock *VisitInitListExpr(InitListExpr *ILE, AddStmtChoice asc);
   CFGBlock *VisitAddrLabelExpr(AddrLabelExpr *A, AddStmtChoice asc);
   CFGBlock *VisitAttributedStmt(AttributedStmt *A, AddStmtChoice asc);

``




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


[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #91879)

2024-05-12 Thread via cfe-commits

https://github.com/yronglin created 
https://github.com/llvm/llvm-project/pull/91879

Depends on https://github.com/llvm/llvm-project/pull/87933

Clang now support the following:
- Extending lifetime of object bound to reference members of aggregates, that 
are created from default member initializer. 
- Rebuild `CXXDefaultArgExpr` and `CXXDefaultInitExpr` as needed where called 
or constructed.

But CFG and ExprEngine need to be updated to address this change.

This PR add `CXXDefaultArgExpr` and `CXXDefaultInitExpr` into CFG, and correct 
handle these expressions in ExprEngine

>From 6969f06f39363deda92d473ec14a08663c71f3b1 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sun, 12 May 2024 14:42:09 +0800
Subject: [PATCH] [Analyzer][CFG] Correctly handle rebuilted default arg and
 default init expression

Signed-off-by: yronglin 
---
 clang/lib/AST/ParentMap.cpp  | 16 +
 clang/lib/Analysis/CFG.cpp   | 38 +++-
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 35 ++
 3 files changed, 56 insertions(+), 33 deletions(-)

diff --git a/clang/lib/AST/ParentMap.cpp b/clang/lib/AST/ParentMap.cpp
index 3d6a1cc84c7b1..534793b837bbb 100644
--- a/clang/lib/AST/ParentMap.cpp
+++ b/clang/lib/AST/ParentMap.cpp
@@ -97,6 +97,22 @@ static void BuildParentMap(MapTy& M, Stmt* S,
   BuildParentMap(M, SubStmt, OVMode);
 }
 break;
+  case Stmt::CXXDefaultArgExprClass:
+if (auto *Arg = dyn_cast(S)) {
+  if (Arg->hasRewrittenInit()) {
+M[Arg->getExpr()] = S;
+BuildParentMap(M, Arg->getExpr(), OVMode);
+  }
+}
+break;
+  case Stmt::CXXDefaultInitExprClass:
+if (auto *Init = dyn_cast(S)) {
+  if (Init->hasRewrittenInit()) {
+M[Init->getExpr()] = S;
+BuildParentMap(M, Init->getExpr(), OVMode);
+  }
+}
+break;
   default:
 for (Stmt *SubStmt : S->children()) {
   if (SubStmt) {
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 64e6155de090c..2f3f3e92516ba 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -556,6 +556,8 @@ class CFGBuilder {
 
 private:
   // Visitors to walk an AST and construct the CFG.
+  CFGBlock *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Default, AddStmtChoice 
asc);
+  CFGBlock *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Default, AddStmtChoice 
asc);
   CFGBlock *VisitInitListExpr(InitListExpr *ILE, AddStmtChoice asc);
   CFGBlock *VisitAddrLabelExpr(AddrLabelExpr *A, AddStmtChoice asc);
   CFGBlock *VisitAttributedStmt(AttributedStmt *A, AddStmtChoice asc);
@@ -2254,16 +2256,10 @@ CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc,
asc, ExternallyDestructed);
 
 case Stmt::CXXDefaultArgExprClass:
+  return VisitCXXDefaultArgExpr(cast(S), asc);
+
 case Stmt::CXXDefaultInitExprClass:
-  // FIXME: The expression inside a CXXDefaultArgExpr is owned by the
-  // called function's declaration, not by the caller. If we simply add
-  // this expression to the CFG, we could end up with the same Expr
-  // appearing multiple times (PR13385).
-  //
-  // It's likewise possible for multiple CXXDefaultInitExprs for the same
-  // expression to be used in the same function (through aggregate
-  // initialization).
-  return VisitStmt(S, asc);
+  return VisitCXXDefaultInitExpr(cast(S), asc);
 
 case Stmt::CXXBindTemporaryExprClass:
   return VisitCXXBindTemporaryExpr(cast(S), asc);
@@ -2433,6 +2429,30 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) {
   return B;
 }
 
+CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Arg,
+ AddStmtChoice asc) {
+  if (Arg->hasRewrittenInit()) {
+if (asc.alwaysAdd(*this, Arg)) {
+  autoCreateBlock();
+  appendStmt(Block, Arg);
+}
+return VisitStmt(Arg->getExpr(), asc);
+  }
+  return VisitStmt(Arg, asc);
+}
+
+CFGBlock *CFGBuilder::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Init,
+  AddStmtChoice asc) {
+  if (Init->hasRewrittenInit()) {
+if (asc.alwaysAdd(*this, Init)) {
+  autoCreateBlock();
+  appendStmt(Block, Init);
+}
+return VisitStmt(Init->getExpr(), asc);
+  }
+  return VisitStmt(Init, asc);
+}
+
 CFGBlock *CFGBuilder::VisitInitListExpr(InitListExpr *ILE, AddStmtChoice asc) {
   if (asc.alwaysAdd(*this, ILE)) {
 autoCreateBlock();
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 0b1edf3e5c96b..41cb4293a8451 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1964,11 +1964,8 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
 case Stmt::CXXDefaultArgExprClass:
 case Stmt::CXXDefaultInitExprClass: {
   Bldr.takeNodes(Pred);
-  ExplodedNodeSet PreVisit;
-  

[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

2024-05-12 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/87933

>From 9fba6da7cb1ffbc7d46b69c6ac0cfd15a89c4b56 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Mon, 8 Apr 2024 01:38:23 +0800
Subject: [PATCH 1/6] [Clang] Support lifetime extension of temporary created
 by aggregate initialization using a default member initializer

Signed-off-by: yronglin 
---
 .../clang/Basic/DiagnosticSemaKinds.td|  6 ---
 clang/lib/Sema/SemaExpr.cpp   | 16 
 clang/lib/Sema/SemaInit.cpp   | 39 +--
 .../Analysis/lifetime-extended-regions.cpp|  2 +-
 clang/test/CXX/drs/dr16xx.cpp |  2 -
 clang/test/CXX/drs/dr18xx.cpp |  5 +--
 clang/test/CXX/special/class.temporary/p6.cpp | 20 ++
 clang/test/SemaCXX/constexpr-default-arg.cpp  |  4 +-
 clang/test/SemaCXX/eval-crashes.cpp   |  6 +--
 9 files changed, 62 insertions(+), 38 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a1dda2d2461c3..ba779e83d2afd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10010,12 +10010,6 @@ def warn_new_dangling_initializer_list : Warning<
   "the allocated initializer list}0 "
   "will be destroyed at the end of the full-expression">,
   InGroup;
-def warn_unsupported_lifetime_extension : Warning<
-  "lifetime extension of "
-  "%select{temporary|backing array of initializer list}0 created "
-  "by aggregate initialization using a default member initializer "
-  "is not yet supported; lifetime of %select{temporary|backing array}0 "
-  "will end at the end of the full-expression">, InGroup;
 
 // For non-floating point, expressions of the form x == x or x != x
 // should result in a warning, since these always evaluate to a constant.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8db4fffeecfe3..b2e0f2a2a6011 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6338,10 +6338,9 @@ ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation 
CallLoc,
 Res = Immediate.TransformInitializer(Param->getInit(),
  /*NotCopy=*/false);
   });
-  if (Res.isInvalid())
-return ExprError();
-  Res = ConvertParamDefaultArgument(Param, Res.get(),
-Res.get()->getBeginLoc());
+  if (Res.isUsable())
+Res = ConvertParamDefaultArgument(Param, Res.get(),
+  Res.get()->getBeginLoc());
   if (Res.isInvalid())
 return ExprError();
   Init = Res.get();
@@ -6377,7 +6376,7 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
   Expr *Init = nullptr;
 
   bool NestedDefaultChecking = isCheckingDefaultArgumentOrInitializer();
-
+  bool InLifetimeExtendingContext = isInLifetimeExtendingContext();
   EnterExpressionEvaluationContext EvalContext(
   *this, ExpressionEvaluationContext::PotentiallyEvaluated, Field);
 
@@ -6412,11 +6411,14 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
   ImmediateCallVisitor V(getASTContext());
   if (!NestedDefaultChecking)
 V.TraverseDecl(Field);
-  if (V.HasImmediateCalls) {
+  if (V.HasImmediateCalls || InLifetimeExtendingContext) {
 ExprEvalContexts.back().DelayedDefaultInitializationContext = {Loc, Field,
CurContext};
 ExprEvalContexts.back().IsCurrentlyCheckingDefaultArgumentOrInitializer =
 NestedDefaultChecking;
+// Pass down lifetime extending flag, and collect temporaries in
+// CreateMaterializeTemporaryExpr when we rewrite the call argument.
+keepInLifetimeExtendingContext();
 
 EnsureImmediateInvocationInDefaultArgs Immediate(*this);
 ExprResult Res;
@@ -6424,7 +6426,7 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
   Res = Immediate.TransformInitializer(Field->getInClassInitializer(),
/*CXXDirectInit=*/false);
 });
-if (!Res.isInvalid())
+if (Res.isUsable())
   Res = ConvertMemberDefaultInitExpression(Field, Res.get(), Loc);
 if (Res.isInvalid()) {
   Field->setInvalidDecl();
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index a75e9925a4314..842412cd674d8 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -710,6 +710,26 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
   if (VerifyOnly)
 return;
 
+  // Enter a lifetime extension context, then we can support lifetime
+  // extension of temporary created by aggregate initialization using a
+  // default member initializer (DR1815 https://wg21.link/CWG1815).
+  //
+  // In 

[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

2024-05-12 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/87933

>From 9fba6da7cb1ffbc7d46b69c6ac0cfd15a89c4b56 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Mon, 8 Apr 2024 01:38:23 +0800
Subject: [PATCH 1/5] [Clang] Support lifetime extension of temporary created
 by aggregate initialization using a default member initializer

Signed-off-by: yronglin 
---
 .../clang/Basic/DiagnosticSemaKinds.td|  6 ---
 clang/lib/Sema/SemaExpr.cpp   | 16 
 clang/lib/Sema/SemaInit.cpp   | 39 +--
 .../Analysis/lifetime-extended-regions.cpp|  2 +-
 clang/test/CXX/drs/dr16xx.cpp |  2 -
 clang/test/CXX/drs/dr18xx.cpp |  5 +--
 clang/test/CXX/special/class.temporary/p6.cpp | 20 ++
 clang/test/SemaCXX/constexpr-default-arg.cpp  |  4 +-
 clang/test/SemaCXX/eval-crashes.cpp   |  6 +--
 9 files changed, 62 insertions(+), 38 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a1dda2d2461c3..ba779e83d2afd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10010,12 +10010,6 @@ def warn_new_dangling_initializer_list : Warning<
   "the allocated initializer list}0 "
   "will be destroyed at the end of the full-expression">,
   InGroup;
-def warn_unsupported_lifetime_extension : Warning<
-  "lifetime extension of "
-  "%select{temporary|backing array of initializer list}0 created "
-  "by aggregate initialization using a default member initializer "
-  "is not yet supported; lifetime of %select{temporary|backing array}0 "
-  "will end at the end of the full-expression">, InGroup;
 
 // For non-floating point, expressions of the form x == x or x != x
 // should result in a warning, since these always evaluate to a constant.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8db4fffeecfe3..b2e0f2a2a6011 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6338,10 +6338,9 @@ ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation 
CallLoc,
 Res = Immediate.TransformInitializer(Param->getInit(),
  /*NotCopy=*/false);
   });
-  if (Res.isInvalid())
-return ExprError();
-  Res = ConvertParamDefaultArgument(Param, Res.get(),
-Res.get()->getBeginLoc());
+  if (Res.isUsable())
+Res = ConvertParamDefaultArgument(Param, Res.get(),
+  Res.get()->getBeginLoc());
   if (Res.isInvalid())
 return ExprError();
   Init = Res.get();
@@ -6377,7 +6376,7 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
   Expr *Init = nullptr;
 
   bool NestedDefaultChecking = isCheckingDefaultArgumentOrInitializer();
-
+  bool InLifetimeExtendingContext = isInLifetimeExtendingContext();
   EnterExpressionEvaluationContext EvalContext(
   *this, ExpressionEvaluationContext::PotentiallyEvaluated, Field);
 
@@ -6412,11 +6411,14 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
   ImmediateCallVisitor V(getASTContext());
   if (!NestedDefaultChecking)
 V.TraverseDecl(Field);
-  if (V.HasImmediateCalls) {
+  if (V.HasImmediateCalls || InLifetimeExtendingContext) {
 ExprEvalContexts.back().DelayedDefaultInitializationContext = {Loc, Field,
CurContext};
 ExprEvalContexts.back().IsCurrentlyCheckingDefaultArgumentOrInitializer =
 NestedDefaultChecking;
+// Pass down lifetime extending flag, and collect temporaries in
+// CreateMaterializeTemporaryExpr when we rewrite the call argument.
+keepInLifetimeExtendingContext();
 
 EnsureImmediateInvocationInDefaultArgs Immediate(*this);
 ExprResult Res;
@@ -6424,7 +6426,7 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
   Res = Immediate.TransformInitializer(Field->getInClassInitializer(),
/*CXXDirectInit=*/false);
 });
-if (!Res.isInvalid())
+if (Res.isUsable())
   Res = ConvertMemberDefaultInitExpression(Field, Res.get(), Loc);
 if (Res.isInvalid()) {
   Field->setInvalidDecl();
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index a75e9925a4314..842412cd674d8 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -710,6 +710,26 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
   if (VerifyOnly)
 return;
 
+  // Enter a lifetime extension context, then we can support lifetime
+  // extension of temporary created by aggregate initialization using a
+  // default member initializer (DR1815 https://wg21.link/CWG1815).
+  //
+  // In