[clang] [llvm] [LLVM] Fix incorrect alignment on AMDGPU variadics (PR #96370)

2024-06-22 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> Here, because the minimum alignment is 4, we will only increment the
buffer by 4, 

It should be incrementing by the size? 4 byte aligned access of 8 byte type 
should work fine

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


[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)

2024-06-22 Thread Zhikai Zeng via cfe-commits

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

>From 64ee10bf71d79c97f45779dbbd9f74e85a5676ee Mon Sep 17 00:00:00 2001
From: Backl1ght 
Date: Sat, 15 Jun 2024 16:56:00 +0800
Subject: [PATCH] fix

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  2 +-
 .../expr.prim.req/compound-requirement.cpp| 36 +++
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ac0fa0141b47..9c8f8c4a4fbaf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -914,6 +914,7 @@ Bug Fixes to C++ Support
 - Clang now diagnoses explicit specializations with storage class specifiers 
in all contexts.
 - Fix an assertion failure caused by parsing a lambda used as a default 
argument for the value of a
   forward-declared class. (#GH93512).
+- Fixed a bug in access checking inside return-type-requirement of compound 
requirements. (#GH93788).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 863cc53c55afa..1fe1fe9d4f833 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2735,7 +2735,7 @@ 
TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
 if (TPLInst.isInvalid())
   return nullptr;
 TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL);
-if (!TPL)
+if (!TPL || Trap.hasErrorOccurred())
   TransRetReq.emplace(createSubstDiag(SemaRef, Info,
   [&] (llvm::raw_ostream& OS) {
   RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
diff --git 
a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
index b7366207882f9..dc0e84280e056 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
@@ -189,3 +189,39 @@ namespace std_example {
   template struct C5_check {}; // expected-note{{because 'short' does 
not satisfy 'C5'}}
   using c5 = C5_check; // expected-error{{constraints not satisfied for 
class template 'C5_check' [with T = short]}}
 }
+
+namespace access_checks {
+namespace in_return_type_requirement {
+
+// https://github.com/llvm/llvm-project/issues/93788
+template 
+concept is_assignable = requires(From from, To to) {
+  from = to;
+};
+
+template 
+class trait {
+ public:
+  using public_type = int;
+ private:
+  using private_type = int;
+};
+
+template 
+concept has_field = requires(T t) {
+  { t.field } -> is_assignable::private_type>;  // 
expected-note {{'private_type' is a private member}}
+};
+template 
+concept has_field2 = requires(T t) {
+  { t.field } -> is_assignable::public_type>;
+};
+
+struct A {
+  int field;
+};
+static_assert(has_field); // expected-error {{static assertion failed}} \
+ // expected-note {{because 'A' does not satisfy 
'has_field'}}
+static_assert(has_field2);
+
+}  // namespace access_checks
+}  // namespace in_return_type_requirement

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


[clang] a091bfe - [Clang] fix access checking inside return-type-requirement of compound requirements (#95651)

2024-06-22 Thread via cfe-commits

Author: Zhikai Zeng
Date: 2024-06-22T15:31:03+08:00
New Revision: a091bfe71fdde4358dbfc73926f875cb05121c00

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

LOG: [Clang] fix access checking inside return-type-requirement of compound 
requirements (#95651)

fixes https://github.com/llvm/llvm-project/issues/93788 .

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ac0fa0141b47..9c8f8c4a4fbaf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -914,6 +914,7 @@ Bug Fixes to C++ Support
 - Clang now diagnoses explicit specializations with storage class specifiers 
in all contexts.
 - Fix an assertion failure caused by parsing a lambda used as a default 
argument for the value of a
   forward-declared class. (#GH93512).
+- Fixed a bug in access checking inside return-type-requirement of compound 
requirements. (#GH93788).
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 863cc53c55afa..1fe1fe9d4f833 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2735,7 +2735,7 @@ 
TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
 if (TPLInst.isInvalid())
   return nullptr;
 TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL);
-if (!TPL)
+if (!TPL || Trap.hasErrorOccurred())
   TransRetReq.emplace(createSubstDiag(SemaRef, Info,
   [&] (llvm::raw_ostream& OS) {
   RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()

diff  --git 
a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
index b7366207882f9..dc0e84280e056 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
@@ -189,3 +189,39 @@ namespace std_example {
   template struct C5_check {}; // expected-note{{because 'short' does 
not satisfy 'C5'}}
   using c5 = C5_check; // expected-error{{constraints not satisfied for 
class template 'C5_check' [with T = short]}}
 }
+
+namespace access_checks {
+namespace in_return_type_requirement {
+
+// https://github.com/llvm/llvm-project/issues/93788
+template 
+concept is_assignable = requires(From from, To to) {
+  from = to;
+};
+
+template 
+class trait {
+ public:
+  using public_type = int;
+ private:
+  using private_type = int;
+};
+
+template 
+concept has_field = requires(T t) {
+  { t.field } -> is_assignable::private_type>;  // 
expected-note {{'private_type' is a private member}}
+};
+template 
+concept has_field2 = requires(T t) {
+  { t.field } -> is_assignable::public_type>;
+};
+
+struct A {
+  int field;
+};
+static_assert(has_field); // expected-error {{static assertion failed}} \
+ // expected-note {{because 'A' does not satisfy 
'has_field'}}
+static_assert(has_field2);
+
+}  // namespace access_checks
+}  // namespace in_return_type_requirement



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


[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)

2024-06-22 Thread Zhikai Zeng via cfe-commits

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


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

2024-06-22 Thread Rajveer Singh Bharadwaj via cfe-commits


@@ -1392,7 +1392,8 @@ class CXXRecordDecl : public RecordDecl {
   bool allowConstDefaultInit() const {
 return !data().HasUninitializedFields ||
!(data().HasDefaultedDefaultConstructor ||
- needsImplicitDefaultConstructor());
+ needsImplicitDefaultConstructor()) ||
+   hasInClassInitializer();

Rajveer100 wrote:

> This is a language extension so we get to choose its semantics, but I think 
> the most logical choice is to reject because the union member is not _fully_ 
> initialized.

At the moment, this gets accepted.

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


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

2024-06-22 Thread Rajveer Singh Bharadwaj via cfe-commits


@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s

Rajveer100 wrote:

Indeed.

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


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

2024-06-22 Thread Rajveer Singh Bharadwaj via cfe-commits


@@ -1392,7 +1392,8 @@ class CXXRecordDecl : public RecordDecl {
   bool allowConstDefaultInit() const {
 return !data().HasUninitializedFields ||
!(data().HasDefaultedDefaultConstructor ||
- needsImplicitDefaultConstructor());
+ needsImplicitDefaultConstructor()) ||
+   hasInClassInitializer();

Rajveer100 wrote:

The two tests that were broken:

```c++
struct some_init {
  int a = 0;
  int b;
  int c = 0;
};

void constobjs() {
  // ...
  const some_init si;
  // ...
}
```

```c++
struct Ints2 {
  int a = 10;
  int b;
};
constexpr Ints2 ints22;
```

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


[clang] [llvm] [Clang] Fix definition of layout-compatible to ignore empty classes (PR #92103)

2024-06-22 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/92103

>From 5908130604728b9aa9b70eeb2523d368df08e68d Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Tue, 14 May 2024 08:28:19 +0100
Subject: [PATCH 1/4] [Clang] Fix definition of layout-compatible to ignore
 empty classes

Also changes the behaviour of __builtin_is_layout_compatible

None of the historic nor the current definition of layout-compatible classes 
mention anything about base classes (other than implicitly through being 
standard-layout) and are defined in terms of members, not direct members.
---
 clang/include/clang/AST/DeclCXX.h  |  7 
 clang/lib/AST/DeclCXX.cpp  | 36 +
 clang/lib/Sema/SemaChecking.cpp| 63 +-
 clang/test/SemaCXX/type-traits.cpp | 11 ++
 llvm/include/llvm/ADT/STLExtras.h  |  6 +++
 5 files changed, 79 insertions(+), 44 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index fb52ac804849d..60a5005c51a5e 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1229,6 +1229,13 @@ class CXXRecordDecl : public RecordDecl {
   /// C++11 [class]p7, specifically using the C++11 rules without any DRs.
   bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; }
 
+  /// If this is a standard-layout class or union, any and all data members 
will
+  /// be declared in the same type.
+  ///
+  /// This retrieves the type if this class has any data members,
+  /// or the current class if there is no class with fields.
+  const CXXRecordDecl *getStandardLayoutBaseWithFields() const;
+
   /// Determine whether this class, or any of its class subobjects,
   /// contains a mutable field.
   bool hasMutableFields() const { return data().HasMutableFields; }
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 75c441293d62e..ab032a4595d46 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -561,6 +561,42 @@ void CXXRecordDecl::addedClassSubobject(CXXRecordDecl 
*Subobj) {
 data().StructuralIfLiteral = false;
 }
 
+const CXXRecordDecl *CXXRecordDecl::getStandardLayoutBaseWithFields() const {
+#ifndef NDEBUG
+  {
+assert(
+isStandardLayout() &&
+"getStandardLayoutBaseWithFields called on a non-standard-layout 
type");
+unsigned NumberOfBasesWithFields = 0;
+if (!field_empty())
+  ++NumberOfBasesWithFields;
+std::set UniqueBases;
+forallBases([&](const CXXRecordDecl *Base) -> bool {
+  if (!Base->field_empty())
+++NumberOfBasesWithFields;
+  assert(
+  UniqueBases.insert(Base->getCanonicalDecl()).second &&
+  "Standard layout struct has multiple base classes of the same type");
+  return true;
+});
+assert(NumberOfBasesWithFields <= 1 &&
+   "Standard layout struct has fields declared in more than one 
class");
+  }
+#endif
+  if (!field_empty())
+return this;
+  const CXXRecordDecl *Result = this;
+  forallBases([&](const CXXRecordDecl *Base) -> bool {
+if (!Base->field_empty()) {
+  // This is the base where the fields are declared; return early
+  Result = Base;
+  return false;
+}
+return true;
+  });
+  return Result;
+}
+
 bool CXXRecordDecl::hasConstexprDestructor() const {
   auto *Dtor = getDestructor();
   return Dtor ? Dtor->isConstexpr() : defaultedDestructorIsConstexpr();
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ecd1821651140..acd142c1932ad 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -19084,7 +19084,8 @@ void Sema::DiagnoseSelfMove(const Expr *LHSExpr, const 
Expr *RHSExpr,
 static bool isLayoutCompatible(ASTContext &C, QualType T1, QualType T2);
 
 /// Check if two enumeration types are layout-compatible.
-static bool isLayoutCompatible(ASTContext &C, EnumDecl *ED1, EnumDecl *ED2) {
+static bool isLayoutCompatible(ASTContext &C, const EnumDecl *ED1,
+   const EnumDecl *ED2) {
   // C++11 [dcl.enum] p8:
   // Two enumeration types are layout-compatible if they have the same
   // underlying type.
@@ -19095,8 +19096,8 @@ static bool isLayoutCompatible(ASTContext &C, EnumDecl 
*ED1, EnumDecl *ED2) {
 /// Check if two fields are layout-compatible.
 /// Can be used on union members, which are exempt from alignment requirement
 /// of common initial sequence.
-static bool isLayoutCompatible(ASTContext &C, FieldDecl *Field1,
-   FieldDecl *Field2,
+static bool isLayoutCompatible(ASTContext &C, const FieldDecl *Field1,
+   const FieldDecl *Field2,
bool AreUnionMembers = false) {
   [[maybe_unused]] const Type *Field1Parent =
   Field1->getParent()->getTypeForDecl();
@@ -19139,52 +19140,26 @@ static bool isLayoutCompatible(ASTContext &C, 
FieldDecl *Field1,
 
 /// Check if two standa

[clang] [llvm] [Clang] Fix definition of layout-compatible to ignore empty classes (PR #92103)

2024-06-22 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

https://github.com/llvm/llvm-project/blob/b0ae923ada836fa2c9114ac2c5afb39466f49fe0/clang/docs/ReleaseNotes.rst#L210-L212

Should be enough for ReleaseNotes, since not much has changed since Clang 18

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


[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)

2024-06-22 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/94352

>From ff839bef048a65760f4cd0e9abafe11cfebd9362 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 4 Jun 2024 21:08:27 +0800
Subject: [PATCH 1/5] [RISCV] Add support for getHostCPUFeatures using hwprobe

Co-authored-by: Yangyu Chen 
---
 llvm/lib/TargetParser/Host.cpp | 68 ++
 1 file changed, 68 insertions(+)

diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 68155acd9e5bc..b4a13b38eb380 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1998,6 +1998,74 @@ bool sys::getHostCPUFeatures(StringMap &Features) {
 
   return true;
 }
+#elif defined(__linux__) && defined(__riscv)
+#ifdef __has_include
+#if __has_include()
+#include 
+#endif
+#endif
+bool sys::getHostCPUFeatures(StringMap &Features) {
+#ifdef RISCV_HWPROBE_KEY_MVENDORID
+  riscv_hwprobe Query[2]{
+  {RISCV_HWPROBE_KEY_IMA_EXT_0, 0},
+  {RISCV_HWPROBE_KEY_CPUPERF_0, 0},
+  };
+  int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query,
+/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, 
/*flags=*/0);
+  if (Ret != 0)
+return false;
+
+  uint64_t ExtMask = Query[0].value;
+  Features["f"] = ExtMask & RISCV_HWPROBE_IMA_FD;
+  Features["d"] = ExtMask & RISCV_HWPROBE_IMA_FD;
+  Features["c"] = ExtMask & RISCV_HWPROBE_IMA_C;
+  Features["v"] = ExtMask & RISCV_HWPROBE_IMA_V;
+  Features["zba"] = ExtMask & RISCV_HWPROBE_IMA_ZBA;
+  Features["zbb"] = ExtMask & RISCV_HWPROBE_IMA_ZBB;
+  Features["zbs"] = ExtMask & RISCV_HWPROBE_IMA_ZBS;
+  Features["zicboz"] = ExtMask & RISCV_HWPROBE_IMA_ZICBOZ;
+  Features["zbc"] = ExtMask & RISCV_HWPROBE_IMA_ZBC;
+  Features["zbkb"] = ExtMask & RISCV_HWPROBE_IMA_ZBKB;
+  Features["zbkc"] = ExtMask & RISCV_HWPROBE_IMA_ZBKC;
+  Features["zbkx"] = ExtMask & RISCV_HWPROBE_IMA_ZBKX;
+  Features["zknd"] = ExtMask & RISCV_HWPROBE_IMA_ZKND;
+  Features["zkne"] = ExtMask & RISCV_HWPROBE_IMA_ZKNE;
+  Features["zknh"] = ExtMask & RISCV_HWPROBE_IMA_ZKNH;
+  Features["zksed"] = ExtMask & RISCV_HWPROBE_IMA_ZKSED;
+  Features["zksh"] = ExtMask & RISCV_HWPROBE_IMA_ZKSH;
+  Features["zkt"] = ExtMask & RISCV_HWPROBE_IMA_ZKT;
+  Features["zvbb"] = ExtMask & RISCV_HWPROBE_IMA_ZVBB;
+  Features["zvbc"] = ExtMask & RISCV_HWPROBE_IMA_ZVBC;
+  Features["zvkb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKB;
+  Features["zvkg"] = ExtMask & RISCV_HWPROBE_IMA_ZVKG;
+  Features["zvkned"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNED;
+  Features["zvknha"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHA;
+  Features["zvknhb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHB;
+  Features["zvksed"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSED;
+  Features["zvksh"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSH;
+  Features["zvkt"] = ExtMask & RISCV_HWPROBE_IMA_ZVKT;
+  Features["zfh"] = ExtMask & RISCV_HWPROBE_IMA_ZFH;
+  Features["zfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZFHMIN;
+  Features["zihintntl"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTNTL;
+  Features["zvfh"] = ExtMask & RISCV_HWPROBE_IMA_ZVFH;
+  Features["zvfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZVFHMIN;
+  Features["zfa"] = ExtMask & RISCV_HWPROBE_IMA_ZFA;
+  Features["ztso"] = ExtMask & RISCV_HWPROBE_IMA_ZTSO;
+  Features["zacas"] = ExtMask & RISCV_HWPROBE_IMA_ZACAS;
+  Features["zicond"] = ExtMask & RISCV_HWPROBE_IMA_ZICOND;
+  Features["zihintpause"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTPAUSE;
+
+  uint64_t MisalignedMask = Query[1].value;
+  if (MisalignedMask == RISCV_HWPROBE_MISALIGNED_FAST) {
+Features["unaligned-scalar-mem"] = true;
+Features["unaligned-vector-mem"] = true;
+  }
+
+  return true;
+#else
+  return false;
+#endif
+}
 #else
 bool sys::getHostCPUFeatures(StringMap &Features) { return false; }
 #endif

>From a2fa6e3d64d3a1e2a8e3a7af91068bdb1fda28b1 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 4 Jun 2024 22:10:55 +0800
Subject: [PATCH 2/5] [RISCV] Address review comments.

---
 llvm/lib/TargetParser/Host.cpp | 112 +++--
 1 file changed, 52 insertions(+), 60 deletions(-)

diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index b4a13b38eb380..ec275c0a7fded 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1999,72 +1999,64 @@ bool sys::getHostCPUFeatures(StringMap &Features) 
{
   return true;
 }
 #elif defined(__linux__) && defined(__riscv)
-#ifdef __has_include
-#if __has_include()
-#include 
-#endif
-#endif
+// struct riscv_hwprobe
+struct RISCVHwProbe {
+  int64_t Key;
+  uint64_t Value;
+};
 bool sys::getHostCPUFeatures(StringMap &Features) {
-#ifdef RISCV_HWPROBE_KEY_MVENDORID
-  riscv_hwprobe Query[2]{
-  {RISCV_HWPROBE_KEY_IMA_EXT_0, 0},
-  {RISCV_HWPROBE_KEY_CPUPERF_0, 0},
-  };
-  int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query,
-/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, 
/*flags=*/0);
+  RISCVHwProbe Query[]{{/*RISCV_HWPROBE_KEY_IMA_EXT_0=*/4, 0}};
+  int Re

[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)

2024-06-22 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/94352

>From ff839bef048a65760f4cd0e9abafe11cfebd9362 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 4 Jun 2024 21:08:27 +0800
Subject: [PATCH 1/6] [RISCV] Add support for getHostCPUFeatures using hwprobe

Co-authored-by: Yangyu Chen 
---
 llvm/lib/TargetParser/Host.cpp | 68 ++
 1 file changed, 68 insertions(+)

diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 68155acd9e5bc..b4a13b38eb380 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1998,6 +1998,74 @@ bool sys::getHostCPUFeatures(StringMap &Features) {
 
   return true;
 }
+#elif defined(__linux__) && defined(__riscv)
+#ifdef __has_include
+#if __has_include()
+#include 
+#endif
+#endif
+bool sys::getHostCPUFeatures(StringMap &Features) {
+#ifdef RISCV_HWPROBE_KEY_MVENDORID
+  riscv_hwprobe Query[2]{
+  {RISCV_HWPROBE_KEY_IMA_EXT_0, 0},
+  {RISCV_HWPROBE_KEY_CPUPERF_0, 0},
+  };
+  int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query,
+/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, 
/*flags=*/0);
+  if (Ret != 0)
+return false;
+
+  uint64_t ExtMask = Query[0].value;
+  Features["f"] = ExtMask & RISCV_HWPROBE_IMA_FD;
+  Features["d"] = ExtMask & RISCV_HWPROBE_IMA_FD;
+  Features["c"] = ExtMask & RISCV_HWPROBE_IMA_C;
+  Features["v"] = ExtMask & RISCV_HWPROBE_IMA_V;
+  Features["zba"] = ExtMask & RISCV_HWPROBE_IMA_ZBA;
+  Features["zbb"] = ExtMask & RISCV_HWPROBE_IMA_ZBB;
+  Features["zbs"] = ExtMask & RISCV_HWPROBE_IMA_ZBS;
+  Features["zicboz"] = ExtMask & RISCV_HWPROBE_IMA_ZICBOZ;
+  Features["zbc"] = ExtMask & RISCV_HWPROBE_IMA_ZBC;
+  Features["zbkb"] = ExtMask & RISCV_HWPROBE_IMA_ZBKB;
+  Features["zbkc"] = ExtMask & RISCV_HWPROBE_IMA_ZBKC;
+  Features["zbkx"] = ExtMask & RISCV_HWPROBE_IMA_ZBKX;
+  Features["zknd"] = ExtMask & RISCV_HWPROBE_IMA_ZKND;
+  Features["zkne"] = ExtMask & RISCV_HWPROBE_IMA_ZKNE;
+  Features["zknh"] = ExtMask & RISCV_HWPROBE_IMA_ZKNH;
+  Features["zksed"] = ExtMask & RISCV_HWPROBE_IMA_ZKSED;
+  Features["zksh"] = ExtMask & RISCV_HWPROBE_IMA_ZKSH;
+  Features["zkt"] = ExtMask & RISCV_HWPROBE_IMA_ZKT;
+  Features["zvbb"] = ExtMask & RISCV_HWPROBE_IMA_ZVBB;
+  Features["zvbc"] = ExtMask & RISCV_HWPROBE_IMA_ZVBC;
+  Features["zvkb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKB;
+  Features["zvkg"] = ExtMask & RISCV_HWPROBE_IMA_ZVKG;
+  Features["zvkned"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNED;
+  Features["zvknha"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHA;
+  Features["zvknhb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHB;
+  Features["zvksed"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSED;
+  Features["zvksh"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSH;
+  Features["zvkt"] = ExtMask & RISCV_HWPROBE_IMA_ZVKT;
+  Features["zfh"] = ExtMask & RISCV_HWPROBE_IMA_ZFH;
+  Features["zfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZFHMIN;
+  Features["zihintntl"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTNTL;
+  Features["zvfh"] = ExtMask & RISCV_HWPROBE_IMA_ZVFH;
+  Features["zvfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZVFHMIN;
+  Features["zfa"] = ExtMask & RISCV_HWPROBE_IMA_ZFA;
+  Features["ztso"] = ExtMask & RISCV_HWPROBE_IMA_ZTSO;
+  Features["zacas"] = ExtMask & RISCV_HWPROBE_IMA_ZACAS;
+  Features["zicond"] = ExtMask & RISCV_HWPROBE_IMA_ZICOND;
+  Features["zihintpause"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTPAUSE;
+
+  uint64_t MisalignedMask = Query[1].value;
+  if (MisalignedMask == RISCV_HWPROBE_MISALIGNED_FAST) {
+Features["unaligned-scalar-mem"] = true;
+Features["unaligned-vector-mem"] = true;
+  }
+
+  return true;
+#else
+  return false;
+#endif
+}
 #else
 bool sys::getHostCPUFeatures(StringMap &Features) { return false; }
 #endif

>From a2fa6e3d64d3a1e2a8e3a7af91068bdb1fda28b1 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 4 Jun 2024 22:10:55 +0800
Subject: [PATCH 2/6] [RISCV] Address review comments.

---
 llvm/lib/TargetParser/Host.cpp | 112 +++--
 1 file changed, 52 insertions(+), 60 deletions(-)

diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index b4a13b38eb380..ec275c0a7fded 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1999,72 +1999,64 @@ bool sys::getHostCPUFeatures(StringMap &Features) 
{
   return true;
 }
 #elif defined(__linux__) && defined(__riscv)
-#ifdef __has_include
-#if __has_include()
-#include 
-#endif
-#endif
+// struct riscv_hwprobe
+struct RISCVHwProbe {
+  int64_t Key;
+  uint64_t Value;
+};
 bool sys::getHostCPUFeatures(StringMap &Features) {
-#ifdef RISCV_HWPROBE_KEY_MVENDORID
-  riscv_hwprobe Query[2]{
-  {RISCV_HWPROBE_KEY_IMA_EXT_0, 0},
-  {RISCV_HWPROBE_KEY_CPUPERF_0, 0},
-  };
-  int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query,
-/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, 
/*flags=*/0);
+  RISCVHwProbe Query[]{{/*RISCV_HWPROBE_KEY_IMA_EXT_0=*/4, 0}};
+  int Re

[clang] [Clang][Sema] qualifier should be transformed (PR #94725)

2024-06-22 Thread Qizhi Hu via cfe-commits

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

>From 8327ee1afef04480a1a18eef169f24906e432e87 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 7 Jun 2024 14:04:52 +0800
Subject: [PATCH] [Clang][Sema] qualifier should be transformed

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/Sema/TreeTransform.h| 18 +
 .../SemaCXX/many-template-parameter-lists.cpp |  6 +++---
 .../PR12884_original_no_crash.cpp | 20 +++
 clang/test/SemaTemplate/PR91677.cpp   | 14 +
 clang/test/SemaTemplate/instantiate-scope.cpp |  5 +
 .../SemaTemplate/typename-specifier-3.cpp |  7 ---
 7 files changed, 61 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/SemaTemplate/PR12884_original_no_crash.cpp
 create mode 100644 clang/test/SemaTemplate/PR91677.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ac0fa0141b47..8f217990a494c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -914,6 +914,7 @@ Bug Fixes to C++ Support
 - Clang now diagnoses explicit specializations with storage class specifiers 
in all contexts.
 - Fix an assertion failure caused by parsing a lambda used as a default 
argument for the value of a
   forward-declared class. (#GH93512).
+- Clang now transforms qualifier of template name. (#91677).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index cf4e80399632b..b3872a18da4fa 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -4568,6 +4568,24 @@ 
TreeTransform::TransformTemplateName(CXXScopeSpec &SS,
   if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
 TemplateDecl *Template = QTN->getUnderlyingTemplate().getAsTemplateDecl();
 assert(Template && "qualified template name must refer to a template");
+if (QTN->getQualifier()) {
+  CXXScopeSpec QualifierSS;
+  QualifierSS.MakeTrivial(getSema().getASTContext(), QTN->getQualifier(),
+  NameLoc);
+  NestedNameSpecifierLoc QualifierLoc =
+  QualifierSS.getWithLocInContext(getSema().getASTContext());
+  NestedNameSpecifierLoc TransformedQualifierLoc =
+  getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
+  if (!TransformedQualifierLoc)
+return Name;
+  if (getDerived().AlwaysRebuild() ||
+  QualifierLoc != TransformedQualifierLoc) {
+SS.Adopt(TransformedQualifierLoc);
+return getDerived().RebuildTemplateName(
+SS, SourceLocation(), *Template->getIdentifier(), NameLoc,
+ObjectType, FirstQualifierInScope, 
/*AllowInjectedClassName=*/true);
+  }
+}
 
 TemplateDecl *TransTemplate
   = cast_or_null(getDerived().TransformDecl(NameLoc,
diff --git a/clang/test/SemaCXX/many-template-parameter-lists.cpp 
b/clang/test/SemaCXX/many-template-parameter-lists.cpp
index f98005c7e6fb5..b5d954986dd4f 100644
--- a/clang/test/SemaCXX/many-template-parameter-lists.cpp
+++ b/clang/test/SemaCXX/many-template-parameter-lists.cpp
@@ -5,7 +5,7 @@
 template 
 struct X {
   template 
-  struct A { // expected-note {{not-yet-instantiated member is declared here}}
+  struct A {
 template 
 struct B {
   template 
@@ -28,9 +28,9 @@ struct X {
   template 
   template 
   template 
-  friend void A::template B::template C::template D::template 
E::operator+=(Z); // expected-warning {{not supported}} expected-error {{no 
member 'A' in 'X'; it has not yet been instantiated}}
+  friend void A::template B::template C::template D::template 
E::operator+=(Z); // expected-warning {{dependent nested name specifier 
'A::B::C::D::template E::' for friend class declaration is not 
supported; turning off access control for 'X'}}
 };
 
 void test() {
-  X::A::B::C::D::E() += 1.0; // expected-note 
{{in instantiation of template class 'X' requested here}}
+  X::A::B::C::D::E() += 1.0;
 }
diff --git a/clang/test/SemaTemplate/PR12884_original_no_crash.cpp 
b/clang/test/SemaTemplate/PR12884_original_no_crash.cpp
new file mode 100644
index 0..f2b6f6e28c2f9
--- /dev/null
+++ b/clang/test/SemaTemplate/PR12884_original_no_crash.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+
+namespace PR12884_original {
+  template  struct A {
+struct B {
+  template  struct X {};
+  typedef int arg;
+};
+struct C {
+  typedef B::X x; // expected-error{{typename specifier 
refers to non-type member 'arg' in 'PR12884_original::A::B'}}
+};
+  };
+
+  template <> struct A::B {
+template  struct X {};
+static const int arg = 0; // expected-note{{referenced member 'arg' is 
declared here}}
+  };
+
+  A::C::x a; // expected-note{{in instantiation of member class 
'PR12884_original::A::C' requested here}}
+}
diff --git a/clang/test/SemaTemplate/PR91

[clang] [Clang][Sema] qualifier should be transformed (PR #94725)

2024-06-22 Thread Qizhi Hu via cfe-commits

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

>From 70928fcec829b6cb02fd9fe19b214518c872eea6 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 7 Jun 2024 14:04:52 +0800
Subject: [PATCH] [Clang][Sema] qualifier should be transformed

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/Sema/TreeTransform.h| 18 +
 .../SemaCXX/many-template-parameter-lists.cpp |  6 +++---
 .../PR12884_original_no_crash.cpp | 20 +++
 clang/test/SemaTemplate/PR91677.cpp   | 14 +
 .../SemaTemplate/typename-specifier-3.cpp |  7 ---
 6 files changed, 60 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaTemplate/PR12884_original_no_crash.cpp
 create mode 100644 clang/test/SemaTemplate/PR91677.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ac0fa0141b47..8f217990a494c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -914,6 +914,7 @@ Bug Fixes to C++ Support
 - Clang now diagnoses explicit specializations with storage class specifiers 
in all contexts.
 - Fix an assertion failure caused by parsing a lambda used as a default 
argument for the value of a
   forward-declared class. (#GH93512).
+- Clang now transforms qualifier of template name. (#91677).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index cf4e80399632b..b3872a18da4fa 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -4568,6 +4568,24 @@ 
TreeTransform::TransformTemplateName(CXXScopeSpec &SS,
   if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
 TemplateDecl *Template = QTN->getUnderlyingTemplate().getAsTemplateDecl();
 assert(Template && "qualified template name must refer to a template");
+if (QTN->getQualifier()) {
+  CXXScopeSpec QualifierSS;
+  QualifierSS.MakeTrivial(getSema().getASTContext(), QTN->getQualifier(),
+  NameLoc);
+  NestedNameSpecifierLoc QualifierLoc =
+  QualifierSS.getWithLocInContext(getSema().getASTContext());
+  NestedNameSpecifierLoc TransformedQualifierLoc =
+  getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
+  if (!TransformedQualifierLoc)
+return Name;
+  if (getDerived().AlwaysRebuild() ||
+  QualifierLoc != TransformedQualifierLoc) {
+SS.Adopt(TransformedQualifierLoc);
+return getDerived().RebuildTemplateName(
+SS, SourceLocation(), *Template->getIdentifier(), NameLoc,
+ObjectType, FirstQualifierInScope, 
/*AllowInjectedClassName=*/true);
+  }
+}
 
 TemplateDecl *TransTemplate
   = cast_or_null(getDerived().TransformDecl(NameLoc,
diff --git a/clang/test/SemaCXX/many-template-parameter-lists.cpp 
b/clang/test/SemaCXX/many-template-parameter-lists.cpp
index f98005c7e6fb5..b5d954986dd4f 100644
--- a/clang/test/SemaCXX/many-template-parameter-lists.cpp
+++ b/clang/test/SemaCXX/many-template-parameter-lists.cpp
@@ -5,7 +5,7 @@
 template 
 struct X {
   template 
-  struct A { // expected-note {{not-yet-instantiated member is declared here}}
+  struct A {
 template 
 struct B {
   template 
@@ -28,9 +28,9 @@ struct X {
   template 
   template 
   template 
-  friend void A::template B::template C::template D::template 
E::operator+=(Z); // expected-warning {{not supported}} expected-error {{no 
member 'A' in 'X'; it has not yet been instantiated}}
+  friend void A::template B::template C::template D::template 
E::operator+=(Z); // expected-warning {{dependent nested name specifier 
'A::B::C::D::template E::' for friend class declaration is not 
supported; turning off access control for 'X'}}
 };
 
 void test() {
-  X::A::B::C::D::E() += 1.0; // expected-note 
{{in instantiation of template class 'X' requested here}}
+  X::A::B::C::D::E() += 1.0;
 }
diff --git a/clang/test/SemaTemplate/PR12884_original_no_crash.cpp 
b/clang/test/SemaTemplate/PR12884_original_no_crash.cpp
new file mode 100644
index 0..f2b6f6e28c2f9
--- /dev/null
+++ b/clang/test/SemaTemplate/PR12884_original_no_crash.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+
+namespace PR12884_original {
+  template  struct A {
+struct B {
+  template  struct X {};
+  typedef int arg;
+};
+struct C {
+  typedef B::X x; // expected-error{{typename specifier 
refers to non-type member 'arg' in 'PR12884_original::A::B'}}
+};
+  };
+
+  template <> struct A::B {
+template  struct X {};
+static const int arg = 0; // expected-note{{referenced member 'arg' is 
declared here}}
+  };
+
+  A::C::x a; // expected-note{{in instantiation of member class 
'PR12884_original::A::C' requested here}}
+}
diff --git a/clang/test/SemaTemplate/PR91677.cpp 
b/clang/test/SemaTemplate/PR91677.cpp
new file mod

[clang] [compiler-rt] [ubsan] Display correct runtime messages for negative _BitInt (PR #93612)

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

mstorsjo wrote:

In addition to the issue noted on buildbots, this also caused failed tests on 
i386:
https://github.com/mstorsjo/llvm-mingw/actions/runs/9606458336/job/26504129718#step:8:1501

There seem to be a couple of different errors there:
```
bit-int.c:72:19: runtime error: implicit conversion from type 'unsigned 
_BitInt(37)' of value [21707795506135039](tel:21707795506135039) (64-bit, 
unsigned) to type '_BitInt(37)' changed the value to -1 (64-bit, signed)

AddressSanitizer: CHECK failed: ubsan_value.cpp:87 "((0 && "libclang_rt.ubsan 
was built without __int128 support")) != (0)" (0x0, 0x0) (tid=2296)

```

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


[clang-tools-extra] [clang-tidy] add option to avoid "no checks enabled" error (PR #96122)

2024-06-22 Thread Danny Mösch via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] add option to avoid "no checks enabled" error (PR #96122)

2024-06-22 Thread Danny Mösch via cfe-commits

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


[clang-tools-extra] [clang-tidy] add option to avoid "no checks enabled" error (PR #96122)

2024-06-22 Thread Danny Mösch via cfe-commits


@@ -125,6 +125,9 @@ Improvements to clang-tidy
 - Added argument `--exclude-header-filter` and config option 
`ExcludeHeaderFilterRegex`
   to exclude headers from analysis via a RegEx.
 
+- Added argument `--allow-no-checks` to suppress "no checks enabled" error
+  when disabling all of the checks.

SimplyDanny wrote:

Perhaps give a hint on what "disabling all checks" means in practice:
```suggestion
  when disabling all of the checks by `--checks='-*'`.
```

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


[clang] [TBAA] Emit int TBAA metadata on FP math libcalls (PR #96025)

2024-06-22 Thread via cfe-commits


@@ -707,7 +707,34 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const 
FunctionDecl *FD,
   const CallExpr *E, llvm::Constant *calleeValue) {
   CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   CGCallee callee = CGCallee::forDirect(calleeValue, GlobalDecl(FD));
-  return CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
+  RValue Call =
+  CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
+
+  // Check the supported intrinsic.
+  if (unsigned BuiltinID = FD->getBuiltinID()) {
+auto IntrinsicID = [&]() -> unsigned {
+  switch (BuiltinID) {
+  case Builtin::BIexpf:
+  case Builtin::BI__builtin_expf:
+  case Builtin::BI__builtin_expf128:
+return true;
+  }
+  // TODO: support more FP math libcalls
+  return false;
+}();
+
+if (IntrinsicID) {
+  llvm::MDBuilder MDHelper(CGF.getLLVMContext());
+  MDNode *RootMD = CGF.CGM.getTBAARoot();
+  // Emit "int" TBAA metadata on FP math libcalls.
+  MDNode *AliasType = MDHelper.createTBAANode("int", RootMD);

vfdff wrote:

sorry, I don't find the metadata for "int". 

ps:I will update the **createTBAANode** into **createTBAAScalarTypeNode** 
according [switch from old TBAA format to the new struct-path aware TBAA 
format](https://discourse.llvm.org/t/dragonegg-switch-from-old-tbaa-format-to-the-new-struct-path-aware-tbaa-format/29448)

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


[clang] [TBAA] Emit int TBAA metadata on FP math libcalls (PR #96025)

2024-06-22 Thread via cfe-commits

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


[clang] [libclang/python] Refactor enum usage (PR #95608)

2024-06-22 Thread Jannick Kremer via cfe-commits

DeinAlptraum wrote:

@Endilll are you taking a look at this, and/or should I ask other reviewers?

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


[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)

2024-06-22 Thread Emilia Kond via cfe-commits

https://github.com/rymiel updated 
https://github.com/llvm/llvm-project/pull/95025

>From 6fc09d022a0e4e395a1b8e17166641dffc7c12eb Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Mon, 10 Jun 2024 22:17:29 +0300
Subject: [PATCH 1/5] [clang-format] Don't count template template parameter as
 declaration

In ContinuationIndenter::mustBreak, a break is required between a
template declaration and the function/class declaration it applies to,
if the template declaration spans multiple lines.

However, this also includes template template parameters, which can
cause extra erroneous line breaks in some declarations.

This patch makes template template parameters not be counted as
template declarations.

Fixes https://github.com/llvm/llvm-project/issues/93793
---
 clang/lib/Format/TokenAnnotator.cpp   | 15 ---
 clang/unittests/Format/TokenAnnotatorTest.cpp | 17 +
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 1fe3b61a5a81f..9ed25d3e4c7ee 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -127,7 +127,7 @@ class AnnotatingParser {
SmallVector &Scopes)
   : Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false),
 IsCpp(Style.isCpp()), LangOpts(getFormattingLangOpts(Style)),
-Keywords(Keywords), Scopes(Scopes) {
+Keywords(Keywords), Scopes(Scopes), TemplateDeclarationDepth(0) {
 assert(IsCpp == LangOpts.CXXOperatorNames);
 Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false));
 resetTokenMetadata();
@@ -1269,10 +1269,17 @@ class AnnotatingParser {
 if (CurrentToken && CurrentToken->is(tok::less)) {
   CurrentToken->setType(TT_TemplateOpener);
   next();
-  if (!parseAngle())
+  TemplateDeclarationDepth++;
+  if (!parseAngle()) {
+TemplateDeclarationDepth--;
 return false;
-  if (CurrentToken)
+  }
+  TemplateDeclarationDepth--;
+  if (CurrentToken &&
+  !(TemplateDeclarationDepth > 0 &&
+CurrentToken->isOneOf(tok::kw_typename, tok::kw_class))) {
 CurrentToken->Previous->ClosesTemplateDeclaration = true;
+  }
   return true;
 }
 return false;
@@ -3073,6 +3080,8 @@ class AnnotatingParser {
   // same decision irrespective of the decisions for tokens leading up to it.
   // Store this information to prevent this from causing exponential runtime.
   llvm::SmallPtrSet NonTemplateLess;
+
+  int TemplateDeclarationDepth;
 };
 
 static const int PrecedenceUnaryOperator = prec::PointerToMember + 1;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 8cc5c239d30a1..82de72ddeeaa1 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -584,6 +584,23 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsNonTemplateAngleBrackets) {
   EXPECT_TOKEN(Tokens[20], tok::greater, TT_BinaryOperator);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsTemplateTemplateParameters) {
+  auto Tokens = annotate("template  typename X,\n"
+ "  template  typename Y,\n"
+ "  typename... T>\n"
+ "class A {};");
+  ASSERT_EQ(Tokens.size(), 28u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[3], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser);
+  EXPECT_EQ(Tokens[6]->ClosesTemplateDeclaration, 0u);
+  EXPECT_TOKEN(Tokens[11], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[14], tok::greater, TT_TemplateCloser);
+  EXPECT_EQ(Tokens[14]->ClosesTemplateDeclaration, 0u);
+  EXPECT_TOKEN(Tokens[21], tok::greater, TT_TemplateCloser);
+  EXPECT_EQ(Tokens[21]->ClosesTemplateDeclaration, 1u);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) {
   FormatStyle Style = getLLVMStyle();
   Style.WhitespaceSensitiveMacros.push_back("FOO");

>From 16f5f19b8d9828396c227ab5c0b6bfe2a270fbf1 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Tue, 11 Jun 2024 23:35:49 +0300
Subject: [PATCH 2/5] Update clang/lib/Format/TokenAnnotator.cpp
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Björn Schäpers 
---
 clang/lib/Format/TokenAnnotator.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 9ed25d3e4c7ee..e658fbf676b7d 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1276,8 +1276,8 @@ class AnnotatingParser {
   }
   TemplateDeclarationDepth--;
   if (CurrentToken &&
-  !(TemplateDeclarationDepth > 0 &&
-CurrentToken->isOneOf(tok::kw_typename, tok::kw_class))) {
+  (Templ

[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)

2024-06-22 Thread Emilia Kond via cfe-commits


@@ -1269,10 +1269,17 @@ class AnnotatingParser {
 if (CurrentToken && CurrentToken->is(tok::less)) {
   CurrentToken->setType(TT_TemplateOpener);
   next();
-  if (!parseAngle())
+  TemplateDeclarationDepth++;
+  if (!parseAngle()) {
+TemplateDeclarationDepth--;
 return false;
-  if (CurrentToken)
+  }
+  TemplateDeclarationDepth--;
+  if (CurrentToken &&
+  (TemplateDeclarationDepth == 0 ||
+   !CurrentToken->isOneOf(tok::kw_typename, tok::kw_class))) {

rymiel wrote:

Thanks!

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


[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)

2024-06-22 Thread Owen Pan via cfe-commits

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


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


[clang] 4a7bf42 - [clang-format] Don't count template template parameter as declaration (#95025)

2024-06-22 Thread via cfe-commits

Author: Emilia Kond
Date: 2024-06-22T12:51:36+03:00
New Revision: 4a7bf42a9b83144db8a11ac06cce4da21166e6a2

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

LOG: [clang-format] Don't count template template parameter as declaration 
(#95025)

In ContinuationIndenter::mustBreak, a break is required between a
template declaration and the function/class declaration it applies to,
if the template declaration spans multiple lines.

However, this also includes template template parameters, which can
cause extra erroneous line breaks in some declarations.

This patch makes template template parameters not be counted as template
declarations.

Fixes https://github.com/llvm/llvm-project/issues/93793
Fixes https://github.com/llvm/llvm-project/issues/48746

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 55c5ecee45e0c..89e134144d433 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -127,7 +127,7 @@ class AnnotatingParser {
SmallVector &Scopes)
   : Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false),
 IsCpp(Style.isCpp()), LangOpts(getFormattingLangOpts(Style)),
-Keywords(Keywords), Scopes(Scopes) {
+Keywords(Keywords), Scopes(Scopes), TemplateDeclarationDepth(0) {
 assert(IsCpp == LangOpts.CXXOperatorNames);
 Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false));
 resetTokenMetadata();
@@ -1266,16 +1266,22 @@ class AnnotatingParser {
   }
 
   bool parseTemplateDeclaration() {
-if (CurrentToken && CurrentToken->is(tok::less)) {
-  CurrentToken->setType(TT_TemplateOpener);
-  next();
-  if (!parseAngle())
-return false;
-  if (CurrentToken)
-CurrentToken->Previous->ClosesTemplateDeclaration = true;
-  return true;
-}
-return false;
+if (!CurrentToken || CurrentToken->isNot(tok::less))
+  return false;
+
+CurrentToken->setType(TT_TemplateOpener);
+next();
+
+TemplateDeclarationDepth++;
+const bool WellFormed = parseAngle();
+TemplateDeclarationDepth--;
+if (!WellFormed)
+  return false;
+
+if (CurrentToken && TemplateDeclarationDepth == 0)
+  CurrentToken->Previous->ClosesTemplateDeclaration = true;
+
+return true;
   }
 
   bool consumeToken() {
@@ -3091,6 +3097,8 @@ class AnnotatingParser {
   // same decision irrespective of the decisions for tokens leading up to it.
   // Store this information to prevent this from causing exponential runtime.
   llvm::SmallPtrSet NonTemplateLess;
+
+  int TemplateDeclarationDepth;
 };
 
 static const int PrecedenceUnaryOperator = prec::PointerToMember + 1;

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 12c4b7fdd5ac2..d3b310fe59527 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -584,6 +584,23 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsNonTemplateAngleBrackets) {
   EXPECT_TOKEN(Tokens[20], tok::greater, TT_BinaryOperator);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsTemplateTemplateParameters) {
+  auto Tokens = annotate("template  typename X,\n"
+ "  template  class Y,\n"
+ "  typename... T>\n"
+ "class A {};");
+  ASSERT_EQ(Tokens.size(), 28u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[3], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser);
+  EXPECT_FALSE(Tokens[6]->ClosesTemplateDeclaration);
+  EXPECT_TOKEN(Tokens[11], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[14], tok::greater, TT_TemplateCloser);
+  EXPECT_FALSE(Tokens[14]->ClosesTemplateDeclaration);
+  EXPECT_TOKEN(Tokens[21], tok::greater, TT_TemplateCloser);
+  EXPECT_TRUE(Tokens[21]->ClosesTemplateDeclaration);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) {
   FormatStyle Style = getLLVMStyle();
   Style.WhitespaceSensitiveMacros.push_back("FOO");



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


[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)

2024-06-22 Thread Emilia Kond via cfe-commits

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


[clang] [clang][Sema] Fix crash on atomic builtins with incomplete type args (PR #96374)

2024-06-22 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

Could you knock out a related bug at the same time:

```c++
template
struct X {
  char arr[1];
};

extern X* p, *q;
//X inst;

void f() {
  __atomic_exchange(p, p, q, __ATOMIC_RELAXED);
}
```

With the line commented out, currently this crashes, but in Clang 18 and with 
your patch, it fails as `X` hasn't been instantiated yet and 
`isTriviallyCopyableType` is false for incomplete types:

```
test:10:3: error: address argument to atomic operation must be a pointer to a 
trivially-copyable type ('X *' invalid)
   10 |   __atomic_exchange(p, p, q, __ATOMIC_RELAXED);
  |   ^ ~
```

`->isIncompleteType()` is true for uninstantiated templates too, so just a 
`RequireCompleteType` should stop the crash and instantiate templates as needed.

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


[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`llvm-clang-x86_64-sie-ubuntu-fast` running on `sie-linux-worker` while 
building `clang` at step 6 "test-build-unified-tree-check-all".

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

Here is the relevant piece of the build log for the reference:
```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'Clang :: Index/overriding-ftemplate-comments.cpp' 
FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: rm -rf 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/test/Index/Output/overriding-ftemplate-comments.cpp.tmp
+ rm -rf 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/test/Index/Output/overriding-ftemplate-comments.cpp.tmp
RUN: at line 2: mkdir 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/test/Index/Output/overriding-ftemplate-comments.cpp.tmp
+ mkdir 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/test/Index/Output/overriding-ftemplate-comments.cpp.tmp
RUN: at line 3: 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/c-index-test
 -test-load-source all 
-comments-xml-schema=/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Index/../../bindings/xml/comment-xml-schema.rng
 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Index/overriding-ftemplate-comments.cpp
 > 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/test/Index/Output/overriding-ftemplate-comments.cpp.tmp/out
+ 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/c-index-test
 -test-load-source all 
-comments-xml-schema=/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Index/../../bindings/xml/comment-xml-schema.rng
 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Index/overriding-ftemplate-comments.cpp
RUN: at line 4: 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck
 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Index/overriding-ftemplate-comments.cpp
 < 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/tools/clang/test/Index/Output/overriding-ftemplate-comments.cpp.tmp/out
+ 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck
 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Index/overriding-ftemplate-comments.cpp
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Index/overriding-ftemplate-comments.cpp:80:11:
 error: CHECK: expected string not found in input
// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#v#template
  class 
BBB>\n class AAA>\nvoid 
comment_to_html_conversion_22()C10
 Ccc 1 
AAA1
 Zzz 
C2 
Ccc 2 
C3 
Ccc 3 
C4 
Ccc 4 
BBB 
Bbb]
  ^
:619:1491: note: scanning from here
// CHECK: overriding-ftemplate-comments.cpp:65:6: 
FunctionTemplate=comment_to_html_conversion_21:65:6 RawComment=[/// \tparam AAA 
Aaa\n/// \tparam BBB Bbb\n/// \tparam CCC Ccc\n/// \tparam DDD Ddd] 
RawCommentRange=[55:1 - 58:20] FullCommentAsHTML=[PPP Aaa 
QQQ Bbb RRR 
Ccc SSS Ddd] FullCommentAsXML=[comment_to_html_conversion_21c:@FT@>1#t>2#t>1#T#Tcomment_to_html_conversion_21#v#template