[clang] [HLSL] Implement the `lit` intrinsic (PR #134171)

2025-04-02 Thread Farzon Lotfi via cfe-commits

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


[clang-tools-extra] [clang-tidy] Improve integer comparison by matching valid expressions outside implicitCastExpr (PR #134188)

2025-04-02 Thread via cfe-commits

llvmbot wrote:




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

Author: David Rivera (RiverDave)


Changes

Covered the edge case where an int expression is not necessarily directly 
wrapped around an ImplicitCastExpr which seemed to be a requirement in this 
check to trigger.

**For instance**:

```cpp
#include 

bool f() {
  std::vector v;
  unsigned int i = 0;

  return i >= v.size();
}
```
**See AST:**
![image](https://github.com/user-attachments/assets/9a52928a-f5a7-4857-aa69-90d978874578)

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


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp 
(+13-3) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
 (+26) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
index eeba5cce80da5..089df7ece3f82 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -39,9 +39,11 @@ intCastExpression(bool IsSigned,
   // std::cmp_{} functions trigger a compile-time error if either LHS or RHS
   // is a non-integer type, char, enum or bool
   // (unsigned char/ signed char are Ok and can be used).
-  auto IntTypeExpr = expr(hasType(hasCanonicalType(qualType(
+  const auto HasIntegerType = hasType(hasCanonicalType(qualType(
   isInteger(), IsSigned ? isSignedInteger() : isUnsignedInteger(),
-  unless(isActualChar()), unless(booleanType()), unless(enumType());
+  unless(isActualChar()), unless(booleanType()), unless(enumType();
+
+  auto IntTypeExpr = expr(HasIntegerType);
 
   const auto ImplicitCastExpr =
   CastBindName.empty() ? implicitCastExpr(hasSourceExpression(IntTypeExpr))
@@ -52,8 +54,16 @@ intCastExpression(bool IsSigned,
   const auto StaticCastExpr = cxxStaticCastExpr(has(ImplicitCastExpr));
   const auto FunctionalCastExpr = cxxFunctionalCastExpr(has(ImplicitCastExpr));
 
+  // Match function calls or variable references not wrapped by an implicit 
cast
+  const auto CallIntExpr = CastBindName.empty()
+   ? callExpr(HasIntegerType)
+   : callExpr(HasIntegerType).bind(CastBindName);
+  const auto DeclRefIntExpr =
+  CastBindName.empty() ? declRefExpr(HasIntegerType)
+   : declRefExpr(HasIntegerType).bind(CastBindName);
+
   return expr(anyOf(ImplicitCastExpr, CStyleCastExpr, StaticCastExpr,
-FunctionalCastExpr));
+FunctionalCastExpr, CallIntExpr));
 }
 
 static StringRef parseOpCode(BinaryOperator::Opcode Code) {
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6cb8d572d3a78..b5f2d8e8fcbd7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -177,6 +177,10 @@ Changes in existing checks
   matched scenarios of ``find`` and ``rfind`` methods and fixing false
   positives when those methods were called with 3 arguments.
 
+- Improved :doc:`modernize-use-integer-sign-comparison
+  ` check by matching
+  valid integer expressions not wrapped around an Implicit Cast.
+
 - Improved :doc:`modernize-use-std-numbers
   ` check to support math
   functions of different precisions.
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 99f00444c2d3f..1d2f64a359a2c 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
@@ -120,3 +120,29 @@ int AllComparisons() {
 
 return 0;
 }
+
+namespace PR127471 {
+int getSignedValue();
+unsigned int getUnsignedValue();
+
+void callExprTest() {
+
+if (getSignedValue() < getUnsignedValue())
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES:  if (std::cmp_less(getSignedValue() , getUnsignedValue()))
+
+int sVar = 0;
+if (getUnsignedValue() > sVar)
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: if (std::cmp_greater(getUnsignedValue() , sVar))
+
+unsigned int uVar = 0;
+if (getSignedValue() > uVar)
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: if (std::cmp_greater(ge

[clang-tools-extra] [clang-tidy] Improve integer comparison by matching valid expressions outside implicitCastExpr (PR #134188)

2025-04-02 Thread David Rivera via cfe-commits

https://github.com/RiverDave created 
https://github.com/llvm/llvm-project/pull/134188

Covered the edge case where an int expression is not necessarily directly 
wrapped around an ImplicitCastExpr which seemed to be a requirement in this 
check to trigger.

**For instance**:

```cpp
#include 

bool f() {
  std::vector v;
  unsigned int i = 0;

  return i >= v.size();
}
```
**See AST:**
![image](https://github.com/user-attachments/assets/9a52928a-f5a7-4857-aa69-90d978874578)

>From ebce879a943f5817aca4b0d3d637a17a626c9683 Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Wed, 2 Apr 2025 21:02:00 -0400
Subject: [PATCH] [clang-tidy] Improve integer comparison by matching valid
 expressions outside implicitCastExpr

---
 .../UseIntegerSignComparisonCheck.cpp | 16 +---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../modernize/use-integer-sign-comparison.cpp | 26 +++
 3 files changed, 43 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
index eeba5cce80da5..089df7ece3f82 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -39,9 +39,11 @@ intCastExpression(bool IsSigned,
   // std::cmp_{} functions trigger a compile-time error if either LHS or RHS
   // is a non-integer type, char, enum or bool
   // (unsigned char/ signed char are Ok and can be used).
-  auto IntTypeExpr = expr(hasType(hasCanonicalType(qualType(
+  const auto HasIntegerType = hasType(hasCanonicalType(qualType(
   isInteger(), IsSigned ? isSignedInteger() : isUnsignedInteger(),
-  unless(isActualChar()), unless(booleanType()), unless(enumType());
+  unless(isActualChar()), unless(booleanType()), unless(enumType();
+
+  auto IntTypeExpr = expr(HasIntegerType);
 
   const auto ImplicitCastExpr =
   CastBindName.empty() ? implicitCastExpr(hasSourceExpression(IntTypeExpr))
@@ -52,8 +54,16 @@ intCastExpression(bool IsSigned,
   const auto StaticCastExpr = cxxStaticCastExpr(has(ImplicitCastExpr));
   const auto FunctionalCastExpr = cxxFunctionalCastExpr(has(ImplicitCastExpr));
 
+  // Match function calls or variable references not wrapped by an implicit 
cast
+  const auto CallIntExpr = CastBindName.empty()
+   ? callExpr(HasIntegerType)
+   : callExpr(HasIntegerType).bind(CastBindName);
+  const auto DeclRefIntExpr =
+  CastBindName.empty() ? declRefExpr(HasIntegerType)
+   : declRefExpr(HasIntegerType).bind(CastBindName);
+
   return expr(anyOf(ImplicitCastExpr, CStyleCastExpr, StaticCastExpr,
-FunctionalCastExpr));
+FunctionalCastExpr, CallIntExpr));
 }
 
 static StringRef parseOpCode(BinaryOperator::Opcode Code) {
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6cb8d572d3a78..b5f2d8e8fcbd7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -177,6 +177,10 @@ Changes in existing checks
   matched scenarios of ``find`` and ``rfind`` methods and fixing false
   positives when those methods were called with 3 arguments.
 
+- Improved :doc:`modernize-use-integer-sign-comparison
+  ` check by matching
+  valid integer expressions not wrapped around an Implicit Cast.
+
 - Improved :doc:`modernize-use-std-numbers
   ` check to support math
   functions of different precisions.
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 99f00444c2d3f..1d2f64a359a2c 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
@@ -120,3 +120,29 @@ int AllComparisons() {
 
 return 0;
 }
+
+namespace PR127471 {
+int getSignedValue();
+unsigned int getUnsignedValue();
+
+void callExprTest() {
+
+if (getSignedValue() < getUnsignedValue())
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES:  if (std::cmp_less(getSignedValue() , getUnsignedValue()))
+
+int sVar = 0;
+if (getUnsignedValue() > sVar)
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: if (std::cmp_greater(getUnsignedValue() , sVar))
+
+unsigned int uVar = 0;
+if (getSignedValue() > uVar)
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsig

[clang] [CIR] Upstream support for break and continue statements (PR #134181)

2025-04-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Andy Kaylor (andykaylor)


Changes

This adds ClangIR support for break and continue statements in loops.

Because only loops are currently implemented upstream in CIR, only breaks in 
loops are supported here, but this same code will work (with minor changes to 
the verification and cfg flattening) when switch statements are upstreamed.

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


8 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h (+10) 
- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+29) 
- (modified) clang/include/clang/CIR/MissingFeatures.h (-2) 
- (modified) clang/lib/CIR/CodeGen/CIRGenFunction.h (+2) 
- (modified) clang/lib/CIR/CodeGen/CIRGenStmt.cpp (+23) 
- (modified) clang/lib/CIR/Dialect/IR/CIRDialect.cpp (+21) 
- (modified) clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp (+11-10) 
- (modified) clang/test/CIR/CodeGen/loop.cpp (+122) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index e666be0b25d75..900d78c401ebf 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -136,6 +136,16 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return create(loc, condBuilder, bodyBuilder, stepBuilder);
   }
 
+  /// Create a break operation.
+  cir::BreakOp createBreak(mlir::Location loc) {
+return create(loc);
+  }
+
+  /// Create a continue operation.
+  cir::ContinueOp createContinue(mlir::Location loc) {
+return create(loc);
+  }
+
   mlir::TypedAttr getConstPtrAttr(mlir::Type type, int64_t value) {
 auto valueAttr = mlir::IntegerAttr::get(
 mlir::IntegerType::get(type.getContext(), 64), value);
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 3965372755685..7ddf5e843bde2 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -569,6 +569,35 @@ def YieldOp : CIR_Op<"yield", [ReturnLike, Terminator,
   ];
 }
 
+//===--===//
+// BreakOp
+//===--===//
+
+def BreakOp : CIR_Op<"break", [Terminator]> {
+  let summary = "C/C++ `break` statement equivalent";
+  let description = [{
+The `cir.break` operation is used to cease the control flow to the parent
+operation, exiting its region's control flow. It is only allowed if it is
+within a breakable operation (loops and `switch`).
+  }];
+  let assemblyFormat = "attr-dict";
+  let hasVerifier = 1;
+}
+
+//===--===//
+// ContinueOp
+//===--===//
+
+def ContinueOp : CIR_Op<"continue", [Terminator]> {
+  let summary = "C/C++ `continue` statement equivalent";
+  let description = [{
+The `cir.continue` operation is used to continue execution to the next
+iteration of a loop. It is only allowed within `cir.loop` regions.
+  }];
+  let assemblyFormat = "attr-dict";
+  let hasVerifier = 1;
+}
+
 
//===--===//
 // ScopeOp
 
//===--===//
diff --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index 3a102d90aba8f..be16b5c063f3b 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -122,12 +122,10 @@ struct MissingFeatures {
 
   // Future CIR operations
   static bool awaitOp() { return false; }
-  static bool breakOp() { return false; }
   static bool callOp() { return false; }
   static bool complexCreateOp() { return false; }
   static bool complexImagOp() { return false; }
   static bool complexRealOp() { return false; }
-  static bool continueOp() { return false; }
   static bool ifOp() { return false; }
   static bool labelOp() { return false; }
   static bool ptrDiffOp() { return false; }
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h 
b/clang/lib/CIR/CodeGen/CIRGenFunction.h
index 5cae4d5da9516..c244e3752d7fe 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h
@@ -395,6 +395,8 @@ class CIRGenFunction : public CIRGenTypeCache {
 
   LValue emitBinaryOperatorLValue(const BinaryOperator *e);
 
+  mlir::LogicalResult emitBreakStmt(const clang::BreakStmt &s);
+  mlir::LogicalResult emitContinueStmt(const clang::ContinueStmt &s);
   mlir::LogicalResult emitDoStmt(const clang::DoStmt &s);
 
   /// Emit an expression as an initializer for an object (variable, field, 
etc.)
diff --git a/clang/lib/CIR/CodeGen/CIRGenStmt.cpp 
b/clang/lib/CIR/CodeGen/CIRGenStmt.c

[clang] [Clang] fixed clang frontend crash with friend class declaration and overload == (PR #133878)

2025-04-02 Thread Younan Zhang via cfe-commits

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


[clang] [Sema] Use llvm::erase_if (NFC) (PR #134017)

2025-04-02 Thread Kazu Hirata via cfe-commits

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


[clang] Reland [Clang][Cmake] fix libtool duplicate member name warnings (PR #133850)

2025-04-02 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/133850

>From cd2f6658a1a609edf7471f629b766eb4ee495122 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Sun, 30 Mar 2025 00:59:48 -0400
Subject: [PATCH 1/3] [Clang][Cmake] fix libtool duplicate member name warnings

fixes #133199

PR #132252 Created a second file that shared .cpp in 
`clang/lib/CodeGen/CMakeLists.txt`

For example There were two AMDGPU.cpp's one in TargetBuiltins and the
other in Targets. Even though these were in different directories
libtool warns that it might not distinguish them because they share the same 
base name.

There are two fixes. The easy fix is to rename one of them and keep one
cmake file. That solution though doesn't future proof this problem in
the event of a third .cpp and it seems teams want to
just use the target name
https://github.com/llvm/llvm-project/pull/132252#issuecomment-2758178483.

The alternative fix is to seperate the cmake files into their own sub
directories. I chose to create static libraries.  It might of been
possible to build an OBJECT, but I only saw examples of $
in compiler-rt and test directories so assumed there was a reason it wasn't 
used.
---
 clang/lib/CodeGen/CMakeLists.txt  | 49 +--
 clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp   |  2 +-
 .../lib/CodeGen/TargetBuiltins/CMakeLists.txt | 14 ++
 clang/lib/CodeGen/Targets/CMakeLists.txt  | 30 
 4 files changed, 57 insertions(+), 38 deletions(-)
 create mode 100644 clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt
 create mode 100644 clang/lib/CodeGen/Targets/CMakeLists.txt

diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index ebe2fbd7db295..cdf9f909a3675 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -116,45 +116,8 @@ add_clang_library(clangCodeGen
   PatternInit.cpp
   SanitizerMetadata.cpp
   SwiftCallingConv.cpp
-  TargetBuiltins/ARM.cpp
-  TargetBuiltins/AMDGPU.cpp
-  TargetBuiltins/Hexagon.cpp
-  TargetBuiltins/NVPTX.cpp
-  TargetBuiltins/PPC.cpp
-  TargetBuiltins/RISCV.cpp
-  TargetBuiltins/SPIR.cpp
-  TargetBuiltins/SystemZ.cpp
-  TargetBuiltins/WebAssembly.cpp
-  TargetBuiltins/X86.cpp
   TargetInfo.cpp
-  Targets/AArch64.cpp
-  Targets/AMDGPU.cpp
-  Targets/ARC.cpp
-  Targets/ARM.cpp
-  Targets/AVR.cpp
-  Targets/BPF.cpp
-  Targets/CSKY.cpp
-  Targets/DirectX.cpp
-  Targets/Hexagon.cpp
-  Targets/Lanai.cpp
-  Targets/LoongArch.cpp
-  Targets/M68k.cpp
-  Targets/MSP430.cpp
-  Targets/Mips.cpp
-  Targets/NVPTX.cpp
-  Targets/PNaCl.cpp
-  Targets/PPC.cpp
-  Targets/RISCV.cpp
-  Targets/SPIR.cpp
-  Targets/Sparc.cpp
-  Targets/SystemZ.cpp
-  Targets/TCE.cpp
-  Targets/VE.cpp
-  Targets/WebAssembly.cpp
-  Targets/X86.cpp
-  Targets/XCore.cpp
   VarBypassDetector.cpp
-
   DEPENDS
   vt_gen
   intrinsics_gen
@@ -170,4 +133,16 @@ add_clang_library(clangCodeGen
   clangFrontend
   clangLex
   clangSerialization
+  clangCodeGenTargetBuiltins
+  clangCodeGenTargets
+  )
+
+  target_include_directories(clangCodeGen
+PUBLIC
+${CMAKE_CURRENT_SOURCE_DIR}
+${CMAKE_CURRENT_SOURCE_DIR}/TargetBuiltins
+${CMAKE_CURRENT_SOURCE_DIR}/Targets
   )
+  
+  add_subdirectory(TargetBuiltins)
+  add_subdirectory(Targets)
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp 
b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index b56b739094ff3..577fee05d4af6 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -1,4 +1,4 @@
-//===--- AMDCPU.cpp - Emit LLVM Code for builtins 
-===//
+//===--- AMDGPU.cpp - Emit LLVM Code for builtins 
-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt 
b/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt
new file mode 100644
index 0..76be68a11d02a
--- /dev/null
+++ b/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt
@@ -0,0 +1,14 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_library(clangCodeGenTargetBuiltins STATIC
+  ARM.cpp
+  AMDGPU.cpp
+  Hexagon.cpp
+  NVPTX.cpp
+  PPC.cpp
+  RISCV.cpp
+  SPIR.cpp
+  SystemZ.cpp
+  WebAssembly.cpp
+  X86.cpp
+)
diff --git a/clang/lib/CodeGen/Targets/CMakeLists.txt 
b/clang/lib/CodeGen/Targets/CMakeLists.txt
new file mode 100644
index 0..6b6e7ce5b0b29
--- /dev/null
+++ b/clang/lib/CodeGen/Targets/CMakeLists.txt
@@ -0,0 +1,30 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_library(clangCodeGenTargets STATIC
+  AArch64.cpp
+  AMDGPU.cpp
+  ARC.cpp
+  ARM.cpp
+  AVR.cpp
+  BPF.cpp
+  CSKY.cpp
+  DirectX.cpp
+  Hexagon.cpp
+  Lanai.cpp
+  LoongArch.cpp
+  M68k.cpp
+  MSP430.cpp
+  Mips.cpp
+  NVPTX.cpp
+  PNaCl.cpp
+  PPC.cpp
+  RISCV.cpp
+  SPIR.cpp
+  Sparc.cpp
+  SystemZ.cpp
+  TCE.cpp
+  VE.cpp
+  WebAssem

[clang] [Clang] Fix a lambda pattern comparison mismatch after ecc7e6ce4 (PR #133863)

2025-04-02 Thread Younan Zhang via cfe-commits

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


[clang] b384d6d - [CodeGen] Don't include CGDebugInfo.h in CodeGenFunction.h (NFC) (#134100)

2025-04-02 Thread via cfe-commits

Author: Nikita Popov
Date: 2025-04-03T08:04:19+02:00
New Revision: b384d6d6ccc8f4452cd7086061c657ce76b41224

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

LOG: [CodeGen] Don't include CGDebugInfo.h in CodeGenFunction.h (NFC) (#134100)

This is an expensive header, only include it where needed. Move some
functions out of line to achieve that.

This reduces time to build clang by ~0.5% in terms of instructions
retired.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGCoroutine.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CGException.cpp
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/CodeGen/CGExprComplex.cpp
clang/lib/CodeGen/CGNonTrivialStruct.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/CodeGen/CGVTables.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/CodeGenPGO.cpp
clang/lib/CodeGen/CodeGenTypes.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/lib/CodeGen/TargetBuiltins/ARM.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 91ac7c5847b02..310addebd50e9 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -14,6 +14,7 @@
 #include "ABIInfo.h"
 #include "CGCUDARuntime.h"
 #include "CGCXXABI.h"
+#include "CGDebugInfo.h"
 #include "CGObjCRuntime.h"
 #include "CGOpenCLRuntime.h"
 #include "CGRecordLayout.h"

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 3cefa3b0c585c..b202255c3a15b 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -17,6 +17,7 @@
 #include "CGBlocks.h"
 #include "CGCXXABI.h"
 #include "CGCleanup.h"
+#include "CGDebugInfo.h"
 #include "CGRecordLayout.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"

diff  --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index a9795c2c0dc8f..0fc488e98aaf0 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -11,10 +11,11 @@
 
//===--===//
 
 #include "CGCleanup.h"
+#include "CGDebugInfo.h"
 #include "CodeGenFunction.h"
-#include "llvm/ADT/ScopeExit.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtVisitor.h"
+#include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
 using namespace CodeGen;

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 52aa956121d73..d659243d38d5f 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -6223,3 +6223,23 @@ CGDebugInfo::createConstantValueExpression(const 
clang::ValueDecl *VD,
 
   return nullptr;
 }
+
+CodeGenFunction::LexicalScope::LexicalScope(CodeGenFunction &CGF,
+SourceRange Range)
+: RunCleanupsScope(CGF), Range(Range), ParentScope(CGF.CurLexicalScope) {
+  CGF.CurLexicalScope = this;
+  if (CGDebugInfo *DI = CGF.getDebugInfo())
+DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin());
+}
+
+CodeGenFunction::LexicalScope::~LexicalScope() {
+  if (CGDebugInfo *DI = CGF.getDebugInfo())
+DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd());
+
+  // If we should perform a cleanup, force them now.  Note that
+  // this ends the cleanup scope before rescoping any labels.
+  if (PerformCleanup) {
+ApplyDebugLocation DL(CGF, Range.getEnd());
+ForceCleanup();
+  }
+}

diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 33c048b48795c..e0921993bd14e 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -11,6 +11,7 @@
 
//===--===//
 
 #include "CGCXXABI.h"
+#include "CGDebugInfo.h"
 #include "CGHLSLRuntime.h"
 #include "CGObjCRuntime.h"
 #include "CGOpenMPRuntime.h"

diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index b4b8c2952b02b..ebecb3aa5241d 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -12,6 +12,7 @@
 
 #include "CGCXXABI.h"
 #include "CGCleanup.h"
+#include "CGDebugInfo.h"
 #include "CGObjCRuntime.h"
 #include "CodeGenFunction.h"
 #include "ConstantEmitter.h"

diff  --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index c8bdda375d1b1..87b2a73fb0c03 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -11,6 +11,7 @@
 
//===--===//

[clang] [llvm] [HLSL] Implement dot2add intrinsic (PR #131237)

2025-04-02 Thread Farzon Lotfi via cfe-commits


@@ -45,6 +45,14 @@ distance_vec_impl(vector X, vector Y) {
   return length_vec_impl(X - Y);
 }
 
+constexpr float dot2add_impl(half2 a, half2 b, float c) {
+#if defined(__DIRECTX__)

farzonl wrote:

Also to answer your question we only need to do one or the other for spirv 
because the HLSL header is intended to be used with clang and clang will set 
both defines when some targets spriv.

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


[clang] Hlsl dst function (PR #133828)

2025-04-02 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify
+
+float4 test_too_many_arg(float4 p0)
+{
+dst(p0, p0, p0);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+}
+
+float4 test_no_second_arg(float4 p0)
+{
+return dst(p0);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+}
+
+float4 test_no_args()
+{
+return dst();
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+}
+
+float4 test_3_components(float3 p0, float3 p1)
+{
+return dst(p0, p1);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector<[...], 3>' to 'vector<[...], 4>' for 1st 
argument}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector' to 'vector' for 1st 
argument}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector' to 'vector' for 1st 
argument}}
+}
+
+float4 test_float2(double4 p0, float4 p1)

farzonl wrote:

the test name is not correct. this test does nothing with float2

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


[clang] c57b9c2 - [CIR] Generate the nsw flag correctly for unary ops (#133815)

2025-04-02 Thread via cfe-commits

Author: Andy Kaylor
Date: 2025-04-02T15:48:55-07:00
New Revision: c57b9c233a87f37e034445596ed09260cc6b23f5

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

LOG: [CIR] Generate the nsw flag correctly for unary ops (#133815)

A previous checkin used a workaround to generate the nsw flag where
needed for unary ops. This change upstreams a subsequent change that was
made in the incubator to generate the flag correctly.

Added: 
clang/test/CIR/IR/unary.cir

Modified: 
clang/include/clang/CIR/Dialect/IR/CIROps.td
clang/include/clang/CIR/MissingFeatures.h
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
clang/test/CIR/CodeGen/unary.cpp

Removed: 




diff  --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 3965372755685..c17abfd752a1a 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -697,17 +697,24 @@ def UnaryOp : CIR_Op<"unary", [Pure, 
SameOperandsAndResultType]> {
 It requires one input operand and has one result, both types
 should be the same.
 
+If the `nsw` (no signed wrap) attribute is present, the result is poison if
+signed overflow occurs.
+
 ```mlir
 %7 = cir.unary(inc, %1) : i32 -> i32
-%8 = cir.unary(dec, %2) : i32 -> i32
+%8 = cir.unary(dec, %2) nsw : i32 -> i32
 ```
   }];
 
   let results = (outs CIR_AnyType:$result);
-  let arguments = (ins Arg:$kind, 
Arg:$input);
+  let arguments = (ins Arg:$kind,
+   Arg:$input,
+   UnitAttr:$no_signed_wrap);
 
   let assemblyFormat = [{
-  `(` $kind `,` $input `)` `:` type($input) `,` type($result) attr-dict
+  `(` $kind `,` $input `)`
+  (`nsw` $no_signed_wrap^)?
+  `:` type($input) `,` type($result) attr-dict 
   }];
 
   let hasVerifier = 1;
@@ -961,9 +968,21 @@ def BinOp : CIR_Op<"binop", [Pure,
 It requires two input operands and has one result, all types
 should be the same.
 
+If the `nsw` (no signed wrap) or `nuw` (no unsigned wrap) attributes are
+present, the result is poison if signed or unsigned overflow occurs
+(respectively).
+
+If the `sat` (saturated) attribute is present, the result is clamped to
+the maximum value representatable by the type if it would otherwise
+exceed that value and is clamped to the minimum representable value if
+it would otherwise be below that value.
+
 ```mlir
-%7 = cir.binop(add, %1, %2) : !s32i
-%7 = cir.binop(mul, %1, %2) : !u8i
+%5 = cir.binop(add, %1, %2) : !s32i
+%6 = cir.binop(mul, %1, %2) : !u8i
+%7 = cir.binop(add, %1, %2) nsw : !s32i
+%8 = cir.binop(add, %3, %4) nuw : !u32i
+%9 = cir.binop(add, %1, %2) sat : !s32i
 ```
   }];
 

diff  --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index 3a102d90aba8f..23bf826d19a69 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -76,7 +76,6 @@ struct MissingFeatures {
   static bool opScopeCleanupRegion() { return false; }
 
   // Unary operator handling
-  static bool opUnarySignedOverflow() { return false; }
   static bool opUnaryPromotionType() { return false; }
 
   // Clang early optimizations or things defered to LLVM lowering.

diff  --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 2cf92dfbf3a5b..5ac1dc1052c2e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -374,7 +374,7 @@ class ScalarExprEmitter : public 
StmtVisitor {
 cir::UnaryOpKind kind =
 e->isIncrementOp() ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec;
 // NOTE(CIR): clang calls CreateAdd but folds this to a unary op
-value = emitUnaryOp(e, kind, input);
+value = emitUnaryOp(e, kind, input, /*nsw=*/false);
   }
 } else if (isa(type)) {
   cgf.cgm.errorNYI(e->getSourceRange(), "Unary inc/dec pointer");
@@ -429,19 +429,17 @@ class ScalarExprEmitter : public 
StmtVisitor {
   mlir::Value emitIncDecConsiderOverflowBehavior(const UnaryOperator *e,
  mlir::Value inVal,
  bool isInc) {
-assert(!cir::MissingFeatures::opUnarySignedOverflow());
 cir::UnaryOpKind kind =
 e->isIncrementOp() ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec;
 switch (cgf.getLangOpts().getSignedOverflowBehavior()) {
 case LangOptions::SOB_Defined:
-  return emitUnaryOp(e, kind, inVal);
+  return emitUnaryOp(e, kind, inVal, /*nsw=*/false);
 case LangOptions::SOB_Undefined:

[clang] [clang-tools-extra] [clang] support pack expansions for trailing requires clauses (PR #133190)

2025-04-02 Thread via cfe-commits


@@ -7379,8 +7378,11 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const 
NamedDecl *Y) const {
   return false;
 }
 
-if (!isSameConstraintExpr(FuncX->getTrailingRequiresClause(),

cor3ntin wrote:

Can we add an overload, at least + comment?

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


[clang] [clang][NFC] Refactor CodeGen's hasBooleanRepresentation (PR #134159)

2025-04-02 Thread Andy Kaylor via cfe-commits

https://github.com/andykaylor created 
https://github.com/llvm/llvm-project/pull/134159

The ClangIR upstreaming project needs the same logic for 
hasBooleanRepresentation() that is currently implemented in the standard clang 
codegen. In order to share this code, this change moves the implementation of 
this function into the AST Type class.

No functional change is intended by this change. The ClangIR use of this 
function will be added separately in a later change.

>From 3f0fe2316040c114c6637545ae8fd0463dbe2b94 Mon Sep 17 00:00:00 2001
From: Andy Kaylor 
Date: Wed, 2 Apr 2025 14:32:27 -0700
Subject: [PATCH] [clang][NFC] Refactor CodeGen's hasBooleanRepresentation

The ClangIR upstreaming project needs the same logic for
hasBooleanRepresentation() that is currently implemented in
the standard clang codegen. In order to share this code, this
change moves the implementation of this function into the AST
Type class.

No functional change is intended by this change. The ClangIR
use of this function will be added separately in a later change.
---
 clang/include/clang/AST/Type.h |  4 
 clang/lib/AST/Type.cpp | 13 +
 clang/lib/CodeGen/CGExpr.cpp   | 23 +--
 3 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a809102c069a8..c38250a13a6e7 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2769,6 +2769,10 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   /// of some sort, e.g., it is a floating-point type or a vector thereof.
   bool hasFloatingRepresentation() const;
 
+  /// Determine whether this type has a boolean representation
+  /// of some sort.
+  bool hasBooleanRepresentation() const;
+
   // Type Checking Functions: Check to see if this type is structurally the
   // specified type, ignoring typedefs and qualifiers, and return a pointer to
   // the best type we can.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 08798219c0b83..42fec3a13cf2f 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2334,6 +2334,19 @@ bool Type::isArithmeticType() const {
   return isa(CanonicalType) || isBitIntType();
 }
 
+bool Type::hasBooleanRepresentation() const {
+  if (isBooleanType())
+return true;
+
+  if (const EnumType *ET = getAs())
+return ET->getDecl()->getIntegerType()->isBooleanType();
+
+  if (const AtomicType *AT = getAs())
+return AT->getValueType()->hasBooleanRepresentation();
+
+  return false;
+}
+
 Type::ScalarTypeKind Type::getScalarTypeKind() const {
   assert(isScalarType());
 
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 3d3a111f0514a..1bde01490a428 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -1893,19 +1893,6 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(LValue 
lvalue,
   lvalue.getTBAAInfo(), lvalue.isNontemporal());
 }
 
-static bool hasBooleanRepresentation(QualType Ty) {
-  if (Ty->isBooleanType())
-return true;
-
-  if (const EnumType *ET = Ty->getAs())
-return ET->getDecl()->getIntegerType()->isBooleanType();
-
-  if (const AtomicType *AT = Ty->getAs())
-return hasBooleanRepresentation(AT->getValueType());
-
-  return false;
-}
-
 static bool getRangeForType(CodeGenFunction &CGF, QualType Ty,
 llvm::APInt &Min, llvm::APInt &End,
 bool StrictEnums, bool IsBool) {
@@ -1928,7 +1915,7 @@ static bool getRangeForType(CodeGenFunction &CGF, 
QualType Ty,
 llvm::MDNode *CodeGenFunction::getRangeForLoadFromType(QualType Ty) {
   llvm::APInt Min, End;
   if (!getRangeForType(*this, Ty, Min, End, CGM.getCodeGenOpts().StrictEnums,
-   hasBooleanRepresentation(Ty)))
+   Ty->hasBooleanRepresentation()))
 return nullptr;
 
   llvm::MDBuilder MDHelper(getLLVMContext());
@@ -1942,7 +1929,7 @@ bool CodeGenFunction::EmitScalarRangeCheck(llvm::Value 
*Value, QualType Ty,
   if (!HasBoolCheck && !HasEnumCheck)
 return false;
 
-  bool IsBool = hasBooleanRepresentation(Ty) ||
+  bool IsBool = Ty->hasBooleanRepresentation() ||
 NSAPI(CGM.getContext()).isObjCBOOLType(Ty);
   bool NeedsBoolCheck = HasBoolCheck && IsBool;
   bool NeedsEnumCheck = HasEnumCheck && Ty->getAs();
@@ -2070,7 +2057,7 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(Address 
Addr, bool Volatile,
 /// by ConvertType) to its load/store type (as returned by
 /// convertTypeForLoadStore).
 llvm::Value *CodeGenFunction::EmitToMemory(llvm::Value *Value, QualType Ty) {
-  if (hasBooleanRepresentation(Ty) || Ty->isBitIntType()) {
+  if (Ty->hasBooleanRepresentation() || Ty->isBitIntType()) {
 llvm::Type *StoreTy = convertTypeForLoadStore(Ty, Value->getType());
 bool Signed = Ty->isSignedIntegerOrEnumerationType();
 return Builder.CreateIntCast(Value, StoreTy, Signed, "storedv");
@

[clang] Hlsl dst function (PR #133828)

2025-04-02 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify
+
+float4 test_too_many_arg(float4 p0)
+{
+dst(p0, p0, p0);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+}
+
+float4 test_no_second_arg(float4 p0)
+{
+return dst(p0);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+}
+
+float4 test_no_args()
+{
+return dst();
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+}
+
+float4 test_3_components(float3 p0, float3 p1)
+{
+return dst(p0, p1);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector<[...], 3>' to 'vector<[...], 4>' for 1st 
argument}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector' to 'vector' for 1st 
argument}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector' to 'vector' for 1st 
argument}}
+}

farzonl wrote:

@metkarpoonam this is my bad the exports are only needed in godbolt. I didn't 
intend for you to add them in these test cases. I appolgize. 

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


[clang] Hlsl dst function (PR #133828)

2025-04-02 Thread via cfe-commits

https://github.com/metkarpoonam updated 
https://github.com/llvm/llvm-project/pull/133828

>From 3a45246453d120da108e597d23da0fb8d9df0b1b Mon Sep 17 00:00:00 2001
From: Poonam Vilas Metkar 
Date: Mon, 31 Mar 2025 16:49:18 -0700
Subject: [PATCH 1/7] Implement a dst function with test cases for HLSL codegen
 and sema

---
 .../lib/Headers/hlsl/hlsl_intrinsic_helpers.h |  6 +++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 25 ++
 clang/test/CodeGenHLSL/builtins/dst.hlsl  | 48 +++
 clang/test/SemaHLSL/BuiltIns/dst-error.hlsl   | 37 ++
 4 files changed, 116 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/dst.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/dst-error.hlsl

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
index 8cdd63d7e07bb..5ea8faf169380 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
@@ -35,6 +35,12 @@ length_vec_impl(vector X) {
 #endif
 }
 
+template 
+constexpr vector dst_impl(vector src0, vector src1) {
+  vector dest = {1, src0[1] * src1[1], src0[2], src1[3]};
+  return dest;
+}
+
 template  constexpr T distance_impl(T X, T Y) {
   return length_impl(X - Y);
 }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index fd799b8d874ae..7ae94731234f9 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -174,6 +174,31 @@ const inline float 
distance(__detail::HLSL_FIXED_VECTOR X,
 __detail::HLSL_FIXED_VECTOR Y) {
   return __detail::distance_vec_impl(X, Y);
 }
+//===--===//
+// dst builtins
+//===--===//
+
+/// \fn fvector dst( fvector, fvector)
+/// \brief Returns the length of a vector
+/// \param src0 [in] The first vector contain {_, d*d, d*d, _}
+/// \param src1 [in] The second vector contain {_, 1/d, _, 1/d}
+///
+/// Return the computed distance vector contain {1, d, d*d, 1/d}
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+const inline vector dst(vector src0, vector src1) {
+  return __detail::dst_impl(src0, src1);
+}
+
+const inline vector dst(vector src0,
+  vector src1) {
+  return __detail::dst_impl(src0, src1);
+}
+
+const inline vector dst(vector src0,
+   vector src1) {
+  return __detail::dst_impl(src0, src1);
+}
 
 
//===--===//
 // fmod builtins
diff --git a/clang/test/CodeGenHLSL/builtins/dst.hlsl 
b/clang/test/CodeGenHLSL/builtins/dst.hlsl
new file mode 100644
index 0..c62c9be5b0c1d
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/dst.hlsl
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.2-library %s -fnative-half-type -emit-llvm -O1 -o - | 
FileCheck %s
+
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x float> 
@_Z12dstWithFloatDv4_fS_(
+// CHECK-SAME: <4 x float> noundef nofpclass(nan inf) [[P:%.*]], <4 x float> 
noundef nofpclass(nan inf) [[Q:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { 
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[VECEXT:%.*]] = extractelement <4 x float> [[P]], i64 1
+// CHECK-NEXT: [[VECEXT1:%.*]] = extractelement <4 x float> [[Q]], i64 1
+// CHECK-NEXT: [[MULRES:%.*]] = fmul reassoc nnan ninf nsz arcp afn float 
[[VECEXT1]], [[VECEXT]]
+// CHECK-NEXT: [[VECINIT:%.*]] = insertelement <4 x float> , float [[MULRES]], i64 1
+// CHECK-NEXT: [[VECINIT3:%.*]] = shufflevector <4 x float> [[VECINIT]], <4 x 
float> [[P]], <4 x i32> 
+// CHECK-NEXT: [[VECINIT5:%.*]] = shufflevector <4 x float> [[VECINIT3]], <4 x 
float> [[Q]], <4 x i32> 
+// CHECK-NEXT: ret <4 x float> [[VECINIT5]]
+
+float4 dstWithFloat(float4 p1, float4 p2)
+{
+return dst(p1, p2);
+}
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x half> 
@_Z11dstwithHalfDv4_DhS_(
+// CHECK-SAME: <4 x half> noundef nofpclass(nan inf) [[P:%.*]], <4 x half> 
noundef nofpclass(nan inf) [[Q:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[VECEXT:%.*]] = extractelement <4 x half> [[P]], i64 1
+// CHECK-NEXT: [[VECEXT1:%.*]] = extractelement <4 x half> [[Q]], i64 1
+// CHECK-NEXT: [[MULRES:%.*]] = fmul reassoc nnan ninf nsz arcp afn half 
[[VECEXT1]], [[VECEXT]]
+// CHECK-NEXT: [[VECINIT:%.*]] = insertelement <4 x half> , half [[MULRES]], i64 1
+// CHECK-NEXT: [[VECINIT3:%.*]] = shufflevector <4 x half> [[VECINIT]], <4 x 
half> [[P]], <4 x i32> 
+// CHECK-NEXT: [[VECINIT5:%.*]] = shufflevector <4 x half> [[VECINIT3]], <4 x 
half> [[Q]], <4 x i32> 
+// CHECK-NEXT: ret <4 x half> [[VECINIT5]]
+half4 dstwithHalf(half4 p1, half4 p2)
+{
+return dst(p1, p2);
+}
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x double>

[clang] Hlsl dst function (PR #133828)

2025-04-02 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify
+
+float4 test_too_many_arg(float4 p0)
+{
+dst(p0, p0, p0);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+}
+
+float4 test_no_second_arg(float4 p0)
+{
+return dst(p0);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+}
+
+float4 test_no_args()
+{
+return dst();
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+}
+
+float4 test_3_components(float3 p0, float3 p1)
+{
+return dst(p0, p1);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector<[...], 3>' to 'vector<[...], 4>' for 1st 
argument}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector' to 'vector' for 1st 
argument}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector' to 'vector' for 1st 
argument}}
+}
+
+float4 test_float2(double4 p0, float4 p1)
+{
+return dst(p0, p1);
+  // expected-error@-1 {{call to 'dst' is ambiguous}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
+}
+
+float2 test_float2(float4 p0, float4 p1)

farzonl wrote:

this test name is not descriptive. 

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


[clang] [clang] Fix crash on invalid `std::initializer_list` template-id (PR #132284)

2025-04-02 Thread via cfe-commits

https://github.com/offsetof updated 
https://github.com/llvm/llvm-project/pull/132284

>From 553ced1e367c0ec6399e71e7a3a3685a550f3431 Mon Sep 17 00:00:00 2001
From: offsetof 
Date: Thu, 20 Mar 2025 20:54:45 +
Subject: [PATCH 1/2] [clang] Fix crash on invalid `std::initializer_list`
 template-id

In `Sema::BuildStdInitializerList`, check that the synthesized
template-id `std::initializer_list` is valid (which might not be the
case if the template has associated constraints or subsequent parameters
with default arguments) before forming the type.
---
 clang/lib/Sema/SemaDeclCXX.cpp |  8 ++--
 .../test/SemaCXX/invalid-std-initializer-list.cpp  | 14 ++
 2 files changed, 20 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/invalid-std-initializer-list.cpp

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 7b2e0df8cb55d..54f7bc9a3b021 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -12182,10 +12182,14 @@ QualType Sema::BuildStdInitializerList(QualType 
Element, SourceLocation Loc) {
   Args.addArgument(TemplateArgumentLoc(TemplateArgument(Element),

Context.getTrivialTypeSourceInfo(Element,
 Loc)));
+
+  QualType T = CheckTemplateIdType(TemplateName(StdInitializerList), Loc, 
Args);
+  if (T.isNull())
+return QualType();
+
   return Context.getElaboratedType(
   ElaboratedTypeKeyword::None,
-  NestedNameSpecifier::Create(Context, nullptr, getStdNamespace()),
-  CheckTemplateIdType(TemplateName(StdInitializerList), Loc, Args));
+  NestedNameSpecifier::Create(Context, nullptr, getStdNamespace()), T);
 }
 
 bool Sema::isInitListConstructor(const FunctionDecl *Ctor) {
diff --git a/clang/test/SemaCXX/invalid-std-initializer-list.cpp 
b/clang/test/SemaCXX/invalid-std-initializer-list.cpp
new file mode 100644
index 0..080a712759c45
--- /dev/null
+++ b/clang/test/SemaCXX/invalid-std-initializer-list.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -verify -std=c++20
+
+namespace std {
+
+template // expected-error 2 {{type 'int' cannot be 
used prior to '::' because it has no members}}
+class initializer_list;
+
+}
+
+auto x = {1}; // expected-note {{in instantiation of default argument for 
'initializer_list' required here}}
+
+void f() {
+   for(int x : {1, 2}); // expected-note {{in instantiation of default 
argument for 'initializer_list' required here}}
+}

>From bd5c32e5716d32a0134d99a6b16bb5cd3039f655 Mon Sep 17 00:00:00 2001
From: offsetof 
Date: Mon, 24 Mar 2025 15:58:36 +
Subject: [PATCH 2/2] fixup! [clang] Fix crash on invalid
 `std::initializer_list` template-id

---
 clang/docs/ReleaseNotes.rst | 1 +
 clang/test/SemaCXX/invalid-std-initializer-list.cpp | 4 
 2 files changed, 5 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 159991e8db981..f1b4310134702 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -357,6 +357,7 @@ Bug Fixes to C++ Support
 - Fixed a Clang regression in C++20 mode where unresolved dependent call 
expressions were created inside non-dependent contexts (#GH122892)
 - Clang now emits the ``-Wunused-variable`` warning when some structured 
bindings are unused
   and the ``[[maybe_unused]]`` attribute is not applied. (#GH125810)
+- Fixed a crash caused by invalid declarations of ``std::initializer_list``. 
(#GH132256)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/test/SemaCXX/invalid-std-initializer-list.cpp 
b/clang/test/SemaCXX/invalid-std-initializer-list.cpp
index 080a712759c45..93246b5f03fd4 100644
--- a/clang/test/SemaCXX/invalid-std-initializer-list.cpp
+++ b/clang/test/SemaCXX/invalid-std-initializer-list.cpp
@@ -7,8 +7,12 @@ class initializer_list;
 
 }
 
+namespace gh132256 {
+
 auto x = {1}; // expected-note {{in instantiation of default argument for 
'initializer_list' required here}}
 
 void f() {
for(int x : {1, 2}); // expected-note {{in instantiation of default 
argument for 'initializer_list' required here}}
 }
+
+}

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


[clang] a0e1e68 - [clang][bytecode] Return Invalid() on non-constexpr builtins (#133700)

2025-04-02 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-31T18:53:12+02:00
New Revision: a0e1e680d28c4ef5f87be948d1d223fbfda2950c

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

LOG: [clang][bytecode] Return Invalid() on non-constexpr builtins (#133700)

So the diagnostic output matches with the current interpreter

Added: 


Modified: 
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/test/AST/ByteCode/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 4d125e4c202d2..3029314ddbad8 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2125,7 +2125,7 @@ static bool interp__builtin_memchr(InterpState &S, 
CodePtr OpPC,
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call, uint32_t BuiltinID) {
   if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
-return false;
+return Invalid(S, OpPC);
 
   const InterpFrame *Frame = S.Current;
 

diff  --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 8408286314bb8..40f7a18119751 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1591,3 +1591,12 @@ namespace WMemChr {
   constexpr bool c = !wcschr(L"hello", L'h'); // both-error {{constant 
expression}} \
   // both-note {{non-constexpr 
function 'wcschr' cannot be used in a constant expression}}
 }
+
+namespace Invalid {
+  constexpr int test() { // both-error {{never produces a constant expression}}
+__builtin_abort(); // both-note 2{{subexpression not valid in a constant 
expression}}
+return 0;
+  }
+  static_assert(test() == 0); // both-error {{not an integral constant 
expression}} \
+  // both-note {{in call to}}
+}



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


[clang] [clang] remove unused frontend flag -fretain_subst_template_type_parm_type_ast_nodes (PR #134177)

2025-04-02 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/134177

This is a follow-up to #132748, where we deferred the flag removal in order to 
ease transition for external users.

The plan is to merge this in the nearish future, in two weeks or so is my best 
guess.

>From 4526115a6afbd5bb78b7ee11b9ff8c9f137fcdab Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 2 Apr 2025 17:47:17 -0300
Subject: [PATCH] [clang] remove unused frontend flag
 -fretain_subst_template_type_parm_type_ast_nodes

This is a folow-up to #132748, where we deferred the flag removal
in order to ease transition for external users.
---
 clang/include/clang/Basic/LangOptions.def | 1 -
 clang/include/clang/Driver/Options.td | 6 --
 2 files changed, 7 deletions(-)

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 3879cc7942877..930c1c06d1a76 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -161,7 +161,6 @@ LANGOPT(Coroutines, 1, 0, "C++20 coroutines")
 LANGOPT(CoroAlignedAllocation, 1, 0, "prefer Aligned Allocation according to 
P2014 Option 2")
 LANGOPT(DllExportInlines  , 1, 1, "dllexported classes dllexport inline 
methods")
 LANGOPT(ExperimentalLibrary, 1, 0, "enable unstable and experimental library 
features")
-LANGOPT(RetainSubstTemplateTypeParmTypeAstNodes, 1, 0, "retain 
SubstTemplateTypeParmType nodes in the AST's representation of alias template 
specializations")
 
 LANGOPT(PointerAuthIntrinsics, 1, 0, "pointer authentication intrinsics")
 LANGOPT(PointerAuthCalls  , 1, 0, "function pointer authentication")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e69b804de63b5..f8b59d5c6e4aa 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3508,12 +3508,6 @@ defm application_extension : 
BoolFOption<"application-extension",
   PosFlag,
   NegFlag>;
-defm retain_subst_template_type_parm_type_ast_nodes : 
BoolFOption<"retain-subst-template-type-parm-type-ast-nodes",
-  LangOpts<"RetainSubstTemplateTypeParmTypeAstNodes">, DefaultFalse,
-  PosFlag,
-  NegFlag,
-  BothFlags<[], [], " retain SubstTemplateTypeParmType nodes in the AST's 
representation"
-  " of alias template specializations">>;
 defm sized_deallocation : BoolFOption<"sized-deallocation",
   LangOpts<"SizedDeallocation">, Default,
   PosFlag,

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


[clang] [SYCL][SPIR-V Backend][clang-sycl-linker] Add SPIR-V backend support inside clang-sycl-linker (PR #133967)

2025-04-02 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-ppc64-aix` running 
on `aix-ppc64` while building `clang` at step 6 
"test-build-unified-tree-check-all".

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


Here is the relevant piece of the build log for the reference

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'Clang :: ClangScanDeps/verbose.test' FAILED 

Exit Code: 1

Command Output (stderr):
--
rm -rf 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp
 # RUN: at line 1
+ rm -rf 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp
split-file 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/ClangScanDeps/verbose.test
 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp
 # RUN: at line 2
+ split-file 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/ClangScanDeps/verbose.test
 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp
sed -e 
"s|DIR|/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp|g"
 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/cdb.json.in
 > 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/cdb.json
 # RUN: at line 3
+ sed -e 
's|DIR|/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp|g'
 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/cdb.json.in
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/bin/clang-scan-deps
 -compilation-database 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/cdb.json
 -v -o 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/result.json
 2>&1 | 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/bin/FileCheck
 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/ClangScanDeps/verbose.test
 # RUN: at line 5
+ 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/bin/clang-scan-deps
 -compilation-database 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/cdb.json
 -v -o 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/test/ClangScanDeps/Output/verbose.test.tmp/result.json
+ 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/bin/FileCheck
 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/ClangScanDeps/verbose.test
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/ClangScanDeps/verbose.test:6:11:
 error: CHECK: expected string not found in input
// CHECK: *** Virtual File System Stats:
  ^
:1:1: note: scanning from here
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace.
^
:1:8: note: possible intended match here
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace.
   ^

Input file: 
Check file: 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/test/ClangScanDeps/verbose.test

-dump-input=help explains the following input dump.

Input was:
<<
   1: PLEASE submit a bug report to 
https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. 
check:6'0 
X~~~
 error: no match found
check:6'1?  
   possible intended match
>>

--




```



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


[clang] [Clang][OpenCL][AMDGPU] Allow a kernel to call another kernel (PR #115821)

2025-04-02 Thread Aniket Lal via cfe-commits

lalaniket8 wrote:

pinging for review @arsenm @yxsamliu @rjmccall 

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


[clang] [llvm] [HLSL] Implement dot2add intrinsic (PR #131237)

2025-04-02 Thread Farzon Lotfi via cfe-commits

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


[clang] [Clang][CodeGen][UBSan] Add more precise attributes to recoverable ubsan handlers (PR #130990)

2025-04-02 Thread Eli Friedman via cfe-commits

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

LGTM

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


[clang] f302f35 - [clang] Track final substitution for Subst* AST nodes (#132748)

2025-04-02 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2025-04-02T19:27:29-03:00
New Revision: f302f35526553abcb46dab278c4494c3d01deb45

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

LOG: [clang] Track final substitution for Subst* AST nodes (#132748)

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/PropertiesBase.td
clang/include/clang/AST/TemplateName.h
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/TemplateName.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/TreeTransform.h
clang/test/AST/ast-dump-template-decls.cpp
clang/test/Misc/diag-template-diffing-cxx11.cpp
clang/test/SemaTemplate/make_integer_seq.cpp

Removed: 
clang/test/AST/ast-dump-retain-subst-template-type-parm-type-ast-nodes.cpp



diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a24f30815e6b9..b3010fa888fa4 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1795,10 +1795,10 @@ class ASTContext : public RefCountedBase {
   QualType Wrapped, QualType Contained,
   const HLSLAttributedResourceType::Attributes &Attrs);
 
-  QualType
-  getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
-   unsigned Index,
-   std::optional PackIndex) const;
+  QualType getSubstTemplateTypeParmType(QualType Replacement,
+Decl *AssociatedDecl, unsigned Index,
+std::optional PackIndex,
+bool Final) const;
   QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl,
 unsigned Index, bool Final,
 const TemplateArgument &ArgPack);
@@ -2393,10 +2393,11 @@ class ASTContext : public RefCountedBase {
   TemplateName
   getDependentTemplateName(const DependentTemplateStorage &Name) const;
 
-  TemplateName
-  getSubstTemplateTemplateParm(TemplateName replacement, Decl *AssociatedDecl,
-   unsigned Index,
-   std::optional PackIndex) const;
+  TemplateName getSubstTemplateTemplateParm(TemplateName replacement,
+Decl *AssociatedDecl,
+unsigned Index,
+std::optional PackIndex,
+bool Final) const;
   TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument 
&ArgPack,
 Decl *AssociatedDecl,
 unsigned Index,

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 223d74993e9e6..028ee82718d50 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -4514,7 +4514,9 @@ class SubstNonTypeTemplateParmExpr : public Expr {
   llvm::PointerIntPair AssociatedDeclAndRef;
 
   unsigned Index : 15;
-  unsigned PackIndex : 16;
+  unsigned PackIndex : 15;
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned Final : 1;
 
   explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
   : Expr(SubstNonTypeTemplateParmExprClass, Empty) {}
@@ -4523,11 +4525,12 @@ class SubstNonTypeTemplateParmExpr : public Expr {
   SubstNonTypeTemplateParmExpr(QualType Ty, ExprValueKind ValueKind,
SourceLocation Loc, Expr *Replacement,
Decl *AssociatedDecl, unsigned Index,
-   std::optional PackIndex, bool 
RefParam)
+   std::optional PackIndex, bool 
RefParam,
+   bool Final)
   : Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary),
 Replacement(Replacement),
 AssociatedDeclAndRef(AssociatedDecl, RefParam), Index(Index),
-PackIndex(PackIndex ? *PackIndex + 1 : 0) {
+PackIndex(PackIndex ? *PackIndex + 1 : 0), Final(Final) {
 assert(AssociatedDecl != nullptr);
 SubstNonTypeTemplateParmExprBits.NameLoc = Loc;
 setDependence(computeDependence(this));
@@ -4555,6 +4558,10 @@ class SubstNonTypeTemplateParmExpr : public Expr {
 return PackIndex - 1;
   }
 
+  // This substitution is Final, which means the substitution is fully
+  // sugared: it doesn't need to be res

[clang] [clang] Track final substitution for Subst* AST nodes (PR #132748)

2025-04-02 Thread Matheus Izvekov via cfe-commits

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


[clang] [HLSL] Make it possible to assign an array from a cbuffer (PR #134174)

2025-04-02 Thread Sarah Spall via cfe-commits

https://github.com/spall created 
https://github.com/llvm/llvm-project/pull/134174

Update Sema Checking to always do an HLSL Array RValue cast in the case we are 
dealing with hlsl constant array types
Instead of comparing canonical types, compare canonical unqualified types
Add a test to show it is possible to assign an array from a cbuffer.
Closes #133767

>From 11ecff90d8d51bce41bc8063afb31bd27e3981cc Mon Sep 17 00:00:00 2001
From: Sarah Spall 
Date: Wed, 2 Apr 2025 12:04:18 -0700
Subject: [PATCH] compare unqualified canonical types and add an hlsl array
 rvalue cast

---
 clang/lib/Sema/SemaExprCXX.cpp  | 13 +++--
 clang/lib/Sema/SemaOverload.cpp | 10 --
 clang/test/CodeGenHLSL/ArrayAssignable.hlsl | 20 
 3 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index fa492bc124abd..17e9311a631f7 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4418,19 +4418,12 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   case ICK_HLSL_Array_RValue:
 if (ToType->isArrayParameterType()) {
   FromType = Context.getArrayParameterType(FromType);
-  From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
-   /*BasePath=*/nullptr, CCK)
- .get();
-} else { // FromType must be ArrayParameterType
-  assert(FromType->isArrayParameterType() &&
- "FromType must be ArrayParameterType in ICK_HLSL_Array_RValue \
-  if it is not ToType");
+} else if (FromType->isArrayParameterType()) {
   const ArrayParameterType *APT = cast(FromType);
   FromType = APT->getConstantArrayType(Context);
-  From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
-   /*BasePath=*/nullptr, CCK)
- .get();
 }
+  From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
+  /*BasePath=*/nullptr, CCK).get();
 break;
 
   case ICK_Function_To_Pointer:
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1802f8f4e1f91..950114046fe5e 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2268,17 +2268,15 @@ static bool IsStandardConversion(Sema &S, Expr* From, 
QualType ToType,
 // handling here.
 if (ToType->isArrayParameterType()) {
   FromType = S.Context.getArrayParameterType(FromType);
-  SCS.First = ICK_HLSL_Array_RValue;
 } else if (FromType->isArrayParameterType()) {
   const ArrayParameterType *APT = cast(FromType);
   FromType = APT->getConstantArrayType(S.Context);
-  SCS.First = ICK_HLSL_Array_RValue;
-} else {
-  SCS.First = ICK_Identity;
 }
 
-if (S.Context.getCanonicalType(FromType) !=
-S.Context.getCanonicalType(ToType))
+SCS.First = ICK_HLSL_Array_RValue;
+
+if (FromType.getCanonicalType().getUnqualifiedType() !=
+   ToType.getCanonicalType().getUnqualifiedType())
   return false;
 
 SCS.setAllToTypes(ToType);
diff --git a/clang/test/CodeGenHLSL/ArrayAssignable.hlsl 
b/clang/test/CodeGenHLSL/ArrayAssignable.hlsl
index e2ff2de68ed99..ce806e1492d80 100644
--- a/clang/test/CodeGenHLSL/ArrayAssignable.hlsl
+++ b/clang/test/CodeGenHLSL/ArrayAssignable.hlsl
@@ -1,5 +1,13 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s --enable-var-scope
 
+
+//CHECK-DAG: [[CBLayout:%.*]] = type <{ [2 x float] }>
+//CHECK-DAG: @CBArrays.cb = global target("dx.CBuffer", target("dx.Layout", 
[[CBLayout]], 20, 0)) poison
+//CHECK-DAG: @c1 = external addrspace(2) global [2 x float], align 4
+cbuffer CBArrays {
+  float c1[2];
+}
+
 // CHECK-LABEL: define void {{.*}}arr_assign1
 // CHECK: [[Arr:%.*]] = alloca [2 x i32], align 4
 // CHECK-NEXT: [[Arr2:%.*]] = alloca [2 x i32], align 4
@@ -116,3 +124,15 @@ void arr_assign7() {
   int Arr2[2][2] = {{0, 0}, {1, 1}};
   (Arr = Arr2)[0] = {6, 6};
 }
+
+// Verify you can assign from a cbuffer array
+
+// CHECK-LABEL: define void {{.*}}arr_assign8
+// CHECK: [[C:%.*]] = alloca [2 x float], align 4
+// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[C]], ptr align 4 
{{.*}}, i32 8, i1 false)
+// CHECK-NEXT: call void @llvm.memcpy.p0.p2.i32(ptr align 4 [[C]], ptr 
addrspace(2) align 4 @c1, i32 8, i1 false)
+// CHECK-NEXT: ret void
+void arr_assign8() {
+  float C[2] = {1.0, 2.0};
+  C = c1;
+}
\ No newline at end of file

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


[clang] [HLSL] Make it possible to assign an array from a cbuffer (PR #134174)

2025-04-02 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 HEAD~1 HEAD --extensions cpp -- 
clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaOverload.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 9e9229ff5..9ab39a824 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4420,8 +4420,9 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   const ArrayParameterType *APT = cast(FromType);
   FromType = APT->getConstantArrayType(Context);
 }
-  From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
-  /*BasePath=*/nullptr, CCK).get();
+From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
+ /*BasePath=*/nullptr, CCK)
+   .get();
 break;
 
   case ICK_Function_To_Pointer:
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 950114046..d282fe50e 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2276,7 +2276,7 @@ static bool IsStandardConversion(Sema &S, Expr* From, 
QualType ToType,
 SCS.First = ICK_HLSL_Array_RValue;
 
 if (FromType.getCanonicalType().getUnqualifiedType() !=
-   ToType.getCanonicalType().getUnqualifiedType())
+ToType.getCanonicalType().getUnqualifiedType())
   return false;
 
 SCS.setAllToTypes(ToType);

``




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


[clang-tools-extra] [clang-tidy] Improve integer comparison by matching valid expressions outside implicitCastExpr (PR #134188)

2025-04-02 Thread David Rivera via cfe-commits

https://github.com/RiverDave updated 
https://github.com/llvm/llvm-project/pull/134188

>From ac9833cd5abdaf4a91c785d5fa9d51190219851a Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Wed, 2 Apr 2025 21:02:00 -0400
Subject: [PATCH] [clang-tidy] Improve integer comparison by matching valid
 expressions outside implicitCastExpr

---
 .../UseIntegerSignComparisonCheck.cpp | 16 +---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../modernize/use-integer-sign-comparison.cpp | 26 +++
 3 files changed, 43 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
index eeba5cce80da5..63e044f8ca993 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -39,9 +39,11 @@ intCastExpression(bool IsSigned,
   // std::cmp_{} functions trigger a compile-time error if either LHS or RHS
   // is a non-integer type, char, enum or bool
   // (unsigned char/ signed char are Ok and can be used).
-  auto IntTypeExpr = expr(hasType(hasCanonicalType(qualType(
+  const auto HasIntegerType = hasType(hasCanonicalType(qualType(
   isInteger(), IsSigned ? isSignedInteger() : isUnsignedInteger(),
-  unless(isActualChar()), unless(booleanType()), unless(enumType());
+  unless(isActualChar()), unless(booleanType()), unless(enumType();
+
+  auto IntTypeExpr = expr(HasIntegerType);
 
   const auto ImplicitCastExpr =
   CastBindName.empty() ? implicitCastExpr(hasSourceExpression(IntTypeExpr))
@@ -52,8 +54,16 @@ intCastExpression(bool IsSigned,
   const auto StaticCastExpr = cxxStaticCastExpr(has(ImplicitCastExpr));
   const auto FunctionalCastExpr = cxxFunctionalCastExpr(has(ImplicitCastExpr));
 
+  // Match function calls or variable references not directly wrapped by an 
implicit cast
+  const auto CallIntExpr = CastBindName.empty()
+   ? callExpr(HasIntegerType)
+   : callExpr(HasIntegerType).bind(CastBindName);
+  const auto DeclRefIntExpr =
+  CastBindName.empty() ? declRefExpr(HasIntegerType)
+   : declRefExpr(HasIntegerType).bind(CastBindName);
+
   return expr(anyOf(ImplicitCastExpr, CStyleCastExpr, StaticCastExpr,
-FunctionalCastExpr));
+FunctionalCastExpr, CallIntExpr));
 }
 
 static StringRef parseOpCode(BinaryOperator::Opcode Code) {
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6cb8d572d3a78..d90f277045003 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -177,6 +177,10 @@ Changes in existing checks
   matched scenarios of ``find`` and ``rfind`` methods and fixing false
   positives when those methods were called with 3 arguments.
 
+- Improved :doc:`modernize-use-integer-sign-comparison
+  ` check by matching
+  valid integer expressions not directly wrapped around an Implicit Cast.
+
 - Improved :doc:`modernize-use-std-numbers
   ` check to support math
   functions of different precisions.
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 99f00444c2d3f..1d2f64a359a2c 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
@@ -120,3 +120,29 @@ int AllComparisons() {
 
 return 0;
 }
+
+namespace PR127471 {
+int getSignedValue();
+unsigned int getUnsignedValue();
+
+void callExprTest() {
+
+if (getSignedValue() < getUnsignedValue())
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES:  if (std::cmp_less(getSignedValue() , getUnsignedValue()))
+
+int sVar = 0;
+if (getUnsignedValue() > sVar)
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: if (std::cmp_greater(getUnsignedValue() , sVar))
+
+unsigned int uVar = 0;
+if (getSignedValue() > uVar)
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: if (std::cmp_greater(getSignedValue() , uVar))
+
+}
+} // namespace PR127471

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


[clang] [Clang] Fix a lambda pattern comparison mismatch after ecc7e6ce4 (PR #133863)

2025-04-02 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

/cherry-pick dcc2182bce

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


[clang] [HLSL] Implement the `lit` intrinsic (PR #134171)

2025-04-02 Thread Farzon Lotfi via cfe-commits


@@ -280,6 +280,22 @@ constexpr bool4 isinf(double4 V) { return 
isinf((float4)V); }
 _DXC_COMPAT_TERNARY_DOUBLE_OVERLOADS(lerp)
 _DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
 
+//===--===//
+// lit builtins overloads
+//===--===//
+
+template 
+constexpr __detail::enable_if_t<__detail::is_arithmetic::Value &&
+(__detail::is_same::value ||

farzonl wrote:

I'm curious do we have to check all these types or can we just check 
`__detail::is_arithmetic` and not half or float so as to not impact the 
other templates?

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


[clang] dcc2182 - [Clang] Fix a lambda pattern comparison mismatch after ecc7e6ce4 (#133863)

2025-04-02 Thread via cfe-commits

Author: Younan Zhang
Date: 2025-04-03T11:15:42+08:00
New Revision: dcc2182bce3d2ef0e0a991664c51b4b3bfcf7197

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

LOG: [Clang] Fix a lambda pattern comparison mismatch after ecc7e6ce4 (#133863)

In ecc7e6ce4, we tried to inspect the `LambdaScopeInfo` on stack to
recover the instantiating lambda captures. However, there was a mismatch
in how we compared the pattern declarations of lambdas: the constraint
instantiation used a tailored `getPatternFunctionDecl()` which is
localized in SemaLambda that finds the very primal template declaration
of a lambda, while `FunctionDecl::getTemplateInstantiationPattern` finds
the latest template pattern of a lambda. This difference causes issues
when lambdas are nested, as we always want the primary template
declaration.

This corrects that by moving `Sema::addInstantiatedCapturesToScope` from
SemaConcept to SemaLambda, allowing it to use the localized version of
`getPatternFunctionDecl`.

It is also worth exploring to coalesce the implementation of
`getPatternFunctionDecl` with
`FunctionDecl::getTemplateInstantiationPattern`. But I’m leaving that
for the future, as I’d like to backport this fix (ecc7e6ce4 made the
issue more visible in clang 20, sorry!), and changing Sema’s ABI would
not be suitable in that regards. Hence, no release note.

Fixes https://github.com/llvm/llvm-project/issues/133719

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaLambda.cpp
clang/test/SemaTemplate/concepts-lambda.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 5e1cd62530c5b..16f9e3d60560e 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -697,75 +697,6 @@ bool Sema::CheckConstraintSatisfaction(
   .isInvalid();
 }
 
-bool Sema::addInstantiatedCapturesToScope(
-FunctionDecl *Function, const FunctionDecl *PatternDecl,
-LocalInstantiationScope &Scope,
-const MultiLevelTemplateArgumentList &TemplateArgs) {
-  const auto *LambdaClass = cast(Function)->getParent();
-  const auto *LambdaPattern = cast(PatternDecl)->getParent();
-
-  unsigned Instantiated = 0;
-
-  // FIXME: This is a workaround for not having deferred lambda body
-  // instantiation.
-  // When transforming a lambda's body, if we encounter another call to a
-  // nested lambda that contains a constraint expression, we add all of the
-  // outer lambda's instantiated captures to the current instantiation scope to
-  // facilitate constraint evaluation. However, these captures don't appear in
-  // the CXXRecordDecl until after the lambda expression is rebuilt, so we
-  // pull them out from the corresponding LSI.
-  LambdaScopeInfo *InstantiatingScope = nullptr;
-  if (LambdaPattern->capture_size() && !LambdaClass->capture_size()) {
-for (FunctionScopeInfo *Scope : llvm::reverse(FunctionScopes)) {
-  auto *LSI = dyn_cast(Scope);
-  if (!LSI ||
-  LSI->CallOperator->getTemplateInstantiationPattern() != PatternDecl)
-continue;
-  InstantiatingScope = LSI;
-  break;
-}
-assert(InstantiatingScope);
-  }
-
-  auto AddSingleCapture = [&](const ValueDecl *CapturedPattern,
-  unsigned Index) {
-ValueDecl *CapturedVar =
-InstantiatingScope ? InstantiatingScope->Captures[Index].getVariable()
-   : LambdaClass->getCapture(Index)->getCapturedVar();
-assert(CapturedVar->isInitCapture());
-Scope.InstantiatedLocal(CapturedPattern, CapturedVar);
-  };
-
-  for (const LambdaCapture &CapturePattern : LambdaPattern->captures()) {
-if (!CapturePattern.capturesVariable()) {
-  Instantiated++;
-  continue;
-}
-ValueDecl *CapturedPattern = CapturePattern.getCapturedVar();
-
-if (!CapturedPattern->isInitCapture()) {
-  Instantiated++;
-  continue;
-}
-
-if (!CapturedPattern->isParameterPack()) {
-  AddSingleCapture(CapturedPattern, Instantiated++);
-} else {
-  Scope.MakeInstantiatedLocalArgPack(CapturedPattern);
-  SmallVector Unexpanded;
-  SemaRef.collectUnexpandedParameterPacks(
-  dyn_cast(CapturedPattern)->getInit(), Unexpanded);
-  auto NumArgumentsInExpansion =
-  getNumArgumentsInExpansionFromUnexpanded(Unexpanded, TemplateArgs);
-  if (!NumArgumentsInExpansion)
-continue;
-  for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg)
-AddSingleCapture(CapturedPattern, Instantiated++);
-}
-  }
-  return false;
-}
-
 bool Sema::SetupConstraintScope(
 FunctionDecl *FD, std::optional> TemplateArgs,
 const MultiLevelTemplateArgumentList &MLTAL,

diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambd

[clang] [clang] Check `std::initializer_list` more strictly (PR #133822)

2025-04-02 Thread Younan Zhang via cfe-commits


@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 %s -verify=expected,type-param -std=c++23 -DTYPE_PARAM
+// RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DCONSTANT_PARAM
+// RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DTYPE_TEMPLATE_PARAM
+// RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DDEFAULT_ARG
+// RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DMULTIPLE_PARAMS
+// RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DPARAM_PACK
+// RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DCONSTRAINED_PARAM
+// RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DREQUIRES_CLAUSE
+// RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DNONCLASS_TEMPLATE
+// RUN: %clang_cc1 %s -verify=expected,others -std=c++23 -DNONTEMPLATE
+

zyn0217 wrote:

Because otherwise they're redefined

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


[clang] [Clang] Fix a lambda pattern comparison mismatch after ecc7e6ce4 (PR #133863)

2025-04-02 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

/cherry-pick dcc2182bc

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


[clang] [clang] Check `std::initializer_list` more strictly (PR #133822)

2025-04-02 Thread Younan Zhang via cfe-commits


@@ -12155,16 +12185,16 @@ static ClassTemplateDecl 
*LookupStdInitializerList(Sema &S, SourceLocation Loc){
 Result.suppressDiagnostics();
 // We found something weird. Complain about the first thing we found.
 NamedDecl *Found = *Result.begin();
-S.Diag(Found->getLocation(), diag::err_malformed_std_initializer_list);
+S.Diag(Found->getLocation(), diag::err_malformed_std_initializer_list)
+<< diag::MalformedStdInitializerList::BadEntityKind;
+S.Diag(Loc, diag::note_used_here);
 return nullptr;

zyn0217 wrote:

Couldn't we use CheckStdInitializerList?

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


[clang] Reapply "[cmake] Refactor clang unittest cmake" (PR #134195)

2025-04-02 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Reid Kleckner (rnk)


Changes

This reapplies 5ffd9bdb50b57 (#133545) with fixes.

The BUILD_SHARED_LIBS=ON build was fixed by adding missing LLVM
dependencies to the InterpTests binary in
unittests/AST/ByteCode/CMakeLists.txt .


---

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


28 Files Affected:

- (modified) clang/unittests/AST/ByteCode/CMakeLists.txt (+7-9) 
- (modified) clang/unittests/AST/CMakeLists.txt (+7-16) 
- (modified) clang/unittests/ASTMatchers/CMakeLists.txt (+7-15) 
- (modified) clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt (+5-13) 
- (modified) clang/unittests/Analysis/CMakeLists.txt (+5-13) 
- (modified) clang/unittests/Analysis/FlowSensitive/CMakeLists.txt (+5-13) 
- (modified) clang/unittests/Basic/CMakeLists.txt (+5-13) 
- (modified) clang/unittests/CMakeLists.txt (+28-4) 
- (modified) clang/unittests/CodeGen/CMakeLists.txt (+5-10) 
- (modified) clang/unittests/CrossTU/CMakeLists.txt (+3-9) 
- (modified) clang/unittests/DirectoryWatcher/CMakeLists.txt (+3-8) 
- (modified) clang/unittests/Driver/CMakeLists.txt (+7-12) 
- (modified) clang/unittests/Format/CMakeLists.txt (+3-8) 
- (modified) clang/unittests/Frontend/CMakeLists.txt (+4-8) 
- (modified) clang/unittests/Index/CMakeLists.txt (+4-9) 
- (modified) clang/unittests/InstallAPI/CMakeLists.txt (+3-6) 
- (modified) clang/unittests/Interpreter/CMakeLists.txt (+12-13) 
- (modified) clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt (+9-11) 
- (modified) clang/unittests/Lex/CMakeLists.txt (+4-12) 
- (modified) clang/unittests/Rewrite/CMakeLists.txt (+3-7) 
- (modified) clang/unittests/Sema/CMakeLists.txt (+5-13) 
- (modified) clang/unittests/Serialization/CMakeLists.txt (+6-11) 
- (modified) clang/unittests/StaticAnalyzer/CMakeLists.txt (+5-13) 
- (modified) clang/unittests/Support/CMakeLists.txt (+3-8) 
- (modified) clang/unittests/Tooling/CMakeLists.txt (+11-17) 
- (modified) clang/unittests/Tooling/Syntax/CMakeLists.txt (+5-10) 
- (modified) clang/unittests/libclang/CMakeLists.txt (+1-4) 
- (modified) clang/unittests/libclang/CrashTests/CMakeLists.txt (+1-4) 


``diff
diff --git a/clang/unittests/AST/ByteCode/CMakeLists.txt 
b/clang/unittests/AST/ByteCode/CMakeLists.txt
index b862fb4834fbd..1469cd6b2a8ea 100644
--- a/clang/unittests/AST/ByteCode/CMakeLists.txt
+++ b/clang/unittests/AST/ByteCode/CMakeLists.txt
@@ -2,19 +2,17 @@ add_clang_unittest(InterpTests
   BitcastBuffer.cpp
   Descriptor.cpp
   toAPValue.cpp
-  )
-
-clang_target_link_libraries(InterpTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangASTMatchers
   clangBasic
   clangFrontend
   clangSerialization
   clangTooling
-  )
-
-  target_link_libraries(InterpTests
-  PRIVATE
+  LINK_LIBS
   clangTesting
-)
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
+  TargetParser
+  )
diff --git a/clang/unittests/AST/CMakeLists.txt 
b/clang/unittests/AST/CMakeLists.txt
index bfa6082a6ffa4..f27d34e8a0719 100644
--- a/clang/unittests/AST/CMakeLists.txt
+++ b/clang/unittests/AST/CMakeLists.txt
@@ -1,10 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  TargetParser
-  )
-
-
 add_subdirectory(ByteCode)
 
 add_clang_unittest(ASTTests
@@ -43,10 +36,7 @@ add_clang_unittest(ASTTests
   TemplateNameTest.cpp
   TypePrinterTest.cpp
   UnresolvedSetTest.cpp
-  )
-
-clang_target_link_libraries(ASTTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangASTMatchers
   clangBasic
@@ -54,11 +44,12 @@ clang_target_link_libraries(ASTTests
   clangLex
   clangSerialization
   clangTooling
-  )
-
-target_link_libraries(ASTTests
-  PRIVATE
+  LINK_LIBS
   clangTesting
   LLVMTestingAnnotations
   LLVMTestingSupport
-)
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
+  TargetParser
+  )
diff --git a/clang/unittests/ASTMatchers/CMakeLists.txt 
b/clang/unittests/ASTMatchers/CMakeLists.txt
index 6a1e629d81b65..47bd5c108bb5a 100644
--- a/clang/unittests/ASTMatchers/CMakeLists.txt
+++ b/clang/unittests/ASTMatchers/CMakeLists.txt
@@ -1,31 +1,23 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  TargetParser
-  )
-
 add_clang_unittest(ASTMatchersTests
   ASTMatchersInternalTest.cpp
   ASTMatchersNodeTest.cpp
   ASTMatchersNarrowingTest.cpp
   ASTMatchersTraversalTest.cpp
   GtestMatchersTest.cpp
-  )
-
-clang_target_link_libraries(ASTMatchersTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangASTMatchers
   clangBasic
   clangFrontend
   clangSerialization
   clangTooling
-  )
-
-target_link_libraries(ASTMatchersTests
-  PRIVATE
+  LINK_LIBS
   clangTesting
   LLVMTestingSupport
-)
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
+  TargetParser
+  )
 
 add_subdirectory(Dynamic)
diff --git a/clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt 
b/clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt
index 6d0e12bcb0759..b6db7ce62afe7 100644
--- a/clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt
+++ b/clang/unittes

[clang] [clang-format] Fix a bug in annotating braces (PR #134039)

2025-04-02 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-android` running on `sanitizer-buildbot-android` while 
building `clang` at step 2 "annotate".

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


Here is the relevant piece of the build log for the reference

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
[   OK ] AddressSanitizer.AtoiAndFriendsOOBTest (2281 ms)
[ RUN  ] AddressSanitizer.HasFeatureAddressSanitizerTest
[   OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN  ] AddressSanitizer.CallocReturnsZeroMem
[   OK ] AddressSanitizer.CallocReturnsZeroMem (13 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN  ] AddressSanitizer.IgnoreTest
[   OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN  ] AddressSanitizer.SignalTest
[   OK ] AddressSanitizer.SignalTest (189 ms)
[ RUN  ] AddressSanitizer.ReallocTest
[   OK ] AddressSanitizer.ReallocTest (35 ms)
[ RUN  ] AddressSanitizer.WrongFreeTest
[   OK ] AddressSanitizer.WrongFreeTest (129 ms)
[ RUN  ] AddressSanitizer.LongJmpTest
[   OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN  ] AddressSanitizer.ThreadStackReuseTest
[   OK ] AddressSanitizer.ThreadStackReuseTest (8 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN  ] AddressSanitizer.UseThenFreeThenUseTest
[   OK ] AddressSanitizer.UseThenFreeThenUseTest (119 ms)
[ RUN  ] AddressSanitizer.FileNameInGlobalReportTest
[   OK ] AddressSanitizer.FileNameInGlobalReportTest (128 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN  ] AddressSanitizer.MlockTest
[   OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFHigh
[ DISABLED ] AddressSanitizer.DISABLED_DemoOOM
[ DISABLED ] AddressSanitizer.DISABLED_DemoDoubleFreeTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoNullDerefTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoFunctionStaticTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoTooMuchMemoryTest
[ RUN  ] AddressSanitizer.LongDoubleNegativeTest
[   OK ] AddressSanitizer.LongDoubleNegativeTest (0 ms)
[--] 19 tests from AddressSanitizer (28529 ms total)

[--] Global test environment tear-down
[==] 22 tests from 2 test suites ran. (28533 ms total)
[  PASSED  ] 22 tests.

  YOU HAVE 1 DISABLED TEST

Step 24 (run instrumented asan tests 
[aarch64/aosp_coral-userdebug/AOSP.MASTER]) failure: run instrumented asan 
tests [aarch64/aosp_coral-userdebug/AOSP.MASTER] (failure)
...
[ RUN  ] AddressSanitizer.HasFeatureAddressSanitizerTest
[   OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN  ] AddressSanitizer.CallocReturnsZeroMem
[   OK ] AddressSanitizer.CallocReturnsZeroMem (7 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN  ] AddressSanitizer.IgnoreTest
[   OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN  ] AddressSanitizer.SignalTest
[   OK ] AddressSanitizer.SignalTest (327 ms)
[ RUN  ] AddressSanitizer.ReallocTest
[   OK ] AddressSanitizer.ReallocTest (24 ms)
[ RUN  ] AddressSanitizer.WrongFreeTest
[   OK ] AddressSanitizer.WrongFreeTest (257 ms)
[ RUN  ] AddressSanitizer.LongJmpTest
[   OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN  ] AddressSanitizer.ThreadStackReuseTest
[   OK ] AddressSanitizer.ThreadStackReuseTest (14 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN  ] AddressSanitizer.UseThenFreeThenUseTest
[   OK ] AddressSanitizer.UseThenFreeThenUseTest (291 ms)
[ RUN  ] AddressSanitizer.FileNameInGlobalReportTest
[   OK ] AddressSanitizer.FileNameInGlobalReportTest (304 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN  ] AddressSanitizer.MlockTest
[   OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] Addr

[clang] [Clang] Fix a lambda pattern comparison mismatch after ecc7e6ce4 (PR #133863)

2025-04-02 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#134194

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


[clang] Reapply "[cmake] Refactor clang unittest cmake" (PR #134195)

2025-04-02 Thread Reid Kleckner via cfe-commits

https://github.com/rnk created https://github.com/llvm/llvm-project/pull/134195

This reapplies 5ffd9bdb50b57 (#133545) with fixes.

The BUILD_SHARED_LIBS=ON build was fixed by adding missing LLVM
dependencies to the InterpTests binary in
unittests/AST/ByteCode/CMakeLists.txt .


>From fe6604dc283a454c212b8e2cd21d94df96fb05d4 Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Wed, 2 Apr 2025 18:34:05 +
Subject: [PATCH] Reapply "[cmake] Refactor clang unittest cmake"

This reapplies 5ffd9bdb50b57 (#133545) with fixes.

The BUILD_SHARED_LIBS=ON build was fixed by adding missing LLVM
dependencies to the InterpTests binary in
unittests/AST/ByteCode/CMakeLists.txt .
---
 clang/unittests/AST/ByteCode/CMakeLists.txt   | 16 --
 clang/unittests/AST/CMakeLists.txt| 23 -
 clang/unittests/ASTMatchers/CMakeLists.txt| 22 -
 .../ASTMatchers/Dynamic/CMakeLists.txt| 18 +++
 clang/unittests/Analysis/CMakeLists.txt   | 18 +++
 .../Analysis/FlowSensitive/CMakeLists.txt | 18 +++
 clang/unittests/Basic/CMakeLists.txt  | 18 +++
 clang/unittests/CMakeLists.txt| 32 ---
 clang/unittests/CodeGen/CMakeLists.txt| 15 +++--
 clang/unittests/CrossTU/CMakeLists.txt| 12 ++-
 .../unittests/DirectoryWatcher/CMakeLists.txt | 11 ++-
 clang/unittests/Driver/CMakeLists.txt | 19 ---
 clang/unittests/Format/CMakeLists.txt | 11 ++-
 clang/unittests/Frontend/CMakeLists.txt   | 12 +++
 clang/unittests/Index/CMakeLists.txt  | 13 +++-
 clang/unittests/InstallAPI/CMakeLists.txt |  9 ++
 clang/unittests/Interpreter/CMakeLists.txt| 25 +++
 .../Interpreter/ExceptionTests/CMakeLists.txt | 20 ++--
 clang/unittests/Lex/CMakeLists.txt| 16 +++---
 clang/unittests/Rewrite/CMakeLists.txt| 10 ++
 clang/unittests/Sema/CMakeLists.txt   | 18 +++
 clang/unittests/Serialization/CMakeLists.txt  | 17 --
 clang/unittests/StaticAnalyzer/CMakeLists.txt | 18 +++
 clang/unittests/Support/CMakeLists.txt| 11 ++-
 clang/unittests/Tooling/CMakeLists.txt| 28 +++-
 clang/unittests/Tooling/Syntax/CMakeLists.txt | 15 +++--
 clang/unittests/libclang/CMakeLists.txt   |  5 +--
 .../libclang/CrashTests/CMakeLists.txt|  5 +--
 28 files changed, 166 insertions(+), 289 deletions(-)

diff --git a/clang/unittests/AST/ByteCode/CMakeLists.txt 
b/clang/unittests/AST/ByteCode/CMakeLists.txt
index b862fb4834fbd..1469cd6b2a8ea 100644
--- a/clang/unittests/AST/ByteCode/CMakeLists.txt
+++ b/clang/unittests/AST/ByteCode/CMakeLists.txt
@@ -2,19 +2,17 @@ add_clang_unittest(InterpTests
   BitcastBuffer.cpp
   Descriptor.cpp
   toAPValue.cpp
-  )
-
-clang_target_link_libraries(InterpTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangASTMatchers
   clangBasic
   clangFrontend
   clangSerialization
   clangTooling
-  )
-
-  target_link_libraries(InterpTests
-  PRIVATE
+  LINK_LIBS
   clangTesting
-)
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
+  TargetParser
+  )
diff --git a/clang/unittests/AST/CMakeLists.txt 
b/clang/unittests/AST/CMakeLists.txt
index bfa6082a6ffa4..f27d34e8a0719 100644
--- a/clang/unittests/AST/CMakeLists.txt
+++ b/clang/unittests/AST/CMakeLists.txt
@@ -1,10 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  TargetParser
-  )
-
-
 add_subdirectory(ByteCode)
 
 add_clang_unittest(ASTTests
@@ -43,10 +36,7 @@ add_clang_unittest(ASTTests
   TemplateNameTest.cpp
   TypePrinterTest.cpp
   UnresolvedSetTest.cpp
-  )
-
-clang_target_link_libraries(ASTTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangASTMatchers
   clangBasic
@@ -54,11 +44,12 @@ clang_target_link_libraries(ASTTests
   clangLex
   clangSerialization
   clangTooling
-  )
-
-target_link_libraries(ASTTests
-  PRIVATE
+  LINK_LIBS
   clangTesting
   LLVMTestingAnnotations
   LLVMTestingSupport
-)
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
+  TargetParser
+  )
diff --git a/clang/unittests/ASTMatchers/CMakeLists.txt 
b/clang/unittests/ASTMatchers/CMakeLists.txt
index 6a1e629d81b65..47bd5c108bb5a 100644
--- a/clang/unittests/ASTMatchers/CMakeLists.txt
+++ b/clang/unittests/ASTMatchers/CMakeLists.txt
@@ -1,31 +1,23 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  TargetParser
-  )
-
 add_clang_unittest(ASTMatchersTests
   ASTMatchersInternalTest.cpp
   ASTMatchersNodeTest.cpp
   ASTMatchersNarrowingTest.cpp
   ASTMatchersTraversalTest.cpp
   GtestMatchersTest.cpp
-  )
-
-clang_target_link_libraries(ASTMatchersTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangASTMatchers
   clangBasic
   clangFrontend
   clangSerialization
   clangTooling
-  )
-
-target_link_libraries(ASTMatchersTests
-  PRIVATE
+  LINK_LIBS
   clangTesting
   LLVMTestingSupport
-)
+  LLVM_COMPONENTS
+  FrontendOpenMP
+  Support
+  TargetParser
+  )
 
 add_subdirectory(Dynamic)
diff -

[clang] [llvm] [EquivalenceClasses] Use SmallVector for deterministic iteration order. (PR #134075)

2025-04-02 Thread Matt Arsenault via cfe-commits


@@ -138,6 +139,9 @@ class EquivalenceClasses {
   /// ECValues, it just keeps the key as part of the value.
   std::set TheMapping;
 
+  /// List of all members, used to provide a determinstic iteration order.
+  SmallVector Members;

arsenm wrote:

Can you combine into SetVector? 

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Joseph Huber via cfe-commits


@@ -585,6 +597,23 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 llvm::Value *Env = EmitScalarExpr(E->getArg(0));
 return Builder.CreateCall(F, {Env});
   }
+  case AMDGPU::BI__builtin_amdgcn_processor_is: {
+assert(CGM.getTriple().isSPIRV() &&

jhuber6 wrote:

Yeah, we 100% should support this for normal IR. We could then replace all of 
those `oclc_isa_version` files.

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


[clang] [HIP] Claim `--offload-compress` for `-M` (PR #133456)

2025-04-02 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/133456

>From be4ea80f2431bff0c017df3aef9f260dddfa9ccc Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Fri, 28 Mar 2025 11:30:39 -0400
Subject: [PATCH] [HIP] Claim --offloading-compress for -M

Cmake automatically generate dependency files with all compilation
options provided by users. When users use  for
HIP compilation, it causes warnings when cmake generates dependency
files. Claim this option to supress warnings.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 6 ++
 clang/test/Driver/hip-options.hip | 4 
 2 files changed, 10 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5f45cf0865b9e..a09b158b75b27 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1026,6 +1026,12 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
   CmdArgs.push_back("-dependency-file");
   CmdArgs.push_back(DepFile);
 }
+// Cmake generates dependency files using all compilation options specified
+// by users. Claim those not used for dependency files.
+if (JA.isOffloading(Action::OFK_HIP)) {
+  Args.ClaimAllArgs(options::OPT_offload_compress);
+  Args.ClaimAllArgs(options::OPT_no_offload_compress);
+}
 
 bool HasTarget = false;
 for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {
diff --git a/clang/test/Driver/hip-options.hip 
b/clang/test/Driver/hip-options.hip
index 0aabc8ad41904..29d23c1b6c8d9 100644
--- a/clang/test/Driver/hip-options.hip
+++ b/clang/test/Driver/hip-options.hip
@@ -242,3 +242,7 @@
 // NO-WARN-ATOMIC: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} 
"-Werror=atomic-alignment" {{.*}} "-Wno-error=atomic-alignment"
 // NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} 
"-Werror=atomic-alignment"
 // NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} 
"-Wno-error=atomic-alignment"
+
+// Check --offload-compress does not cause warning.
+// RUN: %clang -### -Werror --target=x86_64-unknown-linux-gnu -nogpuinc 
-nogpulib \
+// RUN:   --offload-arch=gfx1100 --offload-compress --offload-host-only -M %s

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


[clang] [SYCL][SPIR-V Backend][clang-sycl-linker] Add SPIR-V backend support inside clang-sycl-linker (PR #133967)

2025-04-02 Thread Arvind Sudarsanam via cfe-commits

https://github.com/asudarsa updated 
https://github.com/llvm/llvm-project/pull/133967

>From 0ab40315cd5ca320d84f87c99b8f23d9b6e8ed36 Mon Sep 17 00:00:00 2001
From: Arvind Sudarsanam 
Date: Mon, 31 Mar 2025 14:31:24 -0700
Subject: [PATCH 1/5] [SYCL][SPIR-V Backend][clang-sycl-linker] Add SPIR-V
 backend support inside clang-sycl-linker

This PR does the following:

1. Use SPIR-V backend to do LLVM to SPIR-V translation inside clang-sycl-linker
2. Remove llvm-spirv translator from clang-sycl-linker
Currently, no SPIR-V extensions are enabled for SYCL compilation flow. This 
will be updated in subsequent commits.

Thanks

Signed-off-by: Arvind Sudarsanam 
---
 clang/test/Driver/clang-sycl-linker-test.cpp  |  14 +-
 clang/test/Driver/sycl-link-spirv-target.cpp  |   6 +-
 clang/tools/clang-sycl-linker/CMakeLists.txt  |   5 +-
 .../clang-sycl-linker/ClangSYCLLinker.cpp | 187 +++---
 clang/tools/clang-sycl-linker/SYCLLinkOpts.td |   2 +-
 5 files changed, 76 insertions(+), 138 deletions(-)

diff --git a/clang/test/Driver/clang-sycl-linker-test.cpp 
b/clang/test/Driver/clang-sycl-linker-test.cpp
index 729561bd09cd8..2f860ae74e97d 100644
--- a/clang/test/Driver/clang-sycl-linker-test.cpp
+++ b/clang/test/Driver/clang-sycl-linker-test.cpp
@@ -6,7 +6,7 @@
 // RUN: clang-sycl-linker --dry-run -v -triple=spirv64 %t_1.bc %t_2.bc -o 
a.spv 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=SIMPLE-FO
 // SIMPLE-FO: sycl-device-link: inputs: {{.*}}.bc, {{.*}}.bc  libfiles:  
output: [[LLVMLINKOUT:.*]].bc
-// SIMPLE-FO-NEXT: "{{.*}}llvm-spirv{{.*}}" {{.*}}-o a.spv [[LLVMLINKOUT]].bc
+// SIMPLE-FO-NEXT: SPIR-V Backend: input: [[LLVMLINKOUT]].bc, output: a.spv
 //
 // Test the dry run of a simple case with device library files specified.
 // RUN: touch %T/lib1.bc
@@ -14,7 +14,7 @@
 // RUN: clang-sycl-linker --dry-run -v -triple=spirv64 %t_1.bc %t_2.bc 
--library-path=%T --device-libs=lib1.bc,lib2.bc -o a.spv 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=DEVLIBS
 // DEVLIBS: sycl-device-link: inputs: {{.*}}.bc  libfiles: {{.*}}lib1.bc, 
{{.*}}lib2.bc  output: [[LLVMLINKOUT:.*]].bc
-// DEVLIBS-NEXT: "{{.*}}llvm-spirv{{.*}}" {{.*}}-o a.spv [[LLVMLINKOUT]].bc
+// DEVLIBS-NEXT: SPIR-V Backend: input: [[LLVMLINKOUT]].bc, output: a.spv
 //
 // Test a simple case with a random file (not bitcode) as input.
 // RUN: touch %t.o
@@ -29,13 +29,3 @@
 // RUN: not clang-sycl-linker --dry-run -triple=spirv64 %t_1.bc %t_2.bc 
--library-path=%T --device-libs=lib1.bc,lib2.bc,lib3.bc -o a.spv 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=DEVLIBSERR2
 // DEVLIBSERR2: '{{.*}}lib3.bc' SYCL device library file is not found
-//
-// Test if correct set of llvm-spirv options are emitted for windows 
environment.
-// RUN: clang-sycl-linker --dry-run -v -triple=spirv64 --is-windows-msvc-env 
%t_1.bc %t_2.bc -o a.spv 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=LLVMOPTSWIN
-// LLVMOPTSWIN: -spirv-debug-info-version=ocl-100 
-spirv-allow-extra-diexpressions -spirv-allow-unknown-intrinsics=llvm.genx. 
-spirv-ext=
-//
-// Test if correct set of llvm-spirv options are emitted for linux environment.
-// RUN: clang-sycl-linker --dry-run -v -triple=spirv64  %t_1.bc %t_2.bc -o 
a.spv 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=LLVMOPTSLIN
-// LLVMOPTSLIN: -spirv-debug-info-version=nonsemantic-shader-200 
-spirv-allow-unknown-intrinsics=llvm.genx. -spirv-ext=
diff --git a/clang/test/Driver/sycl-link-spirv-target.cpp 
b/clang/test/Driver/sycl-link-spirv-target.cpp
index 7585ef8b14a59..586adae619165 100644
--- a/clang/test/Driver/sycl-link-spirv-target.cpp
+++ b/clang/test/Driver/sycl-link-spirv-target.cpp
@@ -3,7 +3,7 @@
 //
 // Test that -Xlinker options are being passed to clang-sycl-linker.
 // RUN: touch %t.bc
-// RUN: %clangxx -### --target=spirv64 --sycl-link -Xlinker 
--llvm-spirv-path=/tmp \
-// RUN:   -Xlinker -triple=spirv64 -Xlinker --library-path=/tmp -Xlinker 
--device-libs=lib1.bc,lib2.bc %t.bc 2>&1 \
+// RUN: %clangxx -### --target=spirv64 --sycl-link -Xlinker -triple=spirv64 
-Xlinker --library-path=/tmp \
+// RUN:   -Xlinker --device-libs=lib1.bc,lib2.bc %t.bc 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=XLINKEROPTS
-// XLINKEROPTS: "{{.*}}clang-sycl-linker{{.*}}" "--llvm-spirv-path=/tmp" 
"-triple=spirv64" "--library-path=/tmp" "--device-libs=lib1.bc,lib2.bc" 
"{{.*}}.bc" "-o" "a.out"
+// XLINKEROPTS: "{{.*}}clang-sycl-linker{{.*}}" "-triple=spirv64" 
"--library-path=/tmp" "--device-libs=lib1.bc,lib2.bc" "{{.*}}.bc" "-o" "a.out"
diff --git a/clang/tools/clang-sycl-linker/CMakeLists.txt 
b/clang/tools/clang-sycl-linker/CMakeLists.txt
index 382c0ca441940..ee89e8b0a5570 100644
--- a/clang/tools/clang-sycl-linker/CMakeLists.txt
+++ b/clang/tools/clang-sycl-linker/CMakeLists.txt
@@ -1,14 +1,17 @@
 set(LLVM_LINK_COMPONENTS
   ${LLVM_TARGETS_TO_BUILD}
+  Analysis
   BinaryFormat
   BitWriter
   Core
   IRReader
   Linker
+  MC
   Option
   Object
-  TargetParser
   Support
+  Target
+  TargetParser
   )
 
 set(LLVM_TARGET_DEFIN

[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Erich Keane via cfe-commits

erichkeane wrote:

> This change adds two semi-magical builtins for AMDGPU:
> 
> * `__builtin_amdgcn_processor_is`, which is similar in observable 
> behaviour with `__builtin_cpu_is`, except that it is never "evaluated" at run 
> time;
> 
> * `__builtin_amdgcn_is_invocable`, which is behaviourally similar with 
> `__has_builtin`, except that it is not a macro (i.e. not evaluated at 
> preprocessing time).
> 
> 
> Neither of these are `constexpr`, even though when compiling for concrete 
> (i.e. `gfxXXX` / `gfxXXX-generic`) targets they get evaluated in Clang, so 
> they shouldn't tear the AST too badly / at all for multi-pass compilation 
> cases like HIP. They can only be used in specific contexts (as args to 
> control structures).
> 
> The motivation for adding these is two-fold:
> 
> * as a nice to have, it provides an AST-visible way to incorporate 
> architecture specific code, rather than having to rely on macros and the 
> preprocessor, which burn in the choice quite early;
> 
> * as a must have, it allows featureful AMDGCN flavoured SPIR-V to be 
> produced, where target specific capability is guarded and chosen or discarded 
> when finalising compilation for a concrete target.
> 
> 
> I've tried to keep the overall footprint of the change small. The changes to 
> Sema are a bit unpleasant, but there was a strong desire to have Clang 
> validate these, and to constrain their uses, and this was the most compact 
> solution I could come up with (suggestions welcome).
> 
> In the end, I will note there is nothing that is actually AMDGPU specific 
> here, so it is possible that in the future, assuming interests from other 
> targets / users, we'd just promote them to generic intrinsics.

First read through this, I find myself wondering WHY these aren't constexpr.  
They seem exactly the sort of thing that folks would like to use `if constexpr` 
for.

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


[clang] 2b7daaf - [sanitizer][CFI] Add support to build CFI with sanitize-coverage (#131296)

2025-04-02 Thread via cfe-commits

Author: Maxim Zhukov
Date: 2025-04-02T16:05:44+03:00
New Revision: 2b7daaf9678181959982b219db0af106f4ef8e3e

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

LOG: [sanitizer][CFI] Add support to build CFI with sanitize-coverage (#131296)

Added ability to build together with -fsanitize=cfi and
-fsanitize-coverage=trace-cmp at the same time.

Added: 


Modified: 
clang/lib/Driver/SanitizerArgs.cpp
clang/test/CodeGen/sanitize-coverage.c
clang/test/Driver/fsanitize-coverage.c

Removed: 




diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 6e75001585c61..3c7cd562a14e3 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -54,7 +54,8 @@ static const SanitizerMask SupportsCoverage =
 SanitizerKind::FuzzerNoLink | SanitizerKind::FloatDivideByZero |
 SanitizerKind::SafeStack | SanitizerKind::ShadowCallStack |
 SanitizerKind::Thread | SanitizerKind::ObjCCast | SanitizerKind::KCFI |
-SanitizerKind::NumericalStability | SanitizerKind::Vptr;
+SanitizerKind::NumericalStability | SanitizerKind::Vptr |
+SanitizerKind::CFI;
 static const SanitizerMask RecoverableByDefault =
 SanitizerKind::Undefined | SanitizerKind::Integer |
 SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |

diff  --git a/clang/test/CodeGen/sanitize-coverage.c 
b/clang/test/CodeGen/sanitize-coverage.c
index cb1ed939d4a93..90892fc0dae06 100644
--- a/clang/test/CodeGen/sanitize-coverage.c
+++ b/clang/test/CodeGen/sanitize-coverage.c
@@ -5,6 +5,7 @@
 // RUN: %clang %s -target x86_64-unknown-linux-gnu -emit-llvm -S 
-fsanitize=thread -fsanitize-coverage=trace-pc,trace-cmp -o - | FileCheck 
%s --check-prefixes=CHECK,TSAN
 // RUN: %clang %s -target x86_64-unknown-linux-gnu -emit-llvm -S 
-fsanitize=undefined  -fsanitize-coverage=trace-pc,trace-cmp -o - | FileCheck 
%s --check-prefixes=CHECK,UBSAN
 // RUN: %clang %s -target x86_64-unknown-linux-gnu -emit-llvm -S 
-fsanitize=kcfi   -fsanitize-coverage=trace-pc,trace-cmp -o - | FileCheck 
%s --check-prefixes=CHECK,KCFI
+// RUN: %clang %s -target x86_64-unknown-linux-gnu -emit-llvm -S 
-fsanitize=cfi-fsanitize-coverage=trace-pc,trace-cmp -flto 
-fvisibility=default -fno-sanitize-trap=cfi -fno-sanitize-ignorelist 
-resource-dir=/dev/null -o - | FileCheck %s --check-prefixes=CHECK,CFI
 
 int x[10];
 extern void (*f)(void);
@@ -21,6 +22,7 @@ void foo(int n) {
   if (n)
 x[n] = 42;
   // KCFI-DAG: call void %[[#]]() [ "kcfi"(i32 {{.*}}) ]
+  // CFI-DAG: call void @__ubsan_handle_cfi_check_fail_abort
   f();
 }
 
@@ -47,6 +49,7 @@ __attribute__((no_sanitize("coverage"))) void 
test_no_sanitize_coverage(int n) {
   if (n)
 x[n] = 42;
   // KCFI-DAG: call void %[[#]]() [ "kcfi"(i32 {{.*}}) ]
+  // CFI-DAG: call void @__ubsan_handle_cfi_check_fail_abort
   f();
 }
 
@@ -94,6 +97,14 @@ void test_no_sanitize_kcfi(void) {
   f();
 }
 
+// CHECK-LABEL: define dso_local void @test_no_sanitize_cfi(
+__attribute__((no_sanitize("cfi", "coverage")))
+void test_no_sanitize_cfi(void) {
+  // CHECK-NOT: call void @__sanitizer_cov_trace
+  // CFI-NOT: call void @__ubsan_handle_cfi_check_fail_abort
+  f();
+}
+
 // CHECK-LABEL: define dso_local void @test_no_sanitize_always_inline(
 __attribute__((no_sanitize("coverage")))
 void test_no_sanitize_always_inline(int n) {

diff  --git a/clang/test/Driver/fsanitize-coverage.c 
b/clang/test/Driver/fsanitize-coverage.c
index c2de897f80eeb..dc4c39396d45c 100644
--- a/clang/test/Driver/fsanitize-coverage.c
+++ b/clang/test/Driver/fsanitize-coverage.c
@@ -17,6 +17,7 @@
 // RUN: %clang --target=x86_64-linux-gnu -fsanitize=dataflow 
-fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
 // RUN: %clang --target=x86_64-linux-gnu -fsanitize=thread 
-fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
 // RUN: %clang --target=x86_64-linux-gnu -fsanitize=kcfi 
-fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
+// RUN: %clang --target=x86_64-linux-gnu -fsanitize=cfi 
-fsanitize-coverage=func,trace-pc -flto -fvisibility=default 
-fno-sanitize-ignorelist -resource-dir=/dev/null %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
 // RUN: %clang --target=%itanium_abi_triple -fsanitize=float-divide-by-zero 
-fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
 // RUN: %clang --target=x86_64-linux-gnu 
-fsanitize-coverage=func,trace-pc %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
 // CHECK-SANITIZE-COVERAGE-FUNC: fsanitize-coverage-type=1

[clang] [sanitizer][CFI] Add support to build CFI with sanitize-coverage (PR #131296)

2025-04-02 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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


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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Yaxun Liu via cfe-commits


@@ -0,0 +1,64 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals all --version 5
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx900 -emit-llvm %s 
-o - | FileCheck --check-prefix=AMDGCN-GFX900 %s
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx1010 -emit-llvm %s 
-o - | FileCheck --check-prefix=AMDGCN-GFX1010 %s
+// RUN: %clang_cc1 -triple spirv64-amd-amdhsa -emit-llvm %s -o - | FileCheck 
--check-prefix=AMDGCNSPIRV %s
+

yxsamliu wrote:

we also need to test the code does not cause error in host compilation, i.e. 
-triple x86_64 -aux-triple amdgcn or spirv64-amd-amdhsa. we can either do this 
here or create a sema test. same for below.

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


[clang] [flang] [flang][OpenMP] Extend `do concurrent` mapping to multi-range loops (PR #127634)

2025-04-02 Thread Kareem Ergawy via cfe-commits

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


[clang] [llvm] [ARM][Clang] Make `+nosimd` functional for AArch32 Targets (PR #130623)

2025-04-02 Thread Jack Styles via cfe-commits

https://github.com/Stylie777 updated 
https://github.com/llvm/llvm-project/pull/130623

>From 8b2ad7c1475ff4aee065e9feb21469d184320472 Mon Sep 17 00:00:00 2001
From: Jack Styles 
Date: Fri, 7 Mar 2025 15:51:34 +
Subject: [PATCH 1/8] [NFC][ARM] Split SIMD identifier away from MVE

Previously, the use of MVE or MVE.FP would be defined
by using the `ARM::AEK_SIMD` identifier. SIMD relates to
the Cortex-A and Cortex-R extension that enables NEON
instructions, which is called MVE for Cortex-M. To enable the
linking of `+simd` and `+nosimd` to `+neon` and `-neon`
when using clang, MVE and MVE.FP can now be defined
using a unique enum identifier, rather than using the existing
identifier for SIMD.

This was originally planned to be merged as part of #130296 but
the changes made `+nosimd` an invalid argument, which, while not
having any functionality, was allowed in previous versions of
LLVM. To avoid regressions being introduced, this has been
combined with the fix for `+nosimd` on AArch32.
---
 llvm/include/llvm/TargetParser/ARMTargetParser.def | 10 +-
 llvm/include/llvm/TargetParser/ARMTargetParser.h   |  1 +
 llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp |  2 +-
 llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp |  2 +-
 llvm/unittests/TargetParser/TargetParserTest.cpp   |  6 +++---
 5 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/llvm/include/llvm/TargetParser/ARMTargetParser.def 
b/llvm/include/llvm/TargetParser/ARMTargetParser.def
index 6b96c3e83c8c4..e515ab665d117 100644
--- a/llvm/include/llvm/TargetParser/ARMTargetParser.def
+++ b/llvm/include/llvm/TargetParser/ARMTargetParser.def
@@ -224,8 +224,8 @@ ARM_ARCH_EXT_NAME("dotprod", ARM::AEK_DOTPROD, "+dotprod", 
"-dotprod")
 ARM_ARCH_EXT_NAME("dsp", ARM::AEK_DSP, "+dsp", "-dsp")
 ARM_ARCH_EXT_NAME("fp", ARM::AEK_FP, {}, {})
 ARM_ARCH_EXT_NAME("fp.dp", ARM::AEK_FP_DP, {}, {})
-ARM_ARCH_EXT_NAME("mve", (ARM::AEK_DSP | ARM::AEK_SIMD), "+mve", "-mve")
-ARM_ARCH_EXT_NAME("mve.fp", (ARM::AEK_DSP | ARM::AEK_SIMD | ARM::AEK_FP),
+ARM_ARCH_EXT_NAME("mve", (ARM::AEK_DSP | ARM::AEK_MVE), "+mve", "-mve")
+ARM_ARCH_EXT_NAME("mve.fp", (ARM::AEK_DSP | ARM::AEK_MVE | ARM::AEK_FP),
   "+mve.fp", "-mve.fp")
 ARM_ARCH_EXT_NAME("idiv", (ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB), {}, {})
 ARM_ARCH_EXT_NAME("mp", ARM::AEK_MP, {}, {})
@@ -345,12 +345,12 @@ ARM_CPU_NAME("cortex-m33", ARMV8MMainline, 
FK_FPV5_SP_D16, false, ARM::AEK_DSP)
 ARM_CPU_NAME("star-mc1", ARMV8MMainline, FK_FPV5_SP_D16, false, ARM::AEK_DSP)
 ARM_CPU_NAME("cortex-m35p", ARMV8MMainline, FK_FPV5_SP_D16, false, 
ARM::AEK_DSP)
 ARM_CPU_NAME("cortex-m55", ARMV8_1MMainline, FK_FP_ARMV8_FULLFP16_D16, false,
- (ARM::AEK_DSP | ARM::AEK_SIMD | ARM::AEK_FP | ARM::AEK_FP16))
+ (ARM::AEK_DSP | ARM::AEK_MVE | ARM::AEK_FP | ARM::AEK_FP16))
 ARM_CPU_NAME("cortex-m85", ARMV8_1MMainline, FK_FP_ARMV8_FULLFP16_D16, false,
- (ARM::AEK_DSP | ARM::AEK_SIMD | ARM::AEK_FP | ARM::AEK_FP16 |
+ (ARM::AEK_DSP | ARM::AEK_MVE | ARM::AEK_FP | ARM::AEK_FP16 |
   ARM::AEK_RAS | ARM::AEK_PACBTI))
 ARM_CPU_NAME("cortex-m52", ARMV8_1MMainline, FK_FP_ARMV8_FULLFP16_D16, false,
- (ARM::AEK_DSP | ARM::AEK_SIMD | ARM::AEK_FP | ARM::AEK_FP16 |
+ (ARM::AEK_DSP | ARM::AEK_MVE | ARM::AEK_FP | ARM::AEK_FP16 |
   ARM::AEK_RAS | ARM::AEK_PACBTI))
 ARM_CPU_NAME("cortex-a32", ARMV8A, FK_CRYPTO_NEON_FP_ARMV8, false, 
ARM::AEK_CRC)
 ARM_CPU_NAME("cortex-a35", ARMV8A, FK_CRYPTO_NEON_FP_ARMV8, false, 
ARM::AEK_CRC)
diff --git a/llvm/include/llvm/TargetParser/ARMTargetParser.h 
b/llvm/include/llvm/TargetParser/ARMTargetParser.h
index 5dbcfd3d2d693..b2403f42f1b79 100644
--- a/llvm/include/llvm/TargetParser/ARMTargetParser.h
+++ b/llvm/include/llvm/TargetParser/ARMTargetParser.h
@@ -61,6 +61,7 @@ enum ArchExtKind : uint64_t {
   AEK_CDECP6 = 1 << 28,
   AEK_CDECP7 = 1 << 29,
   AEK_PACBTI = 1 << 30,
+  AEK_MVE = 1ULL << 31,
   // Unsupported extensions.
   AEK_OS = 1ULL << 59,
   AEK_IWMMXT = 1ULL << 60,
diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp 
b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
index 456c3b5396fc9..956fc9680ee33 100644
--- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -12970,7 +12970,7 @@ bool ARMAsmParser::enableArchExtFeature(StringRef Name, 
SMLoc &ExtLoc) {
   {ARM::AEK_CRYPTO,
{Feature_HasV8Bit},
{ARM::FeatureCrypto, ARM::FeatureNEON, ARM::FeatureFPARMv8}},
-  {(ARM::AEK_DSP | ARM::AEK_SIMD | ARM::AEK_FP),
+  {(ARM::AEK_DSP | ARM::AEK_MVE | ARM::AEK_FP),
{Feature_HasV8_1MMainlineBit},
{ARM::HasMVEFloatOps}},
   {ARM::AEK_FP,
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp 
b/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
index b0fa03a35ec04..632dbebf58f04 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
+++ b/

[clang] [llvm] [EquivalenceClasses] Use SmallVector for deterministic iteration order. (PR #134075)

2025-04-02 Thread Nikita Popov via cfe-commits

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

This looks reasonable to me. We could keep the existing API with a custom 
iterator, but given the limited amount of uses this seems ok.

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


[libclc] [libclc] Move cbrt to the CLC library; vectorize (PR #133940)

2025-04-02 Thread Fraser Cormack via cfe-commits

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


[clang] [llvm] [EquivalenceClasses] Use SmallVector for deterministic iteration order. (PR #134075)

2025-04-02 Thread Florian Hahn via cfe-commits


@@ -138,6 +139,9 @@ class EquivalenceClasses {
   /// ECValues, it just keeps the key as part of the value.
   std::set TheMapping;
 
+  /// List of all members, used to provide a determinstic iteration order.
+  SmallVector Members;

fhahn wrote:

This is where things get a little tricky. `ECValue` contain pointers to other 
`ECValue`'s (the leader of the class and the next member of the class), so 
using something like `SetVector` as the backing storage won't work I think, as 
it might reallocate and move the objects.

One thing I tried is using a BumpAllocator for the elements in the class and a 
separate DenseMap instead of the std::set: 
https://github.com/llvm/llvm-project/commit/5c13864badfd7170c9c7c0a908e3cba8aa0f4fea

I think SetVector (or MapVector) would be slightly worse here, as it stores an 
ECValue in both a vector and a denseSet, and ECValue contains 3 pointers, so it 
would require quite a bit of extra memory .

The patch could use a `DenseSet`, it just requires a custom DenseMapInfo for 
ECValue to just hash/compare the data part. I can do that if desired and 
prepare the patch for review

Compile-time wise this looks neutral, but it would simplify things slightly 
https://llvm-compile-time-tracker.com/compare.php?from=b0c2ac67a88d3ef86987e2f82115ea0170675a17&to=5c13864badfd7170c9c7c0a908e3cba8aa0f4fea&stat=instructions:u

(the patch just has the unit tests for EQClass removed, because one of the keys 
doesn't have DenseMapInfo).



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


[clang] [llvm] [Clang] [OpenMP] Support NOWAIT with optional argument (PR #128742)

2025-04-02 Thread Michael Klemm via cfe-commits

mjklemm wrote:

> Should the `nowait(EXPR)` behavior be guarded by the OpenMP version flag? It 
> seems to me that the tests would currently not respect which OpenMP version 
> is selected and always generate the error.

I agree.  This should be under `-fopenmp-version=6.0`

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


[clang] [llvm] [EquivalenceClasses] Use SmallVector for deterministic iteration order. (PR #134075)

2025-04-02 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated 
https://github.com/llvm/llvm-project/pull/134075

>From 10afe2fb4743c0fccaad2797fffca174736a0997 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Sat, 29 Mar 2025 20:20:39 +
Subject: [PATCH 1/2] [EquivalenceClasses] Use SmallVector for deterministic
 iteration order.

Currently iterators over EquivalenceClasses will iterate over std::set,
which guarantees the order specified by the comperator. Unfortunately in
many cases, EquivalenceClasses are used with pointers, so iterating over
std::set of pointers will not be deterministic across runs.

There are multiple places that explicitly try to sort the equivalence
classes before using them to try to get a deterministic order
(LowerTypeTests, SplitModule), but there are others that do not at the
moment and this can result at least in non-determinstic value naming in
Float2Int.

This patch updates EquivalenceClasses to keep track of all members via a
extra SmallVector and removes code from LowerTypeTests and SplitModule
to sort the classes before processing.

Overall it looks like compile-time slightly decreases in most cases, but
close to noise:
https://llvm-compile-time-tracker.com/compare.php?from=7d441d9892295a6eb8aaf481e1715f039f6f224f&to=b0c2ac67a88d3ef86987e2f82115ea0170675a17&stat=instructions
---
 .../FlowSensitive/SimplifyConstraints.cpp |  8 ++---
 llvm/include/llvm/ADT/EquivalenceClasses.h| 25 +--
 llvm/lib/Analysis/VectorUtils.cpp |  8 ++---
 .../AArch64/AArch64A57FPLoadBalancing.cpp |  4 +--
 llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp  |  5 +--
 llvm/lib/Transforms/IPO/LowerTypeTests.cpp| 29 +++--
 llvm/lib/Transforms/Scalar/Float2Int.cpp  | 10 +++---
 llvm/lib/Transforms/Scalar/LoopDistribute.cpp |  6 ++--
 llvm/lib/Transforms/Utils/SplitModule.cpp | 32 +--
 .../type-inference.td |  2 +-
 .../LowerTypeTests/function-disjoint.ll   | 12 +++
 .../Transforms/LowerTypeTests/nonstring.ll|  2 +-
 llvm/test/tools/llvm-split/preserve-locals.ll | 13 
 llvm/test/tools/llvm-split/scc-const-alias.ll | 10 +++---
 .../test/tools/llvm-split/scc-global-alias.ll | 16 +-
 .../TableGen/GlobalISelCombinerEmitter.cpp|  3 +-
 16 files changed, 81 insertions(+), 104 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp 
b/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
index 69a90334c9df5..3c385ed8ef663 100644
--- a/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
+++ b/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
@@ -111,8 +111,8 @@ void simplifyConstraints(llvm::SetVector 
&Constraints,
 FalseAtoms = projectToLeaders(FalseAtoms, EquivalentAtoms);
 
 llvm::DenseMap Substitutions;
-for (auto It = EquivalentAtoms.begin(); It != EquivalentAtoms.end(); ++It) 
{
-  Atom TheAtom = It->getData();
+for (const auto &E : EquivalentAtoms) {
+  Atom TheAtom = E->getData();
   Atom Leader = EquivalentAtoms.getLeaderValue(TheAtom);
   if (TrueAtoms.contains(Leader)) {
 if (FalseAtoms.contains(Leader)) {
@@ -152,9 +152,9 @@ void simplifyConstraints(llvm::SetVector 
&Constraints,
 
   if (Info) {
 for (const auto &E : EquivalentAtoms) {
-  if (!E.isLeader())
+  if (!E->isLeader())
 continue;
-  Atom At = *EquivalentAtoms.findLeader(E);
+  Atom At = *EquivalentAtoms.findLeader(*E);
   if (TrueAtoms.contains(At) || FalseAtoms.contains(At))
 continue;
   llvm::SmallVector Atoms =
diff --git a/llvm/include/llvm/ADT/EquivalenceClasses.h 
b/llvm/include/llvm/ADT/EquivalenceClasses.h
index 46f186a71f5ce..906971baf74af 100644
--- a/llvm/include/llvm/ADT/EquivalenceClasses.h
+++ b/llvm/include/llvm/ADT/EquivalenceClasses.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_ADT_EQUIVALENCECLASSES_H
 #define LLVM_ADT_EQUIVALENCECLASSES_H
 
+#include "llvm/ADT/SmallVector.h"
 #include 
 #include 
 #include 
@@ -138,6 +139,9 @@ class EquivalenceClasses {
   /// ECValues, it just keeps the key as part of the value.
   std::set TheMapping;
 
+  /// List of all members, used to provide a determinstic iteration order.
+  SmallVector Members;
+
 public:
   EquivalenceClasses() = default;
   EquivalenceClasses(const EquivalenceClasses &RHS) {
@@ -146,9 +150,10 @@ class EquivalenceClasses {
 
   EquivalenceClasses &operator=(const EquivalenceClasses &RHS) {
 TheMapping.clear();
+Members.clear();
 for (const auto &E : RHS)
-  if (E.isLeader()) {
-member_iterator MI = RHS.member_begin(E);
+  if (E->isLeader()) {
+member_iterator MI = RHS.member_begin(*E);
 member_iterator LeaderIt = member_begin(insert(*MI));
 for (++MI; MI != member_end(); ++MI)
   unionSets(LeaderIt, member_begin(insert(*MI)));
@@ -161,11 +166,10 @@ class EquivalenceClasses {
   //
 
   /// iterator* - Provides a way to iterate over all values in the set.
-  using iterator =
-  type

[libclc] [libclc]: clspv: add a dummy implememtation for mul_hi (PR #134094)

2025-04-02 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

For the record, clspv implementation is based on OpMulExtended which is SPIR-V 
specific and not accessible from C.

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


[clang] [clang] Allow parentheses around CTAD declarators (PR #132829)

2025-04-02 Thread via cfe-commits

https://github.com/offsetof updated 
https://github.com/llvm/llvm-project/pull/132829

>From 66833f41d26a6c6355ef67b2f9041ba771b690b7 Mon Sep 17 00:00:00 2001
From: offsetof 
Date: Mon, 24 Mar 2025 20:51:23 +
Subject: [PATCH 1/3] [clang] Allow parentheses around CTAD declarators

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++--
 clang/lib/Sema/SemaType.cpp   |  9 ++-
 ...xx1z-class-template-argument-deduction.cpp |  8 +++---
 clang/test/SemaCXX/ctad.cpp   | 26 +++
 5 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f919b66dd0e41..24c65dbef5869 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -358,6 +358,8 @@ Bug Fixes to C++ Support
 - Fixed a Clang regression in C++20 mode where unresolved dependent call 
expressions were created inside non-dependent contexts (#GH122892)
 - Clang now emits the ``-Wunused-variable`` warning when some structured 
bindings are unused
   and the ``[[maybe_unused]]`` attribute is not applied. (#GH125810)
+- Declarations using class template argument deduction with redundant
+  parentheses around the declarator are no longer rejected. (#GH39811)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c77cde297dc32..a19975f6d6bdf 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2612,10 +2612,9 @@ def err_decltype_auto_initializer_list : Error<
   "cannot deduce 'decltype(auto)' from initializer list">;
 
 // C++17 deduced class template specialization types
-def err_deduced_class_template_compound_type : Error<
-  "cannot %select{form pointer to|form reference to|form array of|"
-  "form function returning|use parentheses when declaring variable with}0 "
-  "deduced class template specialization type">;
+def err_deduced_class_template_compound_type
+: Error<"cannot form %select{pointer to|reference to|array of|function "
+"returning}0 deduced class template specialization type">;
 def err_deduced_non_class_or_alias_template_specialization_type : Error<
   "%select{|function template|variable template|alias template|"
   "template template parameter|concept|template}0 %1 requires template "
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index aec33303780a0..16315d93ef8ce 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -4282,8 +4282,8 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
 
   // If T is 'decltype(auto)', the only declarators we can have are parens
   // and at most one function declarator if this is a function declaration.
-  // If T is a deduced class template specialization type, we can have no
-  // declarator chunks at all.
+  // If T is a deduced class template specialization type, only parentheses
+  // are allowed.
   if (auto *DT = T->getAs()) {
 const AutoType *AT = T->getAs();
 bool IsClassTemplateDeduction = isa(DT);
@@ -4297,11 +4297,6 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
 unsigned DiagKind = 0;
 switch (DeclChunk.Kind) {
 case DeclaratorChunk::Paren:
-  // FIXME: Rejecting this is a little silly.
-  if (IsClassTemplateDeduction) {
-DiagKind = 4;
-break;
-  }
   continue;
 case DeclaratorChunk::Function: {
   if (IsClassTemplateDeduction) {
diff --git a/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp 
b/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
index a1594333abae7..d29eed40b1864 100644
--- a/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ b/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -39,7 +39,7 @@ namespace template_template_arg_pack {
   template struct YP {};
 
   struct Z { template struct Q {}; }; // expected-note 2{{here}}
-  
+
   template using ZId = Z;
 
   template struct A {
@@ -152,7 +152,7 @@ namespace decl {
   A a;
   A b = 0;
   const A c = 0;
-  A (parens) = 0; // expected-error {{cannot use parentheses when declaring 
variable with deduced class template specialization type}}
+  A (parens) = 0;
   A *p = 0; // expected-error {{cannot form pointer to deduced class template 
specialization type}}
   A &r = *p; // expected-error {{cannot form reference to deduced class 
template specialization type}}
   A arr[3] = 0; // expected-error {{cannot form array of deduced class 
template specialization type}}
@@ -179,7 +179,7 @@ namespace typename_specifier {
   }
   typename ::A a = 0;
   const typename ::A b = 0;
-  typename ::A (parens) = 0; // expected-error {{cannot use parentheses when 
declaring variable with de

[clang] Hlsl dst function (PR #133828)

2025-04-02 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify
+
+float4 test_too_many_arg(float4 p0)
+{
+dst(p0, p0, p0);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+}
+
+float4 test_no_second_arg(float4 p0)
+{
+return dst(p0);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+}
+
+float4 test_no_args()
+{
+return dst();
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+}
+
+float4 test_3_components(float3 p0, float3 p1)
+{
+return dst(p0, p1);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector<[...], 3>' to 'vector<[...], 4>' for 1st 
argument}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector' to 'vector' for 1st 
argument}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector' to 'vector' for 1st 
argument}}
+}

farzonl wrote:

I think I resolved the last comment on this to quickly thinking the tests were 
added. I copied your implementation into godbolt and added a few tests
https://hlsl.godbolt.org/z/exrzrP4j6

All of these should be ` error: call to 'dst' is ambiguous`:
```hlsl
export float4 test(float4 a, double b) {
return dst(a,b);
}

export float4 test(double a, float4 b) {
return dst(a,b);
}

export float4 test(double4 a, float b) {
return dst(a,b);
}

export float4 test(double4 a, float4 b) {
return dst(a,b);
}
```

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


[clang] [flang] [llvm] [flang-rt] Pass the whole path of libflang_rt.runtime.a to linker on AIX (PR #131041)

2025-04-02 Thread Daniel Chen via cfe-commits

DanielCChen wrote:

> LGTM.
> 
> It would be safer/clearer to make the `IsFortran` argument change a separate 
> PR...

Good point. I could have made another PR to set `flang-rt` library name only. 
Will keep that in mind.

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


[clang] [HLSL] Implement `SpirvType` and `SpirvOpaqueType` (PR #134034)

2025-04-02 Thread Cassandra Beckley via cfe-commits

https://github.com/cassiebeckley updated 
https://github.com/llvm/llvm-project/pull/134034

>From 78ac1bc4225b41bc4b9fbd9fd9ab9dc82a2953ca Mon Sep 17 00:00:00 2001
From: Cassandra Beckley 
Date: Tue, 1 Apr 2025 23:12:02 -0700
Subject: [PATCH 1/3] [HLSL] Implement `SpirvType` and `SpirvOpaqueType`

This implements the design proposed by [Representing SpirvType in
Clang's Type System](https://github.com/llvm/wg-hlsl/pull/181). It
creates `HLSLInlineSpirvType` as a new `Type` subclass, and
`__hlsl_spirv_type` as a new builtin type template to create such a
type.

This new type is lowered to the `spirv.Type` target extension type, as
described in [Target Extension Types for Inline SPIR-V and Decorated
Types](https://github.com/llvm/wg-hlsl/blob/main/proposals/0017-inline-spirv-and-decorated-types.md).
---
 clang/include/clang-c/Index.h |   3 +-
 clang/include/clang/AST/ASTContext.h  |   5 +
 clang/include/clang/AST/ASTNodeTraverser.h|  18 +++
 clang/include/clang/AST/PropertiesBase.td |   1 +
 clang/include/clang/AST/RecursiveASTVisitor.h |  11 ++
 clang/include/clang/AST/Type.h| 142 +-
 clang/include/clang/AST/TypeLoc.h |  19 +++
 clang/include/clang/AST/TypeProperties.td |  18 +++
 clang/include/clang/Basic/BuiltinTemplates.td |  18 ++-
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Basic/TypeNodes.td|   1 +
 .../clang/Serialization/ASTRecordReader.h |   2 +
 .../clang/Serialization/ASTRecordWriter.h |  14 ++
 .../clang/Serialization/TypeBitCodes.def  |   1 +
 clang/lib/AST/ASTContext.cpp  |  59 
 clang/lib/AST/ASTImporter.cpp |  42 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp|  17 +++
 clang/lib/AST/ExprConstant.cpp|   1 +
 clang/lib/AST/ItaniumMangle.cpp   |  40 -
 clang/lib/AST/MicrosoftMangle.cpp |   5 +
 clang/lib/AST/Type.cpp|  14 ++
 clang/lib/AST/TypePrinter.cpp |  48 ++
 clang/lib/CodeGen/CGDebugInfo.cpp |   8 +
 clang/lib/CodeGen/CGDebugInfo.h   |   1 +
 clang/lib/CodeGen/CodeGenFunction.cpp |   2 +
 clang/lib/CodeGen/CodeGenTypes.cpp|   6 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |   2 +
 clang/lib/CodeGen/Targets/SPIR.cpp|  90 ++-
 clang/lib/Headers/CMakeLists.txt  |   1 +
 clang/lib/Headers/hlsl.h  |   4 +
 clang/lib/Headers/hlsl/hlsl_spirv.h   |  30 
 clang/lib/Sema/SemaExpr.cpp   |   1 +
 clang/lib/Sema/SemaLookup.cpp |  21 ++-
 clang/lib/Sema/SemaTemplate.cpp   | 103 -
 clang/lib/Sema/SemaTemplateDeduction.cpp  |   2 +
 clang/lib/Sema/SemaType.cpp   |   1 +
 clang/lib/Sema/TreeTransform.h|   7 +
 clang/lib/Serialization/ASTReader.cpp |   9 ++
 clang/lib/Serialization/ASTWriter.cpp |   4 +
 .../test/AST/HLSL/Inputs/pch_spirv_type.hlsl  |   6 +
 clang/test/AST/HLSL/ast-dump-SpirvType.hlsl   |  27 
 clang/test/AST/HLSL/pch_spirv_type.hlsl   |  17 +++
 clang/test/AST/HLSL/vector-alias.hlsl | 105 +++--
 .../inline/SpirvType.alignment.hlsl   |  16 ++
 .../inline/SpirvType.dx.error.hlsl|  12 ++
 clang/test/CodeGenHLSL/inline/SpirvType.hlsl  |  68 +
 .../inline/SpirvType.incomplete.hlsl  |  14 ++
 .../inline/SpirvType.literal.error.hlsl   |  11 ++
 clang/tools/libclang/CIndex.cpp   |   5 +
 clang/tools/libclang/CXType.cpp   |   1 +
 .../TableGen/ClangBuiltinTemplatesEmitter.cpp |  72 +++--
 51 files changed, 1052 insertions(+), 76 deletions(-)
 create mode 100644 clang/lib/Headers/hlsl/hlsl_spirv.h
 create mode 100644 clang/test/AST/HLSL/Inputs/pch_spirv_type.hlsl
 create mode 100644 clang/test/AST/HLSL/ast-dump-SpirvType.hlsl
 create mode 100644 clang/test/AST/HLSL/pch_spirv_type.hlsl
 create mode 100644 clang/test/CodeGenHLSL/inline/SpirvType.alignment.hlsl
 create mode 100644 clang/test/CodeGenHLSL/inline/SpirvType.dx.error.hlsl
 create mode 100644 clang/test/CodeGenHLSL/inline/SpirvType.hlsl
 create mode 100644 clang/test/CodeGenHLSL/inline/SpirvType.incomplete.hlsl
 create mode 100644 clang/test/CodeGenHLSL/inline/SpirvType.literal.error.hlsl

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 38e2417dcd181..757f8a3afc758 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -3034,7 +3034,8 @@ enum CXTypeKind {
 
   /* HLSL Types */
   CXType_HLSLResource = 179,
-  CXType_HLSLAttributedResource = 180
+  CXType_HLSLAttributedResource = 180,
+  CXType_HLSLInlineSpirv = 181
 };
 
 /**
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a24f30815e6b9..c62f9f7672010 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/i

[clang] [llvm] [Clang] [OpenMP] Support NOWAIT with optional argument (PR #128742)

2025-04-02 Thread Michael Klemm via cfe-commits


@@ -7,13 +7,14 @@ void foo() {
 
 int main(int argc, char **argv) {
   int i;
-  #pragma omp target simd nowait( // expected-warning {{extra tokens at the 
end of '#pragma omp target simd' are ignored}}
+  #pragma omp target simd nowait( //  expected-error {{expected expression}} 
//  expected-error {{expected ')'}} // expected-note {{to match this '('}}
   for (i = 0; i < argc; ++i) foo();
   #pragma omp target simd nowait (argc)) // expected-warning {{extra tokens at 
the end of '#pragma omp target simd' are ignored}}
   for (i = 0; i < argc; ++i) foo();
   #pragma omp target simd nowait device (-10u)
   for (i = 0; i < argc; ++i) foo();
-  #pragma omp target simd nowait (3.14) device (-10u) // expected-warning 
{{extra tokens at the end of '#pragma omp target simd' are ignored}}
+  #pragma omp target simd nowait (3.14) device (-10u) // expected-error 
{{arguments of OpenMP clause 'nowait' with bitwise operators cannot be of 
floating type}}

mjklemm wrote:

```suggestion
  #pragma omp target simd nowait (3.14) device (-10u) // expected-error 
{{arguments of OpenMP clause 'nowait' with bitwise operators cannot be of 
floating-point type}}
```

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Erich Keane via cfe-commits


@@ -4920,6 +4920,116 @@ If no address spaces names are provided, all address 
spaces are fenced.
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local")
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local", "global")
 
+__builtin_amdgcn_processor_is and __builtin_amdgcn_is_invocable
+^^^
+
+``__builtin_amdgcn_processor_is`` and ``__builtin_amdgcn_is_invocable`` provide
+a functional mechanism for programatically querying:
+
+* the identity of the current target processor;
+* the capability of the current target processor to invoke a particular 
builtin.
+
+**Syntax**:
+
+.. code-block:: c
+
+  // When used as the predicate for a control structure
+  bool __builtin_amdgcn_processor_is(const char*);
+  bool __builtin_amdgcn_is_invocable(builtin_name);
+  // Otherwise
+  void __builtin_amdgcn_processor_is(const char*);
+  void __builtin_amdgcn_is_invocable(void);
+
+**Example of use**:
+
+.. code-block:: c++
+
+  if (__builtin_amdgcn_processor_is("gfx1201") ||
+  __builtin_amdgcn_is_invocable(__builtin_amdgcn_s_sleep_var))
+__builtin_amdgcn_s_sleep_var(x);
+
+  if (!__builtin_amdgcn_processor_is("gfx906"))
+__builtin_amdgcn_s_wait_event_export_ready();
+  else if (__builtin_amdgcn_processor_is("gfx1010") ||
+   __builtin_amdgcn_processor_is("gfx1101"))
+__builtin_amdgcn_s_ttracedata_imm(1);
+
+  while (__builtin_amdgcn_processor_is("gfx1101")) *p += x;
+
+  do { *p -= x; } while (__builtin_amdgcn_processor_is("gfx1010"));

erichkeane wrote:

is the formatting OK on this line?  Github is making this look awful weird.

Also-also: This is an infinite loop, right?  As you said this is never 
evaluated at runtime, the answer would be fixed?

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Erich Keane via cfe-commits


@@ -13329,6 +13359,9 @@ inline QualType Sema::CheckLogicalOperands(ExprResult 
&LHS, ExprResult &RHS,
   // The following is safe because we only use this method for
   // non-overloadable operands.
 
+  if (IsAMDGPUPredicateBI(LHS.get()) && IsAMDGPUPredicateBI(RHS.get()))

erichkeane wrote:

If we want to diagnose this not in the 'right' place we should, though that is 
going ot be absolutely fraught with problems.  But making it return `void` is 
not the way to do this.

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


[clang] [llvm] [Clang] [OpenMP] Support NOWAIT with optional argument (PR #128742)

2025-04-02 Thread Michael Klemm via cfe-commits


@@ -7,13 +7,13 @@ void foo() {
 
 int main(int argc, char **argv) {
   int i;
-#pragma omp target teams distribute parallel for nowait( // expected-warning 
{{extra tokens at the end of '#pragma omp target teams distribute parallel for' 
are ignored}}
+#pragma omp target teams distribute parallel for nowait( //  expected-error 
{{expected expression}} //  expected-error {{expected ')'}} // expected-note 
{{to match this '('}}
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute parallel for nowait (argc)) // 
expected-warning {{extra tokens at the end of '#pragma omp target teams 
distribute parallel for' are ignored}}
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute parallel for nowait device (-10u)
   for (i = 0; i < argc; ++i) foo();
-#pragma omp target teams distribute parallel for nowait (3.14) device (-10u) 
// expected-warning {{extra tokens at the end of '#pragma omp target teams 
distribute parallel for' are ignored}}
+#pragma omp target teams distribute parallel for nowait (3.14) device (-10u) 
// expected-error {{arguments of OpenMP clause 'nowait' with bitwise operators 
cannot be of floating type}}

mjklemm wrote:

```suggestion
#pragma omp target teams distribute parallel for nowait (3.14) device (-10u) // 
expected-error {{arguments of OpenMP clause 'nowait' with bitwise operators 
cannot be of floating-point type}}
```

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


[clang] [llvm] [Clang] [OpenMP] Support NOWAIT with optional argument (PR #128742)

2025-04-02 Thread Michael Klemm via cfe-commits


@@ -6,13 +6,11 @@ void foo() {
 }
 
 int main(int argc, char **argv) {
-#pragma omp target teams nowait( // expected-warning {{extra tokens at the end 
of '#pragma omp target teams' are ignored}}
-  foo();
-#pragma omp target teams nowait (argc)) // expected-warning {{extra tokens at 
the end of '#pragma omp target teams' are ignored}}
+#pragma omp target teams nowait( // expected-error {{expected expression}} // 
expected-error {{expected ')'}} //expected-note {{to match this '('}}
   foo();
 #pragma omp target teams nowait device (-10u)
   foo();
-#pragma omp target teams nowait (3.14) device (-10u) // expected-warning 
{{extra tokens at the end of '#pragma omp target teams' are ignored}}
+#pragma omp target teams nowait (3.14) device (-10u) // expected-error 
{{arguments of OpenMP clause 'nowait' with bitwise operators cannot be of 
floating type}}

mjklemm wrote:

```suggestion
#pragma omp target teams nowait (3.14) device (-10u) // expected-error 
{{arguments of OpenMP clause 'nowait' with bitwise operators cannot be of 
floating-point type}}
```

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Erich Keane via cfe-commits


@@ -4920,6 +4920,116 @@ If no address spaces names are provided, all address 
spaces are fenced.
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local")
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local", "global")
 
+__builtin_amdgcn_processor_is and __builtin_amdgcn_is_invocable
+^^^
+
+``__builtin_amdgcn_processor_is`` and ``__builtin_amdgcn_is_invocable`` provide
+a functional mechanism for programatically querying:
+
+* the identity of the current target processor;
+* the capability of the current target processor to invoke a particular 
builtin.
+
+**Syntax**:
+
+.. code-block:: c
+
+  // When used as the predicate for a control structure
+  bool __builtin_amdgcn_processor_is(const char*);
+  bool __builtin_amdgcn_is_invocable(builtin_name);
+  // Otherwise
+  void __builtin_amdgcn_processor_is(const char*);
+  void __builtin_amdgcn_is_invocable(void);
+
+**Example of use**:
+
+.. code-block:: c++
+
+  if (__builtin_amdgcn_processor_is("gfx1201") ||
+  __builtin_amdgcn_is_invocable(__builtin_amdgcn_s_sleep_var))
+__builtin_amdgcn_s_sleep_var(x);
+
+  if (!__builtin_amdgcn_processor_is("gfx906"))
+__builtin_amdgcn_s_wait_event_export_ready();
+  else if (__builtin_amdgcn_processor_is("gfx1010") ||
+   __builtin_amdgcn_processor_is("gfx1101"))
+__builtin_amdgcn_s_ttracedata_imm(1);
+
+  while (__builtin_amdgcn_processor_is("gfx1101")) *p += x;
+
+  do { *p -= x; } while (__builtin_amdgcn_processor_is("gfx1010"));
+
+  for (; __builtin_amdgcn_processor_is("gfx1201"); ++*p) break;
+
+  if 
(__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_wait_event_export_ready))
+__builtin_amdgcn_s_wait_event_export_ready();
+  else if (__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_ttracedata_imm))
+__builtin_amdgcn_s_ttracedata_imm(1);
+
+  do {
+*p -= x;
+  } while 
(__builtin_amdgcn_is_invocable(__builtin_amdgcn_global_load_tr_b64_i32));
+
+  for (; __builtin_amdgcn_is_invocable(__builtin_amdgcn_permlane64); ++*p) 
break;
+
+**Description**:
+
+When used as the predicate value of the following control structures:
+
+.. code-block:: c++
+
+  if (...)
+  while (...)
+  do { } while (...)
+  for (...)
+
+be it directly, or as arguments to logical operators such as ``!, ||, &&``, the

erichkeane wrote:

How about when used as an initializer in one of those?  Consider:

`if (auto b = __builtin_amd_gcn_processor_is("gfx1201"); b && 
another_condition)`

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


[clang] [llvm] [Clang] [OpenMP] Support NOWAIT with optional argument (PR #128742)

2025-04-02 Thread Michael Klemm via cfe-commits


@@ -6,13 +6,13 @@ void foo() {
 }
 
 int main(int argc, char **argv) {
-  #pragma omp target parallel nowait( // expected-warning {{extra tokens at 
the end of '#pragma omp target parallel' are ignored}}
-  foo();
+  #pragma omp target parallel nowait( //  expected-error {{expected 
expression}} //  expected-error {{expected ')'}} // expected-note {{to match 
this '('}}
+foo();
   #pragma omp target parallel nowait (argc)) // expected-warning {{extra 
tokens at the end of '#pragma omp target parallel' are ignored}}
   foo();
   #pragma omp target parallel nowait device (-10u)
   foo();
-  #pragma omp target parallel nowait (3.14) device (-10u) // expected-warning 
{{extra tokens at the end of '#pragma omp target parallel' are ignored}}
+  #pragma omp target parallel nowait (3.14) device (-10u) // expected-error 
{{arguments of OpenMP clause 'nowait' with bitwise operators cannot be of 
floating type}}

mjklemm wrote:

```suggestion
  #pragma omp target parallel nowait (3.14) device (-10u) // expected-error 
{{arguments of OpenMP clause 'nowait' with bitwise operators cannot be of 
floating-point type}}
```

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


[clang] [llvm] [Clang] [OpenMP] Support NOWAIT with optional argument (PR #128742)

2025-04-02 Thread Michael Klemm via cfe-commits


@@ -7,13 +7,13 @@ void foo() {
 
 int main(int argc, char **argv) {
   int i;
-  #pragma omp target parallel for nowait( // expected-warning {{extra tokens 
at the end of '#pragma omp target parallel for' are ignored}}
+  #pragma omp target parallel for nowait( //  expected-error {{expected 
expression}} //  expected-error {{expected ')'}} // expected-note {{to match 
this '('}}
   for (i = 0; i < argc; ++i) foo();
   #pragma omp target parallel for nowait (argc)) // expected-warning {{extra 
tokens at the end of '#pragma omp target parallel for' are ignored}}
   for (i = 0; i < argc; ++i) foo();
   #pragma omp target parallel for nowait device (-10u)
   for (i = 0; i < argc; ++i) foo();
-  #pragma omp target parallel for nowait (3.14) device (-10u) // 
expected-warning {{extra tokens at the end of '#pragma omp target parallel for' 
are ignored}}
+  #pragma omp target parallel for nowait (3.14) device (-10u) // 
expected-error {{arguments of OpenMP clause 'nowait' with bitwise operators 
cannot be of floating type}}

mjklemm wrote:

```suggestion
  #pragma omp target parallel for nowait (3.14) device (-10u) // expected-error 
{{arguments of OpenMP clause 'nowait' with bitwise operators cannot be of 
floating-point type}}
```

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Erich Keane via cfe-commits


@@ -6541,6 +6541,22 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, 
SourceLocation LParenLoc,
   if (Result.isInvalid()) return ExprError();
   Fn = Result.get();
 
+  // The __builtin_amdgcn_is_invocable builtin is special, and will be resolved

erichkeane wrote:

Not a big fan of this AT ALL.  This needs to be much less special.

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


[clang] [SYCL][SPIR-V Backend][clang-sycl-linker] Add SPIR-V backend support inside clang-sycl-linker (PR #133967)

2025-04-02 Thread Arvind Sudarsanam via cfe-commits

https://github.com/asudarsa updated 
https://github.com/llvm/llvm-project/pull/133967

>From 0ab40315cd5ca320d84f87c99b8f23d9b6e8ed36 Mon Sep 17 00:00:00 2001
From: Arvind Sudarsanam 
Date: Mon, 31 Mar 2025 14:31:24 -0700
Subject: [PATCH 1/6] [SYCL][SPIR-V Backend][clang-sycl-linker] Add SPIR-V
 backend support inside clang-sycl-linker

This PR does the following:

1. Use SPIR-V backend to do LLVM to SPIR-V translation inside clang-sycl-linker
2. Remove llvm-spirv translator from clang-sycl-linker
Currently, no SPIR-V extensions are enabled for SYCL compilation flow. This 
will be updated in subsequent commits.

Thanks

Signed-off-by: Arvind Sudarsanam 
---
 clang/test/Driver/clang-sycl-linker-test.cpp  |  14 +-
 clang/test/Driver/sycl-link-spirv-target.cpp  |   6 +-
 clang/tools/clang-sycl-linker/CMakeLists.txt  |   5 +-
 .../clang-sycl-linker/ClangSYCLLinker.cpp | 187 +++---
 clang/tools/clang-sycl-linker/SYCLLinkOpts.td |   2 +-
 5 files changed, 76 insertions(+), 138 deletions(-)

diff --git a/clang/test/Driver/clang-sycl-linker-test.cpp 
b/clang/test/Driver/clang-sycl-linker-test.cpp
index 729561bd09cd8..2f860ae74e97d 100644
--- a/clang/test/Driver/clang-sycl-linker-test.cpp
+++ b/clang/test/Driver/clang-sycl-linker-test.cpp
@@ -6,7 +6,7 @@
 // RUN: clang-sycl-linker --dry-run -v -triple=spirv64 %t_1.bc %t_2.bc -o 
a.spv 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=SIMPLE-FO
 // SIMPLE-FO: sycl-device-link: inputs: {{.*}}.bc, {{.*}}.bc  libfiles:  
output: [[LLVMLINKOUT:.*]].bc
-// SIMPLE-FO-NEXT: "{{.*}}llvm-spirv{{.*}}" {{.*}}-o a.spv [[LLVMLINKOUT]].bc
+// SIMPLE-FO-NEXT: SPIR-V Backend: input: [[LLVMLINKOUT]].bc, output: a.spv
 //
 // Test the dry run of a simple case with device library files specified.
 // RUN: touch %T/lib1.bc
@@ -14,7 +14,7 @@
 // RUN: clang-sycl-linker --dry-run -v -triple=spirv64 %t_1.bc %t_2.bc 
--library-path=%T --device-libs=lib1.bc,lib2.bc -o a.spv 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=DEVLIBS
 // DEVLIBS: sycl-device-link: inputs: {{.*}}.bc  libfiles: {{.*}}lib1.bc, 
{{.*}}lib2.bc  output: [[LLVMLINKOUT:.*]].bc
-// DEVLIBS-NEXT: "{{.*}}llvm-spirv{{.*}}" {{.*}}-o a.spv [[LLVMLINKOUT]].bc
+// DEVLIBS-NEXT: SPIR-V Backend: input: [[LLVMLINKOUT]].bc, output: a.spv
 //
 // Test a simple case with a random file (not bitcode) as input.
 // RUN: touch %t.o
@@ -29,13 +29,3 @@
 // RUN: not clang-sycl-linker --dry-run -triple=spirv64 %t_1.bc %t_2.bc 
--library-path=%T --device-libs=lib1.bc,lib2.bc,lib3.bc -o a.spv 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=DEVLIBSERR2
 // DEVLIBSERR2: '{{.*}}lib3.bc' SYCL device library file is not found
-//
-// Test if correct set of llvm-spirv options are emitted for windows 
environment.
-// RUN: clang-sycl-linker --dry-run -v -triple=spirv64 --is-windows-msvc-env 
%t_1.bc %t_2.bc -o a.spv 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=LLVMOPTSWIN
-// LLVMOPTSWIN: -spirv-debug-info-version=ocl-100 
-spirv-allow-extra-diexpressions -spirv-allow-unknown-intrinsics=llvm.genx. 
-spirv-ext=
-//
-// Test if correct set of llvm-spirv options are emitted for linux environment.
-// RUN: clang-sycl-linker --dry-run -v -triple=spirv64  %t_1.bc %t_2.bc -o 
a.spv 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=LLVMOPTSLIN
-// LLVMOPTSLIN: -spirv-debug-info-version=nonsemantic-shader-200 
-spirv-allow-unknown-intrinsics=llvm.genx. -spirv-ext=
diff --git a/clang/test/Driver/sycl-link-spirv-target.cpp 
b/clang/test/Driver/sycl-link-spirv-target.cpp
index 7585ef8b14a59..586adae619165 100644
--- a/clang/test/Driver/sycl-link-spirv-target.cpp
+++ b/clang/test/Driver/sycl-link-spirv-target.cpp
@@ -3,7 +3,7 @@
 //
 // Test that -Xlinker options are being passed to clang-sycl-linker.
 // RUN: touch %t.bc
-// RUN: %clangxx -### --target=spirv64 --sycl-link -Xlinker 
--llvm-spirv-path=/tmp \
-// RUN:   -Xlinker -triple=spirv64 -Xlinker --library-path=/tmp -Xlinker 
--device-libs=lib1.bc,lib2.bc %t.bc 2>&1 \
+// RUN: %clangxx -### --target=spirv64 --sycl-link -Xlinker -triple=spirv64 
-Xlinker --library-path=/tmp \
+// RUN:   -Xlinker --device-libs=lib1.bc,lib2.bc %t.bc 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=XLINKEROPTS
-// XLINKEROPTS: "{{.*}}clang-sycl-linker{{.*}}" "--llvm-spirv-path=/tmp" 
"-triple=spirv64" "--library-path=/tmp" "--device-libs=lib1.bc,lib2.bc" 
"{{.*}}.bc" "-o" "a.out"
+// XLINKEROPTS: "{{.*}}clang-sycl-linker{{.*}}" "-triple=spirv64" 
"--library-path=/tmp" "--device-libs=lib1.bc,lib2.bc" "{{.*}}.bc" "-o" "a.out"
diff --git a/clang/tools/clang-sycl-linker/CMakeLists.txt 
b/clang/tools/clang-sycl-linker/CMakeLists.txt
index 382c0ca441940..ee89e8b0a5570 100644
--- a/clang/tools/clang-sycl-linker/CMakeLists.txt
+++ b/clang/tools/clang-sycl-linker/CMakeLists.txt
@@ -1,14 +1,17 @@
 set(LLVM_LINK_COMPONENTS
   ${LLVM_TARGETS_TO_BUILD}
+  Analysis
   BinaryFormat
   BitWriter
   Core
   IRReader
   Linker
+  MC
   Option
   Object
-  TargetParser
   Support
+  Target
+  TargetParser
   )
 
 set(LLVM_TARGET_DEFIN

[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Erich Keane via cfe-commits


@@ -15576,6 +15609,38 @@ static bool isOverflowingIntegerType(ASTContext &Ctx, 
QualType T) {
   return Ctx.getIntWidth(T) >= Ctx.getIntWidth(Ctx.IntTy);
 }
 
+static Expr *ExpandAMDGPUPredicateBI(ASTContext &Ctx, CallExpr *CE) {
+  if (!CE->getBuiltinCallee())
+return CXXBoolLiteralExpr::Create(Ctx, false, Ctx.BoolTy, 
CE->getExprLoc());
+
+  if (Ctx.getTargetInfo().getTriple().isSPIRV()) {
+CE->setType(Ctx.getLogicalOperationType());
+return CE;
+  }
+
+  bool P = false;
+  auto &TI = Ctx.getTargetInfo();
+
+  if (CE->getDirectCallee()->getName() == "__builtin_amdgcn_processor_is") {

erichkeane wrote:

This isn't sufficient, you actually have to check that it is the builtin.  If 
you check just the name it could be a different one, as this doesn't give you 
the name of namespaces/classes/etc, just the immediate name.

ALSO, `getName` in many cases will assert if this is an operator/other nameless 
function.

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Erich Keane via cfe-commits


@@ -4920,6 +4920,116 @@ If no address spaces names are provided, all address 
spaces are fenced.
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local")
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local", "global")
 
+__builtin_amdgcn_processor_is and __builtin_amdgcn_is_invocable
+^^^
+
+``__builtin_amdgcn_processor_is`` and ``__builtin_amdgcn_is_invocable`` provide
+a functional mechanism for programatically querying:
+
+* the identity of the current target processor;
+* the capability of the current target processor to invoke a particular 
builtin.
+
+**Syntax**:
+
+.. code-block:: c
+
+  // When used as the predicate for a control structure
+  bool __builtin_amdgcn_processor_is(const char*);
+  bool __builtin_amdgcn_is_invocable(builtin_name);
+  // Otherwise
+  void __builtin_amdgcn_processor_is(const char*);
+  void __builtin_amdgcn_is_invocable(void);
+
+**Example of use**:
+
+.. code-block:: c++
+
+  if (__builtin_amdgcn_processor_is("gfx1201") ||
+  __builtin_amdgcn_is_invocable(__builtin_amdgcn_s_sleep_var))
+__builtin_amdgcn_s_sleep_var(x);
+
+  if (!__builtin_amdgcn_processor_is("gfx906"))
+__builtin_amdgcn_s_wait_event_export_ready();
+  else if (__builtin_amdgcn_processor_is("gfx1010") ||
+   __builtin_amdgcn_processor_is("gfx1101"))
+__builtin_amdgcn_s_ttracedata_imm(1);
+
+  while (__builtin_amdgcn_processor_is("gfx1101")) *p += x;
+
+  do { *p -= x; } while (__builtin_amdgcn_processor_is("gfx1010"));
+
+  for (; __builtin_amdgcn_processor_is("gfx1201"); ++*p) break;
+
+  if 
(__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_wait_event_export_ready))
+__builtin_amdgcn_s_wait_event_export_ready();
+  else if (__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_ttracedata_imm))
+__builtin_amdgcn_s_ttracedata_imm(1);
+
+  do {
+*p -= x;
+  } while 
(__builtin_amdgcn_is_invocable(__builtin_amdgcn_global_load_tr_b64_i32));

erichkeane wrote:

Formatting on this one is weird too.  Also, same question again, and again on 
4972.

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Erich Keane via cfe-commits


@@ -15576,6 +15609,38 @@ static bool isOverflowingIntegerType(ASTContext &Ctx, 
QualType T) {
   return Ctx.getIntWidth(T) >= Ctx.getIntWidth(Ctx.IntTy);
 }
 
+static Expr *ExpandAMDGPUPredicateBI(ASTContext &Ctx, CallExpr *CE) {
+  if (!CE->getBuiltinCallee())
+return CXXBoolLiteralExpr::Create(Ctx, false, Ctx.BoolTy, 
CE->getExprLoc());
+
+  if (Ctx.getTargetInfo().getTriple().isSPIRV()) {
+CE->setType(Ctx.getLogicalOperationType());
+return CE;
+  }
+
+  bool P = false;
+  auto &TI = Ctx.getTargetInfo();
+
+  if (CE->getDirectCallee()->getName() == "__builtin_amdgcn_processor_is") {
+auto GFX = dyn_cast(CE->getArg(0)->IgnoreParenCasts());
+auto TID = TI.getTargetID();
+if (GFX && TID) {
+  auto N = GFX->getString();
+  P = TI.isValidCPUName(GFX->getString()) && TID->find(N) == 0;
+}
+  } else {
+auto FD = cast(CE->getArg(0)->getReferencedDeclOfCallee());

erichkeane wrote:

so many more missing stars.

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Erich Keane via cfe-commits


@@ -4920,6 +4920,116 @@ If no address spaces names are provided, all address 
spaces are fenced.
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local")
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local", "global")
 
+__builtin_amdgcn_processor_is and __builtin_amdgcn_is_invocable
+^^^
+
+``__builtin_amdgcn_processor_is`` and ``__builtin_amdgcn_is_invocable`` provide
+a functional mechanism for programatically querying:
+
+* the identity of the current target processor;
+* the capability of the current target processor to invoke a particular 
builtin.
+
+**Syntax**:
+
+.. code-block:: c
+
+  // When used as the predicate for a control structure
+  bool __builtin_amdgcn_processor_is(const char*);
+  bool __builtin_amdgcn_is_invocable(builtin_name);
+  // Otherwise

erichkeane wrote:

Re-answering my own question: Later on you seem to be using 'predicate for a 
control structure' to mean 'the condition of a if/while/for.  However, why is 
it problematic to have someone check this and store it in a variable?  Why is:

`if (__builtin_amd_gcn_processor_is("gfx1201"))`  fine, but:
`bool b = __builtin_amd_gcn_processor_is("gfx1201"); if (b)` a  problem?  

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Erich Keane via cfe-commits


@@ -4920,6 +4920,116 @@ If no address spaces names are provided, all address 
spaces are fenced.
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local")
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local", "global")
 
+__builtin_amdgcn_processor_is and __builtin_amdgcn_is_invocable
+^^^
+
+``__builtin_amdgcn_processor_is`` and ``__builtin_amdgcn_is_invocable`` provide
+a functional mechanism for programatically querying:
+
+* the identity of the current target processor;
+* the capability of the current target processor to invoke a particular 
builtin.
+
+**Syntax**:
+
+.. code-block:: c
+
+  // When used as the predicate for a control structure
+  bool __builtin_amdgcn_processor_is(const char*);
+  bool __builtin_amdgcn_is_invocable(builtin_name);
+  // Otherwise
+  void __builtin_amdgcn_processor_is(const char*);
+  void __builtin_amdgcn_is_invocable(void);
+
+**Example of use**:
+
+.. code-block:: c++
+
+  if (__builtin_amdgcn_processor_is("gfx1201") ||
+  __builtin_amdgcn_is_invocable(__builtin_amdgcn_s_sleep_var))
+__builtin_amdgcn_s_sleep_var(x);
+
+  if (!__builtin_amdgcn_processor_is("gfx906"))
+__builtin_amdgcn_s_wait_event_export_ready();
+  else if (__builtin_amdgcn_processor_is("gfx1010") ||
+   __builtin_amdgcn_processor_is("gfx1101"))
+__builtin_amdgcn_s_ttracedata_imm(1);
+
+  while (__builtin_amdgcn_processor_is("gfx1101")) *p += x;
+
+  do { *p -= x; } while (__builtin_amdgcn_processor_is("gfx1010"));
+
+  for (; __builtin_amdgcn_processor_is("gfx1201"); ++*p) break;
+
+  if 
(__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_wait_event_export_ready))
+__builtin_amdgcn_s_wait_event_export_ready();
+  else if (__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_ttracedata_imm))
+__builtin_amdgcn_s_ttracedata_imm(1);
+
+  do {
+*p -= x;
+  } while 
(__builtin_amdgcn_is_invocable(__builtin_amdgcn_global_load_tr_b64_i32));
+
+  for (; __builtin_amdgcn_is_invocable(__builtin_amdgcn_permlane64); ++*p) 
break;
+
+**Description**:
+
+When used as the predicate value of the following control structures:
+
+.. code-block:: c++
+
+  if (...)
+  while (...)
+  do { } while (...)
+  for (...)
+
+be it directly, or as arguments to logical operators such as ``!, ||, &&``, the
+builtins return a boolean value that:
+
+* indicates whether the current target matches the argument; the argument MUST
+  be a string literal and a valid AMDGPU target
+* indicates whether the builtin function passed as the argument can be invoked
+  by the current target; the argument MUST be either a generic or AMDGPU
+  specific builtin name
+
+Outside of these contexts, the builtins have a ``void`` returning signature
+which prevents their misuse.

erichkeane wrote:

What misuse here?  If you want to catch other situations, just diagnose.  But 
it seems that these values could be useful/possible outside of condition 
expressions.

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Erich Keane via cfe-commits

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

The user interface design of these builtins is just completely unacceptable, 
and it has made the sema implementation more difficult than it needs to be.  

Best I can tell, the answer for even things like `decltype` changes whether it 
is in a conditional or not, which isn't right.



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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Erich Keane via cfe-commits


@@ -585,6 +597,23 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 llvm::Value *Env = EmitScalarExpr(E->getArg(0));
 return Builder.CreateCall(F, {Env});
   }
+  case AMDGPU::BI__builtin_amdgcn_processor_is: {
+assert(CGM.getTriple().isSPIRV() &&
+   "__builtin_amdgcn_processor_is should never reach CodeGen for "
+   "concrete targets!");
+StringRef Proc = cast(E->getArg(0))->getString();
+return GetOrInsertAMDGPUPredicate(*this, "llvm.amdgcn.is." + Proc);
+  }
+  case AMDGPU::BI__builtin_amdgcn_is_invocable: {
+assert(CGM.getTriple().isSPIRV() &&
+   "__builtin_amdgcn_is_invocable should never reach CodeGen for "
+   "concrete targets!");
+auto FD = cast(

erichkeane wrote:

```suggestion
auto *FD = cast(
```

With auto, we require a * with all pointer types, looks like you've missed a 
few, so please go back and fix the ones you have.

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


[clang] Remove duplicate API (PR #132776)

2025-04-02 Thread via cfe-commits

Jugst3r wrote:

Sure, I did what @Endilll suggested. It is kind of unfortunate to have such 
similar type names :/. I don't think I can use the [[attribute]] C++-style 
syntax, maybe there is another syntax I am not aware of, but for the mean time 
I put the deprecated inside the comments.

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


[clang] [clang-tools-extra] [clang] support pack expansions for trailing requires clauses (PR #133190)

2025-04-02 Thread Erich Keane via cfe-commits


@@ -78,6 +78,22 @@ class UnresolvedSetImpl;
 class VarTemplateDecl;
 enum class ImplicitParamKind;
 
+// Holds a constraint expression along with a pack expansion index, if
+// expanded.
+struct AssociatedConstraint {
+  const Expr *ConstraintExpr = nullptr;
+  int ArgumentPackSubstitutionIndex = -1;

erichkeane wrote:

I was thinking about it... I'd LOVE instead (though this is a 'more work' thing 
:D so nothing to do here unless you'd like to ) if we just  had a 
`std::optional` like type to represent all of these substitution/pack indexes.  
The difference here is that the `optional` type would just use a single value 
as its `unset` state instead of a separate value, so we don't pay the size cost.

Additionally, we could make all of these unsigned instead of signed ints, so 
presumably we get a little bit of (unusable for other reasons!) range back.  

Also/also: serialization/etc all ends up being self-solved since they can have 
their own serialization/etc.

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


[clang] [flang] [flang] Complete alignment of -x language modes with gfortran (PR #133775)

2025-04-02 Thread David Truby via cfe-commits

https://github.com/DavidTruby updated 
https://github.com/llvm/llvm-project/pull/133775

>From aeca7c2c7bf4cc7aef87374f3890f2a42e61d07d Mon Sep 17 00:00:00 2001
From: David Truby 
Date: Mon, 31 Mar 2025 19:39:37 +0100
Subject: [PATCH 1/2] [flang] Complete alignment of -x language modes with
 gfortran

This fixes an issue where, since the alignment of the -x lanaguage
modes, .f90 files were being preprocessed by default. This patch
completes the alignment of the meaning of the f95-pp-input and f95
language modes to match gfortran, fixing that issue.
---
 clang/include/clang/Driver/Types.def |  4 ++--
 .../Driver/input-from-stdin/input-from-stdin.f90 |  2 +-
 flang/test/Driver/phases.f90 | 12 ++--
 flang/test/Driver/pp-fixed-form.f90  | 16 
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Driver/Types.def 
b/clang/include/clang/Driver/Types.def
index 214c5e7a789f9..2b6b3e75c1c97 100644
--- a/clang/include/clang/Driver/Types.def
+++ b/clang/include/clang/Driver/Types.def
@@ -88,8 +88,8 @@ TYPE("assembler-with-cpp",   Asm,  PP_Asm,
  "S",  phases
 // modules when Flang needs to emit pre-processed files. Therefore, the
 // `PP_TYPE` is set to `PP_Fortran` so that the driver is fine with
 // "pre-processing a pre-processed file".
-TYPE("f95",  PP_Fortran,   PP_Fortran,  "i",  
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
-TYPE("f95-cpp-input",Fortran,  PP_Fortran,  nullptr,  
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
+TYPE("f95",  Fortran,   PP_Fortran,  nullptr,  
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
+TYPE("f95-cpp-input",PP_Fortran,  PP_Fortran,  "i",  
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
 TYPE("java", Java, INVALID, nullptr,  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 
 // LLVM IR/LTO types. We define separate types for IR and LTO because LTO
diff --git a/flang/test/Driver/input-from-stdin/input-from-stdin.f90 
b/flang/test/Driver/input-from-stdin/input-from-stdin.f90
index 1fcc0340a64ba..285f0751b35d8 100644
--- a/flang/test/Driver/input-from-stdin/input-from-stdin.f90
+++ b/flang/test/Driver/input-from-stdin/input-from-stdin.f90
@@ -6,7 +6,7 @@
 ! Input type is implicit
 ! RUN: cat %s | %flang -E -cpp - | FileCheck %s --check-prefix=PP-NOT-DEFINED
 ! RUN: cat %s | %flang -DNEW -E -cpp - | FileCheck %s --check-prefix=PP-DEFINED
-! RUN: cat %s | %flang -DNEW -E - | FileCheck %s --check-prefix=PP-DEFINED
+! RUN: cat %s | %flang -DNEW -E - | FileCheck %s --check-prefix=PP-NOT-DEFINED
 ! RUN: cat %s | %flang -DNEW -E -nocpp - | FileCheck %s 
--check-prefix=PP-NOT-DEFINED
 
 ! Input type is explicit
diff --git a/flang/test/Driver/phases.f90 b/flang/test/Driver/phases.f90
index b688600dae035..9346773c883ef 100644
--- a/flang/test/Driver/phases.f90
+++ b/flang/test/Driver/phases.f90
@@ -4,15 +4,15 @@
 ! RUN: %flang -fsyntax-only -ccc-print-phases %s 2>&1 | FileCheck %s 
--check-prefix=COMPILE
 ! RUN: %flang -c -ccc-print-phases %s 2>&1 | FileCheck %s 
--check-prefix=EMIT_OBJ
 
-! PP: +- 0: input, "{{.*}}phases.f90", f95-cpp-input
-! PP-NEXT: 1: preprocessor, {0}, f95
+! PP: +- 0: input, "{{.*}}phases.f90", f95
+! PP-NEXT: 1: preprocessor, {0}, f95-cpp-input
 
-! COMPILE: +- 0: input, "{{.*}}phases.f90", f95-cpp-input
-! COMPILE-NEXT: 1: preprocessor, {0}, f95
+! COMPILE: +- 0: input, "{{.*}}phases.f90", f95
+! COMPILE-NEXT: 1: preprocessor, {0}, f95-cpp-input
 ! COMPILE-NEXT: 2: compiler, {1}, none
 
-! EMIT_OBJ: +- 0: input, "{{.*}}phases.f90", f95-cpp-input
-! EMIT_OBJ-NEXT: 1: preprocessor, {0}, f95
+! EMIT_OBJ: +- 0: input, "{{.*}}phases.f90", f95
+! EMIT_OBJ-NEXT: 1: preprocessor, {0}, f95-cpp-input
 ! EMIT_OBJ-NEXT: 2: compiler, {1}, ir
 ! EMIT_OBJ-NEXT: +- 3: backend, {2}, assembler
 ! EMIT_OBJ-NEXT: 4: assembler, {3}, object
diff --git a/flang/test/Driver/pp-fixed-form.f90 
b/flang/test/Driver/pp-fixed-form.f90
index 4695da78763ae..bb869cd3341a7 100644
--- a/flang/test/Driver/pp-fixed-form.f90
+++ b/flang/test/Driver/pp-fixed-form.f90
@@ -1,19 +1,19 @@
 !RUN: %flang -save-temps -### %S/Inputs/free-form-test.f90  2>&1 | FileCheck 
%s --check-prefix=FREE
-FREE:   "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" "f95-cpp-input" 
"{{.*}}/free-form-test.f90"
-FREE-NEXT:  "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95" "free-form-test.i"
+FREE:   "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" "f95" 
"{{.*}}/free-form-test.f90"
+FREE-NEXT:  "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95-cpp-input" 
"free-form-test.i"
 
 !RUN: %flang -save-temps -### %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s 
--check-prefix=FIXED
-FIXED:  "-fc1"

[clang] [Clang] Fix dependent local class instantiation bugs (PR #134038)

2025-04-02 Thread Erich Keane via cfe-commits


@@ -4264,7 +4264,8 @@ Sema::InstantiateClassMembers(SourceLocation 
PointOfInstantiation,
   if (FunctionDecl *Pattern =
   Function->getInstantiatedFromMemberFunction()) {
 
-if (Function->isIneligibleOrNotSelected())
+if (!Instantiation->getDeclContext()->isDependentContext() &&

erichkeane wrote:

Hmm... I don't think we want to go this far, right?We still would like to 
aggressively instantiate these so we get diagnostics/etc, even if it is in a 
dependent context.  

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


[clang] [llvm] [Clang][AMDGPU] Add __builtin_amdgcn_cvt_off_f32_i4 (PR #133741)

2025-04-02 Thread Shilei Tian via cfe-commits
Juan Manuel Martinez =?utf-8?q?Caamaño?= ,
Juan Manuel Martinez =?utf-8?q?Caamaño?= ,
Juan Manuel Martinez =?utf-8?q?Caamaño?= ,
Juan Manuel Martinez =?utf-8?q?Caamaño?= ,
Juan Manuel Martinez =?utf-8?q?Caamaño?= ,
Juan Manuel Martinez =?utf-8?q?Caamaño?= ,
Juan Manuel Martinez =?utf-8?q?Caamaño?= ,
Juan Manuel Martinez =?utf-8?q?Caamaño?= 
Message-ID:
In-Reply-To: 



@@ -743,9 +743,13 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, 
IntrinsicInst &II) const {
 if (!CArg)
   break;
 
-int CArg4BitAsInt = CArg->getValue().trunc(4).getSExtValue();
-float ResVal = 0.0625 * CArg4BitAsInt;
-Constant *Res = ConstantFP::get(II.getType(), ResVal);
+// Tabulated 0.0625 * (sext (CArg & 0xf)).
+constexpr size_t ResValsSize = 16;
+const float ResVals[ResValsSize] = {

shiltian wrote:

or even `constexpr`?

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Alex Voicu via cfe-commits


@@ -284,6 +284,18 @@ void 
CodeGenFunction::AddAMDGPUFenceAddressSpaceMMRA(llvm::Instruction *Inst,
   Inst->setMetadata(LLVMContext::MD_mmra, MMRAMetadata::getMD(Ctx, MMRAs));
 }
 
+static Value *GetOrInsertAMDGPUPredicate(CodeGenFunction &CGF, Twine Name) {
+  auto PTy = IntegerType::getInt1Ty(CGF.getLLVMContext());
+
+  auto P = cast(

AlexVlx wrote:

Done.

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Alex Voicu via cfe-commits


@@ -15576,6 +15609,38 @@ static bool isOverflowingIntegerType(ASTContext &Ctx, 
QualType T) {
   return Ctx.getIntWidth(T) >= Ctx.getIntWidth(Ctx.IntTy);
 }
 
+static Expr *ExpandAMDGPUPredicateBI(ASTContext &Ctx, CallExpr *CE) {
+  if (!CE->getBuiltinCallee())
+return CXXBoolLiteralExpr::Create(Ctx, false, Ctx.BoolTy, 
CE->getExprLoc());
+
+  if (Ctx.getTargetInfo().getTriple().isSPIRV()) {
+CE->setType(Ctx.getLogicalOperationType());
+return CE;
+  }
+
+  bool P = false;
+  auto &TI = Ctx.getTargetInfo();
+
+  if (CE->getDirectCallee()->getName() == "__builtin_amdgcn_processor_is") {
+auto GFX = dyn_cast(CE->getArg(0)->IgnoreParenCasts());
+auto TID = TI.getTargetID();
+if (GFX && TID) {
+  auto N = GFX->getString();
+  P = TI.isValidCPUName(GFX->getString()) && TID->find(N) == 0;
+}
+  } else {
+auto FD = cast(CE->getArg(0)->getReferencedDeclOfCallee());

AlexVlx wrote:

Done.

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


[clang] [llvm][doc]: Merge the contents of identical entries. (PR #134089)

2025-04-02 Thread via cfe-commits

https://github.com/YLChenZ created 
https://github.com/llvm/llvm-project/pull/134089

Closes #133706.

before the patch:


![docb4](https://github.com/user-attachments/assets/6db1000f-d555-48b8-8a19-85c41b043fd8)
after the patch:


![doc-after](https://github.com/user-attachments/assets/1cff64b6-db2e-48d8-b0a9-a403fd61f8af)


>From 319c55aef5c458ae4ac6c7f3f186d338f6fe2e37 Mon Sep 17 00:00:00 2001
From: YLChenZ 
Date: Wed, 2 Apr 2025 22:03:53 +0800
Subject: [PATCH] [llvm][doc]: Merge the contents of identical entries.

---
 clang/utils/TableGen/ClangAttrEmitter.cpp | 68 +--
 1 file changed, 50 insertions(+), 18 deletions(-)

diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 06f6b073240ba..6a2cdcd4ebc8e 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -5144,6 +5144,14 @@ class SpellingList {
 
 Spellings[(size_t)Kind].push_back(Name);
   }
+
+  void merge(const SpellingList &Other) {
+for (size_t Kind = 0; Kind < NumSpellingKinds; ++Kind) {
+  Spellings[Kind].insert(Spellings[Kind].end(),
+ Other.Spellings[Kind].begin(),
+ Other.Spellings[Kind].end());
+}
+  }
 };
 
 class DocumentationData {
@@ -5301,44 +5309,68 @@ void EmitClangAttrDocs(const RecordKeeper &Records, 
raw_ostream &OS) {
   return L->getValueAsString("Name") < R->getValueAsString("Name");
 }
   };
-  std::map, CategoryLess>
+
+  std::map,
+   CategoryLess>
   SplitDocs;
+
+  // Collect documentation data, grouping by category and heading.
   for (const auto *A : Records.getAllDerivedDefinitions("Attr")) {
 const Record &Attr = *A;
 std::vector Docs =
 Attr.getValueAsListOfDefs("Documentation");
+
 for (const auto *D : Docs) {
   const Record &Doc = *D;
   const Record *Category = Doc.getValueAsDef("Category");
   // If the category is "InternalOnly", then there cannot be any other
   // documentation categories (otherwise, the attribute would be
   // emitted into the docs).
-  const StringRef Cat = Category->getValueAsString("Name");
-  bool InternalOnly = Cat == "InternalOnly";
-  if (InternalOnly && Docs.size() > 1)
+  StringRef Cat = Category->getValueAsString("Name");
+  if (Cat == "InternalOnly" && Docs.size() > 1)
 PrintFatalError(Doc.getLoc(),
 "Attribute is \"InternalOnly\", but has multiple "
 "documentation categories");
 
-  if (!InternalOnly)
-SplitDocs[Category].push_back(DocumentationData(
-Doc, Attr, GetAttributeHeadingAndSpellings(Doc, Attr, Cat)));
+  if (Cat == "InternalOnly")
+continue;
+
+  // Generate Heading and Spellings.
+  auto HeadingAndSpellings =
+  GetAttributeHeadingAndSpellings(Doc, Attr, Cat);
+
+  auto &CategoryDocs = SplitDocs[Category];
+
+  // If the heading already exists, merge the documentation.
+  auto It = CategoryDocs.find(HeadingAndSpellings.first);
+  if (It != CategoryDocs.end()) {
+// Merge spellings
+It->second.SupportedSpellings.merge(HeadingAndSpellings.second);
+// Merge content
+It->second.Documentation = &Doc; // Update reference
+  } else {
+// Otherwise, add a new entry.
+CategoryDocs.emplace(HeadingAndSpellings.first,
+ DocumentationData(Doc, Attr, 
HeadingAndSpellings));
+  }
 }
   }
 
-  // Having split the attributes out based on what documentation goes where,
-  // we can begin to generate sections of documentation.
-  for (auto &I : SplitDocs) {
-WriteCategoryHeader(I.first, OS);
+  // Write out documentation, merging attributes with the same heading.
+  for (auto &CategoryPair : SplitDocs) {
+WriteCategoryHeader(CategoryPair.first, OS);
+
+std::vector MergedDocs;
+for (auto &DocPair : CategoryPair.second)
+  MergedDocs.push_back(std::move(DocPair.second));
 
-sort(I.second,
- [](const DocumentationData &D1, const DocumentationData &D2) {
-   return D1.Heading < D2.Heading;
- });
+std::sort(MergedDocs.begin(), MergedDocs.end(),
+  [](const DocumentationData &D1, const DocumentationData &D2) {
+return D1.Heading < D2.Heading;
+  });
 
-// Walk over each of the attributes in the category and write out their
-// documentation.
-for (const auto &Doc : I.second)
+// Output each documentation entry.
+for (const auto &Doc : MergedDocs)
   WriteDocumentation(Records, Doc, OS);
   }
 }

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/134016

>From 91eeaf02336e539f14dcb0a79ff15dbe8befe6f1 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Wed, 2 Apr 2025 02:47:42 +0100
Subject: [PATCH 1/8] Add the functional identity and feature queries.

---
 clang/docs/LanguageExtensions.rst | 110 ++
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |   5 +
 .../clang/Basic/DiagnosticSemaKinds.td|  10 +
 clang/lib/Basic/Targets/SPIR.cpp  |   4 +
 clang/lib/Basic/Targets/SPIR.h|   4 +
 clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp   |  29 ++
 clang/lib/Sema/SemaExpr.cpp   | 157 
 clang/test/CodeGen/amdgpu-builtin-cpu-is.c|  65 
 .../CodeGen/amdgpu-builtin-is-invocable.c |  64 
 .../amdgpu-feature-builtins-invalid-use.cpp   |  43 +++
 llvm/lib/Target/AMDGPU/AMDGPU.h   |   9 +
 .../AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp   | 207 ++
 llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def |   2 +
 .../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp |   3 +-
 llvm/lib/Target/AMDGPU/CMakeLists.txt |   1 +
 ...pu-expand-feature-predicates-unfoldable.ll |  28 ++
 .../amdgpu-expand-feature-predicates.ll   | 359 ++
 17 files changed, 1099 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/amdgpu-builtin-cpu-is.c
 create mode 100644 clang/test/CodeGen/amdgpu-builtin-is-invocable.c
 create mode 100644 clang/test/CodeGen/amdgpu-feature-builtins-invalid-use.cpp
 create mode 100644 llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp
 create mode 100644 
llvm/test/CodeGen/AMDGPU/amdgpu-expand-feature-predicates-unfoldable.ll
 create mode 100644 llvm/test/CodeGen/AMDGPU/amdgpu-expand-feature-predicates.ll

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3b8a9cac6587a..8a7cb75af13e5 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -4920,6 +4920,116 @@ If no address spaces names are provided, all address 
spaces are fenced.
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local")
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local", "global")
 
+__builtin_amdgcn_processor_is and __builtin_amdgcn_is_invocable
+^^^
+
+``__builtin_amdgcn_processor_is`` and ``__builtin_amdgcn_is_invocable`` provide
+a functional mechanism for programatically querying:
+
+* the identity of the current target processor;
+* the capability of the current target processor to invoke a particular 
builtin.
+
+**Syntax**:
+
+.. code-block:: c
+
+  // When used as the predicate for a control structure
+  bool __builtin_amdgcn_processor_is(const char*);
+  bool __builtin_amdgcn_is_invocable(builtin_name);
+  // Otherwise
+  void __builtin_amdgcn_processor_is(const char*);
+  void __builtin_amdgcn_is_invocable(void);
+
+**Example of use**:
+
+.. code-block:: c++
+
+  if (__builtin_amdgcn_processor_is("gfx1201") ||
+  __builtin_amdgcn_is_invocable(__builtin_amdgcn_s_sleep_var))
+__builtin_amdgcn_s_sleep_var(x);
+
+  if (!__builtin_amdgcn_processor_is("gfx906"))
+__builtin_amdgcn_s_wait_event_export_ready();
+  else if (__builtin_amdgcn_processor_is("gfx1010") ||
+   __builtin_amdgcn_processor_is("gfx1101"))
+__builtin_amdgcn_s_ttracedata_imm(1);
+
+  while (__builtin_amdgcn_processor_is("gfx1101")) *p += x;
+
+  do { *p -= x; } while (__builtin_amdgcn_processor_is("gfx1010"));
+
+  for (; __builtin_amdgcn_processor_is("gfx1201"); ++*p) break;
+
+  if 
(__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_wait_event_export_ready))
+__builtin_amdgcn_s_wait_event_export_ready();
+  else if (__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_ttracedata_imm))
+__builtin_amdgcn_s_ttracedata_imm(1);
+
+  do {
+*p -= x;
+  } while 
(__builtin_amdgcn_is_invocable(__builtin_amdgcn_global_load_tr_b64_i32));
+
+  for (; __builtin_amdgcn_is_invocable(__builtin_amdgcn_permlane64); ++*p) 
break;
+
+**Description**:
+
+When used as the predicate value of the following control structures:
+
+.. code-block:: c++
+
+  if (...)
+  while (...)
+  do { } while (...)
+  for (...)
+
+be it directly, or as arguments to logical operators such as ``!, ||, &&``, the
+builtins return a boolean value that:
+
+* indicates whether the current target matches the argument; the argument MUST
+  be a string literal and a valid AMDGPU target
+* indicates whether the builtin function passed as the argument can be invoked
+  by the current target; the argument MUST be either a generic or AMDGPU
+  specific builtin name
+
+Outside of these contexts, the builtins have a ``void`` returning signature
+which prevents their misuse.
+
+**Example of invalid use**:
+
+.. code-block:: c++
+
+  void kernel(int* p, int x, bool (*pfn)(bool), const char* str) {
+if (__builtin_amdgcn_processor_is("not_an_amdgcn_gfx_id")) return;
+else if (__bui

[libclc] [libclc] Move sinh, cosh & tanh to the CLC library (PR #134063)

2025-04-02 Thread Fraser Cormack via cfe-commits

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


[libclc] d51525b - [libclc] Move lgamma, lgamma_r & tgamma to CLC library (#134053)

2025-04-02 Thread via cfe-commits

Author: Fraser Cormack
Date: 2025-04-02T15:20:32+01:00
New Revision: d51525ba36017507fe95ce48e9670b6f4b267016

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

LOG: [libclc] Move lgamma, lgamma_r & tgamma to CLC library (#134053)

Also enable half-precision variants of tgamma, which were previously
missing.

Note that unlike recent work, these builtins are not vectorized as part
of this commit. Ultimately all three call into lgamma_r, which has heavy
control flow (including switch statements) that would be difficult to
vectorize. Additionally the lgamma_r algorithm is copyrighted to SunPro
so may need a rewrite in the future anyway.

There are no codegen changes (to non-SPIR-V targets) with this commit,
aside from the new half builtins.

Added: 
libclc/clc/include/clc/math/clc_lgamma.h
libclc/clc/include/clc/math/clc_lgamma_r.h
libclc/clc/include/clc/math/clc_tgamma.h
libclc/clc/include/clc/math/unary_def_via_fp32.inc
libclc/clc/lib/generic/math/clc_lgamma.cl
libclc/clc/lib/generic/math/clc_lgamma.inc
libclc/clc/lib/generic/math/clc_lgamma_r.cl
libclc/clc/lib/generic/math/clc_lgamma_r.inc
libclc/clc/lib/generic/math/clc_tgamma.cl

Modified: 
libclc/clc/lib/generic/SOURCES
libclc/generic/include/clc/math/lgamma_r.h
libclc/generic/lib/math/lgamma.cl
libclc/generic/lib/math/lgamma_r.cl
libclc/generic/lib/math/tgamma.cl

Removed: 
libclc/generic/include/clc/math/lgamma_r.inc
libclc/generic/lib/math/lgamma_r.inc



diff  --git a/libclc/generic/include/clc/math/lgamma_r.inc 
b/libclc/clc/include/clc/math/clc_lgamma.h
similarity index 57%
rename from libclc/generic/include/clc/math/lgamma_r.inc
rename to libclc/clc/include/clc/math/clc_lgamma.h
index 0f78c0e686386..7e516c1f08793 100644
--- a/libclc/generic/include/clc/math/lgamma_r.inc
+++ b/libclc/clc/include/clc/math/clc_lgamma.h
@@ -6,6 +6,15 @@
 //
 
//===--===//
 
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE lgamma_r(__CLC_GENTYPE x, global 
__CLC_INTN *iptr);
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE lgamma_r(__CLC_GENTYPE x, local 
__CLC_INTN *iptr);
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE lgamma_r(__CLC_GENTYPE x, private 
__CLC_INTN *iptr);
+#ifndef __CLC_MATH_CLC_LGAMMA_H__
+#define __CLC_MATH_CLC_LGAMMA_H__
+
+#define __CLC_BODY 
+#define __CLC_FUNCTION __clc_lgamma
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_LGAMMA_H__

diff  --git a/libclc/clc/include/clc/math/clc_lgamma_r.h 
b/libclc/clc/include/clc/math/clc_lgamma_r.h
new file mode 100644
index 0..5db55a13b4d82
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_lgamma_r.h
@@ -0,0 +1,20 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef __CLC_MATH_CLC_LGAMMA_R_H__
+#define __CLC_MATH_CLC_LGAMMA_R_H__
+
+#define __CLC_FUNCTION __clc_lgamma_r
+#define __CLC_BODY 
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_LGAMMA_R_H__

diff  --git a/libclc/clc/include/clc/math/clc_tgamma.h 
b/libclc/clc/include/clc/math/clc_tgamma.h
new file mode 100644
index 0..c4e5714616fae
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_tgamma.h
@@ -0,0 +1,20 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef __CLC_MATH_CLC_TGAMMA_H__
+#define __CLC_MATH_CLC_TGAMMA_H__
+
+#define __CLC_BODY 
+#define __CLC_FUNCTION __clc_tgamma
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_TGAMMA_H__

diff  --git a/libclc/generic/lib/math/lgamma_r.inc 
b/libclc/clc/include/clc/math/unary_def_via_fp32.inc
similarity index 62%
rename from libclc/generic/lib/math/lgamma_r.inc
rename to libclc/clc/include/clc/math/unary_def_via_fp32.inc
index 89cb52ea7a78a..aefee6170571d 100644
--- a/libclc/generic/lib/math/lgamma_r.inc
+++ b/libclc/clc/include/clc/math/unary_def_via_fp32.inc
@@ -6,9 +6,6 @@
 //
 
//===--===//
 
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE lgamma_r(__CLC_GENTYPE x, __CLC_ADDRSPACE 
__CLC_INTN *iptr) {
-__CLC_INTN private

[clang] [Clang] Add warning message for C++17 alias template CTAD (PR #133806)

2025-04-02 Thread via cfe-commits

https://github.com/GeorgeKA updated 
https://github.com/llvm/llvm-project/pull/133806

>From dd978982b2ab41d3d2a55abb448e653a80158ecd Mon Sep 17 00:00:00 2001
From: George Asante 
Date: Mon, 31 Mar 2025 17:41:20 -0400
Subject: [PATCH 1/3] Add warning message for C++17 alias template CTAD

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td| 13 ++---
 clang/lib/Sema/SemaInit.cpp |  4 +++-
 clang/test/SemaCXX/cxx17-compat.cpp |  2 +-
 .../cxx1z-class-template-argument-deduction.cpp |  4 ++--
 4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c77cde297dc32..6f71628f19a4a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8444,9 +8444,16 @@ let CategoryName = "Lambda Issue" in {
 "C++ standards before C++20">, InGroup, DefaultIgnore;
 
   // C++20 class template argument deduction for alias templates.
-  def warn_cxx17_compat_ctad_for_alias_templates : Warning<
-  "class template argument deduction for alias templates is incompatible with "
-  "C++ standards before C++20">, InGroup, DefaultIgnore;
+  def warn_cxx17_compat_ctad_for_alias_templates
+  : Warning<"class template argument deduction for alias templates is "
+"incompatible with "
+"C++ standards before C++20">,
+InGroup,
+DefaultIgnore;
+  def ext_ctad_for_alias_templates_cxx20
+  : ExtWarn<"class template argument deduction for alias templates is a "
+"C++20 extension">,
+InGroup;
 }
 
 def err_return_in_captured_stmt : Error<
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index cea121d576c5c..7229cd42f85d0 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -9896,7 +9896,9 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
 if (auto *AliasTemplate = dyn_cast_or_null(
 TemplateName.getAsTemplateDecl())) {
   Diag(Kind.getLocation(),
-   diag::warn_cxx17_compat_ctad_for_alias_templates);
+   getLangOpts().CPlusPlus20
+   ? diag::warn_cxx17_compat_ctad_for_alias_templates
+   : diag::ext_ctad_for_alias_templates_cxx20);
   LookupTemplateDecl = AliasTemplate;
   auto UnderlyingType = AliasTemplate->getTemplatedDecl()
 ->getUnderlyingType()
diff --git a/clang/test/SemaCXX/cxx17-compat.cpp 
b/clang/test/SemaCXX/cxx17-compat.cpp
index 54ea3384022d4..81b3e1fde5493 100644
--- a/clang/test/SemaCXX/cxx17-compat.cpp
+++ b/clang/test/SemaCXX/cxx17-compat.cpp
@@ -137,7 +137,7 @@ template struct A { A(T); };
 template using B = A;
 B b = {1};
 #if __cplusplus <= 201703L
-  // FIXME: diagnose as well
+  // expected-warning@-2 {{class template argument deduction for alias 
templates is a C++20 extension}}
 #else
   // expected-warning@-4 {{class template argument deduction for alias 
templates is incompatible with C++ standards before C++20}}
 #endif
diff --git a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp 
b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
index 9aaa13d7ac41a..a7d740e66ba63 100644
--- a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
+++ b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
@@ -113,9 +113,9 @@ namespace dependent {
   };
   template void f() {
 typename T::X tx = 0;
-typename T::Y ty = 0;
+typename T::Y ty = 0; // expected-warning {{class template argument 
deduction for alias templates is a C++20 extension}}
   }
-  template void f();
+  template void f(); // expected-note {{in instantiation of function 
template specialization 'dependent::f' requested here}}
 
   template struct C { C(T); };
   template C(T) -> C;

>From c48c4a60c1ed8aebff27bf8a7bb108dd3a9ad3ef Mon Sep 17 00:00:00 2001
From: George Asante 
Date: Mon, 31 Mar 2025 18:38:06 -0400
Subject: [PATCH 2/3] Switched to using multiclasses for both messages

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 14 ++
 clang/lib/Sema/SemaInit.cpp  |  4 ++--
 2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6f71628f19a4a..79389eebd81f1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -49,6 +49,8 @@ defm constexpr_ctor_missing_init : CXX20Compat<
 defm adl_only_template_id : CXX20Compat<
   "use of function template name with no prior declaration in function call "
   "with explicit template arguments is">;
+defm ctad_for_alias_templates
+: CXX20Compat<"class template argument deduction for alias templates is">;
 
 // C++23 compatibility with C++20 and earlier.
 defm constexpr_static_var : CXX

[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/134016

>From 91eeaf02336e539f14dcb0a79ff15dbe8befe6f1 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Wed, 2 Apr 2025 02:47:42 +0100
Subject: [PATCH 1/9] Add the functional identity and feature queries.

---
 clang/docs/LanguageExtensions.rst | 110 ++
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |   5 +
 .../clang/Basic/DiagnosticSemaKinds.td|  10 +
 clang/lib/Basic/Targets/SPIR.cpp  |   4 +
 clang/lib/Basic/Targets/SPIR.h|   4 +
 clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp   |  29 ++
 clang/lib/Sema/SemaExpr.cpp   | 157 
 clang/test/CodeGen/amdgpu-builtin-cpu-is.c|  65 
 .../CodeGen/amdgpu-builtin-is-invocable.c |  64 
 .../amdgpu-feature-builtins-invalid-use.cpp   |  43 +++
 llvm/lib/Target/AMDGPU/AMDGPU.h   |   9 +
 .../AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp   | 207 ++
 llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def |   2 +
 .../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp |   3 +-
 llvm/lib/Target/AMDGPU/CMakeLists.txt |   1 +
 ...pu-expand-feature-predicates-unfoldable.ll |  28 ++
 .../amdgpu-expand-feature-predicates.ll   | 359 ++
 17 files changed, 1099 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/amdgpu-builtin-cpu-is.c
 create mode 100644 clang/test/CodeGen/amdgpu-builtin-is-invocable.c
 create mode 100644 clang/test/CodeGen/amdgpu-feature-builtins-invalid-use.cpp
 create mode 100644 llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp
 create mode 100644 
llvm/test/CodeGen/AMDGPU/amdgpu-expand-feature-predicates-unfoldable.ll
 create mode 100644 llvm/test/CodeGen/AMDGPU/amdgpu-expand-feature-predicates.ll

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3b8a9cac6587a..8a7cb75af13e5 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -4920,6 +4920,116 @@ If no address spaces names are provided, all address 
spaces are fenced.
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local")
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local", "global")
 
+__builtin_amdgcn_processor_is and __builtin_amdgcn_is_invocable
+^^^
+
+``__builtin_amdgcn_processor_is`` and ``__builtin_amdgcn_is_invocable`` provide
+a functional mechanism for programatically querying:
+
+* the identity of the current target processor;
+* the capability of the current target processor to invoke a particular 
builtin.
+
+**Syntax**:
+
+.. code-block:: c
+
+  // When used as the predicate for a control structure
+  bool __builtin_amdgcn_processor_is(const char*);
+  bool __builtin_amdgcn_is_invocable(builtin_name);
+  // Otherwise
+  void __builtin_amdgcn_processor_is(const char*);
+  void __builtin_amdgcn_is_invocable(void);
+
+**Example of use**:
+
+.. code-block:: c++
+
+  if (__builtin_amdgcn_processor_is("gfx1201") ||
+  __builtin_amdgcn_is_invocable(__builtin_amdgcn_s_sleep_var))
+__builtin_amdgcn_s_sleep_var(x);
+
+  if (!__builtin_amdgcn_processor_is("gfx906"))
+__builtin_amdgcn_s_wait_event_export_ready();
+  else if (__builtin_amdgcn_processor_is("gfx1010") ||
+   __builtin_amdgcn_processor_is("gfx1101"))
+__builtin_amdgcn_s_ttracedata_imm(1);
+
+  while (__builtin_amdgcn_processor_is("gfx1101")) *p += x;
+
+  do { *p -= x; } while (__builtin_amdgcn_processor_is("gfx1010"));
+
+  for (; __builtin_amdgcn_processor_is("gfx1201"); ++*p) break;
+
+  if 
(__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_wait_event_export_ready))
+__builtin_amdgcn_s_wait_event_export_ready();
+  else if (__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_ttracedata_imm))
+__builtin_amdgcn_s_ttracedata_imm(1);
+
+  do {
+*p -= x;
+  } while 
(__builtin_amdgcn_is_invocable(__builtin_amdgcn_global_load_tr_b64_i32));
+
+  for (; __builtin_amdgcn_is_invocable(__builtin_amdgcn_permlane64); ++*p) 
break;
+
+**Description**:
+
+When used as the predicate value of the following control structures:
+
+.. code-block:: c++
+
+  if (...)
+  while (...)
+  do { } while (...)
+  for (...)
+
+be it directly, or as arguments to logical operators such as ``!, ||, &&``, the
+builtins return a boolean value that:
+
+* indicates whether the current target matches the argument; the argument MUST
+  be a string literal and a valid AMDGPU target
+* indicates whether the builtin function passed as the argument can be invoked
+  by the current target; the argument MUST be either a generic or AMDGPU
+  specific builtin name
+
+Outside of these contexts, the builtins have a ``void`` returning signature
+which prevents their misuse.
+
+**Example of invalid use**:
+
+.. code-block:: c++
+
+  void kernel(int* p, int x, bool (*pfn)(bool), const char* str) {
+if (__builtin_amdgcn_processor_is("not_an_amdgcn_gfx_id")) return;
+else if (__bui

[clang] [clang] Add SPIR-V to some OpenMP clang tests (PR #133503)

2025-04-02 Thread Joseph Huber via cfe-commits

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

Alright, LG.

Unrelated, but it would be nice if someone who knows SPIR-V better could look 
at adding similar builtins for the ones we need to get it working through 
OpenMP. I've landed some merges that should make that work, but it seems that 
most of the SPIR-V support isn't intended to be used for compute. It's not that 
hard if we just do the current 'status quo' and emit intrinsics for the target.

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


[clang] [clang][modules] Determine if the SDK supports builtin modules independent of the target (PR #134005)

2025-04-02 Thread Volodymyr Sapsai via cfe-commits


@@ -62,6 +63,28 @@ DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(
   Min, Max, MinValue, MaximumDeploymentTarget, std::move(Mapping));
 }
 
+static llvm::Triple::OSType parseOS(const llvm::json::Object &Obj) {
+  // The CanonicalName is the Xcode platform, a version, and an optional 
suffix,
+  // e.g. macosx16.0.

vsapsai wrote:

The example doesn't have a suffix, as far as I can tell. Up to you if you want 
to make it more representative.

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


[clang] [clang][modules] Determine if the SDK supports builtin modules independent of the target (PR #134005)

2025-04-02 Thread Volodymyr Sapsai via cfe-commits


@@ -2990,26 +2996,18 @@ static bool sdkSupportsBuiltinModules(
 return false;
 
   VersionTuple SDKVersion = SDKInfo->getVersion();
-  switch (TargetPlatform) {
+  switch (SDKInfo->getOS()) {
   // Existing SDKs added support for builtin modules in the fall
   // 2024 major releases.
-  case Darwin::MacOS:
+  case llvm::Triple::MacOSX:
 return SDKVersion >= VersionTuple(15U);
-  case Darwin::IPhoneOS:
-switch (TargetEnvironment) {
-case Darwin::MacCatalyst:

vsapsai wrote:

How is it handled in the new version? I don't see a special case for 
MacCatalyst in the new code, though I could have missed it.

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


[clang] [SYCL][SPIR-V Backend][clang-sycl-linker] Add SPIR-V backend support inside clang-sycl-linker (PR #133967)

2025-04-02 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-amdgpu-runtime-2` running on `rocm-worker-hw-02` while building 
`clang` at step 7 "Add check check-clang".

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


Here is the relevant piece of the build log for the reference

```
Step 7 (Add check check-clang) failure: test (failure)
 TEST 'Clang :: Driver/clang-sycl-linker-test.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/clang 
--driver-mode=g++ -emit-llvm -c -target spirv64 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp
 -o 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc
 # RUN: at line 4
+ /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/clang 
--driver-mode=g++ -emit-llvm -c -target spirv64 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp
 -o 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/clang 
--driver-mode=g++ -emit-llvm -c -target spirv64 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp
 -o 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
 # RUN: at line 5
+ /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/clang 
--driver-mode=g++ -emit-llvm -c -target spirv64 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp
 -o 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/clang-sycl-linker
 --dry-run -v -triple=spirv64 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc
 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
 -o a.spv 2>&1| 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/FileCheck 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp
 --check-prefix=SIMPLE-FO # RUN: at line 6
+ 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/clang-sycl-linker
 --dry-run -v -triple=spirv64 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc
 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
 -o a.spv
+ 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/FileCheck 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp
 --check-prefix=SIMPLE-FO
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp:9:20:
 error: SIMPLE-FO-NEXT: expected string not found in input
// SIMPLE-FO-NEXT: SPIR-V Backend: input: [[LLVMLINKOUT]].bc, output: a.spv
   ^
:1:349: note: scanning from here
sycl-device-link: inputs: 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc,
 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
 libfiles: output: /tmp/lit-tmp-faew3ndu/a.spv-b34085.bc




^
:1:349: note: with "LLVMLINKOUT" equal to 
"/tmp/lit-tmp-faew3ndu/a\\.spv-b34085"
sycl-device-link: inputs: 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc,
 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
 libfiles: output: /tmp/lit-tmp-faew3ndu/a.spv-b34085.bc


  

[clang] fixed clang frontend crash with friend class declaration and overload == (PR #133878)

2025-04-02 Thread Ankur Ahir via cfe-commits

https://github.com/Ankur-0429 updated 
https://github.com/llvm/llvm-project/pull/133878

>From 289f8630dccf916b8cf7cc43758bae60df036c5d Mon Sep 17 00:00:00 2001
From: Ankur Ahir 
Date: Wed, 2 Apr 2025 00:53:33 -0700
Subject: [PATCH 1/4] clang frontend crash with friend class declaration and
 overloaded operator ==

---
 clang/docs/ReleaseNotes.rst  |  1 +
 clang/lib/Sema/SemaDeclCXX.cpp   |  3 +--
 .../class/class.compare/class.compare.default/p1.cpp | 12 
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index daad01919ecd4..431ae0863d9e4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -342,6 +342,7 @@ Bug Fixes to Attribute Support
 Bug Fixes to C++ Support
 
 
+- Clang Now Supports Implicitly-Defined Comparison Operators for 
Friend-Declarations
 - Clang now diagnoses copy constructors taking the class by value in template 
instantiations. (#GH130866)
 - Clang is now better at keeping track of friend function template instance 
contexts. (#GH55509)
 - Clang now prints the correct instantiation context for diagnostics suppressed
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 676d53a1f4b45..d1516860dfe71 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -9037,8 +9037,7 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, 
FunctionDecl *FD,
   return true;
 
 if (llvm::none_of(RD->friends(), [&](const FriendDecl *F) {
-  return FD->getCanonicalDecl() ==
- F->getFriendDecl()->getCanonicalDecl();
+  return declaresSameEntity(F->getFriendDecl(), FD);
 })) {
   Diag(FD->getLocation(), diag::err_defaulted_comparison_not_friend)
   << int(DCK) << int(0) << RD;
diff --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
index a195e0548152d..5db4f05da552c 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -285,3 +285,15 @@ struct j {
 };
 bool j::operator==(const j &) const = default;
 }
+
+namespace evil2 {
+  struct k {
+  };
+  
+  struct l {
+  friend bool operator==(const l& a, const l& b);
+  friend class k;
+  };
+  
+  bool operator==(const l& a, const l& b) = default;
+}
\ No newline at end of file

>From 78fecd58986e25147b47220ee9ef0a392c45651e Mon Sep 17 00:00:00 2001
From: Ankur Ahir 
Date: Wed, 2 Apr 2025 00:53:33 -0700
Subject: [PATCH 2/4] clang frontend crash with friend class declaration and
 overloaded operator ==

---
 clang/docs/ReleaseNotes.rst  |  1 +
 clang/lib/Sema/SemaDeclCXX.cpp   |  3 +--
 .../class/class.compare/class.compare.default/p1.cpp | 12 
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index daad01919ecd4..88ed3018c58ea 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -342,6 +342,7 @@ Bug Fixes to Attribute Support
 Bug Fixes to C++ Support
 
 
+- Clang Now supports Implicitly-Defined Comparison Operators for 
Friend-Declarations
 - Clang now diagnoses copy constructors taking the class by value in template 
instantiations. (#GH130866)
 - Clang is now better at keeping track of friend function template instance 
contexts. (#GH55509)
 - Clang now prints the correct instantiation context for diagnostics suppressed
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 676d53a1f4b45..d1516860dfe71 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -9037,8 +9037,7 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, 
FunctionDecl *FD,
   return true;
 
 if (llvm::none_of(RD->friends(), [&](const FriendDecl *F) {
-  return FD->getCanonicalDecl() ==
- F->getFriendDecl()->getCanonicalDecl();
+  return declaresSameEntity(F->getFriendDecl(), FD);
 })) {
   Diag(FD->getLocation(), diag::err_defaulted_comparison_not_friend)
   << int(DCK) << int(0) << RD;
diff --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
index a195e0548152d..5db4f05da552c 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -285,3 +285,15 @@ struct j {
 };
 bool j::operator==(const j &) const = default;
 }
+
+namespace evil2 {
+  struct k {
+  };
+  
+  struct l {
+  friend bool operator==(const l& a, const l& b);
+  friend class k;
+  };
+  
+  bool operator==(const l& a, const l& b) = default;
+}
\ No newline at end of f

[clang] [SYCL][SPIR-V Backend][clang-sycl-linker] Add SPIR-V backend support inside clang-sycl-linker (PR #133967)

2025-04-02 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-sles-build-only` running on `rocm-worker-hw-04-sles` while 
building `clang` at step 6 "Add check check-clang".

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


Here is the relevant piece of the build log for the reference

```
Step 6 (Add check check-clang) failure: test (failure)
 TEST 'Clang :: Driver/clang-sycl-linker-test.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang 
--driver-mode=g++ -emit-llvm -c -target spirv64 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp
 -o 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc
 # RUN: at line 4
+ /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang 
--driver-mode=g++ -emit-llvm -c -target spirv64 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp
 -o 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang 
--driver-mode=g++ -emit-llvm -c -target spirv64 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp
 -o 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
 # RUN: at line 5
+ /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang 
--driver-mode=g++ -emit-llvm -c -target spirv64 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp
 -o 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang-sycl-linker
 --dry-run -v -triple=spirv64 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc
 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
 -o a.spv 2>&1| 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/FileCheck 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp
 --check-prefix=SIMPLE-FO # RUN: at line 6
+ 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang-sycl-linker
 --dry-run -v -triple=spirv64 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc
 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
 -o a.spv
+ 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/FileCheck 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp
 --check-prefix=SIMPLE-FO
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/Driver/clang-sycl-linker-test.cpp:9:20:
 error: SIMPLE-FO-NEXT: expected string not found in input
// SIMPLE-FO-NEXT: SPIR-V Backend: input: [[LLVMLINKOUT]].bc, output: a.spv
   ^
:1:347: note: scanning from here
sycl-device-link: inputs: 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc,
 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
 libfiles: output: /tmp/lit-tmp-xkwu2lef/a.spv-5691cc.bc




  ^
:1:347: note: with "LLVMLINKOUT" equal to 
"/tmp/lit-tmp-xkwu2lef/a\\.spv-5691cc"
sycl-device-link: inputs: 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_1.bc,
 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/tools/clang/test/Driver/Output/clang-sycl-linker-test.cpp.tmp_2.bc
 libfiles: output: /tmp/lit-tmp-xkwu2lef/a.spv-5691cc.bc


 

[clang] [SYCL][SPIR-V Backend][clang-sycl-linker] Add SPIR-V backend support inside clang-sycl-linker (PR #133967)

2025-04-02 Thread Arvind Sudarsanam via cfe-commits

asudarsa wrote:

@sarnex, @jhuber6 

Thanks much for your kind feedbacks. This is ready to be merged. Can one of you 
please help?

Sincerely

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-02 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/134016

>From 91eeaf02336e539f14dcb0a79ff15dbe8befe6f1 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Wed, 2 Apr 2025 02:47:42 +0100
Subject: [PATCH 01/10] Add the functional identity and feature queries.

---
 clang/docs/LanguageExtensions.rst | 110 ++
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |   5 +
 .../clang/Basic/DiagnosticSemaKinds.td|  10 +
 clang/lib/Basic/Targets/SPIR.cpp  |   4 +
 clang/lib/Basic/Targets/SPIR.h|   4 +
 clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp   |  29 ++
 clang/lib/Sema/SemaExpr.cpp   | 157 
 clang/test/CodeGen/amdgpu-builtin-cpu-is.c|  65 
 .../CodeGen/amdgpu-builtin-is-invocable.c |  64 
 .../amdgpu-feature-builtins-invalid-use.cpp   |  43 +++
 llvm/lib/Target/AMDGPU/AMDGPU.h   |   9 +
 .../AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp   | 207 ++
 llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def |   2 +
 .../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp |   3 +-
 llvm/lib/Target/AMDGPU/CMakeLists.txt |   1 +
 ...pu-expand-feature-predicates-unfoldable.ll |  28 ++
 .../amdgpu-expand-feature-predicates.ll   | 359 ++
 17 files changed, 1099 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/amdgpu-builtin-cpu-is.c
 create mode 100644 clang/test/CodeGen/amdgpu-builtin-is-invocable.c
 create mode 100644 clang/test/CodeGen/amdgpu-feature-builtins-invalid-use.cpp
 create mode 100644 llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp
 create mode 100644 
llvm/test/CodeGen/AMDGPU/amdgpu-expand-feature-predicates-unfoldable.ll
 create mode 100644 llvm/test/CodeGen/AMDGPU/amdgpu-expand-feature-predicates.ll

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3b8a9cac6587a..8a7cb75af13e5 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -4920,6 +4920,116 @@ If no address spaces names are provided, all address 
spaces are fenced.
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local")
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local", "global")
 
+__builtin_amdgcn_processor_is and __builtin_amdgcn_is_invocable
+^^^
+
+``__builtin_amdgcn_processor_is`` and ``__builtin_amdgcn_is_invocable`` provide
+a functional mechanism for programatically querying:
+
+* the identity of the current target processor;
+* the capability of the current target processor to invoke a particular 
builtin.
+
+**Syntax**:
+
+.. code-block:: c
+
+  // When used as the predicate for a control structure
+  bool __builtin_amdgcn_processor_is(const char*);
+  bool __builtin_amdgcn_is_invocable(builtin_name);
+  // Otherwise
+  void __builtin_amdgcn_processor_is(const char*);
+  void __builtin_amdgcn_is_invocable(void);
+
+**Example of use**:
+
+.. code-block:: c++
+
+  if (__builtin_amdgcn_processor_is("gfx1201") ||
+  __builtin_amdgcn_is_invocable(__builtin_amdgcn_s_sleep_var))
+__builtin_amdgcn_s_sleep_var(x);
+
+  if (!__builtin_amdgcn_processor_is("gfx906"))
+__builtin_amdgcn_s_wait_event_export_ready();
+  else if (__builtin_amdgcn_processor_is("gfx1010") ||
+   __builtin_amdgcn_processor_is("gfx1101"))
+__builtin_amdgcn_s_ttracedata_imm(1);
+
+  while (__builtin_amdgcn_processor_is("gfx1101")) *p += x;
+
+  do { *p -= x; } while (__builtin_amdgcn_processor_is("gfx1010"));
+
+  for (; __builtin_amdgcn_processor_is("gfx1201"); ++*p) break;
+
+  if 
(__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_wait_event_export_ready))
+__builtin_amdgcn_s_wait_event_export_ready();
+  else if (__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_ttracedata_imm))
+__builtin_amdgcn_s_ttracedata_imm(1);
+
+  do {
+*p -= x;
+  } while 
(__builtin_amdgcn_is_invocable(__builtin_amdgcn_global_load_tr_b64_i32));
+
+  for (; __builtin_amdgcn_is_invocable(__builtin_amdgcn_permlane64); ++*p) 
break;
+
+**Description**:
+
+When used as the predicate value of the following control structures:
+
+.. code-block:: c++
+
+  if (...)
+  while (...)
+  do { } while (...)
+  for (...)
+
+be it directly, or as arguments to logical operators such as ``!, ||, &&``, the
+builtins return a boolean value that:
+
+* indicates whether the current target matches the argument; the argument MUST
+  be a string literal and a valid AMDGPU target
+* indicates whether the builtin function passed as the argument can be invoked
+  by the current target; the argument MUST be either a generic or AMDGPU
+  specific builtin name
+
+Outside of these contexts, the builtins have a ``void`` returning signature
+which prevents their misuse.
+
+**Example of invalid use**:
+
+.. code-block:: c++
+
+  void kernel(int* p, int x, bool (*pfn)(bool), const char* str) {
+if (__builtin_amdgcn_processor_is("not_an_amdgcn_gfx_id")) return;
+else if (__b

[clang] Hlsl dst function (PR #133828)

2025-04-02 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify
+
+float4 test_too_many_arg(float4 p0)
+{
+dst(p0, p0, p0);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 3 were provided}}
+}
+
+float4 test_no_second_arg(float4 p0)
+{
+return dst(p0);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 1 was provided}}
+}
+
+float4 test_no_args()
+{
+return dst();
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires 2 arguments, but 0 were provided}}
+}
+
+float4 test_3_components(float3 p0, float3 p1)
+{
+return dst(p0, p1);
+  // expected-error@-1 {{no matching function for call to 'dst'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector<[...], 3>' to 'vector<[...], 4>' for 1st 
argument}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector' to 'vector' for 1st 
argument}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector' to 'vector' for 1st 
argument}}
+}

farzonl wrote:

If this doesn't warn then don't worry we don't need this test case.

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


[clang] [clang][CodeGen] Add range metadata for atomic load of boolean type. #131476 (PR #133546)

2025-04-02 Thread Eli Friedman via cfe-commits
Jan =?utf-8?q?Górski?= ,
Jan =?utf-8?q?Górski?= 
Message-ID:
In-Reply-To: 



@@ -590,6 +590,29 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
 llvm::LoadInst *Load = CGF.Builder.CreateLoad(Ptr);
 Load->setAtomic(Order, Scope);
 Load->setVolatile(E->isVolatile());
+
+if (CGF.CGM.getCodeGenOpts().OptimizationLevel == 0) {
+  CGF.Builder.CreateStore(Load, Dest);
+  return;
+}
+
+QualType Ty = E->getValueType();
+if (!Ty->isBooleanType()) {
+  CGF.Builder.CreateStore(Load, Dest);
+  return;

efriedma-quic wrote:

Using an early return like this is weird; just stick a normal if statement 
around the code that creates the metadata.

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


[clang] [clang][CodeGen] Add range metadata for atomic load of boolean type. #131476 (PR #133546)

2025-04-02 Thread Eli Friedman via cfe-commits
Jan =?utf-8?q?Górski?= ,
Jan =?utf-8?q?Górski?= 
Message-ID:
In-Reply-To: 



@@ -590,6 +590,29 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
 llvm::LoadInst *Load = CGF.Builder.CreateLoad(Ptr);
 Load->setAtomic(Order, Scope);
 Load->setVolatile(E->isVolatile());
+
+if (CGF.CGM.getCodeGenOpts().OptimizationLevel == 0) {
+  CGF.Builder.CreateStore(Load, Dest);
+  return;
+}
+
+QualType Ty = E->getValueType();
+if (!Ty->isBooleanType()) {
+  CGF.Builder.CreateStore(Load, Dest);
+  return;
+}
+
+llvm::MDBuilder MDHelper(CGF.getLLVMContext());
+llvm::APInt BooleanMin = llvm::APInt(CGF.getContext().getTypeSize(Ty), 0);
+llvm::APInt BooleanEnd = llvm::APInt(CGF.getContext().getTypeSize(Ty), 2);
+
+if (llvm::MDNode *RangeInfo =
+MDHelper.createRange(BooleanMin, BooleanEnd)) {

efriedma-quic wrote:

Please refactor the code from CodeGenFunction::EmitLoadOfScalar, instead of 
reinventing the code to compute the range metadata.

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


  1   2   3   4   >