[clang] [clang-forma] Support `PointerAlignment: Left` for pointer to member (PR #86253)

2024-03-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixes #85761.

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


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+19-12) 
- (modified) clang/unittests/Format/FormatTest.cpp (+6-1) 


``diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 94d2266555f6b9..d54a0fe4ce6748 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4351,9 +4351,11 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;
 
+  const auto *BeforeLeft = Left.Previous;
+
   // operator co_await(x)
-  if (Right.is(tok::l_paren) && Left.is(tok::kw_co_await) && Left.Previous &&
-  Left.Previous->is(tok::kw_operator)) {
+  if (Right.is(tok::l_paren) && Left.is(tok::kw_co_await) && BeforeLeft &&
+  BeforeLeft->is(tok::kw_operator)) {
 return false;
   }
   // co_await (x), co_yield (x), co_return (x)
@@ -4404,8 +4406,8 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   return false;
   }
   if (Right.is(tok::ellipsis)) {
-return Left.Tok.isLiteral() || (Left.is(tok::identifier) && Left.Previous 
&&
-Left.Previous->is(tok::kw_case));
+return Left.Tok.isLiteral() || (Left.is(tok::identifier) && BeforeLeft &&
+BeforeLeft->is(tok::kw_case));
   }
   if (Left.is(tok::l_square) && Right.is(tok::amp))
 return Style.SpacesInSquareBrackets;
@@ -4473,8 +4475,8 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
 if (Right.is(tok::l_brace) && Right.is(BK_Block))
   return true;
 // for (auto a = 0, b = 0; const auto& c : {1, 2, 3})
-if (Left.Previous && Left.Previous->isTypeOrIdentifier(IsCpp) &&
-Right.Next && Right.Next->is(TT_RangeBasedForLoopColon)) {
+if (BeforeLeft && BeforeLeft->isTypeOrIdentifier(IsCpp) && Right.Next &&
+Right.Next->is(TT_RangeBasedForLoopColon)) {
   return getTokenPointerOrReferenceAlignment(Left) !=
  FormatStyle::PAS_Right;
 }
@@ -4496,12 +4498,17 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   startsWithInitStatement(Line {
   return false;
 }
-return Left.Previous && !Left.Previous->isOneOf(
-tok::l_paren, tok::coloncolon, tok::l_square);
+if (!BeforeLeft)
+  return false;
+if (BeforeLeft->is(tok::coloncolon)) {
+  return Left.is(tok::star) &&
+ Style.PointerAlignment != FormatStyle::PAS_Right;
+}
+return !BeforeLeft->isOneOf(tok::l_paren, tok::l_square);
   }
   // Ensure right pointer alignment with ellipsis e.g. int *...P
-  if (Left.is(tok::ellipsis) && Left.Previous &&
-  Left.Previous->isPointerOrReference()) {
+  if (Left.is(tok::ellipsis) && BeforeLeft &&
+  BeforeLeft->isPointerOrReference()) {
 return Style.PointerAlignment != FormatStyle::PAS_Right;
   }
 
@@ -4663,13 +4670,13 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   return Style.SpaceBeforeParensOptions.AfterFunctionDefinitionName ||
  spaceRequiredBeforeParens(Right);
 }
-if (!Left.Previous || !Left.Previous->isOneOf(tok::period, tok::arrow)) {
+if (!BeforeLeft || !BeforeLeft->isOneOf(tok::period, tok::arrow)) {
   if (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch)) {
 return Style.SpaceBeforeParensOptions.AfterControlStatements ||
spaceRequiredBeforeParens(Right);
   }
   if (Left.isOneOf(tok::kw_new, tok::kw_delete)) {
-return ((!Line.MightBeFunctionDecl || !Left.Previous) &&
+return ((!Line.MightBeFunctionDecl || !BeforeLeft) &&
 Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
spaceRequiredBeforeParens(Right);
   }
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index bea989c8c306db..cab5556af47cc0 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11054,7 +11054,12 @@ TEST_F(FormatTest, UnderstandsPointersToMembers) {
   "aaa(aaa));");
   FormatStyle Style = getLLVMStyle();
   Style.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("typedef bool* (Class::*Member)() const;", Style);
+  verifyFormat("typedef bool* (Class::* Member)() const;", Style);
+  verifyFormat("void function(int A::* parameter, int* parameter2) {\n"
+   "  int A::* variable = &A::B;\n"
+   "  int* A::B;\n"
+   "}",
+   Style);
 }
 
 TEST_F(FormatTest, UnderstandsUnaryOperators) {

``




https://github.com/llvm/llvm-project/pull/86253
__

[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-21 Thread Piotr Sobczak via cfe-commits

piotrAMD wrote:

The change LG - thanks for adding support for bf16.

Agreed that the intrinsics should match the builtins for consistency (now or in 
a follow-up commit).
These intrinsics were added for the upcoming generation - it should be fine to 
rename them at this stage.

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


[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-21 Thread Stanislav Mekhanoshin via cfe-commits

rampitec wrote:

> I don't think intrinsics are meant for users. Builtins are the user-facing 
> front. :-)

Depending on who you consider an user. Are folks writing MLIR generators users?

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


[clang] Split -Wcast-function-type into a separate group (PR #86131)

2024-03-21 Thread Abhin P Jose via cfe-commits

Abhinkop wrote:

I think that this would occur primarily in the whole code base. Because a 
compilation that has added -Wextra diagnostic group would provide new warnings 
and coupling, this with -Werror would break the build. I think we have to take 
a look at these builds and investigate why it is done, and for the time being, 
we can use the -Wno-cast-function-type to make the builds go green.

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


[clang] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-21 Thread Takuto Ikuta via cfe-commits

atetubou wrote:

@MaskRay could you review this?

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


[clang] Add `clang_getCursorCallExprKind` to get the underlying type of CallExpr (PR #86143)

2024-03-21 Thread via cfe-commits

https://github.com/16bit-ykiko updated 
https://github.com/llvm/llvm-project/pull/86143

>From 32d4fc35f3d52b54e308b76c00c292497afe9621 Mon Sep 17 00:00:00 2001
From: ykiko 
Date: Fri, 22 Mar 2024 00:00:30 +0800
Subject: [PATCH 1/4] add `clang_getCursorCallExprKind` to get the underlying
 type of CallExpr.

---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/include/clang-c/Index.h | 46 +++
 clang/tools/libclang/CIndex.cpp   | 30 ++-
 clang/tools/libclang/libclang.map |  5 +++
 clang/unittests/libclang/LibclangTest.cpp | 24 
 5 files changed, 106 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3a74c070ff9ffe..b25296cafc8285 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -509,6 +509,8 @@ clang-format
 libclang
 
 
+- Added ``CXCallExprKind`` and ``clang_getCursorCallExprKind``.
+
 Static Analyzer
 ---
 
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 60db3cf0966c02..1828b8ec3edaab 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -6663,6 +6663,52 @@ clang_getUnaryOperatorKindSpelling(enum 
CXUnaryOperatorKind kind);
 CINDEX_LINKAGE enum CXUnaryOperatorKind
 clang_getCursorUnaryOperatorKind(CXCursor cursor);
 
+/**
+ * Describes the kind of CallExpr.
+ */
+enum CXCallExprKind {
+  /** Not a CallExpr. */
+  CXCallExpr_Invalid = 0,
+  /** Simple C function call. */
+  CXCallExpr_Default,
+  /** Call to overloaded operator using operator syntax. */
+  CXCallExpr_CXXOperatorCallExpr,
+  /**
+   * Call to a member function written with member call syntax or
+   * normal function-call syntax within a member function.
+   */
+  CXCallExpr_CXXMemberCallExpr,
+  /** Call to a CUDA kernel function. */
+  CXCallExpr_CUDAKernelCallExpr,
+  /** Call to a C++ constructor. */
+  CXCallExpr_CXXConstructExpr,
+  /**
+   * Call to an inherited base class constructor from an
+   * inheriting constructor. Implicitly forwards arguments.
+   */
+  CXCallExpr_CXXInheritedCtorInitExpr,
+  /**
+   * C++ functional cast expression building a temporary object.
+   */
+  CXCallExpr_CXXTemporaryObjectExpr,
+  /**
+   * Explicit type conversion using functional notation, unresolved
+   * due to type-dependency.
+   */
+  CXCallExpr_CXXUnresolvedConstructExpr,
+  /**
+   * Call to a user-defined literal.
+   */
+  CXCallExpr_UserDefinedLiteral,
+};
+
+/**
+ *  Retrieve the detailed kind of a call expression.
+ *
+ *  If this cursor is not a CallExpr then returns Invalid.
+ */
+CINDEX_LINKAGE enum CXCallExprKind clang_getCursorCallExprKind(CXCursor 
cursor);
+
 /**
  * @}
  */
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 418b152ba4a13f..51f78b22c43e0c 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -2122,7 +2122,7 @@ class EnqueueVisitor : public 
ConstStmtVisitor,
   void VisitBlockExpr(const BlockExpr *B);
   void VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
   void VisitCompoundStmt(const CompoundStmt *S);
-  void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) { /* Do nothing. */
+  void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) { /* Do nothing. */ 
   }
   void VisitMSDependentExistsStmt(const MSDependentExistsStmt *S);
   void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E);
@@ -9727,3 +9727,31 @@ enum CXUnaryOperatorKind 
clang_getCursorUnaryOperatorKind(CXCursor cursor) {
 
   return CXUnaryOperator_Invalid;
 }
+
+enum CXCallExprKind clang_getCursorCallExprKind(CXCursor cursor) {
+  if (clang_isExpression(cursor.kind)) {
+const Expr *expr = getCursorExpr(cursor);
+
+switch (expr->getStmtClass()) {
+case Stmt::CallExprClass:
+  return CXCallExpr_Default;
+case Stmt::CXXOperatorCallExprClass:
+  return CXCallExpr_CXXOperatorCallExpr;
+case Stmt::CXXMemberCallExprClass:
+  return CXCallExpr_CXXMemberCallExpr;
+case Stmt::CUDAKernelCallExprClass:
+  return CXCallExpr_CUDAKernelCallExpr;
+case Stmt::CXXConstructExprClass:
+  return CXCallExpr_CXXConstructExpr;
+case Stmt::CXXInheritedCtorInitExprClass:
+  return CXCallExpr_CXXInheritedCtorInitExpr;
+case Stmt::CXXTemporaryObjectExprClass:
+  return CXCallExpr_CXXTemporaryObjectExpr;
+case Stmt::CXXUnresolvedConstructExprClass:
+  return CXCallExpr_CXXUnresolvedConstructExpr;
+case Stmt::UserDefinedLiteralClass:
+  return CXCallExpr_UserDefinedLiteral;
+}
+  }
+  return CXCallExpr_Invalid;
+}
\ No newline at end of file
diff --git a/clang/tools/libclang/libclang.map 
b/clang/tools/libclang/libclang.map
index 5676198a286d9b..5499c38a8289f9 100644
--- a/clang/tools/libclang/libclang.map
+++ b/clang/tools/libclang/libclang.map
@@ -428,6 +428,11 @@ LLVM_17 {
 clang_getCursorUnaryOperatorKind;
 };
 
+LLVM_18 {
+  global:
+clang_

[clang] [Clang][Sema] Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-21 Thread Kees Cook via cfe-commits


@@ -21,10 +27,76 @@ struct __attribute((packed, aligned(4))) { char a; int x; 
char z[]; } e = { 1, 2
 struct { int x; char y[]; } f = { 1, { 13, 15 } };
 // CHECK: @f ={{.*}} global <{ i32, [2 x i8] }> <{ i32 1, [2 x i8] c"\0D\0F" }>
 
-union {
-  struct {
-int a;
-char b[];
-  } x;
-} in_union = {};
-// CHECK: @in_union ={{.*}} global %union.anon zeroinitializer
+struct __attribute((packed)) { short a; char z[]; } g = { 2, { 11, 13, 15 } };
+// CHECK: @g ={{.*}} <{ i16, [3 x i8] }> <{ i16 2, [3 x i8] c"\0B\0D\0F" }>,
+
+// Last member is the potential flexible array, unnamed initializer skips it.
+struct { int a; union { int b; short x; }; int c; int d; } h = {1, 2, {}, 3};
+// CHECK: @h = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 }, 
i32 0, i32 3 }
+struct { int a; union { int b; short x[0]; }; int c; int d; } h0 = {1, 2, {}, 
3};
+// CHECK: @h0 = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 
}, i32 0, i32 3 }
+struct { int a; union { int b; short x[1]; }; int c; int d; } h1 = {1, 2, {}, 
3};
+// CHECK: @h1 = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 
}, i32 0, i32 3 }
+struct {
+  int a;
+  union {
+int b;
+struct {
+  struct { } __ununsed;
+  short x[];
+};
+  };
+  int c;
+  int d;
+} hiding = {1, 2, {}, 3};
+// CHECK: @hiding = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 
2 }, i32 0, i32 3 }
+struct { int a; union { int b; short x[]; }; int c; int d; } hf = {1, 2, {}, 
3};
+// CHECK: @hf = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 
}, i32 0, i32 3 }
+
+// First member is the potential flexible array, initialization requires 
braces.
+struct { int a; union { short x; int b; }; int c; int d; } i = {1, 2, {}, 3};
+// CHECK: @i = global { i32, { i16, [2 x i8] }, i32, i32 } { i32 1, { i16, [2 
x i8] } { i16 2, [2 x i8] undef }, i32 0, i32 3 }
+struct { int a; union { short x[0]; int b; }; int c; int d; } i0 = {1, {}, 2, 
3};
+// CHECK: @i0 = global { i32, { [0 x i16], [4 x i8] }, i32, i32 } { i32 1, { 
[0 x i16], [4 x i8] } { [0 x i16] zeroinitializer, [4 x i8] undef }, i32 2, i32 
3 }
+struct { int a; union { short x[1]; int b; }; int c; int d; } i1 = {1, {2}, 
{}, 3};
+// CHECK: @i1 = global { i32, { [1 x i16], [2 x i8] }, i32, i32 } { i32 1, { 
[1 x i16], [2 x i8] } { [1 x i16] [i16 2], [2 x i8] undef }, i32 0, i32 3 }
+struct { int a; union { short x[]; int b; }; int c; int d; } i_f = {4, {}, {}, 
6};
+// CHECK: @i_f = global { i32, { [0 x i16], [4 x i8] }, i32, i32 } { i32 4, { 
[0 x i16], [4 x i8] } { [0 x i16] zeroinitializer, [4 x i8] undef }, i32 0, i32 
6 }
+
+// Named initializers; order doesn't matter.
+struct { int a; union { int b; short x; }; int c; int d; } hn = {.a = 1, .x = 
2, .c = 3};
+// CHECK: @hn = global { i32, { i16, [2 x i8] }, i32, i32 } { i32 1, { i16, [2 
x i8] } { i16 2, [2 x i8] undef }, i32 3, i32 0 }
+struct { int a; union { int b; short x[0]; }; int c; int d; } hn0 = {.a = 1, 
.x = {2}, .c = 3};
+// CHECK: @hn0 = global { i32, { [0 x i16], [4 x i8] }, i32, i32 } { i32 1, { 
[0 x i16], [4 x i8] } { [0 x i16] zeroinitializer, [4 x i8] undef }, i32 3, i32 
0 }
+struct { int a; union { int b; short x[1]; }; int c; int d; } hn1 = {.a = 1, 
.x = {2}, .c = 3};
+// CHECK: @hn1 = global { i32, { [1 x i16], [2 x i8] }, i32, i32 } { i32 1, { 
[1 x i16], [2 x i8] } { [1 x i16] [i16 2], [2 x i8] undef }, i32 3, i32 0 }
+
+struct { char a[]; } empty_struct = {};
+// CHECK: @empty_struct ={{.*}} global %struct.anon{{.*}} zeroinitializer, 
align 1
+
+struct { char a[]; } empty_struct0 = {0};
+// CHECK: @empty_struct0 = global { [1 x i8] } zeroinitializer, align 1
+
+union { struct { int a; char b[]; }; } struct_in_union = {};
+// CHECK: @struct_in_union = global %union.anon{{.*}} zeroinitializer, align 4
+
+union { struct { int a; char b[]; }; } struct_in_union0 = {0};
+// CHECK: @struct_in_union0 = global %union.anon{{.*}} zeroinitializer, align 4
+
+union { int a; char b[]; } trailing_in_union = {};
+// CHECK: @trailing_in_union = global %union.anon{{.*}} zeroinitializer, align 
4
+
+union { int a; char b[]; } trailing_in_union0 = {0};
+// CHECK: @trailing_in_union0 = global %union.anon{{.*}} zeroinitializer, 
align 4
+
+union { char a[]; } only_in_union = {};
+// CHECK: @only_in_union = global %union.anon{{.*}} zeroinitializer, align 1
+
+union { char a[]; } only_in_union0 = {0};
+// CHECK: @only_in_union0 = global { [1 x i8] } zeroinitializer, align 1
+
+union { char a[]; int b; } first_in_union = {};
+// CHECK: @first_in_union = global { [0 x i8], [4 x i8] } { [0 x i8] 
zeroinitializer, [4 x i8] undef }, align 4
+
+union { char a[]; int b; } first_in_union0 = {};
+// CHECK: @first_in_union0 = global { [0 x i8], [4 x i8] } { [0 x i8] 
zeroinitializer, [4 x i8] undef }, align 4

kees wrote:

Whoops! Yes, thank you. Fixing.

https://github.com/llvm/llvm-project/pull/84428
___
cfe-commits mailin

[clang] Add 'forNone' and 'forNoDescendant' AST matchers (PR #86230)

2024-03-21 Thread June Rhodes via cfe-commits

https://github.com/hach-que updated 
https://github.com/llvm/llvm-project/pull/86230

>From 941ac5286c0e5f859ae832dc397a55a9d21221c9 Mon Sep 17 00:00:00 2001
From: June Rhodes 
Date: Fri, 22 Mar 2024 13:07:57 +1100
Subject: [PATCH] Add 'forNone' and 'forNoDescendant' AST matchers

---
 clang/include/clang/ASTMatchers/ASTMatchers.h | 15 +++
 .../clang/ASTMatchers/ASTMatchersInternal.h   | 98 +++
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp | 13 +++
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|  2 +
 4 files changed, 128 insertions(+)

diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f71053d030f68..fa6afe2f02f6b0 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3547,6 +3547,21 @@ extern const internal::ArgumentAdaptingMatcherFunc<
 internal::ForEachDescendantMatcher>
 forEachDescendant;
 
+/// Matches AST nodes that have no child AST nodes that match the
+/// provided matcher.
+///
+/// Usable as: Any Matcher
+extern const internal::ArgumentAdaptingMatcherFunc
+forNone;
+
+/// Matches AST nodes that have no descendant AST nodes that match the
+/// provided matcher.
+///
+/// Usable as: Any Matcher
+extern const internal::ArgumentAdaptingMatcherFunc<
+internal::ForNoDescendantMatcher>
+forNoDescendant;
+
 /// Matches if the node or any descendant matches.
 ///
 /// Generates results for each match.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 47d912c73dd7eb..552553a0742b06 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -268,6 +268,26 @@ class BoundNodesMap {
 return true;
   }
 
+  /// Returns \c true if the \c BoundNodesMap entirely contains the values
+  /// in \c Subset.
+  bool contains(const BoundNodesMap &Subset) {
+const auto &N = this->NodeMap.end();
+if (Subset.NodeMap.size() == 1) {
+  // Avoid iteration if the subset only has a single value.
+  const auto &F = Subset.NodeMap.begin();
+  const auto &T = this->NodeMap.find(F->first);
+  return T != N && T->second == F->second;
+} else {
+  for (const auto &F : Subset.NodeMap) {
+const auto &T = this->NodeMap.find(F.first);
+if (T == N || T->second != F.second) {
+  return false;
+}
+  }
+}
+return true;
+  }
+
 private:
   IDToNodeMap NodeMap;
 };
@@ -306,6 +326,10 @@ class BoundNodesTreeBuilder {
   /// The ownership of 'ResultVisitor' remains at the caller.
   void visitMatches(Visitor* ResultVisitor);
 
+  /// Returns true if any of the entries in this tree contain the
+  /// other bound nodes map.
+  bool contains(const internal::BoundNodesMap &Subset);
+
   template 
   bool removeBindings(const ExcludePredicate &Predicate) {
 llvm::erase_if(Bindings, Predicate);
@@ -1626,6 +1650,42 @@ class ForEachMatcher : public MatcherInterface {
   }
 };
 
+/// Matches nodes of type T that have no child nodes of type ChildT for
+/// which a specified child matcher matches. ChildT must be an AST base
+/// type.
+/// ForNoneMatcher will only match if none of the child nodes match
+/// the inner matcher.
+template 
+class ForNoneMatcher : public MatcherInterface {
+  static_assert(IsBaseType::value,
+"for none only accepts base type matcher");
+
+  DynTypedMatcher InnerMatcher;
+
+public:
+  explicit ForNoneMatcher(const Matcher &InnerMatcher)
+  : InnerMatcher(InnerMatcher) {}
+
+  bool matches(const T &Node, ASTMatchFinder *Finder,
+   BoundNodesTreeBuilder *Builder) const override {
+BoundNodesTreeBuilder MatchingBuilder(*Builder);
+bool AnyMatched = Finder->matchesChildOf(
+Node, this->InnerMatcher, &MatchingBuilder, ASTMatchFinder::BK_All);
+if (!AnyMatched) {
+  // We didn't iterate over any nodes that matched, so
+  // Builder would be empty. This is a success case.
+  return true;
+}
+// Otherwise remove from Builder any entries that we
+// also have in MatchingBuilder because we want to leave
+// only the remaining entries.
+return Builder->removeBindings(
+[&MatchingBuilder](const internal::BoundNodesMap &Nodes) {
+  return MatchingBuilder.contains(Nodes);
+});
+  }
+};
+
 /// @}
 
 template 
@@ -1724,6 +1784,44 @@ class ForEachDescendantMatcher : public 
MatcherInterface {
   }
 };
 
+/// Matches nodes of type T that have no descendant node of
+/// type DescendantT for which the given inner matcher matches.
+///
+/// DescendantT must be an AST base type.
+/// ForNoDescendantMatcher only matches if none of the descendant nodes
+/// match.
+template 
+class ForNoDescendantMatcher : public MatcherInterface {
+  static_assert(IsBaseType::value,
+"for no descendant only accepts base type matcher");
+
+  DynTypedMat

[clang-tools-extra] [clang-tidy] add new check readability-enum-initial-value (PR #86129)

2024-03-21 Thread via cfe-commits

https://github.com/paperchalice updated 
https://github.com/llvm/llvm-project/pull/86129

>From 4e0845a143a820d4a68ffbdced206654c7593359 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Fri, 15 Mar 2024 08:07:47 +0800
Subject: [PATCH 1/2] [clang-tidy] add new check readability-enum-initial-value

Fixes: #85243.
---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../readability/EnumInitialValueCheck.cpp | 82 +++
 .../readability/EnumInitialValueCheck.h   | 31 +++
 .../readability/ReadabilityTidyModule.cpp |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../checks/readability/enum-initial-value.rst | 45 ++
 .../checkers/readability/enum-initial-value.c | 27 ++
 .../readability/enum-initial-value.cpp| 27 ++
 9 files changed, 223 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/enum-initial-value.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5728c9970fb65d..dd772d69202548 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -17,6 +17,7 @@ add_clang_library(clangTidyReadabilityModule
   DeleteNullPointerCheck.cpp
   DuplicateIncludeCheck.cpp
   ElseAfterReturnCheck.cpp
+  EnumInitialValueCheck.cpp
   FunctionCognitiveComplexityCheck.cpp
   FunctionSizeCheck.cpp
   IdentifierLengthCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
new file mode 100644
index 00..78d5101d439dde
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
@@ -0,0 +1,82 @@
+//===--- EnumInitialValueCheck.cpp - clang-tidy 
---===//
+//
+// 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
+//
+//===--===//
+
+#include "EnumInitialValueCheck.h"
+#include "../utils/LexerUtils.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/SmallString.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+namespace {
+
+AST_MATCHER(EnumDecl, isNoneEnumeratorsInitialized) {
+  return llvm::all_of(Node.enumerators(), [](EnumConstantDecl const *ECD) {
+return ECD->getInitExpr() == nullptr;
+  });
+}
+
+AST_MATCHER(EnumDecl, isOnlyFirstEnumeratorsInitialized) {
+  for (EnumConstantDecl const *ECD : Node.enumerators())
+if (ECD == *Node.enumerator_begin()) {
+  if (ECD->getInitExpr() == nullptr)
+return false;
+} else {
+  if (ECD->getInitExpr() != nullptr)
+return false;
+}
+  return true;
+}
+
+AST_MATCHER(EnumDecl, isAllEnumeratorsInitialized) {
+  return llvm::all_of(Node.enumerators(), [](EnumConstantDecl const *ECD) {
+return ECD->getInitExpr() != nullptr;
+  });
+}
+
+} // namespace
+
+void EnumInitialValueCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(enumDecl(unless(anyOf(isNoneEnumeratorsInitialized(),
+   isOnlyFirstEnumeratorsInitialized(),
+   isAllEnumeratorsInitialized(
+ .bind("enum"),
+ this);
+}
+
+void EnumInitialValueCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Enum = Result.Nodes.getNodeAs("enum");
+  assert(Enum != nullptr);
+  SourceLocation Loc = Enum->getBeginLoc();
+  if (Loc.isInvalid() || Loc.isMacroID())
+return;
+  DiagnosticBuilder Diag =
+  diag(Loc, "inital value in enum %0 has readability issue, "
+"explicit initialization of all of enumerators")
+  << Enum->getName();
+  for (EnumConstantDecl const *ECD : Enum->enumerators())
+if (ECD->getInitExpr() == nullptr) {
+  SourceLocation ECDLoc = ECD->getEndLoc();
+  if (ECDLoc.isInvalid() || ECDLoc.isMacroID())
+continue;
+  std::optional Next = utils::lexer::findNextTokenSkippingComments(
+  ECDLoc, *Result.SourceManager, getLangOpts());
+  if (!Next.has_value() || Next->getLocation().isMacroID())
+continue;
+  llvm::SmallString<8> Str{" = "

[clang] Add 'isPODType' AST matcher (PR #86233)

2024-03-21 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] Add 'isPODType' AST matcher (PR #86233)

2024-03-21 Thread June Rhodes via cfe-commits

https://github.com/hach-que updated 
https://github.com/llvm/llvm-project/pull/86233

>From 0e6cfaba6ab55166b7b08eecb28714c0746707f1 Mon Sep 17 00:00:00 2001
From: June Rhodes 
Date: Fri, 22 Mar 2024 13:36:54 +1100
Subject: [PATCH] Add 'isPODType' AST matcher

---
 clang/include/clang/ASTMatchers/ASTMatchers.h | 17 +
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|  1 +
 2 files changed, 18 insertions(+)

diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f71053d030f68..b114d681828212 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4087,6 +4087,23 @@ AST_POLYMORPHIC_MATCHER_P(
   return Inner.matches(source->getTypeLoc(), Finder, Builder);
 }
 
+/// Matches if the matched type is a Plain Old Data (POD) type.
+///
+/// Given
+/// \code
+///   class Y
+///   {
+///   public:
+///   int a;
+///   std::string b;
+///   };
+/// \endcode
+/// fieldDecl(hasType(qualType(isPODType(
+///   matches Y::a
+AST_MATCHER(QualType, isPODType) {
+  return Node.isPODType(Finder->getASTContext());
+}
+
 /// Matches if the matched type is represented by the given string.
 ///
 /// Given
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 2c75e6beb74301..4f716d9f166495 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -377,6 +377,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(hasTypeLoc);
   REGISTER_MATCHER(hasUnaryOperand);
   REGISTER_MATCHER(hasUnarySelector);
+  REGISTER_MATCHER(isPODType);
   REGISTER_MATCHER(hasUnderlyingDecl);
   REGISTER_MATCHER(hasUnderlyingType);
   REGISTER_MATCHER(hasUnqualifiedDesugaredType);

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


[clang] Add 'isPODType' AST matcher (PR #86233)

2024-03-21 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 718fbbef5f18a2b7e7fc4f842b1452ae9bee581a 
87d02c2278e023b9439be96c2d34e934bcb57a26 -- 
clang/include/clang/ASTMatchers/ASTMatchers.h 
clang/lib/ASTMatchers/Dynamic/Registry.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index a9e803eec5..b114d68182 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4092,7 +4092,7 @@ AST_POLYMORPHIC_MATCHER_P(
 /// Given
 /// \code
 ///   class Y
-///   { 
+///   {
 ///   public:
 ///   int a;
 ///   std::string b;

``




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


[clang] Add 'forNone' AST matcher (PR #86230)

2024-03-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: June Rhodes (hach-que)


Changes

This adds a `forNone` AST matcher, which matches only if there are no immediate 
children of the current node that match the inner matcher. For example, given:

```cpp
class F
{
public:
  int A;

  F() {};
};
```

the matcher:

```
cxxConstructorDecl(
unless(isImplicit()),
unless(isDelegatingConstructor()),
unless(isDeleted()),
unless(isDefaulted()),
hasBody(stmt()),
ofClass(cxxRecordDecl(forEach(fieldDecl().bind("declared_field",

forNone(cxxCtorInitializer(forField(fieldDecl(equalsBoundNode("declared_field")).bind("referenced_field"
).bind("bad_constructor")
```

would match `F()`, because it does not have an initializer for `A`. We use this 
in our modified version of Clang to detect constructors that do not fully 
initialize all fields.


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


4 Files Affected:

- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+7) 
- (modified) clang/include/clang/ASTMatchers/ASTMatchersInternal.h (+36) 
- (modified) clang/lib/ASTMatchers/ASTMatchersInternal.cpp (+2) 
- (modified) clang/lib/ASTMatchers/Dynamic/Registry.cpp (+1) 


``diff
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f71053d030f68..8cc7a0e92acbdd 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3547,6 +3547,13 @@ extern const internal::ArgumentAdaptingMatcherFunc<
 internal::ForEachDescendantMatcher>
 forEachDescendant;
 
+/// Matches AST nodes that have no child AST nodes that match the
+/// provided matcher.
+///
+/// Usable as: Any Matcher
+extern const internal::ArgumentAdaptingMatcherFunc
+forNone;
+
 /// Matches if the node or any descendant matches.
 ///
 /// Generates results for each match.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 47d912c73dd7eb..bf5aaf74c0ef9a 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1626,6 +1626,42 @@ class ForEachMatcher : public MatcherInterface {
   }
 };
 
+/// Matches nodes of type T that have no child nodes of type ChildT for
+/// which a specified child matcher matches. ChildT must be an AST base
+/// type.
+/// ForNoneMatcher will only match if none of the child nodes match
+/// the inner matcher.
+template 
+class ForNoneMatcher : public MatcherInterface {
+  static_assert(IsBaseType::value,
+"for none only accepts base type matcher");
+
+  DynTypedMatcher InnerMatcher;
+
+public:
+  explicit ForNoneMatcher(const Matcher &InnerMatcher)
+  : InnerMatcher(InnerMatcher) {}
+
+  bool matches(const T &Node, ASTMatchFinder *Finder,
+   BoundNodesTreeBuilder *Builder) const override {
+BoundNodesTreeBuilder MatchingBuilder(*Builder);
+bool AnyMatched = Finder->matchesChildOf(Node, this->InnerMatcher, 
&MatchingBuilder,
+ASTMatchFinder::BK_All);
+if (!AnyMatched) {
+  // We didn't iterate over any nodes that matched, so
+  // Builder would be empty. This is a success case.
+  return true;
+}
+// Otherwise remove from Builder any entries that we
+// also have in MatchingBuilder because we want to leave
+// only the remaining entries.
+return Builder->removeBindings(
+[&MatchingBuilder](const internal::BoundNodesMap &Nodes) {
+  return MatchingBuilder.contains(Nodes);
+});
+  }
+};
+
 /// @}
 
 template 
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index bf87b1aa0992a5..4a8f383011b336 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -1022,6 +1022,8 @@ const 
internal::ArgumentAdaptingMatcherFunc
 hasDescendant = {};
 const internal::ArgumentAdaptingMatcherFunc forEach =
 {};
+const internal::ArgumentAdaptingMatcherFunc forNone =
+{};
 const internal::ArgumentAdaptingMatcherFunc
 forEachDescendant = {};
 const internal::ArgumentAdaptingMatcherFunc<
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 2c75e6beb74301..f6b866e6a0bcbf 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -259,6 +259,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(forEachOverridden);
   REGISTER_MATCHER(forEachSwitchCase);
   REGISTER_MATCHER(forEachTemplateArgument);
+  REGISTER_MATCHER(forNone);
   REGISTER_MATCHER(forField);
   REGISTER_MATCHER(forFunction);
   REGISTER_MATCHER(forStmt);

``




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

[clang] Add 'forNone' and 'forNoDescendant' AST matchers (PR #86230)

2024-03-21 Thread June Rhodes via cfe-commits

https://github.com/hach-que updated 
https://github.com/llvm/llvm-project/pull/86230

>From 25e3b11324ba4fc43e36035d357d1aa785898bbc Mon Sep 17 00:00:00 2001
From: June Rhodes 
Date: Fri, 22 Mar 2024 13:07:57 +1100
Subject: [PATCH] Add 'forNone' and 'forNoDescendant' AST matchers

---
 clang/include/clang/ASTMatchers/ASTMatchers.h | 15 +++
 .../clang/ASTMatchers/ASTMatchersInternal.h   | 98 +++
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp | 13 +++
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|  2 +
 4 files changed, 128 insertions(+)

diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f71053d030f68..fa6afe2f02f6b0 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3547,6 +3547,21 @@ extern const internal::ArgumentAdaptingMatcherFunc<
 internal::ForEachDescendantMatcher>
 forEachDescendant;
 
+/// Matches AST nodes that have no child AST nodes that match the
+/// provided matcher.
+///
+/// Usable as: Any Matcher
+extern const internal::ArgumentAdaptingMatcherFunc
+forNone;
+
+/// Matches AST nodes that have no descendant AST nodes that match the
+/// provided matcher.
+///
+/// Usable as: Any Matcher
+extern const internal::ArgumentAdaptingMatcherFunc<
+internal::ForNoDescendantMatcher>
+forNoDescendant;
+
 /// Matches if the node or any descendant matches.
 ///
 /// Generates results for each match.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 47d912c73dd7eb..b40f0b77b042db 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -268,6 +268,26 @@ class BoundNodesMap {
 return true;
   }
 
+  /// Returns \c true if the \c BoundNodesMap entirely contains the values
+  /// in \c Subset.
+  bool contains(const BoundNodesMap &Subset) {
+const auto &N = this->NodeMap.end();
+if (Subset.NodeMap.size() == 1) {
+  // Avoid iteration if the subset only has a single value.
+  const auto &F = Subset.NodeMap.begin();
+  const auto &T = this->NodeMap.find(F->first);
+  return T != N && T->second == F->second;
+} else {
+  for (const auto &F : Subset.NodeMap) {
+const auto &T = this->NodeMap.find(F.first);
+if (T == N || T->second != F.second) {
+  return false;
+}
+  }
+}
+return true;
+  }
+
 private:
   IDToNodeMap NodeMap;
 };
@@ -306,6 +326,10 @@ class BoundNodesTreeBuilder {
   /// The ownership of 'ResultVisitor' remains at the caller.
   void visitMatches(Visitor* ResultVisitor);
 
+  /// Returns true if any of the entries in this tree contain the
+  /// other bound nodes map.
+  bool contains(const internal::BoundNodesMap &Subset);
+
   template 
   bool removeBindings(const ExcludePredicate &Predicate) {
 llvm::erase_if(Bindings, Predicate);
@@ -1626,6 +1650,42 @@ class ForEachMatcher : public MatcherInterface {
   }
 };
 
+/// Matches nodes of type T that have no child nodes of type ChildT for
+/// which a specified child matcher matches. ChildT must be an AST base
+/// type.
+/// ForNoneMatcher will only match if none of the child nodes match
+/// the inner matcher.
+template 
+class ForNoneMatcher : public MatcherInterface {
+  static_assert(IsBaseType::value,
+"for none only accepts base type matcher");
+
+  DynTypedMatcher InnerMatcher;
+
+public:
+  explicit ForNoneMatcher(const Matcher &InnerMatcher)
+  : InnerMatcher(InnerMatcher) {}
+
+  bool matches(const T &Node, ASTMatchFinder *Finder,
+   BoundNodesTreeBuilder *Builder) const override {
+BoundNodesTreeBuilder MatchingBuilder(*Builder);
+bool AnyMatched = Finder->matchesChildOf(
+Node, this->InnerMatcher, &MatchingBuilder, ASTMatchFinder::BK_All);
+if (!AnyMatched) {
+  // We didn't iterate over any nodes that matched, so
+  // Builder would be empty. This is a success case.
+  return true;
+}
+// Otherwise remove from Builder any entries that we
+// also have in MatchingBuilder because we want to leave
+// only the remaining entries.
+return Builder->removeBindings(
+[&MatchingBuilder](const internal::BoundNodesMap &Nodes) {
+  return MatchingBuilder.contains(Nodes);
+});
+  }
+};
+
 /// @}
 
 template 
@@ -1724,6 +1784,44 @@ class ForEachDescendantMatcher : public 
MatcherInterface {
   }
 };
 
+/// Matches nodes of type T that have no descendant node of
+/// type DescendantT for which the given inner matcher matches.
+///
+/// DescendantT must be an AST base type.
+/// ForNoDescendantMatcher only matches if none of the descendant nodes
+/// match.
+template 
+class ForNoDescendantMatcher : public MatcherInterface {
+  static_assert(IsBaseType::value,
+"for no descendant only accepts base type matcher");
+
+  DynTypedMat

[clang] Add 'isPODType' AST matcher (PR #86233)

2024-03-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: June Rhodes (hach-que)


Changes

This adds an `isPODType` AST matcher which matches if the matched type is a 
Plain Old Data (POD) type.

Given:

```cpp
class Y
{ 
public:
int a;
std::string b;
};
```

the matcher `fieldDecl(hasType(qualType(isPODType(` would match `Y::a` but 
not `Y::b`.

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


2 Files Affected:

- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+17) 
- (modified) clang/lib/ASTMatchers/Dynamic/Registry.cpp (+1) 


``diff
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f71053d030f68..a9e803eec570c7 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4087,6 +4087,23 @@ AST_POLYMORPHIC_MATCHER_P(
   return Inner.matches(source->getTypeLoc(), Finder, Builder);
 }
 
+/// Matches if the matched type is a Plain Old Data (POD) type.
+///
+/// Given
+/// \code
+///   class Y
+///   { 
+///   public:
+///   int a;
+///   std::string b;
+///   };
+/// \endcode
+/// fieldDecl(hasType(qualType(isPODType(
+///   matches Y::a
+AST_MATCHER(QualType, isPODType) {
+  return Node.isPODType(Finder->getASTContext());
+}
+
 /// Matches if the matched type is represented by the given string.
 ///
 /// Given
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 2c75e6beb74301..4f716d9f166495 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -377,6 +377,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(hasTypeLoc);
   REGISTER_MATCHER(hasUnaryOperand);
   REGISTER_MATCHER(hasUnarySelector);
+  REGISTER_MATCHER(isPODType);
   REGISTER_MATCHER(hasUnderlyingDecl);
   REGISTER_MATCHER(hasUnderlyingType);
   REGISTER_MATCHER(hasUnqualifiedDesugaredType);

``




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


[clang] Add 'isPODType' AST matcher (PR #86233)

2024-03-21 Thread June Rhodes via cfe-commits

https://github.com/hach-que created 
https://github.com/llvm/llvm-project/pull/86233

This adds an `isPODType` AST matcher which matches if the matched type is a 
Plain Old Data (POD) type.

Given:

```cpp
class Y
{ 
public:
int a;
std::string b;
};
```

the matcher `fieldDecl(hasType(qualType(isPODType(` would match `Y::a` but 
not `Y::b`.

>From 87d02c2278e023b9439be96c2d34e934bcb57a26 Mon Sep 17 00:00:00 2001
From: June Rhodes 
Date: Fri, 22 Mar 2024 13:36:54 +1100
Subject: [PATCH] Add 'isPODType' AST matcher

---
 clang/include/clang/ASTMatchers/ASTMatchers.h | 17 +
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|  1 +
 2 files changed, 18 insertions(+)

diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f71053d030f68..a9e803eec570c7 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4087,6 +4087,23 @@ AST_POLYMORPHIC_MATCHER_P(
   return Inner.matches(source->getTypeLoc(), Finder, Builder);
 }
 
+/// Matches if the matched type is a Plain Old Data (POD) type.
+///
+/// Given
+/// \code
+///   class Y
+///   { 
+///   public:
+///   int a;
+///   std::string b;
+///   };
+/// \endcode
+/// fieldDecl(hasType(qualType(isPODType(
+///   matches Y::a
+AST_MATCHER(QualType, isPODType) {
+  return Node.isPODType(Finder->getASTContext());
+}
+
 /// Matches if the matched type is represented by the given string.
 ///
 /// Given
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 2c75e6beb74301..4f716d9f166495 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -377,6 +377,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(hasTypeLoc);
   REGISTER_MATCHER(hasUnaryOperand);
   REGISTER_MATCHER(hasUnarySelector);
+  REGISTER_MATCHER(isPODType);
   REGISTER_MATCHER(hasUnderlyingDecl);
   REGISTER_MATCHER(hasUnderlyingType);
   REGISTER_MATCHER(hasUnqualifiedDesugaredType);

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


[clang] Add 'forNone' and 'forNoDescendant' AST matchers (PR #86230)

2024-03-21 Thread June Rhodes via cfe-commits

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


[clang] Add 'forNone' and 'forNoDescendant' AST matchers (PR #86230)

2024-03-21 Thread June Rhodes via cfe-commits

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


[clang] Add 'forNone' and 'forNoDescendant' AST matchers (PR #86230)

2024-03-21 Thread June Rhodes via cfe-commits

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


[clang] Add 'forNone' AST matcher (PR #86230)

2024-03-21 Thread June Rhodes via cfe-commits

https://github.com/hach-que updated 
https://github.com/llvm/llvm-project/pull/86230

>From 9b04a03646992a3366022dd7022858c98f7560e7 Mon Sep 17 00:00:00 2001
From: June Rhodes 
Date: Fri, 22 Mar 2024 13:07:57 +1100
Subject: [PATCH] Add 'forNone' and 'forNoDescendant' AST matchers

---
 clang/include/clang/ASTMatchers/ASTMatchers.h | 15 +++
 .../clang/ASTMatchers/ASTMatchersInternal.h   | 97 +++
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp | 13 +++
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|  2 +
 4 files changed, 127 insertions(+)

diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f71053d030f68..fa6afe2f02f6b0 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3547,6 +3547,21 @@ extern const internal::ArgumentAdaptingMatcherFunc<
 internal::ForEachDescendantMatcher>
 forEachDescendant;
 
+/// Matches AST nodes that have no child AST nodes that match the
+/// provided matcher.
+///
+/// Usable as: Any Matcher
+extern const internal::ArgumentAdaptingMatcherFunc
+forNone;
+
+/// Matches AST nodes that have no descendant AST nodes that match the
+/// provided matcher.
+///
+/// Usable as: Any Matcher
+extern const internal::ArgumentAdaptingMatcherFunc<
+internal::ForNoDescendantMatcher>
+forNoDescendant;
+
 /// Matches if the node or any descendant matches.
 ///
 /// Generates results for each match.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 47d912c73dd7eb..5612730462465a 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -268,6 +268,26 @@ class BoundNodesMap {
 return true;
   }
 
+  /// Returns \c true if the \c BoundNodesMap entirely contains the values
+  /// in \c Subset.
+  bool contains(const BoundNodesMap& Subset) {
+const auto &N = this->NodeMap.end();
+if (Subset.NodeMap.size() == 1) {
+  // Avoid iteration if the subset only has a single value.
+  const auto &F = Subset.NodeMap.begin();
+  const auto &T = this->NodeMap.find(F->first);
+  return T != N && T->second == F->second;
+} else {
+  for (const auto &F : Subset.NodeMap) {
+const auto &T = this->NodeMap.find(F.first);
+if (T == N || T->second != F.second) {
+  return false;
+}
+  }
+}
+return true;
+  }
+
 private:
   IDToNodeMap NodeMap;
 };
@@ -306,6 +326,10 @@ class BoundNodesTreeBuilder {
   /// The ownership of 'ResultVisitor' remains at the caller.
   void visitMatches(Visitor* ResultVisitor);
 
+  /// Returns true if any of the entries in this tree contain the
+  /// other bound nodes map.
+  bool contains(const internal::BoundNodesMap &Subset);
+
   template 
   bool removeBindings(const ExcludePredicate &Predicate) {
 llvm::erase_if(Bindings, Predicate);
@@ -1626,6 +1650,42 @@ class ForEachMatcher : public MatcherInterface {
   }
 };
 
+/// Matches nodes of type T that have no child nodes of type ChildT for
+/// which a specified child matcher matches. ChildT must be an AST base
+/// type.
+/// ForNoneMatcher will only match if none of the child nodes match
+/// the inner matcher.
+template 
+class ForNoneMatcher : public MatcherInterface {
+  static_assert(IsBaseType::value,
+"for none only accepts base type matcher");
+
+  DynTypedMatcher InnerMatcher;
+
+public:
+  explicit ForNoneMatcher(const Matcher &InnerMatcher)
+  : InnerMatcher(InnerMatcher) {}
+
+  bool matches(const T &Node, ASTMatchFinder *Finder,
+   BoundNodesTreeBuilder *Builder) const override {
+BoundNodesTreeBuilder MatchingBuilder(*Builder);
+bool AnyMatched = Finder->matchesChildOf(Node, this->InnerMatcher, 
&MatchingBuilder,
+ASTMatchFinder::BK_All);
+if (!AnyMatched) {
+  // We didn't iterate over any nodes that matched, so
+  // Builder would be empty. This is a success case.
+  return true;
+}
+// Otherwise remove from Builder any entries that we
+// also have in MatchingBuilder because we want to leave
+// only the remaining entries.
+return Builder->removeBindings(
+[&MatchingBuilder](const internal::BoundNodesMap &Nodes) {
+  return MatchingBuilder.contains(Nodes);
+});
+  }
+};
+
 /// @}
 
 template 
@@ -1724,6 +1784,43 @@ class ForEachDescendantMatcher : public 
MatcherInterface {
   }
 };
 
+/// Matches nodes of type T that have no descendant node of
+/// type DescendantT for which the given inner matcher matches.
+///
+/// DescendantT must be an AST base type.
+/// ForNoDescendantMatcher only matches if none of the descendant nodes
+/// match.
+template 
+class ForNoDescendantMatcher : public MatcherInterface {
+  static_assert(IsBaseType::value,
+"for no descendant only accepts base 

[clang] Add 'forNone' AST matcher (PR #86230)

2024-03-21 Thread June Rhodes via cfe-commits

https://github.com/hach-que updated 
https://github.com/llvm/llvm-project/pull/86230

>From bf78fb2172048c703824698b839e20ad1b8bf0b2 Mon Sep 17 00:00:00 2001
From: June Rhodes 
Date: Fri, 22 Mar 2024 13:07:57 +1100
Subject: [PATCH] Add 'forNone' AST matcher

---
 clang/include/clang/ASTMatchers/ASTMatchers.h |  7 +++
 .../clang/ASTMatchers/ASTMatchersInternal.h   | 60 +++
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp | 11 
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|  1 +
 4 files changed, 79 insertions(+)

diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f71053d030f68..8cc7a0e92acbdd 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3547,6 +3547,13 @@ extern const internal::ArgumentAdaptingMatcherFunc<
 internal::ForEachDescendantMatcher>
 forEachDescendant;
 
+/// Matches AST nodes that have no child AST nodes that match the
+/// provided matcher.
+///
+/// Usable as: Any Matcher
+extern const internal::ArgumentAdaptingMatcherFunc
+forNone;
+
 /// Matches if the node or any descendant matches.
 ///
 /// Generates results for each match.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 47d912c73dd7eb..fc6d44c3b8b933 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -268,6 +268,26 @@ class BoundNodesMap {
 return true;
   }
 
+  /// Returns \c true if the \c BoundNodesMap entirely contains the values
+  /// in \c Subset.
+  bool contains(const BoundNodesMap& Subset) {
+const auto &N = this->NodeMap.end();
+if (Subset.NodeMap.size() == 1) {
+  // Avoid iteration if the subset only has a single value.
+  const auto &F = Subset.NodeMap.begin();
+  const auto &T = this->NodeMap.find(F->first);
+  return T != N && T->second == F->second;
+} else {
+  for (const auto &F : Subset.NodeMap) {
+const auto &T = this->NodeMap.find(F.first);
+if (T == N || T->second != F.second) {
+  return false;
+}
+  }
+}
+return true;
+  }
+
 private:
   IDToNodeMap NodeMap;
 };
@@ -306,6 +326,10 @@ class BoundNodesTreeBuilder {
   /// The ownership of 'ResultVisitor' remains at the caller.
   void visitMatches(Visitor* ResultVisitor);
 
+  /// Returns true if any of the entries in this tree contain the
+  /// other bound nodes map.
+  bool contains(const internal::BoundNodesMap &Subset);
+
   template 
   bool removeBindings(const ExcludePredicate &Predicate) {
 llvm::erase_if(Bindings, Predicate);
@@ -1626,6 +1650,42 @@ class ForEachMatcher : public MatcherInterface {
   }
 };
 
+/// Matches nodes of type T that have no child nodes of type ChildT for
+/// which a specified child matcher matches. ChildT must be an AST base
+/// type.
+/// ForNoneMatcher will only match if none of the child nodes match
+/// the inner matcher.
+template 
+class ForNoneMatcher : public MatcherInterface {
+  static_assert(IsBaseType::value,
+"for none only accepts base type matcher");
+
+  DynTypedMatcher InnerMatcher;
+
+public:
+  explicit ForNoneMatcher(const Matcher &InnerMatcher)
+  : InnerMatcher(InnerMatcher) {}
+
+  bool matches(const T &Node, ASTMatchFinder *Finder,
+   BoundNodesTreeBuilder *Builder) const override {
+BoundNodesTreeBuilder MatchingBuilder(*Builder);
+bool AnyMatched = Finder->matchesChildOf(Node, this->InnerMatcher, 
&MatchingBuilder,
+ASTMatchFinder::BK_All);
+if (!AnyMatched) {
+  // We didn't iterate over any nodes that matched, so
+  // Builder would be empty. This is a success case.
+  return true;
+}
+// Otherwise remove from Builder any entries that we
+// also have in MatchingBuilder because we want to leave
+// only the remaining entries.
+return Builder->removeBindings(
+[&MatchingBuilder](const internal::BoundNodesMap &Nodes) {
+  return MatchingBuilder.contains(Nodes);
+});
+  }
+};
+
 /// @}
 
 template 
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index bf87b1aa0992a5..f36a8c3ae834c3 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -106,6 +106,15 @@ void BoundNodesTreeBuilder::visitMatches(Visitor 
*ResultVisitor) {
   }
 }
 
+bool BoundNodesTreeBuilder::contains(const internal::BoundNodesMap &Subset) {
+  for (BoundNodesMap &Binding : Bindings) {
+if (Binding.contains(Subset)) {
+  return true;
+}
+  }
+  return false;
+}
+
 namespace {
 
 using VariadicOperatorFunction = bool (*)(
@@ -1022,6 +1031,8 @@ const 
internal::ArgumentAdaptingMatcherFunc
 hasDescendant = {};
 const internal::ArgumentAdaptingMatcherFunc forEach =
   

[clang] Add 'forNone' AST matcher (PR #86230)

2024-03-21 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] Add 'forNone' AST matcher (PR #86230)

2024-03-21 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 718fbbef5f18a2b7e7fc4f842b1452ae9bee581a 
b0ef223dfab9c8ebc67601ccfbbe0ce3abe15f12 -- 
clang/include/clang/ASTMatchers/ASTMatchers.h 
clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
clang/lib/ASTMatchers/Dynamic/Registry.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index bf5aaf74c0..31c0ec2c29 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1645,8 +1645,8 @@ public:
   bool matches(const T &Node, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const override {
 BoundNodesTreeBuilder MatchingBuilder(*Builder);
-bool AnyMatched = Finder->matchesChildOf(Node, this->InnerMatcher, 
&MatchingBuilder,
-ASTMatchFinder::BK_All);
+bool AnyMatched = Finder->matchesChildOf(
+Node, this->InnerMatcher, &MatchingBuilder, ASTMatchFinder::BK_All);
 if (!AnyMatched) {
   // We didn't iterate over any nodes that matched, so
   // Builder would be empty. This is a success case.

``




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


[clang] Add 'forNone' AST matcher (PR #86230)

2024-03-21 Thread June Rhodes via cfe-commits

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


[clang] Add 'forNone' AST matcher (PR #86230)

2024-03-21 Thread June Rhodes via cfe-commits

https://github.com/hach-que created 
https://github.com/llvm/llvm-project/pull/86230

This adds a `forNone` AST matcher, which matches only if there are no immediate 
children of the current node that match the inner matcher. For example, given:

```cpp
class F
{
public:
  int A;

  F() {};
};
```

the matcher:

```
cxxConstructorDecl(
unless(isImplicit()),
unless(isDelegatingConstructor()),
unless(isDeleted()),
unless(isDefaulted()),
hasBody(stmt()),
unless(ofClass(cxxRecordDecl(isUClass(,
unless(ofClass(cxxRecordDecl(isUInterface(,
ofClass(cxxRecordDecl(forEach(fieldDecl().bind("declared_field",

forNone(cxxCtorInitializer(forField(fieldDecl(equalsBoundNode("declared_field")).bind("referenced_field"
).bind("bad_constructor")
```

would match `F()`, because it does not have an initializer for `A`. We use this 
in our modified version of Clang to detect constructors that do not fully 
initialize all fields.


>From b0ef223dfab9c8ebc67601ccfbbe0ce3abe15f12 Mon Sep 17 00:00:00 2001
From: June Rhodes 
Date: Fri, 22 Mar 2024 13:07:57 +1100
Subject: [PATCH] Add 'forNone' AST matcher

---
 clang/include/clang/ASTMatchers/ASTMatchers.h |  7 
 .../clang/ASTMatchers/ASTMatchersInternal.h   | 36 +++
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp |  2 ++
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|  1 +
 4 files changed, 46 insertions(+)

diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f71053d030f68..8cc7a0e92acbdd 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3547,6 +3547,13 @@ extern const internal::ArgumentAdaptingMatcherFunc<
 internal::ForEachDescendantMatcher>
 forEachDescendant;
 
+/// Matches AST nodes that have no child AST nodes that match the
+/// provided matcher.
+///
+/// Usable as: Any Matcher
+extern const internal::ArgumentAdaptingMatcherFunc
+forNone;
+
 /// Matches if the node or any descendant matches.
 ///
 /// Generates results for each match.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 47d912c73dd7eb..bf5aaf74c0ef9a 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1626,6 +1626,42 @@ class ForEachMatcher : public MatcherInterface {
   }
 };
 
+/// Matches nodes of type T that have no child nodes of type ChildT for
+/// which a specified child matcher matches. ChildT must be an AST base
+/// type.
+/// ForNoneMatcher will only match if none of the child nodes match
+/// the inner matcher.
+template 
+class ForNoneMatcher : public MatcherInterface {
+  static_assert(IsBaseType::value,
+"for none only accepts base type matcher");
+
+  DynTypedMatcher InnerMatcher;
+
+public:
+  explicit ForNoneMatcher(const Matcher &InnerMatcher)
+  : InnerMatcher(InnerMatcher) {}
+
+  bool matches(const T &Node, ASTMatchFinder *Finder,
+   BoundNodesTreeBuilder *Builder) const override {
+BoundNodesTreeBuilder MatchingBuilder(*Builder);
+bool AnyMatched = Finder->matchesChildOf(Node, this->InnerMatcher, 
&MatchingBuilder,
+ASTMatchFinder::BK_All);
+if (!AnyMatched) {
+  // We didn't iterate over any nodes that matched, so
+  // Builder would be empty. This is a success case.
+  return true;
+}
+// Otherwise remove from Builder any entries that we
+// also have in MatchingBuilder because we want to leave
+// only the remaining entries.
+return Builder->removeBindings(
+[&MatchingBuilder](const internal::BoundNodesMap &Nodes) {
+  return MatchingBuilder.contains(Nodes);
+});
+  }
+};
+
 /// @}
 
 template 
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index bf87b1aa0992a5..4a8f383011b336 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -1022,6 +1022,8 @@ const 
internal::ArgumentAdaptingMatcherFunc
 hasDescendant = {};
 const internal::ArgumentAdaptingMatcherFunc forEach =
 {};
+const internal::ArgumentAdaptingMatcherFunc forNone =
+{};
 const internal::ArgumentAdaptingMatcherFunc
 forEachDescendant = {};
 const internal::ArgumentAdaptingMatcherFunc<
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 2c75e6beb74301..f6b866e6a0bcbf 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -259,6 +259,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(forEachOverridden);
   REGISTER_MATCHER(forEachSwitchCase);
   REGISTER_MATCHER(forEachTemplateArgument);
+  REGISTER_MATCHER(forNone);
   REGISTER_MATCHER(forField);
   REGISTER_MATCHER(forFunctio

[clang] Add 'refersToPack' AST matcher (PR #86228)

2024-03-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: June Rhodes (hach-que)


Changes

This adds a 'refersToPack' AST matcher, which can be used to match against 
template arguments that are inside parameter packs. The inner matcher is 
evaluated against each argument in the parameter pack, such that given:

```cpp
template class A {};
A a;
A b;
A c;
```

The matcher 
`classTemplateSpecializationDecl(hasAnyTemplateArgument(refersToPack(refersToType(...`
 would evaluate the `refersToType` against:

- For `a`, the `double` template argument. 
- For `b`, the `int` template argument.
- For `c`, the `int` template argument, then the `long` template argument.

If the inner matcher matches against any argument of the parameter pack, then 
`refersToPack` matches.

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


2 Files Affected:

- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+29) 
- (modified) clang/lib/ASTMatchers/Dynamic/Registry.cpp (+1) 


``diff
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f71053d030f68..df30d4c85c22c6 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1151,6 +1151,35 @@ AST_MATCHER_P(TemplateArgument, refersToDeclaration,
   return false;
 }
 
+/// Matches template arguments within a pack template argument; the inner
+/// matcher is compared against each argument of the parameter pack.
+///
+/// Given
+/// \code
+///   template class A {};
+///   A a;
+///   A b;
+/// \endcode
+///
+/// \endcode
+/// classTemplateSpecializationDecl(hasAnyTemplateArgument(
+/// refersToPack(refersToType(asString("double")
+///   matches the specialization \c A
+///   but does not match the specialization \c A
+AST_MATCHER_P(TemplateArgument, refersToPack,
+  internal::Matcher, InnerMatcher) {
+  if (Node.getKind() == TemplateArgument::Pack) {
+for (const TemplateArgument &Arg : Node.pack_elements()) {
+  BoundNodesTreeBuilder Result(*Builder);
+  if (InnerMatcher.matches(Arg, Finder, &Result)) {
+*Builder = std::move(Result);
+return true;
+  }
+}
+  }
+  return false;
+}
+
 /// Matches a sugar TemplateArgument that refers to a certain expression.
 ///
 /// Given
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 2c75e6beb74301..732d49e850288a 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -551,6 +551,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(referenceType);
   REGISTER_MATCHER(referenceTypeLoc);
   REGISTER_MATCHER(refersToDeclaration);
+  REGISTER_MATCHER(refersToPack);
   REGISTER_MATCHER(refersToIntegralType);
   REGISTER_MATCHER(refersToTemplate);
   REGISTER_MATCHER(refersToType);

``




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


[clang] Add 'refersToPack' AST matcher (PR #86228)

2024-03-21 Thread June Rhodes via cfe-commits

https://github.com/hach-que created 
https://github.com/llvm/llvm-project/pull/86228

This adds a 'refersToPack' AST matcher, which can be used to match against 
template arguments that are inside parameter packs. The inner matcher is 
evaluated against each argument in the parameter pack, such that given:

```cpp
template class A {};
A a;
A b;
A c;
```

The matcher 
`classTemplateSpecializationDecl(hasAnyTemplateArgument(refersToPack(refersToType(...`
 would evaluate the `refersToType` against:

- For `a`, the `double` template argument. 
- For `b`, the `int` template argument.
- For `c`, the `int` template argument, then the `long` template argument.

If the inner matcher matches against any argument of the parameter pack, then 
`refersToPack` matches.

>From e298ea2437dfdd3d44e7d53ef2a5e41bf17bd329 Mon Sep 17 00:00:00 2001
From: June Rhodes 
Date: Fri, 22 Mar 2024 12:51:40 +1100
Subject: [PATCH] Add 'refersToPack' AST matcher

---
 clang/include/clang/ASTMatchers/ASTMatchers.h | 29 +++
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|  1 +
 2 files changed, 30 insertions(+)

diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2f71053d030f68..df30d4c85c22c6 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1151,6 +1151,35 @@ AST_MATCHER_P(TemplateArgument, refersToDeclaration,
   return false;
 }
 
+/// Matches template arguments within a pack template argument; the inner
+/// matcher is compared against each argument of the parameter pack.
+///
+/// Given
+/// \code
+///   template class A {};
+///   A a;
+///   A b;
+/// \endcode
+///
+/// \endcode
+/// classTemplateSpecializationDecl(hasAnyTemplateArgument(
+/// refersToPack(refersToType(asString("double")
+///   matches the specialization \c A
+///   but does not match the specialization \c A
+AST_MATCHER_P(TemplateArgument, refersToPack,
+  internal::Matcher, InnerMatcher) {
+  if (Node.getKind() == TemplateArgument::Pack) {
+for (const TemplateArgument &Arg : Node.pack_elements()) {
+  BoundNodesTreeBuilder Result(*Builder);
+  if (InnerMatcher.matches(Arg, Finder, &Result)) {
+*Builder = std::move(Result);
+return true;
+  }
+}
+  }
+  return false;
+}
+
 /// Matches a sugar TemplateArgument that refers to a certain expression.
 ///
 /// Given
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 2c75e6beb74301..732d49e850288a 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -551,6 +551,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(referenceType);
   REGISTER_MATCHER(referenceTypeLoc);
   REGISTER_MATCHER(refersToDeclaration);
+  REGISTER_MATCHER(refersToPack);
   REGISTER_MATCHER(refersToIntegralType);
   REGISTER_MATCHER(refersToTemplate);
   REGISTER_MATCHER(refersToType);

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


[clang] [X86_32] Teach X86_32 va_arg to ignore empty structs. (PR #86075)

2024-03-21 Thread Longsheng Mou via cfe-commits


@@ -1069,6 +1069,10 @@ Address X86_32ABIInfo::EmitVAArg(CodeGenFunction &CGF,
 
   auto TypeInfo = getContext().getTypeInfoInChars(Ty);
 
+  // Empty records are ignored for parameter passing purposes on non-Windows.
+  if (!IsWin32StructABI && isEmptyRecord(getContext(), Ty, true))
+return CGF.CreateMemTemp(Ty);

CoTinker wrote:

classifyArgumentType in X86_32 need CCState parameter, but we can not get it in 
this scope, because the CCState is temporarily calculated in 
X86_32ABIInfo::computeInfo.

https://github.com/llvm/llvm-project/pull/86075
___
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 new check readability-enum-initial-value (PR #86129)

2024-03-21 Thread Congcong Cai via cfe-commits


@@ -0,0 +1,82 @@
+//===--- EnumInitialValueCheck.cpp - clang-tidy 
---===//
+//
+// 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
+//
+//===--===//
+
+#include "EnumInitialValueCheck.h"
+#include "../utils/LexerUtils.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/SmallString.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+namespace {
+
+AST_MATCHER(EnumDecl, isNoneEnumeratorsInitialized) {
+  return llvm::all_of(Node.enumerators(), [](EnumConstantDecl const *ECD) {
+return ECD->getInitExpr() == nullptr;
+  });
+}
+
+AST_MATCHER(EnumDecl, isOnlyFirstEnumeratorsInitialized) {
+  for (EnumConstantDecl const *ECD : Node.enumerators())
+if (ECD == *Node.enumerator_begin()) {
+  if (ECD->getInitExpr() == nullptr)
+return false;
+} else {
+  if (ECD->getInitExpr() != nullptr)
+return false;
+}
+  return true;
+}
+
+AST_MATCHER(EnumDecl, isAllEnumeratorsInitialized) {
+  return llvm::all_of(Node.enumerators(), [](EnumConstantDecl const *ECD) {
+return ECD->getInitExpr() != nullptr;
+  });
+}
+
+} // namespace
+
+void EnumInitialValueCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(enumDecl(unless(anyOf(isNoneEnumeratorsInitialized(),
+   isOnlyFirstEnumeratorsInitialized(),
+   isAllEnumeratorsInitialized(

HerrCai0907 wrote:

I will add some options to make it possible to let it strict.
But I don't find the code guideline about "all enums are initialized but with 
consecutive values, in such case those inits could be removed and only first 
could be left". Inferring the usage of enum is hard and impossible, I think 
adding this check will create lots of false positive.
For example 
```c++
enum A {
a = 0,
b = 1,
c = 2,
}
```
can also be a bitmap.

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


[clang] Add 'refersToPack' AST matcher (PR #86228)

2024-03-21 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [NFC][Clang] Fix static analyzer bugs with dereference after null checks (PR #86018)

2024-03-21 Thread via cfe-commits

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


[clang] [NFC][Clang] Fix static analyzer bugs with dereference after null checks (PR #86018)

2024-03-21 Thread via cfe-commits

smanna12 wrote:

> If you read the code, it should be obvious the pointer is in fact non-null. 
> Please don't insert null checks into the code just to address static analyzer 
> false positives.

Thank you @efriedma-quic for reviews! I misunderstood some of the code parts.  

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


[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)

2024-03-21 Thread via cfe-commits

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

Thanks for looking into this.

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


[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-21 Thread Changpeng Fang via cfe-commits

changpeng wrote:

> I don't think intrinsics are meant for users. Builtins are the user-facing 
> front. :-)

Then renaing the intrinsics should be relatively at a lower priority. We may do 
it in a separate patch once we have reached an agreement.

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


[clang] [Clang] Make '-frtlib-add-rpath' include the standard library directory (PR #86217)

2024-03-21 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/86217

>From 722b8b454d652b3d52e20b9bacff58e096cc7feb Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 21 Mar 2024 18:25:35 -0500
Subject: [PATCH] [Clang] Make '-frtlib-add-rpath' include the standard library
 directory

Summary:
The original intention of the `openmp-add-rpath` option was to add the
rpath to the language runtime directory. However, the current
implementation only adds it to the compiler's resource directory. This
patch adds support for appending the `-rpath` to the compiler's standard
library directory as well. Currently this is `/../lib/`.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4478865313636d..6b1fbba7abd031 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1142,7 +1142,11 @@ void tools::addArchSpecificRPath(const ToolChain &TC, 
const ArgList &Args,
 options::OPT_fno_rtlib_add_rpath, false))
 return;
 
-  for (const auto &CandidateRPath : TC.getArchSpecificLibPaths()) {
+  SmallVector CandidateRPaths(TC.getArchSpecificLibPaths());
+  if (const auto CandidateRPath = TC.getStdlibPath())
+CandidateRPaths.emplace_back(*CandidateRPath);
+
+  for (const auto &CandidateRPath : CandidateRPaths) {
 if (TC.getVFS().exists(CandidateRPath)) {
   CmdArgs.push_back("-rpath");
   CmdArgs.push_back(Args.MakeArgString(CandidateRPath));

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


[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-21 Thread Heejin Ahn via cfe-commits

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


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


[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-21 Thread Shilei Tian via cfe-commits

shiltian wrote:

> > > > Do you want to rename intrinsics as well? Because now intrinsic names 
> > > > do not match builtin names.
> > > 
> > > 
> > > Do we have to match builtins with intrinsics? Renaming intrinsics here 
> > > means we will have to duplicate the intrinsics.
> > 
> > 
> > Is that because of the mangling?
> > Right.  It was originally suggested to use  a single instrinsic "load_lr".  
> > But eventually we use global_load_tr to indicate this is in global address 
> > space.  If we want to rename intrinsics here, it should be 
> > global_load_tr_b64 and global_load_tr_b128.
> 
> We should rename intrinsic if users can use intrinsics directly. I think 
> use-friendly is more important.

I don't think intrinsics are meant for users. Builtins are the user-facing 
front. :-)

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


[clang] [llvm] [CodeGen][LLVM] Make the `va_list` related intrinsics generic. (PR #85460)

2024-03-21 Thread Jessica Clarke via cfe-commits

jrtc27 wrote:

This probably also needs to tweak LangRef

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


[clang] [Clang] Make '-frtlib-add-rpath' include the standard library directory (PR #86217)

2024-03-21 Thread Fangrui Song via cfe-commits

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


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


[clang] [llvm] [CodeGen][LLVM] Make the `va_list` related intrinsics generic. (PR #85460)

2024-03-21 Thread Alexander Richardson via cfe-commits


@@ -792,13 +792,14 @@ EncompassingIntegerType(ArrayRef Types) {
 
 Value *CodeGenFunction::EmitVAStartEnd(Value *ArgValue, bool IsStart) {
   Intrinsic::ID inst = IsStart ? Intrinsic::vastart : Intrinsic::vaend;
-  return Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue);
+  return Builder.CreateCall(CGM.getIntrinsic(inst, {ArgValue->getType()}),
+ArgValue);
 }
 
 /// Checks if using the result of __builtin_object_size(p, @p From) in place of
 /// __builtin_object_size(p, @p To) is correct
 static bool areBOSTypesCompatible(int From, int To) {
-  // Note: Our __builtin_object_size implementation currently treats Type=0 and
+  // Note: Our __builtin_object_size implementation currently treats Type=0 
andV

arichardson wrote:

```suggestion
  // Note: Our __builtin_object_size implementation currently treats Type=0 and
```
typo

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


[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)

2024-03-21 Thread Usama Hameed via cfe-commits

https://github.com/usama54321 created 
https://github.com/llvm/llvm-project/pull/86220

The HOST_LINK_VERSION is a hardcoded string in Darwin clang that detects the 
linker version at configure time. The driver uses this information to build the 
correct set of arguments for the linker. This patch detects the linker version 
again during compiler-rt configuration and passes it to the tests. This allows 
a clang built on a machine with a new linker to run compiler-rt tests on a 
machine with an old linker.

rdar://125198603

>From 3148a5e1030493d37da0b24079b1280d9f893331 Mon Sep 17 00:00:00 2001
From: usama 
Date: Thu, 21 Mar 2024 16:56:32 -0700
Subject: [PATCH] Get the linker version and pass the it to compiler-rt tests
 on Darwin.

The HOST_LINK_VERSION is a hardcoded string in Darwin clang that detects
the linker version at configure time. The driver uses this information
to build the correct set of arguments for the linker. This patch detects
the linker version again during compiler-rt configuration and passes it
to the tests. This allows a clang built on a machine with a new linker
to run compiler-rt tests on a machine with an old linker.

rdar://125198603
---
 clang/CMakeLists.txt   | 16 ++--
 cmake/Modules/GetDarwinLinkerVersion.cmake | 19 +++
 compiler-rt/CMakeLists.txt | 10 ++
 compiler-rt/test/lit.common.cfg.py |  4 
 compiler-rt/test/lit.common.configured.in  |  1 +
 5 files changed, 36 insertions(+), 14 deletions(-)
 create mode 100644 cmake/Modules/GetDarwinLinkerVersion.cmake

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 761dab8c28c134..bcafbc37fbe1fb 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -15,6 +15,7 @@ endif()
 
 # Must go below project(..)
 include(GNUInstallDirs)
+include(GetDarwinLinkerVersion)
 
 if(CLANG_BUILT_STANDALONE)
   set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
@@ -346,20 +347,7 @@ endif ()
 # Determine HOST_LINK_VERSION on Darwin.
 set(HOST_LINK_VERSION)
 if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*")
-  set(LD_V_OUTPUT)
-  execute_process(
-COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
-RESULT_VARIABLE HAD_ERROR
-OUTPUT_VARIABLE LD_V_OUTPUT
-  )
-  if (HAD_ERROR)
-message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
-  endif()
-  if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
-string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION 
${LD_V_OUTPUT})
-  elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
-string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION 
${LD_V_OUTPUT})
-  endif()
+  get_darwin_linker_version()
   message(STATUS "Host linker version: ${HOST_LINK_VERSION}")
 endif()
 
diff --git a/cmake/Modules/GetDarwinLinkerVersion.cmake 
b/cmake/Modules/GetDarwinLinkerVersion.cmake
new file mode 100644
index 00..b6a10fdc173677
--- /dev/null
+++ b/cmake/Modules/GetDarwinLinkerVersion.cmake
@@ -0,0 +1,19 @@
+# Get the linker version on Darwin
+function(get_darwin_linker_version)
+  set(LINK_VERSION)
+  set(LD_V_OUTPUT)
+  execute_process(
+COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
+RESULT_VARIABLE HAD_ERROR
+OUTPUT_VARIABLE LD_V_OUTPUT
+)
+  if (HAD_ERROR)
+message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
+  endif()
+  if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
+string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" LINK_VERSION 
${LD_V_OUTPUT})
+  elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
+string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" LINK_VERSION 
${LD_V_OUTPUT})
+  endif()
+  set(HOST_LINK_VERSION ${LINK_VERSION} PARENT_SCOPE)
+endfunction()
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index d562a6206c00e7..9fb15403b933dc 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -36,6 +36,7 @@ include(SetPlatformToolchainTools)
 include(base-config-ix)
 include(CompilerRTUtils)
 include(CMakeDependentOption)
+include(GetDarwinLinkerVersion)
 
 option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
 mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
@@ -444,6 +445,15 @@ else()
   set(SANITIZER_USE_SYMBOLS FALSE)
 endif()
 
+# Get the linker version while configuring compiler-rt and explicitly pass it
+# in cflags during testing. This fixes the compiler/linker version mismatch
+# issue when running a clang built with a newer Xcode in an older Xcode
+set(HOST_LINK_VERSION)
+if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*")
+  get_darwin_linker_version()
+  message(STATUS "Host linker version: ${HOST_LINK_VERSION}")
+endif()
+
 # Build sanitizer runtimes with debug info.
 if(MSVC)
   # Use /Z7 instead of /Zi for the asan runtime. This avoids the LNK4099
diff --git a/compiler-rt/test/lit.common.cfg.py 
b/compiler-rt/test/lit.common.cfg.py
index bd9b926c1505b1..cc59a794e11352 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/co

[clang] [llvm] [CodeGen][LLVM] Make the `va_list` related intrinsics generic. (PR #85460)

2024-03-21 Thread Alex Voicu via cfe-commits


@@ -700,10 +700,13 @@ class MSBuiltin {
 //===--- Variable Argument Handling Intrinsics 
===//
 //
 
-def int_vastart : DefaultAttrsIntrinsic<[], [llvm_ptr_ty], [], 
"llvm.va_start">;
-def int_vacopy  : DefaultAttrsIntrinsic<[], [llvm_ptr_ty, llvm_ptr_ty], [],
-"llvm.va_copy">;
-def int_vaend   : DefaultAttrsIntrinsic<[], [llvm_ptr_ty], [], "llvm.va_end">;
+def int_vastart : DefaultAttrsIntrinsic<[],
+[llvm_anyptr_ty], [], "llvm.va_start">;
+def int_vacopy  : DefaultAttrsIntrinsic<[],
+[llvm_anyptr_ty, llvm_anyptr_ty], [],
+"llvm.va_copy">;

AlexVlx wrote:

Ok, I think you and @arsenm have the right of it, I've taken Matt's suggestion.

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


[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)

2024-03-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Usama Hameed (usama54321)


Changes

The HOST_LINK_VERSION is a hardcoded string in Darwin clang that detects the 
linker version at configure time. The driver uses this information to build the 
correct set of arguments for the linker. This patch detects the linker version 
again during compiler-rt configuration and passes it to the tests. This allows 
a clang built on a machine with a new linker to run compiler-rt tests on a 
machine with an old linker.

rdar://125198603

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


5 Files Affected:

- (modified) clang/CMakeLists.txt (+2-14) 
- (added) cmake/Modules/GetDarwinLinkerVersion.cmake (+19) 
- (modified) compiler-rt/CMakeLists.txt (+10) 
- (modified) compiler-rt/test/lit.common.cfg.py (+4) 
- (modified) compiler-rt/test/lit.common.configured.in (+1) 


``diff
diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 761dab8c28c134..bcafbc37fbe1fb 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -15,6 +15,7 @@ endif()
 
 # Must go below project(..)
 include(GNUInstallDirs)
+include(GetDarwinLinkerVersion)
 
 if(CLANG_BUILT_STANDALONE)
   set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
@@ -346,20 +347,7 @@ endif ()
 # Determine HOST_LINK_VERSION on Darwin.
 set(HOST_LINK_VERSION)
 if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*")
-  set(LD_V_OUTPUT)
-  execute_process(
-COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
-RESULT_VARIABLE HAD_ERROR
-OUTPUT_VARIABLE LD_V_OUTPUT
-  )
-  if (HAD_ERROR)
-message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
-  endif()
-  if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
-string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION 
${LD_V_OUTPUT})
-  elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
-string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION 
${LD_V_OUTPUT})
-  endif()
+  get_darwin_linker_version()
   message(STATUS "Host linker version: ${HOST_LINK_VERSION}")
 endif()
 
diff --git a/cmake/Modules/GetDarwinLinkerVersion.cmake 
b/cmake/Modules/GetDarwinLinkerVersion.cmake
new file mode 100644
index 00..b6a10fdc173677
--- /dev/null
+++ b/cmake/Modules/GetDarwinLinkerVersion.cmake
@@ -0,0 +1,19 @@
+# Get the linker version on Darwin
+function(get_darwin_linker_version)
+  set(LINK_VERSION)
+  set(LD_V_OUTPUT)
+  execute_process(
+COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
+RESULT_VARIABLE HAD_ERROR
+OUTPUT_VARIABLE LD_V_OUTPUT
+)
+  if (HAD_ERROR)
+message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
+  endif()
+  if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
+string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" LINK_VERSION 
${LD_V_OUTPUT})
+  elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
+string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" LINK_VERSION 
${LD_V_OUTPUT})
+  endif()
+  set(HOST_LINK_VERSION ${LINK_VERSION} PARENT_SCOPE)
+endfunction()
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index d562a6206c00e7..9fb15403b933dc 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -36,6 +36,7 @@ include(SetPlatformToolchainTools)
 include(base-config-ix)
 include(CompilerRTUtils)
 include(CMakeDependentOption)
+include(GetDarwinLinkerVersion)
 
 option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
 mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
@@ -444,6 +445,15 @@ else()
   set(SANITIZER_USE_SYMBOLS FALSE)
 endif()
 
+# Get the linker version while configuring compiler-rt and explicitly pass it
+# in cflags during testing. This fixes the compiler/linker version mismatch
+# issue when running a clang built with a newer Xcode in an older Xcode
+set(HOST_LINK_VERSION)
+if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*")
+  get_darwin_linker_version()
+  message(STATUS "Host linker version: ${HOST_LINK_VERSION}")
+endif()
+
 # Build sanitizer runtimes with debug info.
 if(MSVC)
   # Use /Z7 instead of /Zi for the asan runtime. This avoids the LNK4099
diff --git a/compiler-rt/test/lit.common.cfg.py 
b/compiler-rt/test/lit.common.cfg.py
index bd9b926c1505b1..cc59a794e11352 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -882,6 +882,10 @@ def is_windows_lto_supported():
 elif config.use_lld and (not config.has_lld):
 config.unsupported = True
 
+if config.host_os == "Darwin":
+if getattr(config, "host_link_version", None):
+extra_cflags += ["-mlinker-version=" + config.host_link_version]
+
 # Append any extra flags passed in lit_config
 append_target_cflags = lit_config.params.get("append_target_cflags", None)
 if append_target_cflags:
diff --git a/compiler-rt/test/lit.common.configured.in 
b/compiler-rt/test/lit.common.configured.in
index db5d7c598b7310..28c0f02a03976c 100644
--- a/compiler-rt/test/lit.common.configured.in
+++ b/compiler-rt/test/lit.

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Joshua Batista via cfe-commits

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

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 1/8] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+

[clang] [llvm] [CIR][Basic][NFC] Add the CIR language to the Language enum (PR #86072)

2024-03-21 Thread Nathan Lanza via cfe-commits

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


[clang] [llvm] [CIR][Basic][NFC] Add the CIR language to the Language enum (PR #86072)

2024-03-21 Thread Nathan Lanza via cfe-commits

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


[clang] [llvm] [CIR][Basic][NFC] Add the CIR language to the Language enum (PR #86072)

2024-03-21 Thread Nathan Lanza via cfe-commits

https://github.com/lanza updated https://github.com/llvm/llvm-project/pull/86072

>From 115f1dcca7b20dacdc5beef0e73819aef94f0ec1 Mon Sep 17 00:00:00 2001
From: Nathan Lanza 
Date: Thu, 21 Mar 2024 03:24:54 +
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 clang/include/clang/Basic/LangStandard.h|  1 +
 clang/include/clang/Driver/Types.def|  1 +
 clang/lib/Basic/LangStandards.cpp   |  3 +++
 .../Serialization/SymbolGraphSerializer.cpp |  1 +
 clang/lib/Frontend/CompilerInvocation.cpp   | 13 +++--
 clang/lib/Frontend/FrontendActions.cpp  |  1 +
 clang/lib/Frontend/FrontendOptions.cpp  |  1 +
 7 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index 199e24c6731603..ed9572672f0563 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -41,6 +41,7 @@ enum class Language : uint8_t {
   RenderScript,
   HIP,
   HLSL,
+  CIR,
   ///@}
 };
 StringRef languageToString(Language L);
diff --git a/clang/include/clang/Driver/Types.def 
b/clang/include/clang/Driver/Types.def
index f72c27e1ee7019..0e0cae5fb7068d 100644
--- a/clang/include/clang/Driver/Types.def
+++ b/clang/include/clang/Driver/Types.def
@@ -90,6 +90,7 @@ TYPE("ir",   LLVM_BC,  INVALID,   
  "bc", phases
 TYPE("lto-ir",   LTO_IR,   INVALID, "s",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("lto-bc",   LTO_BC,   INVALID, "o",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 
+TYPE("cir",  CIR,  INVALID, "cir",
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 // Misc.
 TYPE("ast",  AST,  INVALID, "ast",
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("ifs",  IFS,  INVALID, "ifs",
phases::IfsMerge)
diff --git a/clang/lib/Basic/LangStandards.cpp 
b/clang/lib/Basic/LangStandards.cpp
index cb2c0772349982..c8c9292abcb22b 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -21,6 +21,8 @@ StringRef clang::languageToString(Language L) {
 return "Asm";
   case Language::LLVM_IR:
 return "LLVM IR";
+  case Language::CIR:
+return "ClangIR";
   case Language::C:
 return "C";
   case Language::CXX:
@@ -92,6 +94,7 @@ LangStandard::Kind 
clang::getDefaultLanguageStandard(clang::Language Lang,
   switch (Lang) {
   case Language::Unknown:
   case Language::LLVM_IR:
+  case Language::CIR:
 llvm_unreachable("Invalid input kind!");
   case Language::OpenCL:
 return LangStandard::lang_opencl12;
diff --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 349b93e2a2326f..545860acb7db80 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -208,6 +208,7 @@ StringRef getLanguageName(Language Lang) {
   case Language::Unknown:
   case Language::Asm:
   case Language::LLVM_IR:
+  case Language::CIR:
 llvm_unreachable("Unsupported language kind");
   }
 
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 0df6a82ccd8933..7bd91d4791ecf0 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2757,6 +2757,9 @@ static void GenerateFrontendArgs(const FrontendOptions 
&Opts,
 case Language::HLSL:
   Lang = "hlsl";
   break;
+case Language::CIR:
+  Lang = "cir";
+  break;
 }
 
 GenerateArg(Consumer, OPT_x,
@@ -2958,6 +2961,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, 
ArgList &Args,
   .Cases("ast", "pcm", "precompiled-header",
  InputKind(Language::Unknown, InputKind::Precompiled))
   .Case("ir", Language::LLVM_IR)
+  .Case("cir", Language::CIR)
   .Default(Language::Unknown);
 
 if (DashX.isUnknown())
@@ -3323,6 +3327,7 @@ static bool IsInputCompatibleWithStandard(InputKind IK,
   switch (IK.getLanguage()) {
   case Language::Unknown:
   case Language::LLVM_IR:
+  case Language::CIR:
 llvm_unreachable("should not parse language flags for this input");
 
   case Language::C:
@@ -3388,6 +3393,8 @@ static StringRef GetInputKindName(InputKind IK) {
 return "Asm";
   case Language::LLVM_IR:
 return "LLVM IR";
+  case Language::CIR:
+return "Clang IR";
 
   case Language::HLSL:
 return "H

[clang] e66b670 - [CIR][Basic][NFC] Add the CIR language to the Language enum

2024-03-21 Thread via cfe-commits

Author: Nathan Lanza
Date: 2024-03-21T19:53:48-04:00
New Revision: e66b670f3bf9312f696e66c31152ae535207d6bb

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

LOG: [CIR][Basic][NFC] Add the CIR language to the Language enum

Add the CIR language to the Language enum and the standard usages of it.

commit-id:fd12b2c2

Reviewers: bcardosolopes, AaronBallman, erichkeane

Reviewed By: AaronBallman, bcardosolopes

Pull Request: https://github.com/llvm/llvm-project/pull/86072

Added: 


Modified: 
clang/include/clang/Basic/LangStandard.h
clang/include/clang/Driver/Types.def
clang/lib/Basic/LangStandards.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Frontend/FrontendOptions.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index 199e24c6731603..8e25afc833661c 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -26,8 +26,9 @@ enum class Language : uint8_t {
   /// Assembly: we accept this only so that we can preprocess it.
   Asm,
 
-  /// LLVM IR: we accept this so that we can run the optimizer on it,
-  /// and compile it to assembly or object code.
+  /// LLVM IR & CIR: we accept these so that we can run the optimizer on them,
+  /// and compile them to assembly or object code (or LLVM for CIR).
+  CIR,
   LLVM_IR,
 
   ///@{ Languages that the frontend can parse and compile.

diff  --git a/clang/include/clang/Driver/Types.def 
b/clang/include/clang/Driver/Types.def
index f72c27e1ee7019..0e0cae5fb7068d 100644
--- a/clang/include/clang/Driver/Types.def
+++ b/clang/include/clang/Driver/Types.def
@@ -90,6 +90,7 @@ TYPE("ir",   LLVM_BC,  INVALID,   
  "bc", phases
 TYPE("lto-ir",   LTO_IR,   INVALID, "s",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("lto-bc",   LTO_BC,   INVALID, "o",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 
+TYPE("cir",  CIR,  INVALID, "cir",
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 // Misc.
 TYPE("ast",  AST,  INVALID, "ast",
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("ifs",  IFS,  INVALID, "ifs",
phases::IfsMerge)

diff  --git a/clang/lib/Basic/LangStandards.cpp 
b/clang/lib/Basic/LangStandards.cpp
index cb2c0772349982..c8c9292abcb22b 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -21,6 +21,8 @@ StringRef clang::languageToString(Language L) {
 return "Asm";
   case Language::LLVM_IR:
 return "LLVM IR";
+  case Language::CIR:
+return "ClangIR";
   case Language::C:
 return "C";
   case Language::CXX:
@@ -92,6 +94,7 @@ LangStandard::Kind 
clang::getDefaultLanguageStandard(clang::Language Lang,
   switch (Lang) {
   case Language::Unknown:
   case Language::LLVM_IR:
+  case Language::CIR:
 llvm_unreachable("Invalid input kind!");
   case Language::OpenCL:
 return LangStandard::lang_opencl12;

diff  --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 349b93e2a2326f..545860acb7db80 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -208,6 +208,7 @@ StringRef getLanguageName(Language Lang) {
   case Language::Unknown:
   case Language::Asm:
   case Language::LLVM_IR:
+  case Language::CIR:
 llvm_unreachable("Unsupported language kind");
   }
 

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 0df6a82ccd8933..7bd91d4791ecf0 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2757,6 +2757,9 @@ static void GenerateFrontendArgs(const FrontendOptions 
&Opts,
 case Language::HLSL:
   Lang = "hlsl";
   break;
+case Language::CIR:
+  Lang = "cir";
+  break;
 }
 
 GenerateArg(Consumer, OPT_x,
@@ -2958,6 +2961,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, 
ArgList &Args,
   .Cases("ast", "pcm", "precompiled-header",
  InputKind(Language::Unknown, InputKind::Precompiled))
   .Case("ir", Language::LLVM_IR)
+  .Case("cir", Language::CIR)
   .Default(Language::Unknown);
 
 if (DashX.isUnknown())
@@ -3323,6 +3327,7 @@ static b

[clang] [lld] [llvm] [ARM][AArch64] Change module flags values. (PR #84804)

2024-03-21 Thread Daniel Kiss via cfe-commits

DanielKristofKiss wrote:

superseded by #86212

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


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Chris B via cfe-commits


@@ -4258,6 +4258,18 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   } else {
 llvm_unreachable("expected DXIL or SPIR-V target");
   }
+  // validate that if fnative-half-type is given, that
+  // the language standard is at least hlsl2021, and that
+  // the target shader model is at least 6.2
+  if (Args.getLastArg(OPT_fnative_half_type)) {

llvm-beanz wrote:

We currently support fp16 in Vulkan 1.0, so this check should probably only 
apply to shader model targets:

https://godbolt.org/z/Wefc6179b

(@sudonatalie or @Keenuts can confirm)

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


[clang] [libcxx] [libc++] Implement LWG3528 (`make_from_tuple` can perform (the equivalent of) a C-style cast) (PR #85263)

2024-03-21 Thread via cfe-commits

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


[clang] [libcxx] [libc++] Implement LWG3528 (`make_from_tuple` can perform (the equivalent of) a C-style cast) (PR #85263)

2024-03-21 Thread via cfe-commits


@@ -1386,9 +1386,19 @@ inline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) 
apply(_Fn&& __f, _Tuple&&
 std::forward<_Tuple>(__t),
 typename 
__make_tuple_indices>>::type{}))
 
+#if _LIBCPP_STD_VER >= 20
 template 
 inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& 
__t, __tuple_indices<_Idx...>)
+  noexcept(noexcept(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...)))
+  requires is_constructible_v<_Tp, 
decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...> {
+  return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...);
+}
+#else
+template 
+inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& 
__t, __tuple_indices<_Idx...>, 
+enable_if_t(std::forward<_Tuple>(__t)))...>> * = nullptr)
 _LIBCPP_NOEXCEPT_RETURN(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...))
+#endif // _LIBCPP_STD_VER >= 20
 
 template 

yronglin wrote:

Sure, I keep the constraints on `__make_from_tuple` and the test for it.

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


[clang] [libcxx] [libc++] Implement LWG3528 (`make_from_tuple` can perform (the equivalent of) a C-style cast) (PR #85263)

2024-03-21 Thread via cfe-commits

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

>From fc8c1a24f09c8860269fbdcfb0b285ffd19f427c Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Fri, 15 Mar 2024 00:48:08 +0800
Subject: [PATCH 01/11] [libc++] Implement LWG3528 (`make_from_tuple` can
 perform (the equivalent of) a C-style cast)

Signed-off-by: yronglin 
---
 libcxx/docs/Status/Cxx23Issues.csv|  2 +-
 libcxx/include/tuple  | 12 ++-
 .../tuple.apply/make_from_tuple.verify.cpp| 74 +++
 3 files changed, 85 insertions(+), 3 deletions(-)
 create mode 100644 
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.verify.cpp

diff --git a/libcxx/docs/Status/Cxx23Issues.csv 
b/libcxx/docs/Status/Cxx23Issues.csv
index e00345533b865d..0fd58649b0cf64 100644
--- a/libcxx/docs/Status/Cxx23Issues.csv
+++ b/libcxx/docs/Status/Cxx23Issues.csv
@@ -77,7 +77,7 @@
 `3523 `__,"``iota_view::sentinel`` is not always 
``iota_view``'s sentinel","June 2021","","","|ranges|"
 `3526 `__,"Return types of 
``uses_allocator_construction_args`` unspecified","June 2021","",""
 `3527 `__,"``uses_allocator_construction_args`` 
handles rvalue pairs of rvalue references incorrectly","June 2021","",""
-`3528 `__,"``make_from_tuple`` can perform (the 
equivalent of) a C-style cast","June 2021","",""
+`3528 `__,"``make_from_tuple`` can perform (the 
equivalent of) a C-style cast","June 2021","|Complete|","19.0"
 `3529 `__,"``priority_queue(first, last)`` should 
construct ``c`` with ``(first, last)``","June 2021","|Complete|","14.0"
 `3530 `__,"``BUILTIN-PTR-MEOW`` should not opt the 
type out of syntactic checks","June 2021","",""
 `3532 `__,"``split_view::inner-iterator::operator++(int)`` should depend on ``Base``","June 
2021","","","|ranges|"
diff --git a/libcxx/include/tuple b/libcxx/include/tuple
index 8808db6739fb9b..1ef546c5b2153d 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -1423,8 +1423,16 @@ inline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) 
apply(_Fn&& __f, _Tuple&&
 typename 
__make_tuple_indices>>::type{}))
 
 template 
-inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& 
__t, __tuple_indices<_Idx...>)
-_LIBCPP_NOEXCEPT_RETURN(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...))
+inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& 
__t, __tuple_indices<_Idx...>) 
+  noexcept(noexcept(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...)))
+#if _LIBCPP_STD_VER >= 20
+  requires is_constructible_v<_Tp, 
decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...>
+#endif
+{
+  static_assert(is_constructible_v<_Tp, 
decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...>, 
+"Cannot constructible target type from the fields of the 
argument tuple.");
+  return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...);
+}
 
 template 
 inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp make_from_tuple(_Tuple&& __t)
diff --git 
a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.verify.cpp
 
b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.verify.cpp
new file mode 100644
index 00..9bdca4dc7813cb
--- /dev/null
+++ 
b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.verify.cpp
@@ -0,0 +1,74 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+// 
+
+// template  constexpr T make_from_tuple(Tuple&&);
+
+#include 
+
+int main() {
+  // clang-format off
+#if _LIBCPP_STD_VER <= 20
+  // reinterpret_cast
+  {
+struct B { int b; } b;
+std::tuple t{&b};
+auto a = std::make_from_tuple(t); // expected-error-re@*:* {{static 
assertion failed {{.*}}Cannot constructible target type from the fields of the 
argument tuple.}}
+(void)a;
+  }
+
+  // const_cast
+  {
+const char *str = "Hello";
+std::tuple t{str};
+auto a = std::make_from_tuple(t); // expected-error-re@*:* 
{{static assertion failed {{.*}}Cannot constructible target type from the 
fields of the argument tuple.}}
+(void)a;
+  }
+
+  // static_cast
+  {
+struct B {};
+struct C : public B {} c;
+B &br = c;
+std::tuple t{br};
+auto a = std::make_from_tuple(t); // expected-error-re@*:* 
{{static assertion failed {{.*}}Cannot constructible target type from the 
fields of the argument tuple.}}
+(void)a;
+  }
+#else
+  // reinterpret_cast
+  {
+   

[clang] [clang][modules] Avoid calling expensive `SourceManager::translateFile()` (PR #86216)

2024-03-21 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 6b1cf0040059c407264d2609403c4fc090673167 
4dd48b40a034edf0b124ab08055a334ad7abd5ba -- clang/include/clang/Lex/ModuleMap.h 
clang/lib/Frontend/FrontendAction.cpp clang/lib/Lex/ModuleMap.cpp 
clang/lib/Serialization/ASTWriter.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index bc4c901325..5921a8c065 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -540,8 +540,10 @@ static Module *prepareToBuildModule(CompilerInstance &CI,
   IsSystem ? SrcMgr::C_System_ModuleMap : SrcMgr::C_User_ModuleMap;
   FileID OriginalModuleMapFID = CI.getSourceManager().getOrCreateFileID(
   *OriginalModuleMap, FileCharacter);
-  CI.getPreprocessor().getHeaderSearchInfo().getModuleMap()
-.setInferredModuleAllowedBy(M, OriginalModuleMapFID);
+  CI.getPreprocessor()
+  .getHeaderSearchInfo()
+  .getModuleMap()
+  .setInferredModuleAllowedBy(M, OriginalModuleMapFID);
 }
   }
 

``




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


[clang] [Clang] Make '-frtlib-add-rpath' include the standard library directory (PR #86217)

2024-03-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Joseph Huber (jhuber6)


Changes

Summary:
The original intention of the `openmp-add-rpath` option was to add the
rpath to the language runtime directory. However, the current
implementation only adds it to the compiler's resource directory. This
patch adds support for appending the `-rpath` to the compiler's standard
library directory as well. Currently this is 
`/../lib/`.


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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+5-1) 
- (modified) clang/test/Driver/arch-specific-libdir-rpath.c (+13) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4478865313636d..6b1fbba7abd031 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1142,7 +1142,11 @@ void tools::addArchSpecificRPath(const ToolChain &TC, 
const ArgList &Args,
 options::OPT_fno_rtlib_add_rpath, false))
 return;
 
-  for (const auto &CandidateRPath : TC.getArchSpecificLibPaths()) {
+  SmallVector CandidateRPaths(TC.getArchSpecificLibPaths());
+  if (const auto CandidateRPath = TC.getStdlibPath())
+CandidateRPaths.emplace_back(*CandidateRPath);
+
+  for (const auto &CandidateRPath : CandidateRPaths) {
 if (TC.getVFS().exists(CandidateRPath)) {
   CmdArgs.push_back("-rpath");
   CmdArgs.push_back(Args.MakeArgString(CandidateRPath));
diff --git a/clang/test/Driver/arch-specific-libdir-rpath.c 
b/clang/test/Driver/arch-specific-libdir-rpath.c
index 1e6bbbc5929ac2..e95fb21c0a5fb1 100644
--- a/clang/test/Driver/arch-specific-libdir-rpath.c
+++ b/clang/test/Driver/arch-specific-libdir-rpath.c
@@ -84,6 +84,15 @@
 // RUN: -frtlib-add-rpath \
 // RUN:   | FileCheck --check-prefixes=PERTARGET %s
 
+// Test that the driver adds an per-target arch-specific subdirectory to the
+// stdlib path.
+//
+// RUN: %clang %s -### 2>&1 --target=x86_64-linux-gnu \
+// RUN: -fsanitize=address -shared-libasan \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -frtlib-add-rpath \
+// RUN:   | FileCheck --check-prefixes=STDLIB %s
+
 // RESDIR: "-resource-dir" "[[RESDIR:[^"]*]]"
 //
 // LIBPATH-X86_64: -L[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}
@@ -101,3 +110,7 @@
 // PERTARGET: "-resource-dir" "[[PTRESDIR:[^"]*]]"
 // PERTARGET: -L[[PTRESDIR]]{{(/|)lib(/|)x86_64-unknown-linux-gnu}}
 // PERTARGET:   "-rpath" 
"[[PTRESDIR]]{{(/|)lib(/|)x86_64-unknown-linux-gnu}}"
+
+// STDLIB: InstalledDir: [[LIBDIR:.+$]]
+// STDLIB: -L[[LIBDIR]]/..{{(/|)lib(/|)x86_64-unknown-linux-gnu}}
+// STDLIB:   "-rpath" 
"[[LIBDIR]]/..{{(/|)lib(/|)x86_64-unknown-linux-gnu}}"

``




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


[clang] [Clang] Make '-frtlib-add-rpath' include the standard library directory (PR #86217)

2024-03-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Joseph Huber (jhuber6)


Changes

Summary:
The original intention of the `openmp-add-rpath` option was to add the
rpath to the language runtime directory. However, the current
implementation only adds it to the compiler's resource directory. This
patch adds support for appending the `-rpath` to the compiler's standard
library directory as well. Currently this is 
`/../lib/`.


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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+5-1) 
- (modified) clang/test/Driver/arch-specific-libdir-rpath.c (+13) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4478865313636d..6b1fbba7abd031 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1142,7 +1142,11 @@ void tools::addArchSpecificRPath(const ToolChain &TC, 
const ArgList &Args,
 options::OPT_fno_rtlib_add_rpath, false))
 return;
 
-  for (const auto &CandidateRPath : TC.getArchSpecificLibPaths()) {
+  SmallVector CandidateRPaths(TC.getArchSpecificLibPaths());
+  if (const auto CandidateRPath = TC.getStdlibPath())
+CandidateRPaths.emplace_back(*CandidateRPath);
+
+  for (const auto &CandidateRPath : CandidateRPaths) {
 if (TC.getVFS().exists(CandidateRPath)) {
   CmdArgs.push_back("-rpath");
   CmdArgs.push_back(Args.MakeArgString(CandidateRPath));
diff --git a/clang/test/Driver/arch-specific-libdir-rpath.c 
b/clang/test/Driver/arch-specific-libdir-rpath.c
index 1e6bbbc5929ac2..e95fb21c0a5fb1 100644
--- a/clang/test/Driver/arch-specific-libdir-rpath.c
+++ b/clang/test/Driver/arch-specific-libdir-rpath.c
@@ -84,6 +84,15 @@
 // RUN: -frtlib-add-rpath \
 // RUN:   | FileCheck --check-prefixes=PERTARGET %s
 
+// Test that the driver adds an per-target arch-specific subdirectory to the
+// stdlib path.
+//
+// RUN: %clang %s -### 2>&1 --target=x86_64-linux-gnu \
+// RUN: -fsanitize=address -shared-libasan \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -frtlib-add-rpath \
+// RUN:   | FileCheck --check-prefixes=STDLIB %s
+
 // RESDIR: "-resource-dir" "[[RESDIR:[^"]*]]"
 //
 // LIBPATH-X86_64: -L[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}
@@ -101,3 +110,7 @@
 // PERTARGET: "-resource-dir" "[[PTRESDIR:[^"]*]]"
 // PERTARGET: -L[[PTRESDIR]]{{(/|)lib(/|)x86_64-unknown-linux-gnu}}
 // PERTARGET:   "-rpath" 
"[[PTRESDIR]]{{(/|)lib(/|)x86_64-unknown-linux-gnu}}"
+
+// STDLIB: InstalledDir: [[LIBDIR:.+$]]
+// STDLIB: -L[[LIBDIR]]/..{{(/|)lib(/|)x86_64-unknown-linux-gnu}}
+// STDLIB:   "-rpath" 
"[[LIBDIR]]/..{{(/|)lib(/|)x86_64-unknown-linux-gnu}}"

``




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


[clang] [Clang] Make '-frtlib-add-rpath' include the standard library directory (PR #86217)

2024-03-21 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/86217

Summary:
The original intention of the `openmp-add-rpath` option was to add the
rpath to the language runtime directory. However, the current
implementation only adds it to the compiler's resource directory. This
patch adds support for appending the `-rpath` to the compiler's standard
library directory as well. Currently this is `/../lib/`.


>From 6bd078cb080903127a8dfa27fb978350e94b8375 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 21 Mar 2024 18:25:35 -0500
Subject: [PATCH] [Clang] Make '-frtlib-add-rpath' include the standard library
 directory

Summary:
The original intention of the `openmp-add-rpath` option was to add the
rpath to the language runtime directory. However, the current
implementation only adds it to the compiler's resource directory. This
patch adds support for appending the `-rpath` to the compiler's standard
library directory as well. Currently this is `/../lib/`.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp |  6 +-
 clang/test/Driver/arch-specific-libdir-rpath.c | 13 +
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4478865313636d..6b1fbba7abd031 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1142,7 +1142,11 @@ void tools::addArchSpecificRPath(const ToolChain &TC, 
const ArgList &Args,
 options::OPT_fno_rtlib_add_rpath, false))
 return;
 
-  for (const auto &CandidateRPath : TC.getArchSpecificLibPaths()) {
+  SmallVector CandidateRPaths(TC.getArchSpecificLibPaths());
+  if (const auto CandidateRPath = TC.getStdlibPath())
+CandidateRPaths.emplace_back(*CandidateRPath);
+
+  for (const auto &CandidateRPath : CandidateRPaths) {
 if (TC.getVFS().exists(CandidateRPath)) {
   CmdArgs.push_back("-rpath");
   CmdArgs.push_back(Args.MakeArgString(CandidateRPath));
diff --git a/clang/test/Driver/arch-specific-libdir-rpath.c 
b/clang/test/Driver/arch-specific-libdir-rpath.c
index 1e6bbbc5929ac2..e95fb21c0a5fb1 100644
--- a/clang/test/Driver/arch-specific-libdir-rpath.c
+++ b/clang/test/Driver/arch-specific-libdir-rpath.c
@@ -84,6 +84,15 @@
 // RUN: -frtlib-add-rpath \
 // RUN:   | FileCheck --check-prefixes=PERTARGET %s
 
+// Test that the driver adds an per-target arch-specific subdirectory to the
+// stdlib path.
+//
+// RUN: %clang %s -### 2>&1 --target=x86_64-linux-gnu \
+// RUN: -fsanitize=address -shared-libasan \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -frtlib-add-rpath \
+// RUN:   | FileCheck --check-prefixes=STDLIB %s
+
 // RESDIR: "-resource-dir" "[[RESDIR:[^"]*]]"
 //
 // LIBPATH-X86_64: -L[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}
@@ -101,3 +110,7 @@
 // PERTARGET: "-resource-dir" "[[PTRESDIR:[^"]*]]"
 // PERTARGET: -L[[PTRESDIR]]{{(/|)lib(/|)x86_64-unknown-linux-gnu}}
 // PERTARGET:   "-rpath" 
"[[PTRESDIR]]{{(/|)lib(/|)x86_64-unknown-linux-gnu}}"
+
+// STDLIB: InstalledDir: [[LIBDIR:.+$]]
+// STDLIB: -L[[LIBDIR]]/..{{(/|)lib(/|)x86_64-unknown-linux-gnu}}
+// STDLIB:   "-rpath" 
"[[LIBDIR]]/..{{(/|)lib(/|)x86_64-unknown-linux-gnu}}"

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


[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-21 Thread Changpeng Fang via cfe-commits

changpeng wrote:

> > > Do you want to rename intrinsics as well? Because now intrinsic names do 
> > > not match builtin names.
> > 
> > 
> > Do we have to match builtins with intrinsics? Renaming intrinsics here 
> > means we will have to duplicate the intrinsics.
> 
> Is that because of the mangling?
Right.  It was originally suggested to use  a single instrinsic "load_lr".  But 
eventually we use global_load_tr to indicate this is in global address space.  
If we want to rename intrinsics here, it should be global_load_tr_b64 and 
global_load_tr_b128. 

We should rename intrinsic if users can use intrinsics directly. I think 
use-friendly is more important.

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


[clang] [clang][modules] Avoid calling expensive `SourceManager::translateFile()` (PR #86216)

2024-03-21 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 created 
https://github.com/llvm/llvm-project/pull/86216

The `ASTWriter` algorithm for computing affecting module maps uses 
`SourceManager::translateFile()` to get a `FileID` from a `FileEntry`. This is 
slow (O(n)) since the function performs a linear walk over `SLocEntries` until 
it finds one with a matching `FileEntry`.

This patch removes this use of `SourceManager::translateFile()` by tracking 
`FileID` instead of `FileEntry` in couple of places in `ModuleMap`, giving 
`ASTWriter` the desired `FileID` directly. There are no changes required for 
clients that still want a `FileEntry` from `ModuleMap`: the existing APIs 
internally use `SourceManager` to perform the reverse `FileID` to `FileEntry` 
conversion in O(1).

>From 4dd48b40a034edf0b124ab08055a334ad7abd5ba Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Thu, 21 Mar 2024 14:40:02 -0700
Subject: [PATCH] [clang][modules] Avoid calling expensive
 `SourceManager::translateFile()`

---
 clang/include/clang/Lex/ModuleMap.h   | 15 +++---
 clang/lib/Frontend/FrontendAction.cpp |  7 ++-
 clang/lib/Lex/ModuleMap.cpp   | 66 +++
 clang/lib/Serialization/ASTWriter.cpp | 23 +-
 4 files changed, 61 insertions(+), 50 deletions(-)

diff --git a/clang/include/clang/Lex/ModuleMap.h 
b/clang/include/clang/Lex/ModuleMap.h
index 867cb6eab42f2d..2e28ff6823cb2a 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -263,8 +263,8 @@ class ModuleMap {
 Attributes Attrs;
 
 /// If \c InferModules is non-zero, the module map file that allowed
-/// inferred modules.  Otherwise, nullopt.
-OptionalFileEntryRef ModuleMapFile;
+/// inferred modules.  Otherwise, invalid.
+FileID ModuleMapFID;
 
 /// The names of modules that cannot be inferred within this
 /// directory.
@@ -279,8 +279,7 @@ class ModuleMap {
 
   /// A mapping from an inferred module to the module map that allowed the
   /// inference.
-  // FIXME: Consider making the values non-optional.
-  llvm::DenseMap InferredModuleAllowedBy;
+  llvm::DenseMap InferredModuleAllowedBy;
 
   llvm::DenseMap AdditionalModMaps;
 
@@ -618,8 +617,9 @@ class ModuleMap {
   ///
   /// \param Module The module whose module map file will be returned, if 
known.
   ///
-  /// \returns The file entry for the module map file containing the given
-  /// module, or nullptr if the module definition was inferred.
+  /// \returns The FileID for the module map file containing the given module,
+  /// invalid if the module definition was inferred.
+  FileID getContainingModuleMapFileID(const Module *Module) const;
   OptionalFileEntryRef getContainingModuleMapFile(const Module *Module) const;
 
   /// Get the module map file that (along with the module name) uniquely
@@ -631,9 +631,10 @@ class ModuleMap {
   /// of inferred modules, returns the module map that allowed the inference
   /// (e.g. contained 'module *'). Otherwise, returns
   /// getContainingModuleMapFile().
+  FileID getModuleMapFileIDForUniquing(const Module *M) const;
   OptionalFileEntryRef getModuleMapFileForUniquing(const Module *M) const;
 
-  void setInferredModuleAllowedBy(Module *M, OptionalFileEntryRef ModMap);
+  void setInferredModuleAllowedBy(Module *M, FileID ModMapFID);
 
   /// Canonicalize \p Path in a manner suitable for a module map file. In
   /// particular, this canonicalizes the parent directory separately from the
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index b9fd9b8897b7e7..bc4c901325c7e1 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -535,8 +535,13 @@ static Module *prepareToBuildModule(CompilerInstance &CI,
 if (*OriginalModuleMap != CI.getSourceManager().getFileEntryRefForID(
   CI.getSourceManager().getMainFileID())) {
   M->IsInferred = true;
+  bool IsSystem = false; // TODO: Propagate the real thing here.
+  auto FileCharacter =
+  IsSystem ? SrcMgr::C_System_ModuleMap : SrcMgr::C_User_ModuleMap;
+  FileID OriginalModuleMapFID = CI.getSourceManager().getOrCreateFileID(
+  *OriginalModuleMap, FileCharacter);
   CI.getPreprocessor().getHeaderSearchInfo().getModuleMap()
-.setInferredModuleAllowedBy(M, *OriginalModuleMap);
+.setInferredModuleAllowedBy(M, OriginalModuleMapFID);
 }
   }
 
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 10c475f617d485..eed7eca2e73562 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -648,8 +648,7 @@ 
ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File) {
   UmbrellaModule = UmbrellaModule->Parent;
 
 if (UmbrellaModule->InferSubmodules) {
-  OptionalFileEntryRef UmbrellaModuleMap =
-  getModuleMapFileForUniquing(UmbrellaModule);
+  FileID UmbrellaModuleMap = getModuleMapFileIDForUniquing

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Damyan Pepper via cfe-commits


@@ -4258,6 +4258,18 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   } else {
 llvm_unreachable("expected DXIL or SPIR-V target");
   }
+  // validate that if fnative-half-type is given, that
+  // the language standard is at least hlsl2021, and that
+  // the target shader model is at least 6.2
+  if (Args.getLastArg(OPT_fnative_half_type)) {

damyanp wrote:

Probably the right thing to do here is figure out what the rules are for SPIR-V 
and get that implemented along with a test.  

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


[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-21 Thread Stanislav Mekhanoshin via cfe-commits

rampitec wrote:

> > Do you want to rename intrinsics as well? Because now intrinsic names do 
> > not match builtin names.
> 
> Do we have to match builtins with intrinsics? Renaming intrinsics here means 
> we will have to duplicate the intrinsics.

Is that because of the mangling?

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


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Damyan Pepper via cfe-commits


@@ -4258,6 +4258,18 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   } else {
 llvm_unreachable("expected DXIL or SPIR-V target");
   }
+  // validate that if fnative-half-type is given, that
+  // the language standard is at least hlsl2021, and that
+  // the target shader model is at least 6.2
+  if (Args.getLastArg(OPT_fnative_half_type)) {

damyanp wrote:

Impression I got from the code is that SPIR-V and DXIL use the value returned 
by `T.getOSVersion()` for different things.

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


[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-21 Thread Changpeng Fang via cfe-commits

changpeng wrote:

> Do you want to rename intrinsics as well? Because now intrinsic names do not 
> match builtin names.

Do we have to match builtins with intrinsics? Renaming intrinsics here means we 
will have to duplicate the intrinsics. 

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


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Joshua Batista via cfe-commits


@@ -4258,6 +4258,18 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   } else {
 llvm_unreachable("expected DXIL or SPIR-V target");
   }
+  // validate that if fnative-half-type is given, that
+  // the language standard is at least hlsl2021, and that
+  // the target shader model is at least 6.2
+  if (Args.getLastArg(OPT_fnative_half_type)) {
+bool LangStdArgIsValid = Opts.LangStd >= LangStandard::lang_hlsl2021;
+bool TPArgIsValid = T.getOSVersion() >= VersionTuple(6, 2);

bob80905 wrote:

TP originally stood for target profile. But yes, I think I'll just move the 
conditions directly into the `if`

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


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Joshua Batista via cfe-commits


@@ -4258,6 +4258,18 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   } else {
 llvm_unreachable("expected DXIL or SPIR-V target");
   }
+  // validate that if fnative-half-type is given, that
+  // the language standard is at least hlsl2021, and that
+  // the target shader model is at least 6.2
+  if (Args.getLastArg(OPT_fnative_half_type)) {

bob80905 wrote:

I thought to put it outside because I assumed SPIRV would have an option for 
enabling half types? I am not sure, but I'll move it for now.

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


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Joshua Batista via cfe-commits

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

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 1/7] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+

[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-03-21 Thread Daniel Kiss via cfe-commits

DanielKristofKiss wrote:

#86212 Deals with the import of the "true"/"false" values in the attributes.

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


[clang] [lld] [llvm] [ARM][AArch64] BTI,GCS,PAC Module flag update. (PR #86212)

2024-03-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-lld

Author: Daniel Kiss (DanielKristofKiss)


Changes

Module flag is used to indicate the feature to be propagated to the function. 
As now the frontend emits all attributes accordingly let's help the auto 
upgrade to only do work when old and new bitcodes are merged.

Depends on #82819 and #86031

---

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


20 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+13-6) 
- (modified) clang/test/CodeGen/aarch64-sign-return-address.c (+6-6) 
- (modified) clang/test/CodeGen/arm-branch-protection-attr-2.c (+4-4) 
- (modified) clang/test/Frontend/arm-ignore-branch-protection-option.c (+1-1) 
- (added) lld/test/ELF/lto/aarch64_inline.ll (+73) 
- (modified) llvm/include/llvm/IR/AutoUpgrade.h (+3) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+1) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+2) 
- (modified) llvm/lib/IR/AutoUpgrade.cpp (+100) 
- (modified) llvm/lib/Linker/IRMover.cpp (+10) 
- (modified) llvm/lib/Target/ARM/ARMAsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/LowerTypeTests.cpp (+1-1) 
- (modified) llvm/test/CodeGen/Thumb2/pacbti-m-outliner-5.ll (+1-1) 
- (removed) llvm/test/LTO/AArch64/Inputs/foo.ll (-16) 
- (added) llvm/test/LTO/AArch64/TestInputs/bar.ll (+35) 
- (added) llvm/test/LTO/AArch64/TestInputs/foo.ll (+38) 
- (added) llvm/test/LTO/AArch64/TestInputs/old.ll (+46) 
- (modified) llvm/test/LTO/AArch64/link-branch-target-enforcement.ll (+4-1) 
- (added) llvm/test/LTO/AArch64/link-sign-return-address.ll (+102) 
- (modified) llvm/test/Linker/link-arm-and-thumb.ll (+3-3) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cb153066b28dd1..1acc0510256268 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1173,22 +1173,29 @@ void CodeGenModule::Release() {
   "tag-stack-memory-buildattr", 1);
 
   if (T.isARM() || T.isThumb() || T.isAArch64()) {
+// Previously 1 is used and meant for the backed to derive the function
+// attribute form it. 2 now means function attributes already set for all
+// functions in this module, so no need to propagate those from the module
+// flag. Value is only used in case of LTO module merge because the backend
+// will see all required function attribute set already. Value is used
+// before modules got merged. Any posive value means the feature is active
+// and required binary markings need to be emit accordingly.
 if (LangOpts.BranchTargetEnforcement)
   getModule().addModuleFlag(llvm::Module::Min, "branch-target-enforcement",
-1);
+2);
 if (LangOpts.BranchProtectionPAuthLR)
   getModule().addModuleFlag(llvm::Module::Min, 
"branch-protection-pauth-lr",
-1);
+2);
 if (LangOpts.GuardedControlStack)
-  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 2);
 if (LangOpts.hasSignReturnAddress())
-  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 2);
 if (LangOpts.isSignReturnAddressScopeAll())
   getModule().addModuleFlag(llvm::Module::Min, "sign-return-address-all",
-1);
+2);
 if (!LangOpts.isSignReturnAddressWithAKey())
   getModule().addModuleFlag(llvm::Module::Min,
-"sign-return-address-with-bkey", 1);
+"sign-return-address-with-bkey", 2);
   }
 
   if (CodeGenOpts.StackClashProtector)
diff --git a/clang/test/CodeGen/aarch64-sign-return-address.c 
b/clang/test/CodeGen/aarch64-sign-return-address.c
index 8bc54b1a56c38c..35c56889e07071 100644
--- a/clang/test/CodeGen/aarch64-sign-return-address.c
+++ b/clang/test/CodeGen/aarch64-sign-return-address.c
@@ -22,17 +22,17 @@
 // NONE-NOT:  !"branch-target-enforcement"
 // ALL-NOT:   !"branch-target-enforcement"
 // PART-NOT:  !"branch-target-enforcement"
-// BTE:   !{i32 8, !"branch-target-enforcement", i32 1}
+// BTE:   !{i32 8, !"branch-target-enforcement", i32 2}
 // B-KEY-NOT: !"branch-target-enforcement"
 
 // NONE-NOT:  !"sign-return-address"
-// ALL:   !{i32 8, !"sign-return-address", i32 1}
-// PART:  !{i32 8, !"sign-return-address", i32 1}
+// ALL:   !{i32 8, !"sign-return-address", i32 2}
+// PART:  !{i32 8, !"sign-return-address", i32 2}
 // BTE-NOT:   !"sign-return-address"
-// B-KEY: !{i32 8, !"sign-return-address", i32 1}
+// B-KEY: !{i32 8, !"sign-return-address", i32 2}
 
 // NONE-NOT:  !"sign-return-address-all"
-// ALL:   !{i32 8, !"sign-return-address-al

[clang] [lld] [llvm] [ARM][AArch64] BTI,GCS,PAC Module flag update. (PR #86212)

2024-03-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Daniel Kiss (DanielKristofKiss)


Changes

Module flag is used to indicate the feature to be propagated to the function. 
As now the frontend emits all attributes accordingly let's help the auto 
upgrade to only do work when old and new bitcodes are merged.

Depends on #82819 and #86031

---

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


20 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+13-6) 
- (modified) clang/test/CodeGen/aarch64-sign-return-address.c (+6-6) 
- (modified) clang/test/CodeGen/arm-branch-protection-attr-2.c (+4-4) 
- (modified) clang/test/Frontend/arm-ignore-branch-protection-option.c (+1-1) 
- (added) lld/test/ELF/lto/aarch64_inline.ll (+73) 
- (modified) llvm/include/llvm/IR/AutoUpgrade.h (+3) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+1) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+2) 
- (modified) llvm/lib/IR/AutoUpgrade.cpp (+100) 
- (modified) llvm/lib/Linker/IRMover.cpp (+10) 
- (modified) llvm/lib/Target/ARM/ARMAsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/LowerTypeTests.cpp (+1-1) 
- (modified) llvm/test/CodeGen/Thumb2/pacbti-m-outliner-5.ll (+1-1) 
- (removed) llvm/test/LTO/AArch64/Inputs/foo.ll (-16) 
- (added) llvm/test/LTO/AArch64/TestInputs/bar.ll (+35) 
- (added) llvm/test/LTO/AArch64/TestInputs/foo.ll (+38) 
- (added) llvm/test/LTO/AArch64/TestInputs/old.ll (+46) 
- (modified) llvm/test/LTO/AArch64/link-branch-target-enforcement.ll (+4-1) 
- (added) llvm/test/LTO/AArch64/link-sign-return-address.ll (+102) 
- (modified) llvm/test/Linker/link-arm-and-thumb.ll (+3-3) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cb153066b28dd1..1acc0510256268 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1173,22 +1173,29 @@ void CodeGenModule::Release() {
   "tag-stack-memory-buildattr", 1);
 
   if (T.isARM() || T.isThumb() || T.isAArch64()) {
+// Previously 1 is used and meant for the backed to derive the function
+// attribute form it. 2 now means function attributes already set for all
+// functions in this module, so no need to propagate those from the module
+// flag. Value is only used in case of LTO module merge because the backend
+// will see all required function attribute set already. Value is used
+// before modules got merged. Any posive value means the feature is active
+// and required binary markings need to be emit accordingly.
 if (LangOpts.BranchTargetEnforcement)
   getModule().addModuleFlag(llvm::Module::Min, "branch-target-enforcement",
-1);
+2);
 if (LangOpts.BranchProtectionPAuthLR)
   getModule().addModuleFlag(llvm::Module::Min, 
"branch-protection-pauth-lr",
-1);
+2);
 if (LangOpts.GuardedControlStack)
-  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 2);
 if (LangOpts.hasSignReturnAddress())
-  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 2);
 if (LangOpts.isSignReturnAddressScopeAll())
   getModule().addModuleFlag(llvm::Module::Min, "sign-return-address-all",
-1);
+2);
 if (!LangOpts.isSignReturnAddressWithAKey())
   getModule().addModuleFlag(llvm::Module::Min,
-"sign-return-address-with-bkey", 1);
+"sign-return-address-with-bkey", 2);
   }
 
   if (CodeGenOpts.StackClashProtector)
diff --git a/clang/test/CodeGen/aarch64-sign-return-address.c 
b/clang/test/CodeGen/aarch64-sign-return-address.c
index 8bc54b1a56c38c..35c56889e07071 100644
--- a/clang/test/CodeGen/aarch64-sign-return-address.c
+++ b/clang/test/CodeGen/aarch64-sign-return-address.c
@@ -22,17 +22,17 @@
 // NONE-NOT:  !"branch-target-enforcement"
 // ALL-NOT:   !"branch-target-enforcement"
 // PART-NOT:  !"branch-target-enforcement"
-// BTE:   !{i32 8, !"branch-target-enforcement", i32 1}
+// BTE:   !{i32 8, !"branch-target-enforcement", i32 2}
 // B-KEY-NOT: !"branch-target-enforcement"
 
 // NONE-NOT:  !"sign-return-address"
-// ALL:   !{i32 8, !"sign-return-address", i32 1}
-// PART:  !{i32 8, !"sign-return-address", i32 1}
+// ALL:   !{i32 8, !"sign-return-address", i32 2}
+// PART:  !{i32 8, !"sign-return-address", i32 2}
 // BTE-NOT:   !"sign-return-address"
-// B-KEY: !{i32 8, !"sign-return-address", i32 1}
+// B-KEY: !{i32 8, !"sign-return-address", i32 2}
 
 // NONE-NOT:  !"sign-return-address-all"
-// ALL:   !{i32 8, !"sign-return-addres

[clang] [lld] [llvm] [ARM][AArch64] BTI,GCS,PAC Module flag update. (PR #86212)

2024-03-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Daniel Kiss (DanielKristofKiss)


Changes

Module flag is used to indicate the feature to be propagated to the function. 
As now the frontend emits all attributes accordingly let's help the auto 
upgrade to only do work when old and new bitcodes are merged.

Depends on #82819 and #86031

---

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


20 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+13-6) 
- (modified) clang/test/CodeGen/aarch64-sign-return-address.c (+6-6) 
- (modified) clang/test/CodeGen/arm-branch-protection-attr-2.c (+4-4) 
- (modified) clang/test/Frontend/arm-ignore-branch-protection-option.c (+1-1) 
- (added) lld/test/ELF/lto/aarch64_inline.ll (+73) 
- (modified) llvm/include/llvm/IR/AutoUpgrade.h (+3) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+1) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+2) 
- (modified) llvm/lib/IR/AutoUpgrade.cpp (+100) 
- (modified) llvm/lib/Linker/IRMover.cpp (+10) 
- (modified) llvm/lib/Target/ARM/ARMAsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/LowerTypeTests.cpp (+1-1) 
- (modified) llvm/test/CodeGen/Thumb2/pacbti-m-outliner-5.ll (+1-1) 
- (removed) llvm/test/LTO/AArch64/Inputs/foo.ll (-16) 
- (added) llvm/test/LTO/AArch64/TestInputs/bar.ll (+35) 
- (added) llvm/test/LTO/AArch64/TestInputs/foo.ll (+38) 
- (added) llvm/test/LTO/AArch64/TestInputs/old.ll (+46) 
- (modified) llvm/test/LTO/AArch64/link-branch-target-enforcement.ll (+4-1) 
- (added) llvm/test/LTO/AArch64/link-sign-return-address.ll (+102) 
- (modified) llvm/test/Linker/link-arm-and-thumb.ll (+3-3) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cb153066b28dd1..1acc0510256268 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1173,22 +1173,29 @@ void CodeGenModule::Release() {
   "tag-stack-memory-buildattr", 1);
 
   if (T.isARM() || T.isThumb() || T.isAArch64()) {
+// Previously 1 is used and meant for the backed to derive the function
+// attribute form it. 2 now means function attributes already set for all
+// functions in this module, so no need to propagate those from the module
+// flag. Value is only used in case of LTO module merge because the backend
+// will see all required function attribute set already. Value is used
+// before modules got merged. Any posive value means the feature is active
+// and required binary markings need to be emit accordingly.
 if (LangOpts.BranchTargetEnforcement)
   getModule().addModuleFlag(llvm::Module::Min, "branch-target-enforcement",
-1);
+2);
 if (LangOpts.BranchProtectionPAuthLR)
   getModule().addModuleFlag(llvm::Module::Min, 
"branch-protection-pauth-lr",
-1);
+2);
 if (LangOpts.GuardedControlStack)
-  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 2);
 if (LangOpts.hasSignReturnAddress())
-  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 2);
 if (LangOpts.isSignReturnAddressScopeAll())
   getModule().addModuleFlag(llvm::Module::Min, "sign-return-address-all",
-1);
+2);
 if (!LangOpts.isSignReturnAddressWithAKey())
   getModule().addModuleFlag(llvm::Module::Min,
-"sign-return-address-with-bkey", 1);
+"sign-return-address-with-bkey", 2);
   }
 
   if (CodeGenOpts.StackClashProtector)
diff --git a/clang/test/CodeGen/aarch64-sign-return-address.c 
b/clang/test/CodeGen/aarch64-sign-return-address.c
index 8bc54b1a56c38c..35c56889e07071 100644
--- a/clang/test/CodeGen/aarch64-sign-return-address.c
+++ b/clang/test/CodeGen/aarch64-sign-return-address.c
@@ -22,17 +22,17 @@
 // NONE-NOT:  !"branch-target-enforcement"
 // ALL-NOT:   !"branch-target-enforcement"
 // PART-NOT:  !"branch-target-enforcement"
-// BTE:   !{i32 8, !"branch-target-enforcement", i32 1}
+// BTE:   !{i32 8, !"branch-target-enforcement", i32 2}
 // B-KEY-NOT: !"branch-target-enforcement"
 
 // NONE-NOT:  !"sign-return-address"
-// ALL:   !{i32 8, !"sign-return-address", i32 1}
-// PART:  !{i32 8, !"sign-return-address", i32 1}
+// ALL:   !{i32 8, !"sign-return-address", i32 2}
+// PART:  !{i32 8, !"sign-return-address", i32 2}
 // BTE-NOT:   !"sign-return-address"
-// B-KEY: !{i32 8, !"sign-return-address", i32 1}
+// B-KEY: !{i32 8, !"sign-return-address", i32 2}
 
 // NONE-NOT:  !"sign-return-address-all"
-// ALL:   !{i32 8, !"sign-return-

[clang] [Clang][Sema] Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-21 Thread Harald van Dijk via cfe-commits


@@ -21,10 +27,76 @@ struct __attribute((packed, aligned(4))) { char a; int x; 
char z[]; } e = { 1, 2
 struct { int x; char y[]; } f = { 1, { 13, 15 } };
 // CHECK: @f ={{.*}} global <{ i32, [2 x i8] }> <{ i32 1, [2 x i8] c"\0D\0F" }>
 
-union {
-  struct {
-int a;
-char b[];
-  } x;
-} in_union = {};
-// CHECK: @in_union ={{.*}} global %union.anon zeroinitializer
+struct __attribute((packed)) { short a; char z[]; } g = { 2, { 11, 13, 15 } };
+// CHECK: @g ={{.*}} <{ i16, [3 x i8] }> <{ i16 2, [3 x i8] c"\0B\0D\0F" }>,
+
+// Last member is the potential flexible array, unnamed initializer skips it.
+struct { int a; union { int b; short x; }; int c; int d; } h = {1, 2, {}, 3};
+// CHECK: @h = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 }, 
i32 0, i32 3 }
+struct { int a; union { int b; short x[0]; }; int c; int d; } h0 = {1, 2, {}, 
3};
+// CHECK: @h0 = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 
}, i32 0, i32 3 }
+struct { int a; union { int b; short x[1]; }; int c; int d; } h1 = {1, 2, {}, 
3};
+// CHECK: @h1 = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 
}, i32 0, i32 3 }
+struct {
+  int a;
+  union {
+int b;
+struct {
+  struct { } __ununsed;
+  short x[];
+};
+  };
+  int c;
+  int d;
+} hiding = {1, 2, {}, 3};
+// CHECK: @hiding = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 
2 }, i32 0, i32 3 }
+struct { int a; union { int b; short x[]; }; int c; int d; } hf = {1, 2, {}, 
3};
+// CHECK: @hf = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 
}, i32 0, i32 3 }
+
+// First member is the potential flexible array, initialization requires 
braces.
+struct { int a; union { short x; int b; }; int c; int d; } i = {1, 2, {}, 3};
+// CHECK: @i = global { i32, { i16, [2 x i8] }, i32, i32 } { i32 1, { i16, [2 
x i8] } { i16 2, [2 x i8] undef }, i32 0, i32 3 }
+struct { int a; union { short x[0]; int b; }; int c; int d; } i0 = {1, {}, 2, 
3};
+// CHECK: @i0 = global { i32, { [0 x i16], [4 x i8] }, i32, i32 } { i32 1, { 
[0 x i16], [4 x i8] } { [0 x i16] zeroinitializer, [4 x i8] undef }, i32 2, i32 
3 }
+struct { int a; union { short x[1]; int b; }; int c; int d; } i1 = {1, {2}, 
{}, 3};
+// CHECK: @i1 = global { i32, { [1 x i16], [2 x i8] }, i32, i32 } { i32 1, { 
[1 x i16], [2 x i8] } { [1 x i16] [i16 2], [2 x i8] undef }, i32 0, i32 3 }
+struct { int a; union { short x[]; int b; }; int c; int d; } i_f = {4, {}, {}, 
6};
+// CHECK: @i_f = global { i32, { [0 x i16], [4 x i8] }, i32, i32 } { i32 4, { 
[0 x i16], [4 x i8] } { [0 x i16] zeroinitializer, [4 x i8] undef }, i32 0, i32 
6 }
+
+// Named initializers; order doesn't matter.
+struct { int a; union { int b; short x; }; int c; int d; } hn = {.a = 1, .x = 
2, .c = 3};
+// CHECK: @hn = global { i32, { i16, [2 x i8] }, i32, i32 } { i32 1, { i16, [2 
x i8] } { i16 2, [2 x i8] undef }, i32 3, i32 0 }
+struct { int a; union { int b; short x[0]; }; int c; int d; } hn0 = {.a = 1, 
.x = {2}, .c = 3};
+// CHECK: @hn0 = global { i32, { [0 x i16], [4 x i8] }, i32, i32 } { i32 1, { 
[0 x i16], [4 x i8] } { [0 x i16] zeroinitializer, [4 x i8] undef }, i32 3, i32 
0 }
+struct { int a; union { int b; short x[1]; }; int c; int d; } hn1 = {.a = 1, 
.x = {2}, .c = 3};
+// CHECK: @hn1 = global { i32, { [1 x i16], [2 x i8] }, i32, i32 } { i32 1, { 
[1 x i16], [2 x i8] } { [1 x i16] [i16 2], [2 x i8] undef }, i32 3, i32 0 }
+
+struct { char a[]; } empty_struct = {};
+// CHECK: @empty_struct ={{.*}} global %struct.anon{{.*}} zeroinitializer, 
align 1
+
+struct { char a[]; } empty_struct0 = {0};
+// CHECK: @empty_struct0 = global { [1 x i8] } zeroinitializer, align 1
+
+union { struct { int a; char b[]; }; } struct_in_union = {};
+// CHECK: @struct_in_union = global %union.anon{{.*}} zeroinitializer, align 4
+
+union { struct { int a; char b[]; }; } struct_in_union0 = {0};
+// CHECK: @struct_in_union0 = global %union.anon{{.*}} zeroinitializer, align 4
+
+union { int a; char b[]; } trailing_in_union = {};
+// CHECK: @trailing_in_union = global %union.anon{{.*}} zeroinitializer, align 
4
+
+union { int a; char b[]; } trailing_in_union0 = {0};
+// CHECK: @trailing_in_union0 = global %union.anon{{.*}} zeroinitializer, 
align 4
+
+union { char a[]; } only_in_union = {};
+// CHECK: @only_in_union = global %union.anon{{.*}} zeroinitializer, align 1
+
+union { char a[]; } only_in_union0 = {0};
+// CHECK: @only_in_union0 = global { [1 x i8] } zeroinitializer, align 1
+
+union { char a[]; int b; } first_in_union = {};
+// CHECK: @first_in_union = global { [0 x i8], [4 x i8] } { [0 x i8] 
zeroinitializer, [4 x i8] undef }, align 4
+
+union { char a[]; int b; } first_in_union0 = {};
+// CHECK: @first_in_union0 = global { [0 x i8], [4 x i8] } { [0 x i8] 
zeroinitializer, [4 x i8] undef }, align 4

hvdijk wrote:

This is identical to the `first_in_union` test, I think you want
```suggestion
union { char a[]; int b; } first_in_union0 = {0};
// CHECK: @first

[clang] [lld] [llvm] [ARM][AArch64] Change module flags values. (PR #84804)

2024-03-21 Thread Daniel Kiss via cfe-commits

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


[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-21 Thread Stanislav Mekhanoshin via cfe-commits


@@ -432,13 +432,15 @@ TARGET_BUILTIN(__builtin_amdgcn_s_wakeup_barrier, "vi", 
"n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_barrier_leave, "b", "n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_get_barrier_state, "Uii", "n", "gfx12-insts")
 
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v2i32, "V2iV2i*1", "nc", 
"gfx12-insts,wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v8i16, "V8sV8s*1", "nc", 
"gfx12-insts,wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v8f16, "V8hV8h*1", "nc", 
"gfx12-insts,wavefrontsize32")
-
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_i32, "ii*1", "nc", 
"gfx12-insts,wavefrontsize64")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v4i16, "V4sV4s*1", "nc", 
"gfx12-insts,wavefrontsize64")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v4f16, "V4hV4h*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_v2i32, "V2iV2i*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8i16, "V8sV8s*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8f16, "V8hV8h*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8bf16, "V8yV8y*1", "nc", 
"gfx12-insts,wavefrontsize32")
+
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_i32, "ii*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4i16, "V4sV4s*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4f16, "V4hV4h*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4bf16, "V4yV4y*1", "nc", 
"gfx12-insts,wavefrontsize64")

rampitec wrote:

There should not be legacy yet.

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


[clang] [lld] [llvm] [ARM][AArch64] BTI,GCS,PAC Module flag update. (PR #86212)

2024-03-21 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss created 
https://github.com/llvm/llvm-project/pull/86212

Module flag is used to indicate the feature to be propagated to the function. 
As now the frontend emits all attributes accordingly let's help the auto 
upgrade to only do work when old and new bitcodes are merged.

Depends on #82819 and #86031

>From 33d8277d188f82847d914273be2379151dd33d41 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Fri, 8 Mar 2024 15:06:28 +0100
Subject: [PATCH] BTI,GCS,PAC Module flag update.

Module flag is used to indicate the feature to be propagated to the
function. As now the frontend emits all attributes accoringly let's
help the automerger to only do work when old and new bitcodes are
merged.
Autoupgrade function attributes from Module attributes when needed.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  19 ++--
 .../CodeGen/aarch64-sign-return-address.c |  12 +--
 .../CodeGen/arm-branch-protection-attr-2.c|   8 +-
 .../arm-ignore-branch-protection-option.c |   2 +-
 lld/test/ELF/lto/aarch64_inline.ll|  73 +
 llvm/include/llvm/IR/AutoUpgrade.h|   3 +
 llvm/lib/AsmParser/LLParser.cpp   |   1 +
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |   2 +
 llvm/lib/IR/AutoUpgrade.cpp   | 100 +
 llvm/lib/Linker/IRMover.cpp   |  10 ++
 llvm/lib/Target/ARM/ARMAsmPrinter.cpp |   2 +-
 llvm/lib/Transforms/IPO/LowerTypeTests.cpp|   2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-5.ll |   2 +-
 llvm/test/LTO/AArch64/Inputs/foo.ll   |  16 ---
 llvm/test/LTO/AArch64/TestInputs/bar.ll   |  35 ++
 llvm/test/LTO/AArch64/TestInputs/foo.ll   |  38 +++
 llvm/test/LTO/AArch64/TestInputs/old.ll   |  46 
 .../AArch64/link-branch-target-enforcement.ll |   5 +-
 .../LTO/AArch64/link-sign-return-address.ll   | 102 ++
 llvm/test/Linker/link-arm-and-thumb.ll|   6 +-
 20 files changed, 444 insertions(+), 40 deletions(-)
 create mode 100644 lld/test/ELF/lto/aarch64_inline.ll
 delete mode 100644 llvm/test/LTO/AArch64/Inputs/foo.ll
 create mode 100644 llvm/test/LTO/AArch64/TestInputs/bar.ll
 create mode 100644 llvm/test/LTO/AArch64/TestInputs/foo.ll
 create mode 100644 llvm/test/LTO/AArch64/TestInputs/old.ll
 create mode 100644 llvm/test/LTO/AArch64/link-sign-return-address.ll

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cb153066b28dd1..1acc0510256268 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1173,22 +1173,29 @@ void CodeGenModule::Release() {
   "tag-stack-memory-buildattr", 1);
 
   if (T.isARM() || T.isThumb() || T.isAArch64()) {
+// Previously 1 is used and meant for the backed to derive the function
+// attribute form it. 2 now means function attributes already set for all
+// functions in this module, so no need to propagate those from the module
+// flag. Value is only used in case of LTO module merge because the backend
+// will see all required function attribute set already. Value is used
+// before modules got merged. Any posive value means the feature is active
+// and required binary markings need to be emit accordingly.
 if (LangOpts.BranchTargetEnforcement)
   getModule().addModuleFlag(llvm::Module::Min, "branch-target-enforcement",
-1);
+2);
 if (LangOpts.BranchProtectionPAuthLR)
   getModule().addModuleFlag(llvm::Module::Min, 
"branch-protection-pauth-lr",
-1);
+2);
 if (LangOpts.GuardedControlStack)
-  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 2);
 if (LangOpts.hasSignReturnAddress())
-  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 1);
+  getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 2);
 if (LangOpts.isSignReturnAddressScopeAll())
   getModule().addModuleFlag(llvm::Module::Min, "sign-return-address-all",
-1);
+2);
 if (!LangOpts.isSignReturnAddressWithAKey())
   getModule().addModuleFlag(llvm::Module::Min,
-"sign-return-address-with-bkey", 1);
+"sign-return-address-with-bkey", 2);
   }
 
   if (CodeGenOpts.StackClashProtector)
diff --git a/clang/test/CodeGen/aarch64-sign-return-address.c 
b/clang/test/CodeGen/aarch64-sign-return-address.c
index 8bc54b1a56c38c..35c56889e07071 100644
--- a/clang/test/CodeGen/aarch64-sign-return-address.c
+++ b/clang/test/CodeGen/aarch64-sign-return-address.c
@@ -22,17 +22,17 @@
 // NONE-NOT:  !"branch-target-enforcement"
 // ALL-NOT:   !"branch-target-enforcement"
 // PAR

[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-21 Thread Shilei Tian via cfe-commits


@@ -432,13 +432,15 @@ TARGET_BUILTIN(__builtin_amdgcn_s_wakeup_barrier, "vi", 
"n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_barrier_leave, "b", "n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_get_barrier_state, "Uii", "n", "gfx12-insts")
 
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v2i32, "V2iV2i*1", "nc", 
"gfx12-insts,wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v8i16, "V8sV8s*1", "nc", 
"gfx12-insts,wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v8f16, "V8hV8h*1", "nc", 
"gfx12-insts,wavefrontsize32")
-
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_i32, "ii*1", "nc", 
"gfx12-insts,wavefrontsize64")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v4i16, "V4sV4s*1", "nc", 
"gfx12-insts,wavefrontsize64")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v4f16, "V4hV4h*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_v2i32, "V2iV2i*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8i16, "V8sV8s*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8f16, "V8hV8h*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8bf16, "V8yV8y*1", "nc", 
"gfx12-insts,wavefrontsize32")
+
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_i32, "ii*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4i16, "V4sV4s*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4f16, "V4hV4h*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4bf16, "V4yV4y*1", "nc", 
"gfx12-insts,wavefrontsize64")

shiltian wrote:

Do we still want to keep the old builtins to maintain compatibility, though I 
doubt there is any legacy code using them?

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


[libunwind] [libunwind] Tweak tests for musl support. (PR #85097)

2024-03-21 Thread Alexander Richardson via cfe-commits


@@ -11,20 +11,27 @@
 
 // Basic test for float registers number are accepted.
 
-#include 
 #include 
 #include 
 #include 
 
+// Using __attribute__((section("main_func"))) is Linux specific, but then

arichardson wrote:

Nit: This is not specific to Linux it is specific to the behaviour of ELF 
linkers that automatically create these symbols for sections that are valid C 
identifiers.

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


[clang] [NFC][Clang] Fix static analyzer bugs with dereference after null checks (PR #86018)

2024-03-21 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic requested changes to this pull request.

If you read the code, it should be obvious the pointer is in fact non-null.  
Please don't insert null checks into the code just to address static analyzer 
false positives.

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


[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-03-21 Thread Daniel Kiss via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/82819

>From 28e7b4e10208991790f0c7b1e225831714a47572 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Mon, 22 Jan 2024 11:33:15 +0100
Subject: [PATCH] Emit attributes for functions always.

Branch protection, sign return address, guarded control stack flags are
only emitted as module flags if not specified per function.

The inliner might inline functions with different set of flags as it
doesn't see the flags.

In case of LTO build the module flags get merged with the `min` rule which means
if one of the modules is not build with PAC/BTI then the features will be turned
off on all functions due to the functions takes the branch-protection and
sign-return-address features from the module flags. The sign-return-address is
function level option therefore it is expected functions from files that are
compiled with -mbranch-protection=pac-ret to be protected but in LTO case this
might not happen. This patch adds the flags to functions in case of an LTO build
therefore they don't need to rely on the module flag.
---
 clang/include/clang/Basic/TargetInfo.h| 44 +--
 clang/lib/CodeGen/Targets/AArch64.cpp | 43 ++
 clang/lib/CodeGen/Targets/ARM.cpp |  8 ++--
 .../CodeGen/aarch64-branch-protection-attr.c  | 26 +--
 .../CodeGen/aarch64-sign-return-address.c | 12 +++--
 clang/test/CodeGen/aarch64-targetattr.c   |  2 +-
 .../CodeGen/arm-branch-protection-attr-1.c| 12 ++---
 .../CodeGen/arm-branch-protection-attr-2.c| 13 --
 .../test/Frontend/arm-branch-protection-lto.c | 22 ++
 .../SelectionDAG/SelectionDAGBuilder.cpp  | 12 +
 llvm/lib/IR/Verifier.cpp  | 20 -
 llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp |  6 +--
 .../AArch64/AArch64MachineFunctionInfo.cpp| 37 ++--
 .../lib/Target/ARM/ARMMachineFunctionInfo.cpp | 22 +-
 llvm/lib/Transforms/IPO/LowerTypeTests.cpp|  6 ++-
 ...ranch-target-enforcement-indirect-calls.ll | 18 
 .../CodeGen/AArch64/bti-branch-relaxation.ll  |  2 +-
 llvm/test/CodeGen/AArch64/kcfi-bti.ll |  7 +--
 ...machine-outliner-2fixup-blr-terminator.mir |  2 +-
 .../CodeGen/AArch64/machine-outliner-bti.mir  |  2 +-
 .../AArch64/machine-outliner-outline-bti.ll   |  4 +-
 .../AArch64/note-gnu-property-pac-bti-0.ll|  2 +-
 .../AArch64/note-gnu-property-pac-bti-4.ll|  4 +-
 .../AArch64/pacbti-llvm-generated-funcs-1.ll  |  4 +-
 .../AArch64/pacbti-llvm-generated-funcs-2.ll  |  4 +-
 .../CodeGen/AArch64/pacbti-module-attrs.ll| 12 ++---
 .../AArch64/patchable-function-entry-bti.ll   | 10 ++---
 .../CodeGen/AArch64/setjmp-bti-outliner.ll| 15 +++
 llvm/test/CodeGen/AArch64/setjmp-bti.ll   |  6 +--
 .../AArch64/sign-return-address-pauth-lr.ll   | 36 +++
 .../CodeGen/AArch64/sign-return-address.ll|  8 ++--
 llvm/test/CodeGen/AArch64/wineh-bti.ll|  7 +--
 llvm/test/CodeGen/AArch64/wineh-pac.ll|  7 +--
 llvm/test/CodeGen/ARM/setjmp-bti-basic.ll |  5 +--
 llvm/test/CodeGen/ARM/setjmp-bti-outliner.ll  |  7 +--
 llvm/test/CodeGen/Thumb2/bti-entry-blocks.ll  |  7 +--
 .../CodeGen/Thumb2/bti-indirect-branches.ll   |  9 ++--
 llvm/test/CodeGen/Thumb2/bti-outliner-1.ll|  9 ++--
 llvm/test/CodeGen/Thumb2/bti-outliner-2.ll| 12 ++---
 .../CodeGen/Thumb2/bti-outliner-cost-2.ll |  6 +--
 .../test/CodeGen/Thumb2/bti-pac-replace-1.mir |  8 +---
 llvm/test/CodeGen/Thumb2/bti-pac-replace-2.ll |  7 +--
 llvm/test/CodeGen/Thumb2/jump-table-bti.ll| 10 ++---
 llvm/test/CodeGen/Thumb2/pacbti-m-basic.ll|  6 +--
 .../Thumb2/pacbti-m-indirect-tail-call.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-1.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-3.ll |  2 +-
 .../CodeGen/Thumb2/pacbti-m-outliner-4.ll |  6 +--
 .../CodeGen/Thumb2/pacbti-m-outliner-5.ll |  4 +-
 .../test/CodeGen/Thumb2/pacbti-m-overalign.ll |  2 +-
 .../test/CodeGen/Thumb2/pacbti-m-stack-arg.ll |  4 +-
 .../Thumb2/pacbti-m-unsupported-arch.ll   |  8 +---
 .../test/CodeGen/Thumb2/pacbti-m-varargs-1.ll |  4 +-
 .../test/CodeGen/Thumb2/pacbti-m-varargs-2.ll |  4 +-
 llvm/test/CodeGen/Thumb2/pacbti-m-vla.ll  |  2 +-
 .../AArch64/link-branch-target-enforcement.ll |  2 +-
 .../Inline/inline-sign-return-address.ll  | 13 +++---
 .../LowerTypeTests/function-arm-thumb.ll  |  2 +-
 .../LowerTypeTests/function-thumb-bti.ll  |  4 +-
 .../Transforms/LowerTypeTests/function.ll |  4 +-
 llvm/test/Verifier/branch-prot-attrs.ll   |  7 ++-
 61 files changed, 281 insertions(+), 312 deletions(-)
 create mode 100644 clang/test/Frontend/arm-branch-protection-lto.c

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 374595edd2ce4a..5f6f5bbba8e56a 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -32,7 +32,9 @@

[clang] [llvm] [InstallAPI] Report exports discovered in binary but not in interface (PR #86025)

2024-03-21 Thread Cyndy Ishida via cfe-commits

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


[clang] e470ca8 - [InstallAPI] Report exports discovered in binary but not in interface (#86025)

2024-03-21 Thread via cfe-commits

Author: Cyndy Ishida
Date: 2024-03-21T15:03:34-07:00
New Revision: e470ca89ba77b2f200ff3a8ad65c74028f42c5f7

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

LOG: [InstallAPI] Report exports discovered in binary but not in interface 
(#86025)

This patch completes the classes of errors installapi can detect.

Added: 
clang/test/InstallAPI/linker-symbols.test
clang/test/InstallAPI/mismatching-objc-class-symbols.test
clang/test/InstallAPI/symbol-flags.test

Modified: 
clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
clang/include/clang/InstallAPI/DylibVerifier.h
clang/lib/InstallAPI/DylibVerifier.cpp
clang/test/InstallAPI/diagnostics-cpp.test
clang/tools/clang-installapi/ClangInstallAPI.cpp
llvm/lib/TextAPI/BinaryReader/DylibReader.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index f99a5fca64cb46..a4c6e630ac5fd8 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -26,6 +26,7 @@ def warn_library_hidden_symbol : Warning<"declaration has 
external linkage, but
 def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">, InGroup;
 def err_header_hidden_symbol : Error<"symbol exported in dynamic library, but 
marked hidden in declaration '%0'">;
 def err_header_symbol_missing : Error<"no declaration found for exported 
symbol '%0' in dynamic library">;
+def warn_header_symbol_missing : Warning<"no declaration was found for 
exported symbol '%0' in dynamic library">, InGroup;
 def warn_header_availability_mismatch : Warning<"declaration '%0' is marked 
%select{available|unavailable}1,"
   " but symbol is %select{not |}2exported in dynamic library">, 
InGroup;
 def err_header_availability_mismatch : Error<"declaration '%0' is marked 
%select{available|unavailable}1,"

diff  --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index bbfa8711313e47..49de24763f1f93 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -28,7 +28,7 @@ enum class VerificationMode {
 /// lifetime of InstallAPI.
 /// As declarations are collected during AST traversal, they are
 /// compared as symbols against what is available in the binary dylib.
-class DylibVerifier {
+class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
 
@@ -72,6 +72,9 @@ class DylibVerifier {
   Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
 const StringRef SuperClass);
 
+  // Scan through dylib slices and report any remaining missing exports.
+  Result verifyRemainingSymbols();
+
   /// Initialize target for verification.
   void setTarget(const Target &T);
 
@@ -128,6 +131,14 @@ class DylibVerifier {
   /// Find matching dylib slice for target triple that is being parsed.
   void assignSlice(const Target &T);
 
+  /// Shared implementation for verifying exported symbols in dylib.
+  void visitSymbolInDylib(const Record &R, SymbolContext &SymCtx);
+
+  void visitGlobal(const GlobalRecord &R) override;
+  void visitObjCInterface(const ObjCInterfaceRecord &R) override;
+  void visitObjCCategory(const ObjCCategoryRecord &R) override;
+  void visitObjCIVar(const ObjCIVarRecord &R, const StringRef Super);
+
   /// Gather annotations for symbol for error reporting.
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
bool ValidSourceLoc = true);

diff  --git a/clang/lib/InstallAPI/DylibVerifier.cpp 
b/clang/lib/InstallAPI/DylibVerifier.cpp
index 24e0d0addf2f46..94b8e9cd3233a9 100644
--- a/clang/lib/InstallAPI/DylibVerifier.cpp
+++ b/clang/lib/InstallAPI/DylibVerifier.cpp
@@ -66,17 +66,15 @@ std::string DylibVerifier::getAnnotatedName(const Record *R,
 Annotation += "(tlv) ";
 
   // Check if symbol represents only part of a @interface declaration.
-  const bool IsAnnotatedObjCClass =
-  ((SymCtx.ObjCIFKind != ObjCIFSymbolKind::None) &&
-   (SymCtx.ObjCIFKind <= ObjCIFSymbolKind::EHType));
-
-  if (IsAnnotatedObjCClass) {
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::EHType)
-  Annotation += "Exception Type of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::MetaClass)
-  Annotation += "Metaclass of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::Class)
-  Annotation += "Class of ";
+  switch (SymCtx.ObjCIFKind) {
+  default:
+break;
+  case ObjCIFSymbolKind::EHType:
+return Annotation + "Exception Type of " + PrettyName;
+  case ObjCIFSymbolKind::MetaClass:
+return Annotation + "Metaclass of " + PrettyName;
+  

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Damyan Pepper via cfe-commits


@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;

damyanp wrote:

```suggestion
  "enable_16bit_types option only valid when target shader model [-T] is >= 6.2 
and HLSL Version [-HV] is >= 2021">;
```

Looks like "HLSL" is spelled "HLSL" elsewhere.

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


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Damyan Pepper via cfe-commits


@@ -4258,6 +4258,18 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   } else {
 llvm_unreachable("expected DXIL or SPIR-V target");
   }
+  // validate that if fnative-half-type is given, that
+  // the language standard is at least hlsl2021, and that
+  // the target shader model is at least 6.2
+  if (Args.getLastArg(OPT_fnative_half_type)) {
+bool LangStdArgIsValid = Opts.LangStd >= LangStandard::lang_hlsl2021;
+bool TPArgIsValid = T.getOSVersion() >= VersionTuple(6, 2);

damyanp wrote:

What does the `TP` prefix mean in this context?

nits on the naming here: neither of these bools really indicate if these 
arguments are "valid".  The first one is "IsAtLeastHLSL2021" and the second is 
"IsAtLeastShaderModel62".  It may even be clearer just to inline these into the 
if condition.

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


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Damyan Pepper via cfe-commits

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


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Damyan Pepper via cfe-commits


@@ -4258,6 +4258,18 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   } else {
 llvm_unreachable("expected DXIL or SPIR-V target");
   }
+  // validate that if fnative-half-type is given, that
+  // the language standard is at least hlsl2021, and that
+  // the target shader model is at least 6.2
+  if (Args.getLastArg(OPT_fnative_half_type)) {

damyanp wrote:

Shouldn't this check be inside a `T.isDXIL()` block?

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


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Damyan Pepper via cfe-commits

https://github.com/damyanp requested changes to this pull request.

I'm worried about what this'll do when `T.isSPIRVLogical()`.

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


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Damyan Pepper via cfe-commits


@@ -4258,6 +4258,18 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   } else {
 llvm_unreachable("expected DXIL or SPIR-V target");
   }
+  // validate that if fnative-half-type is given, that
+  // the language standard is at least hlsl2021, and that
+  // the target shader model is at least 6.2
+  if (Args.getLastArg(OPT_fnative_half_type)) {

damyanp wrote:

This comment just repeats what the code does - and is also pretty redundant 
with the comment on line 4268.

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


[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-21 Thread Stanislav Mekhanoshin via cfe-commits

https://github.com/rampitec commented:

Do you want to rename intrinsics as well? Because now intrinsic names do not 
match builtin names.

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


[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-21 Thread Changpeng Fang via cfe-commits

https://github.com/changpeng created 
https://github.com/llvm/llvm-project/pull/86202

  Make the name of a clang builtin as close to the mnemonic instruction name as 
possible. The data type suffix may not be enough to tell what instruction the 
builtin is going to produce.
  This patch also add the bf16 support for global_load_tr_b128 builtins.

>From a65bd5bd52db208d9aa9c22cbb834787aff978d4 Mon Sep 17 00:00:00 2001
From: Changpeng Fang 
Date: Thu, 21 Mar 2024 14:24:43 -0700
Subject: [PATCH] AMDGPU: Rename and add bf16 support for global_load_tr
 builtins

  Make the name of a clang builtin as close to the mnemonic
instruction name as possible. The data type suffix may not be
enough to tell what instruction the builtin is going to produce.

  This patch also add the bf16 support for global_load_tr_b128
builtins.
---
 clang/include/clang/Basic/BuiltinsAMDGPU.def  | 16 
 clang/lib/CodeGen/CGBuiltin.cpp   | 34 +++--
 ...uiltins-amdgcn-global-load-tr-gfx11-err.cl | 25 ++--
 ...ins-amdgcn-global-load-tr-gfx12-w32-err.cl | 11 +++---
 ...ins-amdgcn-global-load-tr-gfx12-w64-err.cl | 11 +++---
 .../builtins-amdgcn-global-load-tr-w32.cl | 38 +--
 .../builtins-amdgcn-global-load-tr-w64.cl | 38 +--
 7 files changed, 94 insertions(+), 79 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 61ec8b79bf054d..4153b316c22b1d 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -432,13 +432,15 @@ TARGET_BUILTIN(__builtin_amdgcn_s_wakeup_barrier, "vi", 
"n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_barrier_leave, "b", "n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_get_barrier_state, "Uii", "n", "gfx12-insts")
 
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v2i32, "V2iV2i*1", "nc", 
"gfx12-insts,wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v8i16, "V8sV8s*1", "nc", 
"gfx12-insts,wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v8f16, "V8hV8h*1", "nc", 
"gfx12-insts,wavefrontsize32")
-
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_i32, "ii*1", "nc", 
"gfx12-insts,wavefrontsize64")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v4i16, "V4sV4s*1", "nc", 
"gfx12-insts,wavefrontsize64")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v4f16, "V4hV4h*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_v2i32, "V2iV2i*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8i16, "V8sV8s*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8f16, "V8hV8h*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8bf16, "V8yV8y*1", "nc", 
"gfx12-insts,wavefrontsize32")
+
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_i32, "ii*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4i16, "V4sV4s*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4f16, "V4hV4h*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4bf16, "V4yV4y*1", "nc", 
"gfx12-insts,wavefrontsize64")
 
 
//===--===//
 // WMMA builtins.
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e14e8908828218..2eaceeba617700 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18531,35 +18531,45 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
 llvm::Function *F = CGM.getIntrinsic(IID, {ArgTy});
 return Builder.CreateCall(F, {Addr, Val, ZeroI32, ZeroI32, ZeroI1});
   }
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_i32:
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_v2i32:
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_v4f16:
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_v4i16:
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_v8f16:
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_v8i16: {
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_v2i32:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4bf16:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4f16:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4i16:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8f16:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16: {
 
 llvm::Type *ArgTy;
 switch (BuiltinID) {
-case AMDGPU::BI__builtin_amdgcn_global_load_tr_i32:
+case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
   ArgTy = llvm::Type::getInt32Ty(getLLVMContext());
   break;
-case AMDGPU::BI__builtin_amdgc

[clang] [clang][SPIRV] Don't warn on -mcmodel (PR #86039)

2024-03-21 Thread Arthur Eubanks via cfe-commits

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


[clang] b19bf3e - [clang][SPIRV] Don't warn on -mcmodel (#86039)

2024-03-21 Thread via cfe-commits

Author: Arthur Eubanks
Date: 2024-03-21T14:48:35-07:00
New Revision: b19bf3e888f95c35bf641cd0eee18a8da702f6fe

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

LOG: [clang][SPIRV] Don't warn on -mcmodel (#86039)

The code model doesn't affect the sub-compilation, so don't check it.

Followup to #70740.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/unsupported-option-gpu.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index bc9cc8ce6cf5a5..86a287db72a4eb 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5863,8 +5863,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 } else if (Triple.getArch() == llvm::Triple::x86_64) {
   Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"},
   CM);
-} else if (Triple.isNVPTX() || Triple.isAMDGPU()) {
-  // NVPTX/AMDGPU does not care about the code model and will accept
+} else if (Triple.isNVPTX() || Triple.isAMDGPU() || Triple.isSPIRV()) {
+  // NVPTX/AMDGPU/SPIRV does not care about the code model and will accept
   // whatever works for the host.
   Ok = true;
 } else if (Triple.isSPARC64()) {

diff  --git a/clang/test/Driver/unsupported-option-gpu.c 
b/clang/test/Driver/unsupported-option-gpu.c
index f23cb71ebfb08e..5618b2cba72e16 100644
--- a/clang/test/Driver/unsupported-option-gpu.c
+++ b/clang/test/Driver/unsupported-option-gpu.c
@@ -2,4 +2,5 @@
 // DEFINE: %{check} = %clang -### --target=x86_64-linux-gnu -c -mcmodel=medium
 
 // RUN: %{check} -x cuda %s --cuda-path=%S/Inputs/CUDA/usr/local/cuda 
--offload-arch=sm_60 --no-cuda-version-check -fbasic-block-sections=all
+// RUN: %{check} -x hip %s --offload=spirv64 -nogpulib -nogpuinc
 // RUN: %{check} -x hip %s --rocm-path=%S/Inputs/rocm -nogpulib -nogpuinc



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


[clang] [clang][SPIRV] Don't warn on -mcmodel (PR #86039)

2024-03-21 Thread Arthur Eubanks via cfe-commits


@@ -5804,7 +5804,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 } else if (Triple.getArch() == llvm::Triple::x86_64) {
   Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"},
   CM);
-} else if (Triple.isNVPTX() || Triple.isAMDGPU()) {
+} else if (Triple.isNVPTX() || Triple.isAMDGPU() || Triple.isSPIRV()) {
   // NVPTX/AMDGPU does not care about the code model and will accept

aeubanks wrote:

done

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


[clang] [clang][SPIRV] Don't warn on -mcmodel (PR #86039)

2024-03-21 Thread Arthur Eubanks via cfe-commits

https://github.com/aeubanks updated 
https://github.com/llvm/llvm-project/pull/86039

>From bba8e4003c4ccc36497e62ad1696197e6987525c Mon Sep 17 00:00:00 2001
From: Arthur Eubanks 
Date: Wed, 20 Mar 2024 23:36:35 +
Subject: [PATCH 1/2] [clang][SPIRV] Ignore -mcmodel

The code model doesn't affect the sub-compilation, so don't check it.

Followup to #70740.
---
 clang/lib/Driver/ToolChains/Clang.cpp  | 2 +-
 clang/test/Driver/unsupported-option-gpu.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 055884d275ce1b..035bfa35299756 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5804,7 +5804,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 } else if (Triple.getArch() == llvm::Triple::x86_64) {
   Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"},
   CM);
-} else if (Triple.isNVPTX() || Triple.isAMDGPU()) {
+} else if (Triple.isNVPTX() || Triple.isAMDGPU() || Triple.isSPIRV()) {
   // NVPTX/AMDGPU does not care about the code model and will accept
   // whatever works for the host.
   Ok = true;
diff --git a/clang/test/Driver/unsupported-option-gpu.c 
b/clang/test/Driver/unsupported-option-gpu.c
index f23cb71ebfb08e..5618b2cba72e16 100644
--- a/clang/test/Driver/unsupported-option-gpu.c
+++ b/clang/test/Driver/unsupported-option-gpu.c
@@ -2,4 +2,5 @@
 // DEFINE: %{check} = %clang -### --target=x86_64-linux-gnu -c -mcmodel=medium
 
 // RUN: %{check} -x cuda %s --cuda-path=%S/Inputs/CUDA/usr/local/cuda 
--offload-arch=sm_60 --no-cuda-version-check -fbasic-block-sections=all
+// RUN: %{check} -x hip %s --offload=spirv64 -nogpulib -nogpuinc
 // RUN: %{check} -x hip %s --rocm-path=%S/Inputs/rocm -nogpulib -nogpuinc

>From 650c120c5ad8360124b4d45a90974f4d60622455 Mon Sep 17 00:00:00 2001
From: Arthur Eubanks 
Date: Thu, 21 Mar 2024 21:44:55 +
Subject: [PATCH 2/2] update comment

---
 clang/lib/Driver/ToolChains/Clang.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 035bfa35299756..57ab8b6e91826c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5805,7 +5805,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"},
   CM);
 } else if (Triple.isNVPTX() || Triple.isAMDGPU() || Triple.isSPIRV()) {
-  // NVPTX/AMDGPU does not care about the code model and will accept
+  // NVPTX/AMDGPU/SPIRV does not care about the code model and will accept
   // whatever works for the host.
   Ok = true;
 } else if (Triple.isSPARC64()) {

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


[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Changpeng Fang (changpeng)


Changes

  Make the name of a clang builtin as close to the mnemonic instruction name as 
possible. The data type suffix may not be enough to tell what instruction the 
builtin is going to produce.
  This patch also add the bf16 support for global_load_tr_b128 builtins.

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


7 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsAMDGPU.def (+9-7) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+22-12) 
- (modified) 
clang/test/CodeGenOpenCL/builtins-amdgcn-global-load-tr-gfx11-err.cl (+13-12) 
- (modified) 
clang/test/CodeGenOpenCL/builtins-amdgcn-global-load-tr-gfx12-w32-err.cl (+6-5) 
- (modified) 
clang/test/CodeGenOpenCL/builtins-amdgcn-global-load-tr-gfx12-w64-err.cl (+6-5) 
- (modified) clang/test/CodeGenOpenCL/builtins-amdgcn-global-load-tr-w32.cl 
(+19-19) 
- (modified) clang/test/CodeGenOpenCL/builtins-amdgcn-global-load-tr-w64.cl 
(+19-19) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 61ec8b79bf054d..4153b316c22b1d 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -432,13 +432,15 @@ TARGET_BUILTIN(__builtin_amdgcn_s_wakeup_barrier, "vi", 
"n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_barrier_leave, "b", "n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_get_barrier_state, "Uii", "n", "gfx12-insts")
 
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v2i32, "V2iV2i*1", "nc", 
"gfx12-insts,wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v8i16, "V8sV8s*1", "nc", 
"gfx12-insts,wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v8f16, "V8hV8h*1", "nc", 
"gfx12-insts,wavefrontsize32")
-
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_i32, "ii*1", "nc", 
"gfx12-insts,wavefrontsize64")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v4i16, "V4sV4s*1", "nc", 
"gfx12-insts,wavefrontsize64")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v4f16, "V4hV4h*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_v2i32, "V2iV2i*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8i16, "V8sV8s*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8f16, "V8hV8h*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8bf16, "V8yV8y*1", "nc", 
"gfx12-insts,wavefrontsize32")
+
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_i32, "ii*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4i16, "V4sV4s*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4f16, "V4hV4h*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4bf16, "V4yV4y*1", "nc", 
"gfx12-insts,wavefrontsize64")
 
 
//===--===//
 // WMMA builtins.
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e14e8908828218..2eaceeba617700 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18531,35 +18531,45 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
 llvm::Function *F = CGM.getIntrinsic(IID, {ArgTy});
 return Builder.CreateCall(F, {Addr, Val, ZeroI32, ZeroI32, ZeroI1});
   }
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_i32:
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_v2i32:
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_v4f16:
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_v4i16:
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_v8f16:
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_v8i16: {
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_v2i32:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4bf16:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4f16:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4i16:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8f16:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16: {
 
 llvm::Type *ArgTy;
 switch (BuiltinID) {
-case AMDGPU::BI__builtin_amdgcn_global_load_tr_i32:
+case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
   ArgTy = llvm::Type::getInt32Ty(getLLVMContext());
   break;
-case AMDGPU::BI__builtin_amdgcn_global_load_tr_v2i32:
+case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_v2i32:
   ArgTy = llvm::FixedVectorType::get(
   llvm::Type::getInt32Ty(getLLVMContext()), 2);
   break;
-case AMDGPU::BI__builtin_amdgcn_global_load_tr_v4f16:
+case AMDGPU::BI__builtin_amd

[clang] [clang][Sema] Fix for enums overflowing (#24667) (PR #78742)

2024-03-21 Thread via cfe-commits

https://github.com/wheatman updated 
https://github.com/llvm/llvm-project/pull/78742

>From df2911ee8f23c9030dce45f835371616cf4355b7 Mon Sep 17 00:00:00 2001
From: Brian Wheatman 
Date: Fri, 19 Jan 2024 11:13:33 -0500
Subject: [PATCH] [clang][Sema] Fix for overflow in enumerators(#24667)

Enums which do not have a specified type can only grow to bigger types
which contain more bits than the prior types.  This means that the
largest signed integer type cannot grow to the largest unsigned integer types.

In the process also implements N3029 Improved Normal Enumerations and
patially implements N3030 Enhancements to Enumerations which brings C enums
more inline with C++ enums.

Fixes #24667
---
 clang/docs/ReleaseNotes.rst |   8 +++
 clang/lib/Sema/SemaDecl.cpp | 115 +--
 clang/test/C/C2x/n3029.c|  81 ++
 clang/test/C/C2x/n3030.c| 130 
 clang/test/Sema/enum.c  |  43 ++--
 clang/test/SemaCXX/enum.cpp |   2 +
 6 files changed, 354 insertions(+), 25 deletions(-)
 create mode 100644 clang/test/C/C2x/n3029.c
 create mode 100644 clang/test/C/C2x/n3030.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 50990140a53ad1..0e30d53584ff2f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -162,6 +162,12 @@ C23 Feature Support
   ``__TYPE_FMTb__`` (e.g., ``__UINT_FAST64_FMTB__``) in C23 mode for use with
   macros typically exposed from , such as ``PRIb8``.
   (`#81896: `_).
+- Enumerations should allow values greater than ``INT_MAX`` and smaller than
+  ``INT_MIN``, in order to provide a value-preserved set of integer constants. 
`N3029 Improved Normal Enumerations 
`_
+
+- Enumerations should have the ability to specify the underlying type to aid
+  in portability and usability across platforms, across ABIs, and across
+  languages (for serialization and similar purposes). `N3030 Enhancements to 
Enumerations `_
 
 - Clang now supports `N3018 The constexpr specifier for object definitions`
   `_.
@@ -320,6 +326,8 @@ Bug Fixes in This Version
 
 - Fixes an assertion failure on invalid code when trying to define member
   functions in lambdas.
+- Fixes a miscompilation when an enum has a specified value such that the 
automatic
+  increment overflows a ``signed long``. Fixes #GH24667.
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index aa754d47a0c43a..e92786fa9709fd 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19875,6 +19875,18 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
   // - If an initializer is specified for an enumerator, the
   //   initializing value has the same type as the expression.
   EltTy = Val->getType();
+} else if (getLangOpts().C23) {
+  // C23 6.7.2.2p11 b4
+  // int, if given explicitly with = and the value of the
+  // integer constant expression is representable by an int
+  //
+  // C23 6.7.2.2p11 b5
+  // the type of the integer constant expression, if given
+  // explicitly with = and if the value of the integer
+  // constant expression is not representable by int;
+  if (isRepresentableIntegerValue(Context, EnumVal, Context.IntTy))
+Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
+  EltTy = Val->getType();
 } else {
   // C99 6.7.2.2p2:
   //   The expression that defines the value of an enumeration constant
@@ -19884,8 +19896,8 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
   // Complain if the value is not representable in an int.
   if (!isRepresentableIntegerValue(Context, EnumVal, Context.IntTy))
 Diag(IdLoc, diag::ext_enum_value_not_int)
-  << toString(EnumVal, 10) << Val->getSourceRange()
-  << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
+<< toString(EnumVal, 10) << Val->getSourceRange()
+<< (EnumVal.isUnsigned() || EnumVal.isNonNegative());
   else if (!Context.hasSameType(Val->getType(), Context.IntTy)) {
 // Force the type of the expression to 'int'.
 Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
@@ -19933,20 +19945,28 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
 //   sufficient to contain the incremented value. If no such type
 //   exists, the program is ill-formed.
 QualType T = getNextLargerIntegralType(Context, EltTy);
-if (T.isNull() || Enum->isFixed()) {
+

[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-03-21 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From d73a87b47a549aeac7f4ea519037107a8f798df6 Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Fri, 26 Jan 2024 18:44:41 -0500
Subject: [PATCH] [libunwind][libcxx][libcxxabi] Fix Exception Handling build
 for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change

Merge remote-tracking branch 'parent/main' into wasmlibunwindfix

remove unwanted changes in unwind-wasm.c

Make Unwind-wasm.c compile correctly without workaround in
CMakeLists.txt

using __wasm__ macro to guard against all wasm eh build

fix UnwindLevel.c's formatting issue

ISO C requires a translation unit to contain at least one declaration 
[-Werror,-Wempty-translation-unit]

compiler-rt does not define CMP_RESULT correct on wasm64
Fixed
---
 compiler-rt/lib/builtins/fp_compare_impl.inc |   2 +-
 libcxx/include/__exception/exception_ptr.h   |  18 +-
 libcxxabi/include/cxxabi.h   | 175 ++---
 libcxxabi/src/cxa_exception.cpp  | 707 ---
 libcxxabi/src/cxa_exception.h|   7 +-
 libunwind/include/__libunwind_config.h   |   1 +
 libunwind/include/libunwind.h|   2 +
 libunwind/src/Unwind-wasm.c  |  13 +-
 libunwind/src/UnwindLevel1.c |   3 +-
 libunwind/src/UnwindRegistersRestore.S   |   3 +-
 libunwind/src/UnwindRegistersSave.S  |   3 +
 libunwind/src/assembly.h |   2 +
 libunwind/src/cet_unwind.h   |   3 +
 libunwind/src/config.h   |  15 +-
 libunwind/src/libunwind.cpp  |   2 +
 libunwind/src/libunwind_ext.h|   2 +
 16 files changed, 426 insertions(+), 532 deletions(-)

diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc 
b/compiler-rt/lib/builtins/fp_compare_impl.inc
index a9a4f6fbf5dfe4..83bdea46a45da4 100644
--- a/compiler-rt/lib/builtins/fp_compare_impl.inc
+++ b/compiler-rt/lib/builtins/fp_compare_impl.inc
@@ -12,7 +12,7 @@
 // functions. We need to ensure that the return value is sign-extended in the
 // same way as GCC expects (since otherwise GCC-generated __builtin_isinf
 // returns true for finite 128-bit floating-point numbers).
-#ifdef __aarch64__
+#if defined(__aarch64__) || defined(__wasm__)
 // AArch64 GCC overrides libgcc_cmp_return to use int instead of long.
 typedef int CMP_RESULT;
 #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4
diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index c9027de9238cdd..3324f832b71602 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -30,19 +30,21 @@
 
 namespace __cxxabiv1 {
 
+#if defined(__wasm__)
+typedef void* (*__libcpp_exception_destructor_func)(void*);
+#elif defined(_WIN32)
+typedef void(__thiscall* __libcpp_exception_destructor_func)(void*);
+#else
+typedef void (*__libcpp_exception_destructor_func)(void*);
+#endif
+
 extern "C" {
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw();
 _LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw();
 
 struct __cxa_exception;
-_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
-void*,
-std::type_info*,
-void(
-#if defined(_WIN32)
-__thiscall
-#endif
-*)(void*)) throw();
+_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception*
+__cxa_init_primary_exception(void*, std::type_info*, 
__libcpp_exception_destructor_func) throw();
 }
 
 } // namespace __cxxabiv1
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index d0701181751c50..4162fd7ec2ba77 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -20,58 +20,51 @@
 #include <__cxxabi_config.h>
 
 #define _LIBCPPABI_VERSION 15000
-#define _LIBCXXABI_NORETURN  __attribute__((noreturn))
+#define _LIBCXXABI_NORETURN __attribute__((noreturn))
 #define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))
 
 #ifdef __cplusplus
 
 namespace std {
-#if defined(_WIN32)
+#  if defined(_WIN32)
 class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
-#else
+#  else
 class type_info; // forward declaration
-#endif
-}
-
+#  endif
+} // namespace std
 
 // runtime routines use C calling conventions, but are in __cxxabiv1 namespace
 namespace __cxxabiv1 {
 
 struct __cxa_exception;
+#  if defined(__wasm__)
+typedef void* (*__libcxxabi_exception_destructor_func)(void*);
+#  else
+typedef voi

[clang] [clang][AST][NFC] Add '[[fallthrough]]' to cases fall through (PR #85921)

2024-03-21 Thread Fangrui Song via cfe-commits

MaskRay wrote:

We should remove the comment. To make the PR more useful, the PR can be changed 
to remove other confusing comments like this.

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


[clang] Unwrap CountAttributed for debug info (PR #86017)

2024-03-21 Thread Yeoul Na via cfe-commits

https://github.com/rapidsna updated 
https://github.com/llvm/llvm-project/pull/86017

>From abfcb60e7b65e755733f4d41795aa9cfd44e0cc3 Mon Sep 17 00:00:00 2001
From: Yeoul Na 
Date: Thu, 21 Mar 2024 06:47:05 +0900
Subject: [PATCH 1/3] Unwrap CountAttributed for debug info

Fix crash caused by 3eb9ff30959a670559bcba03d149d4c51bf7c9c9
---
 clang/lib/CodeGen/CGDebugInfo.cpp  |  3 +++
 .../test/CodeGen/attr-counted-by-debug-info.c  | 18 ++
 2 files changed, 21 insertions(+)
 create mode 100644 clang/test/CodeGen/attr-counted-by-debug-info.c

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 07ecaa81c47d84..7453ed14aef414 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3463,6 +3463,9 @@ static QualType UnwrapTypeForDebugInfo(QualType T, const 
ASTContext &C) {
 case Type::BTFTagAttributed:
   T = cast(T)->getWrappedType();
   break;
+case Type::CountAttributed:
+  T = cast(T)->desugar();
+  break;
 case Type::Elaborated:
   T = cast(T)->getNamedType();
   break;
diff --git a/clang/test/CodeGen/attr-counted-by-debug-info.c 
b/clang/test/CodeGen/attr-counted-by-debug-info.c
new file mode 100644
index 00..f3e7897e12d667
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-debug-info.c
@@ -0,0 +1,18 @@
+// RUN: %clang -emit-llvm -DCOUNTED_BY -S -g %s -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -g %s -o - | FileCheck %s
+
+#ifdef COUNTED_BY
+#define __counted_by(member)__attribute__((__counted_by__(member)))
+#else
+#define __counted_by(member)
+#endif
+
+struct {
+  int num_counters;
+  long value[] __counted_by(num_counters);
+} agent_send_response_port_num;
+
+// CHECK: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[BT:.*]], 
elements: ![[ELEMENTS:.*]])
+// ![[BT]] = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
+// ![[ELEMENTS]] = !{![[COUNT]]}
+// ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file

>From 5bb879be895b90dc942d160fbe9dfe657e73db1d Mon Sep 17 00:00:00 2001
From: Yeoul Na 
Date: Thu, 21 Mar 2024 06:59:11 +0900
Subject: [PATCH 2/3] Add missing CHECKs

---
 clang/test/CodeGen/attr-counted-by-debug-info.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/CodeGen/attr-counted-by-debug-info.c 
b/clang/test/CodeGen/attr-counted-by-debug-info.c
index f3e7897e12d667..15197f79e4370c 100644
--- a/clang/test/CodeGen/attr-counted-by-debug-info.c
+++ b/clang/test/CodeGen/attr-counted-by-debug-info.c
@@ -13,6 +13,6 @@ struct {
 } agent_send_response_port_num;
 
 // CHECK: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[BT:.*]], 
elements: ![[ELEMENTS:.*]])
-// ![[BT]] = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
-// ![[ELEMENTS]] = !{![[COUNT]]}
-// ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file
+// CHECK: ![[BT]] = !DIBasicType(name: "long", size: 64, encoding: 
DW_ATE_signed)
+// CHECK: ![[ELEMENTS]] = !{![[COUNT:.*]]}
+// CHECK: ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file

>From c1da42c5c5154fdc1fe8324dccd5368568d5304e Mon Sep 17 00:00:00 2001
From: Yeoul Na 
Date: Fri, 22 Mar 2024 05:45:31 +0900
Subject: [PATCH 3/3] Fix test.attr-counted-by-debug-info.c to also cover
 32-bit long

---
 clang/test/CodeGen/attr-counted-by-debug-info.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGen/attr-counted-by-debug-info.c 
b/clang/test/CodeGen/attr-counted-by-debug-info.c
index 15197f79e4370c..a6c2b1382b796b 100644
--- a/clang/test/CodeGen/attr-counted-by-debug-info.c
+++ b/clang/test/CodeGen/attr-counted-by-debug-info.c
@@ -13,6 +13,6 @@ struct {
 } agent_send_response_port_num;
 
 // CHECK: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[BT:.*]], 
elements: ![[ELEMENTS:.*]])
-// CHECK: ![[BT]] = !DIBasicType(name: "long", size: 64, encoding: 
DW_ATE_signed)
+// CHECK: ![[BT]] = !DIBasicType(name: "long", size: {{.*}}, encoding: 
DW_ATE_signed)
 // CHECK: ![[ELEMENTS]] = !{![[COUNT:.*]]}
 // CHECK: ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file

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


[clang] [clang][SPIRV] Don't warn on -mcmodel (PR #86039)

2024-03-21 Thread Fangrui Song via cfe-commits


@@ -5804,7 +5804,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 } else if (Triple.getArch() == llvm::Triple::x86_64) {
   Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"},
   CM);
-} else if (Triple.isNVPTX() || Triple.isAMDGPU()) {
+} else if (Triple.isNVPTX() || Triple.isAMDGPU() || Triple.isSPIRV()) {
   // NVPTX/AMDGPU does not care about the code model and will accept

MaskRay wrote:

Should the comment be updated?

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


[clang] [X86_32] Teach X86_32 va_arg to ignore empty structs. (PR #86075)

2024-03-21 Thread Eli Friedman via cfe-commits


@@ -1069,6 +1069,10 @@ Address X86_32ABIInfo::EmitVAArg(CodeGenFunction &CGF,
 
   auto TypeInfo = getContext().getTypeInfoInChars(Ty);
 
+  // Empty records are ignored for parameter passing purposes on non-Windows.
+  if (!IsWin32StructABI && isEmptyRecord(getContext(), Ty, true))
+return CGF.CreateMemTemp(Ty);

efriedma-quic wrote:

I'd prefer to use classifyArgumentType, like we do for the 64-bit case, instead 
of trying to duplicate the logic.

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


[clang] [X86_64] fix arg pass error in struct. (PR #85394)

2024-03-21 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

gcc uses memory, and the ABI standard doesn't explicitly contradict it, so 
let's just go with that.

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


  1   2   3   4   >