[clang] [clang] Reject VLAs in `__is_layout_compatible()` (PR #87737)

2024-04-05 Thread Vlad Serebrennikov via cfe-commits
Endilll wrote:

> I think the current behavior is reasonable-ish. Rejecting specific types is a 
> bit weird... I think VLA should model incomplete types (but we currently 
> don't reject that either, which is a bug)
> 
> IE, I would expect __is_layout_compatible to return false in the presence of 
> VLAs, incomplete types, and FAM

My reading of your comment is that in the first paragraph you're asking both 
VLAs and incomplete types to be rejected, then in the second paragraph you're 
asking to extend the intrinsic to accept them and yield false. Can you pick one?

> (but we currently don't reject that either, which is a bug)

I'll address that in a follow-up PR, even though rejecting 
`__is_layout_compatible(IncompleteStruct, IncompleteStruct)` doesn't make sense 
to me.

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


[clang] [clang] Reject VLAs in `__is_layout_compatible()` (PR #87737)

2024-04-05 Thread via cfe-commits
cor3ntin wrote:

We should not reject (ie, make the programm ill-form) _any_ type. Just return 
`false` in all of these cases

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


[clang] cfb86ae - [Clang][Sema] Skip checking anonymous enum in using enum declaration (#87144)

2024-04-05 Thread via cfe-commits
Author: Qizhi Hu
Date: 2024-04-05T15:18:07+08:00
New Revision: cfb86ae7497e43e9221ab890221789ae320381e9

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

LOG: [Clang][Sema] Skip checking anonymous enum in using enum declaration 
(#87144)

Try to fix https://github.com/llvm/llvm-project/issues/86790
`getFETokenInfo` requires `DeclarationName` shouldn't be empty and this
will produce crash when checking name conflict of an anonymous
`NamedDecl` in `Sema::PushOnScopeChains` and whether it's a reserved
identifier or not. These wouldn't happen when it's a anonymous enum and
we can skip the checking and just add the declaration to current scope.

Co-authored-by: huqizhi <836744...@qq.com>

Added: 
clang/test/SemaCXX/PR86790.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b11a81139bb1eb..28e8ddb3c41c3e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -503,6 +503,7 @@ Bug Fixes to C++ Support
 
 - Fix crash when inheriting from a cv-qualified type. Fixes:
   (`#35603 `_)
+- Fix a crash when the using enum declaration uses an anonymous enumeration. 
Fixes (#GH86790).
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index cbd84dd2974446..c790dab72dd721 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1537,6 +1537,10 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S, 
bool AddToContext) {
   cast(D)->isFunctionTemplateSpecialization())
 return;
 
+  if (isa(D) && D->getDeclName().isEmpty()) {
+S->AddDecl(D);
+return;
+  }
   // If this replaces anything in the current scope,
   IdentifierResolver::iterator I = IdResolver.begin(D->getDeclName()),
IEnd = IdResolver.end();

diff  --git a/clang/test/SemaCXX/PR86790.cpp b/clang/test/SemaCXX/PR86790.cpp
new file mode 100644
index 00..09e9bb3505e1bf
--- /dev/null
+++ b/clang/test/SemaCXX/PR86790.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+
+enum {A, S, D, F};
+int main() {
+using asdf = decltype(A);
+using enum asdf; // this line causes the crash
+return 0;
+}
+
+namespace N1 {
+enum {A, S, D, F};
+constexpr struct T {
+using asdf = decltype(A);
+using enum asdf;
+} t;
+
+static_assert(t.D == D);
+static_assert(T::S == S);
+}
+
+namespace N2 {
+enum {A, S, D, F};
+constexpr struct T {
+struct {
+using asdf = decltype(A);
+using enum asdf;
+} inner;
+} t;
+
+static_assert(t.inner.D == D);
+static_assert(t.D == D); // expected-error {{no member named 'D' in 
'N2::T'}}
+}



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


[clang] [Clang][Sema] Skip checking anonymous enum in using enum declaration (PR #87144)

2024-04-05 Thread Qizhi Hu via cfe-commits
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/87144
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for scalable vectors in __builtin_reduce_* functions (PR #87750)

2024-04-05 Thread Lawrence Benson via cfe-commits
https://github.com/lawben created 
https://github.com/llvm/llvm-project/pull/87750

Currently, a lot of `__builtin_reduce_*` function do not support scalable 
vectors, i.e., ARM SVE and RISCV V. This PR adds support for them. The main 
code change is to use a different path to extract the type from the vectors, 
the rest is the same and LLVM supports the reduce functions for `vscale` 
vectors.

This PR adds scalable vector support for:
- `__builtin_reduce_add`
- `__builtin_reduce_mul`
- `__builtin_reduce_xor`
- `__builtin_reduce_or`
- `__builtin_reduce_and`
- `__builtin_reduce_min`
- `__builtin_reduce_max`

Note: For all except `min/max`, the element type must still be an integer 
value. Adding floating point support for `add` and `mul` is still an open TODO.

>From a56d6eacc7053a0dac38c5b7ba21d2e37a790baa Mon Sep 17 00:00:00 2001
From: Lawrence Benson 
Date: Fri, 5 Apr 2024 09:15:30 +0200
Subject: [PATCH] [AARCH64,RISCV] Add support for scalable vectors in
 __builtin_reduce* functions.

---
 clang/include/clang/AST/Type.h   |  4 ++
 clang/lib/AST/Type.cpp   | 12 +
 clang/lib/CodeGen/CGBuiltin.cpp  | 10 +++-
 clang/lib/Sema/SemaChecking.cpp  | 23 +++--
 clang/test/CodeGen/builtins-reduction-math.c | 53 
 5 files changed, 96 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 99f45d518c7960..a9f888a037109b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2172,6 +2172,10 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   /// 'riscv_rvv_vector_bits' type attribute as VectorType.
   QualType getRVVEltType(const ASTContext &Ctx) const;
 
+  /// Returns the representative type for the element of a sizeless vector
+  /// builtin type.
+  QualType getSizelessVectorEltType(const ASTContext &Ctx) const;
+
   /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
   /// object types, function types, and incomplete types.
 
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index cb22c91a12aa89..dcba47de0cc7ae 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2510,6 +2510,18 @@ bool Type::isSveVLSBuiltinType() const {
   return false;
 }
 
+QualType Type::getSizelessVectorEltType(const ASTContext &Ctx) const {
+  assert(isSizelessVectorType() && "Must be sizeless vector type");
+  // Currently supports SVE and RVV
+  if (isSVESizelessBuiltinType())
+return getSveEltType(Ctx);
+
+  if (isRVVSizelessBuiltinType())
+return getRVVEltType(Ctx);
+
+  llvm_unreachable("Unhandled type");
+}
+
 QualType Type::getSveEltType(const ASTContext &Ctx) const {
   assert(isSveVLSBuiltinType() && "unsupported type!");
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2537e715b63ee4..e76a211242fdd7 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3868,9 +3868,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   }
 
   case Builtin::BI__builtin_reduce_max: {
-auto GetIntrinsicID = [](QualType QT) {
+auto GetIntrinsicID = [this](QualType QT) {
   if (auto *VecTy = QT->getAs())
 QT = VecTy->getElementType();
+  else if (QT->isSizelessVectorType())
+QT = QT->getSizelessVectorEltType(CGM.getContext());
+
   if (QT->isSignedIntegerType())
 return llvm::Intrinsic::vector_reduce_smax;
   if (QT->isUnsignedIntegerType())
@@ -3883,9 +3886,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   }
 
   case Builtin::BI__builtin_reduce_min: {
-auto GetIntrinsicID = [](QualType QT) {
+auto GetIntrinsicID = [this](QualType QT) {
   if (auto *VecTy = QT->getAs())
 QT = VecTy->getElementType();
+  else if (QT->isSizelessVectorType())
+QT = QT->getSizelessVectorEltType(CGM.getContext());
+
   if (QT->isSignedIntegerType())
 return llvm::Intrinsic::vector_reduce_smin;
   if (QT->isUnsignedIntegerType())
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3dcd18b3afc8b4..6d45dd8bb7ed97 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3166,13 +3166,20 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 
 const Expr *Arg = TheCall->getArg(0);
 const auto *TyA = Arg->getType()->getAs();
-if (!TyA) {
+
+QualType ElTy;
+if (TyA)
+  ElTy = TyA->getElementType();
+else if (Arg->getType()->isSizelessVectorType())
+  ElTy = Arg->getType()->getSizelessVectorEltType(Context);
+
+if (ElTy.isNull()) {
   Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
   << 1 << /* vector ty*/ 4 << Arg->getType();
   return ExprError();
 }
 
-TheCall->setType(TyA->getElementType());
+TheCall->setType(ElTy);
 break;
   }
 
@

[clang] [Clang] Add support for scalable vectors in __builtin_reduce_* functions (PR #87750)

2024-04-05 Thread via cfe-commits
llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Lawrence Benson (lawben)


Changes

Currently, a lot of `__builtin_reduce_*` function do not support scalable 
vectors, i.e., ARM SVE and RISCV V. This PR adds support for them. The main 
code change is to use a different path to extract the type from the vectors, 
the rest is the same and LLVM supports the reduce functions for `vscale` 
vectors.

This PR adds scalable vector support for:
- `__builtin_reduce_add`
- `__builtin_reduce_mul`
- `__builtin_reduce_xor`
- `__builtin_reduce_or`
- `__builtin_reduce_and`
- `__builtin_reduce_min`
- `__builtin_reduce_max`

Note: For all except `min/max`, the element type must still be an integer 
value. Adding floating point support for `add` and `mul` is still an open TODO.

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


5 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+4) 
- (modified) clang/lib/AST/Type.cpp (+12) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+8-2) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+19-4) 
- (modified) clang/test/CodeGen/builtins-reduction-math.c (+53) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 99f45d518c7960..a9f888a037109b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2172,6 +2172,10 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   /// 'riscv_rvv_vector_bits' type attribute as VectorType.
   QualType getRVVEltType(const ASTContext &Ctx) const;
 
+  /// Returns the representative type for the element of a sizeless vector
+  /// builtin type.
+  QualType getSizelessVectorEltType(const ASTContext &Ctx) const;
+
   /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
   /// object types, function types, and incomplete types.
 
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index cb22c91a12aa89..dcba47de0cc7ae 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2510,6 +2510,18 @@ bool Type::isSveVLSBuiltinType() const {
   return false;
 }
 
+QualType Type::getSizelessVectorEltType(const ASTContext &Ctx) const {
+  assert(isSizelessVectorType() && "Must be sizeless vector type");
+  // Currently supports SVE and RVV
+  if (isSVESizelessBuiltinType())
+return getSveEltType(Ctx);
+
+  if (isRVVSizelessBuiltinType())
+return getRVVEltType(Ctx);
+
+  llvm_unreachable("Unhandled type");
+}
+
 QualType Type::getSveEltType(const ASTContext &Ctx) const {
   assert(isSveVLSBuiltinType() && "unsupported type!");
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2537e715b63ee4..e76a211242fdd7 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3868,9 +3868,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   }
 
   case Builtin::BI__builtin_reduce_max: {
-auto GetIntrinsicID = [](QualType QT) {
+auto GetIntrinsicID = [this](QualType QT) {
   if (auto *VecTy = QT->getAs())
 QT = VecTy->getElementType();
+  else if (QT->isSizelessVectorType())
+QT = QT->getSizelessVectorEltType(CGM.getContext());
+
   if (QT->isSignedIntegerType())
 return llvm::Intrinsic::vector_reduce_smax;
   if (QT->isUnsignedIntegerType())
@@ -3883,9 +3886,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   }
 
   case Builtin::BI__builtin_reduce_min: {
-auto GetIntrinsicID = [](QualType QT) {
+auto GetIntrinsicID = [this](QualType QT) {
   if (auto *VecTy = QT->getAs())
 QT = VecTy->getElementType();
+  else if (QT->isSizelessVectorType())
+QT = QT->getSizelessVectorEltType(CGM.getContext());
+
   if (QT->isSignedIntegerType())
 return llvm::Intrinsic::vector_reduce_smin;
   if (QT->isUnsignedIntegerType())
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3dcd18b3afc8b4..6d45dd8bb7ed97 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3166,13 +3166,20 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 
 const Expr *Arg = TheCall->getArg(0);
 const auto *TyA = Arg->getType()->getAs();
-if (!TyA) {
+
+QualType ElTy;
+if (TyA)
+  ElTy = TyA->getElementType();
+else if (Arg->getType()->isSizelessVectorType())
+  ElTy = Arg->getType()->getSizelessVectorEltType(Context);
+
+if (ElTy.isNull()) {
   Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
   << 1 << /* vector ty*/ 4 << Arg->getType();
   return ExprError();
 }
 
-TheCall->setType(TyA->getElementType());
+TheCall->setType(ElTy);
 break;
   }
 
@@ -3188,12 +3195,20 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 
 const Expr *Arg = TheCall->getArg(0);
 const auto *TyA = Arg->getTyp

[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #79236)

2024-04-05 Thread Jay Foad via cfe-commits
jayfoad wrote:

Can you add at least one test for a VMEM (flat or scratch or global or buffer 
or image) atomic without return? That should use vscnt on GFX10.

Apart from that the SIInsertWaitcnts.cpp and tests look good to me. I have not 
reviewed the clang parts but it looks like @Pierre-vh approved them previously?

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


[clang] [clang] Add test for CWG593 (PR #87752)

2024-04-05 Thread Vlad Serebrennikov via cfe-commits
https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/87752

[CWG593](https://cplusplus.github.io/CWG/issues/593.html) "Falling off the end 
of a destructor's function-try-block handler". As usual with CWG issues 
resolved as NAD, we test for status-quo confirmed by CWG.

>From 2266ded77acfc1bbaa8580ad767f99895fee1a4a Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Fri, 5 Apr 2024 10:38:23 +0300
Subject: [PATCH] [clang] Add test for CWG593

[CWG593](https://cplusplus.github.io/CWG/issues/593.html) "Falling off the end 
of a destructor's function-try-block handler". As usual with CWG issues 
resolved as NAD, we test for status-quo confirmed by CWG.
---
 clang/test/CXX/drs/dr593.cpp | 35 +++
 clang/test/CXX/drs/dr5xx.cpp |  2 +-
 clang/www/cxx_dr_status.html |  2 +-
 3 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CXX/drs/dr593.cpp

diff --git a/clang/test/CXX/drs/dr593.cpp b/clang/test/CXX/drs/dr593.cpp
new file mode 100644
index 00..4998af966ebb90
--- /dev/null
+++ b/clang/test/CXX/drs/dr593.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+
+#if __cplusplus == 199711L
+#define NOTHROW throw()
+#else
+#define NOTHROW noexcept(true)
+#endif
+
+namespace dr593 { // dr593: 2.8
+
+void f();
+void fence() NOTHROW;
+
+struct A {
+  ~A() try {
+f();
+  } catch (...) {
+fence();
+  }
+};
+
+void g() {
+  A();
+}
+
+} // namespace dr593
+
+// CHECK:  call void @dr593::fence()()
+// CHECK-NEXT: invoke void @__cxa_rethrow()
diff --git a/clang/test/CXX/drs/dr5xx.cpp b/clang/test/CXX/drs/dr5xx.cpp
index 426b368b390ae6..0ea306a041167b 100644
--- a/clang/test/CXX/drs/dr5xx.cpp
+++ b/clang/test/CXX/drs/dr5xx.cpp
@@ -1098,7 +1098,7 @@ namespace dr591 { // dr591: no
 }
 
 // dr592: na
-// dr593 needs an IRGen test.
+// dr593 is in dr593.cpp
 // dr594: na
 
 namespace dr595 { // dr595: dup 1330
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 5e1e03dec1d484..38f99012c8126b 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -3600,7 +3600,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/593.html";>593
 NAD
 Falling off the end of a destructor's function-try-block 
handler
-Unknown
+Clang 2.8
   
   
 https://cplusplus.github.io/CWG/issues/594.html";>594

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


[clang] [clang] Add test for CWG593 (PR #87752)

2024-04-05 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

[CWG593](https://cplusplus.github.io/CWG/issues/593.html) "Falling off the end 
of a destructor's function-try-block handler". As usual with CWG issues 
resolved as NAD, we test for status-quo confirmed by CWG.

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


3 Files Affected:

- (added) clang/test/CXX/drs/dr593.cpp (+35) 
- (modified) clang/test/CXX/drs/dr5xx.cpp (+1-1) 
- (modified) clang/www/cxx_dr_status.html (+1-1) 


``diff
diff --git a/clang/test/CXX/drs/dr593.cpp b/clang/test/CXX/drs/dr593.cpp
new file mode 100644
index 00..4998af966ebb90
--- /dev/null
+++ b/clang/test/CXX/drs/dr593.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+
+#if __cplusplus == 199711L
+#define NOTHROW throw()
+#else
+#define NOTHROW noexcept(true)
+#endif
+
+namespace dr593 { // dr593: 2.8
+
+void f();
+void fence() NOTHROW;
+
+struct A {
+  ~A() try {
+f();
+  } catch (...) {
+fence();
+  }
+};
+
+void g() {
+  A();
+}
+
+} // namespace dr593
+
+// CHECK:  call void @dr593::fence()()
+// CHECK-NEXT: invoke void @__cxa_rethrow()
diff --git a/clang/test/CXX/drs/dr5xx.cpp b/clang/test/CXX/drs/dr5xx.cpp
index 426b368b390ae6..0ea306a041167b 100644
--- a/clang/test/CXX/drs/dr5xx.cpp
+++ b/clang/test/CXX/drs/dr5xx.cpp
@@ -1098,7 +1098,7 @@ namespace dr591 { // dr591: no
 }
 
 // dr592: na
-// dr593 needs an IRGen test.
+// dr593 is in dr593.cpp
 // dr594: na
 
 namespace dr595 { // dr595: dup 1330
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 5e1e03dec1d484..38f99012c8126b 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -3600,7 +3600,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/593.html";>593
 NAD
 Falling off the end of a destructor's function-try-block 
handler
-Unknown
+Clang 2.8
   
   
 https://cplusplus.github.io/CWG/issues/594.html";>594

``




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


[clang] [clang] Claim conformance for CWG466 (PR #87748)

2024-04-05 Thread via cfe-commits
cor3ntin wrote:

I agree with that (the new wording in [basic.lookup.qual.general] ignore cv 
qualifications)

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


[clang] [clang] Claim conformance for CWG466 (PR #87748)

2024-04-05 Thread via cfe-commits
https://github.com/cor3ntin approved this pull request.


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


[clang-tools-extra] 7e958f6 - [flang][clang] Add Visibility specific help text for options (#81869)

2024-04-05 Thread via cfe-commits
Author: David Spickett
Date: 2024-04-05T09:03:16+01:00
New Revision: 7e958f64efea6cb824e96ace51e021afbc150922

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

LOG: [flang][clang] Add Visibility specific help text for options (#81869)

And use it to print the correct default OpenMP version for flang and
flang -fc1.

This change adds an optional `HelpTextsForVariants` to options. This
allows you to change the help text that gets shown in documentation and
`--help` based on the program its being generated for.

As `OptTable` needs to be constexpr compatible, I have used a std::array
of help text variants. Each entry is:
(list of visibilities) - > help text string

So for the OpenMP version we have (flang, fc1) -> "OpenMP version for
flang is...".

So you can have multiple visibilities use the same string. The number of
entries is currently set to 1, and the number of visibilities per entry
is 2, because that's the maximum we need for now. The code is written so
we can increase these numbers later, and the unused elements will be 
initialised.

I have not applied this to group descriptions just because I don't know
of one that needs changing. It could easily be enabled for those too if
needed. There are minor changes to them just to get it all to compile.

This approach of storing many help strings per option in the 1 driver
library seemed preferable to making a whole new library for Flang (even
if that would mostly be including stuff from Clang).

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/utils/TableGen/ClangOptionDocEmitter.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
lld/MachO/DriverUtils.cpp
lld/MinGW/Driver.cpp
lld/wasm/Driver.cpp
llvm/include/llvm/Option/OptParser.td
llvm/include/llvm/Option/OptTable.h
llvm/lib/Option/OptTable.cpp
llvm/unittests/Option/OptionMarshallingTest.cpp
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index 5b8128fca62668..fddfffe7523d95 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -466,7 +466,8 @@ llvm::ArrayRef 
ArgStripper::rulesFor(llvm::StringRef Arg) {
   static constexpr llvm::ArrayRef NAME(   
\
   NAME##_init, std::size(NAME##_init) - 1);
 #define OPTION(PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS,   
\
-   FLAGS, VISIBILITY, PARAM, HELP, METAVAR, VALUES)
\
+   FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS,   
\
+   METAVAR, VALUES)
\
   Prefixes[DriverID::OPT_##ID] = PREFIX;
 #include "clang/Driver/Options.inc"
 #undef OPTION
@@ -478,7 +479,8 @@ llvm::ArrayRef 
ArgStripper::rulesFor(llvm::StringRef Arg) {
   const void *AliasArgs;
 } AliasTable[] = {
 #define OPTION(PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS,   
\
-   FLAGS, VISIBILITY, PARAM, HELP, METAVAR, VALUES)
\
+   FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS,   
\
+   METAVAR, VALUES)
\
   {DriverID::OPT_##ID, DriverID::OPT_##ALIAS, ALIASARGS},
 #include "clang/Driver/Options.inc"
 #undef OPTION

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 12e8dc7912c3b8..f051bca6c1e953 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3409,10 +3409,16 @@ def fopenmp : Flag<["-"], "fopenmp">, Group,
   HelpText<"Parse OpenMP pragmas and generate parallel code.">;
 def fno_openmp : Flag<["-"], "fno-openmp">, Group,
   Flags<[NoArgumentUnused]>;
+class OpenMPVersionHelp {
+  string str = !strconcat(
+"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default 
value is ",
+default, " for ", program);
+}
 def fopenmp_version_EQ : Joined<["-"], "fopenmp-version=">, Group,
   Flags<[NoArgumentUnused]>,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
-  HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). 
Default value is 51 for Clang">;
+  HelpText.str>,
+  HelpTextForVariants<[FlangOption, FC1Option], OpenMPVersionHelp<"Flang", 
"11">.str>;
 defm openmp_extensions: BoolFOption<"openmp-extensions",
   LangOpts<"OpenMPExtensions">, DefaultTrue,
   PosFlag VisibilitiesHelp =
+  R->getValueAsListOfDefs("HelpTextsForVariants");
+  for (Record *VisibilityHelp : VisibilitiesHelp) {
+

[clang] [clang-tools-extra] [flang] [lld] [llvm] [flang][clang] Add Visibility specific help text for options (PR #81869)

2024-04-05 Thread David Spickett via cfe-commits
https://github.com/DavidSpickett closed 
https://github.com/llvm/llvm-project/pull/81869
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread Julian Nagele via cfe-commits
https://github.com/juliannagele created 
https://github.com/llvm/llvm-project/pull/87753

When generating tbaa.struct metadata we treat multiple adjacent bitfields as a 
single "field", with one corresponding entry in the metadata. At the moment 
this is achieved by adding an entry for the first bitfield in the run using its 
StorageSize and skipping the remaining bitfields. The problem is that "first" 
is determined by checking that the Offset of the field in the run is 0, which 
breaks for big endian.

>From cd73a85e55d683f9aa18e1099302202d663e5e7d Mon Sep 17 00:00:00 2001
From: Julian Nagele 
Date: Thu, 4 Apr 2024 11:48:19 +0100
Subject: [PATCH] Fix tbaa.struct metadata for bitfields using big endian.

When generating tbaa.struct metadata we treat multiple adjacent
bitfields as a single "field", with one corresponding entry in the
metadata.
At the moment this is achieved by adding an entry for the first
bitfield in the run using its StorageSize (and skipping the remaining
bitfields). The problem is that "first" is determined by checking that
the Offset of the field in the run is 0. This breaks for big endian.
---
 clang/lib/CodeGen/CodeGenTBAA.cpp  |  6 +-
 clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp | 10 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index a1e14c5f0a8c78..0ddefc4751b08c 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/LLVMContext.h"
@@ -319,7 +320,10 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0
+: Info.Offset == 0;
+if (!IsFirst)
   continue;
 unsigned CurrentBitFieldSize = Info.StorageSize;
 uint64_t Size =
diff --git a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp 
b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
index 80884b49ddc669..e8bb46982537bb 100644
--- a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
+++ b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
@@ -1,13 +1,10 @@
 // RUN: %clang_cc1 -triple aarch64_be-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-BE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 // RUN: %clang_cc1 -triple aarch64-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-LE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 //
 // Check that TBAA metadata for structs containing bitfields is
 // consistent between big and little endian layouts.
-//
-// FIXME: The metadata below is invalid for the big endian layout: the
-// start offset of 2 is incorrect.
 
 struct NamedBitfields {
   int f1 : 8;
@@ -28,8 +25,7 @@ void copy(NamedBitfields *a1, NamedBitfields *a2) {
   *a1 = *a2;
 }
 
-// CHECK-BE: [[TBAA_STRUCT2]] = !{i64 2, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
-// CHECK-LE: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
+// CHECK: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 4, 
[[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
 // CHECK: [[META3]] = !{[[META4:![0-9]+]], [[META4]], i64 0}
 // CHECK: [[META4]] = !{!"omnipotent char", [[META5:![0-9]+]], i64 0}
 // CHECK: [[META5]] = !{!"Simple C++ TBAA"}

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


[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Julian Nagele (juliannagele)


Changes

When generating tbaa.struct metadata we treat multiple adjacent bitfields as a 
single "field", with one corresponding entry in the metadata. At the moment 
this is achieved by adding an entry for the first bitfield in the run using its 
StorageSize and skipping the remaining bitfields. The problem is that "first" 
is determined by checking that the Offset of the field in the run is 0, which 
breaks for big endian.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenTBAA.cpp (+5-1) 
- (modified) clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp (+3-7) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index a1e14c5f0a8c78..0ddefc4751b08c 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/LLVMContext.h"
@@ -319,7 +320,10 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0
+: Info.Offset == 0;
+if (!IsFirst)
   continue;
 unsigned CurrentBitFieldSize = Info.StorageSize;
 uint64_t Size =
diff --git a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp 
b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
index 80884b49ddc669..e8bb46982537bb 100644
--- a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
+++ b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
@@ -1,13 +1,10 @@
 // RUN: %clang_cc1 -triple aarch64_be-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-BE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 // RUN: %clang_cc1 -triple aarch64-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-LE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 //
 // Check that TBAA metadata for structs containing bitfields is
 // consistent between big and little endian layouts.
-//
-// FIXME: The metadata below is invalid for the big endian layout: the
-// start offset of 2 is incorrect.
 
 struct NamedBitfields {
   int f1 : 8;
@@ -28,8 +25,7 @@ void copy(NamedBitfields *a1, NamedBitfields *a2) {
   *a1 = *a2;
 }
 
-// CHECK-BE: [[TBAA_STRUCT2]] = !{i64 2, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
-// CHECK-LE: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
+// CHECK: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 4, 
[[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
 // CHECK: [[META3]] = !{[[META4:![0-9]+]], [[META4]], i64 0}
 // CHECK: [[META4]] = !{!"omnipotent char", [[META5:![0-9]+]], i64 0}
 // CHECK: [[META5]] = !{!"Simple C++ TBAA"}

``




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


[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread Julian Nagele via cfe-commits
https://github.com/juliannagele updated 
https://github.com/llvm/llvm-project/pull/87753

>From db1ee85ca26d7ddbaa163f4e9b1038c28e3d4a57 Mon Sep 17 00:00:00 2001
From: Julian Nagele 
Date: Thu, 4 Apr 2024 11:48:19 +0100
Subject: [PATCH] Fix tbaa.struct metadata for bitfields using big endian.

When generating tbaa.struct metadata we treat multiple adjacent
bitfields as a single "field", with one corresponding entry in the
metadata.
At the moment this is achieved by adding an entry for the first
bitfield in the run using its StorageSize (and skipping the remaining
bitfields). The problem is that "first" is determined by checking that
the Offset of the field in the run is 0. This breaks for big endian.
---
 clang/lib/CodeGen/CodeGenTBAA.cpp  |  6 +-
 clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp | 10 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index a1e14c5f0a8c78..0ddefc4751b08c 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/LLVMContext.h"
@@ -319,7 +320,10 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0
+: Info.Offset == 0;
+if (!IsFirst)
   continue;
 unsigned CurrentBitFieldSize = Info.StorageSize;
 uint64_t Size =
diff --git a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp 
b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
index 80884b49ddc669..e8bb46982537bb 100644
--- a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
+++ b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
@@ -1,13 +1,10 @@
 // RUN: %clang_cc1 -triple aarch64_be-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-BE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 // RUN: %clang_cc1 -triple aarch64-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-LE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 //
 // Check that TBAA metadata for structs containing bitfields is
 // consistent between big and little endian layouts.
-//
-// FIXME: The metadata below is invalid for the big endian layout: the
-// start offset of 2 is incorrect.
 
 struct NamedBitfields {
   int f1 : 8;
@@ -28,8 +25,7 @@ void copy(NamedBitfields *a1, NamedBitfields *a2) {
   *a1 = *a2;
 }
 
-// CHECK-BE: [[TBAA_STRUCT2]] = !{i64 2, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
-// CHECK-LE: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
+// CHECK: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 4, 
[[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
 // CHECK: [[META3]] = !{[[META4:![0-9]+]], [[META4]], i64 0}
 // CHECK: [[META4]] = !{!"omnipotent char", [[META5:![0-9]+]], i64 0}
 // CHECK: [[META5]] = !{!"Simple C++ TBAA"}

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


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-05 Thread Charalampos Mitrodimas via cfe-commits
https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From ffc6db2006ed503369ce79a6507fa237649e6af1 Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

Warning '-Wundefined-func-template' incorrectly indicates that no
definition is available for a pure virtual function. However, a
definition is not needed for a pure virtual function.

Fixes #74016

Signed-off-by: Charalampos Mitrodimas 
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/lib/Sema/SemaExpr.cpp   |  5 +-
 .../instantiate-pure-virtual-function.cpp | 68 +++
 3 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8054d90fc70f93..643eb6cc157732 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -294,6 +294,10 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+- Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
+  functions.
+  (`#74016 `_)
+
 - Fixed missing warnings when comparing mismatched enumeration constants
   in C (`#29217 `).
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5f03b981428251..d74dc66b1b5075 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18975,8 +18975,9 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   // Note that we skip the implicit instantiation of templates that are only
   // used in unused default arguments or by recursive calls to themselves.
   // This is formally non-conforming, but seems reasonable in practice.
-  bool NeedDefinition = !IsRecursiveCall && (OdrUse == OdrUseContext::Used ||
- NeededForConstantEvaluation);
+  bool NeedDefinition = !IsRecursiveCall &&
+(OdrUse == OdrUseContext::Used ||
+ NeededForConstantEvaluation || Func->isPureVirtual());
 
   // C++14 [temp.expl.spec]p6:
   //   If a template [...] is explicitly specialized then that specialization
diff --git a/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp 
b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
new file mode 100644
index 00..1dd668a385ec84
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+
+namespace GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); } // expected-warning 
{{instantiation of function 'GH74016::B::bar' required here, but no 
definition is available}}
+// expected-note@-1 {{add an explicit instantiation declaration to 
suppress this warning if 'GH74016::B::bar' is explicitly instantiated in 
another translation unit}}
+virtual constexpr void bar(unsigned int) = 0; // expected-note {{forward 
declaration of template entity is here}}
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};
+
+namespace call_pure_virtual_function_from_virtual {
+  template  class B {
+  public:
+const void foo(const T &) { B::bar(1); } // expected-warning 
{{instantiation of function 
'call_pure_virtual_function_from_virtual::B::bar' required here, but no 
definition is available}}
+// expected-note@-1 {{add an explicit instantiation declaration to 
suppress this warning if 'call_pure_virtual_function_from_virtual::B::bar' 
is explicitly instantiated in another translation unit}}
+virtual const void bar(unsigned int) = 0; // expected-note {{forward 
declaration of template entity is here}}
+  };
+
+  template  class D : public B {
+  public:
+const void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0); // expected-note {{in instantiation of member function 
'call_pure_virtual_function_from_virtual::B::foo' requested here}}
+  }
+};
+
+namespace non_pure_virtual_function {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+
+virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
+// expected-note@-1 {{forward declaration of template entity is here}}
+// expected-note@-2 {{forward declaration of template entity is here}}
+// expected-note@-3 {{forward declaration of template entity is here}}
+  };
+
+  template  class D : public B { // expected-warning 
{{instantiation of function 'non_pure_virtual_function::B::ba

[clang-tools-extra] aff197f - Reland "[flang][clang] Add Visibility specific help text for options (#81869)"

2024-04-05 Thread David Spickett via cfe-commits
Author: David Spickett
Date: 2024-04-05T08:27:59Z
New Revision: aff197ff2163a4b7732d08b833906cc21f4a5c89

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

LOG: Reland "[flang][clang] Add Visibility specific help text for options 
(#81869)"

This reverts commit 67d20412b448533c77f54ac7a1e5d0775d273729.

This includes fixes for clanginstallapi.

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/tools/clang-installapi/Options.cpp
clang/tools/clang-installapi/Options.h
clang/utils/TableGen/ClangOptionDocEmitter.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
lld/MachO/DriverUtils.cpp
lld/MinGW/Driver.cpp
lld/wasm/Driver.cpp
llvm/include/llvm/Option/OptParser.td
llvm/include/llvm/Option/OptTable.h
llvm/lib/Option/OptTable.cpp
llvm/unittests/Option/OptionMarshallingTest.cpp
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index 5b8128fca62668..fddfffe7523d95 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -466,7 +466,8 @@ llvm::ArrayRef 
ArgStripper::rulesFor(llvm::StringRef Arg) {
   static constexpr llvm::ArrayRef NAME(   
\
   NAME##_init, std::size(NAME##_init) - 1);
 #define OPTION(PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS,   
\
-   FLAGS, VISIBILITY, PARAM, HELP, METAVAR, VALUES)
\
+   FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS,   
\
+   METAVAR, VALUES)
\
   Prefixes[DriverID::OPT_##ID] = PREFIX;
 #include "clang/Driver/Options.inc"
 #undef OPTION
@@ -478,7 +479,8 @@ llvm::ArrayRef 
ArgStripper::rulesFor(llvm::StringRef Arg) {
   const void *AliasArgs;
 } AliasTable[] = {
 #define OPTION(PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS,   
\
-   FLAGS, VISIBILITY, PARAM, HELP, METAVAR, VALUES)
\
+   FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS,   
\
+   METAVAR, VALUES)
\
   {DriverID::OPT_##ID, DriverID::OPT_##ALIAS, ALIASARGS},
 #include "clang/Driver/Options.inc"
 #undef OPTION

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 12e8dc7912c3b8..f051bca6c1e953 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3409,10 +3409,16 @@ def fopenmp : Flag<["-"], "fopenmp">, Group,
   HelpText<"Parse OpenMP pragmas and generate parallel code.">;
 def fno_openmp : Flag<["-"], "fno-openmp">, Group,
   Flags<[NoArgumentUnused]>;
+class OpenMPVersionHelp {
+  string str = !strconcat(
+"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default 
value is ",
+default, " for ", program);
+}
 def fopenmp_version_EQ : Joined<["-"], "fopenmp-version=">, Group,
   Flags<[NoArgumentUnused]>,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
-  HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). 
Default value is 51 for Clang">;
+  HelpText.str>,
+  HelpTextForVariants<[FlangOption, FC1Option], OpenMPVersionHelp<"Flang", 
"11">.str>;
 defm openmp_extensions: BoolFOption<"openmp-extensions",
   LangOpts<"OpenMPExtensions">, DefaultTrue,
   PosFlag
 /// Create table mapping all options defined in InstallAPIOpts.td.
 static constexpr OptTable::Info InfoTable[] = {
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, 
\
-   VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES)   
\
-  {PREFIX, NAME,  HELPTEXT,   METAVAR, OPT_##ID,Option::KIND##Class,   
\
-   PARAM,  FLAGS, VISIBILITY, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, 
\
+   VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, METAVAR, 
\
+   VALUES) 
\
+  {PREFIX, 
\
+   NAME,   
\
+   HELPTEXT,   
\
+   HELPTEXTSFORVARIANTS,   
\
+   METAVAR,
\
+   OPT_##ID,   
\
+   Option::KIND##Class,

[clang] [llvm] [Clang] Emit DW_TAG_template_alias for template aliases (PR #87623)

2024-04-05 Thread Orlando Cazalet-Hyams via cfe-commits
OCHyams wrote:

> LLVM IR parts look good to me.

Thanks!

@pogo59 said:

> Converting frame-types.s from v4 to v5 should be done as a separate commit. 
> Then adding the alias would be a simpler change to review.

I've split that into two commits in this PR: upgrade to v5: 
[18446f2](https://github.com/llvm/llvm-project/pull/87623/commits/18446f27e31803057d9d90c957e5e191eb263b7b),
 add template alias: 
[49d6642](https://github.com/llvm/llvm-project/pull/87623/commits/49d66423ae61baf9cacd42c2b57333e09e4c1e81).
 It does improve readability a bit but its still quite noisy. I am happy to 
commit the former separately then rebase this PR, if you'd like? 

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


[clang] [analyzer] Make recognition of hardened __FOO_chk functions explicit (PR #86536)

2024-04-05 Thread via cfe-commits
https://github.com/NagyDonat updated 
https://github.com/llvm/llvm-project/pull/86536

>From fdde1056e8a34ad642f50eef120dbc8ee08f8825 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Mon, 18 Mar 2024 14:47:57 +0100
Subject: [PATCH 1/2] [analyzer] Make recognition of hardened __FOO_chk
 functions explicit

In builds that use source hardening (-D_FORTIFY_SOURCE), many standard
functions are implemented as macros that expand to calls of hardened
functions that take one additional argument compared to the "usual"
variant and perform additional input validation. For example, a `memcpy`
call may expand to `__memcpy_chk()` or `__builtin___memcpy_chk()`.

Before this commit, `CallDescription`s created with the matching mode
`CDM::CLibrary` automatically matched these hardened variants (in a
addition to the "usual" function) with a fairly lenient heuristic.

Unfortunately this heuristic meant that the `CLibrary` matching mode was
only usable by checkers that were prepared to handle matches with an
unusual number of arguments.

This commit limits the recognition of the hardened functions to a
separate matching mode `CDM::CLibraryMaybeHardened` and applies this
mode for functions that have hardened variants and were previously
recognized with `CDM::CLibrary`.

This way checkers that are prepared to handle the hardened variants will
be able to detect them easily; while other checkers can simply use
`CDM::CLibrary` for matching C library functions (and they won't
encounter surprising argument counts).

The initial motivation for refactoring this area was that previously
`CDM::CLibrary` accepted calls with more arguments/parameters than the
expected number, so I wasn't able to use it for `malloc` without
accidentally matching calls to the 3-argument BSD kernel malloc.

After this commit this "may have more args/params" logic will only
activate when we're actually matching a hardened variant function (in
`CDM::CLibraryMaybeHardened` mode). The recognition of "sprintf()" and
"snprintf()" in CStringChecker was refactored, because previously it was
abusing the behavior that extra arguments are accepted even if the
matched function is not a hardened variant.

This commit also fixes the oversight that the old code would've
recognized e.g. `__wmemcpy_chk` as a hardened variant of `memcpy`.

After this commit I'm planning to create several follow-up commits that
ensure that checkers looking for C library functions use `CDM::CLibrary`
as a "sane default" matching mode.

This commit is not truly NFC (it eliminates some buggy corner cases),
but it does not intentionally modify the behavior of CSA on real-world
non-crazy code.

As a minor unrelated change I'm eliminating the argument/variable
"IsBuiltin" from the evalSprintf function family in CStringChecker,
because it was completely unused.
---
 .../Core/PathSensitive/CallDescription.h  |  26 ++--
 .../Core/PathSensitive/CheckerContext.h   |  24 +++-
 .../Checkers/CStringChecker.cpp   |  76 +++
 .../Checkers/GenericTaintChecker.cpp  |  27 ++--
 .../StaticAnalyzer/Core/CallDescription.cpp   | 122 +-
 .../StaticAnalyzer/Core/CheckerContext.cpp|  19 ++-
 .../StaticAnalyzer/CallDescriptionTest.cpp|  54 ++--
 7 files changed, 217 insertions(+), 131 deletions(-)

diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
index b4e1636130ca7c..ccfe8d47c290bc 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
@@ -32,19 +32,22 @@ namespace ento {
 class CallDescription {
 public:
   enum class Mode {
-/// Match calls to functions from the C standard library. On some platforms
-/// some functions may be implemented as macros that expand to calls to
-/// built-in variants of the given functions, so in this mode we use some
-/// heuristics to recognize these implementation-defined variants:
-///  - We also accept calls where the name is derived from the specified
-///name by adding "__builtin" or similar prefixes/suffixes.
-///  - We also accept calls where the number of arguments or parameters is
-///greater than the specified value.
+/// Match calls to functions from the C standard library. This also
+/// recognizes builtin variants whose name is derived by adding
+/// "__builtin", "__inline" or similar prefixes or suffixes; but only
+/// matches functions than are externally visible and are declared either
+/// directly within a TU or in the namespace 'std'.
 /// For the exact heuristics, see CheckerContext::isCLibraryFunction().
-/// (This mode only matches functions that are declared either directly
-/// within a TU or in the namespace `std`.)
 CLibrary,
 
+/// An extended version of the `CLibrary` mode that also ma

[clang] fb299ca - [analyzer] Make recognition of hardened __FOO_chk functions explicit (#86536)

2024-04-05 Thread via cfe-commits
Author: NagyDonat
Date: 2024-04-05T11:20:27+02:00
New Revision: fb299cae5167f63933df45979e3e9de97fca1b8f

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

LOG: [analyzer] Make recognition of hardened __FOO_chk functions explicit 
(#86536)

In builds that use source hardening (-D_FORTIFY_SOURCE), many standard
functions are implemented as macros that expand to calls of hardened
functions that take one additional argument compared to the "usual"
variant and perform additional input validation. For example, a `memcpy`
call may expand to `__memcpy_chk()` or `__builtin___memcpy_chk()`.

Before this commit, `CallDescription`s created with the matching mode
`CDM::CLibrary` automatically matched these hardened variants (in a
addition to the "usual" function) with a fairly lenient heuristic.

Unfortunately this heuristic meant that the `CLibrary` matching mode was
only usable by checkers that were prepared to handle matches with an
unusual number of arguments.

This commit limits the recognition of the hardened functions to a
separate matching mode `CDM::CLibraryMaybeHardened` and applies this
mode for functions that have hardened variants and were previously
recognized with `CDM::CLibrary`.

This way checkers that are prepared to handle the hardened variants will
be able to detect them easily; while other checkers can simply use
`CDM::CLibrary` for matching C library functions (and they won't
encounter surprising argument counts).

The initial motivation for refactoring this area was that previously
`CDM::CLibrary` accepted calls with more arguments/parameters than the
expected number, so I wasn't able to use it for `malloc` without
accidentally matching calls to the 3-argument BSD kernel malloc.

After this commit this "may have more args/params" logic will only
activate when we're actually matching a hardened variant function (in
`CDM::CLibraryMaybeHardened` mode). The recognition of "sprintf()" and
"snprintf()" in CStringChecker was refactored, because previously it was
abusing the behavior that extra arguments are accepted even if the
matched function is not a hardened variant.

This commit also fixes the oversight that the old code would've
recognized e.g. `__wmemcpy_chk` as a hardened variant of `memcpy`.

After this commit I'm planning to create several follow-up commits that
ensure that checkers looking for C library functions use `CDM::CLibrary`
as a "sane default" matching mode.

This commit is not truly NFC (it eliminates some buggy corner cases),
but it does not intentionally modify the behavior of CSA on real-world
non-crazy code.

As a minor unrelated change I'm eliminating the argument/variable
"IsBuiltin" from the evalSprintf function family in CStringChecker,
because it was completely unused.

-

Co-authored-by: Balazs Benics 

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
clang/lib/StaticAnalyzer/Core/CallDescription.cpp
clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
index b4e1636130ca7c..ccfe8d47c290bc 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
@@ -32,19 +32,22 @@ namespace ento {
 class CallDescription {
 public:
   enum class Mode {
-/// Match calls to functions from the C standard library. On some platforms
-/// some functions may be implemented as macros that expand to calls to
-/// built-in variants of the given functions, so in this mode we use some
-/// heuristics to recognize these implementation-defined variants:
-///  - We also accept calls where the name is derived from the specified
-///name by adding "__builtin" or similar prefixes/suffixes.
-///  - We also accept calls where the number of arguments or parameters is
-///greater than the specified value.
+/// Match calls to functions from the C standard library. This also
+/// recognizes builtin variants whose name is derived by adding
+/// "__builtin", "__inline" or similar prefixes or suffixes; but only
+/// matches functions than are externally visible and are declared either
+/// directly within a TU or in the namespace 'std'.
 /// For the exact heuristics, see CheckerContext::isCLibraryFunction().
-/// (This mode only matches func

[clang] [analyzer] Make recognition of hardened __FOO_chk functions explicit (PR #86536)

2024-04-05 Thread via cfe-commits
https://github.com/NagyDonat closed 
https://github.com/llvm/llvm-project/pull/86536
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 163301d - [analyzer] Remove barely used class 'KnownSVal' (NFC) (#86953)

2024-04-05 Thread via cfe-commits
Author: NagyDonat
Date: 2024-04-05T11:22:08+02:00
New Revision: 163301d785a7e6b45d25a4060a239d6af72d6ae6

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

LOG: [analyzer] Remove barely used class 'KnownSVal' (NFC) (#86953)

The class `KnownSVal` was very magical abstract class within the `SVal`
class hierarchy: with a hacky `classof` method it acted as if it was the
common ancestor of the classes `UndefinedSVal` and `DefinedSVal`.

However, it was only used in two `getAs()` calls and the
signatures of two methods, which does not "pay for" its weird behavior,
so I created this commit that removes it and replaces its use with more
straightforward solutions.

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
index d9b3d9352d3224..cc3d93aabafda4 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
@@ -374,6 +374,7 @@ bool trackExpressionValue(const ExplodedNode *N, const Expr 
*E,
 /// from.
 ///
 /// \param V We're searching for the store where \c R received this value.
+///It may be either defined or undefined, but should not be unknown.
 /// \param R The region we're tracking.
 /// \param Opts Tracking options specifying how we want to track the value.
 /// \param Origin Only adds notes when the last store happened in a
@@ -383,7 +384,7 @@ bool trackExpressionValue(const ExplodedNode *N, const Expr 
*E,
 ///changes to its value in a nested stackframe could be pruned, and
 ///this visitor can prevent that without polluting the bugpath too
 ///much.
-void trackStoredValue(KnownSVal V, const MemRegion *R,
+void trackStoredValue(SVal V, const MemRegion *R,
   PathSensitiveBugReport &Report, TrackingOptions Opts = 
{},
   const StackFrameContext *Origin = nullptr);
 

diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
index c60528b7685fe8..3a4b0872571494 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -232,14 +232,6 @@ class DefinedSVal : public DefinedOrUnknownSVal {
   : DefinedOrUnknownSVal(Kind, Data) {}
 };
 
-/// Represents an SVal that is guaranteed to not be UnknownVal.
-class KnownSVal : public SVal {
-public:
-  /*implicit*/ KnownSVal(DefinedSVal V) : SVal(V) {}
-  /*implicit*/ KnownSVal(UndefinedVal V) : SVal(V) {}
-  static bool classof(SVal V) { return !V.isUnknown(); }
-};
-
 class NonLoc : public DefinedSVal {
 protected:
   NonLoc(SValKind Kind, const void *Data) : DefinedSVal(Kind, Data) {}

diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
index c3acb73ba7175b..086c3e5e49b770 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -977,7 +977,7 @@ void RefLeakReport::findBindingToReport(CheckerContext &Ctx,
 //   something like derived regions if we want to construct SVal from
 //   Sym. Instead, we take the value that is definitely stored in that
 //   region, thus guaranteeing that trackStoredValue will work.
-bugreporter::trackStoredValue(AllVarBindings[0].second.castAs(),
+bugreporter::trackStoredValue(AllVarBindings[0].second,
   AllocBindingToReport, *this);
   } else {
 AllocBindingToReport = AllocFirstBinding;

diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index a0822513a6d02e..984755fa7e502f 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1238,7 +1238,7 @@ class StoreSiteFinder final : public 
TrackingBugReporterVisitor {
   ///changes to its value in a nested stackframe could be pruned, and
   ///this visitor can prevent that without polluting the bugpath too
   ///much.
-  StoreSiteFinder(bugreporter::TrackerRef ParentTracker, KnownSVal V,
+  StoreSiteFinde

[clang] [analyzer] Remove barely used class 'KnownSVal' (NFC) (PR #86953)

2024-04-05 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


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


[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread via cfe-commits

@@ -319,7 +320,10 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0

dobbelaj-snps wrote:

Maybe cleaner to say ?

bool IsFirst = IsBE ? (Info.Offset + Info.Size) == Info.StorageSize

as in: in BE a bitfield is first if it starts at the most significant bit of 
the storage ?


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


[clang] [compiler-rt] Fix "[clang][UBSan] Add implicit conversion check for bitfields" (PR #87761)

2024-04-05 Thread Axel Lundberg via cfe-commits
https://github.com/Zonotora created 
https://github.com/llvm/llvm-project/pull/87761

Fix since #75481 got reverted.

- Explicitly set BitfieldBits to 0 to avoid uninitialized field member for the 
integer checks:
```diff
-   llvm::ConstantInt::get(Builder.getInt8Ty(), Check.first)};
+  llvm::ConstantInt::get(Builder.getInt8Ty(), Check.first),
+  llvm::ConstantInt::get(Builder.getInt32Ty(), 0)};
```
- `Value **Previous` was erroneously `Value *Previous` in 
`CodeGenFunction::EmitWithOriginalRHSBitfieldAssignment`, fixed now.
- Assert instead of check:
```diff
- if (Kind == CK_IntegralCast) {
+assert(Kind == CK_IntegralCast || Kind == CK_LValueToRValue &&
+ "Should be either CK_IntegralCast or CK_LValueToRValue");
```
CK_LValueToRValue when going from, e.g., char to char, and CK_IntegralCast 
otherwise.
- Make sure that `Value *Previous = nullptr;` is initialized (see 
https://github.com/llvm/llvm-project/commit/1189e87951e59a81ee097eae847c06008276fef1)
- Add another extensive testcase 
`ubsan/TestCases/ImplicitConversion/bitfield-conversion.c`

>From c782d7d15788f87a850d29e770042f86c939185b Mon Sep 17 00:00:00 2001
From: Zonotora 
Date: Thu, 4 Apr 2024 20:27:14 +0200
Subject: [PATCH] Fix "[clang][UBSan] Add implicit conversion check for
 bitfields"

---
 clang/docs/ReleaseNotes.rst   |   7 +
 clang/docs/UndefinedBehaviorSanitizer.rst |  19 +-
 clang/include/clang/Basic/Sanitizers.def  |  20 +-
 clang/lib/CodeGen/CGExpr.cpp  |  37 +-
 clang/lib/CodeGen/CGExprScalar.cpp| 264 +++-
 clang/lib/CodeGen/CodeGenFunction.h   |  15 +
 .../test/CodeGen/ubsan-bitfield-conversion.c  |  61 ++
 .../CodeGenCXX/ubsan-bitfield-conversion.cpp  |  94 +++
 clang/test/Driver/fsanitize.c |  28 +-
 compiler-rt/lib/ubsan/ubsan_handlers.cpp  |  27 +-
 compiler-rt/lib/ubsan/ubsan_handlers.h|   1 +
 .../ImplicitConversion/bitfield-conversion.c  | 641 ++
 12 files changed, 1139 insertions(+), 75 deletions(-)
 create mode 100644 clang/test/CodeGen/ubsan-bitfield-conversion.c
 create mode 100644 clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp
 create mode 100644 
compiler-rt/test/ubsan/TestCases/ImplicitConversion/bitfield-conversion.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 28e8ddb3c41c3e9..abf15c8dc49d9e7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -198,6 +198,10 @@ Non-comprehensive list of changes in this release
 
 New Compiler Flags
 --
+- ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and
+  sign change.
+- ``-fsanitize=implicit-integer-conversion`` a group that replaces the previous
+  group ``-fsanitize=implicit-conversion``.
 
 - ``-Wmissing-designated-field-initializers``, grouped under 
``-Wmissing-field-initializers``.
   This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
@@ -211,6 +215,9 @@ Modified Compiler Flags
 - Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under
   ``-Wreturn-type``, and moved some of the diagnostics previously controlled by
   ``-Wreturn-type`` under this new flag. Fixes #GH72116.
+- ``-fsanitize=implicit-conversion`` is now a group for both
+  ``-fsanitize=implicit-integer-conversion`` and
+  ``-fsanitize=implicit-bitfield-conversion``.
 
 - Added ``-Wcast-function-type-mismatch`` under the ``-Wcast-function-type``
   warning group. Moved the diagnostic previously controlled by
diff --git a/clang/docs/UndefinedBehaviorSanitizer.rst 
b/clang/docs/UndefinedBehaviorSanitizer.rst
index 8f58c92bd2a1634..531d56e313826c7 100644
--- a/clang/docs/UndefinedBehaviorSanitizer.rst
+++ b/clang/docs/UndefinedBehaviorSanitizer.rst
@@ -148,6 +148,11 @@ Available checks are:
  Issues caught by this sanitizer are not undefined behavior,
  but are often unintentional.
   -  ``-fsanitize=integer-divide-by-zero``: Integer division by zero.
+  -  ``-fsanitize=implicit-bitfield-conversion``: Implicit conversion from
+ integer of larger bit width to smaller bitfield, if that results in data
+ loss. This includes unsigned/signed truncations and sign changes, 
similarly
+ to how the ``-fsanitize=implicit-integer-conversion`` group works, but
+ explicitly for bitfields.
   -  ``-fsanitize=nonnull-attribute``: Passing null pointer as a function
  parameter which is declared to never be null.
   -  ``-fsanitize=null``: Use of a null pointer or creation of a null
@@ -193,8 +198,8 @@ Available checks are:
  signed division overflow (``INT_MIN/-1``). Note that checks are still
  added even when ``-fwrapv`` is enabled. This sanitizer does not check for
  lossy implicit conversions performed before the computation (see
- ``-fsanitize=implicit-conversion``). Both of these two issues are handled
- by ``-fsanitize=implicit-conversion`` group of checks.
+ ``-fsanitize=implicit-intege

[clang] [compiler-rt] Fix "[clang][UBSan] Add implicit conversion check for bitfields" (PR #87761)

2024-04-05 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Axel Lundberg (Zonotora)


Changes

Fix since #75481 got reverted.

- Explicitly set BitfieldBits to 0 to avoid uninitialized field member for the 
integer checks:
```diff
-   llvm::ConstantInt::get(Builder.getInt8Ty(), Check.first)};
+  llvm::ConstantInt::get(Builder.getInt8Ty(), Check.first),
+  llvm::ConstantInt::get(Builder.getInt32Ty(), 0)};
```
- `Value **Previous` was erroneously `Value *Previous` in 
`CodeGenFunction::EmitWithOriginalRHSBitfieldAssignment`, fixed now.
- Assert instead of check:
```diff
- if (Kind == CK_IntegralCast) {
+assert(Kind == CK_IntegralCast || Kind == CK_LValueToRValue &&
+ "Should be either CK_IntegralCast or CK_LValueToRValue");
```
CK_LValueToRValue when going from, e.g., char to char, and CK_IntegralCast 
otherwise.
- Make sure that `Value *Previous = nullptr;` is initialized (see 
https://github.com/llvm/llvm-project/commit/1189e87951e59a81ee097eae847c06008276fef1)
- Add another extensive testcase 
`ubsan/TestCases/ImplicitConversion/bitfield-conversion.c`

---

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


12 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+7) 
- (modified) clang/docs/UndefinedBehaviorSanitizer.rst (+14-5) 
- (modified) clang/include/clang/Basic/Sanitizers.def (+10-10) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+35-2) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+230-34) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+15) 
- (added) clang/test/CodeGen/ubsan-bitfield-conversion.c (+61) 
- (added) clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp (+94) 
- (modified) clang/test/Driver/fsanitize.c (+14-14) 
- (modified) compiler-rt/lib/ubsan/ubsan_handlers.cpp (+17-10) 
- (modified) compiler-rt/lib/ubsan/ubsan_handlers.h (+1) 
- (added) 
compiler-rt/test/ubsan/TestCases/ImplicitConversion/bitfield-conversion.c 
(+641) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 28e8ddb3c41c3e9..abf15c8dc49d9e7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -198,6 +198,10 @@ Non-comprehensive list of changes in this release
 
 New Compiler Flags
 --
+- ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and
+  sign change.
+- ``-fsanitize=implicit-integer-conversion`` a group that replaces the previous
+  group ``-fsanitize=implicit-conversion``.
 
 - ``-Wmissing-designated-field-initializers``, grouped under 
``-Wmissing-field-initializers``.
   This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
@@ -211,6 +215,9 @@ Modified Compiler Flags
 - Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under
   ``-Wreturn-type``, and moved some of the diagnostics previously controlled by
   ``-Wreturn-type`` under this new flag. Fixes #GH72116.
+- ``-fsanitize=implicit-conversion`` is now a group for both
+  ``-fsanitize=implicit-integer-conversion`` and
+  ``-fsanitize=implicit-bitfield-conversion``.
 
 - Added ``-Wcast-function-type-mismatch`` under the ``-Wcast-function-type``
   warning group. Moved the diagnostic previously controlled by
diff --git a/clang/docs/UndefinedBehaviorSanitizer.rst 
b/clang/docs/UndefinedBehaviorSanitizer.rst
index 8f58c92bd2a1634..531d56e313826c7 100644
--- a/clang/docs/UndefinedBehaviorSanitizer.rst
+++ b/clang/docs/UndefinedBehaviorSanitizer.rst
@@ -148,6 +148,11 @@ Available checks are:
  Issues caught by this sanitizer are not undefined behavior,
  but are often unintentional.
   -  ``-fsanitize=integer-divide-by-zero``: Integer division by zero.
+  -  ``-fsanitize=implicit-bitfield-conversion``: Implicit conversion from
+ integer of larger bit width to smaller bitfield, if that results in data
+ loss. This includes unsigned/signed truncations and sign changes, 
similarly
+ to how the ``-fsanitize=implicit-integer-conversion`` group works, but
+ explicitly for bitfields.
   -  ``-fsanitize=nonnull-attribute``: Passing null pointer as a function
  parameter which is declared to never be null.
   -  ``-fsanitize=null``: Use of a null pointer or creation of a null
@@ -193,8 +198,8 @@ Available checks are:
  signed division overflow (``INT_MIN/-1``). Note that checks are still
  added even when ``-fwrapv`` is enabled. This sanitizer does not check for
  lossy implicit conversions performed before the computation (see
- ``-fsanitize=implicit-conversion``). Both of these two issues are handled
- by ``-fsanitize=implicit-conversion`` group of checks.
+ ``-fsanitize=implicit-integer-conversion``). Both of these two issues are 
handled
+ by ``-fsanitize=implicit-integer-conversion`` group of checks.
   -  ``-fsanitize=unreachable``: If control flow reaches an unreachable
  program point.
   -  ``-fsanitize=unsigned-integer-overflow``: Unsigned integer ov

[clang] [compiler-rt] Fix "[clang][UBSan] Add implicit conversion check for bitfields" (PR #87761)

2024-04-05 Thread Axel Lundberg via cfe-commits
https://github.com/Zonotora updated 
https://github.com/llvm/llvm-project/pull/87761

>From a2a1ba32654f6b4a6b3d85e7a8733c9f8bd1b5f7 Mon Sep 17 00:00:00 2001
From: Zonotora 
Date: Thu, 4 Apr 2024 20:27:14 +0200
Subject: [PATCH] Fix "[clang][UBSan] Add implicit conversion check for
 bitfields"

---
 clang/docs/ReleaseNotes.rst   |   7 +
 clang/docs/UndefinedBehaviorSanitizer.rst |  19 +-
 clang/include/clang/Basic/Sanitizers.def  |  20 +-
 clang/lib/CodeGen/CGExpr.cpp  |  37 +-
 clang/lib/CodeGen/CGExprScalar.cpp| 265 +++-
 clang/lib/CodeGen/CodeGenFunction.h   |  15 +
 .../test/CodeGen/ubsan-bitfield-conversion.c  |  61 ++
 .../CodeGenCXX/ubsan-bitfield-conversion.cpp  |  94 +++
 clang/test/Driver/fsanitize.c |  28 +-
 compiler-rt/lib/ubsan/ubsan_handlers.cpp  |  27 +-
 compiler-rt/lib/ubsan/ubsan_handlers.h|   1 +
 .../ImplicitConversion/bitfield-conversion.c  | 639 ++
 12 files changed, 1138 insertions(+), 75 deletions(-)
 create mode 100644 clang/test/CodeGen/ubsan-bitfield-conversion.c
 create mode 100644 clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp
 create mode 100644 
compiler-rt/test/ubsan/TestCases/ImplicitConversion/bitfield-conversion.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 28e8ddb3c41c3e9..abf15c8dc49d9e7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -198,6 +198,10 @@ Non-comprehensive list of changes in this release
 
 New Compiler Flags
 --
+- ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and
+  sign change.
+- ``-fsanitize=implicit-integer-conversion`` a group that replaces the previous
+  group ``-fsanitize=implicit-conversion``.
 
 - ``-Wmissing-designated-field-initializers``, grouped under 
``-Wmissing-field-initializers``.
   This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
@@ -211,6 +215,9 @@ Modified Compiler Flags
 - Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under
   ``-Wreturn-type``, and moved some of the diagnostics previously controlled by
   ``-Wreturn-type`` under this new flag. Fixes #GH72116.
+- ``-fsanitize=implicit-conversion`` is now a group for both
+  ``-fsanitize=implicit-integer-conversion`` and
+  ``-fsanitize=implicit-bitfield-conversion``.
 
 - Added ``-Wcast-function-type-mismatch`` under the ``-Wcast-function-type``
   warning group. Moved the diagnostic previously controlled by
diff --git a/clang/docs/UndefinedBehaviorSanitizer.rst 
b/clang/docs/UndefinedBehaviorSanitizer.rst
index 8f58c92bd2a1634..531d56e313826c7 100644
--- a/clang/docs/UndefinedBehaviorSanitizer.rst
+++ b/clang/docs/UndefinedBehaviorSanitizer.rst
@@ -148,6 +148,11 @@ Available checks are:
  Issues caught by this sanitizer are not undefined behavior,
  but are often unintentional.
   -  ``-fsanitize=integer-divide-by-zero``: Integer division by zero.
+  -  ``-fsanitize=implicit-bitfield-conversion``: Implicit conversion from
+ integer of larger bit width to smaller bitfield, if that results in data
+ loss. This includes unsigned/signed truncations and sign changes, 
similarly
+ to how the ``-fsanitize=implicit-integer-conversion`` group works, but
+ explicitly for bitfields.
   -  ``-fsanitize=nonnull-attribute``: Passing null pointer as a function
  parameter which is declared to never be null.
   -  ``-fsanitize=null``: Use of a null pointer or creation of a null
@@ -193,8 +198,8 @@ Available checks are:
  signed division overflow (``INT_MIN/-1``). Note that checks are still
  added even when ``-fwrapv`` is enabled. This sanitizer does not check for
  lossy implicit conversions performed before the computation (see
- ``-fsanitize=implicit-conversion``). Both of these two issues are handled
- by ``-fsanitize=implicit-conversion`` group of checks.
+ ``-fsanitize=implicit-integer-conversion``). Both of these two issues are 
handled
+ by ``-fsanitize=implicit-integer-conversion`` group of checks.
   -  ``-fsanitize=unreachable``: If control flow reaches an unreachable
  program point.
   -  ``-fsanitize=unsigned-integer-overflow``: Unsigned integer overflow, where
@@ -202,7 +207,7 @@ Available checks are:
  type. Unlike signed integer overflow, this is not undefined behavior, but
  it is often unintentional. This sanitizer does not check for lossy 
implicit
  conversions performed before such a computation
- (see ``-fsanitize=implicit-conversion``).
+ (see ``-fsanitize=implicit-integer-conversion``).
   -  ``-fsanitize=vla-bound``: A variable-length array whose bound
  does not evaluate to a positive value.
   -  ``-fsanitize=vptr``: Use of an object whose vptr indicates that it is of
@@ -224,11 +229,15 @@ You can also use the following check groups:
   -  ``-fsanitize=implicit-integer-arithmetic-value-change``: Catches implicit
  

[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-05 Thread Charalampos Mitrodimas via cfe-commits
https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From c0ef5a06026d449aadfadca9948d148b25d1 Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

Warning '-Wundefined-func-template' incorrectly indicates that no
definition is available for a pure virtual function. However, a
definition is not needed for a pure virtual function.

Fixes #74016

Signed-off-by: Charalampos Mitrodimas 
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/lib/Sema/SemaExpr.cpp   |  8 ++-
 .../instantiate-pure-virtual-function.cpp | 67 +++
 3 files changed, 76 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 28e8ddb3c41c3e..15738b3fa03739 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -346,6 +346,10 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+- Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
+  functions.
+  (`#74016 `_)
+
 - Fixed missing warnings when comparing mismatched enumeration constants
   in C (`#29217 `).
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6b2eb245d58263..932c2c5a123a8d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18980,10 +18980,12 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   // Note that we skip the implicit instantiation of templates that are only
   // used in unused default arguments or by recursive calls to themselves.
   // This is formally non-conforming, but seems reasonable in practice.
-  bool NeedDefinition = !IsRecursiveCall && (OdrUse == OdrUseContext::Used ||
- NeededForConstantEvaluation);
+  bool NeedDefinition =
+  !IsRecursiveCall &&
+  (OdrUse == OdrUseContext::Used ||
+   (NeededForConstantEvaluation && !Func->isPureVirtual()));
 
-  // C++14 [temp.expl.spec]p6:
+  // C++14 [temp.expl.spec]p6:a
   //   If a template [...] is explicitly specialized then that specialization
   //   shall be declared before the first use of that specialization that would
   //   cause an implicit instantiation to take place, in every translation unit
diff --git a/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp 
b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
new file mode 100644
index 00..caec42b6b77f95
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+
+namespace GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};
+
+namespace call_pure_virtual_function_from_virtual {
+  template  class B {
+  public:
+const void foo(const T &) { B::bar(1); } // expected-warning 
{{instantiation of function 
'call_pure_virtual_function_from_virtual::B::bar' required here, but no 
definition is available}}
+// expected-note@-1 {{add an explicit instantiation declaration to 
suppress this warning if 'call_pure_virtual_function_from_virtual::B::bar' 
is explicitly instantiated in another translation unit}}
+virtual const void bar(unsigned int) = 0; // expected-note {{forward 
declaration of template entity is here}}
+  };
+
+  template  class D : public B {
+  public:
+const void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0); // expected-note {{in instantiation of member function 
'call_pure_virtual_function_from_virtual::B::foo' requested here}}
+  }
+};
+
+namespace non_pure_virtual_function {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+
+virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
+// expected-note@-1 {{forward declaration of template entity is here}}
+// expected-note@-2 {{forward declaration of template entity is here}}
+// expected-note@-3 {{forward declaration of template entity is here}}
+  };
+
+  template  class D : public B { // expected-warning 
{{instantiation of function 'non_pure_virtual_function::B::bar' required 
here, but no definition is available}}
+// expected-warning@-1 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available

[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread Julian Nagele via cfe-commits

@@ -319,7 +320,10 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0

juliannagele wrote:

Agreed, and that's what I had originally, but then saw 
https://github.com/llvm/llvm-project/blob/0b7362c257ff7b656c31266b4f9b8485a7ba4033/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp#L759
 so thought I'd go with the same structure, but no strong feelings either way.

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


[clang] [NFC] Remove semicolons after function definitions (PR #87764)

2024-04-05 Thread via cfe-commits
https://github.com/NagyDonat created 
https://github.com/llvm/llvm-project/pull/87764

They were accidentally left behind when
https://github.com/llvm/llvm-project/pull/86536 converted some lambdas into 
stand-alone methods.

This fixes warnings from -Wc++98-compat-extra-semi

>From 77e472432c524a365f7a92d2edb3a53095e46ce3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Fri, 5 Apr 2024 11:56:47 +0200
Subject: [PATCH] [NFC] Remove semicolons after function definitions

They were accidentally left behind when
https://github.com/llvm/llvm-project/pull/86536 converted some lambdas
into stand-alone methods.

This fixes warnings from -Wc++98-compat-extra-semi
---
 clang/lib/StaticAnalyzer/Core/CallDescription.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/CallDescription.cpp 
b/clang/lib/StaticAnalyzer/Core/CallDescription.cpp
index dcf6a2625b66f4..0bb0fe66e54ff8 100644
--- a/clang/lib/StaticAnalyzer/Core/CallDescription.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallDescription.cpp
@@ -89,7 +89,7 @@ bool ento::CallDescription::matchNameOnly(const NamedDecl 
*ND) const {
   // FIXME This comparison is way SLOWER than comparing pointers.
   // At some point in the future, we should compare FunctionDecl pointers.
   return Name.getAsString() == getFunctionName();
-};
+}
 
 bool ento::CallDescription::matchQualifiedNameParts(const Decl *D) const {
   const auto FindNextNamespaceOrRecord =
@@ -115,7 +115,7 @@ bool ento::CallDescription::matchQualifiedNameParts(const 
Decl *D) const {
 
   // We matched if we consumed all expected qualifier segments.
   return QualifierPartsIt == QualifierPartsEndIt;
-};
+}
 
 bool ento::CallDescription::matchesImpl(const FunctionDecl *FD, size_t 
ArgCount,
 size_t ParamCount) const {

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


[clang] [NFC] Remove semicolons after function definitions (PR #87764)

2024-04-05 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: None (NagyDonat)


Changes

They were accidentally left behind when
https://github.com/llvm/llvm-project/pull/86536 converted some lambdas into 
stand-alone methods.

This fixes warnings from -Wc++98-compat-extra-semi

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


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/CallDescription.cpp (+2-2) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Core/CallDescription.cpp 
b/clang/lib/StaticAnalyzer/Core/CallDescription.cpp
index dcf6a2625b66f4..0bb0fe66e54ff8 100644
--- a/clang/lib/StaticAnalyzer/Core/CallDescription.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallDescription.cpp
@@ -89,7 +89,7 @@ bool ento::CallDescription::matchNameOnly(const NamedDecl 
*ND) const {
   // FIXME This comparison is way SLOWER than comparing pointers.
   // At some point in the future, we should compare FunctionDecl pointers.
   return Name.getAsString() == getFunctionName();
-};
+}
 
 bool ento::CallDescription::matchQualifiedNameParts(const Decl *D) const {
   const auto FindNextNamespaceOrRecord =
@@ -115,7 +115,7 @@ bool ento::CallDescription::matchQualifiedNameParts(const 
Decl *D) const {
 
   // We matched if we consumed all expected qualifier segments.
   return QualifierPartsIt == QualifierPartsEndIt;
-};
+}
 
 bool ento::CallDescription::matchesImpl(const FunctionDecl *FD, size_t 
ArgCount,
 size_t ParamCount) const {

``




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


[clang] 9a16c12 - [NFC] Remove semicolons after function definitions (#87764)

2024-04-05 Thread via cfe-commits
Author: NagyDonat
Date: 2024-04-05T12:01:43+02:00
New Revision: 9a16c12abe13a06470502370833e7c0e6ff70e2c

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

LOG: [NFC] Remove semicolons after function definitions (#87764)

They were accidentally left behind when
https://github.com/llvm/llvm-project/pull/86536 converted some lambdas
into stand-alone methods.

This fixes warnings from -Wc++98-compat-extra-semi

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/CallDescription.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/CallDescription.cpp 
b/clang/lib/StaticAnalyzer/Core/CallDescription.cpp
index dcf6a2625b66f4..0bb0fe66e54ff8 100644
--- a/clang/lib/StaticAnalyzer/Core/CallDescription.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallDescription.cpp
@@ -89,7 +89,7 @@ bool ento::CallDescription::matchNameOnly(const NamedDecl 
*ND) const {
   // FIXME This comparison is way SLOWER than comparing pointers.
   // At some point in the future, we should compare FunctionDecl pointers.
   return Name.getAsString() == getFunctionName();
-};
+}
 
 bool ento::CallDescription::matchQualifiedNameParts(const Decl *D) const {
   const auto FindNextNamespaceOrRecord =
@@ -115,7 +115,7 @@ bool ento::CallDescription::matchQualifiedNameParts(const 
Decl *D) const {
 
   // We matched if we consumed all expected qualifier segments.
   return QualifierPartsIt == QualifierPartsEndIt;
-};
+}
 
 bool ento::CallDescription::matchesImpl(const FunctionDecl *FD, size_t 
ArgCount,
 size_t ParamCount) const {



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


[clang] [NFC] Remove semicolons after function definitions (PR #87764)

2024-04-05 Thread via cfe-commits
https://github.com/NagyDonat closed 
https://github.com/llvm/llvm-project/pull/87764
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-05 Thread Charalampos Mitrodimas via cfe-commits

@@ -18931,7 +18931,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   //   constant evaluated
   bool NeededForConstantEvaluation =
   isPotentiallyConstantEvaluatedContext(*this) &&
-  isImplicitlyDefinableConstexprFunction(Func);
+  isImplicitlyDefinableConstexprFunction(Func) && !Func->isPure();

charmitro wrote:

You're actually right. 

I don't really recall what I was entering back when I was developing it, but it 
should work now.

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


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-05 Thread Charalampos Mitrodimas via cfe-commits
https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From 0348c138e5a4295d86defbe40259105b64703d13 Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

Warning '-Wundefined-func-template' incorrectly indicates that no
definition is available for a pure virtual function. However, a
definition is not needed for a pure virtual function.

Fixes #74016

Signed-off-by: Charalampos Mitrodimas 
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/lib/Sema/SemaExpr.cpp   |  6 +-
 .../instantiate-pure-virtual-function.cpp | 67 +++
 3 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 28e8ddb3c41c3e..15738b3fa03739 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -346,6 +346,10 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+- Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
+  functions.
+  (`#74016 `_)
+
 - Fixed missing warnings when comparing mismatched enumeration constants
   in C (`#29217 `).
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6b2eb245d58263..33f8a7fdb4d903 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18980,8 +18980,10 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   // Note that we skip the implicit instantiation of templates that are only
   // used in unused default arguments or by recursive calls to themselves.
   // This is formally non-conforming, but seems reasonable in practice.
-  bool NeedDefinition = !IsRecursiveCall && (OdrUse == OdrUseContext::Used ||
- NeededForConstantEvaluation);
+  bool NeedDefinition =
+  !IsRecursiveCall &&
+  (OdrUse == OdrUseContext::Used ||
+   (NeededForConstantEvaluation && !Func->isPureVirtual()));
 
   // C++14 [temp.expl.spec]p6:
   //   If a template [...] is explicitly specialized then that specialization
diff --git a/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp 
b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
new file mode 100644
index 00..caec42b6b77f95
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+
+namespace GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};
+
+namespace call_pure_virtual_function_from_virtual {
+  template  class B {
+  public:
+const void foo(const T &) { B::bar(1); } // expected-warning 
{{instantiation of function 
'call_pure_virtual_function_from_virtual::B::bar' required here, but no 
definition is available}}
+// expected-note@-1 {{add an explicit instantiation declaration to 
suppress this warning if 'call_pure_virtual_function_from_virtual::B::bar' 
is explicitly instantiated in another translation unit}}
+virtual const void bar(unsigned int) = 0; // expected-note {{forward 
declaration of template entity is here}}
+  };
+
+  template  class D : public B {
+  public:
+const void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0); // expected-note {{in instantiation of member function 
'call_pure_virtual_function_from_virtual::B::foo' requested here}}
+  }
+};
+
+namespace non_pure_virtual_function {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+
+virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
+// expected-note@-1 {{forward declaration of template entity is here}}
+// expected-note@-2 {{forward declaration of template entity is here}}
+// expected-note@-3 {{forward declaration of template entity is here}}
+  };
+
+  template  class D : public B { // expected-warning 
{{instantiation of function 'non_pure_virtual_function::B::bar' required 
here, but no definition is available}}
+// expected-warning@-1 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-warning@-2 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-note@-3 {{add an explicit instantiation dec

[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread via cfe-commits

@@ -319,7 +320,10 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0

dobbelaj-snps wrote:

I see. Then it might make sense to keep what you did, but add a comment 
referring to that function ? It does has a lot more comments on what is going 
on there. 


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


[clang] [llvm] Remove remaining uses of Instruction-constructors that insert before another Instruction (PR #85981)

2024-04-05 Thread Stephen Tozer via cfe-commits
https://github.com/SLTozer updated 
https://github.com/llvm/llvm-project/pull/85981

>From b2f6d93d87082dd0ccc91a9a8094a4c3552b81a2 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Wed, 20 Mar 2024 17:43:10 +
Subject: [PATCH] Assorted fixes since rebase and outside core llvm

---
 clang/lib/CodeGen/CGCUDANV.cpp|  6 +-
 clang/lib/CodeGen/CGCall.cpp  |  4 +-
 clang/lib/CodeGen/CGCleanup.cpp   |  8 ++-
 clang/lib/CodeGen/CGCoroutine.cpp |  5 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGObjC.cpp  |  3 +-
 clang/lib/CodeGen/CodeGenFunction.h   |  4 +-
 clang/lib/CodeGen/CodeGenModule.cpp   | 10 +--
 llvm/examples/IRTransforms/SimplifyCFG.cpp|  7 +-
 llvm/include/llvm/IR/InstrTypes.h |  9 ---
 llvm/lib/FuzzMutate/IRMutator.cpp |  5 +-
 llvm/lib/FuzzMutate/Operations.cpp| 32 ++
 llvm/lib/FuzzMutate/RandomIRBuilder.cpp   | 17 ++---
 .../Instrumentation/AddressSanitizer.cpp  |  4 +-
 .../deltas/ReduceOperandBundles.cpp   |  3 +-
 llvm/tools/llvm-stress/llvm-stress.cpp| 64 ++-
 16 files changed, 98 insertions(+), 85 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 0cb5b06a519c00..13660fcd69b465 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -484,9 +484,9 @@ static void replaceManagedVar(llvm::GlobalVariable *Var,
 }
 if (auto *I = dyn_cast(U)) {
   llvm::Value *OldV = Var;
-  llvm::Instruction *NewV =
-  new llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,
- llvm::Align(Var->getAlignment()), I);
+  llvm::Instruction *NewV = new llvm::LoadInst(
+  Var->getType(), ManagedVar, "ld.managed", false,
+  llvm::Align(Var->getAlignment()), I->getIterator());
   WorkItem.pop_back();
   // Replace constant expressions directly or indirectly using the managed
   // variable with instructions.
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index f12765b826935b..3c8c3fe9f5e6e8 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5062,8 +5062,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 llvm::AllocaInst *AI;
 if (IP) {
   IP = IP->getNextNode();
-  AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(),
-"argmem", IP);
+  AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(), "argmem",
+IP->getIterator());
 } else {
   AI = CreateTempAlloca(ArgStruct, "argmem");
 }
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index e6f8e6873004f2..3cd540c65d3b34 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -295,7 +295,8 @@ void EHScopeStack::Cleanup::anchor() {}
 static void createStoreInstBefore(llvm::Value *value, Address addr,
   llvm::Instruction *beforeInst,
   CodeGenFunction &CGF) {
-  auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF), 
beforeInst);
+  auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF),
+   beforeInst->getIterator());
   store->setAlignment(addr.getAlignment().getAsAlign());
 }
 
@@ -304,7 +305,7 @@ static llvm::LoadInst *createLoadInstBefore(Address addr, 
const Twine &name,
 CodeGenFunction &CGF) {
   return new llvm::LoadInst(addr.getElementType(), addr.emitRawPointer(CGF),
 name, false, addr.getAlignment().getAsAlign(),
-beforeInst);
+beforeInst->getIterator());
 }
 
 /// All the branch fixups on the EH stack have propagated out past the
@@ -612,7 +613,8 @@ static void destroyOptimisticNormalEntry(CodeGenFunction 
&CGF,
 llvm::SwitchInst *si = cast(use.getUser());
 if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) {
   // Replace the switch with a branch.
-  llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(), si);
+  llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(),
+   si->getIterator());
 
   // The switch operand is a load from the cleanup-dest alloca.
   llvm::LoadInst *condition = cast(si->getCondition());
diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 93ca711f716fce..fcad59bb05c728 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -867,8 +867,9 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt &S) {
 EmitStmt(S.getPromiseDeclStmt());
 
 Address PromiseAddr = GetAddrOfLocalVar(S.getPromiseDecl());
-auto *

[clang] Rework the printing of attributes (PR #87281)

2024-04-05 Thread Vassil Vassilev via cfe-commits

@@ -73,3 +73,15 @@ class C {
   // CHECK: void pwtt(void *, int) __attribute__((pointer_with_type_tag(foo, 
2, 3)));
   void pwtt(void *, int) __attribute__((pointer_with_type_tag(foo, 2, 3)));
 };
+
+#define ANNOTATE_ATTR __attribute__((annotate("Annotated")))
+ANNOTATE_ATTR int annotated_attr ANNOTATE_ATTR = 0;
+// CHECK: __attribute__((annotate("Annotated"))) int annotated_attr 
__attribute__((annotate("Annotated"))) = 0;
+
+// FIXME: We do not print the attribute as written after the type specifier.
+int ANNOTATE_ATTR annotated_attr_fixme = 0;

vgvassilev wrote:

Is that something this PR breaks? I am not sure I understand if I need to 
change anything. 

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


[clang] [clang][Sema] Avoid guessing unexpanded packs' size in getFullyPackExpandedSize (PR #87768)

2024-04-05 Thread Younan Zhang via cfe-commits
https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/87768

None

>From eb6c961896646a62f334284093994160d8c0e38e Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 5 Apr 2024 19:12:28 +0800
Subject: [PATCH] [clang][Sema] Avoid guessing unexpanded packs' size in
 getFullyPackExpandedSize

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

diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 903fbfd18e779c..f26771c64074b3 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1243,7 +1243,10 @@ std::optional 
Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
 // expanded this pack expansion into the enclosing pack if we could.
 if (Elem.isPackExpansion())
   return std::nullopt;
+if (Elem.containsUnexpandedParameterPack())
+  return std::nullopt;
   }
+  // llvm::errs() << "Optimization takes effect: " << Pack.pack_size() << "\n";
   return Pack.pack_size();
 }
 

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


[clang] Fix formatting of a comment; NFC (PR #87739)

2024-04-05 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman edited 
https://github.com/llvm/llvm-project/pull/87739
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix formatting of a comment; NFC (PR #87739)

2024-04-05 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman approved this pull request.

LGTM, thank you for the cleanup!

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


[clang] 2c0a99f - Fix formatting of a comment; NFC (#87739)

2024-04-05 Thread via cfe-commits
Author: AX网
Date: 2024-04-05T07:40:36-04:00
New Revision: 2c0a99f54fd5045a1b382c03fc5481b648a62a8e

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

LOG: Fix formatting of a comment; NFC (#87739)

Added: 


Modified: 
clang/include/clang/Lex/Token.h

Removed: 




diff  --git a/clang/include/clang/Lex/Token.h b/clang/include/clang/Lex/Token.h
index 36ec5ddaa29adb..4f29fb7d114159 100644
--- a/clang/include/clang/Lex/Token.h
+++ b/clang/include/clang/Lex/Token.h
@@ -58,7 +58,7 @@ class Token {
   ///  Annotations (resolved type names, C++ scopes, etc): isAnnotation().
   ///This is a pointer to sema-specific data for the annotation token.
   ///  Eof:
-  // This is a pointer to a Decl.
+  ///This is a pointer to a Decl.
   ///  Other:
   ///This is null.
   void *PtrData;



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


[clang] Fix formatting of a comment; NFC (PR #87739)

2024-04-05 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman closed 
https://github.com/llvm/llvm-project/pull/87739
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix formatting of a comment; NFC (PR #87739)

2024-04-05 Thread via cfe-commits
github-actions[bot] wrote:



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

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

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

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

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

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


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


[clang] [flang] [FLANG] allow -fopenmp= (PR #86816)

2024-04-05 Thread Tom Eccles via cfe-commits
https://github.com/tblah approved this pull request.

Thanks! LGTM

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


[clang] [clang] Reject VLAs in `__is_layout_compatible()` (PR #87737)

2024-04-05 Thread Aaron Ballman via cfe-commits
AaronBallman wrote:

> We should not reject (ie, make the programm ill-form) _any_ type. Just return 
> `false` in all of these cases

GCC rejects incomplete types: https://godbolt.org/z/xWbes5Wsc
Both Clang and GCC reject instantiating templates with VLAs but accept it in 
the builtin: https://godbolt.org/z/b95GEGcGx
Both Clang and GCC accept flexible arrays: https://godbolt.org/z/fWbfExMTb

I think the behavior from GCC is defensible, so I think we should reject 
incomplete types, but accept flexible arrays. VLAs I'm ambivalent about because 
of the template instantiation behavior. CC @ldionne @philnik777 @mordante for 
libc++ perspective.

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


[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

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

@@ -358,3 +399,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 endif()
   endforeach( d )
 endforeach( t )
+
+if( NOT LIBCLC_STANDALONE_BUILD )
+  add_subdirectory( test )

rjodinchr wrote:

There is no `CMakeLists.txt` in `/llvm/libclc/test`.

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


[clang] [clang] Reject VLAs in `__is_layout_compatible()` (PR #87737)

2024-04-05 Thread via cfe-commits
cor3ntin wrote:

The library does require complete types, interesting 
https://eel.is/c++draft/meta 
However, at the language level, I cannot find any wording either way.

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


[clang] [clang] Reject VLAs in `__is_layout_compatible()` (PR #87737)

2024-04-05 Thread Nikolas Klauser via cfe-commits
philnik777 wrote:

I think clang should reject incomplete types when the standard says so. It 
doesn't seem particularly useful to accept some special cases but reject 
incomplete types in general. All the traits should probably be audited once. It 
looks like Clang has other problematic cases: https://godbolt.org/z/hajWfq7a6

I don't really care whether Clang should reject VLAs when using the builtin, 
since the trait will be used through some template and that's rejected that 
anyways. FWIW it'd be more consistent, since in my mind `__some_type_trait(T, 
U)` behaves the same as `std::some_type_trait_v`.

Flexible arrays are accepted because they are arrays of unknown bounds in the 
type system, which is part of the standard. The extension is only that they 
aren't rejected at the end of a struct and have some special meaning there. 
They should definitely not be rejected.


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


[clang] [llvm] [OpenMP] Add amdgpu-num-work-groups attribute to OpenMP kernels (PR #87695)

2024-04-05 Thread Joseph Huber via cfe-commits
https://github.com/jhuber6 closed 
https://github.com/llvm/llvm-project/pull/87695
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Reject VLAs in `__is_layout_compatible()` (PR #87737)

2024-04-05 Thread Vlad Serebrennikov via cfe-commits
Endilll wrote:

> However, at the language level, I cannot find any wording either way.

In my reading, http://eel.is/c++draft/basic.types.general#11 makes any type 
layout-compatible with itself, and even ignores cv-qualification:

> Two types cv1 T1 and cv2 T2 are [layout-compatible 
> types](http://eel.is/c++draft/basic.types.general#def:type,layout-compatible) 
> if T1 and T2 are the same type, [layout-compatible 
> enumerations](http://eel.is/c++draft/dcl.enum#def:layout-compatible,enumeration),
>  or [layout-compatible standard-layout class 
> types](http://eel.is/c++draft/class.mem#def:layout-compatible,class)[.](http://eel.is/c++draft/basic.types.general#11.sentence-1)

I find the gap between core language term and type trait rather unfortunate.

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


[clang] 2650375 - [OpenMP] Add amdgpu-num-work-groups attribute to OpenMP kernels (#87695)

2024-04-05 Thread via cfe-commits
Author: Joseph Huber
Date: 2024-04-05T07:38:01-05:00
New Revision: 2650375b3beeb60596ca38e2e06685e48e8ed01f

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

LOG: [OpenMP] Add amdgpu-num-work-groups attribute to OpenMP kernels (#87695)

Summary:
This new attribute was introduced recently. We already do this for NVPTX
kernels so we should apply this for AMDGPU as well. This patch simply
applies this metadata in cases where a lower bound is known

Added: 
clang/test/OpenMP/thread_limit_amdgpu.c

Modified: 
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Removed: 




diff  --git a/clang/test/OpenMP/thread_limit_amdgpu.c 
b/clang/test/OpenMP/thread_limit_amdgpu.c
new file mode 100644
index 00..f884eeb73c3ff1
--- /dev/null
+++ b/clang/test/OpenMP/thread_limit_amdgpu.c
@@ -0,0 +1,34 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux-gnu 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-x86-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple amdgcn-amd-amdhsa 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-target-device 
-fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+void foo(int N) {
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < N; ++i)
+;
+#pragma omp target teams distribute parallel for simd thread_limit(4)
+  for (int i = 0; i < N; ++i)
+;
+#pragma omp target teams distribute parallel for simd 
ompx_attribute(__attribute__((launch_bounds(42, 42
+  for (int i = 0; i < N; ++i)
+;
+#pragma omp target teams distribute parallel for simd 
ompx_attribute(__attribute__((launch_bounds(42, 42 num_threads(22)
+  for (int i = 0; i < N; ++i)
+;
+}
+
+#endif
+
+// CHECK: define weak_odr protected amdgpu_kernel void 
@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+__Z3fooi_}}l10({{.*}}) #[[ATTR1:.+]] {
+// CHECK: define weak_odr protected amdgpu_kernel void 
@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+__Z3fooi_}}l13({{.*}}) #[[ATTR2:.+]] {
+// CHECK: define weak_odr protected amdgpu_kernel void 
@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+__Z3fooi_}}l16({{.*}}) #[[ATTR3:.+]] {
+// CHECK: define weak_odr protected amdgpu_kernel void 
@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+__Z3fooi_}}l19({{.*}}) #[[ATTR4:.+]] {
+
+// CHECK: attributes #[[ATTR1]] = { {{.*}} 
"amdgpu-flat-work-group-size"="1,256" {{.*}} }
+// CHECK: attributes #[[ATTR2]] = { {{.*}} "amdgpu-flat-work-group-size"="1,4" 
{{.*}} }
+// CHECK: attributes #[[ATTR3]] = { {{.*}} 
"amdgpu-flat-work-group-size"="1,42" "amdgpu-max-num-workgroups"="42,1,1"{{.*}} 
}
+// CHECK: attributes #[[ATTR4]] = { {{.*}} 
"amdgpu-flat-work-group-size"="1,22" "amdgpu-max-num-workgroups"="42,1,1"{{.*}} 
}

diff  --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 16507a69ea8502..7fd8474c2ec890 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4791,6 +4791,9 @@ void OpenMPIRBuilder::writeTeamsForKernel(const Triple 
&T, Function &Kernel,
   updateNVPTXMetadata(Kernel, "maxclusterrank", UB, true);
 updateNVPTXMetadata(Kernel, "minctasm", LB, false);
   }
+  if (T.isAMDGPU())
+Kernel.addFnAttr("amdgpu-max-num-workgroups", llvm::utostr(LB) + ",1,1");
+
   Kernel.addFnAttr("omp_target_num_teams", std::to_string(LB));
 }
 



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


[clang] [clang][ExtractAPI] Fix handling of anonymous TagDecls (PR #87772)

2024-04-05 Thread Daniel Grumberg via cfe-commits
https://github.com/daniel-grumberg created 
https://github.com/llvm/llvm-project/pull/87772

This changes the handling of anonymous TagDecls to the following rules:
- If the TagDecl is embedded in the declaration for some VarDecl (this is the 
only possibility for RecordDecls), then pretend the child decls belong to the 
VarDecl
- If it's an EnumDecl proceed as we did previously, i.e., embed it in the 
enclosing DeclContext.

Additionally this fixes a few issues with declaration fragments not 
consistently including "{ ... }" for anonymous TagDecls. To make testing these 
additions easier this patch fixes some text declaration fragments merging 
issues and updates tests accordingly.

>From f2755070ead054c56f7e9f9a2084ec40c10968bf Mon Sep 17 00:00:00 2001
From: Daniel Grumberg 
Date: Thu, 4 Apr 2024 18:33:25 +0100
Subject: [PATCH] [clang][ExtractAPI] Fix handling of anonymous TagDecls

This changes the handling of anonymous TagDecls to the following rules:
- If the TagDecl is embedded in the declaration for some VarDecl (this
  is the only possibility for RecordDecls), then pretend the child decls
  belong to the VarDecl
- If it's an EnumDecl proceed as we did previously, i.e., embed it in
  the enclosing DeclContext.

Additionally this fixes a few issues with declaration fragments not
consistently including "{ ... }" for anonymous TagDecls. To make testing
these additions easier this patch fixes some text declaration fragments
merging issues and updates tests accordingly.
---
 clang/include/clang/ExtractAPI/API.h  | 132 ++--
 clang/include/clang/ExtractAPI/APIRecords.inc |  16 +-
 .../clang/ExtractAPI/DeclarationFragments.h   |  84 ++-
 .../clang/ExtractAPI/ExtractAPIVisitor.h  |  76 ++-
 clang/lib/ExtractAPI/API.cpp  |   8 +
 clang/lib/ExtractAPI/DeclarationFragments.cpp |  17 +-
 .../Serialization/SymbolGraphSerializer.cpp   |   8 +
 .../ExtractAPI/anonymous_record_no_typedef.c  | 565 +-
 clang/test/ExtractAPI/enum.c  |  12 +-
 clang/test/ExtractAPI/function_noexcepts.cpp  |  18 +-
 clang/test/ExtractAPI/methods.cpp |   6 +-
 clang/test/ExtractAPI/objc_block.m|  48 +-
 .../ExtractAPI/typedef_anonymous_record.c |   4 +-
 clang/test/ExtractAPI/typedef_struct_enum.c   |   2 +-
 14 files changed, 427 insertions(+), 569 deletions(-)

diff --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index 92cacf65c7d64e..05cfabd072a560 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -208,20 +208,20 @@ struct APIRecord {
 RK_ClassTemplate,
 RK_ClassTemplateSpecialization,
 RK_ClassTemplatePartialSpecialization,
-RK_LastRecordContext,
-RK_GlobalFunction,
-RK_GlobalFunctionTemplate,
-RK_GlobalFunctionTemplateSpecialization,
+RK_StructField,
+RK_UnionField,
+RK_CXXField,
+RK_StaticField,
+RK_CXXFieldTemplate,
 RK_GlobalVariable,
 RK_GlobalVariableTemplate,
 RK_GlobalVariableTemplateSpecialization,
 RK_GlobalVariableTemplatePartialSpecialization,
+RK_LastRecordContext,
+RK_GlobalFunction,
+RK_GlobalFunctionTemplate,
+RK_GlobalFunctionTemplateSpecialization,
 RK_EnumConstant,
-RK_StructField,
-RK_UnionField,
-RK_StaticField,
-RK_CXXField,
-RK_CXXFieldTemplate,
 RK_Concept,
 RK_CXXStaticMethod,
 RK_CXXInstanceMethod,
@@ -321,6 +321,8 @@ class RecordContext {
 
   RecordContext(APIRecord::RecordKind Kind) : Kind(Kind) {}
 
+  void stealRecordChain(RecordContext &Other);
+
   APIRecord::RecordKind getKind() const { return Kind; }
 
   struct record_iterator {
@@ -475,7 +477,7 @@ struct GlobalFunctionTemplateSpecializationRecord : 
GlobalFunctionRecord {
 };
 
 /// This holds information associated with global functions.
-struct GlobalVariableRecord : APIRecord {
+struct GlobalVariableRecord : APIRecord, RecordContext {
   GlobalVariableRecord(StringRef USR, StringRef Name, SymbolReference Parent,
PresumedLoc Loc, AvailabilityInfo Availability,
LinkageInfo Linkage, const DocComment &Comment,
@@ -483,23 +485,28 @@ struct GlobalVariableRecord : APIRecord {
DeclarationFragments SubHeading, bool 
IsFromSystemHeader)
   : APIRecord(RK_GlobalVariable, USR, Name, Parent, Loc,
   std::move(Availability), Linkage, Comment, Declaration,
-  SubHeading, IsFromSystemHeader) {}
+  SubHeading, IsFromSystemHeader),
+RecordContext(RK_GlobalVariable) {}
 
   GlobalVariableRecord(RecordKind Kind, StringRef USR, StringRef Name,
-   SymbolReference Parent,
-
-   PresumedLoc Loc, AvailabilityInfo Availability,
-   LinkageInfo Linkage, const DocComment &Comment,
+   SymbolReference Parent, PresumedLoc Loc,
+   AvailabilityInfo Availability, Li

[clang] [clang][ExtractAPI] Fix handling of anonymous TagDecls (PR #87772)

2024-04-05 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Daniel Grumberg (daniel-grumberg)


Changes

This changes the handling of anonymous TagDecls to the following rules:
- If the TagDecl is embedded in the declaration for some VarDecl (this is the 
only possibility for RecordDecls), then pretend the child decls belong to the 
VarDecl
- If it's an EnumDecl proceed as we did previously, i.e., embed it in the 
enclosing DeclContext.

Additionally this fixes a few issues with declaration fragments not 
consistently including "{ ... }" for anonymous TagDecls. To make testing these 
additions easier this patch fixes some text declaration fragments merging 
issues and updates tests accordingly.

---

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


14 Files Affected:

- (modified) clang/include/clang/ExtractAPI/API.h (+88-44) 
- (modified) clang/include/clang/ExtractAPI/APIRecords.inc (+14-2) 
- (modified) clang/include/clang/ExtractAPI/DeclarationFragments.h (+57-27) 
- (modified) clang/include/clang/ExtractAPI/ExtractAPIVisitor.h (+53-23) 
- (modified) clang/lib/ExtractAPI/API.cpp (+8) 
- (modified) clang/lib/ExtractAPI/DeclarationFragments.cpp (+13-4) 
- (modified) clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp (+8) 
- (modified) clang/test/ExtractAPI/anonymous_record_no_typedef.c (+165-400) 
- (modified) clang/test/ExtractAPI/enum.c (+6-6) 
- (modified) clang/test/ExtractAPI/function_noexcepts.cpp (+3-15) 
- (modified) clang/test/ExtractAPI/methods.cpp (+1-5) 
- (modified) clang/test/ExtractAPI/objc_block.m (+8-40) 
- (modified) clang/test/ExtractAPI/typedef_anonymous_record.c (+2-2) 
- (modified) clang/test/ExtractAPI/typedef_struct_enum.c (+1-1) 


``diff
diff --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index 92cacf65c7d64e..05cfabd072a560 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -208,20 +208,20 @@ struct APIRecord {
 RK_ClassTemplate,
 RK_ClassTemplateSpecialization,
 RK_ClassTemplatePartialSpecialization,
-RK_LastRecordContext,
-RK_GlobalFunction,
-RK_GlobalFunctionTemplate,
-RK_GlobalFunctionTemplateSpecialization,
+RK_StructField,
+RK_UnionField,
+RK_CXXField,
+RK_StaticField,
+RK_CXXFieldTemplate,
 RK_GlobalVariable,
 RK_GlobalVariableTemplate,
 RK_GlobalVariableTemplateSpecialization,
 RK_GlobalVariableTemplatePartialSpecialization,
+RK_LastRecordContext,
+RK_GlobalFunction,
+RK_GlobalFunctionTemplate,
+RK_GlobalFunctionTemplateSpecialization,
 RK_EnumConstant,
-RK_StructField,
-RK_UnionField,
-RK_StaticField,
-RK_CXXField,
-RK_CXXFieldTemplate,
 RK_Concept,
 RK_CXXStaticMethod,
 RK_CXXInstanceMethod,
@@ -321,6 +321,8 @@ class RecordContext {
 
   RecordContext(APIRecord::RecordKind Kind) : Kind(Kind) {}
 
+  void stealRecordChain(RecordContext &Other);
+
   APIRecord::RecordKind getKind() const { return Kind; }
 
   struct record_iterator {
@@ -475,7 +477,7 @@ struct GlobalFunctionTemplateSpecializationRecord : 
GlobalFunctionRecord {
 };
 
 /// This holds information associated with global functions.
-struct GlobalVariableRecord : APIRecord {
+struct GlobalVariableRecord : APIRecord, RecordContext {
   GlobalVariableRecord(StringRef USR, StringRef Name, SymbolReference Parent,
PresumedLoc Loc, AvailabilityInfo Availability,
LinkageInfo Linkage, const DocComment &Comment,
@@ -483,23 +485,28 @@ struct GlobalVariableRecord : APIRecord {
DeclarationFragments SubHeading, bool 
IsFromSystemHeader)
   : APIRecord(RK_GlobalVariable, USR, Name, Parent, Loc,
   std::move(Availability), Linkage, Comment, Declaration,
-  SubHeading, IsFromSystemHeader) {}
+  SubHeading, IsFromSystemHeader),
+RecordContext(RK_GlobalVariable) {}
 
   GlobalVariableRecord(RecordKind Kind, StringRef USR, StringRef Name,
-   SymbolReference Parent,
-
-   PresumedLoc Loc, AvailabilityInfo Availability,
-   LinkageInfo Linkage, const DocComment &Comment,
+   SymbolReference Parent, PresumedLoc Loc,
+   AvailabilityInfo Availability, LinkageInfo Linkage,
+   const DocComment &Comment,
DeclarationFragments Declaration,
DeclarationFragments SubHeading, bool 
IsFromSystemHeader)
   : APIRecord(Kind, USR, Name, Parent, Loc, std::move(Availability),
   Linkage, Comment, Declaration, SubHeading,
-  IsFromSystemHeader) {}
+  IsFromSystemHeader),
+RecordContext(Kind) {}
 
   static bool classof(const APIRecord *Record) {
 return classofKind(Record->getKind());
   }
-  static bool clas

[clang] [flang] [flang][Frontend] Implement printing defined macros via -dM (PR #87627)

2024-04-05 Thread Krzysztof Parzyszek via cfe-commits
kparzysz wrote:

The Windows build has the same failure as before (it's a known build breakage):
```
error LNK2019: unresolved external symbol _FortranAioSetForm referenced in 
function "private: virtual void __cdecl 
ExternalIOTests_TestWriteAfterEndfile_Test::TestBody(void)" 
(?TestBody@ExternalIOTests_TestWriteAfterEndfile_Test@@EEAAXXZ)
```

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


[clang] 6d2f57d - [FLANG] allow -fopenmp= (#86816)

2024-04-05 Thread via cfe-commits
Author: Mats Petersson
Date: 2024-04-05T13:48:43+01:00
New Revision: 6d2f57d2c4053af8f0c730bbfed141949149604c

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

LOG: [FLANG] allow -fopenmp= (#86816)

This enables the -fopenmp= option to the set of options
supported by flang.

The generated arguments for the FC1 compilation will appear in a
slightly different order, so one test had to be updated to be less
sensitive to order of the arguments.

Added: 
flang/test/Driver/fopenmp.f90

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/test/Driver/omp-driver-offload.f90

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 3d86f7510bde20..6186a88e1c803f 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -142,6 +142,9 @@ def warn_drv_unsupported_diag_option_for_flang : Warning<
 def warn_drv_unsupported_option_for_processor : Warning<
   "ignoring '%0' option as it is not currently supported for processor '%1'">,
   InGroup;
+def warn_drv_unsupported_openmp_library : Warning<
+  "The library '%0=%1' is not supported, openmp is not be enabled">,
+  InGroup;
 
 def err_drv_invalid_thread_model_for_target : Error<
   "invalid thread model '%0' in '%1' for this target">;

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f051bca6c1e953..827d9d7c0c18e4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3425,7 +3425,8 @@ defm openmp_extensions: BoolFOption<"openmp-extensions",
   "Enable all Clang extensions for OpenMP directives and clauses">,
   NegFlag>;
-def fopenmp_EQ : Joined<["-"], "fopenmp=">, Group;
+def fopenmp_EQ : Joined<["-"], "fopenmp=">, Group,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
 def fopenmp_use_tls : Flag<["-"], "fopenmp-use-tls">, Group,
   Flags<[NoArgumentUnused, HelpHidden]>;
 def fnoopenmp_use_tls : Flag<["-"], "fnoopenmp-use-tls">, Group,

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 70daa699e3a949..2c83f70eb7887e 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -35,27 +35,18 @@ static void addDashXForInput(const ArgList &Args, const 
InputInfo &Input,
 
 void Flang::addFortranDialectOptions(const ArgList &Args,
  ArgStringList &CmdArgs) const {
-  Args.addAllArgs(CmdArgs, {options::OPT_ffixed_form,
-options::OPT_ffree_form,
-options::OPT_ffixed_line_length_EQ,
-options::OPT_fopenmp,
-options::OPT_fopenmp_version_EQ,
-options::OPT_fopenacc,
-options::OPT_finput_charset_EQ,
-options::OPT_fimplicit_none,
-options::OPT_fno_implicit_none,
-options::OPT_fbackslash,
-options::OPT_fno_backslash,
-options::OPT_flogical_abbreviations,
-options::OPT_fno_logical_abbreviations,
-options::OPT_fxor_operator,
-options::OPT_fno_xor_operator,
-options::OPT_falternative_parameter_statement,
-options::OPT_fdefault_real_8,
-options::OPT_fdefault_integer_8,
-options::OPT_fdefault_double_8,
-options::OPT_flarge_sizes,
-options::OPT_fno_automatic});
+  Args.addAllArgs(
+  CmdArgs, {options::OPT_ffixed_form, options::OPT_ffree_form,
+options::OPT_ffixed_line_length_EQ, options::OPT_fopenacc,
+options::OPT_finput_charset_EQ, options::OPT_fimplicit_none,
+options::OPT_fno_implicit_none, options::OPT_fbackslash,
+options::OPT_fno_backslash, 
options::OPT_flogical_abbreviations,
+options::OPT_fno_logical_abbreviations,
+options::OPT_fxor_operator, options::OPT_fno_xor_operator,
+options::OPT_falternative_parameter_statement,
+options::OPT_fdefault_real_8, options::OPT_fdefault_integer_8,
+options::OPT_fdefault_double_8, options::OPT_flarge_sizes,
+options::OPT_fno_automatic});
 }
 
 void Flang::addPreprocessingOptions(const ArgList &Args,
@@ -763,6 +754,35 @@

[clang] [flang] [FLANG] allow -fopenmp= (PR #86816)

2024-04-05 Thread Mats Petersson via cfe-commits
https://github.com/Leporacanthicus closed 
https://github.com/llvm/llvm-project/pull/86816
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Reject VLAs in `__is_layout_compatible()` (PR #87737)

2024-04-05 Thread Aaron Ballman via cfe-commits
AaronBallman wrote:

> > However, at the language level, I cannot find any wording either way.
> 
> In my reading, http://eel.is/c++draft/basic.types.general#11 makes any type 
> layout-compatible with itself, and even ignores cv-qualification:
> 
> > Two types cv1 T1 and cv2 T2 are [layout-compatible 
> > types](http://eel.is/c++draft/basic.types.general#def:type,layout-compatible)
> >  if T1 and T2 are the same type, [layout-compatible 
> > enumerations](http://eel.is/c++draft/dcl.enum#def:layout-compatible,enumeration),
> >  or [layout-compatible standard-layout class 
> > types](http://eel.is/c++draft/class.mem#def:layout-compatible,class)[.](http://eel.is/c++draft/basic.types.general#11.sentence-1)
> 
> I find the gap between core language term and type trait rather unfortunate.

There are a lot of gaps between core language terms and type traits. For 
another example, copy constructible in the library is quite different from it 
in the language, volatile types are almost entirely ignored by the library, etc.

At the end of the day, these builtins are intended to be used as the underlying 
implementation for the type traits, so when in doubt, following the library 
rules is usually a safe bet.

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


[clang] [clang] Catch missing format attributes (PR #70024)

2024-04-05 Thread Budimir Aranđelović via cfe-commits
https://github.com/budimirarandjelovicsyrmia updated 
https://github.com/llvm/llvm-project/pull/70024

From 184fa1b21011d3700f2d501c49882bb87fcb5f38 Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 5 Apr 2024 15:20:37 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Sema.h   |   3 +
 clang/lib/Sema/SemaChecking.cpp   |   4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 117 -
 clang/test/Sema/attr-format-missing.c | 223 
 clang/test/Sema/attr-format-missing.cpp   | 238 ++
 8 files changed, 587 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3a84ff16a1e4d4..c6cd05da32332d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -381,6 +381,9 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Clang now diagnoses missing format attributes for non-template functions and
+  class/struct/union members. Fixes #GH70024
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 520168f01fd846..5c6a69ff1586db 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -505,7 +505,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index df57f5e6ce11ba..d32bf4c8a9549e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1008,6 +1008,9 @@ def err_opencl_invalid_param : Error<
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
 def warn_enum_value_overflow : Warning<"overflow in enumeration value">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 8c98d8c7fef7a7..1d57cb8779d7d0 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1698,6 +1698,9 @@ class Sema final {
 ChangedStateAtExit
   };
 
+  void DiagnoseMissingFormatAttributes(const FunctionDecl *FDecl,
+   ArrayRef Args,
+   SourceLocation Loc);
   void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind,
  SourceLocation IncludeLoc);
   void DiagnoseUnterminatedPragmaAlignPack();
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3dcd18b3afc8b4..77e01ba344e5a5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -8034,8 +8034,10 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 }
   }
 
-  if (FD)
+  if (FD) {
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
+DiagnoseMissingFormatAttributes(FD, Args, Range.getBegin());
+  }
 }
 
 /// CheckConstructorCall - Check a constructor call for correctness and safety
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 8bce04640e748e..281cae2bfa52de 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -159,6 +159,13 @@ static bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+static bool checkIfMethodHasImplicitThisParam(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 static inline bool isNSStringType(QualType T, ASTContext &Ctx,
   bool AllowNSAttributedString = false) {
   const auto *PT = T->getAs();
@@ -308,7 +315,7 @@ static bool checkFunctionOrMethodParameterIndex(
  

[clang] [clang] Catch missing format attributes (PR #70024)

2024-04-05 Thread Budimir Aranđelović via cfe-commits
https://github.com/budimirarandjelovicsyrmia reopened 
https://github.com/llvm/llvm-project/pull/70024
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC][NFC] Add OpenACC Clause AST Nodes/infrastructure (PR #87675)

2024-04-05 Thread Erich Keane via cfe-commits

@@ -30,13 +31,23 @@ class OpenACCConstructStmt : public Stmt {
   /// the directive.
   SourceRange Range;
 
-  // TODO OPENACC: Clauses should probably be collected in this class.
+  /// The list of clauses.  This is stored here as an ArrayRef, as this is the
+  /// most convienient place to access the list, however the list itself should
+  /// be stored in leaf nodes, likely in trailing-storage.
+  MutableArrayRef Clauses;

erichkeane wrote:

Unfortunately de-Serialization means we have to be able to modify the elements. 
 See ASTReaderStmt.cpp:2790 here.

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


[clang] [clang] Reject VLAs in `__is_layout_compatible()` (PR #87737)

2024-04-05 Thread Aaron Ballman via cfe-commits

@@ -1741,8 +1741,10 @@ void is_layout_compatible(int n)
   static_assert(!__is_layout_compatible(unsigned char, signed char));
   static_assert(__is_layout_compatible(int[], int[]));
   static_assert(__is_layout_compatible(int[2], int[2]));
-  static_assert(!__is_layout_compatible(int[n], int[2])); // FIXME: VLAs 
should be rejected
-  static_assert(!__is_layout_compatible(int[n], int[n])); // FIXME: VLAs 
should be rejected
+  static_assert(!__is_layout_compatible(int[n], int[2]));
+  // expected-error@-1 {{variable length arrays are not supported for 
'__is_layout_compatible'}}
+  static_assert(!__is_layout_compatible(int[n], int[n]));

AaronBallman wrote:

I think where we ended up is:

1) Reject incomplete types (still needs to be done)
2) Reject VLAs (done, looks good)
3) FAMs are accepted (no changes needed)

So I think you should implement #1 and add tests for it, then add tests for #3, 
and I think that finishes this.

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


[clang] [OpenACC][NFC] Add OpenACC Clause AST Nodes/infrastructure (PR #87675)

2024-04-05 Thread Erich Keane via cfe-commits

@@ -94,9 +94,10 @@ StmtResult 
SemaOpenACC::ActOnEndStmtDirective(OpenACCDirectiveKind K,
   case OpenACCDirectiveKind::Parallel:
   case OpenACCDirectiveKind::Serial:
   case OpenACCDirectiveKind::Kernels:
+// TODO OpenACC: Add clauses to the construct here.
 return OpenACCComputeConstruct::Create(
 getASTContext(), K, StartLoc, EndLoc,
-AssocStmt.isUsable() ? AssocStmt.get() : nullptr);
+/*Clauses=*/{}, AssocStmt.isUsable() ? AssocStmt.get() : nullptr);

erichkeane wrote:

Making the change (assuming it builds:) )  But curious as to why the nullopt 
preference here?  Both create an 'empty' `ArrayRef`, right?

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


[clang] [OpenACC][NFC] Add OpenACC Clause AST Nodes/infrastructure (PR #87675)

2024-04-05 Thread Erich Keane via cfe-commits

@@ -101,24 +113,45 @@ class OpenACCAssociatedStmtConstruct : public 
OpenACCConstructStmt {
 /// those three, as they are semantically identical, and have only minor
 /// differences in the permitted list of clauses, which can be differentiated 
by
 /// the 'Kind'.
-class OpenACCComputeConstruct : public OpenACCAssociatedStmtConstruct {
+class OpenACCComputeConstruct final
+: public OpenACCAssociatedStmtConstruct,
+  public llvm::TrailingObjects {
   friend class ASTStmtWriter;
   friend class ASTStmtReader;
   friend class ASTContext;
-  OpenACCComputeConstruct()
-  : OpenACCAssociatedStmtConstruct(
-OpenACCComputeConstructClass, OpenACCDirectiveKind::Invalid,
-SourceLocation{}, SourceLocation{}, /*AssociatedStmt=*/nullptr) {}
+  OpenACCComputeConstruct(unsigned NumClauses)
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
+   OpenACCDirectiveKind::Invalid,
+   SourceLocation{}, SourceLocation{},
+   /*AssociatedStmt=*/nullptr) {
+// We cannot send the TrailingObjects storage to the base class (which 
holds
+// a reference to the data) until it is constructed, so we have to set it
+// separately here.
+memset(getTrailingObjects(), 0,
+   NumClauses * sizeof(const OpenACCClause *));

erichkeane wrote:

Do you mean 
https://en.cppreference.com/w/cpp/memory/uninitialized_default_construct ?  Or 
is there something else you mean?

`std::uninitialized_default_construct` unfortunately 'default constructs', 
which means I get indeterminate values instead of nullptr.

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


[clang] [OpenACC][NFC] Add OpenACC Clause AST Nodes/infrastructure (PR #87675)

2024-04-05 Thread Alexey Bataev via cfe-commits

@@ -94,9 +94,10 @@ StmtResult 
SemaOpenACC::ActOnEndStmtDirective(OpenACCDirectiveKind K,
   case OpenACCDirectiveKind::Parallel:
   case OpenACCDirectiveKind::Serial:
   case OpenACCDirectiveKind::Kernels:
+// TODO OpenACC: Add clauses to the construct here.
 return OpenACCComputeConstruct::Create(
 getASTContext(), K, StartLoc, EndLoc,
-AssocStmt.isUsable() ? AssocStmt.get() : nullptr);
+/*Clauses=*/{}, AssocStmt.isUsable() ? AssocStmt.get() : nullptr);

alexey-bataev wrote:

Just preferred way for constructing empty ArrayRef

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


[clang] [clang] Catch missing format attributes (PR #70024)

2024-04-05 Thread Vlad Serebrennikov via cfe-commits
https://github.com/Endilll edited 
https://github.com/llvm/llvm-project/pull/70024
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Catch missing format attributes (PR #70024)

2024-04-05 Thread Vlad Serebrennikov via cfe-commits
https://github.com/Endilll requested changes to this pull request.


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


[clang] [clang] Catch missing format attributes (PR #70024)

2024-04-05 Thread Vlad Serebrennikov via cfe-commits

@@ -1698,6 +1698,9 @@ class Sema final {
 ChangedStateAtExit
   };
 
+  void DiagnoseMissingFormatAttributes(const FunctionDecl *FDecl,

Endilll wrote:

This declaration is placed among functions implemented in `SemaAttr.cpp`, as 
you might see around line 1296, but its implementation is placed in 
`SemaDeclAttr.cpp`. Declarations of functions in this file have their own 
section in `Sema.h`, which starts around line 3690. This discrepancy should be 
fixed one way or another.

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


[clang] [libTooling] Fix `getFileRangeForEdit` for inner nested template types (PR #87673)

2024-04-05 Thread Yitzhak Mandelbaum via cfe-commits
https://github.com/ymand edited https://github.com/llvm/llvm-project/pull/87673
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libTooling] Fix `getFileRangeForEdit` for inner nested template types (PR #87673)

2024-04-05 Thread Yitzhak Mandelbaum via cfe-commits
https://github.com/ymand approved this pull request.

Nice work - really subtle! I'd been wondering how clang handles this issue (of 
relexing returning the wrong token because it lacked context).

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


[clang] [libTooling] Fix `getFileRangeForEdit` for inner nested template types (PR #87673)

2024-04-05 Thread Yitzhak Mandelbaum via cfe-commits

@@ -510,6 +519,26 @@ int c = M3(3);
   Visitor.runOver(Code.code());
 }
 
+TEST(SourceCodeTest, InnerNestedTemplate) {

ymand wrote:

Add a test case that covers the case of the split being in the BeginToken?

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


[clang] [OpenACC][NFC] Add OpenACC Clause AST Nodes/infrastructure (PR #87675)

2024-04-05 Thread Alexey Bataev via cfe-commits

@@ -101,24 +113,45 @@ class OpenACCAssociatedStmtConstruct : public 
OpenACCConstructStmt {
 /// those three, as they are semantically identical, and have only minor
 /// differences in the permitted list of clauses, which can be differentiated 
by
 /// the 'Kind'.
-class OpenACCComputeConstruct : public OpenACCAssociatedStmtConstruct {
+class OpenACCComputeConstruct final
+: public OpenACCAssociatedStmtConstruct,
+  public llvm::TrailingObjects {
   friend class ASTStmtWriter;
   friend class ASTStmtReader;
   friend class ASTContext;
-  OpenACCComputeConstruct()
-  : OpenACCAssociatedStmtConstruct(
-OpenACCComputeConstructClass, OpenACCDirectiveKind::Invalid,
-SourceLocation{}, SourceLocation{}, /*AssociatedStmt=*/nullptr) {}
+  OpenACCComputeConstruct(unsigned NumClauses)
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
+   OpenACCDirectiveKind::Invalid,
+   SourceLocation{}, SourceLocation{},
+   /*AssociatedStmt=*/nullptr) {
+// We cannot send the TrailingObjects storage to the base class (which 
holds
+// a reference to the data) until it is constructed, so we have to set it
+// separately here.
+memset(getTrailingObjects(), 0,
+   NumClauses * sizeof(const OpenACCClause *));

alexey-bataev wrote:

I meant something like std::unitialized_copy

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


[clang] [OpenACC][NFC] Add OpenACC Clause AST Nodes/infrastructure (PR #87675)

2024-04-05 Thread Erich Keane via cfe-commits

@@ -94,9 +94,10 @@ StmtResult 
SemaOpenACC::ActOnEndStmtDirective(OpenACCDirectiveKind K,
   case OpenACCDirectiveKind::Parallel:
   case OpenACCDirectiveKind::Serial:
   case OpenACCDirectiveKind::Kernels:
+// TODO OpenACC: Add clauses to the construct here.
 return OpenACCComputeConstruct::Create(
 getASTContext(), K, StartLoc, EndLoc,
-AssocStmt.isUsable() ? AssocStmt.get() : nullptr);
+/*Clauses=*/{}, AssocStmt.isUsable() ? AssocStmt.get() : nullptr);

erichkeane wrote:

Ah, ok then :)  Patch incoming.

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


[clang] Rework the printing of attributes (PR #87281)

2024-04-05 Thread Aaron Ballman via cfe-commits

@@ -73,3 +73,15 @@ class C {
   // CHECK: void pwtt(void *, int) __attribute__((pointer_with_type_tag(foo, 
2, 3)));
   void pwtt(void *, int) __attribute__((pointer_with_type_tag(foo, 2, 3)));
 };
+
+#define ANNOTATE_ATTR __attribute__((annotate("Annotated")))
+ANNOTATE_ATTR int annotated_attr ANNOTATE_ATTR = 0;
+// CHECK: __attribute__((annotate("Annotated"))) int annotated_attr 
__attribute__((annotate("Annotated"))) = 0;
+
+// FIXME: We do not print the attribute as written after the type specifier.
+int ANNOTATE_ATTR annotated_attr_fixme = 0;

AaronBallman wrote:

The PR changes behavior from one really broken state to a slightly less but 
still broken state. Consider:
```
[[clang::annotate("do the")]] int [[clang::annotate_type("test")]] * 
[[clang::annotate_type("again")]] i [[clang::annotate("and again!")]] = 0;
```
Currently we print this back as: `int *i [[clang::annotate_type(...)]] 
[[clang::annotate_type(...)]] [[clang::annotate("do the")]] 
[[clang::annotate("and again!")]] = 0;` which is all kinds of wrong. Now we 
print this back as: `[[clang::annotate("do the")]] int *i 
[[clang::annotate_type(...)]] [[clang::annotate_type(...)]] 
[[clang::annotate("and again!")]] = 0;` which is in better shape but still gets 
the type attributes wrong by moving the attribute off `int` and `*` and onto 
the declaration of `i`. The new code won't compile (it tries to add type 
attributes to a declaration, and the `...` instead of the original string 
literal won't compile either).

Given that printing is best-effort, perhaps this is fine because it's 
incremental improvement, but we're still not quite there in terms of accurate 
printing either.

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


[clang] [OpenACC][NFC] Add OpenACC Clause AST Nodes/infrastructure (PR #87675)

2024-04-05 Thread Erich Keane via cfe-commits

@@ -101,24 +113,45 @@ class OpenACCAssociatedStmtConstruct : public 
OpenACCConstructStmt {
 /// those three, as they are semantically identical, and have only minor
 /// differences in the permitted list of clauses, which can be differentiated 
by
 /// the 'Kind'.
-class OpenACCComputeConstruct : public OpenACCAssociatedStmtConstruct {
+class OpenACCComputeConstruct final
+: public OpenACCAssociatedStmtConstruct,
+  public llvm::TrailingObjects {
   friend class ASTStmtWriter;
   friend class ASTStmtReader;
   friend class ASTContext;
-  OpenACCComputeConstruct()
-  : OpenACCAssociatedStmtConstruct(
-OpenACCComputeConstructClass, OpenACCDirectiveKind::Invalid,
-SourceLocation{}, SourceLocation{}, /*AssociatedStmt=*/nullptr) {}
+  OpenACCComputeConstruct(unsigned NumClauses)
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
+   OpenACCDirectiveKind::Invalid,
+   SourceLocation{}, SourceLocation{},
+   /*AssociatedStmt=*/nullptr) {
+// We cannot send the TrailingObjects storage to the base class (which 
holds
+// a reference to the data) until it is constructed, so we have to set it
+// separately here.
+memset(getTrailingObjects(), 0,
+   NumClauses * sizeof(const OpenACCClause *));

erichkeane wrote:

Ah!  That DOES seem like it is useful in the other init here.  Perhaps 
`std::uninitialized_value_construct` is useful for the memcpy.  Patch incoming 
:) 

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


[clang] [OpenACC][NFC] Add OpenACC Clause AST Nodes/infrastructure (PR #87675)

2024-04-05 Thread Alexey Bataev via cfe-commits

@@ -101,24 +113,45 @@ class OpenACCAssociatedStmtConstruct : public 
OpenACCConstructStmt {
 /// those three, as they are semantically identical, and have only minor
 /// differences in the permitted list of clauses, which can be differentiated 
by
 /// the 'Kind'.
-class OpenACCComputeConstruct : public OpenACCAssociatedStmtConstruct {
+class OpenACCComputeConstruct final
+: public OpenACCAssociatedStmtConstruct,
+  public llvm::TrailingObjects {
   friend class ASTStmtWriter;
   friend class ASTStmtReader;
   friend class ASTContext;
-  OpenACCComputeConstruct()
-  : OpenACCAssociatedStmtConstruct(
-OpenACCComputeConstructClass, OpenACCDirectiveKind::Invalid,
-SourceLocation{}, SourceLocation{}, /*AssociatedStmt=*/nullptr) {}
+  OpenACCComputeConstruct(unsigned NumClauses)
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
+   OpenACCDirectiveKind::Invalid,
+   SourceLocation{}, SourceLocation{},
+   /*AssociatedStmt=*/nullptr) {
+// We cannot send the TrailingObjects storage to the base class (which 
holds
+// a reference to the data) until it is constructed, so we have to set it
+// separately here.
+memset(getTrailingObjects(), 0,
+   NumClauses * sizeof(const OpenACCClause *));

alexey-bataev wrote:

I just thought that memset can be removed here and instead use 
std::unitialized_copy in setClauseList. But up to you, this is just a suggestion

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


[clang] [clang] Reject VLAs in `__is_layout_compatible()` (PR #87737)

2024-04-05 Thread Vlad Serebrennikov via cfe-commits

@@ -1741,8 +1741,10 @@ void is_layout_compatible(int n)
   static_assert(!__is_layout_compatible(unsigned char, signed char));
   static_assert(__is_layout_compatible(int[], int[]));
   static_assert(__is_layout_compatible(int[2], int[2]));
-  static_assert(!__is_layout_compatible(int[n], int[2])); // FIXME: VLAs 
should be rejected
-  static_assert(!__is_layout_compatible(int[n], int[n])); // FIXME: VLAs 
should be rejected
+  static_assert(!__is_layout_compatible(int[n], int[2]));
+  // expected-error@-1 {{variable length arrays are not supported for 
'__is_layout_compatible'}}
+  static_assert(!__is_layout_compatible(int[n], int[n]));

Endilll wrote:

I recognize that discussion has spiraled out of VLAs into incomplete types and 
flexible array members, but can I keep the original scope of this PR, focusing 
on just VLAs?

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


[clang] [llvm] Remove remaining uses of Instruction-constructors that insert before another Instruction (PR #85981)

2024-04-05 Thread Orlando Cazalet-Hyams via cfe-commits

@@ -1542,19 +1542,10 @@ class CallBase : public Instruction {
 OperandBundleDef OB,
 Instruction *InsertPt = nullptr);
 
-  /// Create a clone of \p CB with operand bundle \p OB added.
-  static CallBase *addOperandBundle(CallBase *CB, uint32_t ID,
-OperandBundleDef OB,
-BasicBlock::iterator InsertPt);
-
   /// Create a clone of \p CB with operand bundle \p ID removed.
   static CallBase *removeOperandBundle(CallBase *CB, uint32_t ID,
Instruction *InsertPt = nullptr);
 
-  /// Create a clone of \p CB with operand bundle \p ID removed.
-  static CallBase *removeOperandBundle(CallBase *CB, uint32_t ID,
-   BasicBlock::iterator InsertPt);

OCHyams wrote:

why are these removed?

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


[clang] [CUDA][HIP] Fix record layout on Windows (PR #87651)

2024-04-05 Thread Yaxun Liu via cfe-commits
yxsamliu wrote:

> > Keeping layout in sync makes sense to me, but I'm completely unfamiliar 
> > with the windows side.
> > @rnk is there anything else we need to worry about?
> 
> I checked, and I think this routes everything over to the MS record layout 
> builder, so it should be comprehensive:
> 
> https://github.com/llvm/llvm-project/blob/d97d560fbf6ed26a198b3afe1594d7d63b88ab3a/clang/lib/AST/RecordLayoutBuilder.cpp#L3354
> 
> I would augment the test a bit, but otherwise this looks good to me.

will add more tests about field access and virtual function calls

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


[clang] [OpenACC][NFC] Add OpenACC Clause AST Nodes/infrastructure (PR #87675)

2024-04-05 Thread Erich Keane via cfe-commits

@@ -101,24 +113,45 @@ class OpenACCAssociatedStmtConstruct : public 
OpenACCConstructStmt {
 /// those three, as they are semantically identical, and have only minor
 /// differences in the permitted list of clauses, which can be differentiated 
by
 /// the 'Kind'.
-class OpenACCComputeConstruct : public OpenACCAssociatedStmtConstruct {
+class OpenACCComputeConstruct final
+: public OpenACCAssociatedStmtConstruct,
+  public llvm::TrailingObjects {
   friend class ASTStmtWriter;
   friend class ASTStmtReader;
   friend class ASTContext;
-  OpenACCComputeConstruct()
-  : OpenACCAssociatedStmtConstruct(
-OpenACCComputeConstructClass, OpenACCDirectiveKind::Invalid,
-SourceLocation{}, SourceLocation{}, /*AssociatedStmt=*/nullptr) {}
+  OpenACCComputeConstruct(unsigned NumClauses)
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
+   OpenACCDirectiveKind::Invalid,
+   SourceLocation{}, SourceLocation{},
+   /*AssociatedStmt=*/nullptr) {
+// We cannot send the TrailingObjects storage to the base class (which 
holds
+// a reference to the data) until it is constructed, so we have to set it
+// separately here.
+memset(getTrailingObjects(), 0,
+   NumClauses * sizeof(const OpenACCClause *));

erichkeane wrote:

I think there is value in setting this to '0', but I've used your suggestion in 
another way.  I don't think 'setClauseList' can do the copy (as it is just 
initializing the ArrayRef to the pointer+size pair), but I'm also going to use 
`std::uninitialized_copy` for the setting of the trailing storage.  

The 'serialization' means the clause `MutableArrayRef` needs to be set in the 
'create empty' case.  Let me know what you think about the next version of this 
patch (more suggestions appreciated!).

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


[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread Julian Nagele via cfe-commits
https://github.com/juliannagele updated 
https://github.com/llvm/llvm-project/pull/87753

>From db1ee85ca26d7ddbaa163f4e9b1038c28e3d4a57 Mon Sep 17 00:00:00 2001
From: Julian Nagele 
Date: Thu, 4 Apr 2024 11:48:19 +0100
Subject: [PATCH 1/2] Fix tbaa.struct metadata for bitfields using big endian.

When generating tbaa.struct metadata we treat multiple adjacent
bitfields as a single "field", with one corresponding entry in the
metadata.
At the moment this is achieved by adding an entry for the first
bitfield in the run using its StorageSize (and skipping the remaining
bitfields). The problem is that "first" is determined by checking that
the Offset of the field in the run is 0. This breaks for big endian.
---
 clang/lib/CodeGen/CodeGenTBAA.cpp  |  6 +-
 clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp | 10 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index a1e14c5f0a8c78..0ddefc4751b08c 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/LLVMContext.h"
@@ -319,7 +320,10 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0
+: Info.Offset == 0;
+if (!IsFirst)
   continue;
 unsigned CurrentBitFieldSize = Info.StorageSize;
 uint64_t Size =
diff --git a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp 
b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
index 80884b49ddc669..e8bb46982537bb 100644
--- a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
+++ b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
@@ -1,13 +1,10 @@
 // RUN: %clang_cc1 -triple aarch64_be-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-BE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 // RUN: %clang_cc1 -triple aarch64-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-LE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 //
 // Check that TBAA metadata for structs containing bitfields is
 // consistent between big and little endian layouts.
-//
-// FIXME: The metadata below is invalid for the big endian layout: the
-// start offset of 2 is incorrect.
 
 struct NamedBitfields {
   int f1 : 8;
@@ -28,8 +25,7 @@ void copy(NamedBitfields *a1, NamedBitfields *a2) {
   *a1 = *a2;
 }
 
-// CHECK-BE: [[TBAA_STRUCT2]] = !{i64 2, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
-// CHECK-LE: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
+// CHECK: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 4, 
[[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
 // CHECK: [[META3]] = !{[[META4:![0-9]+]], [[META4]], i64 0}
 // CHECK: [[META4]] = !{!"omnipotent char", [[META5:![0-9]+]], i64 0}
 // CHECK: [[META5]] = !{!"Simple C++ TBAA"}

>From bdfc7dd785d50d4bf41428afb314a4c89d22c100 Mon Sep 17 00:00:00 2001
From: Julian Nagele 
Date: Fri, 5 Apr 2024 14:58:29 +0100
Subject: [PATCH 2/2] fixup! Fix tbaa.struct metadata for bitfields using big
 endian.

---
 clang/lib/CodeGen/CodeGenTBAA.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 0ddefc4751b08c..837bf725da388a 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -320,6 +320,9 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
+// For big endian targets the first bitfield in the consecutive run is
+// at the most-significant end; see CGRecordLowering::setBitFieldInfo
+// for more information.
 bool IsBE = Context.getTargetInfo().isBigEndian();
 bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0
 : Info.Offset == 0;

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


[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread Julian Nagele via cfe-commits

@@ -319,7 +320,10 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0

juliannagele wrote:

Added a comment, thanks!

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


[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-05 Thread Aaron Ballman via cfe-commits

@@ -1980,6 +1981,23 @@ static void handleWeakRefAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   D->addAttr(::new (S.Context) WeakRefAttr(S.Context, AL));
 }
 
+// Mark alias/ifunc target as used. For C++, we look up the demangled name
+// ignoring parameters. This should handle the majority of use cases while
+// leaveing false positives for namespace scope names and false negatives in
+// the presence of overloads.
+static void markUsedForAliasOrIfunc(Sema &S, Decl *D, const ParsedAttr &AL,
+StringRef Str) {
+  char *Demangled = llvm::itaniumDemangle(Str, /*ParseParams=*/false);

AaronBallman wrote:

> I added a `S.getASTContext().getCXXABIKind() != TargetCXXABI::Microsoft` 
> check.
> 
> Note: while `alias` works for Windows, it is only checked in tests 
> CodeGenCXX/visibility-dllstorageclass.cpp/CodeGen/debug-info-alias-pointer.c 
> . I don't consider an internal linkage target used or cared by users.

I'm not certain why there's so much resistance to doing this when three people 
have pointed out the concern. It still works for Windows. e.g.,
```
F:\source\llvm-project>cat "C:\Users\aballman\OneDrive - Intel 
Corporation\Desktop\test.cpp"
namespace NS {
  extern "C" int puts(const char *);
  void f() { puts("I did the thing!"); }
}

void func() __attribute__((alias("?f@NS@@YAXXZ")));

int main() {
  func();
}

F:\source\llvm-project>llvm\out\build\x64-Debug\bin\clang.exe 
"C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.cpp"

F:\source\llvm-project>a.exe
I did the thing!
```
We should support it properly rather than only halfway, *especially considering 
the context of the bug report*.

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


[clang] [Sema] Remove the duplicated `DeduceTemplateArguments` for partial specialization, NFC (PR #87782)

2024-04-05 Thread Haojian Wu via cfe-commits
https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/87782

We have two identical "DeduceTemplateArguments" implementations for class and 
variable partial template specializations, this patch removes the duplicated 
code. 

>From 209ace7709ca176216a94cfd10edee13ea26955d Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 5 Apr 2024 15:58:00 +0200
Subject: [PATCH] [Sema] Remove the duplicated `DeductionTemplateArguments` for
 partial specialization, NFC

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 83 +++-
 1 file changed, 23 insertions(+), 60 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 716660244537b8..06c89783a2da19 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3140,13 +3140,15 @@ static TemplateDeductionResult 
FinishTemplateArgumentDeduction(
   return TemplateDeductionResult::Success;
 }
 
-/// Perform template argument deduction to determine whether
-/// the given template arguments match the given class template
-/// partial specialization per C++ [temp.class.spec.match].
-TemplateDeductionResult
-Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
-  ArrayRef TemplateArgs,
-  TemplateDeductionInfo &Info) {
+/// Perform template argument deduction to determine whether the given template
+/// arguments match the given class or variable template partial specialization
+/// per C++ [temp.class.spec.match].
+template 
+static std::enable_if_t::value,
+TemplateDeductionResult>
+DeduceTemplateArguments(Sema &S, T *Partial,
+ArrayRef TemplateArgs,
+TemplateDeductionInfo &Info) {
   if (Partial->isInvalidDecl())
 return TemplateDeductionResult::Invalid;
 
@@ -3158,24 +3160,24 @@ 
Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
 
   // Unevaluated SFINAE context.
   EnterExpressionEvaluationContext Unevaluated(
-  *this, Sema::ExpressionEvaluationContext::Unevaluated);
-  SFINAETrap Trap(*this);
+  S, Sema::ExpressionEvaluationContext::Unevaluated);
+  Sema::SFINAETrap Trap(S);
 
   // This deduction has no relation to any outer instantiation we might be
   // performing.
-  LocalInstantiationScope InstantiationScope(*this);
+  LocalInstantiationScope InstantiationScope(S);
 
   SmallVector Deduced;
   Deduced.resize(Partial->getTemplateParameters()->size());
   if (TemplateDeductionResult Result = ::DeduceTemplateArguments(
-  *this, Partial->getTemplateParameters(),
+  S, Partial->getTemplateParameters(),
   Partial->getTemplateArgs().asArray(), TemplateArgs, Info, Deduced,
   /*NumberOfArgumentsMustMatch=*/false);
   Result != TemplateDeductionResult::Success)
 return Result;
 
   SmallVector DeducedArgs(Deduced.begin(), Deduced.end());
-  InstantiatingTemplate Inst(*this, Info.getLocation(), Partial, DeducedArgs,
+  Sema::InstantiatingTemplate Inst(S, Info.getLocation(), Partial, DeducedArgs,
  Info);
   if (Inst.isInvalid())
 return TemplateDeductionResult::InstantiationDepth;
@@ -3184,64 +3186,25 @@ 
Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
 return TemplateDeductionResult::SubstitutionFailure;
 
   TemplateDeductionResult Result;
-  runWithSufficientStackSpace(Info.getLocation(), [&] {
-Result = ::FinishTemplateArgumentDeduction(*this, Partial,
+  S.runWithSufficientStackSpace(Info.getLocation(), [&] {
+Result = ::FinishTemplateArgumentDeduction(S, Partial,
/*IsPartialOrdering=*/false,
TemplateArgs, Deduced, Info);
   });
   return Result;
 }
 
-/// Perform template argument deduction to determine whether
-/// the given template arguments match the given variable template
-/// partial specialization per C++ [temp.class.spec.match].
+TemplateDeductionResult
+Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
+  ArrayRef TemplateArgs,
+  TemplateDeductionInfo &Info) {
+  return ::DeduceTemplateArguments(*this, Partial, TemplateArgs, Info);
+}
 TemplateDeductionResult
 Sema::DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial,
   ArrayRef TemplateArgs,
   TemplateDeductionInfo &Info) {
-  if (Partial->isInvalidDecl())
-return TemplateDeductionResult::Invalid;
-
-  // C++ [temp.class.spec.match]p2:
-  //   A partial specialization matches a given actual template
-  //   argument list if the template arguments of the partial
-  //   specialization can be deduced from the actual template argument
-  //   list (14.8.2).
-
-  // Unevaluated SFINAE context.
-  Enter

[clang] [Sema] Mark alias/ifunc targets used and consider mangled names (PR #87130)

2024-04-05 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman requested changes to this pull request.

Marking as requesting changes until we get agreement on the behavior for the 
Microsoft ABI.

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


[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread Florian Hahn via cfe-commits
https://github.com/fhahn approved this pull request.

LGTM, thanks!

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


[clang] [Sema] Remove the duplicated `DeduceTemplateArguments` for partial specialization, NFC (PR #87782)

2024-04-05 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

We have two identical "DeduceTemplateArguments" implementations for class and 
variable partial template specializations, this patch removes the duplicated 
code. 

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+23-60) 


``diff
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 716660244537b8..06c89783a2da19 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3140,13 +3140,15 @@ static TemplateDeductionResult 
FinishTemplateArgumentDeduction(
   return TemplateDeductionResult::Success;
 }
 
-/// Perform template argument deduction to determine whether
-/// the given template arguments match the given class template
-/// partial specialization per C++ [temp.class.spec.match].
-TemplateDeductionResult
-Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
-  ArrayRef TemplateArgs,
-  TemplateDeductionInfo &Info) {
+/// Perform template argument deduction to determine whether the given template
+/// arguments match the given class or variable template partial specialization
+/// per C++ [temp.class.spec.match].
+template 
+static std::enable_if_t::value,
+TemplateDeductionResult>
+DeduceTemplateArguments(Sema &S, T *Partial,
+ArrayRef TemplateArgs,
+TemplateDeductionInfo &Info) {
   if (Partial->isInvalidDecl())
 return TemplateDeductionResult::Invalid;
 
@@ -3158,24 +3160,24 @@ 
Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
 
   // Unevaluated SFINAE context.
   EnterExpressionEvaluationContext Unevaluated(
-  *this, Sema::ExpressionEvaluationContext::Unevaluated);
-  SFINAETrap Trap(*this);
+  S, Sema::ExpressionEvaluationContext::Unevaluated);
+  Sema::SFINAETrap Trap(S);
 
   // This deduction has no relation to any outer instantiation we might be
   // performing.
-  LocalInstantiationScope InstantiationScope(*this);
+  LocalInstantiationScope InstantiationScope(S);
 
   SmallVector Deduced;
   Deduced.resize(Partial->getTemplateParameters()->size());
   if (TemplateDeductionResult Result = ::DeduceTemplateArguments(
-  *this, Partial->getTemplateParameters(),
+  S, Partial->getTemplateParameters(),
   Partial->getTemplateArgs().asArray(), TemplateArgs, Info, Deduced,
   /*NumberOfArgumentsMustMatch=*/false);
   Result != TemplateDeductionResult::Success)
 return Result;
 
   SmallVector DeducedArgs(Deduced.begin(), Deduced.end());
-  InstantiatingTemplate Inst(*this, Info.getLocation(), Partial, DeducedArgs,
+  Sema::InstantiatingTemplate Inst(S, Info.getLocation(), Partial, DeducedArgs,
  Info);
   if (Inst.isInvalid())
 return TemplateDeductionResult::InstantiationDepth;
@@ -3184,64 +3186,25 @@ 
Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
 return TemplateDeductionResult::SubstitutionFailure;
 
   TemplateDeductionResult Result;
-  runWithSufficientStackSpace(Info.getLocation(), [&] {
-Result = ::FinishTemplateArgumentDeduction(*this, Partial,
+  S.runWithSufficientStackSpace(Info.getLocation(), [&] {
+Result = ::FinishTemplateArgumentDeduction(S, Partial,
/*IsPartialOrdering=*/false,
TemplateArgs, Deduced, Info);
   });
   return Result;
 }
 
-/// Perform template argument deduction to determine whether
-/// the given template arguments match the given variable template
-/// partial specialization per C++ [temp.class.spec.match].
+TemplateDeductionResult
+Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
+  ArrayRef TemplateArgs,
+  TemplateDeductionInfo &Info) {
+  return ::DeduceTemplateArguments(*this, Partial, TemplateArgs, Info);
+}
 TemplateDeductionResult
 Sema::DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial,
   ArrayRef TemplateArgs,
   TemplateDeductionInfo &Info) {
-  if (Partial->isInvalidDecl())
-return TemplateDeductionResult::Invalid;
-
-  // C++ [temp.class.spec.match]p2:
-  //   A partial specialization matches a given actual template
-  //   argument list if the template arguments of the partial
-  //   specialization can be deduced from the actual template argument
-  //   list (14.8.2).
-
-  // Unevaluated SFINAE context.
-  EnterExpressionEvaluationContext Unevaluated(
-  *this, Sema::ExpressionEvaluationContext::Unevaluated);
-  SFINAETrap Trap(*this);
-
-  // This deduction has no relation to any outer instantia

[clang] [Sema] Remove the duplicated `DeduceTemplateArguments` for partial specialization, NFC (PR #87782)

2024-04-05 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 6d2f57d2c4053af8f0c730bbfed141949149604c 
209ace7709ca176216a94cfd10edee13ea26955d -- 
clang/lib/Sema/SemaTemplateDeduction.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 06c89783a2..0b6375001f 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3178,7 +3178,7 @@ DeduceTemplateArguments(Sema &S, T *Partial,
 
   SmallVector DeducedArgs(Deduced.begin(), Deduced.end());
   Sema::InstantiatingTemplate Inst(S, Info.getLocation(), Partial, DeducedArgs,
- Info);
+   Info);
   if (Inst.isInvalid())
 return TemplateDeductionResult::InstantiationDepth;
 

``




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


[clang] [analyzer] Set and display CSA analysis entry points as notes on debugging (PR #84823)

2024-04-05 Thread Balazs Benics via cfe-commits

@@ -788,7 +791,7 @@ class PathDiagnostic : public llvm::FoldingSetNode {
   PathDiagnostic(StringRef CheckerName, const Decl *DeclWithIssue,
  StringRef bugtype, StringRef verboseDesc, StringRef shortDesc,
  StringRef category, PathDiagnosticLocation LocationToUnique,
- const Decl *DeclToUnique,
+ const Decl *DeclToUnique, const Decl *AnalysisEntryPoint,

steakhal wrote:

> It looks like you have a nice solution that doesn't force each checker to 
> fill it in manually. 

TBH I'm pretty discontent with my implementation. This was basically the third 
attempt and the so far the cleanest - but it's still bad. The whole diagnostic 
pipeline is just a mess.

> I mean, this is a debug feature. Debug features are great but it's probably 
> ok to have them slightly incorrect or incomplete if it means that they're no 
> longer associated with increased complexity, with paying for something we 
> don't use.

Do you imply I should relax the PathDiagnostic ctor precondition to allow 
nullptr entry point decls?
>From the name `Path` I judged, the entry point must be always present.

> Out of those AST checkers, how many are emitting diagnostics outside of the 
> entry function / decl-with-issue function? If you append
> 
> ```
> [debug] This bubble's decl name is 'foo()'
> ```
> 
> to _every_ message bubble, would that entirely cover all your needs?

I'm not sure what "bubble" refers to, but if it's a synonym for "note" or 
"message", then yes - plus:
The entry point decl would be also beneficial for a primitive caching mechanism 
to know what reports we need to invalidate if a given decl changes across 
subsequent static analyzer runs on different git commits. I'll present the idea 
at EuroLLVM next week, but the gist of it is basically that we associate each 
diagnostic with a decl, hash that decl; and if subsequent runs hash that decl 
to the same value, then we can replay the diagnostic and skipping the entry 
point. To achieve this, we of course need to know the entry point.

> I can easily see how there could be a checker that always warns outside of 
> the entry function. If that's the case then it's probably incredibly useful 
> for debugging to quickly know which entry function inspired the warning. But 
> at the same time I'm not sure I can think of a good example when the same 
> information wouldn't be useful for the _user_ as well; maybe the users could 
> benefit from a user-facing note too? (Somewhat similarly to how Clang 
> explains template instantiation stack when diagnosing problems in individual 
> template instantiations. (Something we cannot mimic in static analysis tools 
> because the instantiation stack is already lost.))

I'm natural for having these notes (or a slightly differently phrased notes) 
denoting the start of the analysis.
If you think it would be genuinely useful, I could add it.

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


[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread via cfe-commits
https://github.com/dobbelaj-snps approved this pull request.

lgtm

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


[clang] [clang] CTAD: build aggregate deduction guides for alias templates. (PR #85904)

2024-04-05 Thread Haojian Wu via cfe-commits
https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/85904

>From a1ac905dfbcfd1d615c5326c45c7f599826cc097 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 15 Mar 2024 10:47:09 +0100
Subject: [PATCH 1/4] [clang] Move the aggreate deduction guide cache login to
 SemaTemplate.cpp, NFC.

this is a NFC refactoring change, which is needed for the upcoming fix
for alias templates.
---
 clang/lib/Sema/SemaInit.cpp | 27 +--
 clang/lib/Sema/SemaTemplate.cpp | 24 ++--
 2 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index e2a1951f1062cb..0b1471449d842d 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10930,32 +10930,15 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
   Context.getLValueReferenceType(ElementTypes[I].withConst());
   }
 
-llvm::FoldingSetNodeID ID;
-ID.AddPointer(Template);
-for (auto &T : ElementTypes)
-  T.getCanonicalType().Profile(ID);
-unsigned Hash = ID.ComputeHash();
-if (AggregateDeductionCandidates.count(Hash) == 0) {
-  if (FunctionTemplateDecl *TD =
-  DeclareImplicitDeductionGuideFromInitList(
-  Template, ElementTypes,
-  TSInfo->getTypeLoc().getEndLoc())) {
-auto *GD = cast(TD->getTemplatedDecl());
-GD->setDeductionCandidateKind(DeductionCandidate::Aggregate);
-AggregateDeductionCandidates[Hash] = GD;
-addDeductionCandidate(TD, GD, DeclAccessPair::make(TD, AS_public),
-  OnlyListConstructors,
-  /*AllowAggregateDeductionCandidate=*/true);
-  }
-} else {
-  CXXDeductionGuideDecl *GD = AggregateDeductionCandidates[Hash];
-  FunctionTemplateDecl *TD = GD->getDescribedFunctionTemplate();
-  assert(TD && "aggregate deduction candidate is function template");
+if (FunctionTemplateDecl *TD =
+DeclareImplicitDeductionGuideFromInitList(
+Template, ElementTypes, TSInfo->getTypeLoc().getEndLoc())) 
{
+  auto *GD = cast(TD->getTemplatedDecl());
   addDeductionCandidate(TD, GD, DeclAccessPair::make(TD, AS_public),
 OnlyListConstructors,
 /*AllowAggregateDeductionCandidate=*/true);
+  HasAnyDeductionGuide = true;
 }
-HasAnyDeductionGuide = true;
   }
 };
 
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 0b75f4fb401e63..d32ddbd71ec2b9 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3018,6 +3018,23 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
 FunctionTemplateDecl *Sema::DeclareImplicitDeductionGuideFromInitList(
 TemplateDecl *Template, MutableArrayRef ParamTypes,
 SourceLocation Loc) {
+  llvm::FoldingSetNodeID ID;
+  ID.AddPointer(Template);
+  for (auto &T : ParamTypes)
+T.getCanonicalType().Profile(ID);
+  unsigned Hash = ID.ComputeHash();
+  
+  auto Found = AggregateDeductionCandidates.find(Hash);
+  if (Found != AggregateDeductionCandidates.end()) {
+CXXDeductionGuideDecl *GD = Found->getSecond();
+return GD->getDescribedFunctionTemplate();
+  }
+  
+  // if (auto *AliasTemplate = 
llvm::dyn_cast(Template)) {
+  //   DeclareImplicitDeductionGuidesForTypeAlias(*this, AliasTemplate, Loc);
+  //   return;
+  // }
+
   if (CXXRecordDecl *DefRecord =
   cast(Template->getTemplatedDecl())->getDefinition()) {
 if (TemplateDecl *DescribedTemplate =
@@ -3050,10 +3067,13 @@ FunctionTemplateDecl 
*Sema::DeclareImplicitDeductionGuideFromInitList(
   Transform.NestedPattern ? Transform.NestedPattern : Transform.Template;
   ContextRAII SavedContext(*this, Pattern->getTemplatedDecl());
 
-  auto *DG = cast(
+  auto *FTD = cast(
   Transform.buildSimpleDeductionGuide(ParamTypes));
   SavedContext.pop();
-  return DG;
+  auto *GD = cast(FTD->getTemplatedDecl());
+  GD->setDeductionCandidateKind(DeductionCandidate::Aggregate);
+  AggregateDeductionCandidates[Hash] = GD;
+  return FTD;
 }
 
 void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,

>From 727eef3591f29676391f60fe688e9706ad2560b4 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Tue, 19 Mar 2024 23:07:09 +0100
Subject: [PATCH 2/4] [clang] CTAD: build aggregate deduction guides for alias
 templates.

Fixes https://github.com/llvm/llvm-project/issues/85767.
---
 clang/lib/Sema/SemaInit.cpp |   3 +-
 clang/lib/Sema/SemaTemplate.cpp | 196 +++-
 clang/test/SemaTemplate/deduction-guide.cpp |  12 ++
 3 files changed, 160 insertions(+), 51 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 0b1471449d842d..f76afc167

[clang] [clang] CTAD: build aggregate deduction guides for alias templates. (PR #85904)

2024-04-05 Thread Haojian Wu via cfe-commits

@@ -9713,7 +9713,8 @@ class Sema final {
   /// not already done so.
   void DeclareImplicitDeductionGuides(TemplateDecl *Template,
   SourceLocation Loc);
-  FunctionTemplateDecl *DeclareImplicitDeductionGuideFromInitList(
+  /// Declare aggregate deduction guides.

hokein wrote:

OK, I removed it. 

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


[clang] [Sema] Remove the duplicated `DeduceTemplateArguments` for partial specialization, NFC (PR #87782)

2024-04-05 Thread Erich Keane via cfe-commits
https://github.com/erichkeane approved this pull request.


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


[clang] [OpenACC][NFC] Add OpenACC Clause AST Nodes/infrastructure (PR #87675)

2024-04-05 Thread Erich Keane via cfe-commits
https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/87675

>From 2e05458175478002a14c9316a7fde66f7301dd94 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Thu, 4 Apr 2024 10:59:34 -0700
Subject: [PATCH 1/2] [OpenACC][NFC] Add OpenACC Clause AST
 Nodes/infrastructure

As a first step in adding clause support for OpenACC to Semantic
Analysis, this patch adds the 'base' AST nodes required for clauses.

This patch has no functional effect at the moment, but followup patches
will add the semantic analysis of clauses (plus individual clauses).
---
 clang/include/clang/AST/ASTNodeTraverser.h|  13 ++
 clang/include/clang/AST/JSONNodeDumper.h  |   1 +
 clang/include/clang/AST/OpenACCClause.h   | 135 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |  13 +-
 clang/include/clang/AST/StmtOpenACC.h |  53 +--
 clang/include/clang/AST/TextNodeDumper.h  |   2 +
 .../clang/Serialization/ASTRecordReader.h |   7 +
 .../clang/Serialization/ASTRecordWriter.h |   7 +
 clang/lib/AST/CMakeLists.txt  |   1 +
 clang/lib/AST/JSONNodeDumper.cpp  |   2 +
 clang/lib/AST/OpenACCClause.cpp   |  17 +++
 clang/lib/AST/StmtOpenACC.cpp |  19 +--
 clang/lib/AST/StmtPrinter.cpp |   8 +-
 clang/lib/AST/StmtProfile.cpp |  21 ++-
 clang/lib/AST/TextNodeDumper.cpp  |  23 ++-
 clang/lib/Sema/SemaOpenACC.cpp|   3 +-
 clang/lib/Serialization/ASTReader.cpp |  66 +
 clang/lib/Serialization/ASTReaderStmt.cpp |  10 +-
 clang/lib/Serialization/ASTWriter.cpp |  62 
 clang/lib/Serialization/ASTWriterStmt.cpp |   3 +-
 20 files changed, 438 insertions(+), 28 deletions(-)
 create mode 100644 clang/include/clang/AST/OpenACCClause.h
 create mode 100644 clang/lib/AST/OpenACCClause.cpp

diff --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index 06d67e9cba9536..94e7dd817809dd 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -53,6 +53,7 @@ struct {
   void Visit(TypeLoc);
   void Visit(const Decl *D);
   void Visit(const CXXCtorInitializer *Init);
+  void Visit(const OpenACCClause *C);
   void Visit(const OMPClause *C);
   void Visit(const BlockDecl::Capture &C);
   void Visit(const GenericSelectionExpr::ConstAssociation &A);
@@ -239,6 +240,13 @@ class ASTNodeTraverser
 });
   }
 
+  void Visit(const OpenACCClause *C) {
+getNodeDelegate().AddChild([=] {
+  getNodeDelegate().Visit(C);
+  // TODO OpenACC: Switch on clauses that have children, and add them.
+});
+  }
+
   void Visit(const OMPClause *C) {
 getNodeDelegate().AddChild([=] {
   getNodeDelegate().Visit(C);
@@ -799,6 +807,11 @@ class ASTNodeTraverser
   Visit(C);
   }
 
+  void VisitOpenACCConstructStmt(const OpenACCConstructStmt *Node) {
+for (const auto *C : Node->clauses())
+  Visit(C);
+  }
+
   void VisitInitListExpr(const InitListExpr *ILE) {
 if (auto *Filler = ILE->getArrayFiller()) {
   Visit(Filler, "array_filler");
diff --git a/clang/include/clang/AST/JSONNodeDumper.h 
b/clang/include/clang/AST/JSONNodeDumper.h
index dde70dde2fa2be..7a60f362650ca0 100644
--- a/clang/include/clang/AST/JSONNodeDumper.h
+++ b/clang/include/clang/AST/JSONNodeDumper.h
@@ -203,6 +203,7 @@ class JSONNodeDumper
   void Visit(const TemplateArgument &TA, SourceRange R = {},
  const Decl *From = nullptr, StringRef Label = {});
   void Visit(const CXXCtorInitializer *Init);
+  void Visit(const OpenACCClause *C);
   void Visit(const OMPClause *C);
   void Visit(const BlockDecl::Capture &C);
   void Visit(const GenericSelectionExpr::ConstAssociation &A);
diff --git a/clang/include/clang/AST/OpenACCClause.h 
b/clang/include/clang/AST/OpenACCClause.h
new file mode 100644
index 00..06a0098bbda4cd
--- /dev/null
+++ b/clang/include/clang/AST/OpenACCClause.h
@@ -0,0 +1,135 @@
+//===- OpenACCClause.h - Classes for OpenACC clauses *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// \file
+// This file defines OpenACC AST classes for clauses.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_AST_OPENACCCLAUSE_H
+#define LLVM_CLANG_AST_OPENACCCLAUSE_H
+#include "clang/AST/ASTContext.h"
+#include "clang/Basic/OpenACCKinds.h"
+
+namespace clang {
+/// This is the base type for all OpenACC Clauses.
+class OpenACCClause {
+  OpenACCClauseKind Kind;
+  SourceRange Location;
+
+protected:
+  OpenACCClause(OpenACCClauseKind K, SourceLocation BeginLoc,
+SourceLocation EndLoc)
+  : K

[clang] [clang] CTAD: build aggregate deduction guides for alias templates. (PR #85904)

2024-04-05 Thread Haojian Wu via cfe-commits

@@ -2792,6 +2811,24 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
   } else {
 assert(false && "unhandled RHS type of the alias");
   }
+  return {Template, AliasRhsTemplateArgs};
+}
+
+// Build deduction guides for a type alias template.
+void DeclareImplicitDeductionGuidesForTypeAlias(
+Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate, SourceLocation Loc) {
+  if (AliasTemplate->isInvalidDecl())
+return;
+  auto &Context = SemaRef.Context;
+  // FIXME: if there is an explicit deduction guide after the first use of the

hokein wrote:

Emitting a diagnostic is an option, but I think it's suboptimal, and it is not 
trivial to detect such cases. I prefer to fix the issue directly rather than 
implementing a diagnostic that would eventually be removed.

Do you consider this case to be critical for the clang trunk at the moment? I 
believe we should fix it before the next clang release, and we still have some 
time to do so.

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


[clang] [clang] CTAD: build aggregate deduction guides for alias templates. (PR #85904)

2024-04-05 Thread Erich Keane via cfe-commits

@@ -2792,6 +2811,24 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
   } else {
 assert(false && "unhandled RHS type of the alias");
   }
+  return {Template, AliasRhsTemplateArgs};
+}
+
+// Build deduction guides for a type alias template.
+void DeclareImplicitDeductionGuidesForTypeAlias(
+Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate, SourceLocation Loc) {
+  if (AliasTemplate->isInvalidDecl())
+return;
+  auto &Context = SemaRef.Context;
+  // FIXME: if there is an explicit deduction guide after the first use of the

erichkeane wrote:

WOULD we remove said diagnostic?  It seems that:
`If there are some explicit deduction guides after the first usage, they are 
not covered and are not added to the overload candidate sets.`

means that adding an explicit deduction guide after first use effectively 'does 
nothing'.  

That said, I'm ok having us do it (or whatever we do next) in a followup patch.

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


[clang] [clang] CTAD: build aggregate deduction guides for alias templates. (PR #85904)

2024-04-05 Thread Vlad Serebrennikov via cfe-commits
https://github.com/Endilll commented:

`Sema.h` changes look good to me.

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


[clang] f905935 - Fix tbaa.struct metadata for bitfields using big endian. (#87753)

2024-04-05 Thread via cfe-commits
Author: Julian Nagele
Date: 2024-04-05T15:26:41+01:00
New Revision: f905935ff96da4c04d2a6bf431340fd16e3a14ea

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

LOG: Fix tbaa.struct metadata for bitfields using big endian. (#87753)

When generating tbaa.struct metadata we treat multiple adjacent
bitfields as a single "field", with one corresponding entry in the
metadata. At the moment this is achieved by adding an entry for the
first bitfield in the run using its StorageSize and skipping the
remaining bitfields. The problem is that "first" is determined by
checking that the Offset of the field in the run is 0, which breaks for
big endian.

PR: https://github.com/llvm/llvm-project/pull/87753

Added: 


Modified: 
clang/lib/CodeGen/CodeGenTBAA.cpp
clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index a1e14c5f0a8c78..837bf725da388a 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/LLVMContext.h"
@@ -319,7 +320,13 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
   // base type.
   if ((*i)->isBitField()) {
 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
-if (Info.Offset != 0)
+// For big endian targets the first bitfield in the consecutive run is
+// at the most-significant end; see CGRecordLowering::setBitFieldInfo
+// for more information.
+bool IsBE = Context.getTargetInfo().isBigEndian();
+bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0
+: Info.Offset == 0;
+if (!IsFirst)
   continue;
 unsigned CurrentBitFieldSize = Info.StorageSize;
 uint64_t Size =

diff  --git a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp 
b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
index 80884b49ddc669..e8bb46982537bb 100644
--- a/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
+++ b/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp
@@ -1,13 +1,10 @@
 // RUN: %clang_cc1 -triple aarch64_be-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-BE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 // RUN: %clang_cc1 -triple aarch64-apple-darwin -emit-llvm -o - -O1 %s | \
-// RUN: FileCheck -check-prefixes=CHECK,CHECK-LE %s
+// RUN: FileCheck -check-prefixes=CHECK %s
 //
 // Check that TBAA metadata for structs containing bitfields is
 // consistent between big and little endian layouts.
-//
-// FIXME: The metadata below is invalid for the big endian layout: the
-// start offset of 2 is incorrect.
 
 struct NamedBitfields {
   int f1 : 8;
@@ -28,8 +25,7 @@ void copy(NamedBitfields *a1, NamedBitfields *a2) {
   *a1 = *a2;
 }
 
-// CHECK-BE: [[TBAA_STRUCT2]] = !{i64 2, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
-// CHECK-LE: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 
4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
+// CHECK: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 4, 
[[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
 // CHECK: [[META3]] = !{[[META4:![0-9]+]], [[META4]], i64 0}
 // CHECK: [[META4]] = !{!"omnipotent char", [[META5:![0-9]+]], i64 0}
 // CHECK: [[META5]] = !{!"Simple C++ TBAA"}



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


[clang] Fix tbaa.struct metadata for bitfields using big endian. (PR #87753)

2024-04-05 Thread Florian Hahn via cfe-commits
https://github.com/fhahn closed https://github.com/llvm/llvm-project/pull/87753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   >