[clang] 6892d54 - [Clang][LLVM] Implement single-single vectors MOP4{A/S} (#127797)

2025-04-01 Thread via cfe-commits

Author: Virginia Cangelosi
Date: 2025-04-01T13:35:09+01:00
New Revision: 6892d5428600113dade7b4ecf6b70bbab3198c90

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

LOG: [Clang][LLVM] Implement single-single vectors MOP4{A/S} (#127797)

Implement all single-single {BF/F/S/U/SU/US}MOP4{A/S} instructions in
clang and llvm following the acle in
https://github.com/ARM-software/acle/pull/381/files

Added: 
clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_mop4_1x1.c
clang/test/Sema/aarch64-sme2p2-instrinsics/acle_sme2p2_imm.cpp
llvm/test/CodeGen/AArch64/sme2-intrinsics-mop4a_1x1.ll

Modified: 
clang/include/clang/Basic/arm_sme.td
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
llvm/lib/Target/AArch64/SMEInstrFormats.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 288a8c04c217f..5012874a08790 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -289,6 +289,87 @@ multiclass ZAFPOuterProd {
 defm SVMOPA : ZAFPOuterProd<"mopa">;
 defm SVMOPS : ZAFPOuterProd<"mops">;
 
+
+// SME2 - FMOP4A, FMOP4S, BFMOP4A, BFMOP4S
+
+multiclass MOP4 
checks> {
+  def _1x1 : Inst<"svmop4" # mode # "[_1x1]" # za # "[_{d}_{d}]", "vidd", t, 
MergeNone, i # "_1x1", [IsInOutZA, IsStreaming], checks>;
+}
+
+let SMETargetGuard = "sme2,sme-mop4" in {
+  defm SVFMOP4A_HtoS  : MOP4<"a", "_za32", "hb", "aarch64_sme_mop4a_wide", 
[ImmCheck<0, ImmCheck0_3>]>;
+  defm SVFMOP4S_HtoS  : MOP4<"s", "_za32", "hb", "aarch64_sme_mop4s_wide", 
[ImmCheck<0, ImmCheck0_3>]>;
+  defm SVFMOP4A_S : MOP4<"a", "_za32", "f", "aarch64_sme_mop4a", 
[ImmCheck<0, ImmCheck0_3>]>;
+  defm SVFMOP4S_S : MOP4<"s", "_za32", "f", "aarch64_sme_mop4s", 
[ImmCheck<0, ImmCheck0_3>]>;
+}
+
+let SMETargetGuard = "sme2,sme-mop4,sme-f64f64" in {
+  defm SVFMOP4A_D : MOP4<"a", "_za64", "d", "aarch64_sme_mop4a", [ImmCheck<0, 
ImmCheck0_7>]>;
+  defm SVFMOP4S_D : MOP4<"s", "_za64", "d", "aarch64_sme_mop4s", [ImmCheck<0, 
ImmCheck0_7>]>;
+}
+
+let SMETargetGuard = "sme2,sme-mop4,sme-f16f16" in {
+  defm SVFMOP4A_H : MOP4<"a", "_za16", "h", "aarch64_sme_mop4a", [ImmCheck<0, 
ImmCheck0_1>]>;
+  defm SVFMOP4S_H : MOP4<"s", "_za16", "h", "aarch64_sme_mop4s", [ImmCheck<0, 
ImmCheck0_1>]>;
+}
+
+let SMETargetGuard = "sme2,sme-mop4,sme-b16b16" in {
+  defm SVBMOP4A_H : MOP4<"a", "_za16", "b", "aarch64_sme_mop4a", [ImmCheck<0, 
ImmCheck0_1>]>;
+  defm SVBMOP4S_H : MOP4<"s", "_za16", "b", "aarch64_sme_mop4s", [ImmCheck<0, 
ImmCheck0_1>]>;
+}
+
+
+// SME2 - SMOP4A, SMOP4S, UMOP4A, UMOP4S
+
+let SMETargetGuard = "sme2,sme-mop4" in {
+  defm SVSMOP4A_H  : MOP4<"a", "_za32", "cs", "aarch64_sme_smop4a_wide", 
[ImmCheck<0, ImmCheck0_3>]>;
+  defm SVSMOP4S_H  : MOP4<"s", "_za32", "cs", "aarch64_sme_smop4s_wide", 
[ImmCheck<0, ImmCheck0_3>]>;
+
+  defm SVUMOP4A_H  : MOP4<"a", "_za32", "UcUs", "aarch64_sme_umop4a_wide", 
[ImmCheck<0, ImmCheck0_3>]>;
+  defm SVUMOP4S_H  : MOP4<"s", "_za32", "UcUs", "aarch64_sme_umop4s_wide", 
[ImmCheck<0, ImmCheck0_3>]>;
+}
+
+let SMETargetGuard = "sme2,sme-mop4,sme-i16i64" in {
+  defm SVSMOP4A_HtoD  : MOP4<"a", "_za64", "s", 
"aarch64_sme_smop4a_za64_wide", [ImmCheck<0, ImmCheck0_7>]>;
+  defm SVSMOP4S_HtoD  : MOP4<"s", "_za64", "s", 
"aarch64_sme_smop4s_za64_wide", [ImmCheck<0, ImmCheck0_7>]>;
+
+  defm SVUMOP4A_HtoD  : MOP4<"a", "_za64", "Us", 
"aarch64_sme_umop4a_za64_wide", [ImmCheck<0, ImmCheck0_7>]>;
+  defm SVUMOP4S_HtoD  : MOP4<"s", "_za64", "Us", 
"aarch64_sme_umop4s_za64_wide", [ImmCheck<0, ImmCheck0_7>]>;
+}
+
+
+// SME2 - SUMOP4A, SUMOP4S, USMOP4A, USMOP4S
+
+multiclass SUMOP4 
checks> {
+  def _1x1 : SInst<"svmop4" # mode # "[_1x1]" # za # "[_{d}_{3}]",
+  "vidu", t, MergeNone, "aarch64_sme_sumop4" # 
mode # i # "_wide_1x1",
+  [IsStreaming, IsInOutZA],
+  checks>;
+}
+
+multiclass USMOP4 
checks> {
+  def _1x1 : SInst<"svmop4" # mode # "[_1x1]" # za # "[_{d}_{3}]",
+  "vidx", t, MergeNone, "aarch64_sme_usmop4" # 
mode # i # "_wide_1x1",
+  [IsStreaming, IsInOutZA],
+  checks>;
+}
+
+let SMETargetGuard = "sme2,sme-mop4" in {
+  defm SVSUMOP4A_S : SUMOP4<"a", "_za32", "c", "", [ImmCheck<0, ImmCheck0_3>]>;
+  defm SVSUMOP4S_S : SUMOP4<"s", "_za32", "c", "", [ImmCheck<0, ImmCheck0_3>]>;
+
+  defm SVUSMOP4A_S : USMOP4<"a", "_za32", "Uc", "", [ImmCheck<0, 

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

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

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

>From a3c7c5b35bd48acb49666cdec410a6a31b14941f 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] aa73124 - Fix complex long double division with -mno-x87. (#133152)

2025-04-01 Thread via cfe-commits

Author: Zahira Ammarguellat
Date: 2025-04-01T11:10:51-04:00
New Revision: aa73124e51d89a22b2ba89380d3a1403e4f1c385

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

LOG: Fix complex long double division with -mno-x87. (#133152)

The combination of `-fcomplex-arithmetic=promoted` and `mno-x87` for
`double` complex division is leading to a crash.
See https://godbolt.org/z/189G957oY
This patch fixes that.

Added: 
clang/test/CodeGen/promoted-complex-div.c

Modified: 
clang/lib/CodeGen/CGExprComplex.cpp
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprComplex.cpp 
b/clang/lib/CodeGen/CGExprComplex.cpp
index a7c8b96da6853..184a355734046 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -303,6 +303,10 @@ class ComplexExprEmitter
 // doubles the exponent of SmallerType.LargestFiniteVal)
 if (llvm::APFloat::semanticsMaxExponent(ElementTypeSemantics) * 2 + 1 <=
 llvm::APFloat::semanticsMaxExponent(HigherElementTypeSemantics)) {
+  if (!Ctx.getTargetInfo().hasLongDoubleType() &&
+  HigherElementType.getCanonicalType().getUnqualifiedType() ==
+  Ctx.LongDoubleTy)
+return QualType();
   FPHasBeenPromoted = true;
   return Ctx.getComplexType(HigherElementType);
 } else {

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 48dab1c1c94a8..1c0ef39878d7f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -15329,8 +15329,10 @@ static void DetectPrecisionLossInComplexDivision(Sema 
&S, SourceLocation OpLoc,
   Ctx.getFloatTypeSemantics(ElementType);
   const llvm::fltSemantics &HigherElementTypeSemantics =
   Ctx.getFloatTypeSemantics(HigherElementType);
-  if (llvm::APFloat::semanticsMaxExponent(ElementTypeSemantics) * 2 + 1 >
-  llvm::APFloat::semanticsMaxExponent(HigherElementTypeSemantics)) {
+  if ((llvm::APFloat::semanticsMaxExponent(ElementTypeSemantics) * 2 + 1 >
+   llvm::APFloat::semanticsMaxExponent(HigherElementTypeSemantics)) ||
+  (HigherElementType == Ctx.LongDoubleTy &&
+   !Ctx.getTargetInfo().hasLongDoubleType())) {
 // Retain the location of the first use of higher precision type.
 if (!S.LocationOfExcessPrecisionNotSatisfied.isValid())
   S.LocationOfExcessPrecisionNotSatisfied = OpLoc;

diff  --git a/clang/test/CodeGen/promoted-complex-div.c 
b/clang/test/CodeGen/promoted-complex-div.c
new file mode 100644
index 0..7ed7b07db83ae
--- /dev/null
+++ b/clang/test/CodeGen/promoted-complex-div.c
@@ -0,0 +1,83 @@
+// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown \
+// RUN: -verify -complex-range=promoted -o - | FileCheck %s
+
+// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown \
+// RUN: -verify=nopromotion -complex-range=promoted -target-feature -x87 \
+// RUN: -o - | FileCheck %s --check-prefix=NOX87
+
+// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-windows \
+// RUN: -verify=nopromotion -complex-range=promoted -o - \
+// RUN: | FileCheck %s --check-prefix=NOX87
+
+// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-windows \
+// RUN: -verify=nopromotion -complex-range=promoted -target-feature -x87 \
+// RUN: -o - | FileCheck %s --check-prefix=NOX87
+
+
+
+// expected-no-diagnostics
+
+// CHECK-LABEL: define dso_local <2 x float> @divd
+_Complex float divd(_Complex float a, _Complex float b) {
+  // CHECK: fpext float {{.*}} to double
+  // CHECK: fpext float {{.*}} to double
+  // CHECK: fdiv double
+  // CHECK: fdiv double
+  // CHECK: fptrunc double {{.*}} to float
+  // CHECK: fptrunc double {{.*}} to float
+
+  // NOX87: fpext float {{.*}} to double
+  // NOX87: fpext float {{.*}} to double
+  // NOX87: fdiv double
+  // NOX87: fdiv double
+  // NOX87: fptrunc double {{.*}} to float
+  // NOX87: fptrunc double {{.*}} to float
+
+  return a / b;
+}
+
+// CHECK-LABEL: define dso_local { double, double } @divf
+_Complex double divf(_Complex double a, _Complex double b) {
+  // CHECK: fpext double {{.*}} to x86_fp80
+  // CHECK: fpext double {{.*}} to x86_fp80
+  // CHECK: fdiv x86_fp80
+  // CHECK: fdiv x86_fp80
+  // CHECK: fptrunc x86_fp80
+  // CHECK: fptrunc x86_fp80
+
+  // NOX87: call double @llvm.fabs.f64(double {{.*}})
+  // NOX87-NEXT: call double @llvm.fabs.f64(double {{.*}})
+  // NOX87-NEXT: fcmp ugt double %{{.*}}, {{.*}}
+  // NOX87-NEXT: br i1 {{.*}}, label
+  // NOX87: abs_rhsr_greater_or_equal_abs_rhsi:
+  // NOX87-NEXT: fdiv double
+  // NOX87-NEXT: fmul double
+  // NOX87-NEXT: fadd double
+  // NOX87-NEXT: fmul double
+  // NOX87-NEXT: fadd double
+  // NOX87-NEXT: fdiv double
+  // NOX87-NEXT: fmul double
+  // NOX87-

[clang] [clang][CGObjC] Remove unused ExternalProtocolPtrTy (NFC) (PR #133870)

2025-04-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mats Jun Larsen (junlarsen)


Changes

This function was previously used to get a type to the protocol that
was used to bitcast the initializer of GenerateProtocol. This bitcast
has later been removed (thanks to opaque pointers), but the member was
left behind.

History:

- 020de3254acc3 used ExternalProtocolPtrTy
- 34ee69b4ce662 removes the bitcast

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGObjCMac.cpp (+1-21) 


``diff
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 639c38e7c4555..026a8dc7d75ca 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -184,25 +184,6 @@ class ObjCCommonTypesHelper {
   /// SelectorPtrTy - LLVM type for selector handles (typeof(SEL))
   llvm::PointerType *SelectorPtrTy;
 
-private:
-  /// ProtocolPtrTy - LLVM type for external protocol handles
-  /// (typeof(Protocol))
-  llvm::Type *ExternalProtocolPtrTy;
-
-public:
-  llvm::Type *getExternalProtocolPtrTy() {
-if (!ExternalProtocolPtrTy) {
-  // FIXME: It would be nice to unify this with the opaque type, so that 
the
-  // IR comes out a bit cleaner.
-  CodeGen::CodeGenTypes &Types = CGM.getTypes();
-  ASTContext &Ctx = CGM.getContext();
-  llvm::Type *T = Types.ConvertType(Ctx.getObjCProtoType());
-  ExternalProtocolPtrTy = llvm::PointerType::getUnqual(T);
-}
-
-return ExternalProtocolPtrTy;
-  }
-
   // SuperCTy - clang type for struct objc_super.
   QualType SuperCTy;
   // SuperPtrCTy - clang type for struct objc_super *.
@@ -5636,8 +5617,7 @@ 
CGObjCNonFragileABIMac::CGObjCNonFragileABIMac(CodeGen::CodeGenModule &cgm)
 /* *** */
 
 ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm)
-: VMContext(cgm.getLLVMContext()), CGM(cgm),
-  ExternalProtocolPtrTy(nullptr) {
+: VMContext(cgm.getLLVMContext()), CGM(cgm) {
   CodeGen::CodeGenTypes &Types = CGM.getTypes();
   ASTContext &Ctx = CGM.getContext();
   unsigned ProgramAS = CGM.getDataLayout().getProgramAddressSpace();

``




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


[clang] e92ff64 - [Clang][LLVM] Implement single-multi vectors MOP4{A/S} (#128854)

2025-04-01 Thread via cfe-commits

Author: Virginia Cangelosi
Date: 2025-04-01T15:05:30+01:00
New Revision: e92ff64bad38835a497f9eb928967bca6a295b28

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

LOG: [Clang][LLVM] Implement single-multi vectors MOP4{A/S} (#128854)

Implement all single-multi {BF/F/S/U/SU/US}MOP4{A/S} instructions in
clang and llvm following the acle in
https://github.com/ARM-software/acle/pull/381/files.

This PR depends on https://github.com/llvm/llvm-project/pull/127797

This patch updates the semantics of template arguments in intrinsic
names for clarity and ease of use. Previously, template argument numbers
indicated which character in the prototype string determined the final
type suffix, which was confusing—especially for intrinsics using
multiple prototype modifiers per operand (e.g., intrinsics operating on
arrays of vectors). The number had to reference the correct character in
the prototype (e.g., the ‘u’ in “2.u”), making the system cumbersome and
error-prone.
With this patch, template argument numbers now refer to the operand
number that determines the final type suffix, providing a more intuitive
and consistent approach.

Added: 
clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_mop4_1x2.c
llvm/test/CodeGen/AArch64/sme2-intrinsics-mop4a_1x2.ll

Modified: 
clang/include/clang/Basic/arm_sme.td
clang/include/clang/Basic/arm_sve.td
clang/test/Sema/aarch64-sme2p2-instrinsics/acle_sme2p2_imm.cpp
clang/utils/TableGen/SveEmitter.cpp
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/SMEInstrFormats.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 5012874a08790..6312223f5d112 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -294,6 +294,7 @@ defm SVMOPS : ZAFPOuterProd<"mops">;
 
 multiclass MOP4 
checks> {
   def _1x1 : Inst<"svmop4" # mode # "[_1x1]" # za # "[_{d}_{d}]", "vidd", t, 
MergeNone, i # "_1x1", [IsInOutZA, IsStreaming], checks>;
+  def _1x2 : Inst<"svmop4" # mode # "[_1x2]" # za # "[_{d}_{d}]", "vid2", t, 
MergeNone, i # "_1x2", [IsInOutZA, IsStreaming], checks>;
 }
 
 let SMETargetGuard = "sme2,sme-mop4" in {
@@ -345,6 +346,10 @@ multiclass SUMOP4 che
   "vidu", t, MergeNone, "aarch64_sme_sumop4" # 
mode # i # "_wide_1x1",
   [IsStreaming, IsInOutZA],
   checks>;
+  def _1x2 : SInst<"svmop4" # mode # "[_1x2]" # za # "[_{d}_{3}]",
+  "vid2.u", t, MergeNone, "aarch64_sme_sumop4" # 
mode # i # "_wide_1x2",
+  [IsStreaming, IsInOutZA],
+  checks>;
 }
 
 multiclass USMOP4 
checks> {
@@ -352,6 +357,10 @@ multiclass USMOP4 che
   "vidx", t, MergeNone, "aarch64_sme_usmop4" # 
mode # i # "_wide_1x1",
   [IsStreaming, IsInOutZA],
   checks>;
+  def _1x2 : SInst<"svmop4" # mode # "[_1x2]" # za # "[_{d}_{3}]",
+  "vid2.x", t, MergeNone, "aarch64_sme_usmop4" # 
mode # i # "_wide_1x2",
+  [IsStreaming, IsInOutZA],
+  checks>;
 }
 
 let SMETargetGuard = "sme2,sme-mop4" in {

diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index b51106fa56759..35263541b67ae 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2420,8 +2420,8 @@ let SVETargetGuard = InvalidMode, SMETargetGuard = "sme2" 
in {
 let SVETargetGuard = InvalidMode, SMETargetGuard = "sme2" in {
   def SVSUNPK_X2 : SInst<"svunpk_{d}[_{1}_x2]", "2h",   "sil",MergeNone, 
"aarch64_sve_sunpk_x2", [IsStreaming], []>;
   def SVUUNPK_X2 : SInst<"svunpk_{d}[_{1}_x2]", "2h",   "UsUiUl", MergeNone, 
"aarch64_sve_uunpk_x2", [IsStreaming], []>;
-  def SVSUNPK_X4 : SInst<"svunpk_{d}[_{3}_x4]", "42.h", "sil",MergeNone, 
"aarch64_sve_sunpk_x4", [IsStreaming], []>;
-  def SVUUNPK_X4 : SInst<"svunpk_{d}[_{3}_x4]", "42.h", "UsUiUl", MergeNone, 
"aarch64_sve_uunpk_x4", [IsStreaming], []>;
+  def SVSUNPK_X4 : SInst<"svunpk_{d}[_{1}_x4]", "42.h", "sil",MergeNone, 
"aarch64_sve_sunpk_x4", [IsStreaming], []>;
+  def SVUUNPK_X4 : SInst<"svunpk_{d}[_{1}_x4]", "42.h", "UsUiUl", MergeNone, 
"aarch64_sve_uunpk_x4", [IsStreaming], []>;
 }
 
 let SVETargetGuard = InvalidMode, SMETargetGuard = "sme2,fp8" in {

diff  --git a/clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_mop4_1x2.c 
b/clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_mop4_1x2.c
new file mode 100644
index 0..3c8bd372aa547
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_mop4_1

[clang] 8f56394 - [clang-repl] Implement LoadDynamicLibrary for clang-repl wasm use cases (#133037)

2025-04-01 Thread via cfe-commits

Author: Anutosh Bhat
Date: 2025-04-01T15:33:45+03:00
New Revision: 8f56394487a4d454be0637667267ad37bd636d0f

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

LOG: [clang-repl] Implement LoadDynamicLibrary for clang-repl wasm use cases 
(#133037)

**Currently we don't make use of the JIT for the wasm use cases so the
approach using the execution engine won't work in these cases.**

Rather if we use dlopen. We should be able to do the following
(demonstrating through a toy project)

1) Make use of LoadDynamicLibrary through the given implementation

```
extern "C" EMSCRIPTEN_KEEPALIVE int load_library(const char *name) {
  auto Err = Interp->LoadDynamicLibrary(name);
  if (Err) {
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "load_library 
error: ");
return -1;
  }
  return 0;
}
```
2) Add a button to call load_library once the library has been added in
our MEMFS (currently we have symengine built as a SIDE MODULE and we are
loading it)

Added: 


Modified: 
clang/lib/Interpreter/IncrementalExecutor.h
clang/lib/Interpreter/Interpreter.cpp
clang/lib/Interpreter/Wasm.cpp
clang/lib/Interpreter/Wasm.h

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalExecutor.h 
b/clang/lib/Interpreter/IncrementalExecutor.h
index dbd61f0b8b1eb..71d71bc3883e2 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ b/clang/lib/Interpreter/IncrementalExecutor.h
@@ -57,7 +57,7 @@ class IncrementalExecutor {
   virtual llvm::Error removeModule(PartialTranslationUnit &PTU);
   virtual llvm::Error runCtors() const;
   virtual llvm::Error cleanUp();
-  llvm::Expected
+  virtual llvm::Expected
   getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
 
   llvm::orc::LLJIT &GetExecutionEngine() { return *Jit; }

diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index fa4c1439c9261..f8c8d0a425659 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -18,6 +18,7 @@
 #include "llvm/Support/VirtualFileSystem.h"
 #ifdef __EMSCRIPTEN__
 #include "Wasm.h"
+#include 
 #endif // __EMSCRIPTEN__
 
 #include "clang/AST/ASTConsumer.h"
@@ -711,6 +712,14 @@ llvm::Error Interpreter::Undo(unsigned N) {
 }
 
 llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
+#ifdef __EMSCRIPTEN__
+  void *handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
+  if (!handle) {
+llvm::errs() << dlerror() << '\n';
+return llvm::make_error("Failed to load dynamic 
library",
+   llvm::inconvertibleErrorCode());
+  }
+#else
   auto EE = getExecutionEngine();
   if (!EE)
 return EE.takeError();
@@ -722,6 +731,7 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char 
*name) {
 EE->getMainJITDylib().addGenerator(std::move(*DLSG));
   else
 return DLSG.takeError();
+#endif
 
   return llvm::Error::success();
 }

diff  --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp
index f7cb7598c77f8..0543a3504c9a2 100644
--- a/clang/lib/Interpreter/Wasm.cpp
+++ b/clang/lib/Interpreter/Wasm.cpp
@@ -144,6 +144,19 @@ llvm::Error WasmIncrementalExecutor::cleanUp() {
   return llvm::Error::success();
 }
 
+llvm::Expected
+WasmIncrementalExecutor::getSymbolAddress(llvm::StringRef Name,
+  SymbolNameKind NameKind) const {
+  void *Sym = dlsym(RTLD_DEFAULT, Name.str().c_str());
+  if (!Sym) {
+return llvm::make_error("dlsym failed for symbol: " +
+   Name.str(),
+   llvm::inconvertibleErrorCode());
+  }
+
+  return llvm::orc::ExecutorAddr::fromPtr(Sym);
+}
+
 WasmIncrementalExecutor::~WasmIncrementalExecutor() = default;
 
 } // namespace clang

diff  --git a/clang/lib/Interpreter/Wasm.h b/clang/lib/Interpreter/Wasm.h
index 4632613326d39..9a752934e3185 100644
--- a/clang/lib/Interpreter/Wasm.h
+++ b/clang/lib/Interpreter/Wasm.h
@@ -29,6 +29,9 @@ class WasmIncrementalExecutor : public IncrementalExecutor {
   llvm::Error removeModule(PartialTranslationUnit &PTU) override;
   llvm::Error runCtors() const override;
   llvm::Error cleanUp() override;
+  llvm::Expected
+  getSymbolAddress(llvm::StringRef Name,
+   SymbolNameKind NameKind) const override;
 
   ~WasmIncrementalExecutor() override;
 };



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


[clang] [clang-repl] Implement LoadDynamicLibrary for clang-repl wasm use cases (PR #133037)

2025-04-01 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> > We really need to figure out how to add in-tree tests.
> 
> Yupp sadly I was only able to test this through cppinterop and xeus-cpp as 
> I've commented above ([#133037 
> (comment)](https://github.com/llvm/llvm-project/pull/133037#discussion_r2015819533))
>  where it works as expected :\
> 
> I shall take out some time in the near future to ideate on this.

I am wondering if we can add such CI for llvm, too... maybe you can discuss 
that at the llvm discord's infrastructure channel...

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


[clang] 7267dbf - [clang][bytecode] Fix comparing the addresses of union members (#133852)

2025-04-01 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-04-01T09:00:46+02:00
New Revision: 7267dbfe1032f5ebd698403848fab4bbfcbe0b19

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

LOG: [clang][bytecode] Fix comparing the addresses of union members (#133852)

Union members get the same address, so we can't just use
`Pointer::getByteOffset()`.

Added: 


Modified: 
clang/lib/AST/ByteCode/Interp.h
clang/lib/AST/ByteCode/Pointer.cpp
clang/lib/AST/ByteCode/Pointer.h
clang/test/AST/ByteCode/unions.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 938077a9f10ae..6fe1d4b1f95ae 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1070,9 +1070,18 @@ inline bool CmpHelperEQ(InterpState &S, CodePtr 
OpPC, CompareFn Fn) {
   }
 
   if (Pointer::hasSameBase(LHS, RHS)) {
+if (LHS.inUnion() && RHS.inUnion()) {
+  // If the pointers point into a union, things are a little more
+  // complicated since the offset we save in interp::Pointer can't be used
+  // to compare the pointers directly.
+  size_t A = LHS.computeOffsetForComparison();
+  size_t B = RHS.computeOffsetForComparison();
+  S.Stk.push(BoolT::from(Fn(Compare(A, B;
+  return true;
+}
+
 unsigned VL = LHS.getByteOffset();
 unsigned VR = RHS.getByteOffset();
-
 // In our Pointer class, a pointer to an array and a pointer to the first
 // element in the same array are NOT equal. They have the same Base value,
 // but a 
diff erent Offset. This is a pretty rare case, so we fix this here

diff  --git a/clang/lib/AST/ByteCode/Pointer.cpp 
b/clang/lib/AST/ByteCode/Pointer.cpp
index 79b47c26992ae..5b522610a22f1 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -339,6 +339,39 @@ void Pointer::print(llvm::raw_ostream &OS) const {
   }
 }
 
+/// Compute an integer that can be used to compare this pointer to
+/// another one.
+size_t Pointer::computeOffsetForComparison() const {
+  if (!isBlockPointer())
+return Offset;
+
+  size_t Result = 0;
+  Pointer P = *this;
+  while (!P.isRoot()) {
+if (P.isArrayRoot()) {
+  P = P.getBase();
+  continue;
+}
+if (P.isArrayElement()) {
+  P = P.expand();
+  Result += (P.getIndex() * P.elemSize());
+  P = P.getArray();
+  continue;
+}
+
+if (const Record *R = P.getBase().getRecord(); R && R->isUnion()) {
+  // Direct child of a union - all have offset 0.
+  P = P.getBase();
+  continue;
+}
+
+Result += P.getInlineDesc()->Offset;
+P = P.getBase();
+  }
+
+  return Result;
+}
+
 std::string Pointer::toDiagnosticString(const ASTContext &Ctx) const {
   if (isZero())
 return "nullptr";

diff  --git a/clang/lib/AST/ByteCode/Pointer.h 
b/clang/lib/AST/ByteCode/Pointer.h
index fd33ee9955f55..988237d39fff4 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -417,7 +417,7 @@ class Pointer {
 return false;
   }
   bool inUnion() const {
-if (isBlockPointer())
+if (isBlockPointer() && asBlockPointer().Base >= sizeof(InlineDescriptor))
   return getInlineDesc()->InUnion;
 return false;
   };
@@ -727,6 +727,8 @@ class Pointer {
   /// Prints the pointer.
   void print(llvm::raw_ostream &OS) const;
 
+  size_t computeOffsetForComparison() const;
+
 private:
   friend class Block;
   friend class DeadBlock;

diff  --git a/clang/test/AST/ByteCode/unions.cpp 
b/clang/test/AST/ByteCode/unions.cpp
index 66b8389606b85..3911a2b2f7dde 100644
--- a/clang/test/AST/ByteCode/unions.cpp
+++ b/clang/test/AST/ByteCode/unions.cpp
@@ -600,3 +600,41 @@ namespace MoveOrAssignOp {
   static_assert(foo());
 }
 #endif
+
+namespace AddressComparison {
+  union {
+int a;
+int c;
+  } U;
+  static_assert(__builtin_addressof(U.a) == (void*)__builtin_addressof(U.c));
+  static_assert(&U.a == &U.c);
+
+
+  struct {
+union {
+  struct {
+int a;
+int b;
+  } a;
+  struct {
+int b;
+int a;
+  }b;
+} u;
+int b;
+  } S;
+
+  static_assert(&S.u.a.a == &S.u.b.b);
+  static_assert(&S.u.a.b != &S.u.b.b);
+  static_assert(&S.u.a.b == &S.u.b.b); // both-error {{failed}}
+
+
+  union {
+int a[2];
+int b[2];
+  } U2;
+
+  static_assert(&U2.a[0] == &U2.b[0]);
+  static_assert(&U2.a[0] != &U2.b[1]);
+  static_assert(&U2.a[0] == &U2.b[1]); // both-error {{failed}}
+}



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


[libclc] 13a313f - [libclc] Move sinpi/cospi/tanpi to the CLC library (#133889)

2025-04-01 Thread via cfe-commits

Author: Fraser Cormack
Date: 2025-04-01T12:03:21+01:00
New Revision: 13a313fe582a3c41fb5c50ca2325c0987c0af6d7

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

LOG: [libclc] Move sinpi/cospi/tanpi to the CLC library (#133889)

Additionally, these builtins are now vectorized.

This also moves the native_recip and native_divide builtins as they are
used by the tanpi builtin.

Added: 
libclc/clc/include/clc/math/clc_cospi.h
libclc/clc/include/clc/math/clc_native_divide.h
libclc/clc/include/clc/math/clc_native_recip.h
libclc/clc/include/clc/math/clc_sincos_piby4.h
libclc/clc/include/clc/math/clc_sincos_piby4.inc
libclc/clc/include/clc/math/clc_sinpi.h
libclc/clc/include/clc/math/clc_tanpi.h
libclc/clc/lib/generic/math/clc_cospi.cl
libclc/clc/lib/generic/math/clc_cospi.inc
libclc/clc/lib/generic/math/clc_native_divide.cl
libclc/clc/lib/generic/math/clc_native_divide.inc
libclc/clc/lib/generic/math/clc_native_recip.cl
libclc/clc/lib/generic/math/clc_native_recip.inc
libclc/clc/lib/generic/math/clc_sinpi.cl
libclc/clc/lib/generic/math/clc_sinpi.inc
libclc/clc/lib/generic/math/clc_tanpi.cl
libclc/clc/lib/generic/math/clc_tanpi.inc

Modified: 
libclc/CMakeLists.txt
libclc/clc/include/clc/math/clc_sincos_helpers.inc
libclc/clc/lib/generic/SOURCES
libclc/clc/lib/generic/math/clc_sincos_helpers.cl
libclc/clc/lib/generic/math/clc_sincos_helpers.inc
libclc/clspv/lib/SOURCES
libclc/generic/lib/SOURCES
libclc/generic/lib/math/clc_tan.cl
libclc/generic/lib/math/cospi.cl
libclc/generic/lib/math/native_divide.cl
libclc/generic/lib/math/native_recip.cl
libclc/generic/lib/math/sincos_helpers.cl
libclc/generic/lib/math/sincos_helpers.h
libclc/generic/lib/math/sinpi.cl
libclc/generic/lib/math/tanpi.cl
libclc/spirv/lib/SOURCES

Removed: 
libclc/generic/lib/math/clc_tanpi.cl
libclc/generic/lib/math/native_divide.inc
libclc/generic/lib/math/native_recip.inc
libclc/generic/lib/math/sincosD_piby4.h
libclc/generic/lib/math/sincospiF_piby4.h



diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index efe7f5804e8fb..d4753b22ed01c 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -265,11 +265,13 @@ endif()
 set_source_files_properties(
   # CLC builtins
   ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_cos.cl
+  ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_divide.cl
   ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp2.cl
   ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp.cl
   ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log10.cl
   ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log2.cl
   ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log.cl
+  ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_recip.cl
   ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_rsqrt.cl
   ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_sin.cl
   ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_sqrt.cl

diff  --git a/libclc/clc/include/clc/math/clc_cospi.h 
b/libclc/clc/include/clc/math/clc_cospi.h
new file mode 100644
index 0..07565c23a2f07
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_cospi.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_COSPI_H__
+#define __CLC_MATH_CLC_COSPI_H__
+
+#define __CLC_BODY 
+#define __CLC_FUNCTION __clc_cospi
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_COSPI_H__

diff  --git a/libclc/clc/include/clc/math/clc_native_divide.h 
b/libclc/clc/include/clc/math/clc_native_divide.h
new file mode 100644
index 0..b48c3e5d03b36
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_native_divide.h
@@ -0,0 +1,22 @@
+//===--===//
+//
+// 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_NATIVE_DIVIDE_H__
+#define __CLC_MATH_CLC_NATIVE_DIVIDE_H__
+
+#define __FLOAT_ONLY
+#define __CLC_FUNCTION __clc_native_divide
+#define __CLC_BODY 
+
+#include 
+
+#und

[clang] [clang][CGObjC] Prefer PointerType::get with LLVMContext over Type (NFC) (PR #133871)

2025-04-01 Thread Mats Jun Larsen via cfe-commits

https://github.com/junlarsen created 
https://github.com/llvm/llvm-project/pull/133871

Part of #123569

>From 0176250dfba2962f24e0e4d484b4ac0ce833bed5 Mon Sep 17 00:00:00 2001
From: Mats Jun Larsen 
Date: Mon, 31 Mar 2025 23:50:17 +0200
Subject: [PATCH] [clang][CGObjC] Prefer PointerType::get with LLVMContext over
 Type (NFC)

Part of #123569
---
 clang/lib/CodeGen/CGObjCMac.cpp | 55 -
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 639c38e7c4555..98f988dfecf84 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -2011,7 +2011,7 @@ CodeGen::RValue CGObjCMac::GenerateMessageSendSuper(
   CGF.Builder.CreateStructGEP(ObjCSuper, 0));
 
   // If this is a class message the metaclass is passed as the target.
-  llvm::Type *ClassTyPtr = llvm::PointerType::getUnqual(ObjCTypes.ClassTy);
+  llvm::Type *ClassTyPtr = llvm::PointerType::getUnqual(VMContext);
   llvm::Value *Target;
   if (IsClassMessage) {
 if (isCategoryImpl) {
@@ -5657,7 +5657,7 @@ 
ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm)
 IvarOffsetVarTy = LongTy;
 
   ObjectPtrTy = 
cast(Types.ConvertType(Ctx.getObjCIdType()));
-  PtrObjectPtrTy = llvm::PointerType::getUnqual(ObjectPtrTy);
+  PtrObjectPtrTy = llvm::PointerType::getUnqual(VMContext);
   SelectorPtrTy =
   cast(Types.ConvertType(Ctx.getObjCSelType()));
 
@@ -5688,7 +5688,7 @@ 
ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm)
   SuperPtrCTy = Ctx.getPointerType(SuperCTy);
 
   SuperTy = cast(Types.ConvertType(SuperCTy));
-  SuperPtrTy = llvm::PointerType::getUnqual(SuperTy);
+  SuperPtrTy = llvm::PointerType::getUnqual(VMContext);
 
   // struct _prop_t {
   //   char *name;
@@ -5704,7 +5704,7 @@ 
ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm)
   PropertyListTy = llvm::StructType::create(
   "struct._prop_list_t", IntTy, IntTy, llvm::ArrayType::get(PropertyTy, 
0));
   // struct _prop_list_t *
-  PropertyListPtrTy = llvm::PointerType::getUnqual(PropertyListTy);
+  PropertyListPtrTy = llvm::PointerType::getUnqual(VMContext);
 
   // struct _objc_method {
   //   SEL _cmd;
@@ -5716,7 +5716,7 @@ 
ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm)
 
   // struct _objc_cache *
   CacheTy = llvm::StructType::create(VMContext, "struct._objc_cache");
-  CachePtrTy = llvm::PointerType::getUnqual(CacheTy);
+  CachePtrTy = llvm::PointerType::getUnqual(VMContext);
 }
 
 ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
@@ -5737,8 +5737,7 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule 
&cgm)
llvm::ArrayType::get(MethodDescriptionTy, 0));
 
   // struct _objc_method_description_list *
-  MethodDescriptionListPtrTy =
-  llvm::PointerType::getUnqual(MethodDescriptionListTy);
+  MethodDescriptionListPtrTy = llvm::PointerType::getUnqual(VMContext);
 
   // Protocol description structures
 
@@ -5756,7 +5755,7 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule 
&cgm)
   PropertyListPtrTy);
 
   // struct _objc_protocol_extension *
-  ProtocolExtensionPtrTy = llvm::PointerType::getUnqual(ProtocolExtensionTy);
+  ProtocolExtensionPtrTy = llvm::PointerType::getUnqual(VMContext);
 
   // Handle construction of Protocol and ProtocolList types
 
@@ -5779,9 +5778,9 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule 
&cgm)
"struct._objc_protocol_list");
 
   // struct _objc_protocol_list *
-  ProtocolListPtrTy = llvm::PointerType::getUnqual(ProtocolListTy);
+  ProtocolListPtrTy = llvm::PointerType::getUnqual(VMContext);
 
-  ProtocolPtrTy = llvm::PointerType::getUnqual(ProtocolTy);
+  ProtocolPtrTy = llvm::PointerType::getUnqual(VMContext);
 
   // Class description structures
 
@@ -5795,17 +5794,17 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule 
&cgm)
 
   // struct _objc_ivar_list *
   IvarListTy = llvm::StructType::create(VMContext, "struct._objc_ivar_list");
-  IvarListPtrTy = llvm::PointerType::getUnqual(IvarListTy);
+  IvarListPtrTy = llvm::PointerType::getUnqual(VMContext);
 
   // struct _objc_method_list *
   MethodListTy =
   llvm::StructType::create(VMContext, "struct._objc_method_list");
-  MethodListPtrTy = llvm::PointerType::getUnqual(MethodListTy);
+  MethodListPtrTy = llvm::PointerType::getUnqual(VMContext);
 
   // struct _objc_class_extension *
   ClassExtensionTy = llvm::StructType::create(
   "struct._objc_class_extension", IntTy, Int8PtrTy, PropertyListPtrTy);
-  ClassExtensionPtrTy = llvm::PointerType::getUnqual(ClassExtensionTy);
+  ClassExtensionPtrTy = llvm::PointerType::getUnqual(VMContext);
 
   // struct _objc_class {
   //   Class isa;
@@ -5828,7 +5827,7 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule 
&cgm)
Int8PtrTy, ClassExtensionPtrTy},
   "stru

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

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

llvm-ci wrote:

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

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


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)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 89848 tests, 88 workers --
Testing:  0.. 10
FAIL: Clang :: Interpreter/inline-virtual.cpp (12898 of 89848)
 TEST 'Clang :: Interpreter/inline-virtual.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
cat 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
 | 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang-repl 
-Xcc -fno-rtti -Xcc -fno-sized-deallocation  | 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
 # RUN: at line 6
+ 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang-repl 
-Xcc -fno-rtti -Xcc -fno-sized-deallocation
+ cat 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
JIT session error: In graph incr_module_18-jitted-objectbuffer, section 
.text._ZN1AC2Ei: relocation target "_ZTV1A" at address 0x756d0810e000 is out of 
range of Delta32 fixup at 0x796d08a2f082 (_ZN1AC2Ei, 0x796d08a2f070 + 0x12)
JIT session error: Failed to materialize symbols: { (main, { 
DW.ref.__gxx_personality_v0 }) }
error: Failed to materialize symbols: { (main, { DW.ref.__gxx_personality_v0, 
a1, _ZN1AC2Ei, $.incr_module_18.__inits.0, __orc_init_func.incr_module_18 }) }
JIT session error: Failed to materialize symbols: { (main, { a1 }) }
error: Failed to materialize symbols: { (main, { 
__orc_init_func.incr_module_19, $.incr_module_19.__inits.0 }) }
error: Failed to materialize symbols: { (main, { __orc_init_func.incr_module_18 
}) }
JIT session error: Failed to materialize symbols: { (main, { _ZN1AD2Ev }) }
error: Failed to materialize symbols: { (main, { $.incr_module_23.__inits.0, 
a2, __orc_init_func.incr_module_23 }) }
error: Failed to materialize symbols: { (main, { __orc_init_func.incr_module_23 
}) }
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp:22:11:
 error: CHECK: expected string not found in input
// CHECK: ~A(1)
  ^
:1:1: note: scanning from here
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl... clang-repl> clang-repl... clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> 
^

Input file: 
Check file: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp

[libclc] bcf0f8d - [libclc] Move exp10 to the CLC library (#133899)

2025-04-01 Thread via cfe-commits

Author: Fraser Cormack
Date: 2025-04-01T14:39:17+01:00
New Revision: bcf0f8d8aa27910545762e2cc7733a11a00954d0

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

LOG: [libclc] Move exp10 to the CLC library (#133899)

The builtin was already nominally in the CLC library; this commit just
moves it over. It also vectorizes the builtin on its way.

Added: 
libclc/clc/include/clc/math/clc_exp10.h
libclc/clc/lib/generic/math/clc_exp10.cl
libclc/clc/lib/generic/math/clc_exp10.inc

Modified: 
libclc/clc/include/clc/math/tables.h
libclc/clc/lib/generic/SOURCES
libclc/clc/lib/generic/math/clc_tables.cl
libclc/clspv/lib/SOURCES
libclc/generic/lib/SOURCES
libclc/generic/lib/math/exp10.cl
libclc/generic/lib/math/tables.cl
libclc/spirv/lib/SOURCES

Removed: 
libclc/generic/lib/math/clc_exp10.cl



diff  --git a/libclc/clc/include/clc/math/clc_exp10.h 
b/libclc/clc/include/clc/math/clc_exp10.h
new file mode 100644
index 0..4f98bf7de6a74
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_exp10.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_EXP10_H__
+#define __CLC_MATH_CLC_EXP10_H__
+
+#define __CLC_BODY 
+#define __CLC_FUNCTION __clc_exp10
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_EXP10_H__

diff  --git a/libclc/clc/include/clc/math/tables.h 
b/libclc/clc/include/clc/math/tables.h
index 3120a18cc996e..44679df8d2cdc 100644
--- a/libclc/clc/include/clc/math/tables.h
+++ b/libclc/clc/include/clc/math/tables.h
@@ -64,13 +64,13 @@ TABLE_FUNCTION_DECL(float2, log10_tbl);
 TABLE_FUNCTION_DECL(uint4, pibits_tbl);
 TABLE_FUNCTION_DECL(float2, sinhcosh_tbl);
 TABLE_FUNCTION_DECL(float2, cbrt_tbl);
-TABLE_FUNCTION_DECL(float, exp_tbl);
 
 CLC_TABLE_FUNCTION_DECL(float, log_inv_tbl_ep_head);
 CLC_TABLE_FUNCTION_DECL(float, log_inv_tbl_ep_tail);
 CLC_TABLE_FUNCTION_DECL(float, loge_tbl_lo);
 CLC_TABLE_FUNCTION_DECL(float, loge_tbl_hi);
 CLC_TABLE_FUNCTION_DECL(float, log_inv_tbl);
+CLC_TABLE_FUNCTION_DECL(float, exp_tbl);
 CLC_TABLE_FUNCTION_DECL(float, exp_tbl_ep_head);
 CLC_TABLE_FUNCTION_DECL(float, exp_tbl_ep_tail);
 

diff  --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES
index 474b11d745a44..becfa3ff6dbed 100644
--- a/libclc/clc/lib/generic/SOURCES
+++ b/libclc/clc/lib/generic/SOURCES
@@ -32,6 +32,7 @@ math/clc_ceil.cl
 math/clc_copysign.cl
 math/clc_cospi.cl
 math/clc_ep_log.cl
+math/clc_exp10.cl
 math/clc_fabs.cl
 math/clc_fma.cl
 math/clc_fmod.cl

diff  --git a/libclc/clc/lib/generic/math/clc_exp10.cl 
b/libclc/clc/lib/generic/math/clc_exp10.cl
new file mode 100644
index 0..04e912ed98885
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_exp10.cl
@@ -0,0 +1,21 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define __CLC_BODY 
+#include 

diff  --git a/libclc/clc/lib/generic/math/clc_exp10.inc 
b/libclc/clc/lib/generic/math/clc_exp10.inc
new file mode 100644
index 0..96bc5331fef17
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_exp10.inc
@@ -0,0 +1,155 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+//
+//  Algorithm:
+//
+//  e^x = 2^(x/ln(2)) = 2^(x*(64/ln(2))/64)
+//
+//  x*(64/ln(2)) = n + f, |f| <= 0.5, n is integer
+//  n = 64*m + j,   0 <= j < 64
+//
+//  e^x = 2^((64*m + j + f)/64)
+//  = (2^m) * (2^(j/64)) * 2^(f/64)
+//  = (2^m) * (2^(j/64)) * e^(f*(ln(2)/64))
+//
+//  f = x*(64/ln(2)) - n
+//  r = f*(ln(2)/64) = x - n*(ln(2)/64)
+//
+//  e^x = (2^m) * (2^(j/64)) * e^r
+//
+//  (2^(j/64)) is precomputed
+//
+//  e^r = 1 + r + (r^2)/2! + (r^3)/3! + (r^4)/4! + (r^5)/5!
+//  e^r = 1 + q
+//
+//  q = r + (r^2)/

[clang] 16603d8 - [HLSL] Add SPIR-V target type for RWStructuredBuffers (#133468)

2025-04-01 Thread via cfe-commits

Author: Steven Perron
Date: 2025-04-01T16:59:46-04:00
New Revision: 16603d838c0dfa6881f9b8118c5a0b5ac2789752

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

LOG: [HLSL] Add SPIR-V target type for RWStructuredBuffers (#133468)

This PR adds the target type for main storage for HLSL raw buffer types.
It does not handle the counter variables that are associated with those
buffers.

This is implementing part of
https://github.com/llvm/wg-hlsl/blob/main/proposals/0018-spirv-resource-representation.md.
We do not handle other HLSL raw buffer types.

Added: 


Modified: 
clang/lib/CodeGen/Targets/SPIR.cpp
clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl

Removed: 




diff  --git a/clang/lib/CodeGen/Targets/SPIR.cpp 
b/clang/lib/CodeGen/Targets/SPIR.cpp
index 43f511e572d37..225d9dfbd980b 100644
--- a/clang/lib/CodeGen/Targets/SPIR.cpp
+++ b/clang/lib/CodeGen/Targets/SPIR.cpp
@@ -386,14 +386,21 @@ llvm::Type *CommonSPIRTargetCodeGenInfo::getHLSLType(
 if (ContainedTy.isNull())
   return nullptr;
 
-assert(!ResAttrs.RawBuffer &&
-   "Raw buffers handles are not implemented for SPIR-V yet");
 assert(!ResAttrs.IsROV &&
"Rasterizer order views not implemented for SPIR-V yet");
 
-// convert element type
 llvm::Type *ElemType = CGM.getTypes().ConvertType(ContainedTy);
-return getSPIRVImageTypeFromHLSLResource(ResAttrs, ElemType, Ctx);
+if (!ResAttrs.RawBuffer) {
+  // convert element type
+  return getSPIRVImageTypeFromHLSLResource(ResAttrs, ElemType, Ctx);
+}
+
+llvm::ArrayType *RuntimeArrayType = llvm::ArrayType::get(ElemType, 0);
+uint32_t StorageClass = /* StorageBuffer storage class */ 12;
+bool IsWritable = ResAttrs.ResourceClass == llvm::dxil::ResourceClass::UAV;
+return llvm::TargetExtType::get(Ctx, "spirv.VulkanBuffer",
+{RuntimeArrayType},
+{StorageClass, IsWritable});
   }
   case llvm::dxil::ResourceClass::CBuffer:
 llvm_unreachable("CBuffer handles are not implemented for SPIR-V yet");

diff  --git 
a/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl 
b/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl
index 04534c5550252..8a1429fd1a6fc 100644
--- a/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl
@@ -1,59 +1,70 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
-// RUN-DISABLED: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
+// RUN: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -DSPIRV 
-disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
 
-// NOTE: SPIRV codegen for resource types is not yet implemented
 
 StructuredBuffer Buf : register(t10);
 RWStructuredBuffer Buf2 : register(u5, space1);
+
+#ifndef SPIRV
+// NOTE: SPIRV codegen for these resource types is not implemented yet.
 AppendStructuredBuffer Buf3 : register(u3);
 ConsumeStructuredBuffer Buf4 : register(u4);
 RasterizerOrderedStructuredBuffer Buf5 : register(u1, space2);
+#endif
+
+// CHECK-DXIL: %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", 
float, 0, 0) }
+// CHECK-DXIL: %"class.hlsl::RWStructuredBuffer" = type { 
target("dx.RawBuffer", float, 1, 0) }
+// CHECK-DXIL: %"class.hlsl::AppendStructuredBuffer" = type { 
target("dx.RawBuffer", float, 1, 0) }
+// CHECK-DXIL: %"class.hlsl::ConsumeStructuredBuffer" = type { 
target("dx.RawBuffer", float, 1, 0) }
+// CHECK-DXIL: %"class.hlsl::RasterizerOrderedStructuredBuffer" = type { 
target("dx.RawBuffer", float, 1, 1) }
+
+// CHECK-SPIRV: %"class.hlsl::StructuredBuffer" = type { 
target("spirv.VulkanBuffer", [0 x float], 12, 0) }
+// CHECK-SPIRV: %"class.hlsl::RWStructuredBuffer" = type { 
target("spirv.VulkanBuffer", [0 x float], 12, 1) }
 
-// CHECK: %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", 
float, 0, 0) }
-// CHECK: %"class.hlsl::RWStructuredBuffer" = type { target("dx.RawBuffer", 
float, 1, 0) }
-// CHECK: %"class.hlsl::AppendStructuredBuffer" = type { 
target("dx.RawBuffer", float, 1, 0) }
-// CHECK: %"class.hlsl::ConsumeStructuredBuffer" = type { 
target("dx.RawBuffer", float, 1, 0) }
-// CHECK: %"class.hlsl::RasterizerOrderedStructuredBuffer" = type { 
target("dx.RawBuffer", float, 1, 1) }
 
-// CHECK: @_ZL3Buf = internal global %"class.hlsl::StructuredBuffer" poison, 
align 4
-// CHECK: @_ZL4Buf2 = internal global %"class.hlsl::RWStructuredBuffer" 
poison, align 4
-// CHECK: @_ZL4B

[clang] 5ffd9bd - [cmake] Refactor clang unittest cmake (#133545)

2025-04-01 Thread via cfe-commits

Author: Reid Kleckner
Date: 2025-04-01T14:12:44-07:00
New Revision: 5ffd9bdb50b5753bbf668e4eab3647dfb46cd0d6

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

LOG: [cmake] Refactor clang unittest cmake (#133545)

Pass all the dependencies into add_clang_unittest. This is consistent
with how it is done for LLDB. I borrowed the same named argument list
structure from add_lldb_unittest. This is a necessary step towards
consolidating unit tests into fewer binaries, but seems like a good
refactoring in its own right.

Added: 


Modified: 
clang/unittests/AST/ByteCode/CMakeLists.txt
clang/unittests/AST/CMakeLists.txt
clang/unittests/ASTMatchers/CMakeLists.txt
clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt
clang/unittests/Analysis/CMakeLists.txt
clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
clang/unittests/Basic/CMakeLists.txt
clang/unittests/CMakeLists.txt
clang/unittests/CodeGen/CMakeLists.txt
clang/unittests/CrossTU/CMakeLists.txt
clang/unittests/DirectoryWatcher/CMakeLists.txt
clang/unittests/Driver/CMakeLists.txt
clang/unittests/Format/CMakeLists.txt
clang/unittests/Frontend/CMakeLists.txt
clang/unittests/Index/CMakeLists.txt
clang/unittests/InstallAPI/CMakeLists.txt
clang/unittests/Interpreter/CMakeLists.txt
clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
clang/unittests/Lex/CMakeLists.txt
clang/unittests/Rewrite/CMakeLists.txt
clang/unittests/Sema/CMakeLists.txt
clang/unittests/Serialization/CMakeLists.txt
clang/unittests/StaticAnalyzer/CMakeLists.txt
clang/unittests/Support/CMakeLists.txt
clang/unittests/Tooling/CMakeLists.txt
clang/unittests/Tooling/Syntax/CMakeLists.txt
clang/unittests/libclang/CMakeLists.txt
clang/unittests/libclang/CrashTests/CMakeLists.txt

Removed: 




diff  --git a/clang/unittests/AST/ByteCode/CMakeLists.txt 
b/clang/unittests/AST/ByteCode/CMakeLists.txt
index b862fb4834fbd..7ccadda2eeb26 100644
--- a/clang/unittests/AST/ByteCode/CMakeLists.txt
+++ b/clang/unittests/AST/ByteCode/CMakeLists.txt
@@ -2,19 +2,13 @@ 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
-)
+  )

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/unittests/ASTMatchers/Dynamic/CMakeLists.txt
@@ -1,16 +1,8 @@
-set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
-  Support
-  )
-
 add_clang_unittest(DynamicASTMatchersTests
   VariantValueTest.cpp
   ParserTest.cpp
   RegistryTest.cpp
-  )
-
-clang_target_link_lib

[libclc] f14ff59 - [libclc] Move exp, exp2 and expm1 to the CLC library (#133932)

2025-04-01 Thread via cfe-commits

Author: Fraser Cormack
Date: 2025-04-01T18:15:37+01:00
New Revision: f14ff59da7f98a405999bcc8481b20446de0d0cd

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

LOG: [libclc] Move exp, exp2 and expm1 to the CLC library (#133932)

These all share the use of a common helper function so are handled in
one go. These builtins are also now vectorized.

Added: 
libclc/clc/include/clc/math/clc_exp.h
libclc/clc/include/clc/math/clc_exp2.h
libclc/clc/include/clc/math/clc_exp_helper.h
libclc/clc/include/clc/math/clc_exp_helper.inc
libclc/clc/include/clc/math/clc_expm1.h
libclc/clc/lib/generic/math/clc_exp.cl
libclc/clc/lib/generic/math/clc_exp.inc
libclc/clc/lib/generic/math/clc_exp2.cl
libclc/clc/lib/generic/math/clc_exp2.inc
libclc/clc/lib/generic/math/clc_exp_helper.cl
libclc/clc/lib/generic/math/clc_exp_helper.inc
libclc/clc/lib/generic/math/clc_expm1.cl
libclc/clc/lib/generic/math/clc_expm1.inc

Modified: 
libclc/clc/lib/generic/SOURCES
libclc/clspv/lib/SOURCES
libclc/generic/lib/SOURCES
libclc/generic/lib/math/exp.cl
libclc/generic/lib/math/exp2.cl
libclc/generic/lib/math/expm1.cl
libclc/spirv/lib/SOURCES

Removed: 
libclc/generic/lib/math/exp_helper.cl
libclc/generic/lib/math/exp_helper.h



diff  --git a/libclc/generic/lib/math/exp_helper.h 
b/libclc/clc/include/clc/math/clc_exp.h
similarity index 60%
rename from libclc/generic/lib/math/exp_helper.h
rename to libclc/clc/include/clc/math/clc_exp.h
index 84a8febb4bb12..00b5a7f69779a 100644
--- a/libclc/generic/lib/math/exp_helper.h
+++ b/libclc/clc/include/clc/math/clc_exp.h
@@ -6,9 +6,15 @@
 //
 
//===--===//
 
-#ifdef cl_khr_fp64
+#ifndef __CLC_MATH_CLC_EXP_H__
+#define __CLC_MATH_CLC_EXP_H__
 
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-_CLC_DECL double __clc_exp_helper(double x, double x_min, double x_max, double 
r, int n);
+#define __CLC_BODY 
+#define __CLC_FUNCTION __clc_exp
 
-#endif
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_EXP_H__

diff  --git a/libclc/clc/include/clc/math/clc_exp2.h 
b/libclc/clc/include/clc/math/clc_exp2.h
new file mode 100644
index 0..20ee54b0a2755
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_exp2.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_EXP2_H__
+#define __CLC_MATH_CLC_EXP2_H__
+
+#define __CLC_BODY 
+#define __CLC_FUNCTION __clc_exp2
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_EXP2_H__

diff  --git a/libclc/clc/include/clc/math/clc_exp_helper.h 
b/libclc/clc/include/clc/math/clc_exp_helper.h
new file mode 100644
index 0..8a2db5de16764
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_exp_helper.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_EXP_HELPER
+#define __CLC_MATH_CLC_EXP_HELPER
+
+#define __DOUBLE_ONLY
+#define __CLC_BODY 
+
+#include 
+
+#undef __CLC_BODY
+#undef __DOUBLE_ONLY
+
+#endif // __CLC_MATH_CLC_EXP_HELPER

diff  --git a/libclc/clc/include/clc/math/clc_exp_helper.inc 
b/libclc/clc/include/clc/math/clc_exp_helper.inc
new file mode 100644
index 0..cdf650405c815
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_exp_helper.inc
@@ -0,0 +1,13 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+_CLC_DECL _CLC_OVERLOAD __CLC_GENTYPE __clc_exp_helper(__CLC_GENTYPE x,
+   __CLC_GENTYPE x_min,
+   __CLC_GENTYPE x_max,
+   __CLC_GENTYPE r,
+   __CLC_INTN

[libclc] c1efd8b - [libclc][NFC] Delete two unused headers

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

Author: Fraser Cormack
Date: 2025-04-01T14:54:50+01:00
New Revision: c1efd8b663b7db3c717fae8a1991dcc4b8304c8f

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

LOG: [libclc][NFC] Delete two unused headers

These should have been deleted when the respective builtins were moved
to the CLC library.

Added: 


Modified: 


Removed: 
libclc/generic/include/math/clc_exp10.h
libclc/generic/include/math/clc_tanpi.h



diff  --git a/libclc/generic/include/math/clc_exp10.h 
b/libclc/generic/include/math/clc_exp10.h
deleted file mode 100644
index b789410d6f2ac..0
--- a/libclc/generic/include/math/clc_exp10.h
+++ /dev/null
@@ -1,12 +0,0 @@
-//===--===//
-//
-// 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
-//
-//===--===//
-
-#define __CLC_FUNCTION __clc_exp10
-#define __CLC_BODY 
-#include 
-#undef __CLC_FUNCTION

diff  --git a/libclc/generic/include/math/clc_tanpi.h 
b/libclc/generic/include/math/clc_tanpi.h
deleted file mode 100644
index 0f7d825dd1483..0
--- a/libclc/generic/include/math/clc_tanpi.h
+++ /dev/null
@@ -1,13 +0,0 @@
-//===--===//
-//
-// 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
-//
-//===--===//
-
-#define __CLC_FUNCTION __clc_tanpi
-#define __CLC_BODY 
-#include 
-#undef __CLC_BODY
-#undef __CLC_FUNCTION



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


[clang] [llvm] [AARCH64][Neon] switch to using bitcasts in arm_neon.h where appropriate (PR #127043)

2025-04-01 Thread via cfe-commits

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

Thank you Marian, 
The patch looks good

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


[clang] [X86][AVX10] Re-target mavx10.1 and emit warning for mavx10.x-256/512 and m[no-]evex512 (PR #132542)

2025-04-01 Thread Simon Pilgrim via cfe-commits

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


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


[clang] [C11] Implement WG14 N1285 (temporary lifetimes) (PR #133472)

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

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/133472

>From f9268b3a331fd8caf2440d742a1f084c0f9648ce Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Fri, 28 Mar 2025 13:01:58 -0400
Subject: [PATCH 1/9] [C11] Implement WG14 N1285 (temporary lifetimes)

This feature largely models the same behavior as in C++11. It is
technically a breaking change between C99 and C11, so the paper is not
being backported to older language modes.

One difference between C++ and C is that things which are rvalues in C
are often lvalues in C++ (such as the result of a ternary operator or a
comma operator).
---
 clang/docs/ReleaseNotes.rst  |   9 +
 clang/lib/CodeGen/CGExpr.cpp |   4 +-
 clang/lib/Sema/Sema.cpp  |   5 +-
 clang/lib/Sema/SemaInit.cpp  |   2 +-
 clang/test/C/C11/n1285.c |  83 ++--
 clang/test/C/C11/n1285_1.c   | 212 +++
 clang/test/CodeGenObjC/property-array-type.m |   5 +-
 clang/www/c_status.html  |   2 +-
 8 files changed, 301 insertions(+), 21 deletions(-)
 create mode 100644 clang/test/C/C11/n1285_1.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b96780cec75d9..c51b3c44f3b3b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -160,6 +160,15 @@ C23 Feature Support
   treated as if the compound literal were within the body rather than at file
   scope.
 
+C11 Feature Support
+^^^
+- Implemented `WG14 N1285 
`_
+  which introduces the notion of objects with a temporary lifetime. When an
+  expression resulting in an rvalue with structure or union type and that type
+  contains a member of array type, the expression result is an automatic 
storage
+  duration object with temporary lifetime which begins when the expression is
+  evaluated and ends at the evaluation of the containing full expression.
+
 Non-comprehensive list of changes in this release
 -
 
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 5943ff9294e1a..2328ad0def736 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -387,8 +387,8 @@ pushTemporaryCleanup(CodeGenFunction &CGF, const 
MaterializeTemporaryExpr *M,
   if (const RecordType *RT =
   E->getType()->getBaseElementTypeUnsafe()->getAs()) {
 // Get the destructor for the reference temporary.
-auto *ClassDecl = cast(RT->getDecl());
-if (!ClassDecl->hasTrivialDestructor())
+if (auto *ClassDecl = dyn_cast(RT->getDecl());
+ClassDecl && !ClassDecl->hasTrivialDestructor())
   ReferenceTemporaryDtor = ClassDecl->getDestructor();
   }
 
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 93a2d797679d4..4b573abb8efba 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -741,10 +741,11 @@ ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty,
   if (Kind == CK_ArrayToPointerDecay) {
 // C++1z [conv.array]: The temporary materialization conversion is applied.
 // We also use this to fuel C++ DR1213, which applies to C++11 onwards.
-if (getLangOpts().CPlusPlus && E->isPRValue()) {
+if ((getLangOpts().C11 || getLangOpts().CPlusPlus) && E->isPRValue()) {
   // The temporary is an lvalue in C++98 and an xvalue otherwise.
   ExprResult Materialized = CreateMaterializeTemporaryExpr(
-  E->getType(), E, !getLangOpts().CPlusPlus11);
+  E->getType(), E,
+  getLangOpts().CPlusPlus && !getLangOpts().CPlusPlus11);
   if (Materialized.isInvalid())
 return ExprError();
   E = Materialized.get();
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 9814c3f456f0d..c47ea71cbafb5 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7654,7 +7654,7 @@ ExprResult Sema::TemporaryMaterializationConversion(Expr 
*E) {
   // FIXME: This means that AST consumers need to deal with "prvalues" that
   // denote materialized temporaries. Maybe we should add another ValueKind
   // for "xvalue pretending to be a prvalue" for C++98 support.
-  if (!E->isPRValue() || !getLangOpts().CPlusPlus11)
+  if (!E->isPRValue() || (!getLangOpts().CPlusPlus11 && !getLangOpts().C11))
 return E;
 
   // C++1z [conv.rval]/1: T shall be a complete type.
diff --git a/clang/test/C/C11/n1285.c b/clang/test/C/C11/n1285.c
index e7a9463e68103..c4fb199e33ae5 100644
--- a/clang/test/C/C11/n1285.c
+++ b/clang/test/C/C11/n1285.c
@@ -1,24 +1,81 @@
-// RUN: %clang_cc1 -verify=wrong -std=c99 %s
-// RUN: %clang_cc1 -verify=wrong -std=c11 %s
-// RUN: %clang_cc1 -verify=cpp -std=c++11 -x c++ %s
+// RUN: %clang_cc1 -fsyntax-only -verify=good -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,c -std=c11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expect

[clang] 2b06410 - Fix a build error (#133957)

2025-04-01 Thread via cfe-commits

Author: Arvind Sudarsanam
Date: 2025-04-01T18:24:54Z
New Revision: 2b064108ed55af510379edc81622983385c7977f

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

LOG: Fix a build error (#133957)

This fixes error reported in post-commit testing of
https://github.com/llvm/llvm-project/pull/133797
LOG: https://lab.llvm.org/buildbot/#/builders/140/builds/20266

Thanks

Signed-off-by: Arvind Sudarsanam 

Added: 


Modified: 
clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp

Removed: 




diff  --git a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp 
b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
index f4a16549340a1..fccea538b1dc5 100644
--- a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
+++ b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
@@ -205,7 +205,7 @@ Expected> 
getBitcodeModule(StringRef File,
 
   auto M = getLazyIRFileModule(File, Err, C);
   if (M)
-return M;
+return std::move(M);
   return createStringError(Err.getMessage());
 }
 



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


[clang] [clang-repl] Implement LoadDynamicLibrary for clang-repl wasm use cases (PR #133037)

2025-04-01 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/133037

>From a7ccd0e0b261c303639d3880fc51b0ed99e17363 Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Wed, 26 Mar 2025 10:33:37 +0530
Subject: [PATCH 1/4] Implement LoadDynamicLibrary for clang-repl wasm use
 cases

---
 clang/lib/Interpreter/Interpreter.cpp | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index fa4c1439c9261..f8c8d0a425659 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -18,6 +18,7 @@
 #include "llvm/Support/VirtualFileSystem.h"
 #ifdef __EMSCRIPTEN__
 #include "Wasm.h"
+#include 
 #endif // __EMSCRIPTEN__
 
 #include "clang/AST/ASTConsumer.h"
@@ -711,6 +712,14 @@ llvm::Error Interpreter::Undo(unsigned N) {
 }
 
 llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
+#ifdef __EMSCRIPTEN__
+  void *handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
+  if (!handle) {
+llvm::errs() << dlerror() << '\n';
+return llvm::make_error("Failed to load dynamic 
library",
+   llvm::inconvertibleErrorCode());
+  }
+#else
   auto EE = getExecutionEngine();
   if (!EE)
 return EE.takeError();
@@ -722,6 +731,7 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char 
*name) {
 EE->getMainJITDylib().addGenerator(std::move(*DLSG));
   else
 return DLSG.takeError();
+#endif
 
   return llvm::Error::success();
 }

>From bc41b71965e1e33a32d1a54fd79148d1b6890dce Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Thu, 27 Mar 2025 12:34:23 +0530
Subject: [PATCH 2/4] Override getSymbolAddress

---
 clang/lib/Interpreter/IncrementalExecutor.h |  2 +-
 clang/lib/Interpreter/Wasm.cpp  | 13 +
 clang/lib/Interpreter/Wasm.h|  2 ++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Interpreter/IncrementalExecutor.h 
b/clang/lib/Interpreter/IncrementalExecutor.h
index dbd61f0b8b1eb..71d71bc3883e2 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ b/clang/lib/Interpreter/IncrementalExecutor.h
@@ -57,7 +57,7 @@ class IncrementalExecutor {
   virtual llvm::Error removeModule(PartialTranslationUnit &PTU);
   virtual llvm::Error runCtors() const;
   virtual llvm::Error cleanUp();
-  llvm::Expected
+  virtual llvm::Expected
   getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
 
   llvm::orc::LLJIT &GetExecutionEngine() { return *Jit; }
diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp
index f7cb7598c77f8..0543a3504c9a2 100644
--- a/clang/lib/Interpreter/Wasm.cpp
+++ b/clang/lib/Interpreter/Wasm.cpp
@@ -144,6 +144,19 @@ llvm::Error WasmIncrementalExecutor::cleanUp() {
   return llvm::Error::success();
 }
 
+llvm::Expected
+WasmIncrementalExecutor::getSymbolAddress(llvm::StringRef Name,
+  SymbolNameKind NameKind) const {
+  void *Sym = dlsym(RTLD_DEFAULT, Name.str().c_str());
+  if (!Sym) {
+return llvm::make_error("dlsym failed for symbol: " +
+   Name.str(),
+   llvm::inconvertibleErrorCode());
+  }
+
+  return llvm::orc::ExecutorAddr::fromPtr(Sym);
+}
+
 WasmIncrementalExecutor::~WasmIncrementalExecutor() = default;
 
 } // namespace clang
diff --git a/clang/lib/Interpreter/Wasm.h b/clang/lib/Interpreter/Wasm.h
index 4632613326d39..beafb01be7d8a 100644
--- a/clang/lib/Interpreter/Wasm.h
+++ b/clang/lib/Interpreter/Wasm.h
@@ -29,6 +29,8 @@ class WasmIncrementalExecutor : public IncrementalExecutor {
   llvm::Error removeModule(PartialTranslationUnit &PTU) override;
   llvm::Error runCtors() const override;
   llvm::Error cleanUp() override;
+  llvm::Expected
+  getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
 
   ~WasmIncrementalExecutor() override;
 };

>From 60d4622e23902bf7c5fd1040c9f82f9b03e134ce Mon Sep 17 00:00:00 2001
From: Anutosh Bhat 
Date: Thu, 27 Mar 2025 14:05:35 +0530
Subject: [PATCH 3/4] Update Wasm.h

---
 clang/lib/Interpreter/Wasm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Interpreter/Wasm.h b/clang/lib/Interpreter/Wasm.h
index beafb01be7d8a..d27455ec42c02 100644
--- a/clang/lib/Interpreter/Wasm.h
+++ b/clang/lib/Interpreter/Wasm.h
@@ -30,7 +30,7 @@ class WasmIncrementalExecutor : public IncrementalExecutor {
   llvm::Error runCtors() const override;
   llvm::Error cleanUp() override;
   llvm::Expected
-  getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
+  getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const 
override;;
 
   ~WasmIncrementalExecutor() override;
 };

>From 50370179c93d5f524fd38e093248d6e74db8155c Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Tue, 1 Apr 2025 10:40:57 +0530
Subject: [PATCH 4/4] fix clang format

---
 clang/lib/Interpreter/Wasm.h | 3 ++

[clang] 7003f7d - [clang-sycl-linker] Replace llvm-link with API calls (#133797)

2025-04-01 Thread via cfe-commits

Author: Arvind Sudarsanam
Date: 2025-04-01T17:09:45Z
New Revision: 7003f7d23aeca97b0301e605ed8b02436b38f789

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

LOG: [clang-sycl-linker] Replace llvm-link with API calls (#133797)

This PR has the following changes:

Replace llvm-link with calls to linkInModule to link device files Add
-print-linked-module option to dump linked module for testing Added a
test to verify that linking is working as expected. We will eventually
move to using thin LTO for linking device inputs.

Thanks

-

Signed-off-by: Arvind Sudarsanam 

Added: 
clang/test/Driver/Inputs/SYCL/bar.ll
clang/test/Driver/Inputs/SYCL/baz.ll
clang/test/Driver/Inputs/SYCL/foo.ll
clang/test/Driver/Inputs/SYCL/libsycl.ll
clang/test/Driver/link-device-code.test

Modified: 
clang/test/Driver/clang-sycl-linker-test.cpp
clang/test/Driver/sycl-link-spirv-target.cpp
clang/tools/clang-sycl-linker/CMakeLists.txt
clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
clang/tools/clang-sycl-linker/SYCLLinkOpts.td

Removed: 




diff  --git a/clang/test/Driver/Inputs/SYCL/bar.ll 
b/clang/test/Driver/Inputs/SYCL/bar.ll
new file mode 100644
index 0..d17221b8dca18
--- /dev/null
+++ b/clang/test/Driver/Inputs/SYCL/bar.ll
@@ -0,0 +1,7 @@
+target triple = "spirv64"
+
+define spir_func i32 @bar_func1(i32 %a, i32 %b) {
+entry:
+  %res = add nsw i32 %b, %a
+  ret i32 %res
+}

diff  --git a/clang/test/Driver/Inputs/SYCL/baz.ll 
b/clang/test/Driver/Inputs/SYCL/baz.ll
new file mode 100644
index 0..6cdf3735ed77e
--- /dev/null
+++ b/clang/test/Driver/Inputs/SYCL/baz.ll
@@ -0,0 +1,15 @@
+target triple = "spirv64"
+
+define spir_func i32 @bar_func1(i32 %a, i32 %b) {
+entry:
+  %mul = shl nsw i32 %a, 1
+  %res = add nsw i32 %mul, %b
+  ret i32 %res
+}
+
+define spir_func i32 @baz_func1(i32 %a) {
+entry:
+  %add = add nsw i32 %a, 5
+  %res = tail call spir_func i32 @bar_func1(i32 %a, i32 %add)
+  ret i32 %res
+}

diff  --git a/clang/test/Driver/Inputs/SYCL/foo.ll 
b/clang/test/Driver/Inputs/SYCL/foo.ll
new file mode 100644
index 0..43aaf1424ee2d
--- /dev/null
+++ b/clang/test/Driver/Inputs/SYCL/foo.ll
@@ -0,0 +1,19 @@
+target triple = "spirv64"
+
+define spir_func i32 @foo_func1(i32 %a, i32 %b) {
+entry:
+  %call = tail call spir_func i32 @addFive(i32 %b)
+  %res = tail call spir_func i32 @bar_func1(i32 %a, i32 %call)
+  ret i32 %res
+}
+
+declare spir_func i32 @bar_func1(i32, i32)
+
+declare spir_func i32 @addFive(i32)
+
+define spir_func i32 @foo_func2(i32 %c, i32 %d, i32 %e) {
+entry:
+  %call = tail call spir_func i32 @foo_func1(i32 %c, i32 %d)
+  %res = mul nsw i32 %call, %e
+  ret i32 %res
+}

diff  --git a/clang/test/Driver/Inputs/SYCL/libsycl.ll 
b/clang/test/Driver/Inputs/SYCL/libsycl.ll
new file mode 100644
index 0..fdc4643e97b6a
--- /dev/null
+++ b/clang/test/Driver/Inputs/SYCL/libsycl.ll
@@ -0,0 +1,13 @@
+target triple = "spirv64"
+
+define spir_func i32 @addFive(i32 %a) {
+entry:
+  %res = add nsw i32 %a, 5
+  ret i32 %res
+}
+
+define spir_func i32 @unusedFunc(i32 %a) {
+entry:
+  %res = mul nsw i32 %a, 5
+  ret i32 %res
+}

diff  --git a/clang/test/Driver/clang-sycl-linker-test.cpp 
b/clang/test/Driver/clang-sycl-linker-test.cpp
index f358900b4fbd8..729561bd09cd8 100644
--- a/clang/test/Driver/clang-sycl-linker-test.cpp
+++ b/clang/test/Driver/clang-sycl-linker-test.cpp
@@ -1,48 +1,41 @@
 // Tests the clang-sycl-linker tool.
 //
-// Test a simple case without arguments.
-// RUN: %clangxx -emit-llvm -c %s -o %t_1.bc
-// RUN: %clangxx -emit-llvm -c %s -o %t_2.bc
-// RUN: clang-sycl-linker --dry-run -triple spirv64 %t_1.bc %t_2.bc -o a.spv 
2>&1 \
-// RUN:   | FileCheck %s --check-prefix=SIMPLE
-// SIMPLE: "{{.*}}llvm-link{{.*}}" {{.*}}.bc {{.*}}.bc -o 
[[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings
-// SIMPLE-NEXT: "{{.*}}llvm-spirv{{.*}}" {{.*}}-o a.spv [[FIRSTLLVMLINKOUT]].bc
+// Test the dry run of a simple case to link two input files.
+// RUN: %clangxx -emit-llvm -c -target spirv64 %s -o %t_1.bc
+// RUN: %clangxx -emit-llvm -c -target spirv64 %s -o %t_2.bc
+// 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
 //
-// Test that llvm-link is not called when only one input is present.
-// RUN: clang-sycl-linker --dry-run -triple spirv64 %t_1.bc -o a.spv 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=SIMPLE-NO-LINK
-// SIMPLE-NO-LINK: "{{.*}}llvm-spirv{{.*}}" {{.*}}-o a.spv {{.*}}.bc
-//
-// Test a simple case with device library files specified

[clang] [clang-sycl-linker] Replace llvm-link with API calls (PR #133797)

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

https://github.com/asudarsa created 
https://github.com/llvm/llvm-project/pull/133797

This PR has the following changes:

Replace llvm-link with calls to linkInModule to link device files Add 
-print-linked-module option to dump linked module for testing Added a test to 
verify that linking is working as expected. We will eventually move to using 
thin LTO for linking device inputs.

Thanks

>From 84b1894733786434f27bc84f7acb7edf38274276 Mon Sep 17 00:00:00 2001
From: Arvind Sudarsanam 
Date: Mon, 31 Mar 2025 13:04:47 -0700
Subject: [PATCH] [clang-sycl-linker] Replace llvm-link with API calls

This PR has the following changes:

Replace llvm-link with calls to linkInModule to link device files
Add -print-linked-module option to dump linked module for testing
Added a test to verify that linking is working as expected.
We will eventually move to using thin LTO for linking device inputs.

Thanks

Signed-off-by: Arvind Sudarsanam 
---
 clang/test/Driver/Inputs/SYCL/bar.ll  |   7 +
 clang/test/Driver/Inputs/SYCL/baz.ll  |  15 ++
 clang/test/Driver/Inputs/SYCL/foo.ll  |  19 ++
 clang/test/Driver/Inputs/SYCL/libsycl.ll  |  13 ++
 clang/test/Driver/clang-sycl-linker-test.cpp  |  43 ++---
 clang/test/Driver/link-device-code.test   |  23 +++
 clang/test/Driver/sycl-link-spirv-target.cpp  |   4 +-
 clang/tools/clang-sycl-linker/CMakeLists.txt  |   4 +
 .../clang-sycl-linker/ClangSYCLLinker.cpp | 175 ++
 clang/tools/clang-sycl-linker/SYCLLinkOpts.td |  16 +-
 10 files changed, 210 insertions(+), 109 deletions(-)
 create mode 100644 clang/test/Driver/Inputs/SYCL/bar.ll
 create mode 100644 clang/test/Driver/Inputs/SYCL/baz.ll
 create mode 100644 clang/test/Driver/Inputs/SYCL/foo.ll
 create mode 100644 clang/test/Driver/Inputs/SYCL/libsycl.ll
 create mode 100644 clang/test/Driver/link-device-code.test

diff --git a/clang/test/Driver/Inputs/SYCL/bar.ll 
b/clang/test/Driver/Inputs/SYCL/bar.ll
new file mode 100644
index 0..d17221b8dca18
--- /dev/null
+++ b/clang/test/Driver/Inputs/SYCL/bar.ll
@@ -0,0 +1,7 @@
+target triple = "spirv64"
+
+define spir_func i32 @bar_func1(i32 %a, i32 %b) {
+entry:
+  %res = add nsw i32 %b, %a
+  ret i32 %res
+}
diff --git a/clang/test/Driver/Inputs/SYCL/baz.ll 
b/clang/test/Driver/Inputs/SYCL/baz.ll
new file mode 100644
index 0..6cdf3735ed77e
--- /dev/null
+++ b/clang/test/Driver/Inputs/SYCL/baz.ll
@@ -0,0 +1,15 @@
+target triple = "spirv64"
+
+define spir_func i32 @bar_func1(i32 %a, i32 %b) {
+entry:
+  %mul = shl nsw i32 %a, 1
+  %res = add nsw i32 %mul, %b
+  ret i32 %res
+}
+
+define spir_func i32 @baz_func1(i32 %a) {
+entry:
+  %add = add nsw i32 %a, 5
+  %res = tail call spir_func i32 @bar_func1(i32 %a, i32 %add)
+  ret i32 %res
+}
diff --git a/clang/test/Driver/Inputs/SYCL/foo.ll 
b/clang/test/Driver/Inputs/SYCL/foo.ll
new file mode 100644
index 0..43aaf1424ee2d
--- /dev/null
+++ b/clang/test/Driver/Inputs/SYCL/foo.ll
@@ -0,0 +1,19 @@
+target triple = "spirv64"
+
+define spir_func i32 @foo_func1(i32 %a, i32 %b) {
+entry:
+  %call = tail call spir_func i32 @addFive(i32 %b)
+  %res = tail call spir_func i32 @bar_func1(i32 %a, i32 %call)
+  ret i32 %res
+}
+
+declare spir_func i32 @bar_func1(i32, i32)
+
+declare spir_func i32 @addFive(i32)
+
+define spir_func i32 @foo_func2(i32 %c, i32 %d, i32 %e) {
+entry:
+  %call = tail call spir_func i32 @foo_func1(i32 %c, i32 %d)
+  %res = mul nsw i32 %call, %e
+  ret i32 %res
+}
diff --git a/clang/test/Driver/Inputs/SYCL/libsycl.ll 
b/clang/test/Driver/Inputs/SYCL/libsycl.ll
new file mode 100644
index 0..fdc4643e97b6a
--- /dev/null
+++ b/clang/test/Driver/Inputs/SYCL/libsycl.ll
@@ -0,0 +1,13 @@
+target triple = "spirv64"
+
+define spir_func i32 @addFive(i32 %a) {
+entry:
+  %res = add nsw i32 %a, 5
+  ret i32 %res
+}
+
+define spir_func i32 @unusedFunc(i32 %a) {
+entry:
+  %res = mul nsw i32 %a, 5
+  ret i32 %res
+}
diff --git a/clang/test/Driver/clang-sycl-linker-test.cpp 
b/clang/test/Driver/clang-sycl-linker-test.cpp
index f358900b4fbd8..729561bd09cd8 100644
--- a/clang/test/Driver/clang-sycl-linker-test.cpp
+++ b/clang/test/Driver/clang-sycl-linker-test.cpp
@@ -1,48 +1,41 @@
 // Tests the clang-sycl-linker tool.
 //
-// Test a simple case without arguments.
-// RUN: %clangxx -emit-llvm -c %s -o %t_1.bc
-// RUN: %clangxx -emit-llvm -c %s -o %t_2.bc
-// RUN: clang-sycl-linker --dry-run -triple spirv64 %t_1.bc %t_2.bc -o a.spv 
2>&1 \
-// RUN:   | FileCheck %s --check-prefix=SIMPLE
-// SIMPLE: "{{.*}}llvm-link{{.*}}" {{.*}}.bc {{.*}}.bc -o 
[[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings
-// SIMPLE-NEXT: "{{.*}}llvm-spirv{{.*}}" {{.*}}-o a.spv [[FIRSTLLVMLINKOUT]].bc
+// Test the dry run of a simple case to link two input files.
+// RUN: %clangxx -emit-llvm -c -target spirv64 %s -o %t_1.bc
+// RUN: %clangxx -emit-llvm -c -target spirv64 %s -o %t_2.bc
+// RUN: clang-sycl-linker --dry-run -v -triple=spirv64 %t_1.bc %t_2.bc -o 
a.spv 2>&1 \
+// RUN:   |

[clang] 9586117 - [clang-sycl-linker] Fix a warning

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

Author: Kazu Hirata
Date: 2025-04-01T10:35:50-07:00
New Revision: 9586117c3ab6f16883a646847cfa65b065ad4ae3

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

LOG: [clang-sycl-linker] Fix a warning

This patch fixes:

  clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp:127:13: error:
  function 'getMainExecutable' is not needed and will not be emitted
  [-Werror,-Wunneeded-internal-declaration]

Added: 


Modified: 
clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp

Removed: 




diff  --git a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp 
b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
index 8dd0394e9610e..f4a16549340a1 100644
--- a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
+++ b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
@@ -124,12 +124,6 @@ const OptTable &getOptTable() {
   exit(EXIT_FAILURE);
 }
 
-std::string getMainExecutable(const char *Name) {
-  void *Ptr = (void *)(intptr_t)&getMainExecutable;
-  auto COWPath = sys::fs::getMainExecutable(Name, Ptr);
-  return sys::path::parent_path(COWPath).str();
-}
-
 Expected createTempFile(const ArgList &Args, const Twine &Prefix,
StringRef Extension) {
   SmallString<128> OutputFile;



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


[clang] 6767555 - Reland "[HLSL][RootSignature] Implement parsing of a DescriptorTable with empty clauses" (#133958)

2025-04-01 Thread via cfe-commits

Author: Finn Plummer
Date: 2025-04-01T14:58:30-07:00
New Revision: 676755561d5a2f074411ad289fed55c977571a32

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

LOG: Reland "[HLSL][RootSignature] Implement parsing of a DescriptorTable with 
empty clauses" (#133958)

This pr relands https://github.com/llvm/llvm-project/pull/133302.

It resolves two issues:
- Linking error during build,
[here](https://github.com/llvm/llvm-project/pull/133302#issuecomment-2767259848).
There was a missing dependency for `clangLex` for the
`ParseHLSLRootSignatureTest.cpp` unit testing. This library was added to
the dependencies to resolve the error. It wasn't caught previously as
the library was transitively linked in most build environments
- Warning of unused declaration,
[here](https://github.com/llvm/llvm-project/pull/133302#issuecomment-2767091368).
There was a usability line in `LexHLSLRootSignature.h` of the form
`using TokenKind = enum RootSignatureToken::Kind` which causes this
error. The declaration is removed from the header file to be used
locally in the `.cpp` files that use it.
Notably, the original pr would also exposed `clang::hlsl::TokenKind` to
everywhere it was included, which had a name clash with
`tok::TokenKind`. This is another motivation to change to the proposed
resolution.

-

Co-authored-by: Finn Plummer 

Added: 
clang/include/clang/Parse/ParseHLSLRootSignature.h
clang/lib/Parse/ParseHLSLRootSignature.cpp
clang/unittests/Parse/CMakeLists.txt
clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
clang/include/clang/Lex/LexHLSLRootSignature.h
clang/lib/Lex/LexHLSLRootSignature.cpp
clang/lib/Parse/CMakeLists.txt
clang/unittests/CMakeLists.txt
clang/unittests/Lex/LexHLSLRootSignatureTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 86c361b4dbcf7..2582e1e5ef0f6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1830,4 +1830,8 @@ def err_hlsl_virtual_function
 def err_hlsl_virtual_inheritance
 : Error<"virtual inheritance is unsupported in HLSL">;
 
+// HLSL Root Siganture diagnostic messages
+def err_hlsl_unexpected_end_of_params
+: Error<"expected %0 to denote end of parameters, or, another valid 
parameter of %1">;
+
 } // end of Parser diagnostics

diff  --git a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def 
b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
index e6df763920430..c514d3456146a 100644
--- a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
+++ b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
@@ -14,16 +14,16 @@
 
//===--===//
 
 #ifndef TOK
-#define TOK(X)
+#define TOK(X, SPELLING)
 #endif
 #ifndef PUNCTUATOR
-#define PUNCTUATOR(X,Y) TOK(pu_ ## X)
+#define PUNCTUATOR(X,Y) TOK(pu_ ## X, Y)
 #endif
 #ifndef KEYWORD
-#define KEYWORD(X) TOK(kw_ ## X)
+#define KEYWORD(X) TOK(kw_ ## X, #X)
 #endif
 #ifndef ENUM
-#define ENUM(NAME, LIT) TOK(en_ ## NAME)
+#define ENUM(NAME, LIT) TOK(en_ ## NAME, LIT)
 #endif
 
 // Defines the various types of enum
@@ -49,15 +49,15 @@
 #endif
 
 // General Tokens:
-TOK(invalid)
-TOK(end_of_stream)
-TOK(int_literal)
+TOK(invalid, "invalid identifier")
+TOK(end_of_stream, "end of stream")
+TOK(int_literal, "integer literal")
 
 // Register Tokens:
-TOK(bReg)
-TOK(tReg)
-TOK(uReg)
-TOK(sReg)
+TOK(bReg, "b register")
+TOK(tReg, "t register")
+TOK(uReg, "u register")
+TOK(sReg, "s register")
 
 // Punctuators:
 PUNCTUATOR(l_paren, '(')
@@ -69,6 +69,7 @@ PUNCTUATOR(plus,'+')
 PUNCTUATOR(minus,   '-')
 
 // RootElement Keywords:
+KEYWORD(RootSignature) // used only for diagnostic messaging
 KEYWORD(DescriptorTable)
 
 // DescriptorTable Keywords:

diff  --git a/clang/include/clang/Lex/LexHLSLRootSignature.h 
b/clang/include/clang/Lex/LexHLSLRootSignature.h
index 21c44e0351d9e..4dc80ff546aa0 100644
--- a/clang/include/clang/Lex/LexHLSLRootSignature.h
+++ b/clang/include/clang/Lex/LexHLSLRootSignature.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_LEX_LEXHLSLROOTSIGNATURE_H
 #define LLVM_CLANG_LEX_LEXHLSLROOTSIGNATURE_H
 
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceLocation.h"
 
 #include "llvm/ADT/SmallVector.h"
@@ -24,11 +25,11 @@ namespace hlsl {
 
 struct RootSignatureToken {
   enum Kind {
-#define TOK(X) X,
+#define TOK(X, SPELLING) X,
 #include "clang/Lex/HLSLRootSignatureTokenKinds.def"
   };
 
-  Kind Kind = Kind::invalid;
+  Kind Tok

[clang] [clang-tools-extra] [clang] Concepts: support pack expansions for type constraints (PR #132626)

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

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/132626

>From bbd2a588f79926323a29a3a70f061e4a2433bdc2 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sat, 22 Mar 2025 17:29:16 -0300
Subject: [PATCH 1/3] Revert "[Clang] Distinguish expanding-pack-in-place cases
 for SubstTemplateTypeParmTypes (#114220)"

This reverts commit adb0d8ddceb143749c519d14b8b31b481071da77.
---
 clang/include/clang/AST/ASTContext.h |  4 +--
 clang/include/clang/AST/PropertiesBase.td|  1 -
 clang/include/clang/AST/Type.h   | 29 ++--
 clang/include/clang/AST/TypeProperties.td|  5 +--
 clang/lib/AST/ASTContext.cpp |  7 ++--
 clang/lib/AST/ASTImporter.cpp|  4 +--
 clang/lib/AST/Type.cpp   |  6 +---
 clang/lib/Sema/SemaTemplateInstantiate.cpp   | 35 ++--
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp |  2 +-
 9 files changed, 23 insertions(+), 70 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index f386282890b5a..a24f30815e6b9 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1798,9 +1798,7 @@ class ASTContext : public RefCountedBase {
   QualType
   getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
unsigned Index,
-   std::optional PackIndex,
-   SubstTemplateTypeParmTypeFlag Flag =
-   SubstTemplateTypeParmTypeFlag::None) const;
+   std::optional PackIndex) const;
   QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl,
 unsigned Index, bool Final,
 const TemplateArgument &ArgPack);
diff --git a/clang/include/clang/AST/PropertiesBase.td 
b/clang/include/clang/AST/PropertiesBase.td
index 178308a24e1a0..5171555008ac9 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -137,7 +137,6 @@ def Selector : PropertyType;
 def SourceLocation : PropertyType;
 def StmtRef : RefPropertyType<"Stmt"> { let ConstWhenWriting = 1; }
   def ExprRef : SubclassPropertyType<"Expr", StmtRef>;
-def SubstTemplateTypeParmTypeFlag : EnumPropertyType;
 def TemplateArgument : PropertyType;
 def TemplateArgumentKind : EnumPropertyType<"TemplateArgument::ArgKind">;
 def TemplateName : DefaultValuePropertyType;
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 988362787a452..cfd417068abb7 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1786,15 +1786,6 @@ enum class AutoTypeKeyword {
   GNUAutoType
 };
 
-enum class SubstTemplateTypeParmTypeFlag {
-  None,
-
-  /// Whether to expand the pack using the stored PackIndex in place. This is
-  /// useful for e.g. substituting into an atomic constraint expression, where
-  /// that expression is part of an unexpanded pack.
-  ExpandPacksInPlace,
-};
-
 enum class ArraySizeModifier;
 enum class ElaboratedTypeKeyword;
 enum class VectorKind;
@@ -2164,9 +2155,6 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 LLVM_PREFERRED_TYPE(bool)
 unsigned HasNonCanonicalUnderlyingType : 1;
 
-LLVM_PREFERRED_TYPE(SubstTemplateTypeParmTypeFlag)
-unsigned SubstitutionFlag : 1;
-
 // The index of the template parameter this substitution represents.
 unsigned Index : 15;
 
@@ -6409,8 +6397,7 @@ class SubstTemplateTypeParmType final
   Decl *AssociatedDecl;
 
   SubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
-unsigned Index, std::optional PackIndex,
-SubstTemplateTypeParmTypeFlag Flag);
+unsigned Index, std::optional PackIndex);
 
 public:
   /// Gets the type that was substituted for the template
@@ -6439,31 +6426,21 @@ class SubstTemplateTypeParmType final
 return SubstTemplateTypeParmTypeBits.PackIndex - 1;
   }
 
-  SubstTemplateTypeParmTypeFlag getSubstitutionFlag() const {
-return static_cast(
-SubstTemplateTypeParmTypeBits.SubstitutionFlag);
-  }
-
   bool isSugared() const { return true; }
   QualType desugar() const { return getReplacementType(); }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, getReplacementType(), getAssociatedDecl(), getIndex(),
-getPackIndex(), getSubstitutionFlag());
+getPackIndex());
   }
 
   static void Profile(llvm::FoldingSetNodeID &ID, QualType Replacement,
   const Decl *AssociatedDecl, unsigned Index,
-  std::optional PackIndex,
-  SubstTemplateTypeParmTypeFlag Flag) {
+  std::optional PackIndex) {
 Replacement.Profile(ID);
 ID.AddPointer(AssociatedDecl);
 ID.AddInteger(Index)

[clang] [cmake] Refactor clang unittest cmake (PR #133545)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-ppc64le-linux-multistage` running on `ppc64le-clang-multistage-test` 
while building `clang` at step 5 "ninja check 1".

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


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

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
...
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/third-party/unittest/googletest/include/gtest/internal/gtest-param-util.h:445:12:
   required from ‘testing::internal::TestFactoryBase* 
testing::internal::TestMetaFactory::CreateTestFactory(testing::internal::TestMetaFactory::ParamType)
 [with TestSuite = clang::tidy::test::SizeTest_TokenSize_Test; 
testing::internal::TestMetaFactory::ParamType = 
clang::tidy::test::{anonymous}::SizeParam]’
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/third-party/unittest/googletest/include/gtest/internal/gtest-param-util.h:444:20:
   required from here
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/third-party/unittest/googletest/include/gtest/internal/gtest-param-util.h:399:7:
 warning: 
‘testing::internal::ParameterizedTestFactory’
 has a field 
‘testing::internal::ParameterizedTestFactory::parameter_’
 whose type uses the anonymous namespace [-Wsubobject-linkage]
 class ParameterizedTestFactory : public TestFactoryBase {
   ^~~~
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/third-party/unittest/googletest/include/gtest/internal/gtest-param-util.h:
 In instantiation of ‘class 
testing::internal::ParameterizedTestFactory’:
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/third-party/unittest/googletest/include/gtest/internal/gtest-param-util.h:445:12:
   required from ‘testing::internal::TestFactoryBase* 
testing::internal::TestMetaFactory::CreateTestFactory(testing::internal::TestMetaFactory::ParamType)
 [with TestSuite = clang::tidy::test::MatcherTest_MatchResult_Test; 
testing::internal::TestMetaFactory::ParamType = 
clang::tidy::test::{anonymous}::MatchParam]’
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/third-party/unittest/googletest/include/gtest/internal/gtest-param-util.h:444:20:
   required from here
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/third-party/unittest/googletest/include/gtest/internal/gtest-param-util.h:399:7:
 warning: 
‘testing::internal::ParameterizedTestFactory’
 has a field 
‘testing::internal::ParameterizedTestFactory::parameter_’
 whose type uses the anonymous namespace [-Wsubobject-linkage]
[1116/1221] Linking CXX executable 
tools/clang/unittests/AST/ByteCode/InterpTests
FAILED: tools/clang/unittests/AST/ByteCode/InterpTests 
: && /usr/lib64/ccache/c++ -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual 
-Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough 
-Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-noexcept-type 
-Wdelete-non-virtual-dtor -Wno-comment -Wno-misleading-indentation 
-fdiagnostics-color -ffunction-sections -fdata-sections -fno-common 
-Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -Wl,--gc-sections 
tools/clang/unittests/AST/ByteCode/CMakeFiles/InterpTests.dir/BitcastBuffer.cpp.o
 tools/clang/unittests/AST/ByteCode/CMakeFiles/InterpTests.dir/Descriptor.cpp.o 
tools/clang/unittests/AST/ByteCode/CMakeFiles/InterpTests.dir/toAPValue.cpp.o 
-o tools/clang/unittests/AST/ByteCode/InterpTests  
-Wl,-rpath,/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/lib
  -lpthread  lib/libllvm_gtest_main.so.21.0git  -lpthread  
lib/libclangTesting.so.21.0git  lib/libclangTooling.so.21.0git  
lib/libllvm_gtest.so.21.0git  lib/libclangFrontend.so.21.0git  
lib/libclangSerialization.so.21.0git  lib/libclangASTMatchers.so.21.0git  
lib/libclangAST.so.21.0git  lib/libclangBasic.so.21.0git  
lib/libLLVMSupport.so.21.0git  
-Wl,-rpath-link,/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/lib
 && :
/usr/bin/ld: 
tools/clang/unittests/AST/ByteCode/CMakeFiles/InterpTests.dir/Descriptor.cpp.o: 
undefined reference to symbol 
'_ZN4llvm3omp27isAllowedClauseForDirectiveENS0_9DirectiveENS0_6ClauseEj'
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/lib/libLLVMFrontendOpenMP.so.21.0git:
 error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
[112

[clang] [Clang] add emit -Wignored-base-class-qualifiers diagnostic for cv-qualified base classes (PR #132116)

2025-04-01 Thread Lyle Dean via cfe-commits

lyledean1 wrote:

CI seems to be failing with the message `no such option: 
--break-system-packages` from `pip` for 
`[buildkite/github-pull-requests/linux-linux-x64](https://buildkite.com/llvm-project/github-pull-requests/builds/164119#0195f387-c1b7-4bc5-8fb8-cc8049f19033)`
 and 
[buildkite/github-pull-requests](https://buildkite.com/llvm-project/github-pull-requests/builds/164119)

But haven't changed anything around this? 

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


[clang] [clang][diagnostics] add '-Wundef-true' warning option (PR #128265)

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

nico wrote:

This found a bug in chromium, https://crbug.com/403123830 Thanks for this cool 
warning! :)

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


[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

2025-04-01 Thread via cfe-commits

mydeveloperday wrote:

I like what @owenca suggested

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


[clang] [C99] Fix definitions of INTn_C macros (PR #133916)

2025-04-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)


Changes

C99 introduced macros of the form `INTn_C(v)` which expand to a signed or 
unsigned integer constant with the specified value `v` and the type 
`int_leastN_t`. Clang's initial implementation of these macros used token 
pasting to form the integer constants, but this means that users cannot define 
a macro named `L`, `U`, `UL`, etc before including `` (in 
freestanding mode, where Clang's header is being used) because that could form 
invalid token pasting results. The new definitions now use the predefined 
`__INTn_C` macros instead of using token pasting. This matches the behavior of 
GCC.

Fixes #85995

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/Headers/stdint.h (+18-129) 
- (modified) clang/test/C/drs/dr209.c (+2-4) 
- (modified) clang/test/Preprocessor/stdint.c (+39-30) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 75a173a48e67e..e7691c583c616 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -333,6 +333,9 @@ Bug Fixes in This Version
 - Fixed a problematic case with recursive deserialization within 
``FinishedDeserializing()`` where
   ``PassInterestingDeclsToConsumer()`` was called before the declarations were 
safe to be passed. (#GH129982)
 - Fixed a modules crash where an explicit Constructor was deserialized. 
(#GH132794)
+- Defining an integer literal suffix (e.g., ``LL``) before including
+   in a freestanding build no longer causes invalid token pasting
+  when using the ``INTn_C`` macros. (#GH85995)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Headers/stdint.h b/clang/lib/Headers/stdint.h
index 01feab7b1ee2c..96c2ccace13d0 100644
--- a/clang/lib/Headers/stdint.h
+++ b/clang/lib/Headers/stdint.h
@@ -317,166 +317,55 @@ typedef __UINTMAX_TYPE__ uintmax_t;
  * integer width that the target implements, so corresponding macros are
  * defined below, too.
  *
- * These macros are defined using the same successive-shrinking approach as
- * the type definitions above. It is likewise important that macros are defined
- * in order of decending width.
- *
  * Note that C++ should not check __STDC_CONSTANT_MACROS here, contrary to the
  * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]).
  */
 
-#define __int_c_join(a, b) a ## b
-#define __int_c(v, suffix) __int_c_join(v, suffix)
-#define __uint_c(v, suffix) __int_c_join(v##U, suffix)
-
-
-#ifdef __INT64_TYPE__
-# undef __int64_c_suffix
-# undef __int32_c_suffix
-# undef __int16_c_suffix
-# undef  __int8_c_suffix
-# ifdef __INT64_C_SUFFIX__
-#  define __int64_c_suffix __INT64_C_SUFFIX__
-#  define __int32_c_suffix __INT64_C_SUFFIX__
-#  define __int16_c_suffix __INT64_C_SUFFIX__
-#  define  __int8_c_suffix __INT64_C_SUFFIX__
-# endif /* __INT64_C_SUFFIX__ */
-#endif /* __INT64_TYPE__ */
-
 #ifdef __int_least64_t
-# ifdef __int64_c_suffix
-#  define INT64_C(v) __int_c(v, __int64_c_suffix)
-#  define UINT64_C(v) __uint_c(v, __int64_c_suffix)
-# else
-#  define INT64_C(v) v
-#  define UINT64_C(v) v ## U
-# endif /* __int64_c_suffix */
+#define INT64_C(v) __INT64_C(v)
+#define UINT64_C(v) __UINT64_C(v)
 #endif /* __int_least64_t */
 
 
 #ifdef __INT56_TYPE__
-# undef __int32_c_suffix
-# undef __int16_c_suffix
-# undef  __int8_c_suffix
-# ifdef __INT56_C_SUFFIX__
-#  define INT56_C(v) __int_c(v, __INT56_C_SUFFIX__)
-#  define UINT56_C(v) __uint_c(v, __INT56_C_SUFFIX__)
-#  define __int32_c_suffix __INT56_C_SUFFIX__
-#  define __int16_c_suffix __INT56_C_SUFFIX__
-#  define __int8_c_suffix  __INT56_C_SUFFIX__
-# else
-#  define INT56_C(v) v
-#  define UINT56_C(v) v ## U
-# endif /* __INT56_C_SUFFIX__ */
+#define INT56_C(v) __INT56_C(v)
+#define UINT56_C(v) __UINT56_C(v)
 #endif /* __INT56_TYPE__ */
 
 
 #ifdef __INT48_TYPE__
-# undef __int32_c_suffix
-# undef __int16_c_suffix
-# undef  __int8_c_suffix
-# ifdef __INT48_C_SUFFIX__
-#  define INT48_C(v) __int_c(v, __INT48_C_SUFFIX__)
-#  define UINT48_C(v) __uint_c(v, __INT48_C_SUFFIX__)
-#  define __int32_c_suffix __INT48_C_SUFFIX__
-#  define __int16_c_suffix __INT48_C_SUFFIX__
-#  define __int8_c_suffix  __INT48_C_SUFFIX__
-# else
-#  define INT48_C(v) v
-#  define UINT48_C(v) v ## U
-# endif /* __INT48_C_SUFFIX__ */
+#define INT48_C(v) __INT48_C(v)
+#define UINT48_C(v) __UINT48_C(v)
 #endif /* __INT48_TYPE__ */
 
 
 #ifdef __INT40_TYPE__
-# undef __int32_c_suffix
-# undef __int16_c_suffix
-# undef  __int8_c_suffix
-# ifdef __INT40_C_SUFFIX__
-#  define INT40_C(v) __int_c(v, __INT40_C_SUFFIX__)
-#  define UINT40_C(v) __uint_c(v, __INT40_C_SUFFIX__)
-#  define __int32_c_suffix __INT40_C_SUFFIX__
-#  define __int16_c_suffix __INT40_C_SUFFIX__
-#  define __int8_c_suffix  __INT40_C_SUFFIX__
-# else
-#  define INT40_C(v) v
-#  define UINT40_C(v) v ## U
-# endif /* _

[clang] [CIR][Upstream] Local initialization for ArrayType (PR #132974)

2025-04-01 Thread Amr Hesham via cfe-commits


@@ -110,6 +110,10 @@ class CIRGenFunction : public CIRGenTypeCache {
 public:
   mlir::Value createDummyValue(mlir::Location loc, clang::QualType qt);
 
+  void emitAggExpr(const clang::Expr *e, AggValueSlot slot);

AmrDeveloper wrote:

Done, thanks

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


[clang] [Clang] add emit -Wignored-base-class-qualifiers diagnostic for cv-qualified base classes (PR #132116)

2025-04-01 Thread Lyle Dean via cfe-commits

lyledean1 wrote:

> It isn't clear what the merge conflicts are (github won't tell me for some 
> reason?) but those need fixing before we can merge this.

It was on the release notes, that's fixed now 

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


[clang] [flang] [flang] Added driver options for arrays repacking. (PR #134002)

2025-04-01 Thread Slava Zakharin via cfe-commits

https://github.com/vzakhari created 
https://github.com/llvm/llvm-project/pull/134002

Added options:
  * -f[no-]repack-arrays
  * -f[no-]stack-repack-arrays
  * -frepack-arrays-contiguity=whole/innermost


>From b936044f9a77cb717d74248cad5021b5d997d407 Mon Sep 17 00:00:00 2001
From: Slava Zakharin 
Date: Tue, 1 Apr 2025 15:55:30 -0700
Subject: [PATCH] [flang] Added driver options for arrays repacking.

Added options:
  * -f[no-]repack-arrays
  * -f[no-]stack-repack-arrays
  * -frepack-arrays-contiguity=whole/innermost
---
 clang/include/clang/Driver/Options.td | 62 ++-
 clang/lib/Driver/ToolChains/Flang.cpp | 28 ++---
 flang/docs/ArrayRepacking.md  | 19 +++---
 flang/include/flang/Lower/LoweringOptions.def |  5 ++
 flang/lib/Frontend/CompilerInvocation.cpp | 14 +
 flang/lib/Lower/ConvertVariable.cpp   |  2 +-
 .../test/Driver/frepack-arrays-contiguity.f90 | 27 
 flang/test/Driver/frepack-arrays.f90  | 24 +++
 flang/test/Driver/fstack-repack-arrays.f90| 24 +++
 flang/test/Lower/repack-arrays.f90|  8 +--
 flang/tools/bbc/bbc.cpp   | 12 +++-
 11 files changed, 198 insertions(+), 27 deletions(-)
 create mode 100644 flang/test/Driver/frepack-arrays-contiguity.f90
 create mode 100644 flang/test/Driver/frepack-arrays.f90
 create mode 100644 flang/test/Driver/fstack-repack-arrays.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 89cb03cc33b98..49a59c0417455 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6819,7 +6819,6 @@ defm real_8_real_10 : BooleanFFlag<"real-8-real-10">, 
Group;
 defm real_8_real_16 : BooleanFFlag<"real-8-real-16">, Group;
 defm real_8_real_4 : BooleanFFlag<"real-8-real-4">, Group;
 defm recursive : BooleanFFlag<"recursive">, Group;
-defm repack_arrays : BooleanFFlag<"repack-arrays">, Group;
 defm second_underscore : BooleanFFlag<"second-underscore">, 
Group;
 defm sign_zero : BooleanFFlag<"sign-zero">, Group;
 defm whole_file : BooleanFFlag<"whole-file">, Group;
@@ -6961,6 +6960,51 @@ defm unsigned : OptInFC1FFlag<"unsigned", "Enables 
UNSIGNED type">;
 def fno_automatic : Flag<["-"], "fno-automatic">, Group,
   HelpText<"Implies the SAVE attribute for non-automatic local objects in 
subprograms unless RECURSIVE">;
 
+defm repack_arrays
+: BoolOptionWithoutMarshalling<
+  "f", "repack-arrays", PosFlag,
+  NegFlag,
+  BothFlags<[], [],
+" non-contiguous assumed shape dummy arrays into "
+"contiguous memory">>,
+  DocBrief<[{Create temporary copies of non-contiguous assumed shape dummy
+arrays in subprogram prologues, and destroy them in subprotram epilogues.
+The temporary copy is initialized with values from the original array
+in the prologue, if needed. In the epilogue, the current values
+in the temporary array are copied into the original array, if needed.
+
+Accessing the contiguous temporary in the program code may result
+in faster execution comparing to accessing elements of the original array,
+when they are sparse in memory. At the same time, the overhead
+of copying values between the original and the temporary arrays
+may be significant, which may slow down some programs.
+
+Enabling array repacking may also change the behavior of certain
+programs:
+* The copy actions may introduce a data race in valid OpenACC/OpenMP programs.
+  For example, if different threads execute the same subprogram
+  with a non-contiguous assumed shape dummy array, and the different threads
+  access unrelated parts of the array, then the whole array copy
+  made in each thread will cause a data race.
+* OpenACC/OpenMP offload programs may behave incorrectly with regards
+  to the device data environment, due to the fact that the original
+  array and the temporary may have different presence status on the device.
+* ``IS_CONTIGUOUS`` intrinsic may return ``TRUE`` with the array repacking
+  enabled, whereas if would return ``FALSE`` with the repacking disabled.
+* The result of ``LOC`` intrinsic applied to an actual argument associated
+  with a non-contiguous assumed shape dummy array, may be different
+  from the result of ``LOC`` applied to the dummy array.}]>;
+
+def frepack_arrays_contiguity_EQ
+: Joined<["-"], "frepack-arrays-contiguity=">,
+  Group,
+  Values<"whole,innermost">,
+  HelpText<
+  "When -frepack-arrays is in effect, 'whole' enables "
+  "repacking for arrays that are non-contiguous in any dimension, "
+  "'innermost' enables repacking for arrays that are non-contiguous "
+  "in the innermost dimension (the default)">;
+
 defm save_main_program : BoolOptionWithoutMarshalling<"f", "save-main-program",
   PosFlag,
@@ -6974,6 +7018,22 @@ defm loop_versioning : BoolOptionWithoutMarshalling<"f", 
"version-loops-for-stri
   PosFlag,
NegF

[clang] [flang] [flang] Added driver options for arrays repacking. (PR #134002)

2025-04-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Slava Zakharin (vzakhari)


Changes

Added options:
  * -f[no-]repack-arrays
  * -f[no-]stack-repack-arrays
  * -frepack-arrays-contiguity=whole/innermost


---

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


11 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+61-1) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+19-9) 
- (modified) flang/docs/ArrayRepacking.md (+10-9) 
- (modified) flang/include/flang/Lower/LoweringOptions.def (+5) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+14) 
- (modified) flang/lib/Lower/ConvertVariable.cpp (+1-1) 
- (added) flang/test/Driver/frepack-arrays-contiguity.f90 (+27) 
- (added) flang/test/Driver/frepack-arrays.f90 (+24) 
- (added) flang/test/Driver/fstack-repack-arrays.f90 (+24) 
- (modified) flang/test/Lower/repack-arrays.f90 (+4-4) 
- (modified) flang/tools/bbc/bbc.cpp (+9-3) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 89cb03cc33b98..49a59c0417455 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6819,7 +6819,6 @@ defm real_8_real_10 : BooleanFFlag<"real-8-real-10">, 
Group;
 defm real_8_real_16 : BooleanFFlag<"real-8-real-16">, Group;
 defm real_8_real_4 : BooleanFFlag<"real-8-real-4">, Group;
 defm recursive : BooleanFFlag<"recursive">, Group;
-defm repack_arrays : BooleanFFlag<"repack-arrays">, Group;
 defm second_underscore : BooleanFFlag<"second-underscore">, 
Group;
 defm sign_zero : BooleanFFlag<"sign-zero">, Group;
 defm whole_file : BooleanFFlag<"whole-file">, Group;
@@ -6961,6 +6960,51 @@ defm unsigned : OptInFC1FFlag<"unsigned", "Enables 
UNSIGNED type">;
 def fno_automatic : Flag<["-"], "fno-automatic">, Group,
   HelpText<"Implies the SAVE attribute for non-automatic local objects in 
subprograms unless RECURSIVE">;
 
+defm repack_arrays
+: BoolOptionWithoutMarshalling<
+  "f", "repack-arrays", PosFlag,
+  NegFlag,
+  BothFlags<[], [],
+" non-contiguous assumed shape dummy arrays into "
+"contiguous memory">>,
+  DocBrief<[{Create temporary copies of non-contiguous assumed shape dummy
+arrays in subprogram prologues, and destroy them in subprotram epilogues.
+The temporary copy is initialized with values from the original array
+in the prologue, if needed. In the epilogue, the current values
+in the temporary array are copied into the original array, if needed.
+
+Accessing the contiguous temporary in the program code may result
+in faster execution comparing to accessing elements of the original array,
+when they are sparse in memory. At the same time, the overhead
+of copying values between the original and the temporary arrays
+may be significant, which may slow down some programs.
+
+Enabling array repacking may also change the behavior of certain
+programs:
+* The copy actions may introduce a data race in valid OpenACC/OpenMP programs.
+  For example, if different threads execute the same subprogram
+  with a non-contiguous assumed shape dummy array, and the different threads
+  access unrelated parts of the array, then the whole array copy
+  made in each thread will cause a data race.
+* OpenACC/OpenMP offload programs may behave incorrectly with regards
+  to the device data environment, due to the fact that the original
+  array and the temporary may have different presence status on the device.
+* ``IS_CONTIGUOUS`` intrinsic may return ``TRUE`` with the array repacking
+  enabled, whereas if would return ``FALSE`` with the repacking disabled.
+* The result of ``LOC`` intrinsic applied to an actual argument associated
+  with a non-contiguous assumed shape dummy array, may be different
+  from the result of ``LOC`` applied to the dummy array.}]>;
+
+def frepack_arrays_contiguity_EQ
+: Joined<["-"], "frepack-arrays-contiguity=">,
+  Group,
+  Values<"whole,innermost">,
+  HelpText<
+  "When -frepack-arrays is in effect, 'whole' enables "
+  "repacking for arrays that are non-contiguous in any dimension, "
+  "'innermost' enables repacking for arrays that are non-contiguous "
+  "in the innermost dimension (the default)">;
+
 defm save_main_program : BoolOptionWithoutMarshalling<"f", "save-main-program",
   PosFlag,
@@ -6974,6 +7018,22 @@ defm loop_versioning : BoolOptionWithoutMarshalling<"f", 
"version-loops-for-stri
   PosFlag,
NegFlag>;
 
+defm stack_repack_arrays
+: BoolOptionWithoutMarshalling<
+  "f", "stack-repack-arrays",
+  PosFlag,
+  NegFlag<
+  SetFalse, [], [],
+  "Allocate -frepack-arrays temporaries on the heap (default)">>,
+  DocBrief<[{Controls whether the array temporaries created under
+**-frepack-arrays** are allocated on the stack or on the heap.
+
+By default, the h

[clang] [flang] [flang] Added driver options for arrays repacking. (PR #134002)

2025-04-01 Thread Slava Zakharin via cfe-commits

https://github.com/vzakhari updated 
https://github.com/llvm/llvm-project/pull/134002

>From b936044f9a77cb717d74248cad5021b5d997d407 Mon Sep 17 00:00:00 2001
From: Slava Zakharin 
Date: Tue, 1 Apr 2025 15:55:30 -0700
Subject: [PATCH 1/2] [flang] Added driver options for arrays repacking.

Added options:
  * -f[no-]repack-arrays
  * -f[no-]stack-repack-arrays
  * -frepack-arrays-contiguity=whole/innermost
---
 clang/include/clang/Driver/Options.td | 62 ++-
 clang/lib/Driver/ToolChains/Flang.cpp | 28 ++---
 flang/docs/ArrayRepacking.md  | 19 +++---
 flang/include/flang/Lower/LoweringOptions.def |  5 ++
 flang/lib/Frontend/CompilerInvocation.cpp | 14 +
 flang/lib/Lower/ConvertVariable.cpp   |  2 +-
 .../test/Driver/frepack-arrays-contiguity.f90 | 27 
 flang/test/Driver/frepack-arrays.f90  | 24 +++
 flang/test/Driver/fstack-repack-arrays.f90| 24 +++
 flang/test/Lower/repack-arrays.f90|  8 +--
 flang/tools/bbc/bbc.cpp   | 12 +++-
 11 files changed, 198 insertions(+), 27 deletions(-)
 create mode 100644 flang/test/Driver/frepack-arrays-contiguity.f90
 create mode 100644 flang/test/Driver/frepack-arrays.f90
 create mode 100644 flang/test/Driver/fstack-repack-arrays.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 89cb03cc33b98..49a59c0417455 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6819,7 +6819,6 @@ defm real_8_real_10 : BooleanFFlag<"real-8-real-10">, 
Group;
 defm real_8_real_16 : BooleanFFlag<"real-8-real-16">, Group;
 defm real_8_real_4 : BooleanFFlag<"real-8-real-4">, Group;
 defm recursive : BooleanFFlag<"recursive">, Group;
-defm repack_arrays : BooleanFFlag<"repack-arrays">, Group;
 defm second_underscore : BooleanFFlag<"second-underscore">, 
Group;
 defm sign_zero : BooleanFFlag<"sign-zero">, Group;
 defm whole_file : BooleanFFlag<"whole-file">, Group;
@@ -6961,6 +6960,51 @@ defm unsigned : OptInFC1FFlag<"unsigned", "Enables 
UNSIGNED type">;
 def fno_automatic : Flag<["-"], "fno-automatic">, Group,
   HelpText<"Implies the SAVE attribute for non-automatic local objects in 
subprograms unless RECURSIVE">;
 
+defm repack_arrays
+: BoolOptionWithoutMarshalling<
+  "f", "repack-arrays", PosFlag,
+  NegFlag,
+  BothFlags<[], [],
+" non-contiguous assumed shape dummy arrays into "
+"contiguous memory">>,
+  DocBrief<[{Create temporary copies of non-contiguous assumed shape dummy
+arrays in subprogram prologues, and destroy them in subprotram epilogues.
+The temporary copy is initialized with values from the original array
+in the prologue, if needed. In the epilogue, the current values
+in the temporary array are copied into the original array, if needed.
+
+Accessing the contiguous temporary in the program code may result
+in faster execution comparing to accessing elements of the original array,
+when they are sparse in memory. At the same time, the overhead
+of copying values between the original and the temporary arrays
+may be significant, which may slow down some programs.
+
+Enabling array repacking may also change the behavior of certain
+programs:
+* The copy actions may introduce a data race in valid OpenACC/OpenMP programs.
+  For example, if different threads execute the same subprogram
+  with a non-contiguous assumed shape dummy array, and the different threads
+  access unrelated parts of the array, then the whole array copy
+  made in each thread will cause a data race.
+* OpenACC/OpenMP offload programs may behave incorrectly with regards
+  to the device data environment, due to the fact that the original
+  array and the temporary may have different presence status on the device.
+* ``IS_CONTIGUOUS`` intrinsic may return ``TRUE`` with the array repacking
+  enabled, whereas if would return ``FALSE`` with the repacking disabled.
+* The result of ``LOC`` intrinsic applied to an actual argument associated
+  with a non-contiguous assumed shape dummy array, may be different
+  from the result of ``LOC`` applied to the dummy array.}]>;
+
+def frepack_arrays_contiguity_EQ
+: Joined<["-"], "frepack-arrays-contiguity=">,
+  Group,
+  Values<"whole,innermost">,
+  HelpText<
+  "When -frepack-arrays is in effect, 'whole' enables "
+  "repacking for arrays that are non-contiguous in any dimension, "
+  "'innermost' enables repacking for arrays that are non-contiguous "
+  "in the innermost dimension (the default)">;
+
 defm save_main_program : BoolOptionWithoutMarshalling<"f", "save-main-program",
   PosFlag,
@@ -6974,6 +7018,22 @@ defm loop_versioning : BoolOptionWithoutMarshalling<"f", 
"version-loops-for-stri
   PosFlag,
NegFlag>;
 
+defm stack_repack_arrays
+: BoolOptionWithoutMarshalling<
+  "f", "stack-repack-arrays",
+ 

[clang] Fixes: Can not use C99 function names as variable names in C89 (PR #129979)

2025-04-01 Thread A. Jiang via cfe-commits


@@ -135,6 +137,24 @@ bool Builtin::Context::isBuiltinFunc(llvm::StringRef 
FuncName) {
   return false;
 }
 
+static bool isSymbolAvailableInC89(const llvm::StringTable &Strings,
+   const Builtin::Info &BuiltinInfo) {
+
+  auto NameStr = Strings[BuiltinInfo.Offsets.Name];
+
+  if (NameStr.starts_with("__builtin_")) {
+return true;
+  }
+
+  // FIXME: add other C89 symbols here
+  if (NameStr == "log" || NameStr == "va_start" || NameStr == "va_arg" ||
+  NameStr == "va_end") {
+return true;
+  }

frederick-vs-ja wrote:

The list would be very long, see https://port70.net/~nsz/c/c89/c89-draft.html. 
Perhaps we should add a `.def` file for this.

https://github.com/llvm/llvm-project/pull/129979
___
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-01 Thread Ian Anderson via cfe-commits

https://github.com/ian-twilightcoder created 
https://github.com/llvm/llvm-project/pull/134005

Whether the SDK supports builtin modules is a property of the SDK itself, and 
really has nothing to do with the target. This was already worked around for 
Mac Catalyst, but there are some other more esoteric non-obvious target-to-sdk 
mappings that aren't handled. Have the SDK parse its OS out of CanonicalName 
and use that instead of the target to determine if builtin modules are 
supported.

>From dc2199388197063189d76ded13cd48fcd238 Mon Sep 17 00:00:00 2001
From: Ian Anderson 
Date: Tue, 1 Apr 2025 16:24:30 -0700
Subject: [PATCH] [clang][modules] Determine if the SDK supports builtin
 modules independent of the target

Whether the SDK supports builtin modules is a property of the SDK itself, and 
really has nothing to do with the target. This was already worked around for 
Mac Catalyst, but there are some other more esoteric non-obvious target-to-sdk 
mappings that aren't handled. Have the SDK parse its OS out of CanonicalName 
and use that instead of the target to determine if builtin modules are 
supported.
---
 clang/include/clang/Basic/DarwinSDKInfo.h |  6 +-
 clang/lib/Basic/DarwinSDKInfo.cpp | 26 +++-
 clang/lib/Driver/ToolChains/Darwin.cpp| 60 +--
 .../Inputs/DriverKit23.0.sdk/SDKSettings.json |  2 +-
 .../Inputs/MacOSX10.14.sdk/SDKSettings.json   |  2 +-
 .../SDKSettings.json  |  1 +
 .../Inputs/MacOSX15.0.sdk/SDKSettings.json|  2 +-
 .../Inputs/MacOSX15.1.sdk/SDKSettings.json|  2 +-
 .../Inputs/WatchOS6.0.sdk/SDKSettings.json|  2 +-
 .../Inputs/iPhoneOS13.0.sdk/SDKSettings.json  |  2 +-
 .../darwin-ld-platform-version-watchos.c  |  4 +-
 .../Inputs/MacOSX13.0.sdk/SDKSettings.json|  1 +
 .../Inputs/AppleTVOS15.0.sdk/SDKSettings.json |  1 +
 .../Inputs/MacOSX11.0.sdk/SDKSettings.json|  1 +
 .../Inputs/WatchOS7.0.sdk/SDKSettings.json|  1 +
 15 files changed, 72 insertions(+), 41 deletions(-)

diff --git a/clang/include/clang/Basic/DarwinSDKInfo.h 
b/clang/include/clang/Basic/DarwinSDKInfo.h
index db20b968a898e..bc122c7d21c72 100644
--- a/clang/include/clang/Basic/DarwinSDKInfo.h
+++ b/clang/include/clang/Basic/DarwinSDKInfo.h
@@ -143,16 +143,19 @@ class DarwinSDKInfo {
 
   DarwinSDKInfo(
   VersionTuple Version, VersionTuple MaximumDeploymentTarget,
+  llvm::Triple::OSType OS,
   llvm::DenseMap>
   VersionMappings =
   llvm::DenseMap>())
   : Version(Version), MaximumDeploymentTarget(MaximumDeploymentTarget),
-VersionMappings(std::move(VersionMappings)) {}
+OS(OS), VersionMappings(std::move(VersionMappings)) {}
 
   const llvm::VersionTuple &getVersion() const { return Version; }
 
+  const llvm::Triple::OSType &getOS() const { return OS; }
+
   // Returns the optional, target-specific version mapping that maps from one
   // target to another target.
   //
@@ -177,6 +180,7 @@ class DarwinSDKInfo {
 private:
   VersionTuple Version;
   VersionTuple MaximumDeploymentTarget;
+  llvm::Triple::OSType OS;
   // Need to wrap the value in an optional here as the value has to be default
   // constructible, and std::unique_ptr doesn't like DarwinSDKInfo being
   // Optional as Optional is trying to copy it in emplace.
diff --git a/clang/lib/Basic/DarwinSDKInfo.cpp 
b/clang/lib/Basic/DarwinSDKInfo.cpp
index 00aa5f9e63cd3..eaf600d8ffed3 100644
--- a/clang/lib/Basic/DarwinSDKInfo.cpp
+++ b/clang/lib/Basic/DarwinSDKInfo.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang/Basic/DarwinSDKInfo.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -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.
+  auto CanonicalName = Obj.getString("CanonicalName");
+  if (!CanonicalName)
+return llvm::Triple::UnknownOS;
+  size_t VersionStart = CanonicalName->find_first_of("0123456789");
+  StringRef XcodePlatform = CanonicalName->slice(0, VersionStart);
+  return llvm::StringSwitch(XcodePlatform)
+  .Case("macosx", llvm::Triple::MacOSX)
+  .Case("iphoneos", llvm::Triple::IOS)
+  .Case("iphonesimulator", llvm::Triple::IOS)
+  .Case("appletvos", llvm::Triple::TvOS)
+  .Case("appletvsimulator", llvm::Triple::TvOS)
+  .Case("watchos", llvm::Triple::WatchOS)
+  .Case("watchsimulator", llvm::Triple::WatchOS)
+  .Case("xros", llvm::Triple::XROS)
+  .Case("xrsimulator", llvm::Triple::XROS)
+  .Case("driverkit", llvm::Triple::DriverKit)
+  .Default(llvm::Triple::UnknownOS);
+}
+
 static std::optional getVersi

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

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

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/132748

>From b50ea7d744280bdfb97f0abaeb10d088d502e81a Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sat, 22 Mar 2025 16:03:04 -0300
Subject: [PATCH 1/4] [clang] Track final substitution for
 SubstTemplateTemplateParm nodes

---
 clang/include/clang/AST/ASTContext.h   |  9 +
 clang/include/clang/AST/PropertiesBase.td  |  3 ++-
 clang/include/clang/AST/TemplateName.h | 17 -
 clang/include/clang/AST/Type.h |  3 ++-
 clang/lib/AST/ASTContext.cpp   |  6 +++---
 clang/lib/AST/ASTImporter.cpp  |  2 +-
 clang/lib/AST/TemplateName.cpp |  6 --
 clang/lib/AST/TextNodeDumper.cpp   |  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  8 ++--
 9 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a24f30815e6b9..fca41fbe38812 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -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/PropertiesBase.td 
b/clang/include/clang/AST/PropertiesBase.td
index 5171555008ac9..0e360de16fdd6 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -730,8 +730,9 @@ let Class = PropertyTypeCase in {
   def : Property<"packIndex", Optional> {
 let Read = [{ parm->getPackIndex() }];
   }
+  def : Property<"final", Bool> { let Read = [{ parm->getFinal() }]; }
   def : Creator<[{
-return ctx.getSubstTemplateTemplateParm(replacement, associatedDecl, 
index, packIndex);
+return ctx.getSubstTemplateTemplateParm(replacement, associatedDecl, 
index, packIndex, final);
   }]>;
 }
 let Class = PropertyTypeCase in 
{
diff --git a/clang/include/clang/AST/TemplateName.h 
b/clang/include/clang/AST/TemplateName.h
index 1a56133b72d6e..ece2afcfa72ab 100644
--- a/clang/include/clang/AST/TemplateName.h
+++ b/clang/include/clang/AST/TemplateName.h
@@ -414,9 +414,11 @@ class SubstTemplateTemplateParmStorage
 
   SubstTemplateTemplateParmStorage(TemplateName Replacement,
Decl *AssociatedDecl, unsigned Index,
-   std::optional PackIndex)
+   std::optional PackIndex,
+   bool Final)
   : UncommonTemplateNameStorage(SubstTemplateTemplateParm, Index,
-PackIndex ? *PackIndex + 1 : 0),
+((PackIndex ? *PackIndex + 1 : 0) << 1) |
+Final),
 Replacement(Replacement), AssociatedDecl(AssociatedDecl) {
 assert(AssociatedDecl != nullptr);
   }
@@ -430,10 +432,15 @@ class SubstTemplateTemplateParmStorage
   /// This should match the result of `getParameter()->getIndex()`.
   unsigned getIndex() const { return Bits.Index; }
 
+  // This substitution is Final, which means the substitution is fully
+  // sugared: it doesn't need to be resugared later.
+  bool getFinal() const { return Bits.Data & 1; }
+
   std::optional getPackIndex() const {
-if (Bits.Data == 0)
+auto Data = Bits.Data >> 1;
+if (Data == 0)
   return std::nullopt;
-return Bits.Data - 1;
+return Data - 1;
   }
 
   TemplateTemplateParmDecl *getParameter() const;
@@ -443,7 +450,7 @@ class SubstTemplateTemplateParmStorage
 
   static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Replacement,
   Decl *AssociatedDecl, unsigned Index,
-  std::optional PackIndex);
+  std::optional PackIndex, bool Final);
 };
 
 class DeducedTemplateStorage : public UncommonTemplateNameStorage,
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index cfd417068abb7..4f33215fd9724 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -6488,7 +6488,8 @@ class SubstTemplateTypeParmPackType : public Type, public 
llvm::FoldingSetNode

[clang] 97dcbde - Revert "[clang-format] Handle C++ keywords in other languages better (#132941)"

2025-04-01 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2025-04-01T18:59:12-07:00
New Revision: 97dcbdef6089175c45e14fcbcf5c88b10233a79a

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

LOG: Revert "[clang-format] Handle C++ keywords in other languages better 
(#132941)"

This reverts commit ab7cee8a0ecf29fdb47c64c8d431a694d63390d2 which had
formatting errors.

Added: 


Modified: 
clang/lib/Format/FormatTokenLexer.cpp
clang/unittests/Format/FormatTestJS.cpp
clang/unittests/Format/FormatTestJava.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 014b10b206d90..eed54a11684b5 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -1306,12 +1306,15 @@ FormatToken *FormatTokenLexer::getNextToken() {
 FormatTok->isOneOf(tok::kw_struct, tok::kw_union, tok::kw_delete,
tok::kw_operator)) {
   FormatTok->Tok.setKind(tok::identifier);
+  FormatTok->Tok.setIdentifierInfo(nullptr);
 } else if (Style.isJavaScript() &&
FormatTok->isOneOf(tok::kw_struct, tok::kw_union,
   tok::kw_operator)) {
   FormatTok->Tok.setKind(tok::identifier);
+  FormatTok->Tok.setIdentifierInfo(nullptr);
 } else if (Style.isTableGen() && !Keywords.isTableGenKeyword(*FormatTok)) {
   FormatTok->Tok.setKind(tok::identifier);
+  FormatTok->Tok.setIdentifierInfo(nullptr);
 }
   } else if (FormatTok->is(tok::greatergreater)) {
 FormatTok->Tok.setKind(tok::greater);

diff  --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index 3dae67fbcdfcb..78c9f887a159b 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -828,18 +828,12 @@ TEST_F(FormatTestJS, AsyncFunctions) {
"}  ");
   // clang-format must not insert breaks between async and function, otherwise
   // automatic semicolon insertion may trigger (in particular in a class body).
-  auto Style = getGoogleJSStyleWithColumns(10);
   verifyFormat("async function\n"
"hello(\n"
"myparamnameiswaytoolng) {\n"
"}",
"async function hello(myparamnameiswaytoolng) {}",
-   Style);
-  verifyFormat("async function\n"
-   "union(\n"
-   "myparamnameiswaytoolng) {\n"
-   "}",
-   Style);
+   getGoogleJSStyleWithColumns(10));
   verifyFormat("class C {\n"
"  async hello(\n"
"  myparamnameiswaytoolng) {\n"
@@ -847,7 +841,7 @@ TEST_F(FormatTestJS, AsyncFunctions) {
"}",
"class C {\n"
"  async hello(myparamnameiswaytoolng) {} }",
-   Style);
+   getGoogleJSStyleWithColumns(10));
   verifyFormat("async function* f() {\n"
"  yield fetch(x);\n"
"}");
@@ -1344,16 +1338,15 @@ TEST_F(FormatTestJS, 
WrapRespectsAutomaticSemicolonInsertion) {
   // The following statements must not wrap, as otherwise the program meaning
   // would change due to automatic semicolon insertion.
   // See http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1.
-  auto Style =getGoogleJSStyleWithColumns(10);
-  verifyFormat("return a;", Style);
-  verifyFormat("yield a;", Style);
-  verifyFormat("return /* hello! */ a;", Style);
-  verifyFormat("continue a;", Style);
-  verifyFormat("continue /* hello! */ a;", Style);
-  verifyFormat("break a;", Style);
-  verifyFormat("throw a;", Style);
-  verifyFormat("a++;", Style);
-  verifyFormat("a--;", Style);
+  verifyFormat("return a;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("yield a;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("return /* hello! */ a;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("continue a;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("continue /* hello! */ a;", 
getGoogleJSStyleWithColumns(10));
+  verifyFormat("break a;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("throw a;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("a++;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("a--;", getGoogleJSStyleWithColumns(10));
   verifyFormat("return [\n"
"  aaa\n"
"];",
@@ -1373,13 +1366,12 @@ TEST_F(FormatTestJS, 
WrapRespectsAutomaticSemicolonInsertion) {
   // Ideally the foo() bit should be indented relative to the async function().
   verifyFormat("async function\n"
"foo() {}",
-   Style);
-  verifyFormat("await theReckoning;", Style);
-  verifyFormat("some['

[clang] [llvm] Define LLVM_ABI and CLANG_ABI for __EMSCRIPTEN__ builds (PR #131578)

2025-04-01 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#133996

https://github.com/llvm/llvm-project/pull/131578
___
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-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ian Anderson (ian-twilightcoder)


Changes

Whether the SDK supports builtin modules is a property of the SDK itself, and 
really has nothing to do with the target. This was already worked around for 
Mac Catalyst, but there are some other more esoteric non-obvious target-to-sdk 
mappings that aren't handled. Have the SDK parse its OS out of CanonicalName 
and use that instead of the target to determine if builtin modules are 
supported.

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


15 Files Affected:

- (modified) clang/include/clang/Basic/DarwinSDKInfo.h (+5-1) 
- (modified) clang/lib/Basic/DarwinSDKInfo.cpp (+25-1) 
- (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+29-31) 
- (modified) clang/test/Driver/Inputs/DriverKit23.0.sdk/SDKSettings.json (+1-1) 
- (modified) clang/test/Driver/Inputs/MacOSX10.14.sdk/SDKSettings.json (+1-1) 
- (modified) 
clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk/SDKSettings.json (+1) 
- (modified) clang/test/Driver/Inputs/MacOSX15.0.sdk/SDKSettings.json (+1-1) 
- (modified) clang/test/Driver/Inputs/MacOSX15.1.sdk/SDKSettings.json (+1-1) 
- (modified) clang/test/Driver/Inputs/WatchOS6.0.sdk/SDKSettings.json (+1-1) 
- (modified) clang/test/Driver/Inputs/iPhoneOS13.0.sdk/SDKSettings.json (+1-1) 
- (modified) clang/test/Driver/darwin-ld-platform-version-watchos.c (+2-2) 
- (modified) clang/test/InstallAPI/Inputs/MacOSX13.0.sdk/SDKSettings.json (+1) 
- (modified) clang/test/Sema/Inputs/AppleTVOS15.0.sdk/SDKSettings.json (+1) 
- (modified) clang/test/Sema/Inputs/MacOSX11.0.sdk/SDKSettings.json (+1) 
- (modified) clang/test/Sema/Inputs/WatchOS7.0.sdk/SDKSettings.json (+1) 


``diff
diff --git a/clang/include/clang/Basic/DarwinSDKInfo.h 
b/clang/include/clang/Basic/DarwinSDKInfo.h
index db20b968a898e..bc122c7d21c72 100644
--- a/clang/include/clang/Basic/DarwinSDKInfo.h
+++ b/clang/include/clang/Basic/DarwinSDKInfo.h
@@ -143,16 +143,19 @@ class DarwinSDKInfo {
 
   DarwinSDKInfo(
   VersionTuple Version, VersionTuple MaximumDeploymentTarget,
+  llvm::Triple::OSType OS,
   llvm::DenseMap>
   VersionMappings =
   llvm::DenseMap>())
   : Version(Version), MaximumDeploymentTarget(MaximumDeploymentTarget),
-VersionMappings(std::move(VersionMappings)) {}
+OS(OS), VersionMappings(std::move(VersionMappings)) {}
 
   const llvm::VersionTuple &getVersion() const { return Version; }
 
+  const llvm::Triple::OSType &getOS() const { return OS; }
+
   // Returns the optional, target-specific version mapping that maps from one
   // target to another target.
   //
@@ -177,6 +180,7 @@ class DarwinSDKInfo {
 private:
   VersionTuple Version;
   VersionTuple MaximumDeploymentTarget;
+  llvm::Triple::OSType OS;
   // Need to wrap the value in an optional here as the value has to be default
   // constructible, and std::unique_ptr doesn't like DarwinSDKInfo being
   // Optional as Optional is trying to copy it in emplace.
diff --git a/clang/lib/Basic/DarwinSDKInfo.cpp 
b/clang/lib/Basic/DarwinSDKInfo.cpp
index 00aa5f9e63cd3..eaf600d8ffed3 100644
--- a/clang/lib/Basic/DarwinSDKInfo.cpp
+++ b/clang/lib/Basic/DarwinSDKInfo.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang/Basic/DarwinSDKInfo.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -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.
+  auto CanonicalName = Obj.getString("CanonicalName");
+  if (!CanonicalName)
+return llvm::Triple::UnknownOS;
+  size_t VersionStart = CanonicalName->find_first_of("0123456789");
+  StringRef XcodePlatform = CanonicalName->slice(0, VersionStart);
+  return llvm::StringSwitch(XcodePlatform)
+  .Case("macosx", llvm::Triple::MacOSX)
+  .Case("iphoneos", llvm::Triple::IOS)
+  .Case("iphonesimulator", llvm::Triple::IOS)
+  .Case("appletvos", llvm::Triple::TvOS)
+  .Case("appletvsimulator", llvm::Triple::TvOS)
+  .Case("watchos", llvm::Triple::WatchOS)
+  .Case("watchsimulator", llvm::Triple::WatchOS)
+  .Case("xros", llvm::Triple::XROS)
+  .Case("xrsimulator", llvm::Triple::XROS)
+  .Case("driverkit", llvm::Triple::DriverKit)
+  .Default(llvm::Triple::UnknownOS);
+}
+
 static std::optional getVersionKey(const llvm::json::Object &Obj,
  StringRef Key) {
   auto Value = Obj.getString(Key);
@@ -82,6 +105,7 @@ DarwinSDKInfo::parseDarwinSDKSettingsJSON(const 
llvm::json::Object *Obj) {
   getVersionKey(*Obj, "MaximumDeploymentTarget");
   if (!Max

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

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

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

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.

>From 91eeaf02336e539f14dcb0a79ff15dbe8befe6f1 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Wed, 2 Apr 2025 02:47:42 +0100
Subject: [PATCH] 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"))
+__bui

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

2025-04-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Alex Voicu (AlexVlx)


Changes

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.

---

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


17 Files Affected:

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


``diff
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_ttrac

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

2025-04-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alex Voicu (AlexVlx)


Changes

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.

---

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


17 Files Affected:

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


``diff
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_im

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

2025-04-01 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 h,c,cpp -- 
clang/test/CodeGen/amdgpu-builtin-cpu-is.c 
clang/test/CodeGen/amdgpu-builtin-is-invocable.c 
clang/test/CodeGen/amdgpu-feature-builtins-invalid-use.cpp 
llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp 
clang/lib/Basic/Targets/SPIR.cpp clang/lib/Basic/Targets/SPIR.h 
clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp clang/lib/Sema/SemaExpr.cpp 
llvm/lib/Target/AMDGPU/AMDGPU.h llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp 
b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index 7b1a38151..8ad1ab74f 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -292,8 +292,8 @@ static Value *GetOrInsertAMDGPUPredicate(CodeGenFunction 
&CGF, Twine Name) {
   P->setConstant(true);
   P->setExternallyInitialized(true);
 
-  return CGF.Builder.CreateLoad(RawAddress(P, PTy, CharUnits::One(),
-   KnownNonNull));
+  return CGF.Builder.CreateLoad(
+  RawAddress(P, PTy, CharUnits::One(), KnownNonNull));
 }
 
 Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
@@ -600,7 +600,7 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_processor_is: {
 assert(CGM.getTriple().isSPIRV() &&
"__builtin_amdgcn_processor_is should never reach CodeGen for "
- "concrete targets!");
+   "concrete targets!");
 StringRef Proc = cast(E->getArg(0))->getString();
 return GetOrInsertAMDGPUPredicate(*this, "llvm.amdgcn.is." + Proc);
   }
@@ -609,7 +609,7 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
"__builtin_amdgcn_is_invocable should never reach CodeGen for "
"concrete targets!");
 auto FD = cast(
-  cast(E->getArg(0))->getReferencedDeclOfCallee());
+cast(E->getArg(0))->getReferencedDeclOfCallee());
 StringRef RF =
 getContext().BuiltinInfo.getRequiredFeatures(FD->getBuiltinID());
 return GetOrInsertAMDGPUPredicate(*this, "llvm.amdgcn.has." + RF);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 24f5262ab..bd0183ae4 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -20549,14 +20549,16 @@ static bool ValidateAMDGPUPredicateBI(Sema &Sema, 
CallExpr *CE) {
 (!Sema.getASTContext().getAuxTargetInfo() ||
  !Sema.getASTContext().getAuxTargetInfo()->isValidCPUName(N))) {
   Sema.Diag(CE->getExprLoc(),
-diag::err_amdgcn_processor_is_arg_invalid_value) << N;
+diag::err_amdgcn_processor_is_arg_invalid_value)
+  << N;
   return false;
 }
   } else {
 auto Arg = CE->getArg(0);
 if (!Arg || Arg->getType() != Sema.getASTContext().BuiltinFnTy) {
   Sema.Diag(CE->getExprLoc(),
-diag::err_amdgcn_is_invocable_arg_invalid_value) << Arg;
+diag::err_amdgcn_is_invocable_arg_invalid_value)
+  << Arg;
   return false;
 }
   }
@@ -20568,10 +20570,9 @@ static Expr *MaybeHandleAMDGPUPredicateBI(Sema &Sema, 
Expr *E, bool &Invalid) {
   if (auto UO = dyn_cast(E)) {
 auto SE = dyn_cast(UO->getSubExpr());
 if (IsAMDGPUPredicateBI(SE)) {
-  assert(
-UO->getOpcode() == UnaryOperator::Opcode::UO_LNot &&
-"__builtin_amdgcn_processor_is and __builtin_amdgcn_is_invocable "
-  "can only be used as operands of logical ops!");
+  assert(UO->getOpcode() == UnaryOperator::Opcode::UO_LNot &&
+ "__builtin_amdgcn_processor_is and __builtin_amdgcn_is_invocable "
+ "can only be used as operands of logical ops!");
 
   if (!ValidateAMDGPUPredicateBI(Sema, SE)) {
 Invalid = true;
@@ -20588,10 +20589,9 @@ static Expr *MaybeHandleAMDGPUPredicateBI(Sema &Sema, 
Expr *E, bool &Invalid) {
 auto LHS = dyn_cast(BO->getLHS());
 auto RHS = dyn_cast(BO->getRHS());
 if (IsAMDGPUPredicateBI(LHS) && IsAMDGPUPredicateBI(RHS)) {
-  assert(
-  BO->isLogicalOp() &&
-  "__builtin_amdgcn_processor_is and __builtin_amdgcn_is_invocable "
-"can only be used as operands of logical ops!");
+  assert(BO->isLogicalOp() &&
+ "__builtin_amdgcn_processor_is and __builtin_amdgcn_is_invocable "
+ "can only be used as operands of logical ops!");
 
   if (!ValidateAMDGPUPredicateBI(Sema, LHS) ||
   !ValidateAMDGPUPredicateBI(Sema, RHS)) {
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp
index 125051c6a..77084de61 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUEx

[clang] 2f25345 - [clang] fix missing initialization msan failure

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

Author: Matheus Izvekov
Date: 2025-04-01T21:06:38-03:00
New Revision: 2f25345670081f1ca460ea3f42a0585ef3f1e877

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

LOG: [clang] fix missing initialization msan failure

fixes msan failure reported here: 
https://lab.llvm.org/buildbot/#/builders/94/builds/5821/steps/17/logs/stdio

This was a regression introduced here: 
https://github.com/llvm/llvm-project/pull/133610

Added: 


Modified: 
clang/lib/Sema/SemaCXXScopeSpec.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index 545da5c295832..ea7936b0e5b8f 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -873,6 +873,7 @@ bool Sema::ActOnCXXNestedNameSpecifier(Scope *S,
 DependentTemplateSpecializationTypeLoc SpecTL
   = Builder.push(T);
 SpecTL.setElaboratedKeywordLoc(SourceLocation());
+SpecTL.setQualifierLoc(NestedNameSpecifierLoc());
 SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
 SpecTL.setTemplateNameLoc(TemplateNameLoc);
 SpecTL.setLAngleLoc(LAngleLoc);



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


[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-04-01 Thread via cfe-commits

PeterChou1 wrote:

> Any progress, @PeterChou1 ?

Sorry for the delay, I am currently trying to fix the bugs associated with this 
branch, I should have something ready for review by tomorrow

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


[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2025-04-01 Thread Trevor Gross via cfe-commits

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


[clang] ad1ca5f - [clang] Concepts: support pack expansions for type constraints (#132626)

2025-04-01 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2025-04-01T21:11:56-03:00
New Revision: ad1ca5f4a2bc09f99fd82e5444f5da37c2985e97

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

LOG: [clang] Concepts: support pack expansions for type constraints (#132626)

This reverts an earlier attempt
(adb0d8ddceb143749c519d14b8b31b481071da77 and
50e5411e4247421fd606f0a206682fcdf0303ae3) to support these expansions,
which was limited to type arguments and which subverted the purpose
of SubstTemplateTypeParmType.

This propagates the ArgumentPackSubstitutionIndex along with the
AssociatedConstraint, so that the pack expansion works, without
needing any new transforms or otherwise any changes to the template
instantiation process.

This keeps the tests from the reverted commits, and adds a few more
showing the new solution also works for NTTPs.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ASTConcept.h
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclTemplate.h
clang/include/clang/AST/PropertiesBase.td
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/SemaConcept.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/DeclTemplate.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaCodeComplete.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
clang/test/SemaCXX/fold_lambda_with_variadics.cpp
clang/unittests/AST/SourceLocationTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
index ea4d99586c711..fb82efb4dd211 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
@@ -356,7 +356,7 @@ static std::vector handleReturnType(const 
FunctionDecl *Function,
   if (!TypeText)
 return {};
 
-  SmallVector ExistingConstraints;
+  SmallVector ExistingConstraints;
   Function->getAssociatedConstraints(ExistingConstraints);
   if (!ExistingConstraints.empty()) {
 // FIXME - Support adding new constraints to existing ones. Do we need to
@@ -404,7 +404,7 @@ handleTrailingTemplateType(const FunctionTemplateDecl 
*FunctionTemplate,
   if (!ConditionText)
 return {};
 
-  SmallVector ExistingConstraints;
+  SmallVector ExistingConstraints;
   Function->getAssociatedConstraints(ExistingConstraints);
   if (!ExistingConstraints.empty()) {
 // FIXME - Support adding new constraints to existing ones. Do we need to

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c3b64d84a1b1c..c4e82678949ff 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -370,6 +370,9 @@ Bug Fixes to C++ Support
 - Clang now uses the parameter location for abbreviated function templates in 
``extern "C"``. (#GH46386)
 - Clang will emit an error instead of crash when use co_await or co_yield in
   C++26 braced-init-list template parameter initialization. (#GH78426)
+- Improved fix for an issue with pack expansions of type constraints, where 
this
+  now also works if the constraint has non-type or template template 
parameters.
+  (#GH131798)
 - Fixes matching of nested template template parameters. (#GH130362)
 - Correctly diagnoses template template paramters which have a pack parameter
   not in the last position.

diff  --git a/clang/include/clang/AST/ASTConcept.h 
b/clang/include/clang/AST/ASTConcept.h
index 00500e214f4ce..f89899c3ea7b1 100644
--- a/clang/include/clang/AST/ASTConcept.h
+++ b/clang/include/clang/AST/ASTConcept.h
@@ -229,12 +229,15 @@ class TypeConstraint {
   /// type-constraint.
   Expr *ImmediatelyDeclaredConstraint = nullptr;
   ConceptReference *ConceptRef;
+  int ArgumentPackSubstitutionIndex;
 
 public:
   TypeConstraint(ConceptReference *ConceptRef,
- Expr *ImmediatelyDeclaredConstraint)
+ Expr *ImmediatelyDeclaredConstraint,
+ int ArgumentPackSubstitutionIndex)
   : ImmediatelyDeclaredConstraint(ImmediatelyDeclaredConstraint),
-ConceptRef(ConceptRef) {}
+Conce

[clang] [clang-tools-extra] [clang] Concepts: support pack expansions for type constraints (PR #132626)

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

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/132626
___
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-01 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
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-tools-extra] [clang] Track final substitution for Subst* AST nodes (PR #132748)

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

https://github.com/mizvekov edited 
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] Fixes: Can not use C99 function names as variable names in C89 (PR #129979)

2025-04-01 Thread Vinay Deshmukh via cfe-commits

vinay-deshmukh wrote:

> @frederick-vs-ja
> 
> Any suggestions on how to go about making further progress on this one? Sort 
> of stuck right now.


@frederick-vs-ja bump


https://github.com/llvm/llvm-project/pull/129979
___
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-01 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/3] 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] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-01 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/2] 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 cbrt to the CLC library; vectorize (PR #133940)

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


@@ -0,0 +1,135 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#if __CLC_FPSIZE == 32
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_cbrt(__CLC_GENTYPE x) {
+  __CLC_UINTN xi = __CLC_AS_UINTN(x);
+  __CLC_UINTN axi = __CLC_AS_UINTN(__clc_fabs(x));
+  __CLC_UINTN xsign = axi ^ xi;
+  xi = axi;
+
+  __CLC_INTN m = __CLC_AS_INTN(xi >> EXPSHIFTBITS_SP32) - EXPBIAS_SP32;
+
+  // Treat subnormals
+  __CLC_UINTN xisub = __CLC_AS_UINTN(__CLC_AS_GENTYPE(xi | 0x3f80) - 1.0f);
+  __CLC_INTN msub = __CLC_AS_INTN(xisub >> EXPSHIFTBITS_SP32) - 253;
+  __CLC_INTN c = m == -127;
+  xi = c ? xisub : xi;
+  m = c ? msub : m;

arsenm wrote:

I think this is frexp again 

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] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

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

https://github.com/jhuber6 commented:

Very cool, in general I'm a fan of being able to use LLVM-IR as a more general 
target. We already hack around these things in practice, so I think it's only 
beneficial to formalize is in a more correct way, even if LLVM-IR wasn't 
'strictly' intended to be this kind of serialization format.

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-01 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 edited 
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] [Sema] Use llvm::erase_if (NFC) (PR #134017)

2025-04-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/lib/Sema/TreeTransform.h (+4-4) 


``diff
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index e455b225d7f49..916b8e2735cd0 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -11963,10 +11963,10 @@ void 
OpenACCClauseTransform::VisitAttachClause(
   llvm::SmallVector VarList = VisitVarList(C.getVarList());
 
   // Ensure each var is a pointer type.
-  VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
+  llvm::erase_if(VarList, [&](Expr *E) {
 return Self.getSema().OpenACC().CheckVarIsPointerType(
 OpenACCClauseKind::Attach, E);
-  }), VarList.end());
+  });
 
   ParsedClause.setVarListDetails(VarList,
  /*IsReadOnly=*/false, /*IsZero=*/false);
@@ -12026,10 +12026,10 @@ void 
OpenACCClauseTransform::VisitDevicePtrClause(
   llvm::SmallVector VarList = VisitVarList(C.getVarList());
 
   // Ensure each var is a pointer type.
-  VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
+  llvm::erase_if(VarList, [&](Expr *E) {
 return Self.getSema().OpenACC().CheckVarIsPointerType(
 OpenACCClauseKind::DevicePtr, E);
-  }), VarList.end());
+  });
 
   ParsedClause.setVarListDetails(VarList,
  /*IsReadOnly=*/false, /*IsZero=*/false);

``




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] [Sema] Use llvm::erase_if (NFC) (PR #134017)

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

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/134017

None

>From 19a4d1d3daa035a37214d48f74651b1d64621efe Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 30 Mar 2025 11:31:56 -0700
Subject: [PATCH] [Sema] Use llvm::erase_if (NFC)

---
 clang/lib/Sema/TreeTransform.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index e455b225d7f49..916b8e2735cd0 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -11963,10 +11963,10 @@ void 
OpenACCClauseTransform::VisitAttachClause(
   llvm::SmallVector VarList = VisitVarList(C.getVarList());
 
   // Ensure each var is a pointer type.
-  VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
+  llvm::erase_if(VarList, [&](Expr *E) {
 return Self.getSema().OpenACC().CheckVarIsPointerType(
 OpenACCClauseKind::Attach, E);
-  }), VarList.end());
+  });
 
   ParsedClause.setVarListDetails(VarList,
  /*IsReadOnly=*/false, /*IsZero=*/false);
@@ -12026,10 +12026,10 @@ void 
OpenACCClauseTransform::VisitDevicePtrClause(
   llvm::SmallVector VarList = VisitVarList(C.getVarList());
 
   // Ensure each var is a pointer type.
-  VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
+  llvm::erase_if(VarList, [&](Expr *E) {
 return Self.getSema().OpenACC().CheckVarIsPointerType(
 OpenACCClauseKind::DevicePtr, E);
-  }), VarList.end());
+  });
 
   ParsedClause.setVarListDetails(VarList,
  /*IsReadOnly=*/false, /*IsZero=*/false);

___
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-01 Thread Alex Voicu 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
+
+// Test that, depending on triple and, if applicable, target-cpu, one of three
+// things happens:
+//1) for gfx900 we emit an empty kernel (concrete target, lacks feature)
+//2) for gfx1010 we emit a call to trap (concrete target, has feature)
+//3) for AMDGCNSPIRV we emit llvm.amdgcn.has.gfx10-insts as a constant
+//   externally initialised bool global, and load from it to provide the
+//   condition to a br (abstract target)
+
+//.
+// AMDGCNSPIRV: @llvm.amdgcn.has.gfx10-insts = external addrspace(1) 
externally_initialized constant i1
+//.
+// AMDGCN-GFX900-LABEL: define dso_local void @foo(
+// AMDGCN-GFX900-SAME: ) #[[ATTR0:[0-9]+]] {
+// AMDGCN-GFX900-NEXT:  [[ENTRY:.*:]]
+// AMDGCN-GFX900-NEXT:ret void
+//
+// AMDGCN-GFX1010-LABEL: define dso_local void @foo(
+// AMDGCN-GFX1010-SAME: ) #[[ATTR0:[0-9]+]] {
+// AMDGCN-GFX1010-NEXT:  [[ENTRY:.*:]]
+// AMDGCN-GFX1010-NEXT:call void @llvm.trap()
+// AMDGCN-GFX1010-NEXT:ret void
+//
+// AMDGCNSPIRV-LABEL: define spir_func void @foo(
+// AMDGCNSPIRV-SAME: ) addrspace(4) #[[ATTR0:[0-9]+]] {
+// AMDGCNSPIRV-NEXT:  [[ENTRY:.*:]]
+// AMDGCNSPIRV-NEXT:[[TMP0:%.*]] = load i1, ptr addrspace(1) 
@llvm.amdgcn.has.gfx10-insts, align 1
+// AMDGCNSPIRV-NEXT:[[TOBOOL:%.*]] = icmp ne i1 [[TMP0]], false
+// AMDGCNSPIRV-NEXT:br i1 [[TOBOOL]], label %[[IF_THEN:.*]], label 
%[[IF_END:.*]]
+// AMDGCNSPIRV:   [[IF_THEN]]:
+// AMDGCNSPIRV-NEXT:call addrspace(4) void @llvm.trap()
+// AMDGCNSPIRV-NEXT:br label %[[IF_END]]
+// AMDGCNSPIRV:   [[IF_END]]:
+// AMDGCNSPIRV-NEXT:ret void
+//
+void foo() {
+if (__builtin_amdgcn_is_invocable(__builtin_amdgcn_permlanex16))

AlexVlx wrote:

Yes.

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-01 Thread Joseph Huber 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
+
+// Test that, depending on triple and, if applicable, target-cpu, one of three
+// things happens:
+//1) for gfx900 we emit an empty kernel (concrete target, lacks feature)
+//2) for gfx1010 we emit a call to trap (concrete target, has feature)
+//3) for AMDGCNSPIRV we emit llvm.amdgcn.has.gfx10-insts as a constant
+//   externally initialised bool global, and load from it to provide the
+//   condition to a br (abstract target)
+
+//.
+// AMDGCNSPIRV: @llvm.amdgcn.has.gfx10-insts = external addrspace(1) 
externally_initialized constant i1
+//.
+// AMDGCN-GFX900-LABEL: define dso_local void @foo(
+// AMDGCN-GFX900-SAME: ) #[[ATTR0:[0-9]+]] {
+// AMDGCN-GFX900-NEXT:  [[ENTRY:.*:]]
+// AMDGCN-GFX900-NEXT:ret void
+//
+// AMDGCN-GFX1010-LABEL: define dso_local void @foo(
+// AMDGCN-GFX1010-SAME: ) #[[ATTR0:[0-9]+]] {
+// AMDGCN-GFX1010-NEXT:  [[ENTRY:.*:]]
+// AMDGCN-GFX1010-NEXT:call void @llvm.trap()
+// AMDGCN-GFX1010-NEXT:ret void
+//
+// AMDGCNSPIRV-LABEL: define spir_func void @foo(
+// AMDGCNSPIRV-SAME: ) addrspace(4) #[[ATTR0:[0-9]+]] {
+// AMDGCNSPIRV-NEXT:  [[ENTRY:.*:]]
+// AMDGCNSPIRV-NEXT:[[TMP0:%.*]] = load i1, ptr addrspace(1) 
@llvm.amdgcn.has.gfx10-insts, align 1
+// AMDGCNSPIRV-NEXT:[[TOBOOL:%.*]] = icmp ne i1 [[TMP0]], false
+// AMDGCNSPIRV-NEXT:br i1 [[TOBOOL]], label %[[IF_THEN:.*]], label 
%[[IF_END:.*]]
+// AMDGCNSPIRV:   [[IF_THEN]]:
+// AMDGCNSPIRV-NEXT:call addrspace(4) void @llvm.trap()
+// AMDGCNSPIRV-NEXT:br label %[[IF_END]]
+// AMDGCNSPIRV:   [[IF_END]]:
+// AMDGCNSPIRV-NEXT:ret void
+//
+void foo() {
+if (__builtin_amdgcn_is_invocable(__builtin_amdgcn_permlanex16))

jhuber6 wrote:

Is this intended to handle builtins that require certain target features to be 
set?

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-01 Thread Alex Voicu via cfe-commits

AlexVlx wrote:

> This is worth a release note item.

Indeed! I botched moving the changes from my internal scratchpad, and the rel 
notes got lost; fixing.

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-01 Thread Joseph Huber 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
+
+// Test that, depending on triple and, if applicable, target-cpu, one of three
+// things happens:
+//1) for gfx900 we emit an empty kernel (concrete target, lacks feature)
+//2) for gfx1010 we emit a call to trap (concrete target, has feature)
+//3) for AMDGCNSPIRV we emit llvm.amdgcn.has.gfx10-insts as a constant
+//   externally initialised bool global, and load from it to provide the
+//   condition to a br (abstract target)
+
+//.
+// AMDGCNSPIRV: @llvm.amdgcn.has.gfx10-insts = external addrspace(1) 
externally_initialized constant i1
+//.
+// AMDGCN-GFX900-LABEL: define dso_local void @foo(
+// AMDGCN-GFX900-SAME: ) #[[ATTR0:[0-9]+]] {
+// AMDGCN-GFX900-NEXT:  [[ENTRY:.*:]]
+// AMDGCN-GFX900-NEXT:ret void
+//
+// AMDGCN-GFX1010-LABEL: define dso_local void @foo(
+// AMDGCN-GFX1010-SAME: ) #[[ATTR0:[0-9]+]] {
+// AMDGCN-GFX1010-NEXT:  [[ENTRY:.*:]]
+// AMDGCN-GFX1010-NEXT:call void @llvm.trap()
+// AMDGCN-GFX1010-NEXT:ret void
+//
+// AMDGCNSPIRV-LABEL: define spir_func void @foo(
+// AMDGCNSPIRV-SAME: ) addrspace(4) #[[ATTR0:[0-9]+]] {
+// AMDGCNSPIRV-NEXT:  [[ENTRY:.*:]]
+// AMDGCNSPIRV-NEXT:[[TMP0:%.*]] = load i1, ptr addrspace(1) 
@llvm.amdgcn.has.gfx10-insts, align 1
+// AMDGCNSPIRV-NEXT:[[TOBOOL:%.*]] = icmp ne i1 [[TMP0]], false
+// AMDGCNSPIRV-NEXT:br i1 [[TOBOOL]], label %[[IF_THEN:.*]], label 
%[[IF_END:.*]]
+// AMDGCNSPIRV:   [[IF_THEN]]:
+// AMDGCNSPIRV-NEXT:call addrspace(4) void @llvm.trap()
+// AMDGCNSPIRV-NEXT:br label %[[IF_END]]
+// AMDGCNSPIRV:   [[IF_END]]:
+// AMDGCNSPIRV-NEXT:ret void
+//
+void foo() {
+if (__builtin_amdgcn_is_invocable(__builtin_amdgcn_permlanex16))

jhuber6 wrote:

Could we get a test? Something simple like `+dpp`?

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] [clang][modules] Guard against bad -fmodule-file mappings (#132059) (PR #133462)

2025-04-01 Thread Naveen Seth Hanig via cfe-commits

https://github.com/naveen-seth updated 
https://github.com/llvm/llvm-project/pull/133462

>From 74ace4fd3c71ff59f2d89680c0f1382d0f9933f4 Mon Sep 17 00:00:00 2001
From: naveen-seth 
Date: Fri, 28 Mar 2025 06:59:06 +0100
Subject: [PATCH 1/2] [clang][modules] Guard against bad -fmodule-file mappings
 (#132059)

Fix #132059.

Providing incorrect mappings via -fmodule-file==,
such that the BMI file corresponds to a different module which
transitively imports the specified module, could previously crash the
compiler.

The crash is caused during serialization, when trying to resolve
declaration IDs in the AST body after having loaded the wrong module.

This commit fixes the issue by checking the module's identity while
reading the AST's control block and erroring out if a mismatch is
detected.
---
 .../Basic/DiagnosticSerializationKinds.td |  2 +
 clang/include/clang/Serialization/ASTReader.h | 17 +
 clang/lib/Frontend/ASTUnit.cpp|  1 +
 clang/lib/Frontend/ChainedIncludesSource.cpp  |  1 +
 clang/lib/Frontend/CompilerInstance.cpp   | 15 ++--
 clang/lib/Serialization/ASTReader.cpp | 73 +--
 .../fmodule-file-bad-transitive-mapping.cpp   | 46 
 7 files changed, 124 insertions(+), 31 deletions(-)
 create mode 100644 clang/test/Modules/fmodule-file-bad-transitive-mapping.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSerializationKinds.td 
b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
index 3914d3930bec7..16cc946e3f3d9 100644
--- a/clang/include/clang/Basic/DiagnosticSerializationKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -98,6 +98,8 @@ def err_imported_module_relocated : Error<
 def err_module_different_modmap : Error<
 "module '%0' %select{uses|does not use}1 additional module map '%2'"
 "%select{| not}1 used when the module was built">;
+def err_module_mismatch : Error<
+  "tried loading module '%0' from '%1' but found module '%2' instead">, 
DefaultFatal;
 
 def err_ast_file_macro_def_undef : Error<
 "macro '%0' was %select{defined|undef'd}1 in the AST file '%2' but "
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 2779b3d1cf2ea..57f2a08e09359 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -423,6 +423,9 @@ class ASTReader
 /// configuration.
 ConfigurationMismatch,
 
+/// The AST file contains a different module than expected.
+ModuleMismatch,
+
 /// The AST file has errors.
 HadErrors
   };
@@ -1512,11 +1515,13 @@ class ASTReader
 SourceLocation ImportLoc, ModuleFile *ImportedBy,
 SmallVectorImpl &Loaded,
 off_t ExpectedSize, time_t ExpectedModTime,
+StringRef ExpectedModuleName,
 ASTFileSignature ExpectedSignature,
 unsigned ClientLoadCapabilities);
   ASTReadResult ReadControlBlock(ModuleFile &F,
  SmallVectorImpl &Loaded,
  const ModuleFile *ImportedBy,
+ StringRef ExpectedModuleName,
  unsigned ClientLoadCapabilities);
   static ASTReadResult
   ReadOptionsBlock(llvm::BitstreamCursor &Stream, StringRef Filename,
@@ -1819,6 +1824,18 @@ class ASTReader
 unsigned ClientLoadCapabilities,
 ModuleFile **NewLoadedModuleFile = nullptr);
 
+  /// \overload
+  ///
+  /// Calls the above function and checks if the AST file contains the expected
+  /// module. Returns ASTReadResult::Failure on mismatch.
+  ///
+  /// \param ExpectedModuleName The expected name of the new loaded module.
+  ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
+SourceLocation ImportLoc,
+unsigned ClientLoadCapabilities,
+StringRef ExpectedModuleName,
+ModuleFile **NewLoadedModuleFile = nullptr);
+
   /// Make the entities in the given module and any of its (non-explicit)
   /// submodules visible to name lookup.
   ///
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 0a5f1cfd1a264..7500be81ea976 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -887,6 +887,7 @@ std::unique_ptr ASTUnit::LoadFromASTFile(
   case ASTReader::OutOfDate:
   case ASTReader::VersionMismatch:
   case ASTReader::ConfigurationMismatch:
+  case ASTReader::ModuleMismatch:
   case ASTReader::HadErrors:
 AST->getDiagnostics().Report(diag::err_fe_unable_to_load_pch);
 return nullptr;
diff --git a/clang/lib/Frontend/ChainedIncludesSource.cpp 
b/clang/lib/Frontend/ChainedIncludesSource.cpp
index a7096e27796a0..ee0363249124b 100644
--- a/clang/lib/Frontend/ChainedIncludesSource.cpp

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

2025-04-01 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/4] 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][modules] Guard against bad -fmodule-file mappings (#132059) (PR #133462)

2025-04-01 Thread Naveen Seth Hanig via cfe-commits

naveen-seth wrote:

Hi, sorry! I left a comment earlier but noticed that a large part of the 
explanation was incorrect and deleted it. Here is the fixed comment:

At first I thought that the issue can be fixed by just checking for duplicates 
while parsing the command-line arguments, but that doesn't seem to be the case.

I will try to describe the crash point and the crash reason with this example 
(without duplicate arguments):

```cpp
//--- a.cppm
export module A;

export int a() {
  return 41;
}
```

```cpp
//--- b.cppm
export module B;
import A;

export int b() {
  return a() + 1;
}
```

```cpp
//--- c.cppm
export module C;

export int c() {
  return 42;
}
```

```cpp
//--- main.cpp
import B;

int main() {
  return b();
}
```

```
# Correctly precompile the modules
clang++ -std=c++20 --precompile a.cppm -o a.pcm
clang++ -std=c++20 --precompile b.cppm -fmodule-file=A=a.pcm -o b.pcm
clang++ -std=c++20 --precompile c.cppm -o c.pcm

# Bad use of -fmodule-file=...
clang++ -std=c++20 main.cpp -std=c++20 main.cpp -fmodule-file=B=b.pcm 
-fmodule-file=A=c.pcm
```

After `import B;` is parsed from `main.cpp`, the following sequence of function 
calls occurs (from top to bottom): 

…
`Sema::ActOnModuleImport`
`CompilerInstance::loadModule`
`CompilerInstance::findOrCompileModuleAndReadAST`
`ASTReader::ReadAST`
`ASTReader::ReadASTCore`
`ASTReader::ReadControlBlock`

When reading a modules control block in `ASTReader::ReadControlBlock`, Clang 
also attempts to get the `ModuleFile` for each of its imports ([see 
here](https://github.com/llvm/llvm-project/blob/943a70717c629f43b309ab56e8141ffb131871a6/clang/lib/Serialization/ASTReader.cpp#L3024)).
First, the matching BMI file for an imported module is looked up, then Clang 
calls back to `ASTReader::ReadASTCore` to ensure the BMI files `ModuleFile`.

Currently (prior to this PR), there is no validation to ensure that the BMI 
file actually contains the module clang is trying to load after having read the 
module name in `ReadControlBlock`.

Because of the faulty `-fmodule-file=` mapping, the `ModuleFile` of the import 
will refer to a BMI built for a different module than the one clang is trying 
to load.
Here, the import of `A` in `b.cppm` will result in loading the `ModuleFile` 
corresponding to `c.pcm` while deserializing `b.pcm`. 

The crash occurs because Clang, assuming it has the correct `ModuleFile`s, 
continues reading AST blocks and attempts to resolve `ModuleFile` remappings 
(any of the mappings mentioned 
[here](https://github.com/llvm/llvm-project/blob/74ace4fd3c71ff59f2d89680c0f1382d0f9933f4/clang/lib/Serialization/ASTReader.cpp#L8765)).
 This results in invalid access into members of the invalid `ModuleFile`s and 
finally the crash.

(Depending on the specific example, the exact location of the crash will be 
different, but it will always happen while trying to resolve the remappings.)

While writing this comment, I noticed that my commit and PR message describe 
the cause of the crash incorrectly and have edited both.

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


[clang] [clang][modules] Guard against bad -fmodule-file mappings (#132059) (PR #133462)

2025-04-01 Thread Naveen Seth Hanig via cfe-commits

https://github.com/naveen-seth edited 
https://github.com/llvm/llvm-project/pull/133462
___
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-01 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/6] 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][modules] Determine if the SDK supports builtin modules independent of the target (PR #134005)

2025-04-01 Thread Ian Anderson via cfe-commits

https://github.com/ian-twilightcoder updated 
https://github.com/llvm/llvm-project/pull/134005

>From c1af28f0af52b84938b8b06957f048bffd8104bb Mon Sep 17 00:00:00 2001
From: Ian Anderson 
Date: Tue, 1 Apr 2025 16:24:30 -0700
Subject: [PATCH] [clang][modules] Determine if the SDK supports builtin
 modules independent of the target

Whether the SDK supports builtin modules is a property of the SDK itself, and 
really has nothing to do with the target. This was already worked around for 
Mac Catalyst, but there are some other more esoteric non-obvious target-to-sdk 
mappings that aren't handled. Have the SDK parse its OS out of CanonicalName 
and use that instead of the target to determine if builtin modules are 
supported.
---
 clang/include/clang/Basic/DarwinSDKInfo.h |  6 +-
 clang/lib/Basic/DarwinSDKInfo.cpp | 26 +++-
 clang/lib/Driver/ToolChains/Darwin.cpp| 60 +--
 .../Inputs/DriverKit23.0.sdk/SDKSettings.json |  2 +-
 .../Inputs/MacOSX10.14.sdk/SDKSettings.json   |  2 +-
 .../SDKSettings.json  |  1 +
 .../Inputs/MacOSX15.0.sdk/SDKSettings.json|  2 +-
 .../Inputs/MacOSX15.1.sdk/SDKSettings.json|  2 +-
 .../Inputs/WatchOS6.0.sdk/SDKSettings.json|  2 +-
 .../Inputs/iPhoneOS13.0.sdk/SDKSettings.json  |  2 +-
 .../darwin-ld-platform-version-watchos.c  |  4 +-
 .../Inputs/MacOSX13.0.sdk/SDKSettings.json|  1 +
 .../Inputs/AppleTVOS15.0.sdk/SDKSettings.json |  1 +
 .../Inputs/MacOSX11.0.sdk/SDKSettings.json|  1 +
 .../Inputs/WatchOS7.0.sdk/SDKSettings.json|  1 +
 15 files changed, 72 insertions(+), 41 deletions(-)

diff --git a/clang/include/clang/Basic/DarwinSDKInfo.h 
b/clang/include/clang/Basic/DarwinSDKInfo.h
index db20b968a898e..bc122c7d21c72 100644
--- a/clang/include/clang/Basic/DarwinSDKInfo.h
+++ b/clang/include/clang/Basic/DarwinSDKInfo.h
@@ -143,16 +143,19 @@ class DarwinSDKInfo {
 
   DarwinSDKInfo(
   VersionTuple Version, VersionTuple MaximumDeploymentTarget,
+  llvm::Triple::OSType OS,
   llvm::DenseMap>
   VersionMappings =
   llvm::DenseMap>())
   : Version(Version), MaximumDeploymentTarget(MaximumDeploymentTarget),
-VersionMappings(std::move(VersionMappings)) {}
+OS(OS), VersionMappings(std::move(VersionMappings)) {}
 
   const llvm::VersionTuple &getVersion() const { return Version; }
 
+  const llvm::Triple::OSType &getOS() const { return OS; }
+
   // Returns the optional, target-specific version mapping that maps from one
   // target to another target.
   //
@@ -177,6 +180,7 @@ class DarwinSDKInfo {
 private:
   VersionTuple Version;
   VersionTuple MaximumDeploymentTarget;
+  llvm::Triple::OSType OS;
   // Need to wrap the value in an optional here as the value has to be default
   // constructible, and std::unique_ptr doesn't like DarwinSDKInfo being
   // Optional as Optional is trying to copy it in emplace.
diff --git a/clang/lib/Basic/DarwinSDKInfo.cpp 
b/clang/lib/Basic/DarwinSDKInfo.cpp
index 00aa5f9e63cd3..eaf600d8ffed3 100644
--- a/clang/lib/Basic/DarwinSDKInfo.cpp
+++ b/clang/lib/Basic/DarwinSDKInfo.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang/Basic/DarwinSDKInfo.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -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.
+  auto CanonicalName = Obj.getString("CanonicalName");
+  if (!CanonicalName)
+return llvm::Triple::UnknownOS;
+  size_t VersionStart = CanonicalName->find_first_of("0123456789");
+  StringRef XcodePlatform = CanonicalName->slice(0, VersionStart);
+  return llvm::StringSwitch(XcodePlatform)
+  .Case("macosx", llvm::Triple::MacOSX)
+  .Case("iphoneos", llvm::Triple::IOS)
+  .Case("iphonesimulator", llvm::Triple::IOS)
+  .Case("appletvos", llvm::Triple::TvOS)
+  .Case("appletvsimulator", llvm::Triple::TvOS)
+  .Case("watchos", llvm::Triple::WatchOS)
+  .Case("watchsimulator", llvm::Triple::WatchOS)
+  .Case("xros", llvm::Triple::XROS)
+  .Case("xrsimulator", llvm::Triple::XROS)
+  .Case("driverkit", llvm::Triple::DriverKit)
+  .Default(llvm::Triple::UnknownOS);
+}
+
 static std::optional getVersionKey(const llvm::json::Object &Obj,
  StringRef Key) {
   auto Value = Obj.getString(Key);
@@ -82,6 +105,7 @@ DarwinSDKInfo::parseDarwinSDKSettingsJSON(const 
llvm::json::Object *Obj) {
   getVersionKey(*Obj, "MaximumDeploymentTarget");
   if (!MaximumDeploymentVersion)
 return std::nullopt;
+  llvm::Triple::OSType OS = parseOS(*Obj);
   ll

[clang] [clang][ExtractAPI] emit correct spelling for type aliases (PR #134007)

2025-04-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Erick Velez (evelez7)


Changes

Previously, C++11 type aliases were serialized using "typedef" regardless of 
the source spelling.
This checks if the TypedefNameDecl is actually a TypeAliasDecl and corrects the 
spelling.

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


2 Files Affected:

- (modified) clang/lib/ExtractAPI/DeclarationFragments.cpp (+19-7) 
- (added) clang/test/ExtractAPI/type-alias.cpp (+56) 


``diff
diff --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp 
b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index d7eebcbc3c2f9..80174e30ffd1a 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -1584,13 +1584,25 @@ DeclarationFragments 
DeclarationFragmentsBuilder::getFragmentsForObjCProtocol(
 DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForTypedef(
 const TypedefNameDecl *Decl) {
   DeclarationFragments Fragments, After;
-  Fragments.append("typedef", DeclarationFragments::FragmentKind::Keyword)
-  .appendSpace()
-  .append(getFragmentsForType(Decl->getUnderlyingType(),
-  Decl->getASTContext(), After))
-  .append(std::move(After))
-  .appendSpace()
-  .append(Decl->getName(), DeclarationFragments::FragmentKind::Identifier);
+  if (!isa(Decl))
+Fragments.append("typedef", DeclarationFragments::FragmentKind::Keyword)
+.appendSpace()
+.append(getFragmentsForType(Decl->getUnderlyingType(),
+Decl->getASTContext(), After))
+.append(std::move(After))
+.appendSpace()
+.append(Decl->getName(),
+DeclarationFragments::FragmentKind::Identifier);
+  else
+Fragments.append("using", DeclarationFragments::FragmentKind::Keyword)
+.appendSpace()
+.append(Decl->getName(), 
DeclarationFragments::FragmentKind::Identifier)
+.appendSpace()
+.append("=", DeclarationFragments::FragmentKind::Text)
+.appendSpace()
+.append(getFragmentsForType(Decl->getUnderlyingType(),
+Decl->getASTContext(), After))
+.append(std::move(After));
 
   return Fragments.appendSemicolon();
 }
diff --git a/clang/test/ExtractAPI/type-alias.cpp 
b/clang/test/ExtractAPI/type-alias.cpp
new file mode 100644
index 0..246e8fbb92156
--- /dev/null
+++ b/clang/test/ExtractAPI/type-alias.cpp
@@ -0,0 +1,56 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -extract-api --pretty-sgf 
--emit-sgf-symbol-labels-for-testing \
+// RUN:   --product-name=TypeAlias -triple arm64-apple-macosx -x c++-header %s 
-o %t/type-alias.symbols.json -verify
+
+// RUN: FileCheck %s --input-file %t/type-alias.symbols.json --check-prefix 
MYALIAS
+using MyAlias = int;
+//MYALIAS-LABEL "!testLabel": "c:@MYALIAS"
+//MYALIAS:   "accessLevel": "public",
+//MYALIAS:   "declarationFragments": [
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "keyword",
+//MYALIAS-NEXT:  "spelling": "using"
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "text",
+//MYALIAS-NEXT:  "spelling": " "
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "identifier",
+//MYALIAS-NEXT:  "spelling": "MyAlias"
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "text",
+//MYALIAS-NEXT:  "spelling": " = "
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "typeIdentifier",
+//MYALIAS-NEXT:  "preciseIdentifier": "c:I",
+//MYALIAS-NEXT:  "spelling": "int"
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "text",
+//MYALIAS-NEXT:  "spelling": ";"
+//MYALIAS-NEXT:}
+//MYALIAS:   "kind": {
+//MYALIAS-NEXT:  "displayName": "Type Alias",
+//MYALIAS-NEXT:  "identifier": "c++.typealias"
+//MYALIAS:   names": {
+//MYALIAS-NEXT:"navigator": [
+//MYALIAS-NEXT:  {
+//MYALIAS-NEXT:"kind": "identifier",
+//MYALIAS-NEXT:"spelling": "MyAlias"
+//MYALIAS-NEXT:  }
+//MYALIAS-NEXT:],
+//MYALIAS-NEXT:  "subHeading": [
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "identifier",
+//MYALIAS-NEXT:  "spelling": "MyAlias"
+//MYALIAS-NEXT:}
+//MYALIAS-NEXT:],
+//MYALIAS-NEXT:"title": "MyAlias"
+//MYALIAS:   "pathComponents": [
+//MYALIAS-NEXT:"MyAlias"
+//MYALIAS-NEXT:  ]
+
+// expected-no-diagnostics
\ No newline at end of file

``




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


[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2025-04-01 Thread Trevor Gross via cfe-commits


@@ -126,3 +138,23 @@ define void @f9(ptr %cptr, ptr %aptr, ptr %bptr) {
   store fp128 %c, ptr %cptr
   ret void
 }
+
+; Test f16 copies in which the sign comes from an f16.
+define half @f10(half %a, half %b) {
+; CHECK-LABEL: f10:
+; CHECK: brasl %r14, copysignh@PLT

tgross35 wrote:

I think `abs` and `copysign` are generally libcall-free, so that would be 
preferable here if possible.

Not related with that change but as a note, I don't think the `h` suffix exists 
for `math.h` routines. C23 does specify sized suffixes however, so e.g. 
`copysignf16` is valid and is provided by both [LLVM's 
`libc`](https://github.com/llvm/llvm-project/blob/749535ba2808e133682074f712ac6829335f8875/libc/src/math/generic/copysignf16.cpp#L16)
 and [Rust's 
builtins](https://docs.rs/compiler_builtins/latest/compiler_builtins/math/full_availability/fn.copysignf16.html).

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


[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2025-04-01 Thread Trevor Gross via cfe-commits

https://github.com/tgross35 edited 
https://github.com/llvm/llvm-project/pull/109164
___
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-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Ian Anderson (ian-twilightcoder)


Changes

Whether the SDK supports builtin modules is a property of the SDK itself, and 
really has nothing to do with the target. This was already worked around for 
Mac Catalyst, but there are some other more esoteric non-obvious target-to-sdk 
mappings that aren't handled. Have the SDK parse its OS out of CanonicalName 
and use that instead of the target to determine if builtin modules are 
supported.

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


15 Files Affected:

- (modified) clang/include/clang/Basic/DarwinSDKInfo.h (+5-1) 
- (modified) clang/lib/Basic/DarwinSDKInfo.cpp (+25-1) 
- (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+29-31) 
- (modified) clang/test/Driver/Inputs/DriverKit23.0.sdk/SDKSettings.json (+1-1) 
- (modified) clang/test/Driver/Inputs/MacOSX10.14.sdk/SDKSettings.json (+1-1) 
- (modified) 
clang/test/Driver/Inputs/MacOSX10.15.versioned.sdk/SDKSettings.json (+1) 
- (modified) clang/test/Driver/Inputs/MacOSX15.0.sdk/SDKSettings.json (+1-1) 
- (modified) clang/test/Driver/Inputs/MacOSX15.1.sdk/SDKSettings.json (+1-1) 
- (modified) clang/test/Driver/Inputs/WatchOS6.0.sdk/SDKSettings.json (+1-1) 
- (modified) clang/test/Driver/Inputs/iPhoneOS13.0.sdk/SDKSettings.json (+1-1) 
- (modified) clang/test/Driver/darwin-ld-platform-version-watchos.c (+2-2) 
- (modified) clang/test/InstallAPI/Inputs/MacOSX13.0.sdk/SDKSettings.json (+1) 
- (modified) clang/test/Sema/Inputs/AppleTVOS15.0.sdk/SDKSettings.json (+1) 
- (modified) clang/test/Sema/Inputs/MacOSX11.0.sdk/SDKSettings.json (+1) 
- (modified) clang/test/Sema/Inputs/WatchOS7.0.sdk/SDKSettings.json (+1) 


``diff
diff --git a/clang/include/clang/Basic/DarwinSDKInfo.h 
b/clang/include/clang/Basic/DarwinSDKInfo.h
index db20b968a898e..bc122c7d21c72 100644
--- a/clang/include/clang/Basic/DarwinSDKInfo.h
+++ b/clang/include/clang/Basic/DarwinSDKInfo.h
@@ -143,16 +143,19 @@ class DarwinSDKInfo {
 
   DarwinSDKInfo(
   VersionTuple Version, VersionTuple MaximumDeploymentTarget,
+  llvm::Triple::OSType OS,
   llvm::DenseMap>
   VersionMappings =
   llvm::DenseMap>())
   : Version(Version), MaximumDeploymentTarget(MaximumDeploymentTarget),
-VersionMappings(std::move(VersionMappings)) {}
+OS(OS), VersionMappings(std::move(VersionMappings)) {}
 
   const llvm::VersionTuple &getVersion() const { return Version; }
 
+  const llvm::Triple::OSType &getOS() const { return OS; }
+
   // Returns the optional, target-specific version mapping that maps from one
   // target to another target.
   //
@@ -177,6 +180,7 @@ class DarwinSDKInfo {
 private:
   VersionTuple Version;
   VersionTuple MaximumDeploymentTarget;
+  llvm::Triple::OSType OS;
   // Need to wrap the value in an optional here as the value has to be default
   // constructible, and std::unique_ptr doesn't like DarwinSDKInfo being
   // Optional as Optional is trying to copy it in emplace.
diff --git a/clang/lib/Basic/DarwinSDKInfo.cpp 
b/clang/lib/Basic/DarwinSDKInfo.cpp
index 00aa5f9e63cd3..eaf600d8ffed3 100644
--- a/clang/lib/Basic/DarwinSDKInfo.cpp
+++ b/clang/lib/Basic/DarwinSDKInfo.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang/Basic/DarwinSDKInfo.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -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.
+  auto CanonicalName = Obj.getString("CanonicalName");
+  if (!CanonicalName)
+return llvm::Triple::UnknownOS;
+  size_t VersionStart = CanonicalName->find_first_of("0123456789");
+  StringRef XcodePlatform = CanonicalName->slice(0, VersionStart);
+  return llvm::StringSwitch(XcodePlatform)
+  .Case("macosx", llvm::Triple::MacOSX)
+  .Case("iphoneos", llvm::Triple::IOS)
+  .Case("iphonesimulator", llvm::Triple::IOS)
+  .Case("appletvos", llvm::Triple::TvOS)
+  .Case("appletvsimulator", llvm::Triple::TvOS)
+  .Case("watchos", llvm::Triple::WatchOS)
+  .Case("watchsimulator", llvm::Triple::WatchOS)
+  .Case("xros", llvm::Triple::XROS)
+  .Case("xrsimulator", llvm::Triple::XROS)
+  .Case("driverkit", llvm::Triple::DriverKit)
+  .Default(llvm::Triple::UnknownOS);
+}
+
 static std::optional getVersionKey(const llvm::json::Object &Obj,
  StringRef Key) {
   auto Value = Obj.getString(Key);
@@ -82,6 +105,7 @@ DarwinSDKInfo::parseDarwinSDKSettingsJSON(const 
llvm::json::Object *Obj) {
   getVersionKey(*Obj, "MaximumDeploymentTarget");
   i

[clang] [clang-sycl-linker] Replace llvm-link with API calls (PR #133797)

2025-04-01 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 5 "build-unified-tree".

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


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

```
Step 5 (build-unified-tree) failure: build (failure)
...
4407.322 [632/10/4707] Building CXX object 
tools/clang/tools/clang-diff/CMakeFiles/clang-diff.dir/ClangDiff.cpp.o
4407.865 [631/10/4708] Building CXX object 
tools/clang/tools/clang-fuzzer/handle-cxx/CMakeFiles/obj.clangHandleCXX.dir/handle_cxx.cpp.o
4408.363 [630/10/4709] Building CXX object 
tools/clang/lib/Interpreter/CMakeFiles/obj.clangInterpreter.dir/Interpreter.cpp.o
4408.984 [629/10/4710] Building CXX object 
tools/clang/tools/clang-installapi/CMakeFiles/clang-installapi.dir/clang-installapi-driver.cpp.o
4409.196 [628/10/4711] Building CXX object 
tools/clang/tools/clang-fuzzer/handle-llvm/CMakeFiles/obj.clangHandleLLVM.dir/handle_llvm.cpp.o
4409.635 [627/10/4712] Building C object 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o
4409.777 [626/10/4713] Building CXX object 
tools/clang/tools/clang-shlib/CMakeFiles/clang-cpp.dir/clang-shlib.cpp.o
4415.812 [625/10/4714] Building CXX object 
tools/clang/tools/clang-import-test/CMakeFiles/clang-import-test.dir/clang-import-test.cpp.o
4419.604 [624/10/4715] Building CXX object 
tools/clang/tools/clang-refactor/CMakeFiles/clang-refactor.dir/TestSupport.cpp.o
4419.913 [623/10/4716] Building CXX object 
tools/clang/tools/clang-sycl-linker/CMakeFiles/clang-sycl-linker.dir/ClangSYCLLinker.cpp.o
FAILED: 
tools/clang/tools/clang-sycl-linker/CMakeFiles/clang-sycl-linker.dir/ClangSYCLLinker.cpp.o
 
/home/llvm/llvm-external-buildbots/clang.19.1.2/bin/clang++ -DGTEST_HAS_RTTI=0 
-DLLVM_BUILD_STATIC -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LARGE_FILE_API 
-D_XOPEN_SOURCE=700 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS 
-I/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/tools/clang-sycl-linker
 
-I/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/tools/clang-sycl-linker
 
-I/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/include
 
-I/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/tools/clang/include
 
-I/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/include
 
-I/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/include
 -mcmodel=large -fPIC -Werror -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables 
-fno-rtti -UNDEBUG -pthread -MD -MT 
tools/clang/tools/clang-sycl-linker/CMakeFiles/clang-sycl-linker.dir/ClangSYCLLinker.cpp.o
 -MF 
tools/clang/tools/clang-sycl-linker/CMakeFiles/clang-sycl-linker.dir/ClangSYCLLinker.cpp.o.d
 -o 
tools/clang/tools/clang-sycl-linker/CMakeFiles/clang-sycl-linker.dir/ClangSYCLLinker.cpp.o
 -c 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp:127:13:
 error: function 'getMainExecutable' is not needed and will not be emitted 
[-Werror,-Wunneeded-internal-declaration]
  127 | std::string getMainExecutable(const char *Name) {
  | ^
1 error generated.
4420.216 [623/9/4717] Building CXX object 
tools/clang/tools/clang-installapi/CMakeFiles/clang-installapi.dir/Options.cpp.o
4420.637 [623/8/4718] Building CXX object 
tools/clang/tools/clang-nvlink-wrapper/CMakeFiles/clang-nvlink-wrapper.dir/ClangNVLinkWrapper.cpp.o
4422.547 [623/7/4719] Building CXX object 
tools/clang/tools/libclang/CMakeFiles/libclang.dir/BuildSystem.cpp.o
4425.321 [623/6/4720] Building CXX object 
tools/clang/tools/clang-check/CMakeFiles/clang-check.dir/ClangCheck.cpp.o
4426.778 [623/5/4721] Building CXX object 
tools/clang/tools/clang-installapi/CMakeFiles/clang-installapi.dir/ClangInstallAPI.cpp.o
4427.727 [623/4/4722] Building CXX object 
tools/clang/tools/clang-refactor/CMakeFiles/clang-refactor.dir/ClangRefactor.cpp.o
4427.985 [623/3/4723] Building CXX object 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/core_main.cpp.o
4431.277 [623/2/4724] Building CXX object 
tools/clang/too

[clang] [llvm] Reland "[HLSL][RootSignature] Implement parsing of a DescriptorTable with empty clauses" (PR #133958)

2025-04-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Finn Plummer (inbelic)


Changes

This pr relands https://github.com/llvm/llvm-project/pull/133302.

It resolves two issues:
- Linking error during build, 
[here](https://github.com/llvm/llvm-project/pull/133302#issuecomment-2767259848).
 There was a missing dependency for `clangLex` for the 
`ParseHLSLRootSignatureTest.cpp` unit testing. This library was added to the 
dependencies to resolve the error. It wasn't caught previously as the library 
was transitively linked in most build environments
- Warning of unused declaration, 
[here](https://github.com/llvm/llvm-project/pull/133302#issuecomment-2767091368).
 There was a usability line in `LexHLSLRootSignature.h` of the form `using 
TokenKind = enum RootSignatureToken::Kind` which causes this error. The 
declaration is removed from the header file to be used locally in the `.cpp` 
files that use it.
Notably, the original pr would also exposed `clang::hlsl::TokenKind` to 
everywhere it was included, which had a name clash with `tok::TokenKind`. This 
is another motivation to change to the proposed resolution.

---

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


12 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+4) 
- (modified) clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def (+12-11) 
- (modified) clang/include/clang/Lex/LexHLSLRootSignature.h (+17-5) 
- (added) clang/include/clang/Parse/ParseHLSLRootSignature.h (+107) 
- (modified) clang/lib/Lex/LexHLSLRootSignature.cpp (+10-8) 
- (modified) clang/lib/Parse/CMakeLists.txt (+1) 
- (added) clang/lib/Parse/ParseHLSLRootSignature.cpp (+168) 
- (modified) clang/unittests/CMakeLists.txt (+1) 
- (modified) clang/unittests/Lex/LexHLSLRootSignatureTest.cpp (+31-29) 
- (added) clang/unittests/Parse/CMakeLists.txt (+20) 
- (added) clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp (+245) 
- (added) llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h (+44) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 86c361b4dbcf7..2582e1e5ef0f6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1830,4 +1830,8 @@ def err_hlsl_virtual_function
 def err_hlsl_virtual_inheritance
 : Error<"virtual inheritance is unsupported in HLSL">;
 
+// HLSL Root Siganture diagnostic messages
+def err_hlsl_unexpected_end_of_params
+: Error<"expected %0 to denote end of parameters, or, another valid 
parameter of %1">;
+
 } // end of Parser diagnostics
diff --git a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def 
b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
index e6df763920430..c514d3456146a 100644
--- a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
+++ b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
@@ -14,16 +14,16 @@
 
//===--===//
 
 #ifndef TOK
-#define TOK(X)
+#define TOK(X, SPELLING)
 #endif
 #ifndef PUNCTUATOR
-#define PUNCTUATOR(X,Y) TOK(pu_ ## X)
+#define PUNCTUATOR(X,Y) TOK(pu_ ## X, Y)
 #endif
 #ifndef KEYWORD
-#define KEYWORD(X) TOK(kw_ ## X)
+#define KEYWORD(X) TOK(kw_ ## X, #X)
 #endif
 #ifndef ENUM
-#define ENUM(NAME, LIT) TOK(en_ ## NAME)
+#define ENUM(NAME, LIT) TOK(en_ ## NAME, LIT)
 #endif
 
 // Defines the various types of enum
@@ -49,15 +49,15 @@
 #endif
 
 // General Tokens:
-TOK(invalid)
-TOK(end_of_stream)
-TOK(int_literal)
+TOK(invalid, "invalid identifier")
+TOK(end_of_stream, "end of stream")
+TOK(int_literal, "integer literal")
 
 // Register Tokens:
-TOK(bReg)
-TOK(tReg)
-TOK(uReg)
-TOK(sReg)
+TOK(bReg, "b register")
+TOK(tReg, "t register")
+TOK(uReg, "u register")
+TOK(sReg, "s register")
 
 // Punctuators:
 PUNCTUATOR(l_paren, '(')
@@ -69,6 +69,7 @@ PUNCTUATOR(plus,'+')
 PUNCTUATOR(minus,   '-')
 
 // RootElement Keywords:
+KEYWORD(RootSignature) // used only for diagnostic messaging
 KEYWORD(DescriptorTable)
 
 // DescriptorTable Keywords:
diff --git a/clang/include/clang/Lex/LexHLSLRootSignature.h 
b/clang/include/clang/Lex/LexHLSLRootSignature.h
index 21c44e0351d9e..4dc80ff546aa0 100644
--- a/clang/include/clang/Lex/LexHLSLRootSignature.h
+++ b/clang/include/clang/Lex/LexHLSLRootSignature.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_LEX_LEXHLSLROOTSIGNATURE_H
 #define LLVM_CLANG_LEX_LEXHLSLROOTSIGNATURE_H
 
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceLocation.h"
 
 #include "llvm/ADT/SmallVector.h"
@@ -24,11 +25,11 @@ namespace hlsl {
 
 struct RootSignatureToken {
   enum Kind {
-#define TOK(X) X,
+#define TOK(X, SPELLING) X,
 #include "clang/Lex/HLSLRootSignatureTokenKinds.def"
   };
 
-  Kind Kind = Kind::invalid;
+  Kind TokKind = Kind::invalid;
 
   // Retain the SouceLocation of the token for diagnostics
   clang::SourceLocation TokLoc;
@@ 

[clang] [CIR][Upstream] Local initialization for ArrayType (PR #132974)

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


@@ -110,6 +110,10 @@ class CIRGenFunction : public CIRGenTypeCache {
 public:
   mlir::Value createDummyValue(mlir::Location loc, clang::QualType qt);
 
+  void emitAggExpr(const clang::Expr *e, AggValueSlot slot);

andykaylor wrote:

These should be moved to the place where other `emit*` functions are declared 
and inserted in alphabetical order.

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


[clang] [cmake] Refactor clang unittest cmake (PR #133545)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-aarch64-windows` 
running on `linaro-armv8-windows-msvc-05` while building `clang` at step 6 
"test".

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


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

```
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: functionalities/wrong_commands/TestWrongCommands.py (699 of 
2104)
UNSUPPORTED: lldb-api :: iohandler/autosuggestion/TestAutosuggestion.py (700 of 
2104)
UNSUPPORTED: lldb-api :: iohandler/completion/TestIOHandlerCompletion.py (701 
of 2104)
UNSUPPORTED: lldb-api :: iohandler/resize/TestIOHandlerResize.py (702 of 2104)
UNSUPPORTED: lldb-api :: iohandler/resize/TestIOHandlerResizeNoEditline.py (703 
of 2104)
UNSUPPORTED: lldb-api :: iohandler/sigint/TestIOHandlerPythonREPLSigint.py (704 
of 2104)
UNSUPPORTED: lldb-api :: iohandler/sigint/TestProcessIOHandlerInterrupt.py (705 
of 2104)
UNSUPPORTED: lldb-api :: iohandler/stdio/TestIOHandlerProcessSTDIO.py (706 of 
2104)
UNSUPPORTED: lldb-api :: iohandler/unicode/TestUnicode.py (707 of 2104)
TIMEOUT: lldb-api :: functionalities/conditional_break/TestConditionalBreak.py 
(708 of 2104)
 TEST 'lldb-api :: 
functionalities/conditional_break/TestConditionalBreak.py' FAILED 

Script:
--
C:/Users/tcwg/scoop/apps/python/current/python.exe 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/llvm-project/lldb\test\API\dotest.py
 -u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./lib --env 
LLVM_INCLUDE_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/include 
--env LLVM_TOOLS_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin 
--arch aarch64 --build-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-lldb\lldb-api
 --clang-module-cache-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-clang\lldb-api
 --executable 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/lldb.exe --compiler 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/clang.exe --dsymutil 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/dsymutil.exe --make 
C:/Users/tcwg/scoop/shims/make.exe --llvm-tools-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin --lldb-obj-root 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/tools/lldb --lldb-libs-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./lib 
--skip-category=watchpoint 
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\API\functionalities\conditional_break
 -p TestConditionalBreak.py
--
Exit Code: 15
Timeout: Reached timeout of 600 seconds

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 
5ffd9bdb50b5753bbf668e4eab3647dfb46cd0d6)
  clang revision 5ffd9bdb50b5753bbf668e4eab3647dfb46cd0d6
  llvm revision 5ffd9bdb50b5753bbf668e4eab3647dfb46cd0d6
Executing commands in 
'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\API\functionalities\conditional_break\.lldb'.
(lldb) breakpoint set -n c
Breakpoint 1: where = a.out`c + 8 at main.c:31:12, address = 0x000140001094
(lldb) command script import -r conditional_break.py
(lldb) breakpoint command add 1 -F "conditional_break.stop_if_called_from_a"

--
Command Output (stderr):
--
UNSUPPORTED: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_with_command_dsym 
(TestConditionalBreak.ConditionalBreakTestCase.test_with_command_dsym) (test 
case does not fall in any category of interest for this run) 

PASS: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_with_command_dwarf 
(TestConditionalBreak.ConditionalBreakTestCase.test_with_command_dwarf)

UNSUPPORTED: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_with_command_dwo 
(TestConditionalBreak.ConditionalBreakTestCase.test_with_command_dwo) (test 
case does not fall in any category of interest for this run) 

UNSUPPORTED: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_with_python_dsym 
(TestConditionalBreak.ConditionalBreakTestCase.test_with_python_dsym) (test 
case does not fall in any category of interest for this run) 


--


PASS: lldb-api :: lang/c/anonymous/TestAnonymous.py (709 of 2104)
UNSUPPORTED: lldb-api :: lang/c/bitfields/TestBitfields.py (710 of 2104)
UNSUPPORTED: lldb-api :: lang/c/blocks/TestBlocks.py (711 of 2104)
PASS: lldb-api :: lang/c/builtin-types/TestCBuiltinTypes.py (712 of 2104)
PASS: lldb-api :: lang/c/array_types/TestArrayTypes.py (713 of 2104)

```



https://github.com/llvm/llvm-project/pull/133545
_

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

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

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/133190

>From 4c3fe79695f8082f56f8403fbf1f9eb299bb4af2 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 26 Mar 2025 18:38:34 -0300
Subject: [PATCH] [clang] support pack expansions for trailing requires clauses

This fixes a crash when evaluating constraints from trailing
requires clauses, when these are part of a generic lambda which
is expanded.
---
 .../refactor/tweaks/ExtractVariable.cpp   |  6 +--
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/include/clang/AST/ASTNodeTraverser.h|  4 +-
 clang/include/clang/AST/Decl.h| 35 +++--
 clang/include/clang/AST/DeclCXX.h | 20 
 clang/include/clang/AST/ExprCXX.h |  2 +-
 clang/include/clang/AST/RecursiveASTVisitor.h |  9 ++--
 clang/include/clang/Sema/Sema.h   | 14 ++---
 clang/lib/AST/ASTContext.cpp  |  7 ++-
 clang/lib/AST/ASTImporter.cpp |  5 +-
 clang/lib/AST/Decl.cpp| 14 ++---
 clang/lib/AST/DeclCXX.cpp | 33 +++-
 clang/lib/AST/DeclPrinter.cpp | 10 ++--
 clang/lib/AST/DeclTemplate.cpp|  4 +-
 clang/lib/AST/ExprCXX.cpp |  2 +-
 clang/lib/AST/ItaniumMangle.cpp   |  2 +-
 clang/lib/ASTMatchers/ASTMatchFinder.cpp  |  3 +-
 clang/lib/Index/IndexDecl.cpp |  4 +-
 clang/lib/Sema/SemaConcept.cpp|  6 +--
 clang/lib/Sema/SemaDecl.cpp   | 21 
 clang/lib/Sema/SemaDeclCXX.cpp|  4 +-
 clang/lib/Sema/SemaFunctionEffects.cpp|  2 +-
 clang/lib/Sema/SemaLambda.cpp | 18 ---
 clang/lib/Sema/SemaOverload.cpp   | 12 +++--
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp | 51 ---
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  4 +-
 clang/lib/Sema/TreeTransform.h|  7 ++-
 clang/lib/Serialization/ASTReaderDecl.cpp |  3 +-
 clang/lib/Serialization/ASTWriterDecl.cpp |  5 +-
 .../SemaCXX/fold_lambda_with_variadics.cpp|  9 
 clang/tools/libclang/CIndex.cpp   |  2 +-
 31 files changed, 187 insertions(+), 133 deletions(-)

diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
index d84e501b87ce7..90dac3b76c648 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -100,9 +100,9 @@ computeReferencedDecls(const clang::Expr *Expr) {
 TraverseLambdaCapture(LExpr, &Capture, Initializer);
   }
 
-  if (clang::Expr *const RequiresClause =
-  LExpr->getTrailingRequiresClause()) {
-TraverseStmt(RequiresClause);
+  if (const clang::Expr *RequiresClause =
+  LExpr->getTrailingRequiresClause().ConstraintExpr) {
+TraverseStmt(const_cast(RequiresClause));
   }
 
   for (auto *const TemplateParam : LExpr->getExplicitTemplateParameters())
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c4e82678949ff..f1066139c8514 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -373,6 +373,8 @@ Bug Fixes to C++ Support
 - Improved fix for an issue with pack expansions of type constraints, where 
this
   now also works if the constraint has non-type or template template 
parameters.
   (#GH131798)
+- Fix crash when evaluating trailing requires clause of generic lambdas which 
are part of
+  a pack expansion.
 - Fixes matching of nested template template parameters. (#GH130362)
 - Correctly diagnoses template template paramters which have a pack parameter
   not in the last position.
diff --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index f086d8134a64b..7bb435146f752 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -538,8 +538,8 @@ class ASTNodeTraverser
   for (const auto *Parameter : D->parameters())
 Visit(Parameter);
 
-if (const Expr *TRC = D->getTrailingRequiresClause())
-  Visit(TRC);
+if (const AssociatedConstraint &TRC = D->getTrailingRequiresClause())
+  Visit(TRC.ConstraintExpr);
 
 if (Traversal == TK_IgnoreUnlessSpelledInSource && D->isDefaulted())
   return;
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 9e7e93d98c9d1..adf3634d205bc 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -81,13 +81,17 @@ enum class ImplicitParamKind;
 // Holds a constraint expression along with a pack expansion index, if
 // expanded.
 struct AssociatedConstraint {
-  const Expr *ConstraintExpr;
-  int ArgumentPackSubstitutionIndex;
+  const Expr *ConstraintExpr = nullptr;
+  int ArgumentPackSubstitutionIndex = -1;
+
+  constexp

[clang] [modules] Handle friend function that was a definition but became only a declaration during AST deserialization (PR #132214)

2025-04-01 Thread Chuanqi Xu via cfe-commits


@@ -1392,6 +1392,20 @@ class ASTReader
 
   llvm::DenseMap DefinitionSource;
 
+  /// The set of extra flags about declarations that we have read from
+  /// the module file.
+  struct ExternalDeclarationBits {
+/// Indicates if given function declaration was a definition but its body
+/// was removed due to declaration merging.
+bool ThisDeclarationWasADefinition : 1;
+
+ExternalDeclarationBits() : ThisDeclarationWasADefinition(false) {}
+  };
+
+  /// A mapping from declarations to extra bits of information about this decl.
+  llvm::DenseMap

ChuanqiXu9 wrote:

```suggestion
  llvm::DenseMap
```

nit: I think we can avoid the abstraction here.

https://github.com/llvm/llvm-project/pull/132214
___
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-01 Thread Matt Arsenault via cfe-commits

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


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] Revert "[cmake] Refactor clang unittest cmake" (PR #134022)

2025-04-01 Thread via cfe-commits

https://github.com/dpalermo created 
https://github.com/llvm/llvm-project/pull/134022

Reverts llvm/llvm-project#133545

This change is breaking several buildbots as well as developer's builds.  
Reverting to allow people to make progress.

>From 8392666bb92c87127db2ecbb85523bd64bfabcd7 Mon Sep 17 00:00:00 2001
From: dpalermo 
Date: Tue, 1 Apr 2025 22:15:57 -0500
Subject: [PATCH] Revert "[cmake] Refactor clang unittest cmake (#133545)"

This reverts commit 5ffd9bdb50b5753bbf668e4eab3647dfb46cd0d6.
---
 clang/unittests/AST/ByteCode/CMakeLists.txt   | 12 +--
 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, 289 insertions(+), 162 deletions(-)

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

[clang] 558ce50 - [Clang][LLVM] Implement multi-single vectors MOP4{A/S} (#129226)

2025-04-01 Thread via cfe-commits

Author: Jonathan Thackray
Date: 2025-04-01T17:04:59+01:00
New Revision: 558ce50ebc31bbcd5ec5bfad0c0126adfde8bbb0

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

LOG: [Clang][LLVM] Implement multi-single vectors MOP4{A/S} (#129226)

Implement all multi-single {BF/F/S/U/SU/US}MOP4{A/S} instructions in clang and
llvm following the ACLE in https://github.com/ARM-software/acle/pull/381/files

Added: 
clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_mop4_2x1.c
llvm/test/CodeGen/AArch64/sme2-intrinsics-mop4a_2x1.ll

Modified: 
clang/include/clang/Basic/arm_sme.td
clang/test/Sema/aarch64-sme2p2-instrinsics/acle_sme2p2_imm.cpp
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/SMEInstrFormats.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 6312223f5d112..3958ed70f6ad0 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -295,6 +295,7 @@ defm SVMOPS : ZAFPOuterProd<"mops">;
 multiclass MOP4 
checks> {
   def _1x1 : Inst<"svmop4" # mode # "[_1x1]" # za # "[_{d}_{d}]", "vidd", t, 
MergeNone, i # "_1x1", [IsInOutZA, IsStreaming], checks>;
   def _1x2 : Inst<"svmop4" # mode # "[_1x2]" # za # "[_{d}_{d}]", "vid2", t, 
MergeNone, i # "_1x2", [IsInOutZA, IsStreaming], checks>;
+  def _2x1 : Inst<"svmop4" # mode # "[_2x1]" # za # "[_{d}_{d}]", "vi2d", t, 
MergeNone, i # "_2x1", [IsInOutZA, IsStreaming], checks>;
 }
 
 let SMETargetGuard = "sme2,sme-mop4" in {
@@ -350,6 +351,10 @@ multiclass SUMOP4 che
   "vid2.u", t, MergeNone, "aarch64_sme_sumop4" # 
mode # i # "_wide_1x2",
   [IsStreaming, IsInOutZA],
   checks>;
+  def _2x1 : SInst<"svmop4" # mode # "[_2x1]" # za # "[_{d}_{3}]",
+  "vi2u", t, MergeNone, "aarch64_sme_sumop4" # 
mode # i # "_wide_2x1",
+  [IsStreaming, IsInOutZA],
+  checks>;
 }
 
 multiclass USMOP4 
checks> {
@@ -361,6 +366,10 @@ multiclass USMOP4 che
   "vid2.x", t, MergeNone, "aarch64_sme_usmop4" # 
mode # i # "_wide_1x2",
   [IsStreaming, IsInOutZA],
   checks>;
+  def _2x1 : SInst<"svmop4" # mode # "[_2x1]" # za # "[_{d}_{3}]",
+  "vi2x", t, MergeNone, "aarch64_sme_usmop4" # 
mode # i # "_wide_2x1",
+  [IsStreaming, IsInOutZA],
+  checks>;
 }
 
 let SMETargetGuard = "sme2,sme-mop4" in {

diff  --git a/clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_mop4_2x1.c 
b/clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_mop4_2x1.c
new file mode 100644
index 0..e42ed95b9b52c
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_mop4_2x1.c
@@ -0,0 +1,304 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64 -target-feature +bf16 -target-feature 
+sme-mop4 -target-feature +sme-f16f16 -target-feature +sme-i16i64 
-target-feature +sme-b16b16 -target-feature +sme-f64f64 -target-feature +sme 
-target-feature +sme2 -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64 -target-feature 
+bf16 -target-feature +sme-mop4 -target-feature +sme-f16f16 -target-feature 
+sme-i16i64 -target-feature +sme-b16b16 -target-feature +sme-f64f64 
-target-feature +sme -target-feature +sme2 -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64 -target-feature +bf16 -target-feature 
+sme-mop4 -target-feature +sme-f16f16 -target-feature +sme-i16i64 
-target-feature +sme-b16b16 -target-feature +sme-f64f64 -target-feature +sme 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+
+#include 
+
+#ifdef SME_OVERLOADED_FORMS
+#define SME_ACLE_FUNC(A1,A2_UNUSED,A3, A4_UNUSED) A1##A3
+#else
+#define SME_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
+#endif
+
+// CHECK-LABEL: @test_svmop4a_2x1_za32_s8_s8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.smop4a.wide.2x1.nxv16i8(i32 
1,  [[ZN_COERCE0:%.*]],  
[[ZN_COERCE1:%.*]],  [[ZM:%.*]])
+// CHECK-NEXT:ret void
+//
+void test_svmop4a_2x1_za32_s8_s8(svint8x2_t zn, svint8_t zm) __arm_streaming 
__arm_inout("za") {
+  SME_ACLE_FUNC(svmop4a,_2x1,_za32,_s8_s8)(1, zn, zm);
+}
+
+// CHECK-LABEL: @test_svmop4s_2x1_za32_s8_s8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.s

[clang] 66b540d - [C11] Claim conformance to WG14 N1518 (#133749)

2025-04-01 Thread via cfe-commits

Author: Aaron Ballman
Date: 2025-04-01T11:45:56-04:00
New Revision: 66b540d861ecc5fef0fc398c9c3590c3a7dc6ff9

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

LOG: [C11] Claim conformance to WG14 N1518 (#133749)

This paper introduced ranges of valid start and continuation characters
for identifiers. C23 made further changes to these sets.

Added: 
clang/test/C/C11/n1518.c

Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/test/C/C11/n1518.c b/clang/test/C/C11/n1518.c
new file mode 100644
index 0..e950d22b20cf9
--- /dev/null
+++ b/clang/test/C/C11/n1518.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -verify=c11,both -std=c11 %s
+// RUN: %clang_cc1 -verify=c23,both -std=c23 %s
+
+/* WG14 N1518: Clang 15
+ * Recommendations for extended identifier characters for C and C++
+ *
+ * This paper effectively adopts UAX #31, which was later officially adopted
+ * for C23 via WG14 N2836 and supersedes N1518.
+ */
+
+// This file takes test cases from clang/test/C/C23/n2836_n2939.c.
+// This file contains Unicode characters; please do not "fix" them!
+
+// This was fine in C11, is now an error in C23.
+extern int ٢;  // c23-error {{character  not allowed at the start of 
an identifier}} \
+  c23-warning {{declaration does not declare anything}}
+
+// This was an error in C11 but is an extension in C23.
+extern int ∞;  // c11-error {{unexpected character }} \
+  c11-warning {{declaration does not declare anything}} \
+  c23-warning {{mathematical notation character  in an 
identifier is a Clang extension}}
+
+int \u1DC0;  // both-error {{expected identifier or '('}}
+int e\u1DC0; // Ok

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index f4f00ac6dd808..8434ed9ecf6f8 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -1105,7 +1105,7 @@ C11 implementation status
 
   Recommendations for extended identifier characters for C and C++
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1518.htm";>N1518
-  Unknown
+  Clang 15
 
 
   Atomic C1x/C++0x compatibility refinements (1st part only)



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


[libclc] 00e6d4f - [libclc][NFC] Delete three unused .inc files

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

Author: Fraser Cormack
Date: 2025-04-01T17:36:01+01:00
New Revision: 00e6d4fe064bb48e16c1eda018e6ed5e9f99cba9

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

LOG: [libclc][NFC] Delete three unused .inc files

Added: 


Modified: 


Removed: 
libclc/generic/lib/clc_unary.inc
libclc/generic/lib/math/binary_impl.inc
libclc/generic/lib/math/clc_sw_binary.inc



diff  --git a/libclc/generic/lib/clc_unary.inc 
b/libclc/generic/lib/clc_unary.inc
deleted file mode 100644
index 702ddd4c0da8b..0
--- a/libclc/generic/lib/clc_unary.inc
+++ /dev/null
@@ -1,11 +0,0 @@
-//===--===//
-//
-// 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
-//
-//===--===//
-
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNC(__CLC_GENTYPE x) {
-  return __CLC_IMPL_FUNC(x);
-}

diff  --git a/libclc/generic/lib/math/binary_impl.inc 
b/libclc/generic/lib/math/binary_impl.inc
deleted file mode 100644
index e7637d991cdeb..0
--- a/libclc/generic/lib/math/binary_impl.inc
+++ /dev/null
@@ -1,29 +0,0 @@
-//===--===//
-//
-// 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_SCALAR
-
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x, __CLC_GENTYPE 
y) {
-  return FUNCTION_IMPL(x, y);
-}
-
-#endif
-
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x, float y) {
-  __CLC_GENTYPE vec_y = (__CLC_GENTYPE) (y);
-  return FUNCTION_IMPL(x, vec_y);
-}
-
-#ifdef cl_khr_fp64
-
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x, double y) {
-  __CLC_GENTYPE vec_y = (__CLC_GENTYPE) (y);
-  return FUNCTION_IMPL(x, vec_y);
-}
-
-#endif

diff  --git a/libclc/generic/lib/math/clc_sw_binary.inc 
b/libclc/generic/lib/math/clc_sw_binary.inc
deleted file mode 100644
index fb787c2e2df2d..0
--- a/libclc/generic/lib/math/clc_sw_binary.inc
+++ /dev/null
@@ -1,34 +0,0 @@
-//===--===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include 
-
-#define __CLC_SW_FUNC(x) __CLC_CONCAT(__clc_, x)
-
-#if __CLC_FPSIZE > 16
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNC(__CLC_GENTYPE x, __CLC_GENTYPE 
y) {
-  return __CLC_SW_FUNC(__CLC_FUNC)(x, y);
-}
-#elif __CLC_FPSIZE == 16
-#ifdef __CLC_SCALAR
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNC(__CLC_GENTYPE x,
-__CLC_GENTYPE y) {
-  return convert_half(
-  __CLC_SW_FUNC(__CLC_FUNC)(convert_float(x), convert_float(y)));
-}
-#else
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNC(__CLC_GENTYPE x,
-__CLC_GENTYPE y) {
-  return __CLC_XCONCAT(convert_half, __CLC_VECSIZE)(__CLC_SW_FUNC(__CLC_FUNC)(
-  __CLC_XCONCAT(convert_float, __CLC_VECSIZE)(x),
-  __CLC_XCONCAT(convert_float, __CLC_VECSIZE)(y)));
-}
-#endif
-#endif
-
-#undef __CLC_SW_FUNC



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


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

2025-04-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fix #133873

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


2 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+5-1) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+5) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index f7712bea01c2c..213b706807b2a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1887,8 +1887,11 @@ void UnwrappedLineParser::parseStructuralElement(
   if (FormatTok->isBinaryOperator())
 nextToken();
   break;
-case tok::caret:
+case tok::caret: {
+  const auto *Prev = FormatTok->getPreviousNonComment();
   nextToken();
+  if (Prev && Prev->is(tok::identifier))
+break;
   // Block return type.
   if (FormatTok->Tok.isAnyIdentifier() || FormatTok->isTypeName(LangOpts)) 
{
 nextToken();
@@ -1903,6 +1906,7 @@ void UnwrappedLineParser::parseStructuralElement(
   if (FormatTok->is(tok::l_brace))
 parseChildBlock();
   break;
+}
 case tok::l_brace:
   if (InRequiresExpression)
 FormatTok->setFinalizedType(TT_BracedListLBrace);
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index af9fd574b068c..7e0af1c7b4c36 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3622,6 +3622,11 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
   EXPECT_BRACE_KIND(Tokens[7], BK_BracedInit);
   EXPECT_BRACE_KIND(Tokens[9], BK_BracedInit);
+
+  Tokens = annotate("return lhs ^ Byte{rhs};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[4], BK_BracedInit);
+  EXPECT_BRACE_KIND(Tokens[6], BK_BracedInit);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {

``




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


[clang] [clang] Do not infer lifetimebound for functions with void return type (PR #131997)

2025-04-01 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#133997

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


[clang] [llvm] Remove Native Client support (PR #133661)

2025-04-01 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> Thanks for working on this! This will be the first time I'm not going to 
> oppose an effort to remove Native Client support 🎉 Although I am going to ask 
> you to wait a couple of months to land it, until we finally turn it off for 
> good and start deleting the support code from Chromium. This is planned after 
> the M139 branch in late June. I will also give this a good review.

Thanks!

After this change goes through, we should look to eliminate the 
BundleAlignSize/`.bundle_align_mode` logic. This assembler code has introduced 
considerable difficulties when attempting to improve the MCAssembler, 
especially in functions like `ensureValid` and `MCELFStreamer::emitInstToData` 
where the layout calculation and bundling logic have shown to be particularly 
complex. 

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


[clang] Revert "[cmake] Refactor clang unittest cmake" (PR #134022)

2025-04-01 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy][C++20] Add support for Initialization Forwarding in structs and Nested Objects within modernize-use-emplace (PR #131969)

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

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

>From 89412d91ff6cd38a8060c84f66bbab3caead2478 Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Sun, 16 Mar 2025 16:20:16 -0400
Subject: [PATCH] [clang-tidy] Add support for Initialization Forwarding in
 Nested Objects within modernize-use-emplace

---
 .../clang-tidy/modernize/UseEmplaceCheck.cpp  | 105 +++---
 clang-tools-extra/docs/ReleaseNotes.rst   |   4 +
 .../checkers/modernize/use-emplace.cpp|  48 ++--
 3 files changed, 132 insertions(+), 25 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
index 430455a38f395..6f9875674448d 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -98,8 +98,8 @@ auto hasWantedType(llvm::ArrayRef TypeNames) {
 
 // Matches member call expressions of the named method on the listed container
 // types.
-auto cxxMemberCallExprOnContainer(
-StringRef MethodName, llvm::ArrayRef ContainerNames) {
+auto cxxMemberCallExprOnContainer(StringRef MethodName,
+  llvm::ArrayRef ContainerNames) {
   return cxxMemberCallExpr(
   hasDeclaration(functionDecl(hasName(MethodName))),
   on(hasTypeOrPointeeType(hasWantedType(ContainerNames;
@@ -174,19 +174,19 @@ void UseEmplaceCheck::registerMatchers(MatchFinder 
*Finder) {
   // passed pointer because smart pointer won't be constructed
   // (and destructed) as in push_back case.
   auto IsCtorOfSmartPtr =
-  hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(SmartPointers;
+  cxxConstructorDecl(ofClass(hasAnyName(SmartPointers)));
 
   // Bitfields binds only to consts and emplace_back take it by universal ref.
-  auto BitFieldAsArgument = hasAnyArgument(
-  ignoringImplicit(memberExpr(hasDeclaration(fieldDecl(isBitField());
+  auto BitFieldAsArgument =
+  ignoringImplicit(memberExpr(hasDeclaration(fieldDecl(isBitField();
 
   // Initializer list can't be passed to universal reference.
-  auto InitializerListAsArgument = hasAnyArgument(
+  auto InitializerListAsArgument =
   ignoringImplicit(allOf(cxxConstructExpr(isListInitialization()),
- unless(cxxTemporaryObjectExpr();
+ unless(cxxTemporaryObjectExpr(;
 
   // We could have leak of resource.
-  auto NewExprAsArgument = hasAnyArgument(ignoringImplicit(cxxNewExpr()));
+  auto NewExprAsArgument = ignoringImplicit(cxxNewExpr());
   // We would call another constructor.
   auto ConstructingDerived =
   hasParent(implicitCastExpr(hasCastKind(CastKind::CK_DerivedToBase)));
@@ -202,11 +202,26 @@ void UseEmplaceCheck::registerMatchers(MatchFinder 
*Finder) {
   // overloaded functions and template names.
   auto SoughtConstructExpr =
   cxxConstructExpr(
-  unless(anyOf(IsCtorOfSmartPtr, HasInitList, BitFieldAsArgument,
-   InitializerListAsArgument, NewExprAsArgument,
-   ConstructingDerived, IsPrivateOrProtectedCtor)))
+  unless(anyOf(hasDeclaration(IsCtorOfSmartPtr), HasInitList,
+   hasAnyArgument(BitFieldAsArgument),
+   hasAnyArgument(InitializerListAsArgument),
+   hasAnyArgument(NewExprAsArgument), ConstructingDerived,
+   IsPrivateOrProtectedCtor)))
   .bind("ctor");
-  auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
+
+  auto IsPrimitiveType = hasType(builtinType());
+
+  auto AggregateInitExpr =
+  getLangOpts().CPlusPlus20
+  ? initListExpr(unless(anyOf(HasInitList, has(IsCtorOfSmartPtr),
+  has(BitFieldAsArgument),
+  has(InitializerListAsArgument),
+  has(NewExprAsArgument), 
IsPrimitiveType)))
+.bind("agg_init")
+  : unless(anything());
+
+  auto HasConstructExpr =
+  has(ignoringImplicit(anyOf(SoughtConstructExpr, AggregateInitExpr)));
 
   // allow for T{} to be replaced, even if no CTOR is declared
   auto HasConstructInitListExpr = has(initListExpr(
@@ -305,6 +320,36 @@ void UseEmplaceCheck::registerMatchers(MatchFinder 
*Finder) {
   this);
 }
 
+static const CXXConstructExpr *unwrapToConstructorExpr(const Expr *E) {
+
+  while (E) {
+
+if (const auto *ConstructorExpr = llvm::dyn_cast(E)) {
+  return ConstructorExpr;
+}
+
+if (const auto *BindTemp = llvm::dyn_cast(E)) {
+  E = BindTemp->getSubExpr();
+  continue;
+}
+
+if (const auto *MaterialTemp =
+llvm::dyn_cast(E)) {
+  E = MaterialTemp->getSubExpr();
+  continue;
+}
+
+if (const auto *Cast = llvm::dyn_cast(E)) {
+  E = Cast->getSubExpr();
+  continue;
+}
+
+break;
+  }
+
+  return nullp

[clang] [clang][ExtractAPI] emit correct spelling for type aliases (PR #134007)

2025-04-01 Thread Erick Velez via cfe-commits

https://github.com/evelez7 created 
https://github.com/llvm/llvm-project/pull/134007

Previously, C++11 type aliases were serialized using "typedef" regardless of 
the source spelling.
This checks if the TypedefNameDecl is actually a TypeAliasDecl and corrects the 
spelling.

>From 28879073b9d59dffa13f9523b4c9ec677b3a7b9c Mon Sep 17 00:00:00 2001
From: Erick Velez 
Date: Tue, 1 Apr 2025 16:20:44 -0700
Subject: [PATCH] [clang][ExtractAPI] emit correct spelling for type aliases

Previously, C++11 type aliases were serialized using "typedef"
regardless of the source spelling.
This checks if the TypedefNameDecl is actually a TypeAliasDecl and
corrects the spelling.
---
 clang/lib/ExtractAPI/DeclarationFragments.cpp | 26 ++---
 clang/test/ExtractAPI/type-alias.cpp  | 56 +++
 2 files changed, 75 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/ExtractAPI/type-alias.cpp

diff --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp 
b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index d7eebcbc3c2f9..80174e30ffd1a 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -1584,13 +1584,25 @@ DeclarationFragments 
DeclarationFragmentsBuilder::getFragmentsForObjCProtocol(
 DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForTypedef(
 const TypedefNameDecl *Decl) {
   DeclarationFragments Fragments, After;
-  Fragments.append("typedef", DeclarationFragments::FragmentKind::Keyword)
-  .appendSpace()
-  .append(getFragmentsForType(Decl->getUnderlyingType(),
-  Decl->getASTContext(), After))
-  .append(std::move(After))
-  .appendSpace()
-  .append(Decl->getName(), DeclarationFragments::FragmentKind::Identifier);
+  if (!isa(Decl))
+Fragments.append("typedef", DeclarationFragments::FragmentKind::Keyword)
+.appendSpace()
+.append(getFragmentsForType(Decl->getUnderlyingType(),
+Decl->getASTContext(), After))
+.append(std::move(After))
+.appendSpace()
+.append(Decl->getName(),
+DeclarationFragments::FragmentKind::Identifier);
+  else
+Fragments.append("using", DeclarationFragments::FragmentKind::Keyword)
+.appendSpace()
+.append(Decl->getName(), 
DeclarationFragments::FragmentKind::Identifier)
+.appendSpace()
+.append("=", DeclarationFragments::FragmentKind::Text)
+.appendSpace()
+.append(getFragmentsForType(Decl->getUnderlyingType(),
+Decl->getASTContext(), After))
+.append(std::move(After));
 
   return Fragments.appendSemicolon();
 }
diff --git a/clang/test/ExtractAPI/type-alias.cpp 
b/clang/test/ExtractAPI/type-alias.cpp
new file mode 100644
index 0..246e8fbb92156
--- /dev/null
+++ b/clang/test/ExtractAPI/type-alias.cpp
@@ -0,0 +1,56 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -extract-api --pretty-sgf 
--emit-sgf-symbol-labels-for-testing \
+// RUN:   --product-name=TypeAlias -triple arm64-apple-macosx -x c++-header %s 
-o %t/type-alias.symbols.json -verify
+
+// RUN: FileCheck %s --input-file %t/type-alias.symbols.json --check-prefix 
MYALIAS
+using MyAlias = int;
+//MYALIAS-LABEL "!testLabel": "c:@MYALIAS"
+//MYALIAS:   "accessLevel": "public",
+//MYALIAS:   "declarationFragments": [
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "keyword",
+//MYALIAS-NEXT:  "spelling": "using"
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "text",
+//MYALIAS-NEXT:  "spelling": " "
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "identifier",
+//MYALIAS-NEXT:  "spelling": "MyAlias"
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "text",
+//MYALIAS-NEXT:  "spelling": " = "
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "typeIdentifier",
+//MYALIAS-NEXT:  "preciseIdentifier": "c:I",
+//MYALIAS-NEXT:  "spelling": "int"
+//MYALIAS-NEXT:},
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "text",
+//MYALIAS-NEXT:  "spelling": ";"
+//MYALIAS-NEXT:}
+//MYALIAS:   "kind": {
+//MYALIAS-NEXT:  "displayName": "Type Alias",
+//MYALIAS-NEXT:  "identifier": "c++.typealias"
+//MYALIAS:   names": {
+//MYALIAS-NEXT:"navigator": [
+//MYALIAS-NEXT:  {
+//MYALIAS-NEXT:"kind": "identifier",
+//MYALIAS-NEXT:"spelling": "MyAlias"
+//MYALIAS-NEXT:  }
+//MYALIAS-NEXT:],
+//MYALIAS-NEXT:  "subHeading": [
+//MYALIAS-NEXT:{
+//MYALIAS-NEXT:  "kind": "identifier",
+//MYALIAS-NEXT:  "spelling": "MyAlias"
+//MYALIAS-NEXT:}
+//MYALIAS-NEXT:],
+//MYALIAS-NEXT:"title": "MyAlias"
+//MYALIAS:   "pathComponents": [
+//MYALIAS-NEXT:"MyAlias"
+//MYALIAS-NEXT:  ]
+
+// expected-no-diagnostics
\ No newline at end of file


[clang] [clang-tools-extra] [Clang] [Sema] Make -Wreturn-type an error by default (PR #131207)

2025-04-01 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/131207

>From bff3db4f6a7fdff572b662048f395c280a11d94b Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Thu, 13 Mar 2025 21:18:14 +0100
Subject: [PATCH 1/3] [Clang] [Sema] Make -Wreturn-type an error by default

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 clang/test/Index/warning-flags.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8e6e6e892cdd7..113e684a53c2b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -722,7 +722,7 @@ def warn_falloff_nonvoid : Warning<
   "non-void "
   
"%enum_select{%Function{function}|%Block{block}|%Lambda{lambda}|%Coroutine{coroutine}}0"
   " does not return a value%select{| in all control paths}1">,
-  InGroup;
+  InGroup, DefaultError;
 def err_falloff_nonvoid : Error<
   "non-void %select{function|block|lambda|coroutine}0 "
   "does not return a value%select{| in all control paths}1">;
diff --git a/clang/test/Index/warning-flags.c b/clang/test/Index/warning-flags.c
index 1694c6abab562..3229f000c4ae0 100644
--- a/clang/test/Index/warning-flags.c
+++ b/clang/test/Index/warning-flags.c
@@ -9,7 +9,7 @@ int *bar(float *f) { return f; }
 // RUN: c-index-test -test-load-source-reparse 5 all -w %s 2>&1 | FileCheck 
-check-prefix=NOWARNINGS %s
 // RUN: c-index-test -test-load-source all -w -O4 %s 2>&1 | FileCheck 
-check-prefix=NOWARNINGS %s
 
-// CHECK-BOTH-WARNINGS: warning: non-void function does not return a value
+// CHECK-BOTH-WARNINGS: error: non-void function does not return a value
 // CHECK-BOTH-WARNINGS: warning: incompatible pointer types returning 'float 
*' from a function with result type 'int *'
 
 // CHECK-SECOND-WARNING-NOT:non-void function does not return a value

>From a8523d15a4c790fe1fb58a6fe41da571cb11ba47 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Tue, 18 Mar 2025 17:52:36 +0100
Subject: [PATCH 2/3] Fix clang-tidy warning

---
 .../test/clang-tidy/checkers/misc/unused-using-decls.cpp| 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
index 62aa17b0b1c22..40451167c5809 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
@@ -233,7 +233,7 @@ namespace my_literals {
 
 using my_literals::operator"" _r;
 
-int foo() {
+void foo() {
   auto x2 = 123_r;
 }
 

>From f830db193424913aec7e355d39af68de8560adfb Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 19 Mar 2025 19:13:01 +0100
Subject: [PATCH 3/3] Add release note

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8989124611e66..1d81b5e191e89 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -38,6 +38,7 @@ Potentially Breaking Changes
 - Fix missing diagnostics for uses of declarations when performing typename 
access,
   such as when performing member access on a '[[deprecated]]' type alias.
   (#GH58547)
+- The `-Wreturn-type` warning now defaults to an error in all language modes.
 
 C/C++ Language Potentially Breaking Changes
 ---

___
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-01 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
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] [flang] [llvm] [flang-rt] Pass the whole path of libflang_rt.runtime.a to linker on AIX (PR #131041)

2025-04-01 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,38 @@
+!! Testing ld command with flang on POWERPC.
+
+!! Because flang-rt currently only supports
+!! LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON, use 
+!! resource_dir_with_per_target_subdir as inputs.
+
+! Check powerpc64-ibm-aix 64-bit linking to static flang-rt
+! RUN: %flang %s -### 2>&1 \
+! RUN:--target=powerpc64-ibm-aix \
+! RUN:
-resource-dir=%S/../../../clang/test/Driver/Inputs/resource_dir_with_per_target_subdir
 \
+! RUN:   | FileCheck %s --check-prefix=AIX64-LD-PER-TARGET
+
+! AIX64-LD-PER-TARGET-NOT: warning:
+! AIX64-LD-PER-TARGET: "-fc1" "-triple" "powerpc64-ibm-aix"

MaskRay wrote:

Use -SAME whenever applicable

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] [RFC] Initial implementation of P2719 (PR #113510)

2025-04-01 Thread Oliver Hunt via cfe-commits


@@ -3096,6 +3096,29 @@ bool Type::isStdByteType() const {
   return false;
 }
 
+TemplateDecl *Type::getSpecializedTemplateDecl() const {
+  const auto *DesugaredType = getUnqualifiedDesugaredType();
+  if (auto *Specialization = 
DesugaredType->getAs())
+return Specialization->getTemplateName().getAsTemplateDecl();
+  if (const auto *Record = DesugaredType->getAsCXXRecordDecl()) {
+if (auto *CTS = dyn_cast(Record))

ojhunt wrote:

Code is gone after endless refactoring :D

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-04-01 Thread Oliver Hunt via cfe-commits


@@ -1392,7 +1393,13 @@ static UsualDeleteParams getUsualDeleteParams(const 
FunctionDecl *FD) {
   const FunctionProtoType *FPT = FD->getType()->castAs();
   auto AI = FPT->param_type_begin(), AE = FPT->param_type_end();
 
-  // The first argument is always a void*.
+  if (FD->isTypeAwareOperatorNewOrDelete()) {
+Params.TypeAwareDelete = TypeAwareAllocationMode::Yes;
+assert(AI != AE);
+++AI;
+  }
+
+  // The first non-type argument is always a void*.

ojhunt wrote:

fixed this comment to use the spec term "the type-identity parameter"




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


[clang] [HLSL] Update __builtin_hlsl_dot builtin Sema Checking to fix error when passed an array literal 1u.xxxx (PR #133941)

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

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

LGTM. 

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


[clang] default clause replaced by otherwise clause for metadirective in OpenMP 5.2 (PR #128640)

2025-04-01 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,c -- 
clang/lib/Parse/ParseOpenMP.cpp clang/test/OpenMP/metadirective_ast_print.c 
clang/test/OpenMP/metadirective_messages.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 21474712b..89c5750d6 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2764,8 +2764,7 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 Diag(Tok, diag::err_omp_unknown_clause)
 << PP.getSpelling(Tok) << "metadirective";
   }
-  if (getLangOpts().OpenMP < 52 &&
-  CKind == OMPC_otherwise) {
+  if (getLangOpts().OpenMP < 52 && CKind == OMPC_otherwise) {
 Diag(Tok, diag::err_omp_unexpected_clause)
 << PP.getSpelling(Tok) << "metadirective";
   }

``




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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-04-01 Thread Oliver Hunt via cfe-commits


@@ -16110,6 +16128,127 @@ bool Sema::CompleteConstructorCall(CXXConstructorDecl 
*Constructor,
   return Invalid;
 }
 
+bool Sema::IsTypeIdentitySpecialization(QualType Type) const {
+  auto *TypeIdentity = getStdTypeIdentity();
+  if (!TypeIdentity)
+return false;
+  auto *SpecializedDecl = Type->getSpecializedTemplateDecl();
+  return TypeIdentity == SpecializedDecl;
+}
+
+bool Sema::IsTypeAwareOperatorNewOrDelete(const FunctionDecl *FnDecl) const {
+  // Type aware operators
+  if (FnDecl->getNumParams() < 2)
+return false;
+  const auto *ParamDecl = FnDecl->getParamDecl(0);
+  return IsTypeIdentitySpecialization(ParamDecl->getType());
+}
+
+bool Sema::IsTypeAwareOperatorNewOrDelete(
+const FunctionTemplateDecl *FTD) const {
+  return IsTypeAwareOperatorNewOrDelete(FTD->getTemplatedDecl());
+}
+
+bool Sema::IsTypeAwareOperatorNewOrDelete(const NamedDecl *ND) const {
+  if (auto *FTD = dyn_cast(ND))
+return IsTypeAwareOperatorNewOrDelete(FTD->getTemplatedDecl());
+  if (auto *FnDecl = dyn_cast(ND))
+return IsTypeAwareOperatorNewOrDelete(FnDecl);
+  return false;
+}
+
+std::optional
+Sema::InstantiateTypeAwareUsualDelete(FunctionTemplateDecl *FnTemplateDecl,
+  QualType DeallocType) {
+  if (!AllowTypeAwareAllocators())
+return std::nullopt;
+
+  auto TemplateParameters = FnTemplateDecl->getTemplateParameters();

ojhunt wrote:

Done.




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


  1   2   >