[clang] 4b0df28 - [clang][Tooling] Prefer for atomic_* family in C++

2025-01-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2025-01-23T10:06:33+01:00
New Revision: 4b0df28a68a4ed4ec5829fb4d8722a0e701d1796

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

LOG: [clang][Tooling] Prefer  for atomic_* family in C++

Added: 


Modified: 
clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc

Removed: 




diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
index 9179217dd6ca8b..0a332c99dd49fc 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -284,100 +284,148 @@ SYMBOL(abs, None, )
 SYMBOL(atomic, std::, )
 // atomic_* family symbols.  is for C compatibility.
 SYMBOL(atomic_bool, std::, )
+SYMBOL(atomic_bool, None, )
 SYMBOL(atomic_bool, None, )
 SYMBOL(atomic_char, std::, )
+SYMBOL(atomic_char, None, )
 SYMBOL(atomic_char, None, )
 SYMBOL(atomic_char16_t, std::, )
+SYMBOL(atomic_char16_t, None, )
 SYMBOL(atomic_char16_t, None, )
 SYMBOL(atomic_char32_t, std::, )
+SYMBOL(atomic_char32_t, None, )
 SYMBOL(atomic_char32_t, None, )
 SYMBOL(atomic_char8_t, std::, )
+SYMBOL(atomic_char8_t, None, )
 SYMBOL(atomic_char8_t, None, )
 SYMBOL(atomic_int, std::, )
+SYMBOL(atomic_int, None, )
 SYMBOL(atomic_int, None, )
 SYMBOL(atomic_int16_t, std::, )
+SYMBOL(atomic_int16_t, None, )
 SYMBOL(atomic_int16_t, None, )
 SYMBOL(atomic_int32_t, std::, )
+SYMBOL(atomic_int32_t, None, )
 SYMBOL(atomic_int32_t, None, )
 SYMBOL(atomic_int64_t, std::, )
+SYMBOL(atomic_int64_t, None, )
 SYMBOL(atomic_int64_t, None, )
 SYMBOL(atomic_int8_t, std::, )
+SYMBOL(atomic_int8_t, None, )
 SYMBOL(atomic_int8_t, None, )
 SYMBOL(atomic_int_fast16_t, std::, )
+SYMBOL(atomic_int_fast16_t, None, )
 SYMBOL(atomic_int_fast16_t, None, )
 SYMBOL(atomic_int_fast32_t, std::, )
+SYMBOL(atomic_int_fast32_t, None, )
 SYMBOL(atomic_int_fast32_t, None, )
 SYMBOL(atomic_int_fast64_t, std::, )
+SYMBOL(atomic_int_fast64_t, None, )
 SYMBOL(atomic_int_fast64_t, None, )
 SYMBOL(atomic_int_fast8_t, std::, )
+SYMBOL(atomic_int_fast8_t, None, )
 SYMBOL(atomic_int_fast8_t, None, )
 SYMBOL(atomic_int_least16_t, std::, )
+SYMBOL(atomic_int_least16_t, None, )
 SYMBOL(atomic_int_least16_t, None, )
 SYMBOL(atomic_int_least32_t, std::, )
+SYMBOL(atomic_int_least32_t, None, )
 SYMBOL(atomic_int_least32_t, None, )
 SYMBOL(atomic_int_least64_t, std::, )
+SYMBOL(atomic_int_least64_t, None, )
 SYMBOL(atomic_int_least64_t, None, )
 SYMBOL(atomic_int_least8_t, std::, )
+SYMBOL(atomic_int_least8_t, None, )
 SYMBOL(atomic_int_least8_t, None, )
 SYMBOL(atomic_intmax_t, std::, )
+SYMBOL(atomic_intmax_t, None, )
 SYMBOL(atomic_intmax_t, None, )
 SYMBOL(atomic_intptr_t, std::, )
+SYMBOL(atomic_intptr_t, None, )
 SYMBOL(atomic_intptr_t, None, )
 SYMBOL(atomic_llong, std::, )
+SYMBOL(atomic_llong, None, )
 SYMBOL(atomic_llong, None, )
 SYMBOL(atomic_long, std::, )
+SYMBOL(atomic_long, None, )
 SYMBOL(atomic_long, None, )
 SYMBOL(atomic_ptr
diff _t, std::, )
+SYMBOL(atomic_ptr
diff _t, None, )
 SYMBOL(atomic_ptr
diff _t, None, )
 SYMBOL(atomic_schar, std::, )
+SYMBOL(atomic_schar, None, )
 SYMBOL(atomic_schar, None, )
 SYMBOL(atomic_short, std::, )
+SYMBOL(atomic_short, None, )
 SYMBOL(atomic_short, None, )
 SYMBOL(atomic_signed_lock_free, std::, )
+SYMBOL(atomic_signed_lock_free, None, )
 SYMBOL(atomic_signed_lock_free, None, )
 SYMBOL(atomic_size_t, std::, )
+SYMBOL(atomic_size_t, None, )
 SYMBOL(atomic_size_t, None, )
 SYMBOL(atomic_uchar, std::, )
+SYMBOL(atomic_uchar, None, )
 SYMBOL(atomic_uchar, None, )
 SYMBOL(atomic_uint, std::, )
+SYMBOL(atomic_uint, None, )
 SYMBOL(atomic_uint, None, )
 SYMBOL(atomic_uint16_t, std::, )
+SYMBOL(atomic_uint16_t, None, )
 SYMBOL(atomic_uint16_t, None, )
 SYMBOL(atomic_uint32_t, std::, )
+SYMBOL(atomic_uint32_t, None, )
 SYMBOL(atomic_uint32_t, None, )
 SYMBOL(atomic_uint64_t, std::, )
+SYMBOL(atomic_uint64_t, None, )
 SYMBOL(atomic_uint64_t, None, )
 SYMBOL(atomic_uint8_t, std::, )
+SYMBOL(atomic_uint8_t, None, )
 SYMBOL(atomic_uint8_t, None, )
 SYMBOL(atomic_uint_fast16_t, std::, )
+SYMBOL(atomic_uint_fast16_t, None, )
 SYMBOL(atomic_uint_fast16_t, None, )
 SYMBOL(atomic_uint_fast32_t, std::, )
+SYMBOL(atomic_uint_fast32_t, None, )
 SYMBOL(atomic_uint_fast32_t, None, )
 SYMBOL(atomic_uint_fast64_t, std::, )
+SYMBOL(atomic_uint_fast64_t, None, )
 SYMBOL(atomic_uint_fast64_t, None, )
 SYMBOL(atomic_uint_fast8_t, std::, )
+SYMBOL(atomic_uint_fast8_t, None, )
 SYMBOL(atomic_uint_fast8_t, None, )
 SYMBOL(atomic_uint_least16_t, std::, )
+SYMBOL(atomic_uint_least16_t, None, )
 SYMBOL(atomic_uint_least16_t, None, )
 SYMBOL(atomic_uint_least32_t, std::, )
+SYMBOL(atomic_uint_least32_t, None, )
 SYMBOL(atomic_uint_least32_t, None, )
 SYMBOL(atomi

[clang] [Arm] Fix generating code with UB in NeonEmitter (PR #121802)

2025-01-23 Thread via cfe-commits

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


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


[clang] [compiler-rt] [Clang] Make `-Wreturn-type` default to an error in all language modes (PR #123470)

2025-01-23 Thread via cfe-commits

Sirraide wrote:

> I see a lot of diagnostics were updated to `DefaultError` but I don't see 
> matching tests that demonstrate the now error. We should be testing each 
> diagnostic.

#123464 also added `-Werror=return-type` to some tests; we can remove those 
now, which should cover at least some of the diagonstics; I’ll add a test for 
whatever is left after that because I don’t think we have one for e.g. the 
coroutine ones.

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


[clang] [compiler-rt] [Clang] Make `-Wreturn-type` default to an error in all language modes (PR #123470)

2025-01-23 Thread via cfe-commits

Sirraide wrote:

> I think this is probably Clang 21 material

Yeah, probably

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


[clang] [Driver] -fno-plt: warn for unsupported targets (PR #124081)

2025-01-23 Thread Martin Storsjö via cfe-commits


@@ -0,0 +1,9 @@
+// RUN: %clang -### -c --target=aarch64 -fno-plt -Werror %s 2>&1 | FileCheck %s
+// RUN: %clang -### -c --target=x86_64 -fno-plt -Werror %s 2>&1 | FileCheck %s
+// RUN: %clang -### -c --target=aarch64 -fno-plt -fplt -Werror %s 2>&1 | 
FileCheck %s --check-prefix=NO

mstorsjo wrote:

There's quite many negations involved in this check line, can you rename the 
`NO` prefix to e.g. `PLT` or something like that, to signify the case when 
`-fplt` is in effect? Then again, using `--check-prefix=PLT` for the 
`aarch64-windows` target feels a bit misleading as well. Perhaps if we'd rename 
`CHECK` into `NOPLT` and `NO` into `DEFAULT`?

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


[clang] 17756aa - [Clang] [Release Notes] Implicit lifetimes are a C++23 feature

2025-01-23 Thread via cfe-commits

Author: cor3ntin
Date: 2025-01-23T12:19:52+01:00
New Revision: 17756aa9c9d2f54a29dba3a2805f217cc1723ff0

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

LOG: [Clang] [Release Notes] Implicit lifetimes are a C++23 feature

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5989788132c92b..5d4b182f29afa0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -294,9 +294,6 @@ C++ Language Changes
 C++2c Feature Support
 ^
 
-- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports
-  `P2647R1 A trait for implicit lifetime types `_
-
 - Add ``__builtin_is_virtual_base_of`` intrinsic, which supports
   `P2985R0 A type trait for detecting virtual base classes 
`_
 
@@ -318,6 +315,9 @@ C++23 Feature Support
 
 - ``__cpp_explicit_this_parameter`` is now defined. (#GH82780)
 
+- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports
+  `P2674R1 A trait for implicit lifetime types `_
+
 - Add support for `P2280R4 Using unknown pointers and references in constant 
expressions `_. (#GH63139)
 
 C++20 Feature Support



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


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator moveBefore at many call-sites (PR #123583)

2025-01-23 Thread Orlando Cazalet-Hyams via cfe-commits


@@ -242,13 +253,19 @@ class Instruction : public User,
   /// \pre I is a valid iterator into BB.
   void moveBefore(BasicBlock &BB, InstListType::iterator I);
 
-  /// (See other overload for moveBeforePreserving).
   void moveBeforePreserving(BasicBlock &BB, InstListType::iterator I);
+  /// Unlink this instruction from its current basic block and insert it into
+  /// the basic block that MovePos lives in, right before MovePos.

OCHyams wrote:

Nit: mismatch param name in comment

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


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator moveBefore at many call-sites (PR #123583)

2025-01-23 Thread Orlando Cazalet-Hyams via cfe-commits


@@ -224,11 +231,15 @@ class Instruction : public User,
   /// the basic block that MovePos lives in, right before MovePos.
   void moveBefore(Instruction *MovePos);
 
+  /// Unlink this instruction from its current basic block and insert it into
+  /// the basic block that MovePos lives in, right before MovePos.
+  void moveBefore(InstListType::iterator InsertPos);

OCHyams wrote:

```suggestion
  /// the basic block that MovePos lives in, right before MovePos.
  void moveBefore(InstListType::iterator MovePos);
```

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


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator moveBefore at many call-sites (PR #123583)

2025-01-23 Thread Orlando Cazalet-Hyams via cfe-commits


@@ -448,7 +448,7 @@ void IRPromoter::ExtendSources() {
   if (isa(V))
 I->moveBefore(InsertPt);
   else
-I->moveAfter(InsertPt);
+I->moveAfter(&*InsertPt);

OCHyams wrote:

Same as earlier - is this a code-transition-state bug, or is there some reason 
we've got to use the `Instruction *` overload here? (this one matters more)

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


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator moveBefore at many call-sites (PR #123583)

2025-01-23 Thread Orlando Cazalet-Hyams via cfe-commits

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

LGTM with a couple nit/questions.

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


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator moveBefore at many call-sites (PR #123583)

2025-01-23 Thread Orlando Cazalet-Hyams via cfe-commits


@@ -8890,21 +8890,21 @@ bool 
CodeGenPrepare::fixupDbgVariableRecord(DbgVariableRecord &DVR) {
   return AnyChange;
 }
 
-static void DbgInserterHelper(DbgValueInst *DVI, Instruction *VI) {
+static void DbgInserterHelper(DbgValueInst *DVI, BasicBlock::iterator VI) {
   DVI->removeFromParent();
   if (isa(VI))
-DVI->insertBefore(&*VI->getParent()->getFirstInsertionPt());
+DVI->insertBefore(VI->getParent()->getFirstInsertionPt());
   else
 DVI->insertAfter(VI);
 }
 
-static void DbgInserterHelper(DbgVariableRecord *DVR, Instruction *VI) {
+static void DbgInserterHelper(DbgVariableRecord *DVR, BasicBlock::iterator VI) 
{
   DVR->removeFromParent();
   BasicBlock *VIBB = VI->getParent();
   if (isa(VI))
 VIBB->insertDbgRecordBefore(DVR, VIBB->getFirstInsertionPt());
   else
-VIBB->insertDbgRecordAfter(DVR, VI);
+VIBB->insertDbgRecordAfter(DVR, &*VI);

OCHyams wrote:

Is this a code-transition-state bug, or is there some reason we've got to use 
the Instruction * overload here? I suppose it doesn't matter either way for dbg 
records.

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


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator moveBefore at many call-sites (PR #123583)

2025-01-23 Thread Orlando Cazalet-Hyams via cfe-commits

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


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator moveBefore at many call-sites (PR #123583)

2025-01-23 Thread Orlando Cazalet-Hyams via cfe-commits


@@ -224,11 +231,15 @@ class Instruction : public User,
   /// the basic block that MovePos lives in, right before MovePos.
   void moveBefore(Instruction *MovePos);
 
+  /// Unlink this instruction from its current basic block and insert it into
+  /// the basic block that MovePos lives in, right before MovePos.
+  void moveBefore(InstListType::iterator InsertPos);

OCHyams wrote:

nit: parameter name and comment don't match up

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


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator moveBefore at many call-sites (PR #123583)

2025-01-23 Thread Orlando Cazalet-Hyams via cfe-commits


@@ -224,11 +231,15 @@ class Instruction : public User,
   /// the basic block that MovePos lives in, right before MovePos.
   void moveBefore(Instruction *MovePos);
 
+  /// Unlink this instruction from its current basic block and insert it into
+  /// the basic block that MovePos lives in, right before MovePos.
+  void moveBefore(InstListType::iterator InsertPos);
+
   /// Perform a \ref moveBefore operation, while signalling that the caller
   /// intends to preserve the original ordering of instructions. This 
implicitly
   /// means that any adjacent debug-info should move with this instruction.
-  /// This method is currently a no-op placeholder, but it will become 
meaningful
-  /// when the "RemoveDIs" project is enabled.
+  /// This method is currently a no-op placeholder, but it will become
+  /// meaningful when the "RemoveDIs" project is enabled.

OCHyams wrote:

Is this comment stale?

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


[clang-tools-extra] [clang-tidy] Fix modernize-use-integer-sign-comparison comparison (PR #121506)

2025-01-23 Thread via cfe-commits

https://github.com/qt-tatiana updated 
https://github.com/llvm/llvm-project/pull/121506

>From 0591e8b7be49299e2b73634a6ad4f2330557b37a Mon Sep 17 00:00:00 2001
From: Tatiana Borisova 
Date: Thu, 2 Jan 2025 18:08:26 +0100
Subject: [PATCH 1/4] [clang-tidy] Fix modernize-use-integer-sign-comparison
 comparison

- modernize-use-integer-sign-comparison should ignore a comparison between
the signed wide type and the unsigned narrow type, see #120867
---
 .../UseIntegerSignComparisonCheck.cpp | 14 ++-
 .../modernize/use-integer-sign-comparison.cpp | 24 +--
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
index 8f807bc0a96d56..ebcfafcd391145 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -89,7 +89,8 @@ void UseIntegerSignComparisonCheck::storeOptions(
 
 void UseIntegerSignComparisonCheck::registerMatchers(MatchFinder *Finder) {
   const auto SignedIntCastExpr = intCastExpression(true, "sIntCastExpression");
-  const auto UnSignedIntCastExpr = intCastExpression(false);
+  const auto UnSignedIntCastExpr =
+  intCastExpression(false, "uIntCastExpression");
 
   // Flag all operators "==", "<=", ">=", "<", ">", "!="
   // that are used between signed/unsigned
@@ -111,7 +112,10 @@ void UseIntegerSignComparisonCheck::check(
 const MatchFinder::MatchResult &Result) {
   const auto *SignedCastExpression =
   Result.Nodes.getNodeAs("sIntCastExpression");
+  const auto *UnSignedCastExpression =
+  Result.Nodes.getNodeAs("uIntCastExpression");
   assert(SignedCastExpression);
+  assert(UnSignedCastExpression);
 
   // Ignore the match if we know that the signed int value is not negative.
   Expr::EvalResult EVResult;
@@ -134,6 +138,13 @@ void UseIntegerSignComparisonCheck::check(
   const Expr *RHS = BinaryOp->getRHS()->IgnoreImpCasts();
   if (LHS == nullptr || RHS == nullptr)
 return;
+
+  if (Result.Context->getTypeSize(
+  SignedCastExpression->getSubExpr()->getType()) >
+  Result.Context->getTypeSize(
+  UnSignedCastExpression->getSubExpr()->getType()))
+return;
+
   const Expr *SubExprLHS = nullptr;
   const Expr *SubExprRHS = nullptr;
   SourceRange R1 = SourceRange(LHS->getBeginLoc());
@@ -151,6 +162,7 @@ void UseIntegerSignComparisonCheck::check(
 SubExprRHS = RHSCast->getSubExpr();
 R2.setEnd(SubExprRHS->getBeginLoc().getLocWithOffset(-1));
   }
+
   DiagnosticBuilder Diag =
   diag(BinaryOp->getBeginLoc(),
"comparison between 'signed' and 'unsigned' integers");
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
index 99f00444c2d3f3..85eda925d5903c 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
@@ -32,7 +32,7 @@ int TemplateFuncParameters(T1 val1, T2 val2) {
 
 int AllComparisons() {
 unsigned int uVar = 42;
-unsigned short uArray[7] = {0, 1, 2, 3, 9, 7, 9};
+unsigned int uArray[7] = {0, 1, 2, 3, 9, 7, 9};
 
 int sVar = -42;
 short sArray[7] = {-1, -2, -8, -94, -5, -4, -6};
@@ -113,10 +113,30 @@ int AllComparisons() {
 // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
 // CHECK-FIXES: if (std::cmp_greater(uArray[6] , VALUE))
 
-
 FuncParameters(uVar);
 TemplateFuncParameter(sVar);
 TemplateFuncParameters(uVar, sVar);
 
 return 0;
 }
+
+bool foo1(int x, unsigned char y) {
+return x == y;
+// CHECK-MESSAGES-NOT: warning:
+}
+
+bool foo2(int x, unsigned short y) {
+return x == y;
+// CHECK-MESSAGES-NOT: warning:
+}
+
+bool bar1(unsigned int x, char y) {
+return x == y;
+// CHECK-MESSAGES-NOT: warning:
+}
+
+bool bar2(unsigned int x, short y) {
+return x == y;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: std::cmp_equal(x , y);
+}

>From 60cc85f4693a9164159754248313119067037f3c Mon Sep 17 00:00:00 2001
From: Tatiana Borisova 
Date: Mon, 6 Jan 2025 12:53:55 +0100
Subject: [PATCH 2/4] [clang-tidy] Fix modernize-use-integer-sign-comparison
 comparison

- add ``ConsideringIntegerSize`` option, that ignores a comparison
between a signed wide and an unsigned narrow integer types, add
documentation.
---
 .../clang-tidy/modernize/ModernizeTidyModule.cpp|  8 
 .../modernize/UseIntegerSignComparisonCheck.cpp | 13 -
 .../modernize/UseIntegerSignComparisonCheck.h   |  1 +
 clang-tools-extra/docs/R

[clang] [Driver] -fno-plt: warn for unsupported targets (PR #124081)

2025-01-23 Thread via cfe-commits

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


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


[clang] [Driver][ASan] Refactor Clang-Driver "Sanitizer Bitcode" linking. (PR #123922)

2025-01-23 Thread Amit Kumar Pandey via cfe-commits


@@ -70,6 +70,10 @@ def err_drv_no_rocm_device_lib : Error<
   "cannot find ROCm device library%select{| for %1| for ABI version %1}0; 
provide its path via "
   "'--rocm-path' or '--rocm-device-lib-path', or pass '-nogpulib' to build "
   "without ROCm device library">;
+def err_drv_no_asan_rt_lib
+: Error<"AMDGPU address sanitizer runtime library (asanrtl) is not found. "
+"Please install ROCm device library which supports address "
+"sanitizer">;

ampandey-1995 wrote:

Thanks, @arsenm . We discussed internally and now removing the ```asanrtl 
bitcode is not found``` diagnostic. 

Hi @arsenm, @yxsamliu, @b-sumner , should I edit the lit 
test(https://github.com/llvm/llvm-project/blob/bb518655127ad49e527bbc2a57a5fd8a3f9f0495/clang/test/Driver/hip-sanitize-options.hip#L63)
 with generic diagnostic or remove it also?

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


[clang] [Driver] -fno-plt: warn for unsupported targets (PR #124081)

2025-01-23 Thread Martin Storsjö via cfe-commits

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

LGTM, thanks! This seems to nicely fix the issue and make the situation clearer.

CC @Martchus.

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


[clang] [Clang] Add BuiltinTemplates.td to generate code for builtin templates (PR #123736)

2025-01-23 Thread Nikolas Klauser via cfe-commits

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

>From 586dd4edfc79c88cc1583b64d186c1481fbd6ce1 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Wed, 4 Sep 2024 13:31:39 +0200
Subject: [PATCH] [Clang] Add BuiltinTemplates.td to generate code for builtin
 templates

---
 clang/include/clang/AST/ASTContext.h  |  35 ++--
 clang/include/clang/AST/DeclID.h  |  10 +-
 clang/include/clang/Basic/BuiltinTemplates.td |  23 +++
 clang/include/clang/Basic/Builtins.h  |  10 +-
 clang/include/clang/Basic/CMakeLists.txt  |   4 +
 clang/lib/AST/ASTContext.cpp  |  30 +--
 clang/lib/AST/ASTImporter.cpp |  12 +-
 clang/lib/AST/DeclTemplate.cpp| 133 +
 clang/lib/Lex/PPMacroExpansion.cpp|   5 +-
 clang/lib/Sema/SemaLookup.cpp |  18 +-
 clang/lib/Serialization/ASTReader.cpp |  22 +--
 clang/lib/Serialization/ASTWriter.cpp |   8 +-
 clang/utils/TableGen/CMakeLists.txt   |   1 +
 .../TableGen/ClangBuiltinTemplatesEmitter.cpp | 184 ++
 clang/utils/TableGen/TableGen.cpp |   6 +
 clang/utils/TableGen/TableGenBackends.h   |   2 +
 16 files changed, 269 insertions(+), 234 deletions(-)
 create mode 100644 clang/include/clang/Basic/BuiltinTemplates.td
 create mode 100644 clang/utils/TableGen/ClangBuiltinTemplatesEmitter.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 0e07c5d6ce8fba..98db5522d564e9 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -410,11 +410,8 @@ class ASTContext : public RefCountedBase {
   /// The identifier 'NSCopying'.
   IdentifierInfo *NSCopyingName = nullptr;
 
-  /// The identifier '__make_integer_seq'.
-  mutable IdentifierInfo *MakeIntegerSeqName = nullptr;
-
-  /// The identifier '__type_pack_element'.
-  mutable IdentifierInfo *TypePackElementName = nullptr;
+#define BuiltinTemplate(BTName) mutable IdentifierInfo *Name##BTName = nullptr;
+#include "clang/Basic/BuiltinTemplates.inc"
 
   /// The identifier '__builtin_common_type'.
   mutable IdentifierInfo *BuiltinCommonTypeName = nullptr;
@@ -624,9 +621,9 @@ class ASTContext : public RefCountedBase {
 
   TranslationUnitDecl *TUDecl = nullptr;
   mutable ExternCContextDecl *ExternCContext = nullptr;
-  mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
-  mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
-  mutable BuiltinTemplateDecl *BuiltinCommonTypeDecl = nullptr;
+
+#define BuiltinTemplate(Name) mutable BuiltinTemplateDecl *Decl##Name = 
nullptr;
+#include "clang/Basic/BuiltinTemplates.inc"
 
   /// The associated SourceManager object.
   SourceManager &SourceMgr;
@@ -1152,9 +1149,9 @@ class ASTContext : public RefCountedBase {
   }
 
   ExternCContextDecl *getExternCContextDecl() const;
-  BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
-  BuiltinTemplateDecl *getTypePackElementDecl() const;
-  BuiltinTemplateDecl *getBuiltinCommonTypeDecl() const;
+
+#define BuiltinTemplate(Name) BuiltinTemplateDecl *get##Name##Decl() const;
+#include "clang/Basic/BuiltinTemplates.inc"
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -2054,17 +2051,13 @@ class ASTContext : public RefCountedBase {
 return BoolName;
   }
 
-  IdentifierInfo *getMakeIntegerSeqName() const {
-if (!MakeIntegerSeqName)
-  MakeIntegerSeqName = &Idents.get("__make_integer_seq");
-return MakeIntegerSeqName;
-  }
-
-  IdentifierInfo *getTypePackElementName() const {
-if (!TypePackElementName)
-  TypePackElementName = &Idents.get("__type_pack_element");
-return TypePackElementName;
+#define BuiltinTemplate(BTName)
\
+  IdentifierInfo *get##BTName##Name() const {  
\
+if (!Name##BTName) 
\
+  Name##BTName = &Idents.get(#BTName); 
\
+return Name##BTName;   
\
   }
+#include "clang/Basic/BuiltinTemplates.inc"
 
   IdentifierInfo *getBuiltinCommonTypeName() const {
 if (!BuiltinCommonTypeName)
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index 49964b43c7d1d8..71e28ec1f9c65f 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -71,20 +71,14 @@ enum PredefinedDeclIDs {
   /// The extern "C" context.
   PREDEF_DECL_EXTERN_C_CONTEXT_ID,
 
-  /// The internal '__make_integer_seq' template.
-  PREDEF_DECL_MAKE_INTEGER_SEQ_ID,
-
   /// The internal '__NSConstantString' typedef.
   PREDEF_DECL_CF_CONSTANT_STRING_ID,
 
   /// The internal '__NSConstantString' tag type.
   PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID,
 
-  /// The internal '__type_pack_element' template.
-  PREDEF_DECL_TYPE_PACK_ELEMENT_ID,
-
-  /// The internal '__builtin_common

[clang] [C++20][Modules] Fix crash/compiler error due broken AST links (PR #123648)

2025-01-23 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/123648

>From e5cd06ddbc4193f9d5910eba93f0eb309d67063c Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Mon, 20 Jan 2025 09:03:25 -0800
Subject: [PATCH 1/7] [C++20][Modules] Fix crash/compiler error due broken AST
 links
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Summary:
This PR fixes bugreport https://github.com/llvm/llvm-project/issues/122493
The root problem is the same as before lambda function and DeclRefExpr 
references
a variable that does not belong to the same module as the enclosing function 
body.
Therefore iteration over the function body doesn’t visit the VarDecl. Before 
this
change RelatedDeclsMap was created only for canonical decl but in reality it 
has to
be done for the definition of the function that does not always match the 
canonical decl.

Test Plan: check-clang
---
 clang/lib/Serialization/ASTWriterDecl.cpp |  5 +-
 ...ash-instantiated-in-scope-cxx-modules5.cpp | 92 +++
 2 files changed, 95 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/Headers/crash-instantiated-in-scope-cxx-modules5.cpp

diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index f8ed155ca389d7..371b4b29e85991 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1571,9 +1571,10 @@ void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) 
{
 } else {
   Record.push_back(0);
 }
-// For lambdas inside canonical FunctionDecl remember the mapping.
+// For lambdas inside template functions, remember the mapping to
+// deserialize them together.
 if (auto FD = llvm::dyn_cast_or_null(D->getDeclContext());
-FD && FD->isCanonicalDecl()) {
+FD && FD->isDependentContext() && FD->isThisDeclarationADefinition()) {
   Writer.RelatedDeclsMap[Writer.GetDeclRef(FD)].push_back(
   Writer.GetDeclRef(D));
 }
diff --git a/clang/test/Headers/crash-instantiated-in-scope-cxx-modules5.cpp 
b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules5.cpp
new file mode 100644
index 00..ca80a3fd21dd00
--- /dev/null
+++ b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules5.cpp
@@ -0,0 +1,92 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -verify -std=c++20 -xc++ -emit-module module.cppmap 
-fmodule-name=mock_resolver -o mock_resolver.pcm
+// RUN: %clang_cc1 -verify -std=c++20 -xc++ -emit-module module.cppmap 
-fmodule-name=sql_internal -o sql_internal.pcm
+// RUN: %clang_cc1 -verify -std=c++20 -xc++ -fmodule-file=mock_resolver.pcm 
-fmodule-file=sql_internal.pcm main.cc -o main.o
+
+//--- module.cppmap
+module "mock_resolver" {
+  export *
+  module "mock_resolver.h" {
+export *
+header "mock_resolver.h"
+  }
+}
+
+module "sql_internal" {
+  export *
+  module "sql_transform_builder.h" {
+export *
+header "sql_transform_builder.h"
+  }
+}
+
+//--- set_bits2.h
+// expected-no-diagnostics
+#pragma once
+
+template 
+void fwd(const T& x) {}
+
+namespace vox::bitset {
+
+template 
+void ForEachSetBit2(const TFunc&) {
+  fwd([](int) {
+const int bit_index_base = 0;
+(void)[&](int) {
+  int v = bit_index_base;
+};
+  });
+}
+
+}  // namespace vox::bitset
+
+//--- sql_transform_builder.h
+// expected-no-diagnostics
+#pragma once
+
+#include "set_bits2.h"
+
+class QualifyingSet3 {
+ public:
+  void GetIndexes() const {
+vox::bitset::ForEachSetBit2([]() {});
+  }
+};
+
+template 
+void DoTransform() {
+  vox::bitset::ForEachSetBit2([]() {});
+}
+
+//--- mock_resolver.h
+// expected-no-diagnostics
+#pragma once 
+#include "set_bits2.h"
+
+class QualifyingSet2 {
+ public:
+  void GetIndexes() const {
+vox::bitset::ForEachSetBit2([]() {});
+  }
+};
+
+//--- main.cc
+// expected-no-diagnostics
+#include "sql_transform_builder.h"
+
+template 
+void get(const Callable& fn) {
+  fwd(fn);
+}
+
+namespace {
+
+void test() {
+  get([]() {});
+  DoTransform();
+}
+
+} // namespace

>From 01254792e2b75e00cc44259b27fcb4e38e719629 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Tue, 21 Jan 2025 02:32:33 -0800
Subject: [PATCH 2/7] Add -Werror=uninitialized to add compilation error in
 builds without assserts All improve comments

---
 clang/include/clang/Serialization/ASTReader.h | 11 ++-
 clang/lib/Serialization/ASTWriterDecl.cpp |  6 +++---
 .../crash-instantiated-in-scope-cxx-modules5.cpp  |  6 +++---
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 9f978762a6fb6b..d27a49863fc557 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -539,11 +539,12 @@ class ASTReader
 
   /// Mapping from main decl ID to the related decls IDs.
   //

[clang] [flang] [llvm] [Clang] Remove ARCMigrate (PR #119269)

2025-01-23 Thread via cfe-commits

cor3ntin wrote:

@AaronBallman 

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


[libclc] [libclc] Move nextafter to the CLC library (PR #124097)

2025-01-23 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/124097

There were two implementations of this - one that implemented nextafter in 
software, and another that called a clang builtin. No in-tree targets called 
the builtin, so all targets build the software version. The builtin version has 
been removed, and the software version has been renamed to be the "default".

This commit also optimizes nextafter, to avoid scalarization as much as 
possible. Note however that the (CLC) relational builtins still scalarize; 
those will be optimized in a separate commit.

Since nextafter is used by some convert_type builtins, the diff to IR codegen 
is not limited to the builtin itself.

>From cf3dc3c2a3cb2f463988a599ee2c2f2902971d5e Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Mon, 4 Nov 2024 14:35:59 +
Subject: [PATCH] [libclc] Move nextafter to the CLC library

There were two implementations of this - one that implemented nextafter
in software, and another that called a clang builtin. No in-tree targets
called the builtin, so all targets build the software version. The
builtin version has been removed, and the software version has been
renamed to be the "default".

This commit also optimizes nextafter, to avoid scalarization as much as
possible. Note however that the (CLC) relational builtins still
scalarize; those will be optimized in a separate commit.

Since nextafter is used by some convert_type builtins, the diff to IR
codegen is not limited to the builtin itself.
---
 libclc/amdgpu/lib/SOURCES |  1 -
 libclc/amdgpu/lib/math/nextafter.cl   | 15 -
 libclc/clc/include/clc/clcmacro.h | 28 +
 .../binary_decl_with_scalar_second_arg.inc|  4 ++
 libclc/clc/include/clc/math/clc_nextafter.h   | 12 
 libclc/clc/include/clc/relational/clc_isnan.h |  7 ---
 libclc/clc/include/clc/shared/binary_decl.inc |  2 +
 libclc/clc/lib/clspv/SOURCES  |  1 +
 libclc/clc/lib/generic/SOURCES|  1 +
 libclc/clc/lib/generic/math/clc_nextafter.cl  | 62 +++
 libclc/clc/lib/spirv/SOURCES  |  1 +
 libclc/clc/lib/spirv64/SOURCES|  1 +
 libclc/clspv/lib/SOURCES  |  3 +-
 libclc/clspv/lib/math/nextafter.cl|  5 --
 libclc/clspv/lib/math/nextafter.inc   |  3 -
 .../generic/include/clc/math/binary_decl.inc  |  2 -
 libclc/generic/include/clc/math/fmax.h|  2 +-
 libclc/generic/include/clc/math/fmin.h|  2 +-
 libclc/generic/include/math/clc_nextafter.h   |  7 ---
 libclc/generic/lib/SOURCES|  1 -
 libclc/generic/lib/math/clc_nextafter.cl  | 49 ---
 libclc/generic/lib/math/nextafter.cl  | 18 +-
 libclc/ptx/lib/SOURCES|  1 -
 libclc/ptx/lib/math/nextafter.cl  | 10 ---
 24 files changed, 130 insertions(+), 108 deletions(-)
 delete mode 100644 libclc/amdgpu/lib/math/nextafter.cl
 create mode 100644 
libclc/clc/include/clc/math/binary_decl_with_scalar_second_arg.inc
 create mode 100644 libclc/clc/include/clc/math/clc_nextafter.h
 create mode 100644 libclc/clc/include/clc/shared/binary_decl.inc
 create mode 100644 libclc/clc/lib/generic/math/clc_nextafter.cl
 delete mode 100644 libclc/clspv/lib/math/nextafter.cl
 delete mode 100644 libclc/clspv/lib/math/nextafter.inc
 delete mode 100644 libclc/generic/include/clc/math/binary_decl.inc
 delete mode 100644 libclc/generic/include/math/clc_nextafter.h
 delete mode 100644 libclc/generic/lib/math/clc_nextafter.cl
 delete mode 100644 libclc/ptx/lib/SOURCES
 delete mode 100644 libclc/ptx/lib/math/nextafter.cl

diff --git a/libclc/amdgpu/lib/SOURCES b/libclc/amdgpu/lib/SOURCES
index b11cbdecf27b9d..24f099d049cd34 100644
--- a/libclc/amdgpu/lib/SOURCES
+++ b/libclc/amdgpu/lib/SOURCES
@@ -10,5 +10,4 @@ math/half_log2.cl
 math/half_recip.cl
 math/half_rsqrt.cl
 math/half_sqrt.cl
-math/nextafter.cl
 math/sqrt.cl
diff --git a/libclc/amdgpu/lib/math/nextafter.cl 
b/libclc/amdgpu/lib/math/nextafter.cl
deleted file mode 100644
index 6dc117b8cdd64c..00
--- a/libclc/amdgpu/lib/math/nextafter.cl
+++ /dev/null
@@ -1,15 +0,0 @@
-#include 
-#include 
-#include 
-
-_CLC_DEFINE_BINARY_BUILTIN(float, nextafter, __clc_nextafter, float, float)
-
-#ifdef cl_khr_fp64
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-_CLC_DEFINE_BINARY_BUILTIN(double, nextafter, __clc_nextafter, double, double)
-#endif
-
-#ifdef cl_khr_fp16
-#pragma OPENCL EXTENSION cl_khr_fp16 : enable
-_CLC_DEFINE_BINARY_BUILTIN(half, nextafter, __clc_nextafter, half, half)
-#endif
diff --git a/libclc/clc/include/clc/clcmacro.h 
b/libclc/clc/include/clc/clcmacro.h
index 676560e9efcb44..14399811bad938 100644
--- a/libclc/clc/include/clc/clcmacro.h
+++ b/libclc/clc/include/clc/clcmacro.h
@@ -159,6 +159,34 @@
   _CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, RET_TYPE, FUNCTION, ARG1_TYPE, 
\
 ARG2_TYPE)
 
+// FIXME: Make

[libclc] [libclc] Move nextafter to the CLC library (PR #124097)

2025-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Fraser Cormack (frasercrmck)


Changes

There were two implementations of this - one that implemented nextafter in 
software, and another that called a clang builtin. No in-tree targets called 
the builtin, so all targets build the software version. The builtin version has 
been removed, and the software version has been renamed to be the "default".

This commit also optimizes nextafter, to avoid scalarization as much as 
possible. Note however that the (CLC) relational builtins still scalarize; 
those will be optimized in a separate commit.

Since nextafter is used by some convert_type builtins, the diff to IR codegen 
is not limited to the builtin itself.

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


24 Files Affected:

- (modified) libclc/amdgpu/lib/SOURCES (-1) 
- (removed) libclc/amdgpu/lib/math/nextafter.cl (-15) 
- (modified) libclc/clc/include/clc/clcmacro.h (+28) 
- (added) libclc/clc/include/clc/math/binary_decl_with_scalar_second_arg.inc 
(+4) 
- (added) libclc/clc/include/clc/math/clc_nextafter.h (+12) 
- (modified) libclc/clc/include/clc/relational/clc_isnan.h (-7) 
- (added) libclc/clc/include/clc/shared/binary_decl.inc (+2) 
- (modified) libclc/clc/lib/clspv/SOURCES (+1) 
- (modified) libclc/clc/lib/generic/SOURCES (+1) 
- (added) libclc/clc/lib/generic/math/clc_nextafter.cl (+62) 
- (modified) libclc/clc/lib/spirv/SOURCES (+1) 
- (modified) libclc/clc/lib/spirv64/SOURCES (+1) 
- (modified) libclc/clspv/lib/SOURCES (+1-2) 
- (removed) libclc/clspv/lib/math/nextafter.cl (-5) 
- (removed) libclc/clspv/lib/math/nextafter.inc (-3) 
- (removed) libclc/generic/include/clc/math/binary_decl.inc (-2) 
- (modified) libclc/generic/include/clc/math/fmax.h (+1-1) 
- (modified) libclc/generic/include/clc/math/fmin.h (+1-1) 
- (removed) libclc/generic/include/math/clc_nextafter.h (-7) 
- (modified) libclc/generic/lib/SOURCES (-1) 
- (removed) libclc/generic/lib/math/clc_nextafter.cl (-49) 
- (modified) libclc/generic/lib/math/nextafter.cl (+15-3) 
- (removed) libclc/ptx/lib/SOURCES (-1) 
- (removed) libclc/ptx/lib/math/nextafter.cl (-10) 


``diff
diff --git a/libclc/amdgpu/lib/SOURCES b/libclc/amdgpu/lib/SOURCES
index b11cbdecf27b9d..24f099d049cd34 100644
--- a/libclc/amdgpu/lib/SOURCES
+++ b/libclc/amdgpu/lib/SOURCES
@@ -10,5 +10,4 @@ math/half_log2.cl
 math/half_recip.cl
 math/half_rsqrt.cl
 math/half_sqrt.cl
-math/nextafter.cl
 math/sqrt.cl
diff --git a/libclc/amdgpu/lib/math/nextafter.cl 
b/libclc/amdgpu/lib/math/nextafter.cl
deleted file mode 100644
index 6dc117b8cdd64c..00
--- a/libclc/amdgpu/lib/math/nextafter.cl
+++ /dev/null
@@ -1,15 +0,0 @@
-#include 
-#include 
-#include 
-
-_CLC_DEFINE_BINARY_BUILTIN(float, nextafter, __clc_nextafter, float, float)
-
-#ifdef cl_khr_fp64
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-_CLC_DEFINE_BINARY_BUILTIN(double, nextafter, __clc_nextafter, double, double)
-#endif
-
-#ifdef cl_khr_fp16
-#pragma OPENCL EXTENSION cl_khr_fp16 : enable
-_CLC_DEFINE_BINARY_BUILTIN(half, nextafter, __clc_nextafter, half, half)
-#endif
diff --git a/libclc/clc/include/clc/clcmacro.h 
b/libclc/clc/include/clc/clcmacro.h
index 676560e9efcb44..14399811bad938 100644
--- a/libclc/clc/include/clc/clcmacro.h
+++ b/libclc/clc/include/clc/clcmacro.h
@@ -159,6 +159,34 @@
   _CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, RET_TYPE, FUNCTION, ARG1_TYPE, 
\
 ARG2_TYPE)
 
+// FIXME: Make _CLC_DEFINE_BINARY_BUILTIN avoid scalarization by default, and
+// introduce an explicit scalarizing version.
+#define _CLC_DEFINE_BINARY_BUILTIN_NO_SCALARIZE(RET_TYPE, FUNCTION, BUILTIN,   
\
+ARG1_TYPE, ARG2_TYPE)  
\
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE FUNCTION(ARG1_TYPE x, ARG2_TYPE y) { 
\
+return BUILTIN(x, y);  
\
+  }
\
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE##2 FUNCTION(ARG1_TYPE##2 x,  
\
+  ARG2_TYPE##2 y) {
\
+return BUILTIN(x, y);  
\
+  }
\
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE##3 FUNCTION(ARG1_TYPE##3 x,  
\
+  ARG2_TYPE##3 y) {
\
+return BUILTIN(x, y);  
\
+  }
\
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE##4 FUNCTION(ARG1_TYPE##4 x,  
\
+  ARG2_TYPE##4 y) {
\
+return BUILTIN(x, y);  
\
+  }  

[clang] [C++20][Modules] Fix crash/compiler error due broken AST links (PR #123648)

2025-01-23 Thread Dmitry Polukhin via cfe-commits

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


[clang] [TySan] Add initial documentation for Type Sanitizer (PR #123595)

2025-01-23 Thread via cfe-commits


@@ -0,0 +1,162 @@
+
+TypeSanitizer
+
+
+.. contents::
+   :local:
+
+Introduction
+
+
+The TypeSanitizer is a detector for strict type aliasing violations. It 
consists of a compiler
+instrumentation module and a run-time library. C/C++ has type-based aliasing 
rules, and LLVM 
+can exploit these for optimizations given the TBAA metadata Clang emits. In 
general, a pointer 
+of a given type cannot access an object of a different type, with only a few 
exceptions. 
+
+These rules aren't always apparent to users, which leads to code that violates 
these rules
+(e.g. for type punning). This can lead to optimization passes introducing bugs 
unless the 
+code is build with ``-fno-strict-aliasing``, sacrificing performance.
+
+TypeSanitizer is built to catch when these strict aliasing rules have been 
violated, helping 
+users find where such bugs originate in their code despite the code looking 
valid at first glance.
+
+As TypeSanitizer is still experimental, it can currently have a large impact 
on runtime speed, 
+memory use, and code size.
+
+How to build
+
+
+Build LLVM/Clang with `CMake `_ and enable
+the ``compiler-rt`` runtime. An example CMake configuration that will allow
+for the use/testing of TypeSanitizer:
+
+.. code-block:: console
+
+   $ cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" 
-DLLVM_ENABLE_RUNTIMES="compiler-rt" /llvm
+
+Usage
+=
+
+Compile and link your program with ``-fsanitize=type`` flag.  The
+TypeSanitizer run-time library should be linked to the final executable, so
+make sure to use ``clang`` (not ``ld``) for the final link step. To
+get a reasonable performance add ``-O1`` or higher.
+TypeSanitizer by default doesn't print the full stack trace in error messages. 
Use ``TYSAN_OPTIONS=print_stacktrace=1`` 
+to print the full trace. To get nicer stack traces in error messages add 
``-fno-omit-frame-pointer`` and 
+``-g``.  To get perfect stack traces you may need to disable inlining (just 
use ``-O1``) and tail call elimination 
+(``-fno-optimize-sibling-calls``).
+
+.. code-block:: console
+
+% cat example_AliasViolation.c
+int main(int argc, char **argv) {
+  int x = 100;
+  float *y = (float*)&x;
+  *y += 2.0f;  // Strict aliasing violation
+  return 0;
+}
+
+# Compile and link
+% clang++ -g -fsanitize=type example_AliasViolation.cc
+
+The program will print an error message to stderr each time a strict aliasing 
violation is detected. 
+The program won't terminate, which will allow you to detect many strict 
aliasing violations in one 
+run.
+
+.. code-block:: console
+
+% ./a.out
+==1375532==ERROR: TypeSanitizer: type-aliasing-violation on address 
0x7ffeebf1a72c (pc 0x5b3b1145ff41 bp 0x7ffeebf1a660 sp 0x7ffeebf19e08 tid 
1375532)
+READ of size 4 at 0x7ffeebf1a72c with type float accesses an existing 
object of type int
+#0 0x5b3b1145ff40 in main example_AliasViolation.c:4:10
+
+==1375532==ERROR: TypeSanitizer: type-aliasing-violation on address 
0x7ffeebf1a72c (pc 0x5b3b1146008a bp 0x7ffeebf1a660 sp 0x7ffeebf19e08 tid 
1375532)
+WRITE of size 4 at 0x7ffeebf1a72c with type float accesses an existing 
object of type int
+#0 0x5b3b11460089 in main example_AliasViolation.c:4:10
+
+Error terminology
+--
+
+There are some terms that may appear in TypeSanitizer errors that are derived 
from 
+`TBAA Metadata `. This 
section hopes to provide a 
+brief dictionary of these terms.
+
+* ``omnipotent char``: This is a special type which can alias with anything. 
Its name comes from the C/C++ 
+  type ``char``.
+* ``type p[x]``: This signifies pointers to the type. x is the number of 
indirections to reach the final value.
+  As an example, a pointer to a pointer to an integer would be ``type p2 int``.
+
+TypeSanitizer is still experimental. User-facing error messages should be 
improved in the future to remove 
+references to LLVM IR specific terms.
+
+Sanitizer features
+==
+
+``__has_feature(type_sanitizer)``
+
+
+In some cases one may need to execute different code depending on whether
+TypeSanitizer is enabled.
+:ref:`\_\_has\_feature ` can be used for
+this purpose.
+
+.. code-block:: c
+
+#if defined(__has_feature)
+#  if __has_feature(type_sanitizer)
+// code that builds only under TypeSanitizer
+#  endif
+#endif
+
+``__attribute__((no_sanitize("type")))``
+---
+
+Some code you may not want to be instrumented by TypeSanitizer.  One may use 
the
+function attribute ``no_sanitize("type")`` to disable instrumenting type 
aliasing. 
+It is possible, depending on what happens in non-instrumented code, that 
instrumented code 
+emits false-positives/ false-negatives. This attribute may not be supported

[clang] [TySan] Add initial documentation for Type Sanitizer (PR #123595)

2025-01-23 Thread via cfe-commits

https://github.com/gbMattN updated 
https://github.com/llvm/llvm-project/pull/123595

>From 807c2c8be0517cbb1b9db890f48baeb6f226ba2f Mon Sep 17 00:00:00 2001
From: gbMattN 
Date: Mon, 20 Jan 2025 11:02:06 +
Subject: [PATCH 1/9] [TySan] Add initial documentation

---
 clang/docs/TypeSanitizer.rst | 152 +++
 1 file changed, 152 insertions(+)
 create mode 100644 clang/docs/TypeSanitizer.rst

diff --git a/clang/docs/TypeSanitizer.rst b/clang/docs/TypeSanitizer.rst
new file mode 100644
index 00..6b320f3bb1773d
--- /dev/null
+++ b/clang/docs/TypeSanitizer.rst
@@ -0,0 +1,152 @@
+
+TypeSanitizer
+
+
+.. contents::
+   :local:
+
+Introduction
+
+
+TypeSanitizer is a detector for strict type aliasing violations. It consists 
of a compiler
+instrumentation module and a run-time library. The tool detects violations 
such as the use 
+of an illegally cast pointer, or misuse of a union.
+
+The violations TypeSanitizer catches may cause the compiler to emit incorrect 
code.
+
+Typical slowdown introduced by TypeSanitizer is about **4x** [[CHECK THIS]]. 
Typical memory overhead introduced by TypeSanitizer is about **9x**. 
+
+How to build
+
+
+Build LLVM/Clang with `CMake `_ and enable
+the ``compiler-rt`` runtime. An example CMake configuration that will allow
+for the use/testing of TypeSanitizer:
+
+.. code-block:: console
+
+   $ cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" 
-DLLVM_ENABLE_RUNTIMES="compiler-rt" /llvm
+
+Usage
+=
+
+Compile and link your program with ``-fsanitize=type`` flag.  The
+TypeSanitizer run-time library should be linked to the final executable, so
+make sure to use ``clang`` (not ``ld``) for the final link step. To
+get a reasonable performance add ``-O1`` or higher 
+(`This may currently lead to false-negatives 
`). 
+TypeSanitizer by default doesn't print the full stack trace on error messages. 
Use ``TYSAN_OPTIONS=print_stacktrace=1`` 
+to print the full trace. To get nicer stack traces in error messages add 
``-fno-omit-frame-pointer`` and 
+``-g``.  To get perfect stack traces you may need to disable inlining (just 
use ``-O1``) and tail call elimination 
+(``-fno-optimize-sibling-calls``).
+
+.. code-block:: console
+
+% cat example_AliasViolation.c
+int main(int argc, char **argv) {
+  int x = 100;
+  float *y = (float*)&x;
+  *y += 2.0f;  // Strict aliasing violation
+  return 0;
+}
+
+# Compile and link
+% clang++ -g -fsanitize=type example_AliasViolation.cc
+
+If a strict aliasing violation is detected, the program will print an error 
message to stderr. 
+The program won't terminate, which will allow you to detect many strict 
aliasing violations in one 
+run.
+
+.. code-block:: console
+% ./a.out
+==1375532==ERROR: TypeSanitizer: type-aliasing-violation on address 
0x7ffeebf1a72c (pc 0x5b3b1145ff41 bp 0x7ffeebf1a660 sp 0x7ffeebf19e08 tid 
1375532)
+READ of size 4 at 0x7ffeebf1a72c with type float accesses an existing 
object of type int
+#0 0x5b3b1145ff40 in main example_AliasViolation.c:4:10
+
+==1375532==ERROR: TypeSanitizer: type-aliasing-violation on address 
0x7ffeebf1a72c (pc 0x5b3b1146008a bp 0x7ffeebf1a660 sp 0x7ffeebf19e08 tid 
1375532)
+WRITE of size 4 at 0x7ffeebf1a72c with type float accesses an existing 
object of type int
+#0 0x5b3b11460089 in main example_AliasViolation.c:4:10
+
+Error terminology
+--
+
+There are some terms that may appear in TypeSanitizer errors that are derived 
from TBAA Metadata. This 
+section hopes to provide a brief dictionary of these terms.
+
+* ``omnipotent char``: This is a special type which can alias with anything. 
Its name comes from the C/C++ 
+  type ``char``.
+* ``type p[x]``: Sometimes a program could generate distinct TBAA metadata 
that resolve to the same name. 
+  To make them unique, they have the character 'p' and a number prepended to 
their name.
+
+These terms are a result of non-user-facing processes, and not always 
self-explanatory. There is some 
+interest in changing TypeSanitizer in the future to translate these terms 
before printing them to users.
+
+Sanitizer features
+==
+
+``__has_feature(type_sanitizer)``
+
+
+In some cases one may need to execute different code depending on whether
+TypeSanitizer is enabled.
+:ref:`\_\_has\_feature ` can be used for
+this purpose.
+
+.. code-block:: c
+
+#if defined(__has_feature)
+#  if __has_feature(type_sanitizer)
+// code that builds only under TypeSanitizer
+#  endif
+#endif
+
+``__attribute__((no_sanitize("type")))``
+---
+
+Some code you may not want to be instrumented by TypeSanitizer.  One may use 
the
+function attribute ``no_sanitize("type")`` to 

[clang] cad6bba - [C++20][Modules] Fix crash/compiler error due broken AST links (#123648)

2025-01-23 Thread via cfe-commits

Author: Dmitry Polukhin
Date: 2025-01-23T10:35:58Z
New Revision: cad6bbade0d7dc57b9c43d9ed8c38260345d50bf

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

LOG: [C++20][Modules] Fix crash/compiler error due broken AST links (#123648)

Summary:
This PR fixes bugreport
https://github.com/llvm/llvm-project/issues/122493 The root problem is
the same as before lambda function and DeclRefExpr references a variable
that does not belong to the same module as the enclosing function body.
Therefore iteration over the function body doesn’t visit the VarDecl.
Before this change RelatedDeclsMap was created only for canonical decl
but in reality it has to be done for the definition of the function that
does not always match the canonical decl.

Test Plan: check-clang

Added: 
clang/test/Headers/crash-instantiated-in-scope-cxx-modules5.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Serialization/ASTReader.h
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a03f42ab910edd..5989788132c92b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -975,6 +975,8 @@ Bug Fixes to C++ Support
 - Fixed a nested lambda substitution issue for constraint evaluation. 
(#GH123441)
 - Fixed various false diagnostics related to the use of immediate functions. 
(#GH123472)
 - Fix immediate escalation not propagating through inherited constructors.  
(#GH112677)
+- Fixed assertions or false compiler diagnostics in the case of C++ modules for
+  lambda functions or inline friend functions defined inside templates 
(#GH122493).
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 7530015c9dacf3..47301419c76c68 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -546,11 +546,18 @@ class ASTReader
 
   /// Mapping from main decl ID to the related decls IDs.
   ///
-  /// These related decls have to be loaded right after the main decl.
-  /// It is required to have canonical declaration for related decls from the
-  /// same module as the enclosing main decl. Without this, due to lazy
-  /// deserialization, canonical declarations for the main decl and related can
-  /// be selected from 
diff erent modules.
+  /// The key is the main decl ID, and the value is a vector of related decls
+  /// that must be loaded immediately after the main decl. This is necessary
+  /// to ensure that the definition for related decls comes from the same 
module
+  /// as the enclosing main decl. Without this, due to lazy deserialization,
+  /// the definition for the main decl and related decls may come from 
diff erent
+  /// modules. It is used for the following cases:
+  /// - Lambda inside a template function definition: The main declaration is
+  ///   the enclosing function, and the related declarations are the lambda
+  ///   declarations.
+  /// - Friend function defined inside a template CXXRecord declaration: The
+  ///   main declaration is the enclosing record, and the related declarations
+  ///   are the friend functions.
   llvm::DenseMap> RelatedDeclsMap;
 
   struct PendingUpdateRecord {

diff  --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index 54570dedb0b227..8b9ba04dce91c4 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -27,6 +27,20 @@
 using namespace clang;
 using namespace serialization;
 
+//===--===//
+// Utility functions
+//===--===//
+
+namespace {
+
+// Helper function that returns true if the decl passed in the argument is
+// a defintion in dependent contxt.
+template  bool isDefinitionInDependentContext(DT *D) {
+  return D->isDependentContext() && D->isThisDeclarationADefinition();
+}
+
+} // namespace
+
 
//===--===//
 // Declaration serialization
 
//===--===//
@@ -801,14 +815,14 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
   }
 
   if (D->getFriendObjectKind()) {
-// For a function defined inline within a class template, we have to force
-// the canonical definition to be the one inside the canonical definition 
of
-// the template. Remember this relation to deserialize them together.
-if (auto *RD = dyn_cast(D->getLexicalParent()))
-  if (RD->isDependentContext() && RD->isThisDeclarat

[clang] [llvm] [AArch64] Improve bcvtn2 and remove aarch64_neon_bfcvt intrinsics (PR #120363)

2025-01-23 Thread Sjoerd Meijer via cfe-commits

sjoerdmeijer wrote:

Forgot to add that a similar problems occur for another test in that same 
directory:  `vmulh_lane_f16_1.c`.


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


[clang] [TySan] Add initial documentation for Type Sanitizer (PR #123595)

2025-01-23 Thread via cfe-commits


@@ -0,0 +1,162 @@
+
+TypeSanitizer
+
+
+.. contents::
+   :local:
+
+Introduction
+
+
+The TypeSanitizer is a detector for strict type aliasing violations. It 
consists of a compiler
+instrumentation module and a run-time library. C/C++ has type-based aliasing 
rules, and LLVM 
+can exploit these for optimizations given the TBAA metadata Clang emits. In 
general, a pointer 
+of a given type cannot access an object of a different type, with only a few 
exceptions. 
+
+These rules aren't always apparent to users, which leads to code that violates 
these rules
+(e.g. for type punning). This can lead to optimization passes introducing bugs 
unless the 
+code is build with ``-fno-strict-aliasing``, sacrificing performance.
+
+TypeSanitizer is built to catch when these strict aliasing rules have been 
violated, helping 
+users find where such bugs originate in their code despite the code looking 
valid at first glance.
+
+As TypeSanitizer is still experimental, it can currently have a large impact 
on runtime speed, 
+memory use, and code size.
+
+How to build
+
+
+Build LLVM/Clang with `CMake `_ and enable
+the ``compiler-rt`` runtime. An example CMake configuration that will allow
+for the use/testing of TypeSanitizer:
+
+.. code-block:: console
+
+   $ cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" 
-DLLVM_ENABLE_RUNTIMES="compiler-rt" /llvm
+
+Usage
+=
+
+Compile and link your program with ``-fsanitize=type`` flag.  The

gbMattN wrote:

From a check, I think its mutually exclusive with all of them currently. I will 
put this in the **Limitations** section

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


[clang] [TySan] Add initial documentation for Type Sanitizer (PR #123595)

2025-01-23 Thread via cfe-commits

https://github.com/gbMattN updated 
https://github.com/llvm/llvm-project/pull/123595

>From 807c2c8be0517cbb1b9db890f48baeb6f226ba2f Mon Sep 17 00:00:00 2001
From: gbMattN 
Date: Mon, 20 Jan 2025 11:02:06 +
Subject: [PATCH 01/10] [TySan] Add initial documentation

---
 clang/docs/TypeSanitizer.rst | 152 +++
 1 file changed, 152 insertions(+)
 create mode 100644 clang/docs/TypeSanitizer.rst

diff --git a/clang/docs/TypeSanitizer.rst b/clang/docs/TypeSanitizer.rst
new file mode 100644
index 00..6b320f3bb1773d
--- /dev/null
+++ b/clang/docs/TypeSanitizer.rst
@@ -0,0 +1,152 @@
+
+TypeSanitizer
+
+
+.. contents::
+   :local:
+
+Introduction
+
+
+TypeSanitizer is a detector for strict type aliasing violations. It consists 
of a compiler
+instrumentation module and a run-time library. The tool detects violations 
such as the use 
+of an illegally cast pointer, or misuse of a union.
+
+The violations TypeSanitizer catches may cause the compiler to emit incorrect 
code.
+
+Typical slowdown introduced by TypeSanitizer is about **4x** [[CHECK THIS]]. 
Typical memory overhead introduced by TypeSanitizer is about **9x**. 
+
+How to build
+
+
+Build LLVM/Clang with `CMake `_ and enable
+the ``compiler-rt`` runtime. An example CMake configuration that will allow
+for the use/testing of TypeSanitizer:
+
+.. code-block:: console
+
+   $ cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" 
-DLLVM_ENABLE_RUNTIMES="compiler-rt" /llvm
+
+Usage
+=
+
+Compile and link your program with ``-fsanitize=type`` flag.  The
+TypeSanitizer run-time library should be linked to the final executable, so
+make sure to use ``clang`` (not ``ld``) for the final link step. To
+get a reasonable performance add ``-O1`` or higher 
+(`This may currently lead to false-negatives 
`). 
+TypeSanitizer by default doesn't print the full stack trace on error messages. 
Use ``TYSAN_OPTIONS=print_stacktrace=1`` 
+to print the full trace. To get nicer stack traces in error messages add 
``-fno-omit-frame-pointer`` and 
+``-g``.  To get perfect stack traces you may need to disable inlining (just 
use ``-O1``) and tail call elimination 
+(``-fno-optimize-sibling-calls``).
+
+.. code-block:: console
+
+% cat example_AliasViolation.c
+int main(int argc, char **argv) {
+  int x = 100;
+  float *y = (float*)&x;
+  *y += 2.0f;  // Strict aliasing violation
+  return 0;
+}
+
+# Compile and link
+% clang++ -g -fsanitize=type example_AliasViolation.cc
+
+If a strict aliasing violation is detected, the program will print an error 
message to stderr. 
+The program won't terminate, which will allow you to detect many strict 
aliasing violations in one 
+run.
+
+.. code-block:: console
+% ./a.out
+==1375532==ERROR: TypeSanitizer: type-aliasing-violation on address 
0x7ffeebf1a72c (pc 0x5b3b1145ff41 bp 0x7ffeebf1a660 sp 0x7ffeebf19e08 tid 
1375532)
+READ of size 4 at 0x7ffeebf1a72c with type float accesses an existing 
object of type int
+#0 0x5b3b1145ff40 in main example_AliasViolation.c:4:10
+
+==1375532==ERROR: TypeSanitizer: type-aliasing-violation on address 
0x7ffeebf1a72c (pc 0x5b3b1146008a bp 0x7ffeebf1a660 sp 0x7ffeebf19e08 tid 
1375532)
+WRITE of size 4 at 0x7ffeebf1a72c with type float accesses an existing 
object of type int
+#0 0x5b3b11460089 in main example_AliasViolation.c:4:10
+
+Error terminology
+--
+
+There are some terms that may appear in TypeSanitizer errors that are derived 
from TBAA Metadata. This 
+section hopes to provide a brief dictionary of these terms.
+
+* ``omnipotent char``: This is a special type which can alias with anything. 
Its name comes from the C/C++ 
+  type ``char``.
+* ``type p[x]``: Sometimes a program could generate distinct TBAA metadata 
that resolve to the same name. 
+  To make them unique, they have the character 'p' and a number prepended to 
their name.
+
+These terms are a result of non-user-facing processes, and not always 
self-explanatory. There is some 
+interest in changing TypeSanitizer in the future to translate these terms 
before printing them to users.
+
+Sanitizer features
+==
+
+``__has_feature(type_sanitizer)``
+
+
+In some cases one may need to execute different code depending on whether
+TypeSanitizer is enabled.
+:ref:`\_\_has\_feature ` can be used for
+this purpose.
+
+.. code-block:: c
+
+#if defined(__has_feature)
+#  if __has_feature(type_sanitizer)
+// code that builds only under TypeSanitizer
+#  endif
+#endif
+
+``__attribute__((no_sanitize("type")))``
+---
+
+Some code you may not want to be instrumented by TypeSanitizer.  One may use 
the
+function attribute ``no_sanitize("type")`` t

[clang] [llvm] [AArch64] Improve bcvtn2 and remove aarch64_neon_bfcvt intrinsics (PR #120363)

2025-01-23 Thread David Green via cfe-commits

davemgreen wrote:

Hi - that sounds like GISel might be miss-compiling it? It doesn't support 
bf16, so shouldn't be trying to use those instructions for fp16. I can try and 
take a look.

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


[libcxx] [libcxxabi] [libunwind] [llvm] [libc++] Enable -Wmissing-prototypes (PR #116261)

2025-01-23 Thread Nikolas Klauser via cfe-commits

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

>From 60f615f419e09714316678e465c4479bedb88506 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 14 Nov 2024 18:30:39 +0100
Subject: [PATCH] [libc++] Enable -Wmissing-prototypes

---
 libcxx/include/fstream | 2 +-
 libcxx/src/charconv.cpp| 5 -
 libcxx/src/experimental/time_zone.cpp  | 2 +-
 libcxx/src/experimental/tzdb.cpp   | 3 +++
 libcxx/src/filesystem/int128_builtins.cpp  | 2 ++
 libcxx/src/include/from_chars_floating_point.h | 4 ++--
 libcxxabi/src/cxa_personality.cpp  | 5 +
 libcxxabi/src/private_typeinfo.cpp | 6 ++
 libunwind/src/UnwindLevel1.c   | 1 -
 libunwind/src/libunwind_ext.h  | 1 +
 runtimes/cmake/Modules/WarningFlags.cmake  | 1 +
 11 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index f0e9425e0a53d9..4c126e724507af 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -226,7 +226,7 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_WIN32API)
+#if _LIBCPP_STD_VER >= 23 && defined(_LIBCPP_WIN32API)
 _LIBCPP_EXPORTED_FROM_ABI void* __filebuf_windows_native_handle(FILE* __file) 
noexcept;
 #endif
 
diff --git a/libcxx/src/charconv.cpp b/libcxx/src/charconv.cpp
index 5e8cb7d97703b4..4621df05066997 100644
--- a/libcxx/src/charconv.cpp
+++ b/libcxx/src/charconv.cpp
@@ -18,9 +18,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace __itoa {
 
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-prototypes")
+// These functions exist for ABI compatibility, so we don't ever want a 
declaration.
 _LIBCPP_EXPORTED_FROM_ABI char* __u32toa(uint32_t value, char* buffer) 
noexcept { return __base_10_u32(buffer, value); }
-
 _LIBCPP_EXPORTED_FROM_ABI char* __u64toa(uint64_t value, char* buffer) 
noexcept { return __base_10_u64(buffer, value); }
+_LIBCPP_DIAGNOSTIC_POP
 
 } // namespace __itoa
 
diff --git a/libcxx/src/experimental/time_zone.cpp 
b/libcxx/src/experimental/time_zone.cpp
index 764a89ab513c86..c5ba94321e07ce 100644
--- a/libcxx/src/experimental/time_zone.cpp
+++ b/libcxx/src/experimental/time_zone.cpp
@@ -711,7 +711,7 @@ __get_sys_info(sys_seconds __time,
 // Iff the "offsets" are the same '__current.__end' is replaced with
 // '__next.__end', which effectively merges the two objects in one object. The
 // function returns true if a merge occurred.
-[[nodiscard]] bool __merge_continuation(sys_info& __current, const sys_info& 
__next) {
+[[nodiscard]] static bool __merge_continuation(sys_info& __current, const 
sys_info& __next) {
   if (__current.end != __next.begin)
 return false;
 
diff --git a/libcxx/src/experimental/tzdb.cpp b/libcxx/src/experimental/tzdb.cpp
index f38f495c2d0bbe..a3861894a045d6 100644
--- a/libcxx/src/experimental/tzdb.cpp
+++ b/libcxx/src/experimental/tzdb.cpp
@@ -49,6 +49,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace chrono {
 
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-prototypes")
 // This function is weak so it can be overriden in the tests. The
 // declaration is in the test header test/support/test_tzdb.h
 _LIBCPP_WEAK string_view __libcpp_tzdb_directory() {
@@ -58,6 +60,7 @@ _LIBCPP_WEAK string_view __libcpp_tzdb_directory() {
 #  error "unknown path to the IANA Time Zone Database"
 #endif
 }
+_LIBCPP_DIAGNOSTIC_POP
 
 
//===--===//
 //   Details
diff --git a/libcxx/src/filesystem/int128_builtins.cpp 
b/libcxx/src/filesystem/int128_builtins.cpp
index da6f39e7d78b60..e811b3e6f912db 100644
--- a/libcxx/src/filesystem/int128_builtins.cpp
+++ b/libcxx/src/filesystem/int128_builtins.cpp
@@ -16,6 +16,8 @@
 #include <__config>
 #include 
 
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-prototypes") // See the FIXME above
+
 #if _LIBCPP_HAS_INT128
 
 extern "C" __attribute__((no_sanitize("undefined"))) _LIBCPP_EXPORTED_FROM_ABI 
__int128_t
diff --git a/libcxx/src/include/from_chars_floating_point.h 
b/libcxx/src/include/from_chars_floating_point.h
index 19eeeb28fb08d2..81d2180cc94805 100644
--- a/libcxx/src/include/from_chars_floating_point.h
+++ b/libcxx/src/include/from_chars_floating_point.h
@@ -193,7 +193,7 @@ struct __exponent_result {
 // __offset, 0, false. This allows using the results unconditionally, the
 // __present is important for the scientific notation, where the value is
 // mandatory.
-__exponent_result __parse_exponent(const char* __input, size_t __n, size_t 
__offset, char __marker) {
+static __exponent_result __parse_exponent(const char* __input, size_t __n, 
size_t __offset, char __marker) {
   if (__offset + 1 < __n &&  // an exponent always 
needs at least one digit.
   std::tolower(__input[__offset]) == __marker && 

[clang] [Driver] -fno-plt: warn for unsupported targets (PR #124081)

2025-01-23 Thread Martin Storsjö via cfe-commits

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


[clang] [Driver][ASan] Refactor Clang-Driver "Sanitizer Bitcode" linking. (PR #123922)

2025-01-23 Thread Amit Kumar Pandey via cfe-commits

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


[clang] [clang][Modules] Raise empty.modulemap expected size to <70KB to fix RISC-V failure (PR #123959)

2025-01-23 Thread Alex Bradbury via cfe-commits

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


[clang] 1930635 - [clang][Modules] Raise empty.modulemap expected size to <70KB to fix RISC-V failure (#123959)

2025-01-23 Thread via cfe-commits

Author: Alex Bradbury
Date: 2025-01-23T10:22:07Z
New Revision: 19306351a2c45e266fa11b41eb1362b20b6ca56d

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

LOG: [clang][Modules] Raise empty.modulemap expected size to <70KB to fix 
RISC-V failure (#123959)

I'm not sure why the test is larger for RISC-V than other targets, but
we saw this before with #111360.

The file is just over the current 60KB limit:

```
62772 
/home/asb/llvm-project/build/stage2/tools/clang/test/Modules/Output/empty.modulemap.tmp/base.pcm
```

Added: 


Modified: 
clang/test/Modules/empty.modulemap

Removed: 




diff  --git a/clang/test/Modules/empty.modulemap 
b/clang/test/Modules/empty.modulemap
index f2d37c19d77bcc..8cad8b67b91155 100644
--- a/clang/test/Modules/empty.modulemap
+++ b/clang/test/Modules/empty.modulemap
@@ -13,8 +13,8 @@
 // The module file should be identical each time we produce it.
 // RUN: 
diff  %t/base.pcm %t/check.pcm
 //
-// We expect an empty module to be less than 60KB (and at least 10K, for now).
+// We expect an empty module to be less than 70KB (and at least 10K, for now).
 // RUN: wc -c %t/base.pcm | FileCheck --check-prefix=CHECK-SIZE %s
-// CHECK-SIZE: {{(^|[^0-9])[1-5][0-9][0-9][0-9][0-9]($|[^0-9])}}
+// CHECK-SIZE: {{(^|[^0-9])[1-6][0-9][0-9][0-9][0-9]($|[^0-9])}}
 
 module empty { header "Inputs/empty.h" export * }



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


[clang] [clang][Modules] Raise empty.modulemap expected size to <70KB to fix RISC-V failure (PR #123959)

2025-01-23 Thread Alex Bradbury via cfe-commits

asb wrote:

Thanks, I've gone ahead an merged. Any insight into why the module files may be 
larger on RISC-V vs other targets greatly appreciated - as I said in 
https://github.com/llvm/llvm-project/pull/111360 I'm not sure how to best 
inspect the module files.

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


[libclc] [libclc] Move nextafter to the CLC library (PR #124097)

2025-01-23 Thread Matt Arsenault via cfe-commits

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


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


[clang] [Clang] Add -fwrapv-pointer flag (PR #122486)

2025-01-23 Thread Nikita Popov via cfe-commits

https://github.com/nikic updated 
https://github.com/llvm/llvm-project/pull/122486

>From 925f74cad21eb6c46514d1ae543ac202073baf27 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Fri, 10 Jan 2025 17:01:07 +0100
Subject: [PATCH] [Clang] Add -fwrapv-pointer flag

GCC supports three flags related to overflow behavior:
 * `-fwrapv`: Makes signed integer overflow well-defined.
 * `-fwrapv-pointer`: Makes pointer overflow well-defined.
 * `-fno-strict-overflow`: Implies `-fwrapv -fwrapv-pointer`,
   making both signed integer overflow and pointer overflow
   well-defined.

Clang currently only supports `-fno-strict-overflow` and `-fwrapv`,
but not `-fwrapv-pointer`.

This PR proposes to introduce `-fwrapv-pointer` and adjust the
semantics of `-fwrapv` to match GCC.

This allows signed integer overflow and pointer overflow to be
controlled independently, while `-fno-strict-overflow` still
exists to control both at the same time (and that option is
consistent across GCC and Clang).
---
 clang/docs/ReleaseNotes.rst   | 15 ++-
 clang/include/clang/Basic/LangOptions.def |  1 +
 clang/include/clang/Driver/Options.td |  5 
 clang/lib/CodeGen/CGBuiltin.cpp   |  2 +-
 clang/lib/CodeGen/CGExpr.cpp  | 27 +--
 clang/lib/CodeGen/CGExprScalar.cpp| 12 -
 clang/lib/Driver/SanitizerArgs.cpp|  3 +++
 clang/lib/Driver/ToolChains/CommonArgs.cpp| 15 ---
 clang/lib/Frontend/CompilerInvocation.cpp |  4 +++
 clang/lib/Sema/SemaExpr.cpp   |  2 +-
 clang/test/CodeGen/integer-overflow.c | 13 ++---
 clang/test/CodeGen/pointer-overflow.c | 12 +
 clang/test/Driver/clang_wrapv_opts.c  | 15 ++-
 .../Sema/tautological-pointer-comparison.c|  2 +-
 14 files changed, 88 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/CodeGen/pointer-overflow.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cad17c1b3957b6..12b2893b1eb824 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -79,7 +79,15 @@ code bases.
   Undefined behavior due to pointer addition overflow can be reliably detected
   using ``-fsanitize=pointer-overflow``. It is also possible to use
   ``-fno-strict-overflow`` to opt-in to a language dialect where signed integer
-  and pointer overflow are well-defined.
+  and pointer overflow are well-defined. Since Clang 20, it is also possible
+  to use ``-fwrapv-pointer`` to only make pointer overflow well-defined, while
+  not affecting the behavior of signed integer overflow.
+
+- The ``-fwrapv`` flag now only makes signed integer overflow well-defined,
+  without affecting pointer overflow, which is controlled by a new
+  ``-fwrapv-pointer`` flag. The ``-fno-strict-overflow`` flag now implies
+  both ``-fwrapv`` and ``-fwrapv-pointer`` and as such retains its old meaning.
+  The new behavior matches GCC.
 
 C/C++ Language Potentially Breaking Changes
 ---
@@ -500,6 +508,11 @@ New Compiler Flags
 - clang-cl and clang-dxc now support 
``-fdiagnostics-color=[auto|never|always]``
   in addition to ``-f[no-]color-diagnostics``.
 
+- The new ``-fwrapv-pointer`` flag opts-in to a language dialect where pointer
+  overflow is well-defined. The ``-fwrapv`` flag previously implied
+  ``-fwrapv-pointer`` as well, but no longer does. ``-fno-strict-overflow``
+  implies ``-fwrapv -fwrapv-pointer``. The flags now match GCC.
+
 Deprecated Compiler Flags
 -
 
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index a980be853d53e6..1bcec212fd332e 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -407,6 +407,7 @@ VALUE_LANGOPT(TrivialAutoVarInitMaxSize, 32, 0,
  "stop trivial automatic variable initialization if var size 
exceeds the specified size (in bytes). Must be greater than 0.")
 ENUM_LANGOPT(SignedOverflowBehavior, SignedOverflowBehaviorTy, 2, 
SOB_Undefined,
  "signed integer overflow handling")
+LANGOPT(PointerOverflowDefined, 1, 0, "make pointer overflow defined")
 ENUM_LANGOPT(ThreadModel  , ThreadModelKind, 2, ThreadModelKind::POSIX, 
"Thread Model")
 
 BENIGN_LANGOPT(ArrowDepth, 32, 256,
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 852051e772fc1c..820ed088029f8c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4299,6 +4299,11 @@ def fwrapv : Flag<["-"], "fwrapv">, Group,
   HelpText<"Treat signed integer overflow as two's complement">;
 def fno_wrapv : Flag<["-"], "fno-wrapv">, Group,
   Visibility<[ClangOption, CLOption, FlangOption]>;
+def fwrapv_pointer : Flag<["-"], "fwrapv-pointer">, Group,
+  Visibility<[ClangOption, CLOption, CC1Option, FlangOption, FC1Option]>,
+  HelpText<"Treat point

[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator moveBefore at many call-sites (PR #123583)

2025-01-23 Thread Jeremy Morse via cfe-commits


@@ -448,7 +448,7 @@ void IRPromoter::ExtendSources() {
   if (isa(V))
 I->moveBefore(InsertPt);
   else
-I->moveAfter(InsertPt);
+I->moveAfter(&*InsertPt);

jmorse wrote:

Good question on this and the other item; I think the most important fact is 
that inserting _after_ an instruction never introduces a problem with head-bits 
and debug records, because it's always "in front" of any debug records. As a 
result, it's not necessary to update moveAfter before stripping out 
intrinsic-support from LLVM (if we get there) so I haven't focused on this.

We could technically update moveAfter to use iterators (which has the benefit 
of uniformity); I suppose it's a transition matter because I'm not planning on 
doing it immediately.

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


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-23 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/123667

>From 00b8b64879ad3ae35a0a671da563ac876ffaf228 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 20 Jan 2025 22:51:00 +0200
Subject: [PATCH 1/2] [Clang] use constant evaluation context for constexpr if
 conditions

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp|  6 ++
 clang/test/SemaCXX/constexpr-if.cpp | 10 ++
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/constexpr-if.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6d5c346021d60..cd16ce13a4e6b6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,7 +963,7 @@ Bug Fixes to C++ Support
 - Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
   constraints are applied. (#GH122134)
 - Fixed canonicalization of pack indexing types - Clang did not always 
recognized identical pack indexing. (#GH123033)
-
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 33a90e0cb8a42a..e174d9a24e7440 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
new file mode 100644
index 00..1832086fee42d4
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s
+
+// expected-no-diagnostics
+
+namespace GH123524 {
+consteval void fn1() {}
+void fn2() {
+  if constexpr (&fn1 != nullptr) { }
+}
+}

>From df6fd0c3f762d5fb76bdf98c6425a79ef01f4d7e Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 21 Jan 2025 10:27:57 +0200
Subject: [PATCH 2/2] update tests to verify changes from c++20

---
 clang/test/SemaCXX/constexpr-if.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
index 1832086fee42d4..494fc45c55c4e0 100644
--- a/clang/test/SemaCXX/constexpr-if.cpp
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -std=c++26 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
+// RUN: %clang_cc1 -std=c++23 -verify=cxx23,expected %s
+// RUN: %clang_cc1 -std=c++26 -verify=cxx26,expected %s
 
 // expected-no-diagnostics
 

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


[clang] [llvm] [AArch64] Improve bcvtn2 and remove aarch64_neon_bfcvt intrinsics (PR #120363)

2025-01-23 Thread Sjoerd Meijer via cfe-commits

sjoerdmeijer wrote:

Hey @davemgreen, we are looking at a runtime failure in a test from the GCC 
test-suite: 
`./testsuite/gcc.target/aarch64/advsimd-intrinsics/vfmash_lane_f16_1.c`

I think to reproduce this, this will work:

   clang vfmash_lane_f16_1.c -mcpu=neoverse-v2 -O0 -lm -o 
./vfmash_lane_f16_1.exe

and

$ ./vfmash_lane_f16_1.exe
 Aborted

Seems to be fine when compiled with -O1 and up.

There are some scary compiler warning messages, e.g.:

  ./arm-neon-ref.h:335:41: warning: value size does not match register size 
specified by the constraint and modifier [-Wasm-operand-widths]  

But haven't looked yet if this important, also haven't looked at the root cause 
yet.

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


[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)

2025-01-23 Thread Nikolaos Chatzikonstantinou via cfe-commits

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


[libclc] 9705500 - [libclc] Move nextafter to the CLC library (#124097)

2025-01-23 Thread via cfe-commits

Author: Fraser Cormack
Date: 2025-01-23T12:24:16Z
New Revision: 9705500582b9c2b2e1dd6de14f03a94d270a9250

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

LOG: [libclc] Move nextafter to the CLC library (#124097)

There were two implementations of this - one that implemented nextafter
in software, and another that called a clang builtin. No in-tree targets
called the builtin, so all targets build the software version. The
builtin version has been removed, and the software version has been
renamed to be the "default".

This commit also optimizes nextafter, to avoid scalarization as much as
possible. Note however that the (CLC) relational builtins still
scalarize; those will be optimized in a separate commit.

Since nextafter is used by some convert_type builtins, the diff to IR
codegen is not limited to the builtin itself.

Added: 
libclc/clc/include/clc/math/binary_decl_with_scalar_second_arg.inc
libclc/clc/include/clc/math/clc_nextafter.h
libclc/clc/include/clc/shared/binary_decl.inc
libclc/clc/lib/generic/math/clc_nextafter.cl

Modified: 
libclc/amdgpu/lib/SOURCES
libclc/clc/include/clc/clcmacro.h
libclc/clc/include/clc/relational/clc_isnan.h
libclc/clc/lib/clspv/SOURCES
libclc/clc/lib/generic/SOURCES
libclc/clc/lib/spirv/SOURCES
libclc/clc/lib/spirv64/SOURCES
libclc/clspv/lib/SOURCES
libclc/generic/include/clc/math/fmax.h
libclc/generic/include/clc/math/fmin.h
libclc/generic/lib/SOURCES
libclc/generic/lib/math/nextafter.cl

Removed: 
libclc/amdgpu/lib/math/nextafter.cl
libclc/clspv/lib/math/nextafter.cl
libclc/clspv/lib/math/nextafter.inc
libclc/generic/include/clc/math/binary_decl.inc
libclc/generic/include/math/clc_nextafter.h
libclc/generic/lib/math/clc_nextafter.cl
libclc/ptx/lib/SOURCES
libclc/ptx/lib/math/nextafter.cl



diff  --git a/libclc/amdgpu/lib/SOURCES b/libclc/amdgpu/lib/SOURCES
index b11cbdecf27b9d..24f099d049cd34 100644
--- a/libclc/amdgpu/lib/SOURCES
+++ b/libclc/amdgpu/lib/SOURCES
@@ -10,5 +10,4 @@ math/half_log2.cl
 math/half_recip.cl
 math/half_rsqrt.cl
 math/half_sqrt.cl
-math/nextafter.cl
 math/sqrt.cl

diff  --git a/libclc/amdgpu/lib/math/nextafter.cl 
b/libclc/amdgpu/lib/math/nextafter.cl
deleted file mode 100644
index 6dc117b8cdd64c..00
--- a/libclc/amdgpu/lib/math/nextafter.cl
+++ /dev/null
@@ -1,15 +0,0 @@
-#include 
-#include 
-#include 
-
-_CLC_DEFINE_BINARY_BUILTIN(float, nextafter, __clc_nextafter, float, float)
-
-#ifdef cl_khr_fp64
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-_CLC_DEFINE_BINARY_BUILTIN(double, nextafter, __clc_nextafter, double, double)
-#endif
-
-#ifdef cl_khr_fp16
-#pragma OPENCL EXTENSION cl_khr_fp16 : enable
-_CLC_DEFINE_BINARY_BUILTIN(half, nextafter, __clc_nextafter, half, half)
-#endif

diff  --git a/libclc/clc/include/clc/clcmacro.h 
b/libclc/clc/include/clc/clcmacro.h
index 676560e9efcb44..14399811bad938 100644
--- a/libclc/clc/include/clc/clcmacro.h
+++ b/libclc/clc/include/clc/clcmacro.h
@@ -159,6 +159,34 @@
   _CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, RET_TYPE, FUNCTION, ARG1_TYPE, 
\
 ARG2_TYPE)
 
+// FIXME: Make _CLC_DEFINE_BINARY_BUILTIN avoid scalarization by default, and
+// introduce an explicit scalarizing version.
+#define _CLC_DEFINE_BINARY_BUILTIN_NO_SCALARIZE(RET_TYPE, FUNCTION, BUILTIN,   
\
+ARG1_TYPE, ARG2_TYPE)  
\
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE FUNCTION(ARG1_TYPE x, ARG2_TYPE y) { 
\
+return BUILTIN(x, y);  
\
+  }
\
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE##2 FUNCTION(ARG1_TYPE##2 x,  
\
+  ARG2_TYPE##2 y) {
\
+return BUILTIN(x, y);  
\
+  }
\
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE##3 FUNCTION(ARG1_TYPE##3 x,  
\
+  ARG2_TYPE##3 y) {
\
+return BUILTIN(x, y);  
\
+  }
\
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE##4 FUNCTION(ARG1_TYPE##4 x,  
\
+  ARG2_TYPE##4 y) {
\
+return BUILTIN(x, y);  
\
+  }
\
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE##8 FUNCTION(ARG1_TYPE##8 x,  
\
+

[libclc] [libclc] Move nextafter to the CLC library (PR #124097)

2025-01-23 Thread Fraser Cormack via cfe-commits

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


[clang] [flang] [flang][driver] add negative from of -fsave-main-program (PR #124110)

2025-01-23 Thread via cfe-commits

https://github.com/jeanPerier created 
https://github.com/llvm/llvm-project/pull/124110

Add the `-fno` form for consistency and to make it easy to switch the default 
for downstream users.

>From 28dba56b12b45f8ce82426e2b79165352f549850 Mon Sep 17 00:00:00 2001
From: Jean Perier 
Date: Thu, 23 Jan 2025 04:37:30 -0800
Subject: [PATCH] [flang][driver] add negative from of -fsave-main-program

---
 clang/include/clang/Driver/Options.td | 4 ++--
 clang/lib/Driver/ToolChains/Flang.cpp | 3 ++-
 flang/lib/Frontend/CompilerInvocation.cpp | 9 +
 flang/test/Driver/fsave-main-program.f90  | 6 +-
 flang/test/Lower/fsave-main-program.f90   | 1 +
 5 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index df705104d9ea31..6fface303c57a6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6968,8 +6968,8 @@ defm unsigned : OptInFC1FFlag<"unsigned", "Enables 
UNSIGNED type">;
 def fno_automatic : Flag<["-"], "fno-automatic">, Group,
   HelpText<"Implies the SAVE attribute for non-automatic local objects in 
subprograms unless RECURSIVE">;
 
-def fsave_main_program : Flag<["-"], "fsave-main-program">, Group,
-  HelpText<"Place all variables from the main program in static memory 
(otherwise scalars may be placed on the stack)">;
+defm save_main_program : OptInFC1FFlag<"save-main-program",
+  "Place all variables from the main program in static memory (otherwise 
scalars may be placed on the stack)">;
 
 defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays",
   PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 9c1fd28a3a8a26..8d1ec016325dfb 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -58,7 +58,8 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
 options::OPT_fhermetic_module_files,
 options::OPT_frealloc_lhs,
 options::OPT_fno_realloc_lhs,
-options::OPT_fsave_main_program});
+options::OPT_fsave_main_program,
+options::OPT_fno_save_main_program});
 }
 
 void Flang::addPreprocessingOptions(const ArgList &Args,
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 3c6da4687f65d3..68b5950d3a51b7 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -770,10 +770,11 @@ static bool parseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
 opts.features.Enable(Fortran::common::LanguageFeature::DefaultSave);
   }
 
-  // -fsave-main-program
-  if (args.hasArg(clang::driver::options::OPT_fsave_main_program)) {
-opts.features.Enable(Fortran::common::LanguageFeature::SaveMainProgram);
-  }
+  // -f{no}-save-main-program
+  opts.features.Enable(
+  Fortran::common::LanguageFeature::SaveMainProgram,
+  args.hasFlag(clang::driver::options::OPT_fsave_main_program,
+   clang::driver::options::OPT_fno_save_main_program, false));
 
   if (args.hasArg(
   clang::driver::options::OPT_falternative_parameter_statement)) {
diff --git a/flang/test/Driver/fsave-main-program.f90 
b/flang/test/Driver/fsave-main-program.f90
index bffdfd97911e80..e7a2f9d8b470ed 100644
--- a/flang/test/Driver/fsave-main-program.f90
+++ b/flang/test/Driver/fsave-main-program.f90
@@ -1,5 +1,9 @@
 ! Check that the driver passes through -fsave-main-program:
 ! RUN: %flang -### -S -fsave-main-program %s -o - 2>&1 | FileCheck %s
+! CHECK: "-fc1"{{.*}}"-fsave-main-program"
+
+! RUN: %flang -### -S -fno-save-main-program %s -o - 2>&1 | FileCheck %s 
--check-prefix=CHECK2
+! CHECK2: "-fc1"{{.*}}"-fno-save-main-program"
+
 ! Check that the compiler accepts -fsave-main-program:
 ! RUN: %flang_fc1 -emit-hlfir -fsave-main-program %s -o -
-! CHECK: "-fc1"{{.*}}"-fsave-main-program"
diff --git a/flang/test/Lower/fsave-main-program.f90 
b/flang/test/Lower/fsave-main-program.f90
index 17fc1b02f5068f..e89244c3c7c51a 100644
--- a/flang/test/Lower/fsave-main-program.f90
+++ b/flang/test/Lower/fsave-main-program.f90
@@ -1,6 +1,7 @@
 ! Test -fsave-main-program switch.
 ! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-DEFAULT 
%s
 ! RUN: %flang_fc1 -fsave-main-program -emit-hlfir -o - %s | FileCheck 
--check-prefix=CHECK-SAVE %s
+! RUN: %flang_fc1 -fsave-main-program -fno-save-main-program -emit-hlfir -o - 
%s | FileCheck --check-prefix=CHECK-DEFAULT %s
 program test
 integer :: i
 call foo(i)

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


[clang] [flang] [flang][driver] add negative from of -fsave-main-program (PR #124110)

2025-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-driver

Author: None (jeanPerier)


Changes

Add the `-fno` form for consistency and to make it easy to switch the default 
for downstream users.

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


5 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+2-2) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2-1) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+5-4) 
- (modified) flang/test/Driver/fsave-main-program.f90 (+5-1) 
- (modified) flang/test/Lower/fsave-main-program.f90 (+1) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index df705104d9ea31..6fface303c57a6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6968,8 +6968,8 @@ defm unsigned : OptInFC1FFlag<"unsigned", "Enables 
UNSIGNED type">;
 def fno_automatic : Flag<["-"], "fno-automatic">, Group,
   HelpText<"Implies the SAVE attribute for non-automatic local objects in 
subprograms unless RECURSIVE">;
 
-def fsave_main_program : Flag<["-"], "fsave-main-program">, Group,
-  HelpText<"Place all variables from the main program in static memory 
(otherwise scalars may be placed on the stack)">;
+defm save_main_program : OptInFC1FFlag<"save-main-program",
+  "Place all variables from the main program in static memory (otherwise 
scalars may be placed on the stack)">;
 
 defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays",
   PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 9c1fd28a3a8a26..8d1ec016325dfb 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -58,7 +58,8 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
 options::OPT_fhermetic_module_files,
 options::OPT_frealloc_lhs,
 options::OPT_fno_realloc_lhs,
-options::OPT_fsave_main_program});
+options::OPT_fsave_main_program,
+options::OPT_fno_save_main_program});
 }
 
 void Flang::addPreprocessingOptions(const ArgList &Args,
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 3c6da4687f65d3..68b5950d3a51b7 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -770,10 +770,11 @@ static bool parseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
 opts.features.Enable(Fortran::common::LanguageFeature::DefaultSave);
   }
 
-  // -fsave-main-program
-  if (args.hasArg(clang::driver::options::OPT_fsave_main_program)) {
-opts.features.Enable(Fortran::common::LanguageFeature::SaveMainProgram);
-  }
+  // -f{no}-save-main-program
+  opts.features.Enable(
+  Fortran::common::LanguageFeature::SaveMainProgram,
+  args.hasFlag(clang::driver::options::OPT_fsave_main_program,
+   clang::driver::options::OPT_fno_save_main_program, false));
 
   if (args.hasArg(
   clang::driver::options::OPT_falternative_parameter_statement)) {
diff --git a/flang/test/Driver/fsave-main-program.f90 
b/flang/test/Driver/fsave-main-program.f90
index bffdfd97911e80..e7a2f9d8b470ed 100644
--- a/flang/test/Driver/fsave-main-program.f90
+++ b/flang/test/Driver/fsave-main-program.f90
@@ -1,5 +1,9 @@
 ! Check that the driver passes through -fsave-main-program:
 ! RUN: %flang -### -S -fsave-main-program %s -o - 2>&1 | FileCheck %s
+! CHECK: "-fc1"{{.*}}"-fsave-main-program"
+
+! RUN: %flang -### -S -fno-save-main-program %s -o - 2>&1 | FileCheck %s 
--check-prefix=CHECK2
+! CHECK2: "-fc1"{{.*}}"-fno-save-main-program"
+
 ! Check that the compiler accepts -fsave-main-program:
 ! RUN: %flang_fc1 -emit-hlfir -fsave-main-program %s -o -
-! CHECK: "-fc1"{{.*}}"-fsave-main-program"
diff --git a/flang/test/Lower/fsave-main-program.f90 
b/flang/test/Lower/fsave-main-program.f90
index 17fc1b02f5068f..e89244c3c7c51a 100644
--- a/flang/test/Lower/fsave-main-program.f90
+++ b/flang/test/Lower/fsave-main-program.f90
@@ -1,6 +1,7 @@
 ! Test -fsave-main-program switch.
 ! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-DEFAULT 
%s
 ! RUN: %flang_fc1 -fsave-main-program -emit-hlfir -o - %s | FileCheck 
--check-prefix=CHECK-SAVE %s
+! RUN: %flang_fc1 -fsave-main-program -fno-save-main-program -emit-hlfir -o - 
%s | FileCheck --check-prefix=CHECK-DEFAULT %s
 program test
 integer :: i
 call foo(i)

``




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


[clang] [Clang] Add -fwrapv-pointer flag (PR #122486)

2025-01-23 Thread Carlo Cabrera via cfe-commits

carlocab wrote:

> Matching gcc's behavior for -f flags both compilers have also makes sense, 
> IMHO.

Agree with this, FWIW.

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


[clang] [clang-format] Fix a regression in `PointerAlignment: Left` (PR #124085)

2025-01-23 Thread via cfe-commits

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

LGTM

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


[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)

2025-01-23 Thread via cfe-commits

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

This seems reasonable to me, but wait for the others, maybe @owenca 

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


[clang] [z/OS] Add option to target older versions of LE on z/OS (PR #123399)

2025-01-23 Thread Abhina Sree via cfe-commits


@@ -277,6 +277,11 @@ def err_cpu_unsupported_isa
 def err_arch_unsupported_isa
   : Error<"architecture '%0' does not support '%1' execution mode">;
 
+def err_zos_target_release_discontinued
+  : Error<"z/OS target level \"%0\" is discontinued.  Unexpected behavior 
might occur if an out-of-support target level is specified.  Use z/OS target 
level \"zOSv2r4\", or later instead">;

abhina-sree wrote:

minor nit: these lines are very long and could be broken up to multiple lines

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


[clang] [flang] [flang] Add -f[no-]vectorize flags (PR #119718)

2025-01-23 Thread Tarun Prabhu via cfe-commits

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

Please move code to be shared between `clang` and `flang` to 
`clang/lib/Driver/ToolChains/CommonArgs.cpp`

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


[clang] [z/OS] Add option to target older versions of LE on z/OS (PR #123399)

2025-01-23 Thread Abhina Sree via cfe-commits

https://github.com/abhina-sree approved this pull request.

LGTM

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


[clang] [flang] [flang][driver] add negative from of -fsave-main-program (PR #124110)

2025-01-23 Thread Kiran Chandramohan via cfe-commits

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

LG. Thanks Jean.

Do you need a `bbc` option?

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


[clang] [clang][Sema] Fix initialization of `NonTypeTemplateParmDecl`... (PR #121768)

2025-01-23 Thread Alejandro Álvarez Ayllón via cfe-commits


@@ -1533,13 +1535,11 @@ class NonTypeTemplateParmDecl final
   /// Return the constraint introduced by the placeholder type of this non-type
   /// template parameter (if any).
   Expr *getPlaceholderTypeConstraint() const {
-return hasPlaceholderTypeConstraint() ? *getTrailingObjects() :
-nullptr;
+return PlaceholderTypeConstraintInitialized ? *getTrailingObjects()
+: nullptr;
   }
 
-  void setPlaceholderTypeConstraint(Expr *E) {
-*getTrailingObjects() = E;

alejandro-alvarez-sonarsource wrote:

Both inside `Sema` and `ASTReaderDecl` the `NonTypeTemplateParmDecl` is created 
relatively far from the parsing / deserialization of the constraint.

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


[clang] [HLSL] cbuffer: Create host layout structs (PR #122820)

2025-01-23 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/122820

>From 71ddb5a2b4cc8a9609410b436e896484401f5e90 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 13 Jan 2025 15:03:12 -0800
Subject: [PATCH 1/7] [HLSL] cbuffer: Create host layout struct and add
 resource handle to AST

Creates layout struct for `cbuffer` in Sema which will contains only 
declarations
contributing to the constant buffer layout. Anything else will be filtered out,
such as static variables decls, struct and function definitions, resources,
or empty struct and zero-sized arrays.

If the constant buffer includes a struct that contains any of the above 
undesirable
declarations, a new version of this struct should be created with these 
declarations
filtered out as well.

The definition of buffer layour struct is added to the HLSLBufferDecl node and 
is followed
by 'cbuffer` resource handle decl referencing the layout struct as its 
contained type.

Fixes #122553
---
 clang/include/clang/AST/Decl.h|   1 +
 clang/lib/AST/Decl.cpp|  13 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |   8 +-
 clang/lib/CodeGen/CGHLSLRuntime.h |   2 +-
 clang/lib/Sema/SemaHLSL.cpp   | 245 ++
 .../ast-dump-comment-cbuffe-tbufferr.hlsl |  15 +-
 clang/test/AST/HLSL/cbuffer.hlsl  | 217 
 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl  |  26 --
 clang/test/AST/HLSL/pch_hlsl_buffer.hlsl  |  17 +-
 9 files changed, 509 insertions(+), 35 deletions(-)
 create mode 100644 clang/test/AST/HLSL/cbuffer.hlsl
 delete mode 100644 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 9c470f09406378..0a66ed3d499ff2 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4967,6 +4967,7 @@ class HLSLBufferDecl final : public NamedDecl, public 
DeclContext {
   SourceLocation getRBraceLoc() const { return RBraceLoc; }
   void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
   bool isCBuffer() const { return IsCBuffer; }
+  const Type *getResourceHandleType() const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 31749e46458d6a..a4f5d1a3a71a63 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5693,6 +5693,19 @@ HLSLBufferDecl 
*HLSLBufferDecl::CreateDeserialized(ASTContext &C,
 SourceLocation(), SourceLocation());
 }
 
+const Type *HLSLBufferDecl::getResourceHandleType() const {
+  // Resource handle is the last decl in the HLSLBufferDecl.
+  // If it is not present, it probably means the buffer is empty.
+  if (VarDecl *VD = llvm::dyn_cast_or_null(LastDecl)) {
+const Type *Ty = VD->getType().getTypePtr();
+if (Ty->isHLSLAttributedResourceType()) {
+  assert(VD->getNameAsString() == "__handle");
+  return Ty;
+}
+  }
+  return nullptr;
+}
+
 
//===--===//
 // ImportDecl Implementation
 
//===--===//
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 5679bd71581795..51e20ad43fcc8d 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -159,10 +159,12 @@ void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) {
   CB.Constants.emplace_back(std::make_pair(GV, LowerBound));
 }
 
-void CGHLSLRuntime::addBufferDecls(const DeclContext *DC, Buffer &CB) {
-  for (Decl *it : DC->decls()) {
+void CGHLSLRuntime::addBufferDecls(const HLSLBufferDecl *D, Buffer &CB) {
+  for (Decl *it : D->decls()) {
 if (auto *ConstDecl = dyn_cast(it)) {
-  addConstant(ConstDecl, CB);
+  if (ConstDecl->getType().getTypePtr() != D->getResourceHandleType()) {
+addConstant(ConstDecl, CB);
+  }
 } else if (isa(it)) {
   // Nothing to do for this declaration.
 } else if (isa(it)) {
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 00e110e8e6fa27..870a5bd0ea6b4f 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -169,7 +169,7 @@ class CGHLSLRuntime {
llvm::hlsl::ElementType ET,
BufferResBinding &Binding);
   void addConstant(VarDecl *D, Buffer &CB);
-  void addBufferDecls(const DeclContext *DC, Buffer &CB);
+  void addBufferDecls(const HLSLBufferDecl *D, Buffer &CB);
   llvm::Triple::ArchType getArch();
   llvm::SmallVector Buffers;
 
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 65ddee05a21512..c726672c0118e0 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -21,10 +21,12 @@
 #include "clang/AST/TypeLo

[clang] [HLSL] cbuffer: Create host layout structs (PR #122820)

2025-01-23 Thread Helena Kotas via cfe-commits


@@ -253,12 +257,229 @@ static void validatePackoffset(Sema &S, HLSLBufferDecl 
*BufDecl) {
   }
 }
 
+// Returns true if the array has a zero size = if any of the dimensions is 0
+static bool isZeroSizedArray(const ConstantArrayType *CAT) {
+  while (CAT && !CAT->isZeroSize())
+CAT = dyn_cast(
+CAT->getElementType()->getUnqualifiedDesugaredType());
+  return CAT != nullptr;
+}
+
+// Returns true if the struct contains at least one element that prevents it
+// from being included inside HLSL Buffer as is, such as an intangible type,
+// empty struct, or zero-sized array. If it does, a new implicit layout struct
+// needs to be created for HLSL Buffer use that will exclude these unwanted
+// declarations (see createHostLayoutStruct function).
+static bool requiresImplicitBufferLayoutStructure(const CXXRecordDecl *RD) {
+  if (RD->getTypeForDecl()->isHLSLIntangibleType() || RD->isEmpty())
+return true;
+  // check fields
+  for (const FieldDecl *Field : RD->fields()) {
+QualType Ty = Field->getType();
+if (Ty->isRecordType()) {
+  if (requiresImplicitBufferLayoutStructure(Ty->getAsCXXRecordDecl()))
+return true;
+} else if (Ty->isConstantArrayType()) {
+  if (isZeroSizedArray(cast(Ty)))
+return true;
+}
+  }
+  // check bases
+  for (const CXXBaseSpecifier &Base : RD->bases())
+if (requiresImplicitBufferLayoutStructure(
+Base.getType()->getAsCXXRecordDecl()))
+  return true;
+  return false;
+}
+
+static CXXRecordDecl *findRecordDecl(Sema &S, IdentifierInfo *II,
+ DeclContext *DC) {
+  DeclarationNameInfo NameInfo =
+  DeclarationNameInfo(DeclarationName(II), SourceLocation());
+  LookupResult R(S, NameInfo, Sema::LookupOrdinaryName);
+  S.LookupName(R, S.getScopeForContext(DC));
+  if (R.isSingleResult())
+return R.getAsSingle();
+  return nullptr;
+}
+
+// Creates a name for buffer layout struct using the provide name base.
+// If the name must be unique (not previously defined), a suffix is added
+// until a unique name is found.
+static IdentifierInfo *getHostLayoutStructName(Sema &S,
+   IdentifierInfo *NameBaseII,
+   bool MustBeUnique,
+   DeclContext *DC) {
+  ASTContext &AST = S.getASTContext();
+  std::string NameBase;
+  if (NameBaseII) {
+NameBase = NameBaseII->getName().str();
+  } else {
+// anonymous struct
+NameBase = "anon";
+MustBeUnique = true;
+  }
+
+  std::string Name = "__layout_" + NameBase;
+  IdentifierInfo *II = &AST.Idents.get(Name, tok::TokenKind::identifier);
+  if (!MustBeUnique)
+return II;
+
+  unsigned suffix = 0;
+  while (true) {
+if (suffix != 0)
+  II = &AST.Idents.get((llvm::Twine(Name) + "_" + Twine(suffix)).str(),
+   tok::TokenKind::identifier);
+if (!findRecordDecl(S, II, DC))
+  return II;
+// declaration with that name already exists - increment suffix and try
+// again until unique name is found
+suffix++;
+  };
+}
+
+// Returns true if the record type is an HLSL resource class
+static bool isResourceRecordType(const Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
+}
+
+static CXXRecordDecl *createHostLayoutStruct(Sema &S, CXXRecordDecl 
*StructDecl,
+ HLSLBufferDecl *BufDecl);
+
+// Creates a field declaration of given name and type for HLSL buffer layout
+// struct. Returns nullptr if the type cannot be use in HLSL Buffer layout.
+static FieldDecl *createFieldForHostLayoutStruct(Sema &S, const Type *Ty,
+ IdentifierInfo *II,
+ CXXRecordDecl *LayoutStruct,
+ HLSLBufferDecl *BufDecl) {
+  if (Ty->isRecordType()) {
+if (isResourceRecordType(Ty))

hekota wrote:

There is an assert at the top of the `createHostLayoutStruct` function that 
will make sure the logic is consistent: 
```
assert(requiresImplicitBufferLayoutStructure(StructDecl) && "struct is already 
HLSL buffer compatible");
```

I have also moved the checking into a shared function 
`isInvalidConstantBufferLeafElementType`. Currently the only intangible types 
are resources classes, but I added a check for builtin resource type as well.



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


[clang] [HLSL] cbuffer: Create host layout structs (PR #122820)

2025-01-23 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 ffe5cddb68ab84348866b3a3ac727d263b2a44c2 
80fc426305ace181d6ad44cf09e5896592b591c7 --extensions cpp -- 
clang/lib/Sema/SemaHLSL.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 1a8ae295e8..6edca32204 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -274,11 +274,10 @@ static bool isResourceRecordType(const Type *Ty) {
   return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
 }
 
-// Returns true if the type is a leaf element type that is not valid to be 
included
-// in HLSL Buffer, such as a resource class, empty struct, zero-sized array,
-// or a builtin intangible type.
-// Returns false it is a valid leaf element type or if it is a record type that
-// needs to be inspected further.
+// Returns true if the type is a leaf element type that is not valid to be
+// included in HLSL Buffer, such as a resource class, empty struct, zero-sized
+// array, or a builtin intangible type. Returns false it is a valid leaf 
element
+// type or if it is a record type that needs to be inspected further.
 static bool isInvalidConstantBufferLeafElementType(const Type *Ty) {
   if (Ty->isRecordType()) {
 if (isResourceRecordType(Ty) || Ty->getAsCXXRecordDecl()->isEmpty())

``




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


[clang] [HLSL] cbuffer: Create host layout structs (PR #122820)

2025-01-23 Thread Helena Kotas via cfe-commits


@@ -253,12 +257,229 @@ static void validatePackoffset(Sema &S, HLSLBufferDecl 
*BufDecl) {
   }
 }
 
+// Returns true if the array has a zero size = if any of the dimensions is 0
+static bool isZeroSizedArray(const ConstantArrayType *CAT) {
+  while (CAT && !CAT->isZeroSize())
+CAT = dyn_cast(
+CAT->getElementType()->getUnqualifiedDesugaredType());
+  return CAT != nullptr;
+}
+
+// Returns true if the struct contains at least one element that prevents it
+// from being included inside HLSL Buffer as is, such as an intangible type,
+// empty struct, or zero-sized array. If it does, a new implicit layout struct
+// needs to be created for HLSL Buffer use that will exclude these unwanted
+// declarations (see createHostLayoutStruct function).
+static bool requiresImplicitBufferLayoutStructure(const CXXRecordDecl *RD) {
+  if (RD->getTypeForDecl()->isHLSLIntangibleType() || RD->isEmpty())
+return true;
+  // check fields
+  for (const FieldDecl *Field : RD->fields()) {
+QualType Ty = Field->getType();
+if (Ty->isRecordType()) {
+  if (requiresImplicitBufferLayoutStructure(Ty->getAsCXXRecordDecl()))
+return true;
+} else if (Ty->isConstantArrayType()) {
+  if (isZeroSizedArray(cast(Ty)))
+return true;
+}
+  }
+  // check bases
+  for (const CXXBaseSpecifier &Base : RD->bases())
+if (requiresImplicitBufferLayoutStructure(
+Base.getType()->getAsCXXRecordDecl()))
+  return true;
+  return false;
+}
+
+static CXXRecordDecl *findRecordDecl(Sema &S, IdentifierInfo *II,
+ DeclContext *DC) {
+  DeclarationNameInfo NameInfo =
+  DeclarationNameInfo(DeclarationName(II), SourceLocation());
+  LookupResult R(S, NameInfo, Sema::LookupOrdinaryName);
+  S.LookupName(R, S.getScopeForContext(DC));
+  if (R.isSingleResult())
+return R.getAsSingle();

hekota wrote:

I see what you mean now. I have added a separate cbuffer AST test with 
namespaces and changed the implementation to always create the layout struct on 
the same context as the original struct so that it will be in the same 
namespace. The lookup is needs to scan just the immediate non-transparent decl 
context.

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


[clang] [Driver] -fno-plt: warn for unsupported targets (PR #124081)

2025-01-23 Thread Carlo Cabrera via cfe-commits

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


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


[clang] [AST] Migrate away from PointerUnion::dyn_cast (NFC) (PR #124074)

2025-01-23 Thread Nikita Popov via cfe-commits

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


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


[clang] [CodeGen] Migrate away from PointerUnion::dyn_cast (NFC) (PR #124076)

2025-01-23 Thread Nikita Popov via cfe-commits

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


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


[clang] [clang][ExprConst] Let diagnostics point to std::allocator calls (PR #123744)

2025-01-23 Thread via cfe-commits

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


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


[clang] [clang][Sema] Fix initialization of `NonTypeTemplateParmDecl`... (PR #121768)

2025-01-23 Thread Erich Keane via cfe-commits
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: 



@@ -1533,13 +1535,11 @@ class NonTypeTemplateParmDecl final
   /// Return the constraint introduced by the placeholder type of this non-type
   /// template parameter (if any).
   Expr *getPlaceholderTypeConstraint() const {
-return hasPlaceholderTypeConstraint() ? *getTrailingObjects() :
-nullptr;
+return PlaceholderTypeConstraintInitialized ? *getTrailingObjects()
+: nullptr;
   }
 
-  void setPlaceholderTypeConstraint(Expr *E) {
-*getTrailingObjects() = E;

erichkeane wrote:

I'm not complaining about the 'set' method, just that the concern is that it is 
uninitialized.  I'm saying, why not just initialize it to nullptr?  Or am I 
misunderstanding the concern.

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


[clang] [NVPTX] Fix ctor / dtor lowering when NVPTX target is not enabled (PR #124116)

2025-01-23 Thread Jan Patrick Lehr via cfe-commits

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

Fixes a build issue I was hitting in 
https://github.com/llvm/llvm-project/pull/123673

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


[clang] [NVPTX] Fix ctor / dtor lowering when NVPTX target is not enabled (PR #124116)

2025-01-23 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

Maybe some day we can just make this the default if we ever provide an in-tree 
way to handle CUDA.

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


[clang] 0c71fdd - [NVPTX] Fix ctor / dtor lowering when NVPTX target is not enabled (#124116)

2025-01-23 Thread via cfe-commits

Author: Joseph Huber
Date: 2025-01-23T08:14:52-06:00
New Revision: 0c71fdd1575b826cbb3c252ee0b15fc84559abec

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

LOG: [NVPTX] Fix ctor / dtor lowering when NVPTX target is not enabled (#124116)

Summary:
We pass the `-nvptx-lower-global-ctor-dtor` option to support the `libc`
like use-case which needs global constructors sometimes. This only
affects the backend. If the NVPTX target is not enabled this option will
be unknown which prevents you from compiling generic IR for this.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Cuda.cpp
clang/test/Driver/cuda-cross-compiling.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index d4099216c81ba8..0922a97ed7c19d 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -639,6 +639,9 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back(
   Args.MakeArgString("--plugin-opt=-mattr=" + llvm::join(Features, ",")));
 
+  // Enable ctor / dtor lowering for the direct / freestanding NVPTX target.
+  CmdArgs.append({"-mllvm", "--nvptx-lower-global-ctor-dtor"});
+
   // Add paths for the default clang library path.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);
@@ -783,7 +786,7 @@ void NVPTXToolChain::addClangTargetOptions(
   // If we are compiling with a standalone NVPTX toolchain we want to try to
   // mimic a standard environment as much as possible. So we enable lowering
   // ctor / dtor functions to global symbols that can be registered.
-  if (Freestanding)
+  if (Freestanding && !getDriver().isUsingLTO())
 CC1Args.append({"-mllvm", "--nvptx-lower-global-ctor-dtor"});
 }
 

diff  --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index baf37048300315..7817e462c47be9 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -63,8 +63,12 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_70 %s -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=LOWERING %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_70 -flto -c %s -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=LOWERING-LTO %s
 
 // LOWERING: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-mllvm" 
"--nvptx-lower-global-ctor-dtor"
+// LOWERING: clang-nvlink-wrapper{{.*}} "-mllvm" 
"--nvptx-lower-global-ctor-dtor"
+// LOWERING-LTO-NOT: "--nvptx-lower-global-ctor-dtor"
 
 //
 // Test passing arguments directly to nvlink.



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


[clang] [NVPTX] Fix ctor / dtor lowering when NVPTX target is not enabled (PR #124116)

2025-01-23 Thread Joseph Huber via cfe-commits

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


[clang] [Clang] __has_builtin should return false for aux triple builtins (PR #121839)

2025-01-23 Thread Nick Sarnie via cfe-commits


@@ -3,7 +3,10 @@
 // RUN: %clang_cc1 %s -ffreestanding -fms-extensions -fms-compatibility \
 // RUN:  -fms-compatibility-version=19.00 -triple x86_64-pc-windows-msvc 
-emit-llvm -o -
 // %clang_cc1 %s -ffreestanding -triple x86_64-w64-windows-gnu -fms-extensions 
-emit-llvm -o -
-// RUN: %clang_cc1 %s -ffreestanding -fopenmp -fopenmp-is-target-device 
-aux-triple x86_64-unknown-linux-gnu
+//
+// TODO(boomanaiden154)

sarnex wrote:

Thanks for the review! 

@boomanaiden154 specifically suggested this 
[here](https://github.com/llvm/llvm-project/pull/121839#discussion_r1925920983),
 but I'm happy to change it to FIXME if you prefer.

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


[clang] [flang] [flang][driver] add negative from of -fsave-main-program (PR #124110)

2025-01-23 Thread Eugene Epshteyn via cfe-commits

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


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


[clang] Reland: [clang] unified CWG2398 and P0522 changes; finishes implementation of P3310 (PR #124137)

2025-01-23 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> Can you explain the revert-issue, and what you did to fix it? The github diff 
> is making REALLY difficult to understand what you did..

If you go on the commit list, you can click on the commit which I pointed out 
in the OP ([clang] Changes to template argument list checking", which contains 
the changes which fix the revert-causing issue)

The commit message there has explanation of the fix.

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


[clang] [Clang] __has_builtin should return false for aux triple builtins (PR #121839)

2025-01-23 Thread Erich Keane via cfe-commits


@@ -3,7 +3,10 @@
 // RUN: %clang_cc1 %s -ffreestanding -fms-extensions -fms-compatibility \
 // RUN:  -fms-compatibility-version=19.00 -triple x86_64-pc-windows-msvc 
-emit-llvm -o -
 // %clang_cc1 %s -ffreestanding -triple x86_64-w64-windows-gnu -fms-extensions 
-emit-llvm -o -
-// RUN: %clang_cc1 %s -ffreestanding -fopenmp -fopenmp-is-target-device 
-aux-triple x86_64-unknown-linux-gnu
+//
+// TODO(boomanaiden154)

erichkeane wrote:

Rather than a `TODO` and the name, a FIXME + the issue should be sufficient.  
Names like that in source are one of those things that age poorly :) 

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


[clang] [Clang] Add BuiltinTemplates.td to generate code for builtin templates (PR #123736)

2025-01-23 Thread via cfe-commits


@@ -0,0 +1,184 @@
+//=- ClangBuiltinsEmitter.cpp - Generate Clang builtin templates-*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend emits Clang's builtin templates.
+//
+//===--===//
+
+#include "TableGenBackends.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/TableGenBackend.h"
+
+using namespace llvm;
+
+std::string TemplateNameList;
+std::string CreateBuiltinTemplateParameterList;
+
+namespace {
+struct ParserState {
+  size_t UniqueCounter = 0;
+  size_t CurrentDepth = 0;
+  bool EmittedSizeTInfo = false;
+};
+
+std::pair
+ParseTemplateParameterList(ParserState &PS, StringRef &TemplateParmList) {
+  auto Alphabetic = [](char c) { return std::isalpha(c); };

Sirraide wrote:

I’m not familiar w/ every last thing that would go into that, but can we maybe 
literally just use the actual parser for this?

As in, this might be a stupid idea, but would it be feasible to just throw this 
as source text at the start of the translation unit and then parse it, maybe w/ 
something like a `[[clang::__builtin_template__]]` attribute?

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


[clang] [Clang] Silently ignore unknown warnings in `--warning-suppression-mappings` (PR #124141)

2025-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: James Y Knight (jyknight)


Changes

This allows the same file to be used on multiple Clang versions, without 
generating output spam.

Also disable parsing of the suppressions file in the Driver, where it's not 
needed. This was previously causing the diagnostics to be emitted twice, as the 
file was being parsed twice.

I'll also note that if we do ever wish to emit non-fatal diagnostics from 
parsing this file, it'll need more: the code deleted here emitted warnings 
which were not possible for a user to disable, since the suppression file is 
parsed _before_ the diagnostic state has been setup.

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


4 Files Affected:

- (modified) clang/lib/Basic/Diagnostic.cpp (+3-5) 
- (modified) clang/test/Misc/Inputs/suppression-mapping.txt (+4) 
- (modified) clang/tools/driver/driver.cpp (+3) 
- (modified) clang/unittests/Basic/DiagnosticTest.cpp (+1-2) 


``diff
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index ae71758bc81e03..55efd5ffafcece 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -547,11 +547,9 @@ void 
WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
 StringRef DiagGroup = SectionEntry->getKey();
 if (Diags.getDiagnosticIDs()->getDiagnosticsInGroup(
 WarningFlavor, DiagGroup, GroupDiags)) {
-  StringRef Suggestion =
-  DiagnosticIDs::getNearestOption(WarningFlavor, DiagGroup);
-  Diags.Report(diag::warn_unknown_diag_option)
-  << static_cast(WarningFlavor) << DiagGroup
-  << !Suggestion.empty() << Suggestion;
+  // If a diagnostic group name is unknown, simply ignore the
+  // suppressions. This allows use of a single suppression file on multiple
+  // versions of clang.
   continue;
 }
 for (diag::kind Diag : GroupDiags)
diff --git a/clang/test/Misc/Inputs/suppression-mapping.txt 
b/clang/test/Misc/Inputs/suppression-mapping.txt
index abe4fde0c265d5..cea8c50daee1c5 100644
--- a/clang/test/Misc/Inputs/suppression-mapping.txt
+++ b/clang/test/Misc/Inputs/suppression-mapping.txt
@@ -11,3 +11,7 @@ src:*foo/*=emit
 [format=2]
 src:*
 src:*foo/*=emit
+
+# A warning group that clang doesn't know about should be silently ignored.
+[barglegunk]
+src:*
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 74923247b7ee16..c68367c177910c 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -319,6 +319,9 @@ int clang_main(int Argc, char **Argv, const 
llvm::ToolContext &ToolContext) {
   IntrusiveRefCntPtr DiagOpts =
   CreateAndPopulateDiagOpts(Args);
 
+  // The _driver_ (vs cc1) diagnostics engine shouldn't bother to load a 
suppression file.
+  DiagOpts->DiagnosticSuppressionMappingsFile = "";
+
   TextDiagnosticPrinter *DiagClient
 = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
   FixupDiagPrefixExeName(DiagClient, ProgName);
diff --git a/clang/unittests/Basic/DiagnosticTest.cpp 
b/clang/unittests/Basic/DiagnosticTest.cpp
index e03d9a464df7f9..6c431ed81c4919 100644
--- a/clang/unittests/Basic/DiagnosticTest.cpp
+++ b/clang/unittests/Basic/DiagnosticTest.cpp
@@ -253,8 +253,7 @@ TEST_F(SuppressionMappingTest, UnknownDiagName) {
   FS->addFile("foo.txt", /*ModificationTime=*/{},
   llvm::MemoryBuffer::getMemBuffer("[non-existing-warning]"));
   clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS);
-  EXPECT_THAT(diags(), ElementsAre(WithMessage(
-   "unknown warning option 'non-existing-warning'")));
+  EXPECT_THAT(diags(), IsEmpty());
 }
 
 TEST_F(SuppressionMappingTest, SuppressesGroup) {

``




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


[clang] [Clang] __has_builtin should return false for aux triple builtins (PR #121839)

2025-01-23 Thread Nick Sarnie via cfe-commits


@@ -3,7 +3,10 @@
 // RUN: %clang_cc1 %s -ffreestanding -fms-extensions -fms-compatibility \
 // RUN:  -fms-compatibility-version=19.00 -triple x86_64-pc-windows-msvc 
-emit-llvm -o -
 // %clang_cc1 %s -ffreestanding -triple x86_64-w64-windows-gnu -fms-extensions 
-emit-llvm -o -
-// RUN: %clang_cc1 %s -ffreestanding -fopenmp -fopenmp-is-target-device 
-aux-triple x86_64-unknown-linux-gnu
+//
+// TODO(boomanaiden154)

sarnex wrote:

sure, will do!

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


[clang] [llvm] [RISCV] Support cR Inline Asm Constraint (PR #124174)

2025-01-23 Thread Craig Topper via cfe-commits

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

LGTM

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


[clang] [llvm] [RISCV] Support cR Inline Asm Constraint (PR #124174)

2025-01-23 Thread Sam Elliott via cfe-commits

https://github.com/lenary created 
https://github.com/llvm/llvm-project/pull/124174

This denotes RVC-compatible GPR Pairs, which are used by the Zclsd extension.

C API PR: riscv-non-isa/riscv-c-api-doc#102

>From d26d237f6586b879aab96b5f604e2e85156e778f Mon Sep 17 00:00:00 2001
From: Sam Elliott 
Date: Thu, 23 Jan 2025 10:48:08 -0800
Subject: [PATCH] [RISCV] Support cR Inline Asm Constraint

This denotes RVC-compatible GPR Pairs, which are used by the Zclsd
extension.

C API PR: riscv-non-isa/riscv-c-api-doc#102
---
 clang/lib/Basic/Targets/RISCV.cpp |  2 +-
 clang/test/CodeGen/RISCV/riscv-inline-asm.c   |  8 +++
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp   |  4 +-
 .../CodeGen/RISCV/rv32-inline-asm-pairs.ll| 70 +++
 .../CodeGen/RISCV/rv64-inline-asm-pairs.ll| 70 +++
 .../CodeGen/RISCV/zdinx-asm-constraint.ll | 44 
 6 files changed, 196 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index db23b0c2283385..8167d7603b0e14 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -102,7 +102,7 @@ bool RISCVTargetInfo::validateAsmConstraint(
 return true;
   case 'c':
 // A RVC register - GPR or FPR
-if (Name[1] == 'r' || Name[1] == 'f') {
+if (Name[1] == 'r' || Name[1] == 'R' || Name[1] == 'f') {
   Info.setAllowsRegister();
   Name += 1;
   return true;
diff --git a/clang/test/CodeGen/RISCV/riscv-inline-asm.c 
b/clang/test/CodeGen/RISCV/riscv-inline-asm.c
index 9da306807ed0dc..f2031e0adcbcb2 100644
--- a/clang/test/CodeGen/RISCV/riscv-inline-asm.c
+++ b/clang/test/CodeGen/RISCV/riscv-inline-asm.c
@@ -46,6 +46,14 @@ double_xlen_t test_R_wide_scalar(double_xlen_t p) {
   return ret;
 }
 
+double_xlen_t test_cR_wide_scalar(double_xlen_t p) {
+// CHECK-LABEL: define{{.*}} {{i128|i64}} @test_cR_wide_scalar(
+// CHECK: call {{i128|i64}} asm sideeffect "", "=^cR,^cR"({{i128|i64}} %{{.*}})
+  double_xlen_t ret;
+  asm volatile("" : "=cR"(ret) : "cR"(p));
+  return ret;
+}
+
 void test_I(void) {
 // CHECK-LABEL: define{{.*}} void @test_I()
 // CHECK: call void asm sideeffect "", "I"(i32 2047)
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index b25cb128bce9fb..e08b22e1f86fb0 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -20903,7 +20903,7 @@ RISCVTargetLowering::getConstraintType(StringRef 
Constraint) const {
   } else {
 if (Constraint == "vr" || Constraint == "vd" || Constraint == "vm")
   return C_RegisterClass;
-if (Constraint == "cr" || Constraint == "cf")
+if (Constraint == "cr" || Constraint == "cR" || Constraint == "cf")
   return C_RegisterClass;
   }
   return TargetLowering::getConstraintType(Constraint);
@@ -20992,6 +20992,8 @@ RISCVTargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
   return std::make_pair(0U, &RISCV::GPRPairCRegClass);
 if (!VT.isVector())
   return std::make_pair(0U, &RISCV::GPRCRegClass);
+  } else if (Constraint == "cR") {
+  return std::make_pair(0U, &RISCV::GPRPairCRegClass);
   } else if (Constraint == "cf") {
 if (VT == MVT::f16) {
   if (Subtarget.hasStdExtZfhmin())
diff --git a/llvm/test/CodeGen/RISCV/rv32-inline-asm-pairs.ll 
b/llvm/test/CodeGen/RISCV/rv32-inline-asm-pairs.ll
index 04a5d268aebff7..f14fe2665835e4 100644
--- a/llvm/test/CodeGen/RISCV/rv32-inline-asm-pairs.ll
+++ b/llvm/test/CodeGen/RISCV/rv32-inline-asm-pairs.ll
@@ -71,3 +71,73 @@ entry:
   %9 = load i64, ptr %3, align 8
   ret i64 %9
 }
+
+define i64 @test_cR_wide_scalar_simple(i64 noundef %0) nounwind {
+; CHECK-LABEL: test_cR_wide_scalar_simple:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:#APP
+; CHECK-NEXT:# a2 <- a0
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:mv a0, a2
+; CHECK-NEXT:mv a1, a3
+; CHECK-NEXT:ret
+entry:
+  %1 = call i64 asm sideeffect "/* $0 <- $1 */", "=&^cR,^cR"(i64 %0)
+  ret i64 %1
+}
+
+define i32 @test_cR_wide_scalar_with_ops(i32 noundef %0) nounwind {
+; CHECK-LABEL: test_cR_wide_scalar_with_ops:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:mv a1, a0
+; CHECK-NEXT:#APP
+; CHECK-NEXT:# a2 <- a0
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:or a0, a2, a3
+; CHECK-NEXT:ret
+entry:
+  %1 = zext i32 %0 to i64
+  %2 = shl i64 %1, 32
+  %3 = or i64 %1, %2
+  %4 = call i64 asm sideeffect "/* $0 <- $1 */", "=&^cR,^cR"(i64 %3)
+  %5 = trunc i64 %4 to i32
+  %6 = lshr i64 %4, 32
+  %7 = trunc i64 %6 to i32
+  %8 = or i32 %5, %7
+  ret i32 %8
+}
+
+define i64 @test_cR_wide_scalar_inout(ptr %0, i64 noundef %1) nounwind {
+; CHECK-LABEL: test_cR_wide_scalar_inout:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addi sp, sp, -16
+; CHECK-NEXT:mv a3, a2
+; CHECK-NEXT:sw a0, 12(sp)
+; CHECK-NEXT:mv a2, a1
+; CHECK-NEXT:sw a1, 0(sp)
+; CHECK-NEXT:sw a3, 4(sp)

[clang] [HLSL] cbuffer: Create host layout structs (PR #122820)

2025-01-23 Thread Tex Riddell via cfe-commits


@@ -253,12 +257,229 @@ static void validatePackoffset(Sema &S, HLSLBufferDecl 
*BufDecl) {
   }
 }
 
+// Returns true if the array has a zero size = if any of the dimensions is 0
+static bool isZeroSizedArray(const ConstantArrayType *CAT) {
+  while (CAT && !CAT->isZeroSize())
+CAT = dyn_cast(
+CAT->getElementType()->getUnqualifiedDesugaredType());
+  return CAT != nullptr;
+}
+
+// Returns true if the struct contains at least one element that prevents it
+// from being included inside HLSL Buffer as is, such as an intangible type,
+// empty struct, or zero-sized array. If it does, a new implicit layout struct
+// needs to be created for HLSL Buffer use that will exclude these unwanted
+// declarations (see createHostLayoutStruct function).
+static bool requiresImplicitBufferLayoutStructure(const CXXRecordDecl *RD) {
+  if (RD->getTypeForDecl()->isHLSLIntangibleType() || RD->isEmpty())
+return true;
+  // check fields
+  for (const FieldDecl *Field : RD->fields()) {
+QualType Ty = Field->getType();
+if (Ty->isRecordType()) {
+  if (requiresImplicitBufferLayoutStructure(Ty->getAsCXXRecordDecl()))
+return true;
+} else if (Ty->isConstantArrayType()) {
+  if (isZeroSizedArray(cast(Ty)))
+return true;
+}
+  }
+  // check bases
+  for (const CXXBaseSpecifier &Base : RD->bases())
+if (requiresImplicitBufferLayoutStructure(
+Base.getType()->getAsCXXRecordDecl()))
+  return true;
+  return false;
+}
+
+static CXXRecordDecl *findRecordDecl(Sema &S, IdentifierInfo *II,
+ DeclContext *DC) {
+  DeclarationNameInfo NameInfo =
+  DeclarationNameInfo(DeclarationName(II), SourceLocation());
+  LookupResult R(S, NameInfo, Sema::LookupOrdinaryName);
+  S.LookupName(R, S.getScopeForContext(DC));
+  if (R.isSingleResult())
+return R.getAsSingle();
+  return nullptr;
+}
+
+// Creates a name for buffer layout struct using the provide name base.
+// If the name must be unique (not previously defined), a suffix is added
+// until a unique name is found.
+static IdentifierInfo *getHostLayoutStructName(Sema &S,
+   IdentifierInfo *NameBaseII,
+   bool MustBeUnique,
+   DeclContext *DC) {
+  ASTContext &AST = S.getASTContext();
+  std::string NameBase;
+  if (NameBaseII) {
+NameBase = NameBaseII->getName().str();
+  } else {
+// anonymous struct
+NameBase = "anon";
+MustBeUnique = true;
+  }
+
+  std::string Name = "__layout_" + NameBase;
+  IdentifierInfo *II = &AST.Idents.get(Name, tok::TokenKind::identifier);
+  if (!MustBeUnique)
+return II;
+
+  unsigned suffix = 0;
+  while (true) {
+if (suffix != 0)
+  II = &AST.Idents.get((llvm::Twine(Name) + "_" + Twine(suffix)).str(),
+   tok::TokenKind::identifier);
+if (!findRecordDecl(S, II, DC))
+  return II;
+// declaration with that name already exists - increment suffix and try
+// again until unique name is found
+suffix++;
+  };
+}
+
+// Returns true if the record type is an HLSL resource class
+static bool isResourceRecordType(const Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
+}
+
+static CXXRecordDecl *createHostLayoutStruct(Sema &S, CXXRecordDecl 
*StructDecl,
+ HLSLBufferDecl *BufDecl);
+
+// Creates a field declaration of given name and type for HLSL buffer layout
+// struct. Returns nullptr if the type cannot be use in HLSL Buffer layout.
+static FieldDecl *createFieldForHostLayoutStruct(Sema &S, const Type *Ty,
+ IdentifierInfo *II,
+ CXXRecordDecl *LayoutStruct,
+ HLSLBufferDecl *BufDecl) {
+  if (Ty->isRecordType()) {
+if (isResourceRecordType(Ty))
+  return nullptr;
+CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();
+if (requiresImplicitBufferLayoutStructure(RD)) {
+  RD = createHostLayoutStruct(S, RD, BufDecl);
+  if (!RD)
+return nullptr;
+  Ty = RD->getTypeForDecl();
+}
+  } else if (Ty->isConstantArrayType()) {
+if (isZeroSizedArray(cast(Ty)))
+  return nullptr;
+  }
+  QualType QT = QualType(Ty, 0);
+  ASTContext &AST = S.getASTContext();
+  TypeSourceInfo *TSI = AST.getTrivialTypeSourceInfo(QT, SourceLocation());
+  auto *Field = FieldDecl::Create(AST, LayoutStruct, SourceLocation(),
+  SourceLocation(), II, QT, TSI, nullptr, 
false,
+  InClassInitStyle::ICIS_NoInit);
+  Field->setAccess(AccessSpecifier::AS_private);
+  return Field;
+}
+
+// Creates host layout struct for a struct included in HLSL Buffer.
+// The layout struct will include only fields that are allowed in HLSL buffer.
+// Thes

[clang] Add an off-by-default warning to complain about MSVC bitfield padding (PR #117428)

2025-01-23 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > > > So I take it we decided not to enable it by default in 
> > > > `-fms-compatibility` mode then?
> > > 
> > > 
> > > I don't believe it is appropriate to do so. The intent of this warning is 
> > > to indicate MSVC compatibility issues when building in 
> > > non-ms-compatibility modes. The existing padding warnings already trigger 
> > > for these layouts in the relevant ms compatibility modes
> > 
> > 
> > We don't typically add new off-by-default warnings though; users don't 
> > enable them often enough to be worth the costs. My thought process is: if 
> > we enable this diagnostic by default in `-fms-compatibility` mode as 
> > telling the user their bit-fields aren't packing, then it's on by default 
> > for some configurations so it meets our bar for inclusion, and it helps us 
> > directly because we have Windows precommit (and post-commit) CI coverage 
> > for building Clang and LLVM. Users on other platforms can opt-in to the 
> > diagnostic if they want the diagnostics for compatibility reasons.
> 
> My concerns with attaching it to `-fms-compatibility` is that projects using 
> that and that care about padding already have the padding/packing warnings 
> enabled. For every other user we will be warning them that the padding 
> matches the abi they're targeting. The problem I'm wanting to address is not 
> "I am targeting the ms abi" it is "I am not targeting ms abi but want to be 
> told about packing/padding that would be different on ms platforms".
> 
> The intention would be to then enable the warning (maybe with a `-Werror=...` 
> once the build is clean :D ) for all llvm projects, not just the windows 
> targets - maybe with some evangelism so larger projects that have similar 
> issues can be made aware of the flag. Then we can start migrating away from 
> unending unsigned bit-fields and adopt enum bit-fields
> 
> > If we want to leave it off by default, then I wonder if we want to roll the 
> > functionality into `-Wpadded-bitfield` which already exists and is off by 
> > default.
> 
> The problem with this is that that people who do not care about windows/ms 
> abi will then be getting what to them are spurious warnings.

My opinion on this is evolving -- this morally is similar to all the padding 
warnings we have in that it's telling you "hey, this packing is suboptimal". 
Those warnings are all off-by-default because they're not identifying a logical 
mistake in your code; your code still *works* even though it may be possible to 
improve it. So I think leaving this as an off-by-default warning is reasonable.

And it is a distinct diagnostic from `-Wpadded-bitfield` in that it's 
identifying new problematic patterns which may not be problematic on all 
platforms, so it should get its own warning group. Maybe that warning group 
sits under `-Wpadded-bitfield`, but we should give users a way to say "I want 
to know about bitfield padding issues, but not ones specific to how Visual 
Studio does things".

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-23 Thread Ben Langmuir via cfe-commits

benlangmuir wrote:

I see that this change has already been reverted by @ilya-biryukov , but FYI 
before this is re-applied: I am seeing crashes from this change if I attempt to 
bootstrap a build of clang with modules enabled on Darwin.  I haven't yet 
managed to minimize a test case, but compiling the following triggers the issue 
at least when using the current Darwin libc++ 

```
#  include 

template 
struct __can_be_converted_to_string_view
: public _BoolConstant< is_convertible >::value &&
!is_convertible::value > 
{};

```

The crash is because we get a call to `loadDeferredAttribute ` with a  
`nullptr` decl. During the read of `basic_string_view` from the module we end 
up calling `readAttributes` with no decl.  Not sure what was supposed to happen 
here.

```
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS 
(code=1, address=0x1c)
  * frame #0: 0x0001032c293c 
clang++`clang::Decl::isFromASTFile(this=0x) const at 
DeclBase.h:786:39
frame #1: 0x0001032c28ec 
clang++`clang::ASTReader::getOwningModuleFile(this=0x00015102d800, 
D=0x) const at ASTReader.cpp:8016:11
frame #2: 0x0001034642f8 
clang++`clang::ASTReader::loadDeferredAttribute(this=0x00015102d800, 
DA=0x63cb01e0) at ASTReaderDecl.cpp:4517:19
frame #3: 0x0001032d35b4 
clang++`clang::ASTReader::finishPendingActions(this=0x00015102d800) at 
ASTReader.cpp:10244:7
frame #4: 0x0001032db234 
clang++`clang::ASTReader::FinishedDeserializing(this=0x00015102d800) at 
ASTReader.cpp:10799:5
frame #5: 0x0001033111bc 
clang++`clang::ExternalASTSource::Deserializing::~Deserializing(this=0x00016fdeedf0)
 at ExternalASTSource.h:88:15
frame #6: 0x00010328fbec 
clang++`clang::ExternalASTSource::Deserializing::~Deserializing(this=0x00016fdeedf0)
 at ExternalASTSource.h:87:22
frame #7: 0x0001032c5ddc 
clang++`clang::ASTReader::FindExternalVisibleDeclsByName(this=0x00015102d800,
 DC=0x00015157f240, Name=(Ptr = 5659675880), OriginalDC=0x00015157f240) 
at ASTReader.cpp:8525:1
frame #8: 0x000105794d78 
clang++`clang::DeclContext::lookupImpl(clang::DeclarationName, 
clang::DeclContext const*) const + 716
frame #9: 0x000104e13738 clang++`LookupDirect(clang::Sema&, 
clang::LookupResult&, clang::DeclContext const*) + 108
```

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


[clang] [compiler-rt] [Clang] Make `-Wreturn-type` default to an error in all language modes (PR #123470)

2025-01-23 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > I think this is probably Clang 21 material
> 
> Yeah, probably

First off, I really appreciate this patch because (to me) it's not really 
defensible in 2025 that falling off the end of a function with a non-void 
return type is anything but an error. So thank you!

I do think this is Clang 21 material though because I suspect the fallout from 
this might be a challenge. Specifically, I wonder about `autoconf`; that tool 
often plays fast-and-loose with the generated code and it relies on the 
presence of diagnostics to say "nope, this is not supported". So I worry there 
will be autoconf scripts out there which do `int test() { malloc(1); }` to test 
for whether `malloc` exists and it now fails because it falls off the end of a 
non-void function and so it gives the wrong answer. However, I don't have 
evidence of this myself. Is that something you've looked into by any chance? If 
not, it would be worthwhile to know what the fallout is. CC @thesamesam who 
maybe has insights into what kind of fallout this will cause (or may be willing 
to do a test-run with the patch?)

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


[clang] [HLSL] cbuffer: Create host layout structs (PR #122820)

2025-01-23 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/122820

>From 71ddb5a2b4cc8a9609410b436e896484401f5e90 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 13 Jan 2025 15:03:12 -0800
Subject: [PATCH 1/8] [HLSL] cbuffer: Create host layout struct and add
 resource handle to AST

Creates layout struct for `cbuffer` in Sema which will contains only 
declarations
contributing to the constant buffer layout. Anything else will be filtered out,
such as static variables decls, struct and function definitions, resources,
or empty struct and zero-sized arrays.

If the constant buffer includes a struct that contains any of the above 
undesirable
declarations, a new version of this struct should be created with these 
declarations
filtered out as well.

The definition of buffer layour struct is added to the HLSLBufferDecl node and 
is followed
by 'cbuffer` resource handle decl referencing the layout struct as its 
contained type.

Fixes #122553
---
 clang/include/clang/AST/Decl.h|   1 +
 clang/lib/AST/Decl.cpp|  13 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |   8 +-
 clang/lib/CodeGen/CGHLSLRuntime.h |   2 +-
 clang/lib/Sema/SemaHLSL.cpp   | 245 ++
 .../ast-dump-comment-cbuffe-tbufferr.hlsl |  15 +-
 clang/test/AST/HLSL/cbuffer.hlsl  | 217 
 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl  |  26 --
 clang/test/AST/HLSL/pch_hlsl_buffer.hlsl  |  17 +-
 9 files changed, 509 insertions(+), 35 deletions(-)
 create mode 100644 clang/test/AST/HLSL/cbuffer.hlsl
 delete mode 100644 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 9c470f09406378..0a66ed3d499ff2 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4967,6 +4967,7 @@ class HLSLBufferDecl final : public NamedDecl, public 
DeclContext {
   SourceLocation getRBraceLoc() const { return RBraceLoc; }
   void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
   bool isCBuffer() const { return IsCBuffer; }
+  const Type *getResourceHandleType() const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 31749e46458d6a..a4f5d1a3a71a63 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5693,6 +5693,19 @@ HLSLBufferDecl 
*HLSLBufferDecl::CreateDeserialized(ASTContext &C,
 SourceLocation(), SourceLocation());
 }
 
+const Type *HLSLBufferDecl::getResourceHandleType() const {
+  // Resource handle is the last decl in the HLSLBufferDecl.
+  // If it is not present, it probably means the buffer is empty.
+  if (VarDecl *VD = llvm::dyn_cast_or_null(LastDecl)) {
+const Type *Ty = VD->getType().getTypePtr();
+if (Ty->isHLSLAttributedResourceType()) {
+  assert(VD->getNameAsString() == "__handle");
+  return Ty;
+}
+  }
+  return nullptr;
+}
+
 
//===--===//
 // ImportDecl Implementation
 
//===--===//
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 5679bd71581795..51e20ad43fcc8d 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -159,10 +159,12 @@ void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) {
   CB.Constants.emplace_back(std::make_pair(GV, LowerBound));
 }
 
-void CGHLSLRuntime::addBufferDecls(const DeclContext *DC, Buffer &CB) {
-  for (Decl *it : DC->decls()) {
+void CGHLSLRuntime::addBufferDecls(const HLSLBufferDecl *D, Buffer &CB) {
+  for (Decl *it : D->decls()) {
 if (auto *ConstDecl = dyn_cast(it)) {
-  addConstant(ConstDecl, CB);
+  if (ConstDecl->getType().getTypePtr() != D->getResourceHandleType()) {
+addConstant(ConstDecl, CB);
+  }
 } else if (isa(it)) {
   // Nothing to do for this declaration.
 } else if (isa(it)) {
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 00e110e8e6fa27..870a5bd0ea6b4f 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -169,7 +169,7 @@ class CGHLSLRuntime {
llvm::hlsl::ElementType ET,
BufferResBinding &Binding);
   void addConstant(VarDecl *D, Buffer &CB);
-  void addBufferDecls(const DeclContext *DC, Buffer &CB);
+  void addBufferDecls(const HLSLBufferDecl *D, Buffer &CB);
   llvm::Triple::ArchType getArch();
   llvm::SmallVector Buffers;
 
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 65ddee05a21512..c726672c0118e0 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -21,10 +21,12 @@
 #include "clang/AST/TypeLo

[clang] [llvm] [AVX10.2] Update convert chapter intrinsic and mnemonics names (PR #123656)

2025-01-23 Thread Phoebe Wang via cfe-commits

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


[clang] [llvm] [AVX10.2] Update convert chapter intrinsic and mnemonics names (PR #123656)

2025-01-23 Thread Phoebe Wang via cfe-commits

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

LGTM.

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


[clang] [clang-format] Fix a bug in annotating angles containing FatArrow (PR #108671)

2025-01-23 Thread Nico Weber via cfe-commits


@@ -243,14 +244,16 @@ class AnnotatingParser {
   // operator that was misinterpreted because we are parsing template
   // parameters.
   // FIXME: This is getting out of hand, write a decent parser.
-  if (InExpr && !Line.startsWith(tok::kw_template) &&
+  if (InExpr && !SeenFatArrow && !Line.startsWith(tok::kw_template) &&
   Prev.is(TT_BinaryOperator)) {
 const auto Precedence = Prev.getPrecedence();
 if (Precedence > prec::Conditional && Precedence < prec::Relational)
   return false;
   }
   if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto())
 SeenTernaryOperator = true;
+  else if (Prev.is(TT_FatArrow))

nico wrote:

When we update clang-format in chromium, we format a chunk of the codebase with 
old and new clang-format versions and look at the diff. We also ran into this 
regression: 
https://chromium-review.googlesource.com/c/chromium/src/+/6174847/1..2/base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc.cc

We reported #123144 which pointed us to here.

While it's true that `a(d)` could be `a < b | c > (d)`, using `|` 
(instead of `||`) with comparisons and using parenthesized one-element 
expressions seems less likely than this being a template function call with 
explicit template arguments that are a bitwise or, right? Maybe the heuristics 
could be tweaked to pick the template personality of <> when that seems "more 
likely"?

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


[clang] [llvm] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)

2025-01-23 Thread Oleksandr T. via cfe-commits


@@ -0,0 +1,100 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -fsyntax-only -verify 
-pedantic %s -DTEST1
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -fsyntax-only -verify 
-pedantic %s -DTEST2
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -fsyntax-only -verify 
-pedantic %s -DTEST3
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -fsyntax-only -verify 
-pedantic %s -DTEST4

a-tarasyuk wrote:

I've added `DefaultIgnore` for this diagnostic, to follow the behavior like 
`macro name is a reserved identifier` does. Is it ok?

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


[clang] [llvm] [X86][AVX10.2-BF16] Update VCOMISBF16 intrinsics and instructions (PR #123307)

2025-01-23 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang updated 
https://github.com/llvm/llvm-project/pull/123307

>From e2ae76e265178880db7f1ea7c2c67b79ebbd1761 Mon Sep 17 00:00:00 2001
From: "Wang, Phoebe" 
Date: Fri, 17 Jan 2025 17:07:26 +0800
Subject: [PATCH 1/2] [X86][AVX10.2-BF16] Update VCOMISBF16 intrinsics and
 instructions

- Add `I` to intrinsics and instructions
- Add `_` before sbf16 in intrinsics

Ref.: https://cdrdv2.intel.com/v1/dl/getContent/828965
---
 clang/include/clang/Basic/BuiltinsX86.td  | 12 ++---
 clang/lib/Headers/avx10_2bf16intrin.h | 36 +++---
 clang/test/CodeGen/X86/avx10_2bf16-builtins.c | 48 +--
 llvm/include/llvm/IR/IntrinsicsX86.td | 14 +++---
 llvm/lib/Target/X86/X86InstrAVX10.td  | 14 +++---
 llvm/lib/Target/X86/X86IntrinsicsInfo.h   | 12 ++---
 .../CodeGen/X86/avx10_2bf16-intrinsics.ll | 32 ++---
 .../MC/Disassembler/X86/avx10.2-bf16-32.txt   | 28 +--
 .../MC/Disassembler/X86/avx10.2-bf16-64.txt   | 28 +--
 llvm/test/MC/X86/avx10.2-bf16-32-att.s| 28 +--
 llvm/test/MC/X86/avx10.2-bf16-32-intel.s  | 28 +--
 llvm/test/MC/X86/avx10.2-bf16-64-att.s| 28 +--
 llvm/test/MC/X86/avx10.2-bf16-64-intel.s  | 28 +--
 llvm/test/TableGen/x86-fold-tables.inc|  4 +-
 14 files changed, 170 insertions(+), 170 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsX86.td 
b/clang/include/clang/Basic/BuiltinsX86.td
index 18fc10eb85c027..312585fd6fc3b2 100644
--- a/clang/include/clang/Basic/BuiltinsX86.td
+++ b/clang/include/clang/Basic/BuiltinsX86.td
@@ -5376,12 +5376,12 @@ let Features = "avx10.2-512", Attributes = [NoThrow, 
Const, RequiredVectorWidth<
 }
 
 let Features = "avx10.2-256", Attributes = [NoThrow, Const, 
RequiredVectorWidth<128>] in {
-  def vcomsbf16eq : X86Builtin<"int(_Vector<8, __bf16>, _Vector<8, __bf16>)">;
-  def vcomsbf16lt : X86Builtin<"int(_Vector<8, __bf16>, _Vector<8, __bf16>)">;
-  def vcomsbf16neq : X86Builtin<"int(_Vector<8, __bf16>, _Vector<8, __bf16>)">;
-  def vcomsbf16ge : X86Builtin<"int(_Vector<8, __bf16>, _Vector<8, __bf16>)">;
-  def vcomsbf16gt : X86Builtin<"int(_Vector<8, __bf16>, _Vector<8, __bf16>)">;
-  def vcomsbf16le : X86Builtin<"int(_Vector<8, __bf16>, _Vector<8, __bf16>)">;
+  def vcomisbf16eq : X86Builtin<"int(_Vector<8, __bf16>, _Vector<8, __bf16>)">;
+  def vcomisbf16lt : X86Builtin<"int(_Vector<8, __bf16>, _Vector<8, __bf16>)">;
+  def vcomisbf16neq : X86Builtin<"int(_Vector<8, __bf16>, _Vector<8, 
__bf16>)">;
+  def vcomisbf16ge : X86Builtin<"int(_Vector<8, __bf16>, _Vector<8, __bf16>)">;
+  def vcomisbf16gt : X86Builtin<"int(_Vector<8, __bf16>, _Vector<8, __bf16>)">;
+  def vcomisbf16le : X86Builtin<"int(_Vector<8, __bf16>, _Vector<8, __bf16>)">;
 }
 
 let Features = "avx10.2-512", Attributes = [NoThrow, Const, 
RequiredVectorWidth<512>] in {
diff --git a/clang/lib/Headers/avx10_2bf16intrin.h 
b/clang/lib/Headers/avx10_2bf16intrin.h
index 0a427b9b7418b9..847c783825554f 100644
--- a/clang/lib/Headers/avx10_2bf16intrin.h
+++ b/clang/lib/Headers/avx10_2bf16intrin.h
@@ -523,34 +523,34 @@ _mm_maskz_min_pbh(__mmask8 __U, __m128bh __A, __m128bh 
__B) {
   (__mmask8)__U, (__v8bf)_mm_min_pbh(__A, __B), (__v8bf)_mm_setzero_pbh());
 }
 
-static __inline__ int __DEFAULT_FN_ATTRS128 _mm_comeqsbh(__m128bh A,
- __m128bh B) {
-  return __builtin_ia32_vcomsbf16eq((__v8bf)A, (__v8bf)B);
+static __inline__ int __DEFAULT_FN_ATTRS128 _mm_comieq_sbh(__m128bh A,
+   __m128bh B) {
+  return __builtin_ia32_vcomisbf16eq((__v8bf)A, (__v8bf)B);
 }
 
-static __inline__ int __DEFAULT_FN_ATTRS128 _mm_comltsbh(__m128bh A,
- __m128bh B) {
-  return __builtin_ia32_vcomsbf16lt((__v8bf)A, (__v8bf)B);
+static __inline__ int __DEFAULT_FN_ATTRS128 _mm_comilt_sbh(__m128bh A,
+   __m128bh B) {
+  return __builtin_ia32_vcomisbf16lt((__v8bf)A, (__v8bf)B);
 }
 
-static __inline__ int __DEFAULT_FN_ATTRS128 _mm_comlesbh(__m128bh A,
- __m128bh B) {
-  return __builtin_ia32_vcomsbf16le((__v8bf)A, (__v8bf)B);
+static __inline__ int __DEFAULT_FN_ATTRS128 _mm_comile_sbh(__m128bh A,
+   __m128bh B) {
+  return __builtin_ia32_vcomisbf16le((__v8bf)A, (__v8bf)B);
 }
 
-static __inline__ int __DEFAULT_FN_ATTRS128 _mm_comgtsbh(__m128bh A,
- __m128bh B) {
-  return __builtin_ia32_vcomsbf16gt((__v8bf)A, (__v8bf)B);
+static __inline__ int __DEFAULT_FN_ATTRS128 _mm_comigt_sbh(__m128bh A,
+   __m128bh B) {
+  return __builtin_ia32_vcomisbf16gt((__v8bf)A, (__v8bf)B);
 }
 
-static __inline__ int __DEFAULT_FN_ATTRS128 _mm_comgesbh(

[clang] 1c28b92 - [Clang] __has_builtin should return false for aux triple builtins (#121839)

2025-01-23 Thread via cfe-commits

Author: Nick Sarnie
Date: 2025-01-23T18:25:54Z
New Revision: 1c28b9237382b093f477479c993c80181922ca6a

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

LOG: [Clang] __has_builtin should return false for aux triple builtins (#121839)

Currently, `__has_builtin` will return true when passed a builtin that
is only supported on the aux target. I found this when `__has_builtin`
was called with an X86 builtin but the current target was SPIR-V.

We should instead return false for aux builtins.

-

Signed-off-by: Sarnie, Nick 

Added: 
clang/test/Preprocessor/builtin_aux_info.cpp

Modified: 
clang/lib/Lex/PPMacroExpansion.cpp
clang/test/Headers/__cpuidex_conflict.c

Removed: 




diff  --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 347c13da0ad215..9cf29668f251fc 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1804,8 +1804,9 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
diag::err_feature_check_malformed);
 if (!II)
   return false;
-else if (II->getBuiltinID() != 0) {
-  switch (II->getBuiltinID()) {
+auto BuiltinID = II->getBuiltinID();
+if (BuiltinID != 0) {
+  switch (BuiltinID) {
   case Builtin::BI__builtin_cpu_is:
 return getTargetInfo().supportsCpuIs();
   case Builtin::BI__builtin_cpu_init:
@@ -1818,8 +1819,11 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
 // usual allocation and deallocation functions. Required by libc++
 return 201802;
   default:
+// __has_builtin should return false for aux builtins.
+if (getBuiltinInfo().isAuxBuiltinID(BuiltinID))
+  return false;
 return Builtin::evaluateRequiredTargetFeatures(
-getBuiltinInfo().getRequiredFeatures(II->getBuiltinID()),
+getBuiltinInfo().getRequiredFeatures(BuiltinID),
 getTargetInfo().getTargetOpts().FeatureMap);
   }
   return true;

diff  --git a/clang/test/Headers/__cpuidex_conflict.c 
b/clang/test/Headers/__cpuidex_conflict.c
index 8687a6aa2f897a..0f5e6e5e0a0ff4 100644
--- a/clang/test/Headers/__cpuidex_conflict.c
+++ b/clang/test/Headers/__cpuidex_conflict.c
@@ -3,7 +3,9 @@
 // RUN: %clang_cc1 %s -ffreestanding -fms-extensions -fms-compatibility \
 // RUN:  -fms-compatibility-version=19.00 -triple x86_64-pc-windows-msvc 
-emit-llvm -o -
 // %clang_cc1 %s -ffreestanding -triple x86_64-w64-windows-gnu -fms-extensions 
-emit-llvm -o -
-// RUN: %clang_cc1 %s -ffreestanding -fopenmp -fopenmp-is-target-device 
-aux-triple x86_64-unknown-linux-gnu
+//
+// FIXME: See https://github.com/llvm/llvm-project/pull/121839
+// RUN: not %clang_cc1 %s -ffreestanding -fopenmp -fopenmp-is-target-device 
-aux-triple x86_64-unknown-linux-gnu
 
 typedef __SIZE_TYPE__ size_t;
 

diff  --git a/clang/test/Preprocessor/builtin_aux_info.cpp 
b/clang/test/Preprocessor/builtin_aux_info.cpp
new file mode 100644
index 00..60c8c6c492479a
--- /dev/null
+++ b/clang/test/Preprocessor/builtin_aux_info.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fopenmp -triple=spirv64 -fopenmp-is-target-device \
+// RUN: -aux-triple x86_64-linux-unknown -E %s | FileCheck 
-implicit-check-not=BAD %s
+
+// RUN: %clang_cc1 -fopenmp -triple=nvptx64 -fopenmp-is-target-device \
+// RUN: -aux-triple x86_64-linux-unknown -E %s | FileCheck 
-implicit-check-not=BAD %s
+
+// RUN: %clang_cc1 -fopenmp -triple=amdgcn-amd-amdhsa 
-fopenmp-is-target-device \
+// RUN: -aux-triple x86_64-linux-unknown -E %s | FileCheck 
-implicit-check-not=BAD %s
+
+// RUN: %clang_cc1 -fopenmp -triple=aarch64 -fopenmp-is-target-device \
+// RUN: -aux-triple x86_64-linux-unknown -E %s | FileCheck 
-implicit-check-not=BAD %s
+
+// CHECK: GOOD
+#if __has_builtin(__builtin_ia32_pause)
+  BAD
+#else
+  GOOD
+#endif



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


[clang] [Clang] __has_builtin should return false for aux triple builtins (PR #121839)

2025-01-23 Thread Nick Sarnie via cfe-commits

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


[clang] [clang][CodeGen] `sret` args should always point to the `alloca` AS, so use that (PR #114062)

2025-01-23 Thread Alex Voicu via cfe-commits

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


[clang] [clang][CodeGen] `sret` args should always point to the `alloca` AS, so use that (PR #114062)

2025-01-23 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx commented:

> There are a still a few places using getTargetAddressSpace(LangAS::Default), 
> which I don't understand.
> 
> Can you also extract my testcase from #115093? I think this should fix that 
> issue (also, this absolutely needs to be fixed in the release branching next 
> week)  

The former was me being daft and missing them. The latter is done (it does fix 
the issue).

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


[clang] [llvm] [clang][DebugInfo] Emit DW_AT_object_pointer on function declarations with explicit `this` (PR #122928)

2025-01-23 Thread Paul T Robinson via cfe-commits

pogo59 wrote:

The C API must remain stable and backward compatible. It's the C++ APIs that we 
are willing to change without worrying.

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


[clang] [HLSL] cbuffer: Create host layout structs (PR #122820)

2025-01-23 Thread Chris B via cfe-commits


@@ -253,12 +257,229 @@ static void validatePackoffset(Sema &S, HLSLBufferDecl 
*BufDecl) {
   }
 }
 
+// Returns true if the array has a zero size = if any of the dimensions is 0
+static bool isZeroSizedArray(const ConstantArrayType *CAT) {
+  while (CAT && !CAT->isZeroSize())
+CAT = dyn_cast(
+CAT->getElementType()->getUnqualifiedDesugaredType());
+  return CAT != nullptr;
+}
+
+// Returns true if the struct contains at least one element that prevents it
+// from being included inside HLSL Buffer as is, such as an intangible type,
+// empty struct, or zero-sized array. If it does, a new implicit layout struct
+// needs to be created for HLSL Buffer use that will exclude these unwanted
+// declarations (see createHostLayoutStruct function).
+static bool requiresImplicitBufferLayoutStructure(const CXXRecordDecl *RD) {
+  if (RD->getTypeForDecl()->isHLSLIntangibleType() || RD->isEmpty())
+return true;
+  // check fields
+  for (const FieldDecl *Field : RD->fields()) {
+QualType Ty = Field->getType();
+if (Ty->isRecordType()) {
+  if (requiresImplicitBufferLayoutStructure(Ty->getAsCXXRecordDecl()))
+return true;
+} else if (Ty->isConstantArrayType()) {
+  if (isZeroSizedArray(cast(Ty)))
+return true;
+}
+  }
+  // check bases
+  for (const CXXBaseSpecifier &Base : RD->bases())
+if (requiresImplicitBufferLayoutStructure(
+Base.getType()->getAsCXXRecordDecl()))
+  return true;
+  return false;
+}
+
+static CXXRecordDecl *findRecordDecl(Sema &S, IdentifierInfo *II,
+ DeclContext *DC) {
+  DeclarationNameInfo NameInfo =
+  DeclarationNameInfo(DeclarationName(II), SourceLocation());
+  LookupResult R(S, NameInfo, Sema::LookupOrdinaryName);
+  S.LookupName(R, S.getScopeForContext(DC));
+  if (R.isSingleResult())
+return R.getAsSingle();
+  return nullptr;
+}
+
+// Creates a name for buffer layout struct using the provide name base.
+// If the name must be unique (not previously defined), a suffix is added
+// until a unique name is found.
+static IdentifierInfo *getHostLayoutStructName(Sema &S,
+   IdentifierInfo *NameBaseII,
+   bool MustBeUnique,
+   DeclContext *DC) {
+  ASTContext &AST = S.getASTContext();
+  std::string NameBase;

llvm-beanz wrote:

`llvm::SmallString` might be a better option to reduce the likelihood of 
needing an allocation, and unifying `NameBase` and `Name` to a single 
`SmallString` would potentially reduce dynamic allocations and copying of 
string data.

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


[clang] [llvm] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)

2025-01-23 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


[clang] [flang] [lld] [Flang] Don't use FortranDecimal for runtime (PR #121997)

2025-01-23 Thread Michael Kruse via cfe-commits

https://github.com/Meinersbur updated 
https://github.com/llvm/llvm-project/pull/121997

>From a08aa48fb4955f9d16c6172580505c100076b5d4 Mon Sep 17 00:00:00 2001
From: Michael Kruse 
Date: Tue, 7 Jan 2025 17:05:39 +0100
Subject: [PATCH 1/4] Join FortranDecimal into FortranCommon

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  3 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  4 -
 flang/docs/FlangDriver.md |  5 +-
 .../binary-floating-point.h   |  8 +-
 .../flang/{Decimal => Common}/decimal.h   | 11 ++-
 flang/lib/CMakeLists.txt  |  1 -
 flang/lib/Common/CMakeLists.txt   |  2 +
 .../big-radix-floating-point.h| 12 +--
 .../{Decimal => Common}/binary-to-decimal.cpp |  4 +-
 .../{Decimal => Common}/decimal-to-binary.cpp |  6 +-
 flang/lib/Decimal/CMakeLists.txt  | 86 ---
 flang/lib/Evaluate/CMakeLists.txt |  1 -
 flang/lib/Evaluate/real.cpp   |  2 +-
 flang/runtime/CMakeLists.txt  | 14 +--
 flang/runtime/edit-input.h|  2 +-
 flang/runtime/edit-output.h   |  2 +-
 flang/runtime/environment.h   |  2 +-
 flang/runtime/format-implementation.h |  2 +-
 flang/runtime/format.h|  2 +-
 flang/test/CMakeLists.txt |  1 -
 flang/test/Driver/linker-flags.f90|  6 +-
 .../test/Driver/msvc-dependent-lib-flags.f90  |  4 -
 flang/test/Driver/nostdlib.f90|  1 -
 flang/test/Runtime/no-cpp-dep.c   |  2 +-
 flang/test/lit.cfg.py |  3 -
 flang/unittests/Decimal/CMakeLists.txt|  4 +-
 flang/unittests/Decimal/quick-sanity-test.cpp |  2 +-
 flang/unittests/Decimal/thorough-test.cpp |  2 +-
 flang/unittests/Evaluate/CMakeLists.txt   |  2 -
 lld/COFF/MinGW.cpp|  1 -
 30 files changed, 40 insertions(+), 157 deletions(-)
 rename flang/include/flang/{Decimal => Common}/binary-floating-point.h (96%)
 rename flang/include/flang/{Decimal => Common}/decimal.h (95%)
 rename flang/lib/{Decimal => Common}/big-radix-floating-point.h (97%)
 rename flang/lib/{Decimal => Common}/binary-to-decimal.cpp (99%)
 rename flang/lib/{Decimal => Common}/decimal-to-binary.cpp (99%)
 delete mode 100644 flang/lib/Decimal/CMakeLists.txt

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 60214c4d59cee5..9e9872975de9c2 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1317,7 +1317,7 @@ void tools::addOpenMPHostOffloadingArgs(const Compilation 
&C,
 /// Add Fortran runtime libs
 void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) {
-  // Link FortranRuntime and FortranDecimal
+  // Link FortranRuntime
   // These are handled earlier on Windows by telling the frontend driver to
   // add the correct libraries to link against as dependents in the object
   // file.
@@ -1334,7 +1334,6 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, 
const ArgList &Args,
 addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
 }
 CmdArgs.push_back("-lFortranRuntime");
-CmdArgs.push_back("-lFortranDecimal");
 addArchSpecificRPath(TC, Args, CmdArgs);
   }
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 7034e5b475c1d3..749af4ada9a696 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -357,21 +357,18 @@ static void processVSRuntimeLibrary(const ToolChain &TC, 
const ArgList &Args,
 CmdArgs.push_back("-D_MT");
 CmdArgs.push_back("--dependent-lib=libcmt");
 CmdArgs.push_back("--dependent-lib=FortranRuntime.static.lib");
-CmdArgs.push_back("--dependent-lib=FortranDecimal.static.lib");
 break;
   case options::OPT__SLASH_MTd:
 CmdArgs.push_back("-D_MT");
 CmdArgs.push_back("-D_DEBUG");
 CmdArgs.push_back("--dependent-lib=libcmtd");
 CmdArgs.push_back("--dependent-lib=FortranRuntime.static_dbg.lib");
-CmdArgs.push_back("--dependent-lib=FortranDecimal.static_dbg.lib");
 break;
   case options::OPT__SLASH_MD:
 CmdArgs.push_back("-D_MT");
 CmdArgs.push_back("-D_DLL");
 CmdArgs.push_back("--dependent-lib=msvcrt");
 CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic.lib");
-CmdArgs.push_back("--dependent-lib=FortranDecimal.dynamic.lib");
 break;
   case options::OPT__SLASH_MDd:
 CmdArgs.push_back("-D_MT");
@@ -379,7 +376,6 @@ static void processVSRuntimeLibrary(const ToolChain &TC, 
const ArgList &Args,
 CmdArgs.push_back("-D_DLL");
 CmdArgs.push_back("--dependent-lib=msvcrtd");
 CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic_dbg.lib");
-CmdArgs.push_back("--dependent-lib=FortranD

[clang] [Clang] Fix segmentation fault caused by `VarBypassDetector` stack overflow on deeply nested expressions (PR #124128)

2025-01-23 Thread Boaz Brickner via cfe-commits

https://github.com/bricknerb created 
https://github.com/llvm/llvm-project/pull/124128

This happens when using -O2.

Added a test that reproduces it based on a test that was reverted in #111701: 
https://github.com/bricknerb/llvm-project/blob/93e4a7386ec897e53d7330c6206d38759a858be2/clang/test/CodeGen/deeply-nested-expressions.cpp
 However, this test is slow and likely to be hard to maintained as discussed in 
https://github.com/llvm/llvm-project/pull/111701/files/1a63281b6c240352653fd2e4299755c1f32a76f4#r1795518779
 so unless there are objections I plan to remove this test before merging.

>From 06bf61b6e3900edb99bcbe1c48e1581463f1ec11 Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Thu, 23 Jan 2025 16:03:22 +0100
Subject: [PATCH] [clang] Fix segmentation fault caused by VarBypassDetector
 stack overflow on deeply nested expressions This happens when using -O2.

Added a test that reproduces it based on a test that was reverted in #111701:
https://github.com/bricknerb/llvm-project/blob/93e4a7386ec897e53d7330c6206d38759a858be2/clang/test/CodeGen/deeply-nested-expressions.cpp
However, this test is slow and likely to be hard to maintained as discussed in 
https://github.com/llvm/llvm-project/pull/111701/files/1a63281b6c240352653fd2e4299755c1f32a76f4#r1795518779
 so unless there are objections I plan to remove this test before merging.
---
 clang/lib/CodeGen/CodeGenFunction.cpp |  2 +-
 clang/lib/CodeGen/VarBypassDetector.cpp   | 23 --
 clang/lib/CodeGen/VarBypassDetector.h |  9 --
 .../CodeGen/deeply-nested-expressions.cpp | 30 +++
 4 files changed, 51 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/CodeGen/deeply-nested-expressions.cpp

diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 11fdddba1144bb..6bdfbbd4013039 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1533,7 +1533,7 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, 
llvm::Function *Fn,
 // Initialize helper which will detect jumps which can cause invalid
 // lifetime markers.
 if (ShouldEmitLifetimeMarkers)
-  Bypasses.Init(Body);
+  Bypasses.Init(CGM, Body);
   }
 
   // Emit the standard function prologue.
diff --git a/clang/lib/CodeGen/VarBypassDetector.cpp 
b/clang/lib/CodeGen/VarBypassDetector.cpp
index 6eda83dfdef2f3..7b2b3542928ad7 100644
--- a/clang/lib/CodeGen/VarBypassDetector.cpp
+++ b/clang/lib/CodeGen/VarBypassDetector.cpp
@@ -8,6 +8,7 @@
 
 #include "VarBypassDetector.h"
 
+#include "CodeGenModule.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/Stmt.h"
@@ -17,13 +18,13 @@ using namespace CodeGen;
 
 /// Clear the object and pre-process for the given statement, usually function
 /// body statement.
-void VarBypassDetector::Init(const Stmt *Body) {
+void VarBypassDetector::Init(CodeGenModule &CGM, const Stmt *Body) {
   FromScopes.clear();
   ToScopes.clear();
   Bypasses.clear();
   Scopes = {{~0U, nullptr}};
   unsigned ParentScope = 0;
-  AlwaysBypassed = !BuildScopeInformation(Body, ParentScope);
+  AlwaysBypassed = !BuildScopeInformation(CGM, Body, ParentScope);
   if (!AlwaysBypassed)
 Detect();
 }
@@ -31,7 +32,7 @@ void VarBypassDetector::Init(const Stmt *Body) {
 /// Build scope information for a declaration that is part of a DeclStmt.
 /// Returns false if we failed to build scope information and can't tell for
 /// which vars are being bypassed.
-bool VarBypassDetector::BuildScopeInformation(const Decl *D,
+bool VarBypassDetector::BuildScopeInformation(CodeGenModule &CGM, const Decl 
*D,
   unsigned &ParentScope) {
   const VarDecl *VD = dyn_cast(D);
   if (VD && VD->hasLocalStorage()) {
@@ -41,7 +42,7 @@ bool VarBypassDetector::BuildScopeInformation(const Decl *D,
 
   if (const VarDecl *VD = dyn_cast(D))
 if (const Expr *Init = VD->getInit())
-  return BuildScopeInformation(Init, ParentScope);
+  return BuildScopeInformation(CGM, Init, ParentScope);
 
   return true;
 }
@@ -50,7 +51,7 @@ bool VarBypassDetector::BuildScopeInformation(const Decl *D,
 /// LabelAndGotoScopes and recursively walking the AST as needed.
 /// Returns false if we failed to build scope information and can't tell for
 /// which vars are being bypassed.
-bool VarBypassDetector::BuildScopeInformation(const Stmt *S,
+bool VarBypassDetector::BuildScopeInformation(CodeGenModule &CGM, const Stmt 
*S,
   unsigned &origParentScope) {
   // If this is a statement, rather than an expression, scopes within it don't
   // propagate out into the enclosing scope. Otherwise we have to worry about
@@ -68,12 +69,12 @@ bool VarBypassDetector::BuildScopeInformation(const Stmt *S,
 
   case Stmt::SwitchStmtClass:
 if (const Stmt *Init = cast(S)->getInit()) {
-  if (!BuildScopeInformation(Init, ParentScope))
+  if (!BuildScopeInf

[clang] [flang] [flang][driver] add negative from of -fsave-main-program (PR #124110)

2025-01-23 Thread via cfe-commits

https://github.com/jeanPerier updated 
https://github.com/llvm/llvm-project/pull/124110

>From 28dba56b12b45f8ce82426e2b79165352f549850 Mon Sep 17 00:00:00 2001
From: Jean Perier 
Date: Thu, 23 Jan 2025 04:37:30 -0800
Subject: [PATCH 1/2] [flang][driver] add negative from of -fsave-main-program

---
 clang/include/clang/Driver/Options.td | 4 ++--
 clang/lib/Driver/ToolChains/Flang.cpp | 3 ++-
 flang/lib/Frontend/CompilerInvocation.cpp | 9 +
 flang/test/Driver/fsave-main-program.f90  | 6 +-
 flang/test/Lower/fsave-main-program.f90   | 1 +
 5 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index df705104d9ea31..6fface303c57a6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6968,8 +6968,8 @@ defm unsigned : OptInFC1FFlag<"unsigned", "Enables 
UNSIGNED type">;
 def fno_automatic : Flag<["-"], "fno-automatic">, Group,
   HelpText<"Implies the SAVE attribute for non-automatic local objects in 
subprograms unless RECURSIVE">;
 
-def fsave_main_program : Flag<["-"], "fsave-main-program">, Group,
-  HelpText<"Place all variables from the main program in static memory 
(otherwise scalars may be placed on the stack)">;
+defm save_main_program : OptInFC1FFlag<"save-main-program",
+  "Place all variables from the main program in static memory (otherwise 
scalars may be placed on the stack)">;
 
 defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays",
   PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 9c1fd28a3a8a26..8d1ec016325dfb 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -58,7 +58,8 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
 options::OPT_fhermetic_module_files,
 options::OPT_frealloc_lhs,
 options::OPT_fno_realloc_lhs,
-options::OPT_fsave_main_program});
+options::OPT_fsave_main_program,
+options::OPT_fno_save_main_program});
 }
 
 void Flang::addPreprocessingOptions(const ArgList &Args,
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 3c6da4687f65d3..68b5950d3a51b7 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -770,10 +770,11 @@ static bool parseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
 opts.features.Enable(Fortran::common::LanguageFeature::DefaultSave);
   }
 
-  // -fsave-main-program
-  if (args.hasArg(clang::driver::options::OPT_fsave_main_program)) {
-opts.features.Enable(Fortran::common::LanguageFeature::SaveMainProgram);
-  }
+  // -f{no}-save-main-program
+  opts.features.Enable(
+  Fortran::common::LanguageFeature::SaveMainProgram,
+  args.hasFlag(clang::driver::options::OPT_fsave_main_program,
+   clang::driver::options::OPT_fno_save_main_program, false));
 
   if (args.hasArg(
   clang::driver::options::OPT_falternative_parameter_statement)) {
diff --git a/flang/test/Driver/fsave-main-program.f90 
b/flang/test/Driver/fsave-main-program.f90
index bffdfd97911e80..e7a2f9d8b470ed 100644
--- a/flang/test/Driver/fsave-main-program.f90
+++ b/flang/test/Driver/fsave-main-program.f90
@@ -1,5 +1,9 @@
 ! Check that the driver passes through -fsave-main-program:
 ! RUN: %flang -### -S -fsave-main-program %s -o - 2>&1 | FileCheck %s
+! CHECK: "-fc1"{{.*}}"-fsave-main-program"
+
+! RUN: %flang -### -S -fno-save-main-program %s -o - 2>&1 | FileCheck %s 
--check-prefix=CHECK2
+! CHECK2: "-fc1"{{.*}}"-fno-save-main-program"
+
 ! Check that the compiler accepts -fsave-main-program:
 ! RUN: %flang_fc1 -emit-hlfir -fsave-main-program %s -o -
-! CHECK: "-fc1"{{.*}}"-fsave-main-program"
diff --git a/flang/test/Lower/fsave-main-program.f90 
b/flang/test/Lower/fsave-main-program.f90
index 17fc1b02f5068f..e89244c3c7c51a 100644
--- a/flang/test/Lower/fsave-main-program.f90
+++ b/flang/test/Lower/fsave-main-program.f90
@@ -1,6 +1,7 @@
 ! Test -fsave-main-program switch.
 ! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-DEFAULT 
%s
 ! RUN: %flang_fc1 -fsave-main-program -emit-hlfir -o - %s | FileCheck 
--check-prefix=CHECK-SAVE %s
+! RUN: %flang_fc1 -fsave-main-program -fno-save-main-program -emit-hlfir -o - 
%s | FileCheck --check-prefix=CHECK-DEFAULT %s
 program test
 integer :: i
 call foo(i)

>From 7b9fe8a3f1f8d2a308d80ddc6d259ce4e4cda6b6 Mon Sep 17 00:00:00 2001
From: Jean Perier 
Date: Thu, 23 Jan 2025 07:06:44 -0800
Subject: [PATCH 2/2] Also print the negative form in the help

I had not noticed that with OptInFC1FFlag, the negative form
is hidden.
---
 clang/include/clang/Driver/Options.td | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff -

[clang] [flang] [flang][driver] add negative from of -fsave-main-program (PR #124110)

2025-01-23 Thread via cfe-commits


@@ -6968,8 +6968,8 @@ defm unsigned : OptInFC1FFlag<"unsigned", "Enables 
UNSIGNED type">;
 def fno_automatic : Flag<["-"], "fno-automatic">, Group,
   HelpText<"Implies the SAVE attribute for non-automatic local objects in 
subprograms unless RECURSIVE">;
 
-def fsave_main_program : Flag<["-"], "fsave-main-program">, Group,
-  HelpText<"Place all variables from the main program in static memory 
(otherwise scalars may be placed on the stack)">;
+defm save_main_program : OptInFC1FFlag<"save-main-program",

jeanPerier wrote:

It does. I just copied from other usages, but looking into it, I think that is 
the intention for this from.

The prefixes are for the help messages and only the positive from of the flag 
is printed in the help since the negative is the default behavior (hence the 
"OptIn"). So this sets the help message of the positive form via `pos_prefix` 
and leaves the negative from help text empty (`neg_prefix # help`)).

But I actually want the negative from to be printed, I am not a fan of hidden 
options, so I changed to `BoolOptionWithoutMarshalling`. Thanks for raising the 
question!

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


[clang] [Clang] Fix segmentation fault caused by `VarBypassDetector` stack overflow on deeply nested expressions (PR #124128)

2025-01-23 Thread Boaz Brickner via cfe-commits

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


[clang] [NFC] Remove invalid features from test and autogenerate checks. (PR #124130)

2025-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alexandros Lamprineas (labrinea)


Changes



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


1 Files Affected:

- (modified) clang/test/CodeGen/AArch64/cpu-supports-target.c (+189-14) 


``diff
diff --git a/clang/test/CodeGen/AArch64/cpu-supports-target.c 
b/clang/test/CodeGen/AArch64/cpu-supports-target.c
index b185dda2881080..a39ffd4e4a74d4 100644
--- a/clang/test/CodeGen/AArch64/cpu-supports-target.c
+++ b/clang/test/CodeGen/AArch64/cpu-supports-target.c
@@ -1,27 +1,150 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-attributes --check-globals all --version 5
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
 
-int check_all_feature() {
+//.
+// CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
+//.
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define dso_local i32 @check_all_features(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 66367
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 66367
+// CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
+// CHECK-NEXT:br i1 [[TMP3]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
+// CHECK:   [[IF_THEN]]:
+// CHECK-NEXT:store i32 1, ptr [[RETVAL]], align 4
+// CHECK-NEXT:br label %[[RETURN:.*]]
+// CHECK:   [[IF_ELSE]]:
+// CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 14272
+// CHECK-NEXT:[[TMP6:%.*]] = icmp eq i64 [[TMP5]], 14272
+// CHECK-NEXT:[[TMP7:%.*]] = and i1 true, [[TMP6]]
+// CHECK-NEXT:br i1 [[TMP7]], label %[[IF_THEN1:.*]], label 
%[[IF_ELSE2:.*]]
+// CHECK:   [[IF_THEN1]]:
+// CHECK-NEXT:store i32 2, ptr [[RETVAL]], align 4
+// CHECK-NEXT:br label %[[RETURN]]
+// CHECK:   [[IF_ELSE2]]:
+// CHECK-NEXT:[[TMP8:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP9:%.*]] = and i64 [[TMP8]], 2065152
+// CHECK-NEXT:[[TMP10:%.*]] = icmp eq i64 [[TMP9]], 2065152
+// CHECK-NEXT:[[TMP11:%.*]] = and i1 true, [[TMP10]]
+// CHECK-NEXT:br i1 [[TMP11]], label %[[IF_THEN3:.*]], label 
%[[IF_ELSE4:.*]]
+// CHECK:   [[IF_THEN3]]:
+// CHECK-NEXT:store i32 3, ptr [[RETVAL]], align 4
+// CHECK-NEXT:br label %[[RETURN]]
+// CHECK:   [[IF_ELSE4]]:
+// CHECK-NEXT:[[TMP12:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP13:%.*]] = and i64 [[TMP12]], 288230376183169792
+// CHECK-NEXT:[[TMP14:%.*]] = icmp eq i64 [[TMP13]], 288230376183169792
+// CHECK-NEXT:[[TMP15:%.*]] = and i1 true, [[TMP14]]
+// CHECK-NEXT:br i1 [[TMP15]], label %[[IF_THEN5:.*]], label 
%[[IF_ELSE6:.*]]
+// CHECK:   [[IF_THEN5]]:
+// CHECK-NEXT:store i32 4, ptr [[RETVAL]], align 4
+// CHECK-NEXT:br label %[[RETURN]]
+// CHECK:   [[IF_ELSE6]]:
+// CHECK-NEXT:[[TMP16:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP17:%.*]] = and i64 [[TMP16]], 1275134720
+// CHECK-NEXT:[[TMP18:%.*]] = icmp eq i64 [[TMP17]], 1275134720
+// CHECK-NEXT:[[TMP19:%.*]] = and i1 true, [[TMP18]]
+// CHECK-NEXT:br i1 [[TMP19]], label %[[IF_THEN7:.*]], label 
%[[IF_ELSE8:.*]]
+// CHECK:   [[IF_THEN7]]:
+// CHECK-NEXT:store i32 5, ptr [[RETVAL]], align 4
+// CHECK-NEXT:br label %[[RETURN]]
+// CHECK:   [[IF_ELSE8]]:
+// CHECK-NEXT:[[TMP20:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP21:%.*]] = and i64 [[TMP20]], 52814742272
+// CHECK-NEXT:[[TMP22:%.*]] = icmp eq i64 [[TMP21]], 52814742272
+// CHECK-NEXT:[[TMP23:%.*]] = and i1 true, [[TMP22]]
+// CHECK-NEXT:br i1 [[TMP23]], label %[[IF_THEN9:.*]], label 
%[[IF_ELSE10:.*]]
+// CHECK:   [[IF_THEN9]]:
+// CHECK-NEXT:store i32 6, ptr [[RETVAL]], align 4
+// CHECK-NEXT:br label %[[RETURN]]
+// CHECK:   [[IF_ELSE10]]:
+// CHECK-NEXT:[[TMP24:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP25:%.*]] = and i64 [[TMP24]], 344671224576
+// CHECK-NEXT:[[TMP26:%.*]] = icmp eq i64 [[TMP25]], 344671224576
+// CHECK-NEXT:[[TMP27:%.*]] = and i1 true, [[TMP26]]
+// CHECK-NEXT:br i1 [[TMP27]], label %[[IF_THEN11:.*]], label 
%[[IF_ELSE12:.*]]
+// CHECK:   [[IF_THEN11]]:
+// CHECK-NEXT:store i32 7, ptr [[RETVAL]], align 4
+// CHECK-NEXT:br label %[[RETURN]]
+// CHECK:   [[IF_ELSE12]]:
+// CHECK-NEXT:[[TMP28:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP29:%.*]] = and i64 [[TMP28]], 3918083994400
+// CHECK-NEXT:[[TMP30:%.*]] = icmp eq i64 [[TMP29]], 3918083994400
+// CHECK-NEXT:[[TMP31:%.*]] = an

  1   2   3   4   >