[clang-tools-extra] 94bb9e1 - [clang-doc] Serialize record files with mangled name (#148021)

2025-07-11 Thread via cfe-commits

Author: Erick Velez
Date: 2025-07-11T13:39:41-07:00
New Revision: 94bb9e12ec4ec243aac747910c5ae6359f354642

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

LOG: [clang-doc] Serialize record files with mangled name (#148021)

This patch changes JSON file serialization. Now, files are serialized
to a single directory instead of nesting them based on namespaces. The
global namespace retains the "index.json" name.

This solves the problem of class template specializations being serialized to 
the
same file as its base template. This is also planned as part of
future integration with the Mustache generator which will consume the JSON 
files.

Added: 
clang-tools-extra/test/clang-doc/json/class-specialization.cpp

Modified: 
clang-tools-extra/clang-doc/BitcodeReader.cpp
clang-tools-extra/clang-doc/BitcodeWriter.cpp
clang-tools-extra/clang-doc/BitcodeWriter.h
clang-tools-extra/clang-doc/JSONGenerator.cpp
clang-tools-extra/clang-doc/Representation.cpp
clang-tools-extra/clang-doc/Representation.h
clang-tools-extra/clang-doc/Serialize.cpp
clang-tools-extra/test/clang-doc/json/class-requires.cpp
clang-tools-extra/test/clang-doc/json/class-template.cpp
clang-tools-extra/test/clang-doc/json/class.cpp
clang-tools-extra/test/clang-doc/json/compound-constraints.cpp
clang-tools-extra/test/clang-doc/json/concept.cpp
clang-tools-extra/test/clang-doc/json/function-requires.cpp
clang-tools-extra/test/clang-doc/json/function-specifiers.cpp
clang-tools-extra/test/clang-doc/json/method-template.cpp
clang-tools-extra/test/clang-doc/json/namespace.cpp
clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index f756ae6d897c8..dce34a8434ff8 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -180,6 +180,8 @@ static llvm::Error parseRecord(const Record &R, unsigned ID,
 return decodeRecord(R, I->TagType, Blob);
   case RECORD_IS_TYPE_DEF:
 return decodeRecord(R, I->IsTypeDef, Blob);
+  case RECORD_MANGLED_NAME:
+return decodeRecord(R, I->MangledName, Blob);
   default:
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"invalid field for RecordInfo");

diff  --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp 
b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
index 3cc0d4ad332f0..eed23726e17bf 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -189,6 +189,7 @@ static const llvm::IndexedMap
   {RECORD_LOCATION, {"Location", &genLocationAbbrev}},
   {RECORD_TAG_TYPE, {"TagType", &genIntAbbrev}},
   {RECORD_IS_TYPE_DEF, {"IsTypeDef", &genBoolAbbrev}},
+  {RECORD_MANGLED_NAME, {"MangledName", &genStringAbbrev}},
   {BASE_RECORD_USR, {"USR", &genSymbolIdAbbrev}},
   {BASE_RECORD_NAME, {"Name", &genStringAbbrev}},
   {BASE_RECORD_PATH, {"Path", &genStringAbbrev}},
@@ -271,7 +272,8 @@ static const std::vector>>
 // Record Block
 {BI_RECORD_BLOCK_ID,
  {RECORD_USR, RECORD_NAME, RECORD_PATH, RECORD_DEFLOCATION,
-  RECORD_LOCATION, RECORD_TAG_TYPE, RECORD_IS_TYPE_DEF}},
+  RECORD_LOCATION, RECORD_TAG_TYPE, RECORD_IS_TYPE_DEF,
+  RECORD_MANGLED_NAME}},
 // BaseRecord Block
 {BI_BASE_RECORD_BLOCK_ID,
  {BASE_RECORD_USR, BASE_RECORD_NAME, BASE_RECORD_PATH,
@@ -616,6 +618,7 @@ void ClangDocBitcodeWriter::emitBlock(const RecordInfo &I) {
   emitRecord(I.USR, RECORD_USR);
   emitRecord(I.Name, RECORD_NAME);
   emitRecord(I.Path, RECORD_PATH);
+  emitRecord(I.MangledName, RECORD_MANGLED_NAME);
   for (const auto &N : I.Namespace)
 emitBlock(N, FieldId::F_namespace);
   for (const auto &CI : I.Description)

diff  --git a/clang-tools-extra/clang-doc/BitcodeWriter.h 
b/clang-tools-extra/clang-doc/BitcodeWriter.h
index d09ec4ca34006..501af12582a8e 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.h
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.h
@@ -126,6 +126,7 @@ enum RecordId {
   RECORD_LOCATION,
   RECORD_TAG_TYPE,
   RECORD_IS_TYPE_DEF,
+  RECORD_MANGLED_NAME,
   BASE_RECORD_USR,
   BASE_RECORD_NAME,
   BASE_RECORD_PATH,

diff  --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp 
b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 0e1a0cc347e45..6fdc7196e9095 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -386,6 +386,7 @@ static void serializeInfo(const RecordInfo &I, json::O

[clang-tools-extra] [clang-doc] Serialize record files with mangled name (PR #148021)

2025-07-11 Thread Erick Velez via cfe-commits

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


[clang] [llvm] [libclang][Cygwin] Provide unversioned DLL file alongside versioned one (PR #147132)

2025-07-11 Thread Tomohiro Kashiwada via cfe-commits

kikairoya wrote:

> I tested this and it broke things for me. This turns cygLLVM-20.dll into a 
> symlink, this doesn't work with existing binaries because DLLs in the import 
> table can't follow the Cygwin symlinks (they're loaded by the Windows 
> loader). It looks like for new binaries it does end up linking to 
> cygLLVM-20.1.dll which is the actual file.

Thank you for testing.
Then, cygLLVM-20.dll must be a regular file.
Other DLLs should also provide a regular file without minor version. I think 
existing binaries will be broken at every minor version up of LLVM.

> Also, I may have screwed something up, but I'm not getting the libclang 
> symlink in the install (only in the build dir).

Oops. I'll retry.


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


[clang] 15d36aa - [clang][CodeGen] Preserve addrspace of enqueue_kernel builtin. (#148062)

2025-07-11 Thread via cfe-commits

Author: jofrn
Date: 2025-07-11T17:00:28-04:00
New Revision: 15d36aa4ce6f78579c6a6a44226502621bb0c241

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

LOG: [clang][CodeGen] Preserve addrspace of enqueue_kernel builtin. (#148062)

__enqueue_kernel_varargs' last parameter is in addrspace(5), but CodeGen
currently misses this qualifier. This commit fixes the code to preserve
the qualifier by referencing Alloca, which has its casts removed, rather
than TmpPtr.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 48c91eb4a5b4f..5f2eb76e7bacb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5987,8 +5987,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   auto *Zero = llvm::ConstantInt::get(IntTy, 0);
   for (unsigned I = First; I < NumArgs; ++I) {
 auto *Index = llvm::ConstantInt::get(IntTy, I - First);
-auto *GEP = Builder.CreateGEP(Tmp.getElementType(), TmpPtr,
-  {Zero, Index});
+auto *GEP =
+Builder.CreateGEP(Tmp.getElementType(), Alloca, {Zero, Index});
 if (I == First)
   ElemPtr = GEP;
 auto *V =

diff  --git a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl 
b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
index bbb55b7e14941..bfbed79dc7f16 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
@@ -209,9 +209,9 @@ kernel void test_target_features_kernel(global int *i) {
 // NOCPU-NEXT:[[BLOCK_CAPTURED19:%.*]] = getelementptr inbounds nuw <{ 
i32, i32, ptr, ptr addrspace(1), ptr addrspace(1), i64, i8 }>, ptr 
[[BLOCK12_ASCAST]], i32 0, i32 5
 // NOCPU-NEXT:[[TMP17:%.*]] = load i64, ptr [[D_ADDR_ASCAST]], align 8
 // NOCPU-NEXT:store i64 [[TMP17]], ptr [[BLOCK_CAPTURED19]], align 8
-// NOCPU-NEXT:[[TMP18:%.*]] = getelementptr [1 x i64], ptr 
[[BLOCK_SIZES_ASCAST]], i32 0, i32 0
-// NOCPU-NEXT:store i64 100, ptr [[TMP18]], align 8
-// NOCPU-NEXT:[[TMP19:%.*]] = call i32 @__enqueue_kernel_varargs(ptr 
addrspace(1) [[TMP12]], i32 [[TMP13]], ptr addrspace(5) [[VARTMP11]], ptr 
addrspacecast (ptr addrspace(1) @__test_block_invoke_3_kernel.runtime.handle to 
ptr), ptr [[BLOCK12_ASCAST]], i32 1, ptr [[TMP18]])
+// NOCPU-NEXT:[[TMP18:%.*]] = getelementptr [1 x i64], ptr addrspace(5) 
[[BLOCK_SIZES]], i32 0, i32 0
+// NOCPU-NEXT:store i64 100, ptr addrspace(5) [[TMP18]], align 8
+// NOCPU-NEXT:[[TMP19:%.*]] = call i32 @__enqueue_kernel_varargs(ptr 
addrspace(1) [[TMP12]], i32 [[TMP13]], ptr addrspace(5) [[VARTMP11]], ptr 
addrspacecast (ptr addrspace(1) @__test_block_invoke_3_kernel.runtime.handle to 
ptr), ptr [[BLOCK12_ASCAST]], i32 1, ptr addrspace(5) [[TMP18]])
 // NOCPU-NEXT:[[BLOCK_SIZE22:%.*]] = getelementptr inbounds nuw <{ i32, 
i32, ptr, i64, ptr addrspace(1) }>, ptr [[BLOCK21_ASCAST]], i32 0, i32 0
 // NOCPU-NEXT:store i32 32, ptr [[BLOCK_SIZE22]], align 8
 // NOCPU-NEXT:[[BLOCK_ALIGN23:%.*]] = getelementptr inbounds nuw <{ i32, 
i32, ptr, i64, ptr addrspace(1) }>, ptr [[BLOCK21_ASCAST]], i32 0, i32 1
@@ -587,9 +587,9 @@ kernel void test_target_features_kernel(global int *i) {
 // GFX900-NEXT:[[TMP17:%.*]] = load i64, ptr [[D_ADDR_ASCAST]], align 8, 
!tbaa [[TBAA3]]
 // GFX900-NEXT:store i64 [[TMP17]], ptr [[BLOCK_CAPTURED19]], align 8, 
!tbaa [[TBAA3]]
 // GFX900-NEXT:call void @llvm.lifetime.start.p5(i64 8, ptr addrspace(5) 
[[BLOCK_SIZES]]) #[[ATTR9]]
-// GFX900-NEXT:[[TMP18:%.*]] = getelementptr [1 x i64], ptr 
[[BLOCK_SIZES_ASCAST]], i32 0, i32 0
-// GFX900-NEXT:store i64 100, ptr [[TMP18]], align 8
-// GFX900-NEXT:[[TMP19:%.*]] = call i32 @__enqueue_kernel_varargs(ptr 
addrspace(1) [[TMP12]], i32 [[TMP13]], ptr addrspace(5) [[VARTMP11]], ptr 
addrspacecast (ptr addrspace(1) @__test_block_invoke_3_kernel.runtime.handle to 
ptr), ptr [[BLOCK12_ASCAST]], i32 1, ptr [[TMP18]])
+// GFX900-NEXT:[[TMP18:%.*]] = getelementptr [1 x i64], ptr addrspace(5) 
[[BLOCK_SIZES]], i32 0, i32 0
+// GFX900-NEXT:store i64 100, ptr addrspace(5) [[TMP18]], align 8
+// GFX900-NEXT:[[TMP19:%.*]] = call i32 @__enqueue_kernel_varargs(ptr 
addrspace(1) [[TMP12]], i32 [[TMP13]], ptr addrspace(5) [[VARTMP11]], ptr 
addrspacecast (ptr addrspace(1) @__test_block_invoke_3_kernel.runtime.handle to 
ptr), ptr [[BLOCK12_ASCAST]], i32 1, ptr addrspace(5) [[TMP18]])
 // GFX900-NEXT:call void @llvm.lifetime.end.p5(i64 8, ptr addrspace(5) 
[[BLOCK_SIZES]]) #[[ATTR9]]
 // GFX900-NEXT:call void @llvm.lifetime.start.p5(i64 8

[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Thurston Dang via cfe-commits

thurstond wrote:

> Complements [this feature](https://github.com/llvm/llvm-project/pull/141997); 
> adds a synthetic inline frame named __clang_trap_msg$$ 
> in debug info. [stub, since I'm not 100% sure on this and kind of just 
> repeats what's already been stated in the first paragraph].

AFAICS the key differences are:
- -fsanitize-annotate-debug-info (tries to) annotate all the UBSan-added 
instructions, not just the final (trap) instruction; this makes it useful for 
profiling. It works with all the UBSan modes (trap, min-rt, full rt). 
Additionally, it will use the precise SanitizerOrdinal name if available, only 
falling back to the SanitizerHandler name if it is ambiguous.
- trap reasons annotates only the trap instruction and always uses the 
SanitizerHandler information. The benefits are it has more informative messages 
and it integrates well with LLDB's frame recognizer.

(I'm not suggesting you need to put all this in the commit message; this 
comment is largely to +1 that these features are complementary.)


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


[clang] [clang-tools-extra] [lldb] [llvm] [mlir] Fix typos 'seperate' -> 'separate' (NFC) (PR #144368)

2025-07-11 Thread via cfe-commits

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


[clang] [WIP][DO NOT MERGE][Clang][Driver] Emit warning when -fsanitize-trap=<...> is passed without associated -fsanitize=<...> (PR #147997)

2025-07-11 Thread Dan Liew via cfe-commits


@@ -730,6 +754,18 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   options::OPT_fno_sanitize_recover_EQ);
   RecoverableKinds &= Kinds;
 
+  // Parse any -fsanitize-trap=<...> flags the user provided, then
+  // diagnose any which do not have a matching -fsanitize=<...>
+  if (DiagnoseErrors) {
+SanitizerMask ExplicitTrap = parseSanitizeArgs(

delcypher wrote:

Is there a reason can't reuse the results of the `parseSanitizeTrapArgs` call 
at the beginning of this method?

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


[clang] [WIP][DO NOT MERGE][Clang][Driver] Emit warning when -fsanitize-trap=<...> is passed without associated -fsanitize=<...> (PR #147997)

2025-07-11 Thread Dan Liew via cfe-commits


@@ -348,6 +348,30 @@ parseSanitizeSkipHotCutoffArgs(const Driver &D, const 
llvm::opt::ArgList &Args,
   return Cutoffs;
 }
 
+// Given a set of mismatched bits, TrapOnly (bits the user asked to trap but
+// that aren’t actually enabled), emit a warning based on -fsanitize-trap=NAME
+static void diagnoseTrapOnly(const Driver &D, SanitizerMask &TrapOnly) {
+// Double pass: one for sanitizer groupings, one for leaves (ex: undefined vs.

delcypher wrote:

For clarity you split this comment. One for the bit where you handle group 
names, and one for the individual sanitizer name (and put the comment next the 
code where we do this).

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


[clang] [WIP][DO NOT MERGE][Clang][Driver] Emit warning when -fsanitize-trap=<...> is passed without associated -fsanitize=<...> (PR #147997)

2025-07-11 Thread Dan Liew via cfe-commits


@@ -874,4 +874,9 @@ def warn_drv_openacc_without_cir
 : Warning<"OpenACC directives will result in no runtime behavior; use "
   "-fclangir to enable runtime effect">,
   InGroup;
+
+def warn_drv_sanitize_trap_mismatch : Warning<
+  "-fsanitize-trap=%0 has no effect because the matching sanitizer is not 
enabled; "
+  "did you mean to pass \"-fsanitize=%0\" as well?">,

delcypher wrote:

Nit: Here's my suggested wording.

`"-fsanitize-trap=%0 has no effect because the "%0" sanitizer is disabled; 
consider passing \"`-fsantize=%0\"` to enable the sanitizer`

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


[clang] [WIP][DO NOT MERGE][Clang][Driver] Emit warning when -fsanitize-trap=<...> is passed without associated -fsanitize=<...> (PR #147997)

2025-07-11 Thread Dan Liew via cfe-commits

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


[clang] [Clang] fix crash in codegen caused by deferred asm diagnostics under -fopenmp (PR #147163)

2025-07-11 Thread Alexey Bataev via cfe-commits


@@ -2092,18 +2092,36 @@ Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() {
 }
 
 Sema::SemaDiagnosticBuilder
-Sema::targetDiag(SourceLocation Loc, unsigned DiagID, const FunctionDecl *FD) {
+Sema::targetDiag(SourceLocation Loc, unsigned DiagID, FunctionDecl *FD) {
   FD = FD ? FD : getCurFunctionDecl();
-  if (LangOpts.OpenMP)
-return LangOpts.OpenMPIsTargetDevice
-   ? OpenMP().diagIfOpenMPDeviceCode(Loc, DiagID, FD)
-   : OpenMP().diagIfOpenMPHostCode(Loc, DiagID, FD);
-  if (getLangOpts().CUDA)
-return getLangOpts().CUDAIsDevice ? CUDA().DiagIfDeviceCode(Loc, DiagID)
-  : CUDA().DiagIfHostCode(Loc, DiagID);
-
-  if (getLangOpts().SYCLIsDevice)
+
+  if (LangOpts.OpenMP) {
+if (LangOpts.OpenMPIsTargetDevice) {
+  return OpenMP().diagIfOpenMPDeviceCode(Loc, DiagID, FD);
+}
+
+SemaDiagnosticBuilder SDB = OpenMP().diagIfOpenMPHostCode(Loc, DiagID, FD);
+if (SDB.isDeferred()) {
+  FD->setInvalidDecl();
+}
+return SDB;
+  }
+
+  if (getLangOpts().CUDA) {
+if (getLangOpts().CUDAIsDevice) {
+  return CUDA().DiagIfDeviceCode(Loc, DiagID);
+}
+
+SemaDiagnosticBuilder SDB = CUDA().DiagIfHostCode(Loc, DiagID);
+if (SDB.isDeferred()) {
+  FD->setInvalidDecl();
+}
+return SDB;
+  }
+
+  if (getLangOpts().SYCLIsDevice) {
 return SYCL().DiagIfDeviceCode(Loc, DiagID);
+  }

alexey-bataev wrote:

Drop extra braces around one-line substatements

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


[clang] [Clang][P1061] Fix template arguments in local classes (PR #121225)

2025-07-11 Thread Matheus Izvekov via cfe-commits


@@ -4433,8 +4433,12 @@ Sema::InstantiateClassMembers(SourceLocation 
PointOfInstantiation,
   // No need to instantiate in-class initializers during explicit
   // instantiation.
   if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) {
+// Handle local classes which could have substituted template params.
 CXXRecordDecl *ClassPattern =
-Instantiation->getTemplateInstantiationPattern();
+Instantiation->isLocalClass()
+? Instantiation->getInstantiatedFromMemberClass()
+: Instantiation->getTemplateInstantiationPattern();

mizvekov wrote:

The main point of `getTemplateInstantiationPattern` is to figure out the 
instantiation pattern as the name suggests, it would be better to fix the 
problem within it.

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


[clang] AMDGPU: Remove "gws" from the “read-only” target feature list (PR #148141)

2025-07-11 Thread Changpeng Fang via cfe-commits

https://github.com/changpeng updated 
https://github.com/llvm/llvm-project/pull/148141

>From c9cf9873e35205f9715acd545680713c0dd912aa Mon Sep 17 00:00:00 2001
From: Changpeng Fang 
Date: Fri, 11 Jul 2025 01:04:04 -0700
Subject: [PATCH 1/3] =?UTF-8?q?AMDGPU:=20Remove=20"gws"=20from=20the=20?=
 =?UTF-8?q?=E2=80=9Cread-only=E2=80=9D=20target=20feature=20list?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

  Since this feature is no longer universally available, we may need it
in the IR.

Fixes: SWDEV-541399
---
 clang/lib/Basic/Targets/AMDGPU.cpp|  2 +-
 .../CodeGenOpenCL/amdgpu-enqueue-kernel.cl|  8 +-
 .../CodeGenOpenCL/amdgpu-features-readonly.cl |  6 --
 clang/test/CodeGenOpenCL/amdgpu-features.cl   | 90 +--
 4 files changed, 50 insertions(+), 56 deletions(-)
 delete mode 100644 clang/test/CodeGenOpenCL/amdgpu-features-readonly.cl

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index cebcfa3c2bc40..4f57c92b0981b 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -266,7 +266,7 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple 
&Triple,
 
   MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
   CUMode = !(GPUFeatures & llvm::AMDGPU::FEATURE_WGP);
-  for (auto F : {"image-insts", "gws", "vmem-to-lds-load-insts"})
+  for (auto F : {"image-insts", "vmem-to-lds-load-insts"})
 ReadOnlyFeatures.insert(F);
   HalfArgsAndReturns = true;
 }
diff --git a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl 
b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
index bbb55b7e14941..c12b42bf9d950 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
@@ -816,12 +816,12 @@ kernel void test_target_features_kernel(global int *i) {
 // NOCPU: attributes #[[ATTR10]] = { convergent nounwind }
 //.
 // GFX900: attributes #[[ATTR0:[0-9]+]] = { "objc_arc_inert" }
-// GFX900: attributes #[[ATTR1]] = { convergent norecurse nounwind 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 }
-// GFX900: attributes #[[ATTR2]] = { convergent norecurse nounwind 
"amdgpu-flat-work-group-size"="1,256" 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 "uniform-work-group-size"="false" }
-// GFX900: attributes #[[ATTR3]] = { alwaysinline convergent norecurse 
nounwind "amdgpu-flat-work-group-size"="1,256" 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 }
+// GFX900: attributes #[[ATTR1]] = { convergent norecurse nounwind 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+gws,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 }
+// GFX900: attributes #[[ATTR2]] = { convergent norecurse nounwind 
"amdgpu-flat-work-group-size"="1,256" 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+gws,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 "uniform-work-group-size"="false" }
+// GFX900: attributes #[[ATTR3]] = { alwaysinline convergent norecurse 
nounwind "amdgpu-flat-work-group-size"="1,256" 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+gws,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 }
 // GFX900: attributes #[[ATTR4:[0-9]+]] = { nocallback nofree nosync nounwind 
willreturn memory(argmem: readwrite) }
 // GFX900: attributes #[[ATTR5:[0-9]+]] = { nocallback nofree nounwind 
willreturn memory(argmem: readwrite) }
-// GFX900: attributes #[[ATTR6]] = { convergent nounwind 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 }
+// GFX900: attributes #[[ATTR6]] = { convergent nounwind 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="

[clang] [llvm] Fix Windows EH IP2State tables (remove +1 bias) (PR #144745)

2025-07-11 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Actually, thinking about it, maybe we should just do the nop insertion for UEFI 
targets.  The UEFI environment is very similar to Windows.  CC @Prabhuk .

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


[clang-tools-extra] [clangd] Improve Markup Rendering (PR #140498)

2025-07-11 Thread via cfe-commits

https://github.com/tcottin updated 
https://github.com/llvm/llvm-project/pull/140498

>From 8fadd8d51fa3d96c7fb82b9d749ef3f35441ac64 Mon Sep 17 00:00:00 2001
From: Tim Cottin 
Date: Mon, 19 May 2025 06:26:36 +
Subject: [PATCH 1/5] [clangd] Improve Markup Rendering

---
 clang-tools-extra/clangd/Hover.cpp|  81 +-
 clang-tools-extra/clangd/support/Markup.cpp   | 252 ++
 clang-tools-extra/clangd/support/Markup.h |  32 ++-
 .../clangd/test/signature-help.test   |   4 +-
 .../clangd/unittests/CodeCompleteTests.cpp|   8 +-
 .../clangd/unittests/HoverTests.cpp   |  75 --
 .../clangd/unittests/support/MarkupTests.cpp  | 214 +++
 7 files changed, 410 insertions(+), 256 deletions(-)

diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 3ab3d89030520..88755733aa67c 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -960,42 +960,6 @@ std::optional getHoverContents(const Attr *A, 
ParsedAST &AST) {
   return HI;
 }
 
-bool isParagraphBreak(llvm::StringRef Rest) {
-  return Rest.ltrim(" \t").starts_with("\n");
-}
-
-bool punctuationIndicatesLineBreak(llvm::StringRef Line) {
-  constexpr llvm::StringLiteral Punctuation = R"txt(.:,;!?)txt";
-
-  Line = Line.rtrim();
-  return !Line.empty() && Punctuation.contains(Line.back());
-}
-
-bool isHardLineBreakIndicator(llvm::StringRef Rest) {
-  // '-'/'*' md list, '@'/'\' documentation command, '>' md blockquote,
-  // '#' headings, '`' code blocks
-  constexpr llvm::StringLiteral LinebreakIndicators = R"txt(-*@\>#`)txt";
-
-  Rest = Rest.ltrim(" \t");
-  if (Rest.empty())
-return false;
-
-  if (LinebreakIndicators.contains(Rest.front()))
-return true;
-
-  if (llvm::isDigit(Rest.front())) {
-llvm::StringRef AfterDigit = Rest.drop_while(llvm::isDigit);
-if (AfterDigit.starts_with(".") || AfterDigit.starts_with(")"))
-  return true;
-  }
-  return false;
-}
-
-bool isHardLineBreakAfter(llvm::StringRef Line, llvm::StringRef Rest) {
-  // Should we also consider whether Line is short?
-  return punctuationIndicatesLineBreak(Line) || isHardLineBreakIndicator(Rest);
-}
-
 void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) {
   if (ND.isInvalidDecl())
 return;
@@ -1601,51 +1565,32 @@ std::optional 
getBacktickQuoteRange(llvm::StringRef Line,
   return Line.slice(Offset, Next + 1);
 }
 
-void parseDocumentationLine(llvm::StringRef Line, markup::Paragraph &Out) {
+void parseDocumentationParagraph(llvm::StringRef Text, markup::Paragraph &Out) 
{
   // Probably this is appendText(Line), but scan for something interesting.
-  for (unsigned I = 0; I < Line.size(); ++I) {
-switch (Line[I]) {
+  for (unsigned I = 0; I < Text.size(); ++I) {
+switch (Text[I]) {
 case '`':
-  if (auto Range = getBacktickQuoteRange(Line, I)) {
-Out.appendText(Line.substr(0, I));
+  if (auto Range = getBacktickQuoteRange(Text, I)) {
+Out.appendText(Text.substr(0, I));
 Out.appendCode(Range->trim("`"), /*Preserve=*/true);
-return parseDocumentationLine(Line.substr(I + Range->size()), Out);
+return parseDocumentationParagraph(Text.substr(I + Range->size()), 
Out);
   }
   break;
 }
   }
-  Out.appendText(Line).appendSpace();
+  Out.appendText(Text);
 }
 
 void parseDocumentation(llvm::StringRef Input, markup::Document &Output) {
-  std::vector ParagraphLines;
-  auto FlushParagraph = [&] {
-if (ParagraphLines.empty())
-  return;
-auto &P = Output.addParagraph();
-for (llvm::StringRef Line : ParagraphLines)
-  parseDocumentationLine(Line, P);
-ParagraphLines.clear();
-  };
+  llvm::StringRef Paragraph, Rest;
+  for (std::tie(Paragraph, Rest) = Input.split("\n\n");
+   !(Paragraph.empty() && Rest.empty());
+   std::tie(Paragraph, Rest) = Rest.split("\n\n")) {
 
-  llvm::StringRef Line, Rest;
-  for (std::tie(Line, Rest) = Input.split('\n');
-   !(Line.empty() && Rest.empty());
-   std::tie(Line, Rest) = Rest.split('\n')) {
-
-// After a linebreak remove spaces to avoid 4 space markdown code blocks.
-// FIXME: make FlushParagraph handle this.
-Line = Line.ltrim();
-if (!Line.empty())
-  ParagraphLines.push_back(Line);
-
-if (isParagraphBreak(Rest) || isHardLineBreakAfter(Line, Rest)) {
-  FlushParagraph();
-}
+if (!Paragraph.empty())
+  parseDocumentationParagraph(Paragraph, Output.addParagraph());
   }
-  FlushParagraph();
 }
-
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
   const HoverInfo::PrintedType &T) {
   OS << T.Type;
diff --git a/clang-tools-extra/clangd/support/Markup.cpp 
b/clang-tools-extra/clangd/support/Markup.cpp
index 63aff96b02056..b1e6252e473f5 100644
--- a/clang-tools-extra/clangd/support/Markup.cpp
+++ b/clang-tools-extra/clangd/support/Markup.cpp
@@ -11,7 +11,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtr

[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Dan Liew via cfe-commits


@@ -85,6 +85,96 @@ enum VariableTypeDescriptorKind : uint16_t {
 //Miscellaneous Helper Methods
 //======//
 
+static llvm::StringRef GetUBSanTrapForHandler(SanitizerHandler ID) {

delcypher wrote:

Yes but with the caveat that  `SanitizerHandler::BoundsSafety` will need 
special handling because we don't want to emit a trap reason for that one 
because that's the value reserved for `-fbounds-safety` that handles it's trap 
reasons differently from the rest of UBSan.

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


[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

2025-07-11 Thread Cory Fields via cfe-commits

theuni wrote:

> > On a related note, do we emit `-Wthread-safety-negative` for reentrant 
> > locks? I don't remember that we carved out an exception for that, and we 
> > probably should.
> 
> We do - and it's deliberate on my part as I've been trying to indicate that 
> there might be valid use cases for that. While conceptually contradictory, 
> there might be cases where developers want to ensure a reentrant mutex is NOT 
> held before entering a function.

Chiming in here with a use-case...

My software currently contains a nasty global recursive lock that we hope to 
(over a long period of time, likely years) convert to non-recursive.

In the meantime, and during the refactor, it's helpful to be able to mark some 
functions as `EXCLUSIVE_LOCKS_REQUIRED(!recursive_mut)` even though technically 
it wouldn't be a problem.

Ideally, that would even "convert" the lock, as far as the annotations go, to 
non-recursive. That way, from that point on, functions further down the 
call-stack could no longer double-lock. Though, I suppose that's arguably a 
different feature altogether.

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


[clang-tools-extra] [clang-tidy] Teach `readability-uppercase-literal-suffix` about C++23 and C23 suffixes (PR #148275)

2025-07-11 Thread via cfe-commits

llvmbot wrote:




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

Author: Victor Chernyakin (localspook)


Changes

C++23 integer literal suffixes:

| Suffix | Type |
|-|-|
|`z`  | `std::make_signed_t`|
|`uz`  | `std::size_t`|

C++23 floating-point literal suffixes:

| Suffix | Type |
|-|-|
|`bf16`   | `std::bfloat16_t`|
|`f16`   | `std::float16_t`|
|`f32`   | `std::float32_t`|
|`f64`   | `std::float64_t`|
|`f128`   | `std::float128_t`|

C23 integer literal suffixes:

| Suffix | Type |
|-|-|
|`wb `  | `_BitInt(N)`|
|`uwb `  | `unsigned _BitInt(N)`|

C23 floating-point literal suffixes:

| Suffix | Type |
|-|-|
|`df`   | `_Decimal32`|
|`dd`   | `_Decimal64`|
|`dl`   | `_Decimal128`|

Clang doesn't actually support any of the new floating point types yet (except 
for `f16`). I've decided to add disabled tests for them, so that when the 
support comes, we can flip the switch and support them with no delay.

---

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


6 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp (+7-6) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-c23.c
 (+162) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-extended-floating-point.cpp
 (+248) 
- (removed) 
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-float16.cpp
 (-51) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-integer.cpp
 (+85-1) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
index 678aa8dad48a7..dd43ee200f4c0 100644
--- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
@@ -25,10 +25,11 @@ struct IntegerLiteralCheck {
   static constexpr llvm::StringLiteral Name = llvm::StringLiteral("integer");
   // What should be skipped before looking for the Suffixes? (Nothing here.)
   static constexpr llvm::StringLiteral SkipFirst = llvm::StringLiteral("");
-  // Suffix can only consist of 'u' and 'l' chars, and can be a complex number
-  // ('i', 'j'). In MS compatibility mode, suffixes like i32 are supported.
+  // Suffix can only consist of 'u', 'l', and 'z' chars, can be a bit-precise
+  // integer (wb), and can be a complex number ('i', 'j'). In MS compatibility
+  // mode, suffixes like i32 are supported.
   static constexpr llvm::StringLiteral Suffixes =
-  llvm::StringLiteral("uUlLiIjJ");
+  llvm::StringLiteral("uUlLzZwWbBiIjJ");
 };
 constexpr llvm::StringLiteral IntegerLiteralCheck::Name;
 constexpr llvm::StringLiteral IntegerLiteralCheck::SkipFirst;
@@ -45,10 +46,10 @@ struct FloatingLiteralCheck {
   // Since the exponent ('p'/'P') is mandatory for hexadecimal floating-point
   // literals, we first skip everything before the exponent.
   static constexpr llvm::StringLiteral SkipFirst = llvm::StringLiteral("pP");
-  // Suffix can only consist of 'f', 'l', "f16", 'h', 'q' chars,
-  // and can be a complex number ('i', 'j').
+  // Suffix can only consist of 'f', 'l', "f16", "bf16", "df", "dd", "dl",
+  // 'h', 'q' chars, and can be a complex number ('i', 'j').
   static constexpr llvm::StringLiteral Suffixes =
-  llvm::StringLiteral("fFlLhHqQiIjJ");
+  llvm::StringLiteral("fFlLbBdDhHqQiIjJ");
 };
 constexpr llvm::StringLiteral FloatingLiteralCheck::Name;
 constexpr llvm::StringLiteral FloatingLiteralCheck::SkipFirst;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ad869265a2db5..119c030b43852 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -354,6 +354,10 @@ Changes in existing checks
   ` check by fixing
   some false positives involving smart pointers to arrays.
 
+- Improved :doc:`readability-uppercase-literal-suffix
+  ` check to recognize
+  literal suffixes added in C++23 and C23.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-c23.c
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-c23.c
new file mode 100644
index 0..75727fc69e68c
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-c23.c
@@ -0,0 +1,162 @@
+// TODO: When Clang adds support for decimal floating point types, enable 
these tests by:
+//1. Removing all the #if 0 + #endif guards.
+//2. Removing all occurrences of the string "DISABLED-" in this file.
+//3. Deleti

[clang-tools-extra] [clang-tidy] Teach `readability-uppercase-literal-suffix` about C++23 and C23 suffixes (PR #148275)

2025-07-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Victor Chernyakin (localspook)


Changes

C++23 integer literal suffixes:

| Suffix | Type |
|-|-|
|`z`  | `std::make_signed_t`|
|`uz`  | `std::size_t`|

C++23 floating-point literal suffixes:

| Suffix | Type |
|-|-|
|`bf16`   | `std::bfloat16_t`|
|`f16`   | `std::float16_t`|
|`f32`   | `std::float32_t`|
|`f64`   | `std::float64_t`|
|`f128`   | `std::float128_t`|

C23 integer literal suffixes:

| Suffix | Type |
|-|-|
|`wb `  | `_BitInt(N)`|
|`uwb `  | `unsigned _BitInt(N)`|

C23 floating-point literal suffixes:

| Suffix | Type |
|-|-|
|`df`   | `_Decimal32`|
|`dd`   | `_Decimal64`|
|`dl`   | `_Decimal128`|

Clang doesn't actually support any of the new floating point types yet (except 
for `f16`). I've decided to add disabled tests for them, so that when the 
support comes, we can flip the switch and support them with no delay.

---

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


6 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp (+7-6) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-c23.c
 (+162) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-extended-floating-point.cpp
 (+248) 
- (removed) 
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-float16.cpp
 (-51) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-integer.cpp
 (+85-1) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
index 678aa8dad48a7..dd43ee200f4c0 100644
--- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
@@ -25,10 +25,11 @@ struct IntegerLiteralCheck {
   static constexpr llvm::StringLiteral Name = llvm::StringLiteral("integer");
   // What should be skipped before looking for the Suffixes? (Nothing here.)
   static constexpr llvm::StringLiteral SkipFirst = llvm::StringLiteral("");
-  // Suffix can only consist of 'u' and 'l' chars, and can be a complex number
-  // ('i', 'j'). In MS compatibility mode, suffixes like i32 are supported.
+  // Suffix can only consist of 'u', 'l', and 'z' chars, can be a bit-precise
+  // integer (wb), and can be a complex number ('i', 'j'). In MS compatibility
+  // mode, suffixes like i32 are supported.
   static constexpr llvm::StringLiteral Suffixes =
-  llvm::StringLiteral("uUlLiIjJ");
+  llvm::StringLiteral("uUlLzZwWbBiIjJ");
 };
 constexpr llvm::StringLiteral IntegerLiteralCheck::Name;
 constexpr llvm::StringLiteral IntegerLiteralCheck::SkipFirst;
@@ -45,10 +46,10 @@ struct FloatingLiteralCheck {
   // Since the exponent ('p'/'P') is mandatory for hexadecimal floating-point
   // literals, we first skip everything before the exponent.
   static constexpr llvm::StringLiteral SkipFirst = llvm::StringLiteral("pP");
-  // Suffix can only consist of 'f', 'l', "f16", 'h', 'q' chars,
-  // and can be a complex number ('i', 'j').
+  // Suffix can only consist of 'f', 'l', "f16", "bf16", "df", "dd", "dl",
+  // 'h', 'q' chars, and can be a complex number ('i', 'j').
   static constexpr llvm::StringLiteral Suffixes =
-  llvm::StringLiteral("fFlLhHqQiIjJ");
+  llvm::StringLiteral("fFlLbBdDhHqQiIjJ");
 };
 constexpr llvm::StringLiteral FloatingLiteralCheck::Name;
 constexpr llvm::StringLiteral FloatingLiteralCheck::SkipFirst;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ad869265a2db5..119c030b43852 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -354,6 +354,10 @@ Changes in existing checks
   ` check by fixing
   some false positives involving smart pointers to arrays.
 
+- Improved :doc:`readability-uppercase-literal-suffix
+  ` check to recognize
+  literal suffixes added in C++23 and C23.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-c23.c
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-c23.c
new file mode 100644
index 0..75727fc69e68c
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-c23.c
@@ -0,0 +1,162 @@
+// TODO: When Clang adds support for decimal floating point types, enable 
these tests by:
+//1. Removing all the #if 0 + #endif guards.
+//2. Removing all occurrences of the string "DISABLED-" in this file.
+//3. Deleting this

[clang-tools-extra] [clang-tidy] Teach `readability-uppercase-literal-suffix` about C++23 and C23 suffixes (PR #148275)

2025-07-11 Thread Victor Chernyakin via cfe-commits

https://github.com/localspook created 
https://github.com/llvm/llvm-project/pull/148275

C++23 integer literal suffixes:

| Suffix | Type |
|-|-|
|`z`  | `std::make_signed_t`|
|`uz`  | `std::size_t`|

C++23 floating-point literal suffixes:

| Suffix | Type |
|-|-|
|`bf16`   | `std::bfloat16_t`|
|`f16`   | `std::float16_t`|
|`f32`   | `std::float32_t`|
|`f64`   | `std::float64_t`|
|`f128`   | `std::float128_t`|

C23 integer literal suffixes:

| Suffix | Type |
|-|-|
|`wb `  | `_BitInt(N)`|
|`uwb `  | `unsigned _BitInt(N)`|

C23 floating-point literal suffixes:

| Suffix | Type |
|-|-|
|`df`   | `_Decimal32`|
|`dd`   | `_Decimal64`|
|`dl`   | `_Decimal128`|

Clang doesn't actually support any of the new floating point types yet (except 
for `f16`). I've decided to add disabled tests for them, so that when the 
support comes, we can flip the switch and support them with no delay.

>From b19ad9cda58288d727861bdd0a9d2a7cedc7c1a6 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin 
Date: Fri, 11 Jul 2025 11:35:50 -0700
Subject: [PATCH] [clang-tidy] Teach `readability-uppercase-literal-suffix`
 about C++23 and C23 suffixes

---
 .../UppercaseLiteralSuffixCheck.cpp   |  13 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |   4 +
 .../uppercase-literal-suffix-c23.c| 162 
 ...literal-suffix-extended-floating-point.cpp | 248 ++
 .../uppercase-literal-suffix-float16.cpp  |  51 
 .../uppercase-literal-suffix-integer.cpp  |  86 +-
 6 files changed, 506 insertions(+), 58 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-c23.c
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-extended-floating-point.cpp
 delete mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-float16.cpp

diff --git 
a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
index 678aa8dad48a7..dd43ee200f4c0 100644
--- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
@@ -25,10 +25,11 @@ struct IntegerLiteralCheck {
   static constexpr llvm::StringLiteral Name = llvm::StringLiteral("integer");
   // What should be skipped before looking for the Suffixes? (Nothing here.)
   static constexpr llvm::StringLiteral SkipFirst = llvm::StringLiteral("");
-  // Suffix can only consist of 'u' and 'l' chars, and can be a complex number
-  // ('i', 'j'). In MS compatibility mode, suffixes like i32 are supported.
+  // Suffix can only consist of 'u', 'l', and 'z' chars, can be a bit-precise
+  // integer (wb), and can be a complex number ('i', 'j'). In MS compatibility
+  // mode, suffixes like i32 are supported.
   static constexpr llvm::StringLiteral Suffixes =
-  llvm::StringLiteral("uUlLiIjJ");
+  llvm::StringLiteral("uUlLzZwWbBiIjJ");
 };
 constexpr llvm::StringLiteral IntegerLiteralCheck::Name;
 constexpr llvm::StringLiteral IntegerLiteralCheck::SkipFirst;
@@ -45,10 +46,10 @@ struct FloatingLiteralCheck {
   // Since the exponent ('p'/'P') is mandatory for hexadecimal floating-point
   // literals, we first skip everything before the exponent.
   static constexpr llvm::StringLiteral SkipFirst = llvm::StringLiteral("pP");
-  // Suffix can only consist of 'f', 'l', "f16", 'h', 'q' chars,
-  // and can be a complex number ('i', 'j').
+  // Suffix can only consist of 'f', 'l', "f16", "bf16", "df", "dd", "dl",
+  // 'h', 'q' chars, and can be a complex number ('i', 'j').
   static constexpr llvm::StringLiteral Suffixes =
-  llvm::StringLiteral("fFlLhHqQiIjJ");
+  llvm::StringLiteral("fFlLbBdDhHqQiIjJ");
 };
 constexpr llvm::StringLiteral FloatingLiteralCheck::Name;
 constexpr llvm::StringLiteral FloatingLiteralCheck::SkipFirst;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ad869265a2db5..119c030b43852 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -354,6 +354,10 @@ Changes in existing checks
   ` check by fixing
   some false positives involving smart pointers to arrays.
 
+- Improved :doc:`readability-uppercase-literal-suffix
+  ` check to recognize
+  literal suffixes added in C++23 and C23.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-c23.c
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-c23.c
new file mode 100644
index 0..75727fc69e68c
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-c23.c
@@ -0,0 +1,162 @@
+// TODO: When Clang adds supp

[clang-tools-extra] [doc] Add documentation for clang-change-namespace (PR #148277)

2025-07-11 Thread via cfe-commits

llvmbot wrote:




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

Author: Konrad Kleine (kwk)


Changes

This adds rst documentation for the `clang-change-namespace` program.

I ran the examples locally to ensure they work.

See #35519

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


2 Files Affected:

- (added) clang-tools-extra/docs/clang-change-namespace.rst (+158) 
- (modified) clang-tools-extra/docs/index.rst (+1) 


``diff
diff --git a/clang-tools-extra/docs/clang-change-namespace.rst 
b/clang-tools-extra/docs/clang-change-namespace.rst
new file mode 100644
index 0..23c3dcc8b7412
--- /dev/null
+++ b/clang-tools-extra/docs/clang-change-namespace.rst
@@ -0,0 +1,158 @@
+==
+Clang-Change-Namespace
+==
+
+.. contents::
+
+.. toctree::
+  :maxdepth: 1
+
+:program:`clang-change-namespace` can be used to change the surrounding
+namespaces of class/function definitions.
+
+Classes/functions in the moved namespace will have new namespaces while
+references to symbols (e.g. types, functions) which are not defined in the
+changed namespace will be correctly qualified by prepending namespace 
specifiers
+before them. This will try to add shortest namespace specifiers possible.
+
+When a symbol reference needs to be fully-qualified, this adds a `::` prefix to
+the namespace specifiers unless the new namespace is the global namespace. For
+classes, only classes that are declared/defined in the given namespace in
+specified files will be moved: forward declarations will remain in the old
+namespace. The will be demonstrated in the next example.
+
+Example usage
+-
+
+For example, consider this `test.cc` example here with the forward declared
+class `FWD` and the defined class `A`, both in the namespace `a`.
+
+.. code-block:: c++
+  :linenos:
+
+  namespace a {
+  class FWD;
+  class A {
+FWD *fwd;
+  };
+  } // namespace a
+
+And now let's change the namespace `a` to `x`.
+
+.. code-block:: console
+  clang-change-namespace \
+--old_namespace "a" \
+--new_namespace "x" \
+--file_pattern "test.cc" \
+--i \
+test.cc
+
+Note that in the code below there's still the forward decalred class `FWD` that
+stayed in the namespace `a`. It wasn't moved to the new namespace because it
+wasn't defined/declared here in `a` but only forward declared.
+
+.. code-block:: c++
+  :linenos:
+
+  namespace a {
+  class FWD;
+  } // namespace a
+  namespace x {
+
+  class A {
+a::FWD *fwd;
+  };
+  } // namespace x
+
+
+Another example
+---
+
+Consider this `test.cc` file:
+
+.. code-block:: c++
+  :linenos:
+
+  namespace na {
+  class X {};
+  namespace nb {
+  class Y {
+X x;
+  };
+  } // namespace nb
+  } // namespace na
+
+To move the definition of class `Y` from namespace `na::nb` to `x::y`, run:
+
+.. code-block:: console
+
+  clang-change-namespace \
+--old_namespace "na::nb" \
+--new_namespace "x::y" \
+--file_pattern "test.cc" \
+--i \
+test.cc
+
+This will overwrite `test.cc` to look like this:
+
+.. code-block:: c++
+  :linenos:
+
+  namespace na {
+  class X {};
+
+  } // namespace na
+  namespace x {
+  namespace y {
+  class Y {
+na::X x;
+  };
+  } // namespace y
+  } // namespace x
+
+Note, that we've successfully moved the class `Y` from namespace `na::nb` to
+namespace `x::y`.
+
+:program:`clang-change-namespace` Command Line Options
+==
+
+.. option:: --allowed_file= 
+
+  A file containing regexes of symbol names that are not expected to be updated
+  when changing namespaces around them.
+
+.. option:: --dump_result   
+
+  Dump new file contents in YAML, if specified.
+
+.. option:: --extra-arg=
+
+  Additional argument to append to the compiler command line
+
+.. option:: --extra-arg-before= 
+
+  Additional argument to prepend to the compiler command line
+
+.. option:: --file_pattern= 
+
+  Only rename namespaces in files that match the given pattern.
+
+.. option:: -i  
+ 
+  Inplace edit s, if specified.
+
+.. option:: --new_namespace=
+ 
+  New namespace.
+
+.. option:: --old_namespace=
+ 
+  Old namespace.
+
+.. option:: -p  
+ 
+  Build path
+
+.. option:: --style=
+ 
+  The style name used for reformatting.
diff --git a/clang-tools-extra/docs/index.rst b/clang-tools-extra/docs/index.rst
index 9f7324fcf7419..3f3a99d1b70c6 100644
--- a/clang-tools-extra/docs/index.rst
+++ b/clang-tools-extra/docs/index.rst
@@ -17,6 +17,7 @@ Contents
 
clang-tidy/index
clang-include-fixer
+   clang-change-namespace
modularize
pp-trace
clangd 

``




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


[clang-tools-extra] [doc] Add documentation for clang-change-namespace (PR #148277)

2025-07-11 Thread Konrad Kleine via cfe-commits

https://github.com/kwk created https://github.com/llvm/llvm-project/pull/148277

This adds rst documentation for the `clang-change-namespace` program.

I ran the examples locally to ensure they work.

See #35519

>From e5f1b218ae17c2c9767ddff7fe3d2fbb2962e4fb Mon Sep 17 00:00:00 2001
From: Konrad Kleine 
Date: Fri, 11 Jul 2025 18:39:16 +
Subject: [PATCH] [doc] Add documentation for clang-change-namespace

This adds rst documentation for the `clang-change-namespace` program.

I ran the examples locally to ensure they work.

See #35519
---
 .../docs/clang-change-namespace.rst   | 158 ++
 clang-tools-extra/docs/index.rst  |   1 +
 2 files changed, 159 insertions(+)
 create mode 100644 clang-tools-extra/docs/clang-change-namespace.rst

diff --git a/clang-tools-extra/docs/clang-change-namespace.rst 
b/clang-tools-extra/docs/clang-change-namespace.rst
new file mode 100644
index 0..23c3dcc8b7412
--- /dev/null
+++ b/clang-tools-extra/docs/clang-change-namespace.rst
@@ -0,0 +1,158 @@
+==
+Clang-Change-Namespace
+==
+
+.. contents::
+
+.. toctree::
+  :maxdepth: 1
+
+:program:`clang-change-namespace` can be used to change the surrounding
+namespaces of class/function definitions.
+
+Classes/functions in the moved namespace will have new namespaces while
+references to symbols (e.g. types, functions) which are not defined in the
+changed namespace will be correctly qualified by prepending namespace 
specifiers
+before them. This will try to add shortest namespace specifiers possible.
+
+When a symbol reference needs to be fully-qualified, this adds a `::` prefix to
+the namespace specifiers unless the new namespace is the global namespace. For
+classes, only classes that are declared/defined in the given namespace in
+specified files will be moved: forward declarations will remain in the old
+namespace. The will be demonstrated in the next example.
+
+Example usage
+-
+
+For example, consider this `test.cc` example here with the forward declared
+class `FWD` and the defined class `A`, both in the namespace `a`.
+
+.. code-block:: c++
+  :linenos:
+
+  namespace a {
+  class FWD;
+  class A {
+FWD *fwd;
+  };
+  } // namespace a
+
+And now let's change the namespace `a` to `x`.
+
+.. code-block:: console
+  clang-change-namespace \
+--old_namespace "a" \
+--new_namespace "x" \
+--file_pattern "test.cc" \
+--i \
+test.cc
+
+Note that in the code below there's still the forward decalred class `FWD` that
+stayed in the namespace `a`. It wasn't moved to the new namespace because it
+wasn't defined/declared here in `a` but only forward declared.
+
+.. code-block:: c++
+  :linenos:
+
+  namespace a {
+  class FWD;
+  } // namespace a
+  namespace x {
+
+  class A {
+a::FWD *fwd;
+  };
+  } // namespace x
+
+
+Another example
+---
+
+Consider this `test.cc` file:
+
+.. code-block:: c++
+  :linenos:
+
+  namespace na {
+  class X {};
+  namespace nb {
+  class Y {
+X x;
+  };
+  } // namespace nb
+  } // namespace na
+
+To move the definition of class `Y` from namespace `na::nb` to `x::y`, run:
+
+.. code-block:: console
+
+  clang-change-namespace \
+--old_namespace "na::nb" \
+--new_namespace "x::y" \
+--file_pattern "test.cc" \
+--i \
+test.cc
+
+This will overwrite `test.cc` to look like this:
+
+.. code-block:: c++
+  :linenos:
+
+  namespace na {
+  class X {};
+
+  } // namespace na
+  namespace x {
+  namespace y {
+  class Y {
+na::X x;
+  };
+  } // namespace y
+  } // namespace x
+
+Note, that we've successfully moved the class `Y` from namespace `na::nb` to
+namespace `x::y`.
+
+:program:`clang-change-namespace` Command Line Options
+==
+
+.. option:: --allowed_file= 
+
+  A file containing regexes of symbol names that are not expected to be updated
+  when changing namespaces around them.
+
+.. option:: --dump_result   
+
+  Dump new file contents in YAML, if specified.
+
+.. option:: --extra-arg=
+
+  Additional argument to append to the compiler command line
+
+.. option:: --extra-arg-before= 
+
+  Additional argument to prepend to the compiler command line
+
+.. option:: --file_pattern= 
+
+  Only rename namespaces in files that match the given pattern.
+
+.. option:: -i  
+ 
+  Inplace edit s, if specified.
+
+.. option:: --new_namespace=
+ 
+  New namespace.
+
+.. option:: --old_namespace=
+ 
+  Old namespace.
+
+.. option:: -p  
+ 
+  Build path
+
+.. option:: --style=
+ 
+  The style name used for reformatting.
diff --git a/clang-tools-extra/docs/index.rst b/clang-tools-extra/docs/index.rst
index 9f7324fcf7419..3f3a99d1b70c6 100644
--- a/clang-tools-extra/docs/index.rst
+++ b/clang-tools-extra/docs/index.rst
@@ -17,6 +17,7 @@ Contents
 
clang-tidy/index
clang-include-fixer
+   clang-change-n

[clang-tools-extra] [clang-tidy] Teach `readability-uppercase-literal-suffix` about C++23 and C23 suffixes (PR #148275)

2025-07-11 Thread Victor Chernyakin via cfe-commits

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


[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Dan Liew via cfe-commits


@@ -85,6 +85,96 @@ enum VariableTypeDescriptorKind : uint16_t {
 //Miscellaneous Helper Methods
 //======//
 
+static llvm::StringRef GetUBSanTrapForHandler(SanitizerHandler ID) {
+  switch (ID) {
+  case SanitizerHandler::AddOverflow:
+return "Signed integer addition overflowed";
+
+  case SanitizerHandler::BuiltinUnreachable:
+return "_builtin_unreachable(), execution reached an unreachable program "
+   "point";
+
+  case SanitizerHandler::CFICheckFail:
+return "Control flow integrity check failed";
+
+  case SanitizerHandler::DivremOverflow:
+return "Signed integer divide or remainder overflowed";
+
+  case SanitizerHandler::DynamicTypeCacheMiss:
+return "Dynamic type cache miss, member call made on an object whose "
+   "dynamic type differs from the expected type";
+
+  case SanitizerHandler::FloatCastOverflow:
+return "Floating-point to integer conversion overflowed";
+
+  case SanitizerHandler::FunctionTypeMismatch:
+return "Function called with mismatched signature";
+
+  case SanitizerHandler::ImplicitConversion:
+return "Implicit integer conversion overflowed or lost data";
+
+  case SanitizerHandler::InvalidBuiltin:
+return "Invalid use of builtin function";
+
+  case SanitizerHandler::InvalidObjCCast:
+return "Invalid Objective-C cast";
+
+  case SanitizerHandler::LoadInvalidValue:
+return "Loaded an invalid or uninitialized value for the type";
+
+  case SanitizerHandler::MissingReturn:
+return "Execution reached the end of a value-returning function without "
+   "returning a value";
+
+  case SanitizerHandler::MulOverflow:
+return "Signed integer multiplication overflowed";
+
+  case SanitizerHandler::NegateOverflow:
+return "Signed integer negation overflowed";
+
+  case SanitizerHandler::NullabilityArg:
+return "Passing null as an argument which is annotated with "
+   "_Nonnull";
+
+  case SanitizerHandler::NullabilityReturn:
+return "Returning null from a function with a return type annotated with "
+   "_Nonnull";
+
+  case SanitizerHandler::NonnullArg:
+return "Passing null pointer as an argument which is declared to never be "
+   "null";
+
+  case SanitizerHandler::NonnullReturn:
+return "Returning null pointer from a function which is declared to never "
+   "return null";
+
+  case SanitizerHandler::OutOfBounds:
+return "Array index out of bounds";
+
+  case SanitizerHandler::PointerOverflow:
+return "Pointer arithmetic overflowed bounds";
+
+  case SanitizerHandler::ShiftOutOfBounds:
+return "Shift exponent is too large for the type";
+
+  case SanitizerHandler::SubOverflow:
+return "Signed integer subtraction overflowed";
+
+  case SanitizerHandler::TypeMismatch:
+return "Type mismatch in operation";

delcypher wrote:

We can do that but this seems like it should be done as a separate patch. Also 
if we do this we need to be careful because the enum values are effectively ABI 
at this point. The main case I'm concerned about is the value for 
`-fbounds-safety` (0x19) is ABI and we have no desire for that to change.

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


[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Dan Liew via cfe-commits

delcypher wrote:

> What is debug info size impact?

We'll ask @anthonyhatran to run some experiments on a few open source projects 
(if you have any that you interested in then particular please let us know).

I wonder how much this will matter in practice though because (at least for 
Apple platforms) debug info is not part of the final binary and is instead 
stored elsewhere (apart from static libraries where debug is stored inside the 
object files). So in a deployment scenario the executable or dynamic library 
size is unchanged, no matter how big the debug info gets.

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


[clang] [clang][SYCL] Add sycl_external attribute and restrict emitting device code (PR #140282)

2025-07-11 Thread Tom Honermann via cfe-commits


@@ -4084,6 +4084,19 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *&OldD, Scope *S,
diag::note_carries_dependency_missing_first_decl) << 0/*Function*/;
 }
 
+// SYCL spec 2020
+//   The first declaration of a function with external linkage must
+//   specify sycl_external attribute.
+//   Subsequent declarations may optionally specify this attribute.

tahonermann wrote:

It is helpful to quote the specification verbatim so that the intent is 
understood from the quoted context in the event that the specification changes.
```suggestion
// SYCL 2020 section 5.10.1, "SYCL functions and member functions linkage":
//   When a function is declared with SYCL_EXTERNAL, that macro must be
//   used on the first declaration of that function in the translation unit.
//   Redeclarations of the function in the same translation unit may
//   optionally use SYCL_EXTERNAL, but this is not required.
```

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


[clang] [clang][SYCL] Add sycl_external attribute and restrict emitting device code (PR #140282)

2025-07-11 Thread Tom Honermann via cfe-commits


@@ -12879,6 +12879,16 @@ def err_sycl_special_type_num_init_method : Error<
   "types with 'sycl_special_class' attribute must have one and only one 
'__init' "
   "method defined">;
 
+// SYCL external attribute diagnostics
+def err_sycl_attribute_invalid_linkage : Error<
+  "'sycl_external' can only be applied to functions with external linkage">;
+def err_sycl_attribute_avoid_main : Error<
+  "'sycl_external' cannot be applied to the 'main' function">;
+def err_sycl_attribute_avoid_deleted_function : Error<
+  "'sycl_external' cannot be applied to an explicitly deleted function">;
+def err_sycl_attribute_missing_on_first_decl
+: Error<"'sycl_external' must be applied to the first declaration">;

tahonermann wrote:

The existing `err_attribute_missing_on_first_decl` diagnostic can be used 
instead of introducing a new one.

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


[clang] [clang][SYCL] Add sycl_external attribute and restrict emitting device code (PR #140282)

2025-07-11 Thread Tom Honermann via cfe-commits


@@ -100,11 +100,9 @@ int main() {
 
 // Verify that SYCL kernel caller functions are emitted for each device target.
 //
-// FIXME: The following set of matches are used to skip over the declaration of
-// main(). main() shouldn't be emitted in device code, but that pruning isn't
-// performed yet.
-// CHECK-DEVICE:  Function Attrs: convergent mustprogress noinline 
norecurse nounwind optnone
-// CHECK-DEVICE-NEXT: define {{[a-z_ ]*}}noundef i32 @main() #0
+// main() shouldn't be emitted in device code. It is not annotated with
+// sycl_kernel_entry_point or sycl_external attributes.

tahonermann wrote:

Since `main()` can't be declared with those attributes, I think we can simplify 
the comment.
```suggestion
// main() shouldn't be emitted in device code.
```

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


[clang] [clang][SYCL] Add sycl_external attribute and restrict emitting device code (PR #140282)

2025-07-11 Thread Tom Honermann via cfe-commits


@@ -4084,6 +4084,19 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *&OldD, Scope *S,
diag::note_carries_dependency_missing_first_decl) << 0/*Function*/;
 }
 
+// SYCL spec 2020
+//   The first declaration of a function with external linkage must
+//   specify sycl_external attribute.
+//   Subsequent declarations may optionally specify this attribute.
+if (LangOpts.SYCLIsDevice) {
+  const SYCLExternalAttr *SEA = New->getAttr();
+  if (SEA && !Old->hasAttr()) {
+Diag(SEA->getLocation(), 
diag::err_sycl_attribute_missing_on_first_decl)
+<< SEA;

tahonermann wrote:

Inline with my other comment regarding using the existing first-decl diagnostic:
```suggestion
Diag(SEA->getLocation(), diag::err_attribute_missing_on_first_decl)
<< SEA;
```

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


[clang] [clang][SYCL] Add sycl_external attribute and restrict emitting device code (PR #140282)

2025-07-11 Thread Tom Honermann via cfe-commits

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


[clang] [clang][SYCL] Add sycl_external attribute and restrict emitting device code (PR #140282)

2025-07-11 Thread Tom Honermann via cfe-commits


@@ -4084,6 +4084,19 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *&OldD, Scope *S,
diag::note_carries_dependency_missing_first_decl) << 0/*Function*/;
 }
 
+// SYCL spec 2020
+//   The first declaration of a function with external linkage must
+//   specify sycl_external attribute.
+//   Subsequent declarations may optionally specify this attribute.
+if (LangOpts.SYCLIsDevice) {
+  const SYCLExternalAttr *SEA = New->getAttr();
+  if (SEA && !Old->hasAttr()) {
+Diag(SEA->getLocation(), 
diag::err_sycl_attribute_missing_on_first_decl)
+<< SEA;
+Diag(Old->getLocation(), diag::note_previous_declaration);
+  }

tahonermann wrote:

In most cases where this diagnostic is issued, the attribute is also dropped 
from the new declaration. I think we should do similarly here. See examples 
[here](https://github.com/llvm/llvm-project/blob/13c897093fd8d40ee3a5b13ff9c0b38c89e72bf1/clang/lib/Sema/SemaDecl.cpp#L3673-L3687)
 and 
[here](https://github.com/llvm/llvm-project/blob/13c897093fd8d40ee3a5b13ff9c0b38c89e72bf1/clang/lib/Sema/SemaDecl.cpp#L4620-L4626).
 A counter example (which might be a bug) is 
[here](https://github.com/llvm/llvm-project/blob/13c897093fd8d40ee3a5b13ff9c0b38c89e72bf1/clang/lib/Sema/SemaDecl.cpp#L4068-L4073).
```suggestion
New->dropAttr();
  }
```

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


[clang] [clang][SYCL] Add sycl_external attribute and restrict emitting device code (PR #140282)

2025-07-11 Thread Tom Honermann via cfe-commits


@@ -1641,6 +1641,13 @@ def DeviceKernel : DeclOrTypeAttr {
 }];
 }
 
+def SYCLExternal : InheritableAttr {
+  let Spellings = [Clang<"sycl_external">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
+  let LangOpts = [SYCLDevice];

tahonermann wrote:

In restrospect, I think we should allow the `sycl_external` attribute to be 
present for SYCL host compilation. It won't have an affect on what is emitted 
on the host side, but will allow for semantic diagnostics to be issued. It 
might be useful for SYCL implementations like AdaptiveCpp that don't 
(necessarily) perform a separate device compilation.
```suggestion
  let LangOpts = [SYCLHost, SYCLDevice];
```

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


[clang] [HLSL] Disallow writing to readonly resources (PR #147806)

2025-07-11 Thread Chris B via cfe-commits

https://github.com/llvm-beanz approved this pull request.


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


[clang] [clang][SYCL] Add sycl_external attribute and restrict emitting device code (PR #140282)

2025-07-11 Thread Tom Honermann via cfe-commits

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

This is looking good @schittir! I added some comments for minor issues. I still 
need to review the tests more closely.

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


[clang] [HLSL] Disallow writing to readonly resources (PR #147806)

2025-07-11 Thread Steven Perron via cfe-commits

https://github.com/s-perron approved this pull request.


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


[clang] [llvm] [libclang][Cygwin] Provide unversioned DLL file alongside versioned one (PR #147132)

2025-07-11 Thread Tomohiro Kashiwada via cfe-commits

https://github.com/kikairoya updated 
https://github.com/llvm/llvm-project/pull/147132

>From 9198e98e6dd7a02c5c5b65e400d788b6bac3a3c3 Mon Sep 17 00:00:00 2001
From: kikairoya 
Date: Sat, 28 Jun 2025 13:11:42 +0900
Subject: [PATCH 1/5] [libclang][Cygwin] Put unversioned DLL file aside of
 versioned DLL file

On Cygwin, a shared library target generates a versioned DLL file like
"cyg${OUTPUT_NAME}-${VERSION}.dll" and an import library
"lib${OUTPUT_NAME}.dll.a", but it does *not* generate the expected
unversioned symlink "cyg${OUTPUT_NAME}.dll" as is typical on other Unix-like 
platforms.

However, `dlopen()` calls typically use the unversioned form (e.g. 
"cygclang.dll"),
and this is consistent with usage on other platforms. In particular, 
`clang-python`
relies on this behavior. Although the Cygwin runtime can resolve other forms 
like
"libclang.so" or "libclang.dll", a symlink alone won't suffice here, as 
`dlopen()`
ultimately calls `LoadLibraryExW`, which does not follow Cygwin-style symlinks.

Therefore, this patch installs an unversioned copy of the DLL without the 
version
suffix to improve compatibility with `dlopen()` and tools like `clang-python`.
---
 clang/tools/libclang/CMakeLists.txt | 23 ++-
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/clang/tools/libclang/CMakeLists.txt 
b/clang/tools/libclang/CMakeLists.txt
index ac7a9a8db37c0..9c5ca26aab099 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -157,15 +157,28 @@ if(ENABLE_STATIC)
 endif()
 
 if(ENABLE_SHARED)
-  if(WIN32)
+  if(WIN32 OR CYGWIN)
 set_target_properties(libclang
   PROPERTIES
   VERSION ${LIBCLANG_LIBRARY_VERSION}
   DEFINE_SYMBOL _CINDEX_LIB_)
-  # Avoid declaring clang c++ symbols that are statically linked into 
libclang as dllimport'ed.
-  # If llvm/libclang-cpp dll is also being built for windows clang c++ 
symbols will still be
-  # implicitly be exported from libclang.
-  target_compile_definitions(libclang PRIVATE CLANG_BUILD_STATIC)
+if (CYGWIN)
+  # On Cygwin environment, a library target generates 
"cyg${OUTPUT_NAME}-${VERSION}.dll" and "lib${OUTPUT_NAME}.dll.a" but
+  # don't provide link "cyg${OUTPUT_NAME}.dll" differs from expected as 
other Unix platforms.
+  # Although, to dlopen(), usually "cyg${OUTPUT_NAME}.dll" will be passed 
(or "lib${OUTPUT_NAME}.dll" and "lib${OUTPUT_NAME}.so"
+  # are also viable as Cygwin runtime replaces those prefix and suffix), 
which is same manner to other Unix platforms,
+  # and clang-python does so.
+  # Thus, put a copy of dll named without version suffix to convinience to 
use of dlopen(). A symbolic link can't be
+  # viable here as the path passed to dlopen() will be passed directly to 
LoadLibraryExW, so it must be a real file.
+  set(UNPAINTED_TARGET_NAME 
"$/$clang$")
+  add_custom_command(TARGET libclang POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy 
"$" "${UNPAINTED_TARGET_NAME}")
+  install(FILES "${UNPAINTED_TARGET_NAME}" DESTINATION 
"${CMAKE_INSTALL_BINDIR}" COMPONENT libclang)
+endif()
+# Avoid declaring clang c++ symbols that are statically linked into 
libclang as dllimport'ed.
+# If llvm/libclang-cpp dll is also being built for windows clang c++ 
symbols will still be
+# implicitly be exported from libclang.
+target_compile_definitions(libclang PRIVATE CLANG_BUILD_STATIC)
   elseif(APPLE)
 set(LIBCLANG_LINK_FLAGS " -Wl,-compatibility_version -Wl,1")
 set(LIBCLANG_LINK_FLAGS "${LIBCLANG_LINK_FLAGS} -Wl,-current_version 
-Wl,${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")

>From 64e727aa96fbe69b0d637e243895fcd43dbf8701 Mon Sep 17 00:00:00 2001
From: kikairoya 
Date: Sat, 5 Jul 2025 22:01:59 +0900
Subject: [PATCH 2/5] rewrite comment

---
 clang/tools/libclang/CMakeLists.txt | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/clang/tools/libclang/CMakeLists.txt 
b/clang/tools/libclang/CMakeLists.txt
index 9c5ca26aab099..d3214104e6e0d 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -163,13 +163,15 @@ if(ENABLE_SHARED)
   VERSION ${LIBCLANG_LIBRARY_VERSION}
   DEFINE_SYMBOL _CINDEX_LIB_)
 if (CYGWIN)
-  # On Cygwin environment, a library target generates 
"cyg${OUTPUT_NAME}-${VERSION}.dll" and "lib${OUTPUT_NAME}.dll.a" but
-  # don't provide link "cyg${OUTPUT_NAME}.dll" differs from expected as 
other Unix platforms.
-  # Although, to dlopen(), usually "cyg${OUTPUT_NAME}.dll" will be passed 
(or "lib${OUTPUT_NAME}.dll" and "lib${OUTPUT_NAME}.so"
-  # are also viable as Cygwin runtime replaces those prefix and suffix), 
which is same manner to other Unix platforms,
-  # and clang-python does so.
-  # Thus, put a copy of dll named without version suffix to convinience to 
use of dlopen(). A symbolic link can't be
-  # viable h

[clang-tools-extra] [clang-tidy][NFC] add '.clang-tidy' config for clang-tidy project (PR #147793)

2025-07-11 Thread Baranov Victor via cfe-commits

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


[clang] [CIR] Add support for non-virtual base class initialization (PR #148080)

2025-07-11 Thread Henrich Lauko via cfe-commits

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

lgtm

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


[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Dan Liew via cfe-commits

delcypher wrote:

@fmayer

> I would prefer this to be behind a flag (not necessarily in this PR), even if 
> it's default turned on. People might not want synthetic frames added to their 
> debug information and the top frame to point to the real code; also as this 
> somewhat overlaps with the logic of `-fsanitize-annotate-debug-info`, with a 
> flag people can choose which one they want.

Do you have a concrete use case where it would be problematic to emit the trap 
reasons in debug info as the patch does? We are not opposed to adding a flag 
that allows it to be disabled (e.g. `-fno-sanitize-annotated-traps` or 
something similar) provided the trap reasons are emitted by default. That being 
said we don't want to implement things that won't be used. What use case(s) do 
you have in mind?

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


[clang] [WIP][DO NOT MERGE][Clang][Driver] Emit warning when -fsanitize-trap=<...> is passed without associated -fsanitize=<...> (PR #147997)

2025-07-11 Thread Dan Liew via cfe-commits


@@ -730,6 +754,18 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   options::OPT_fno_sanitize_recover_EQ);
   RecoverableKinds &= Kinds;
 
+  // Parse any -fsanitize-trap=<...> flags the user provided, then
+  // diagnose any which do not have a matching -fsanitize=<...>
+  if (DiagnoseErrors) {

delcypher wrote:

Given that we emit warnings, not errors here `DiagnoseErrors` doesn't sound 
like the right guard variable. Perhaps we need a new `DiagnoseWarnings` 
parameter?

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


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

2025-07-11 Thread David Rivera via cfe-commits

RiverDave wrote:

Gentle ping
@vbvictor 

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


[clang] [llvm] [HIPSTDPAR] Add support for globals (PR #146813)

2025-07-11 Thread Alex Voicu via cfe-commits

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

>From d98e3785a144ada9881cdbe24c86f273850eca20 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Thu, 3 Jul 2025 02:02:04 +0100
Subject: [PATCH 1/6] Add support for true globals.

---
 llvm/lib/Transforms/HipStdPar/HipStdPar.cpp   | 220 +-
 ...al-var-indirection-wrong-table-member-0.ll |  15 ++
 ...al-var-indirection-wrong-table-member-1.ll |  15 ++
 ...al-var-indirection-wrong-table-member-2.ll |  15 ++
 ...ar-indirection-wrong-table-member-count.ll |  14 ++
 ...global-var-indirection-wrong-table-type.ll |  13 ++
 .../HipStdPar/global-var-indirection.ll   |  87 +++
 llvm/test/Transforms/HipStdPar/global-var.ll  |   4 +-
 8 files changed, 371 insertions(+), 12 deletions(-)
 create mode 100644 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-member-0.ll
 create mode 100644 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-member-1.ll
 create mode 100644 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-member-2.ll
 create mode 100644 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-member-count.ll
 create mode 100644 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-type.ll
 create mode 100644 llvm/test/Transforms/HipStdPar/global-var-indirection.ll

diff --git a/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp 
b/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
index 5a87cf8c83d79..87fbcd40be431 100644
--- a/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
+++ b/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
@@ -48,6 +48,7 @@
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 
@@ -114,24 +115,223 @@ static inline void clearModule(Module &M) { // TODO: 
simplify.
 eraseFromModule(*M.ifuncs().begin());
 }
 
+static inline SmallVector> collectIndirectableUses(
+  GlobalVariable *G) {
+  // We are interested only in use chains that end in an Instruction.
+  SmallVector> Uses;
+
+  SmallVector> Tmp(G->use_begin(), G->use_end());
+  while (!Tmp.empty()) {
+Use &U = Tmp.back();
+Tmp.pop_back();
+if (isa(U.getUser()))
+  Uses.emplace_back(U);
+else
+  transform(U.getUser()->uses(), std::back_inserter(Tmp), [](auto &&U) {
+return std::ref(U);
+  });
+  }
+
+  return Uses;
+}
+
+static inline GlobalVariable *getGlobalForName(GlobalVariable *G) {
+  // Create an anonymous global which stores the variable's name, which will be
+  // used by the HIPSTDPAR runtime to look up the program-wide symbol.
+  LLVMContext &Ctx = G->getContext();
+  auto *CDS = ConstantDataArray::getString(Ctx, G->getName());
+
+  GlobalVariable *N = G->getParent()->getOrInsertGlobal("", CDS->getType());
+  N->setInitializer(CDS);
+  N->setLinkage(GlobalValue::LinkageTypes::PrivateLinkage);
+  N->setConstant(true);
+
+  return N;
+}
+
+static inline GlobalVariable *getIndirectionGlobal(Module *M) {
+  // Create an anonymous global which stores a pointer to a pointer, which will
+  // be externally initialised by the HIPSTDPAR runtime with the address of the
+  // program-wide symbol.
+  Type *PtrTy =
+  PointerType::get(M->getContext(),
+   M->getDataLayout().getDefaultGlobalsAddressSpace());
+  GlobalVariable *NewG = M->getOrInsertGlobal("", PtrTy);
+
+  NewG->setInitializer(PoisonValue::get(NewG->getValueType()));
+  NewG->setLinkage(GlobalValue::LinkageTypes::PrivateLinkage);
+  NewG->setConstant(true);
+  NewG->setExternallyInitialized(true);
+
+  return NewG;
+}
+
+static inline Constant *appendIndirectedGlobal(
+const GlobalVariable *IndirectionTable,
+SmallVector &SymbolIndirections,
+GlobalVariable *ToIndirect) {
+  Module *M = ToIndirect->getParent();
+
+  auto *InitTy = cast(IndirectionTable->getValueType());
+  auto *SymbolListTy = cast(InitTy->getStructElementType(2));
+  Type *NameTy = SymbolListTy->getElementType(0);
+  Type *IndirectTy = SymbolListTy->getElementType(1);
+
+  Constant *NameG = getGlobalForName(ToIndirect);
+  Constant *IndirectG = getIndirectionGlobal(M);
+  Constant *Entry = ConstantStruct::get(
+  SymbolListTy, {ConstantExpr::getAddrSpaceCast(NameG, NameTy),
+ ConstantExpr::getAddrSpaceCast(IndirectG, IndirectTy)});
+  SymbolIndirections.push_back(Entry);
+
+  return IndirectG;
+}
+
+static void fillIndirectionTable(GlobalVariable *IndirectionTable,
+ SmallVector Indirections) {
+  Module *M = IndirectionTable->getParent();
+  size_t SymCnt = Indirections.size();
+
+  auto *InitTy = cast(IndirectionTable->getValueType());
+  Type *SymbolListTy = InitTy->getStructElementType(1);
+  auto *SymbolTy = cast(InitTy->getStructElementType(2));
+
+  Constant *Count = ConstantInt::get(InitTy->getStructElementType(0), SymCnt);
+  M->removeGlobalV

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

2025-07-11 Thread Baranov Victor via cfe-commits

vbvictor wrote:

I will take a look at the weekend.
Sorry for double ping of other reviewers, GitHub mobile is kind of strange..

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


[clang] [llvm] [HIPSTDPAR] Add support for globals (PR #146813)

2025-07-11 Thread Alex Voicu via cfe-commits


@@ -114,24 +115,221 @@ static inline void clearModule(Module &M) { // TODO: 
simplify.
 eraseFromModule(*M.ifuncs().begin());
 }
 
+static inline SmallVector>
+collectIndirectableUses(GlobalVariable *G) {
+  // We are interested only in use chains that end in an Instruction.
+  SmallVector> Uses;
+
+  SmallVector> Tmp(G->use_begin(), G->use_end());
+  while (!Tmp.empty()) {
+Use &U = Tmp.back();
+Tmp.pop_back();
+if (isa(U.getUser()))
+  Uses.emplace_back(U);
+else
+  transform(U.getUser()->uses(), std::back_inserter(Tmp),
+[](auto &&U) { return std::ref(U); });
+  }
+
+  return Uses;
+}
+
+static inline GlobalVariable *getGlobalForName(GlobalVariable *G) {
+  // Create an anonymous global which stores the variable's name, which will be
+  // used by the HIPSTDPAR runtime to look up the program-wide symbol.
+  LLVMContext &Ctx = G->getContext();
+  auto *CDS = ConstantDataArray::getString(Ctx, G->getName());
+
+  GlobalVariable *N = G->getParent()->getOrInsertGlobal("", CDS->getType());
+  N->setInitializer(CDS);
+  N->setLinkage(GlobalValue::LinkageTypes::PrivateLinkage);
+  N->setConstant(true);
+
+  return N;
+}
+
+static inline GlobalVariable *getIndirectionGlobal(Module *M) {
+  // Create an anonymous global which stores a pointer to a pointer, which will
+  // be externally initialised by the HIPSTDPAR runtime with the address of the
+  // program-wide symbol.
+  Type *PtrTy = PointerType::get(
+  M->getContext(), M->getDataLayout().getDefaultGlobalsAddressSpace());
+  GlobalVariable *NewG = M->getOrInsertGlobal("", PtrTy);
+
+  NewG->setInitializer(PoisonValue::get(NewG->getValueType()));
+  NewG->setLinkage(GlobalValue::LinkageTypes::PrivateLinkage);
+  NewG->setConstant(true);
+  NewG->setExternallyInitialized(true);
+
+  return NewG;
+}
+
+static inline Constant *
+appendIndirectedGlobal(const GlobalVariable *IndirectionTable,
+   SmallVector &SymbolIndirections,
+   GlobalVariable *ToIndirect) {
+  Module *M = ToIndirect->getParent();
+
+  auto *InitTy = cast(IndirectionTable->getValueType());
+  auto *SymbolListTy = cast(InitTy->getStructElementType(2));
+  Type *NameTy = SymbolListTy->getElementType(0);
+  Type *IndirectTy = SymbolListTy->getElementType(1);
+
+  Constant *NameG = getGlobalForName(ToIndirect);
+  Constant *IndirectG = getIndirectionGlobal(M);
+  Constant *Entry = ConstantStruct::get(
+  SymbolListTy, {ConstantExpr::getAddrSpaceCast(NameG, NameTy),
+ ConstantExpr::getAddrSpaceCast(IndirectG, IndirectTy)});
+  SymbolIndirections.push_back(Entry);
+
+  return IndirectG;
+}
+
+static void fillIndirectionTable(GlobalVariable *IndirectionTable,
+ SmallVector Indirections) {
+  Module *M = IndirectionTable->getParent();
+  size_t SymCnt = Indirections.size();
+
+  auto *InitTy = cast(IndirectionTable->getValueType());
+  Type *SymbolListTy = InitTy->getStructElementType(1);
+  auto *SymbolTy = cast(InitTy->getStructElementType(2));
+
+  Constant *Count = ConstantInt::get(InitTy->getStructElementType(0), SymCnt);
+  M->removeGlobalVariable(IndirectionTable);
+  GlobalVariable *Symbols =
+  M->getOrInsertGlobal("", ArrayType::get(SymbolTy, SymCnt));
+  Symbols->setLinkage(GlobalValue::LinkageTypes::PrivateLinkage);
+  Symbols->setInitializer(
+  ConstantArray::get(ArrayType::get(SymbolTy, SymCnt), {Indirections}));
+  Symbols->setConstant(true);
+
+  Constant *ASCSymbols = ConstantExpr::getAddrSpaceCast(Symbols, SymbolListTy);
+  Constant *Init = ConstantStruct::get(
+  InitTy, {Count, ASCSymbols, PoisonValue::get(SymbolTy)});
+  M->insertGlobalVariable(IndirectionTable);
+  IndirectionTable->setInitializer(Init);
+}
+
+static void replaceWithIndirectUse(const Use &U, const GlobalVariable *G,
+   Constant *IndirectedG) {
+  auto *I = cast(U.getUser());
+
+  IRBuilder<> Builder(I);
+  Value *Op = I->getOperand(U.getOperandNo());
+
+  // We walk back up the use chain, which could be an arbitrarily long sequence
+  // of constexpr AS casts, ptr-to-int and GEP instructions, until we reach the
+  // indirected global.
+  while (auto *CE = dyn_cast(Op)) {
+assert((CE->getOpcode() == Instruction::GetElementPtr ||
+CE->getOpcode() == Instruction::AddrSpaceCast ||
+CE->getOpcode() == Instruction::PtrToInt) &&
+   "Only GEP, ASCAST or PTRTOINT constant uses supported!");
+
+Instruction *NewI = Builder.Insert(CE->getAsInstruction());
+I->replaceUsesOfWith(Op, NewI);
+I = NewI;
+Op = I->getOperand(0);
+Builder.SetInsertPoint(I);
+  }
+
+  assert(Op == G && "Must reach indirected global!");
+
+  Builder.GetInsertPoint()->setOperand(

AlexVlx wrote:

I was wrong, I wasn't thinking about stores, so there WAS a bug with the 
current formulation, so cheers for catching that!

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

[clang] [llvm] Fix Windows EH IP2State tables (remove +1 bias) (PR #144745)

2025-07-11 Thread Eli Friedman via cfe-commits


@@ -37,9 +37,11 @@ cond.end: ; preds = 
%entry, %cond.true
 ; CHECK: testq
 ; CHECK: je
 ; CHECK: callq alloc
+; CHECK-NEXT: nop

efriedma-quic wrote:

Do we actually need a nop here?  As far as I can tell, msvc doesn't insert one.

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


[clang] [llvm] Fix Windows EH IP2State tables (remove +1 bias) (PR #144745)

2025-07-11 Thread Eli Friedman via cfe-commits


@@ -101,7 +101,8 @@ define void @f5() "frame-pointer"="all" {
 ; CHECK-NEXT:.seh_endprologue
 ; CHECK-NEXT:leaq -92(%rbp), %rcx
 ; CHECK-NEXT:callq external
-; CHECK-NEXT:nop
+; UEFI does not have SEH, so does not require NOP
+; WIN64-NEXT:nop

efriedma-quic wrote:

This looks hand-edited; please regenerate with update_llc_test_checks.

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


[clang] [llvm] Fix Windows EH IP2State tables (remove +1 bias) (PR #144745)

2025-07-11 Thread Eli Friedman via cfe-commits


@@ -84,12 +84,12 @@ define void @pr66984(ptr %arg) personality ptr 
@__CxxFrameHandler3 {
 ; X86_64-NEXT:movq %rcx, {{[-0-9]+}}(%r{{[sb]}}p) # 8-byte Spill
 ; X86_64-NEXT:  .Ltmp0:
 ; X86_64-NEXT:callq throw
+; X86_64-NEXT:nop

efriedma-quic wrote:

Should this be an int3?

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


[clang] [llvm] Fix Windows EH IP2State tables (remove +1 bias) (PR #144745)

2025-07-11 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

You might need to edit the FileCheck commands for the UEFI tests so there's a 
non-overlapping prefix it can use.  (When two outputs in the same test file are 
different, FileCheck usually splits the emitted checks on a per-function basis.)

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


[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

What is debug info size impact?

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


[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

> @fmayer
> 
> > I would prefer this to be behind a flag (not necessarily in this PR), even 
> > if it's default turned on. People might not want synthetic frames added to 
> > their debug information and the top frame to point to the real code; also 
> > as this somewhat overlaps with the logic of 
> > `-fsanitize-annotate-debug-info`, with a flag people can choose which one 
> > they want.
> 
> Do you have a concrete use case where it would be problematic to emit the 
> trap reasons in debug info as the patch does? We are not opposed to adding a 
> flag that allows it to be disabled (e.g. `-fno-sanitize-annotated-traps` or 
> something similar) provided the trap reasons are emitted by default. That 
> being said we don't want to implement things that won't be used. What use 
> case(s) do you have in mind?

I am sure it will break some users how have some stack trace analyzers. Flag 
will unblock compiler upgrade for them.
So having a flag sounds reasonable to me. I don't have opinion what should be a 
default for that flag.

In this patch probaly (copt<> "defaut is off") is OK, and in followup patch 
copt -> clang flag.

Given that it's done for fsanitize-annotate-debug-info, should be easy, just 
"replay" that patch. However that patch includes per-sanitizer granularity, 
which may be not needed?



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


[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Vitaly Buka via cfe-commits


@@ -85,6 +85,96 @@ enum VariableTypeDescriptorKind : uint16_t {
 //Miscellaneous Helper Methods
 //======//
 
+static llvm::StringRef GetUBSanTrapForHandler(SanitizerHandler ID) {

vitalybuka wrote:

Can we put this into llvm-project/clang/lib/CodeGen/SanitizerHandler.h as 

SANITIZER_CHECK(AddOverflow, add_overflow, 0, "Signed integer addition 
overflowed")   


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


[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Vitaly Buka via cfe-commits


@@ -85,6 +85,96 @@ enum VariableTypeDescriptorKind : uint16_t {
 //Miscellaneous Helper Methods
 //======//
 
+static llvm::StringRef GetUBSanTrapForHandler(SanitizerHandler ID) {
+  switch (ID) {
+  case SanitizerHandler::AddOverflow:
+return "Signed integer addition overflowed";
+
+  case SanitizerHandler::BuiltinUnreachable:
+return "_builtin_unreachable(), execution reached an unreachable program "
+   "point";
+
+  case SanitizerHandler::CFICheckFail:
+return "Control flow integrity check failed";
+
+  case SanitizerHandler::DivremOverflow:
+return "Signed integer divide or remainder overflowed";
+
+  case SanitizerHandler::DynamicTypeCacheMiss:
+return "Dynamic type cache miss, member call made on an object whose "
+   "dynamic type differs from the expected type";
+
+  case SanitizerHandler::FloatCastOverflow:
+return "Floating-point to integer conversion overflowed";
+
+  case SanitizerHandler::FunctionTypeMismatch:
+return "Function called with mismatched signature";
+
+  case SanitizerHandler::ImplicitConversion:
+return "Implicit integer conversion overflowed or lost data";
+
+  case SanitizerHandler::InvalidBuiltin:
+return "Invalid use of builtin function";
+
+  case SanitizerHandler::InvalidObjCCast:
+return "Invalid Objective-C cast";
+
+  case SanitizerHandler::LoadInvalidValue:
+return "Loaded an invalid or uninitialized value for the type";
+
+  case SanitizerHandler::MissingReturn:
+return "Execution reached the end of a value-returning function without "
+   "returning a value";
+
+  case SanitizerHandler::MulOverflow:
+return "Signed integer multiplication overflowed";
+
+  case SanitizerHandler::NegateOverflow:
+return "Signed integer negation overflowed";
+
+  case SanitizerHandler::NullabilityArg:
+return "Passing null as an argument which is annotated with "
+   "_Nonnull";
+
+  case SanitizerHandler::NullabilityReturn:
+return "Returning null from a function with a return type annotated with "
+   "_Nonnull";
+
+  case SanitizerHandler::NonnullArg:
+return "Passing null pointer as an argument which is declared to never be "
+   "null";
+
+  case SanitizerHandler::NonnullReturn:
+return "Returning null pointer from a function which is declared to never "
+   "return null";
+
+  case SanitizerHandler::OutOfBounds:
+return "Array index out of bounds";
+
+  case SanitizerHandler::PointerOverflow:
+return "Pointer arithmetic overflowed bounds";
+
+  case SanitizerHandler::ShiftOutOfBounds:
+return "Shift exponent is too large for the type";
+
+  case SanitizerHandler::SubOverflow:
+return "Signed integer subtraction overflowed";
+
+  case SanitizerHandler::TypeMismatch:
+return "Type mismatch in operation";

vitalybuka wrote:

Let's not do that and instead fix ambiguity by splitting enum

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


[clang] [llvm] [libclang][Cygwin] Provide unversioned DLL file alongside versioned one (PR #147132)

2025-07-11 Thread Tomohiro Kashiwada via cfe-commits

https://github.com/kikairoya updated 
https://github.com/llvm/llvm-project/pull/147132

>From 9198e98e6dd7a02c5c5b65e400d788b6bac3a3c3 Mon Sep 17 00:00:00 2001
From: kikairoya 
Date: Sat, 28 Jun 2025 13:11:42 +0900
Subject: [PATCH 1/6] [libclang][Cygwin] Put unversioned DLL file aside of
 versioned DLL file

On Cygwin, a shared library target generates a versioned DLL file like
"cyg${OUTPUT_NAME}-${VERSION}.dll" and an import library
"lib${OUTPUT_NAME}.dll.a", but it does *not* generate the expected
unversioned symlink "cyg${OUTPUT_NAME}.dll" as is typical on other Unix-like 
platforms.

However, `dlopen()` calls typically use the unversioned form (e.g. 
"cygclang.dll"),
and this is consistent with usage on other platforms. In particular, 
`clang-python`
relies on this behavior. Although the Cygwin runtime can resolve other forms 
like
"libclang.so" or "libclang.dll", a symlink alone won't suffice here, as 
`dlopen()`
ultimately calls `LoadLibraryExW`, which does not follow Cygwin-style symlinks.

Therefore, this patch installs an unversioned copy of the DLL without the 
version
suffix to improve compatibility with `dlopen()` and tools like `clang-python`.
---
 clang/tools/libclang/CMakeLists.txt | 23 ++-
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/clang/tools/libclang/CMakeLists.txt 
b/clang/tools/libclang/CMakeLists.txt
index ac7a9a8db37c0..9c5ca26aab099 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -157,15 +157,28 @@ if(ENABLE_STATIC)
 endif()
 
 if(ENABLE_SHARED)
-  if(WIN32)
+  if(WIN32 OR CYGWIN)
 set_target_properties(libclang
   PROPERTIES
   VERSION ${LIBCLANG_LIBRARY_VERSION}
   DEFINE_SYMBOL _CINDEX_LIB_)
-  # Avoid declaring clang c++ symbols that are statically linked into 
libclang as dllimport'ed.
-  # If llvm/libclang-cpp dll is also being built for windows clang c++ 
symbols will still be
-  # implicitly be exported from libclang.
-  target_compile_definitions(libclang PRIVATE CLANG_BUILD_STATIC)
+if (CYGWIN)
+  # On Cygwin environment, a library target generates 
"cyg${OUTPUT_NAME}-${VERSION}.dll" and "lib${OUTPUT_NAME}.dll.a" but
+  # don't provide link "cyg${OUTPUT_NAME}.dll" differs from expected as 
other Unix platforms.
+  # Although, to dlopen(), usually "cyg${OUTPUT_NAME}.dll" will be passed 
(or "lib${OUTPUT_NAME}.dll" and "lib${OUTPUT_NAME}.so"
+  # are also viable as Cygwin runtime replaces those prefix and suffix), 
which is same manner to other Unix platforms,
+  # and clang-python does so.
+  # Thus, put a copy of dll named without version suffix to convinience to 
use of dlopen(). A symbolic link can't be
+  # viable here as the path passed to dlopen() will be passed directly to 
LoadLibraryExW, so it must be a real file.
+  set(UNPAINTED_TARGET_NAME 
"$/$clang$")
+  add_custom_command(TARGET libclang POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy 
"$" "${UNPAINTED_TARGET_NAME}")
+  install(FILES "${UNPAINTED_TARGET_NAME}" DESTINATION 
"${CMAKE_INSTALL_BINDIR}" COMPONENT libclang)
+endif()
+# Avoid declaring clang c++ symbols that are statically linked into 
libclang as dllimport'ed.
+# If llvm/libclang-cpp dll is also being built for windows clang c++ 
symbols will still be
+# implicitly be exported from libclang.
+target_compile_definitions(libclang PRIVATE CLANG_BUILD_STATIC)
   elseif(APPLE)
 set(LIBCLANG_LINK_FLAGS " -Wl,-compatibility_version -Wl,1")
 set(LIBCLANG_LINK_FLAGS "${LIBCLANG_LINK_FLAGS} -Wl,-current_version 
-Wl,${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")

>From 64e727aa96fbe69b0d637e243895fcd43dbf8701 Mon Sep 17 00:00:00 2001
From: kikairoya 
Date: Sat, 5 Jul 2025 22:01:59 +0900
Subject: [PATCH 2/6] rewrite comment

---
 clang/tools/libclang/CMakeLists.txt | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/clang/tools/libclang/CMakeLists.txt 
b/clang/tools/libclang/CMakeLists.txt
index 9c5ca26aab099..d3214104e6e0d 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -163,13 +163,15 @@ if(ENABLE_SHARED)
   VERSION ${LIBCLANG_LIBRARY_VERSION}
   DEFINE_SYMBOL _CINDEX_LIB_)
 if (CYGWIN)
-  # On Cygwin environment, a library target generates 
"cyg${OUTPUT_NAME}-${VERSION}.dll" and "lib${OUTPUT_NAME}.dll.a" but
-  # don't provide link "cyg${OUTPUT_NAME}.dll" differs from expected as 
other Unix platforms.
-  # Although, to dlopen(), usually "cyg${OUTPUT_NAME}.dll" will be passed 
(or "lib${OUTPUT_NAME}.dll" and "lib${OUTPUT_NAME}.so"
-  # are also viable as Cygwin runtime replaces those prefix and suffix), 
which is same manner to other Unix platforms,
-  # and clang-python does so.
-  # Thus, put a copy of dll named without version suffix to convinience to 
use of dlopen(). A symbolic link can't be
-  # viable h

[clang] [WIP][DO NOT MERGE][Clang][Driver] Emit warning when -fsanitize-trap=<...> is passed without associated -fsanitize=<...> (PR #147997)

2025-07-11 Thread Dan Liew via cfe-commits

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

Looks good for the sketch patch. I have a few minor questions and nits that 
I've left. Please add a few driver test cases to illustrate how you expect this 
to work (including a test case that suppresses the warning).

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


[clang] [clang-tools-extra] [lldb] [Clang][AST][NFC] (`RecordDecl` -> `CXXRecordDecl`)`::isInjectedClassName` (PR #148195)

2025-07-11 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

> > I'm not sure if I should update 
> > `llvm/include/llvm/Testing/Demangle/DemangleTestCases.inc` and 
> > `libcxxabi/test/DemangleTestCases.inc`.
> 
> Why would you need to? There are no changes to mangling/demangling here AFAICT

These files test demangling `RecordDecl::isInjectedClassName`, which will be 
out-of-date (I think) after merging this PR.

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


[clang] [Clang] Extract offloading code from static libs with 'offload-arch=' (PR #147823)

2025-07-11 Thread Michael Klemm via cfe-commits

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

LGTM

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


[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Dan Liew via cfe-commits

delcypher wrote:

@PiJoules 

> Moving forward, I think it would be good to gather consensus on a better 
> scheme with respect to verbose messages handled by the debugger. Rather than 
> baking a custom format into the function name, we think it's more portable 
> and straightforward to use standard dwarf features. If we don't end up using 
> DW_AT_description in this PR, I think it would be good to at least ensure 
> that using this mangled format isn't a permanent status quo and we leave room 
> for incremental improvements in the future towards a more portable 
> standardized approach. Such a scheme definitely needs more flushing out than 
> what I posted earlier in this thread, so I'll likely post an RFC on discourse 
> with a more formal proposal some time in the future.

I don't think we are strongly tied to the mangled function name format (in fact 
we've already changed the mangling once internally already). If we do introduce 
a new approach based on `DW_AT_description` then provided we can have LLDB 
understand both the old (mangled function name) and new approach (uing 
`DW_AT_description`) for encoding the trap reasons for a few releases (so that 
newer debuggers can handle older binaries) then I suspect that would be fine. 
@Michael137 @adrian-prantl may want to chime in though.

An RFC on a more fleshed out version of what you sketched out would be great. 
When writing it though please consider that UBSan is not the only use case for 
this. In particular

* `-fbounds-safety` (implemented in the open source Swift fork of clang) uses 
this mechanism too in an incredibly similar way. 
* `__builtin_verbose_trap` (which is already adopted in libcxx IIRC) uses the 
current mechanism.
* Swift uses a very similar mechanism for its traps but the implementation is 
independent from Clang. Swift's implementation is in fact the inspiration for 
how we implemented representing trap messages in Clang.

If  `DW_AT_description` just encodes a static string that would be general 
enough for `-fbounds-safety` and `__builtin_verbose_trap` but as soon as we 
start talking about "fake" arguments to the "fake" function in debug info then 
things get much more complicated and doesn't necessary generalize.

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


[clang] [Clang][P1061] Fix template arguments in local classes (PR #121225)

2025-07-11 Thread Jason Rice via cfe-commits


@@ -4433,8 +4433,12 @@ Sema::InstantiateClassMembers(SourceLocation 
PointOfInstantiation,
   // No need to instantiate in-class initializers during explicit
   // instantiation.
   if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) {
+// Handle local classes which could have substituted template params.
 CXXRecordDecl *ClassPattern =
-Instantiation->getTemplateInstantiationPattern();
+Instantiation->isLocalClass()
+? Instantiation->getInstantiatedFromMemberClass()
+: Instantiation->getTemplateInstantiationPattern();

ricejasonf wrote:

The comments for that states 
```cpp
  /// Retrieve the record declaration from which this record could be
  /// instantiated. Returns null if this class is not a template instantiation.
  const CXXRecordDecl *getTemplateInstantiationPattern() const;
```

So the "pattern" as I read it, is not an instantiation itself but the template 
(or partial specialization). In the case of the field in  `struct L` we need 
the intermediate instantiated struct to get the instantiated field.

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


[clang] [CIR] Upstream ComplexRealPtrOp for ComplexType (PR #144235)

2025-07-11 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/144235

>From 1543f10164d64c28951ae4fff396f58877c43f74 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Mon, 7 Jul 2025 20:52:33 +0200
Subject: [PATCH 1/2] [CIR] Upstream ComplexRealPtrOp for ComplexType

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 30 +++
 .../CIR/Dialect/IR/CIRTypeConstraints.td  | 24 +++
 clang/lib/CIR/CodeGen/CIRGenBuilder.h | 14 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  | 25 ++--
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   | 18 +++
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 18 +++
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.h   | 30 ---
 clang/test/CIR/CodeGen/complex.cpp| 16 +-
 clang/test/CIR/IR/invalid-complex.cir | 12 
 9 files changed, 174 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index d5cdb5aa91251..99fcb322a42d5 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2612,6 +2612,36 @@ def ComplexImagOp : CIR_Op<"complex.imag", [Pure]> {
   let hasFolder = 1;
 }
 
+//===--===//
+// ComplexRealPtrOp
+//===--===//
+
+def ComplexRealPtrOp : CIR_Op<"complex.real_ptr", [Pure]> {
+  let summary = "Derive a pointer to the real part of a complex value";
+  let description = [{
+`cir.complex.real_ptr` operation takes a pointer operand that points to a
+complex value of type `!cir.complex` and yields a pointer to the real part
+of the operand.
+
+Example:
+
+```mlir
+%1 = cir.complex.real_ptr %0 : !cir.ptr>
+  -> !cir.ptr
+```
+  }];
+
+  let results = (outs CIR_PtrToIntOrFloatType:$result);
+  let arguments = (ins CIR_PtrToComplexType:$operand);
+
+  let assemblyFormat = [{
+$operand `:`
+qualified(type($operand)) `->` qualified(type($result)) attr-dict
+  }];
+
+  let hasVerifier = 1;
+}
+
 
//===--===//
 // ComplexAddOp
 
//===--===//
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
index bcd516e27cc76..2bf77583465a6 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
@@ -159,6 +159,12 @@ def CIR_AnyIntOrFloatType : AnyTypeOf<[CIR_AnyFloatType, 
CIR_AnyIntType],
 let cppFunctionName = "isAnyIntegerOrFloatingPointType";
 }
 
+//===--===//
+// Complex Type predicates
+//===--===//
+
+def CIR_AnyComplexType : CIR_TypeBase<"::cir::ComplexType", "complex type">;
+
 
//===--===//
 // Pointer Type predicates
 
//===--===//
@@ -180,6 +186,17 @@ class CIR_PtrToPtrTo
 : CIR_ConfinedType],
 "pointer to pointer to " # summary>;
 
+// Pointee type constraint bases
+class CIR_PointeePred : SubstLeaves<"$_self",
+  "::mlir::cast<::cir::PointerType>($_self).getPointee()", pred>;
+
+class CIR_PtrToAnyOf types, string summary = "">
+: CIR_ConfinedType)>],
+  !if(!empty(summary),
+  "pointer to " # CIR_TypeSummaries.value,
+  summary)>;
+
 // Void pointer type constraints
 def CIR_VoidPtrType
 : CIR_PtrTo<"::cir::VoidType", "void type">,
@@ -192,6 +209,13 @@ def CIR_PtrToVoidPtrType
 "$_builder.getType<" # cppType # ">("
 "cir::VoidType::get($_builder.getContext(">;
 
+class CIR_PtrToType : CIR_PtrToAnyOf<[type]>;
+
+// Pointer to type constraints
+def CIR_PtrToIntOrFloatType : CIR_PtrToType;
+
+def CIR_PtrToComplexType : CIR_PtrToType;
+
 
//===--===//
 // Vector Type predicates
 
//===--===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index d95ea36a5e0d0..d0b6b6918f0e2 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -364,6 +364,20 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
 return create(loc, operandTy.getElementType(), 
operand);
   }
 
+  /// Create a cir.complex.real_ptr operation that derives a pointer to the 
real
+  /// part of the complex value pointed to by the specified pointer value.
+  mlir::Value createComplexRealPtr(mlir::Location loc, mlir::Value value) {
+auto srcPtrT

[clang] 44baef9 - [CIR] Use ZeroAttr as zeroinitializer for ComplexType (#148033)

2025-07-11 Thread via cfe-commits

Author: Amr Hesham
Date: 2025-07-11T19:57:21+02:00
New Revision: 44baef98431e21309a4b364fa7b3704a7b687ad6

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

LOG: [CIR] Use ZeroAttr as zeroinitializer for ComplexType (#148033)

Use ZeroAttr as a zeroinitializer for ComplexType, similar to what we
did in CXXScalarValueInitExpr

https://github.com/llvm/llvm-project/issues/141365

Added: 


Modified: 
clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
clang/test/CIR/CodeGen/complex.cpp

Removed: 




diff  --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
index 24a9bf13e1880..cb83691b4452d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
@@ -291,12 +291,8 @@ mlir::Value ComplexExprEmitter::VisitInitListExpr(const 
InitListExpr *e) {
   }
 
   assert(e->getNumInits() == 0 && "Unexpected number of inits");
-  QualType complexElemTy =
-  e->getType()->castAs()->getElementType();
-  mlir::Type complexElemLLVMTy = cgf.convertType(complexElemTy);
-  mlir::TypedAttr defaultValue = builder.getZeroInitAttr(complexElemLLVMTy);
-  auto complexAttr = cir::ConstComplexAttr::get(defaultValue, defaultValue);
-  return builder.create(loc, complexAttr);
+  mlir::Type complexTy = cgf.convertType(e->getType());
+  return builder.getNullValue(complexTy, loc);
 }
 
 mlir::Value

diff  --git a/clang/test/CIR/CodeGen/complex.cpp 
b/clang/test/CIR/CodeGen/complex.cpp
index 6e7e889df146f..f33909150044e 100644
--- a/clang/test/CIR/CodeGen/complex.cpp
+++ b/clang/test/CIR/CodeGen/complex.cpp
@@ -31,7 +31,7 @@ float _Complex cf2 = { 1.0f, 2.0f };
 void foo() { int _Complex c = {}; }
 
 // CIR: %[[INIT:.*]] = cir.alloca !cir.complex, 
!cir.ptr>, ["c", init]
-// CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.int<0> : !s32i, 
#cir.int<0> : !s32i> : !cir.complex
+// CIR: %[[COMPLEX:.*]] = cir.const #cir.zero : !cir.complex
 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex, 
!cir.ptr>
 
 // LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4
@@ -741,7 +741,7 @@ void foo29() {
 }
 
 // CIR: %[[INIT:.*]] = cir.alloca !cir.complex, 
!cir.ptr>, ["a", init]
-// CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.int<0> : !s32i, 
#cir.int<0> : !s32i> : !cir.complex
+// CIR: %[[COMPLEX:.*]] = cir.const #cir.zero : !cir.complex
 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex, 
!cir.ptr>
 
 // LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4



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


[clang] [llvm] Fix Windows EH IP2State tables (remove +1 bias) (PR #144745)

2025-07-11 Thread Eli Friedman via cfe-commits


@@ -84,12 +84,12 @@ define void @pr66984(ptr %arg) personality ptr 
@__CxxFrameHandler3 {
 ; X86_64-NEXT:movq %rcx, {{[-0-9]+}}(%r{{[sb]}}p) # 8-byte Spill
 ; X86_64-NEXT:  .Ltmp0:
 ; X86_64-NEXT:callq throw
+; X86_64-NEXT:nop

efriedma-quic wrote:

I think this is optimized code.

I didn't really think that deeply when I suggested looking for a block with no 
successors.  In this case, you end up with two edges: an unwind edge, and a 
fallthrough edge to a an empty block with no successors.  Which is a pattern 
you could detect, I guess.

I don't want the initial patch here to get too complicated here, though, so it 
would be fine to just file an issue for this, and look into it later.

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


[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

> There is still one test case that fails: `cfi-check-fail-debuginfo.c`. From 
> the crash report, I thought it was due to double wrapping, so I initially 
> added a guard to prevent that, leading the test case to pass. Upon internal 
> discussion, the guard has since been removed because double wrapping may be 
> intended behavior. Crash report is left in the comments.

This part is not useful as a commit message.

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


[clang] [CIR] Use ZeroAttr as zeroinitializer for ComplexType (PR #148033)

2025-07-11 Thread Amr Hesham via cfe-commits

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


[clang] [llvm] Fix Windows EH IP2State tables (remove +1 bias) (PR #144745)

2025-07-11 Thread Eli Friedman via cfe-commits


@@ -37,9 +37,11 @@ cond.end: ; preds = 
%entry, %cond.true
 ; CHECK: testq
 ; CHECK: je
 ; CHECK: callq alloc
+; CHECK-NEXT: nop

efriedma-quic wrote:

There is no handler?  This function doesn't contain any exception-handling 
constructs at all.

MSVC does not insert a nop before the epilogue in this case, as far as I can 
tell.

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


[clang] [llvm] Fix Windows EH IP2State tables (remove +1 bias) (PR #144745)

2025-07-11 Thread via cfe-commits

sivadeilra wrote:

> This looks hand-edited; please regenerate with update_llc_test_checks.

I ran `update_llc_test_checks.py` on `win64_frame.ll` and it deleted all of the 
checks from the body of `f5` and `f6`.  That doesn't seem right.

I tried running it with `--function f5` and it still deleted everything in `f5` 
and also appended this to the end of the file:

```
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add 
tests below this line:
; CHECK: {{.*}}
```

Is that because the output of `f5` and `f6` are now different between the 
variations in this file?

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


[clang] [Clang] fix crash in codegen caused by deferred asm diagnostics under -fopenmp (PR #147163)

2025-07-11 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

I don't think we want to use the "isInvalidDecl" bit here.  The declaration is 
still valid in the sense that code referring to the declaration should treat it 
normally.  (For example, we want overload resolution to work the same way it 
usually does.)

One way to think of this is that we're essentially inferring __device__ 
markings for functions that can't be built on the host.  Then if it turns out 
we actually need the function on the host, we error out because you're trying 
to use a function that isn't available.

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


[clang] [llvm] [AMDGPU] Add support for `v_tanh_bf16` on gfx1250 (PR #147425)

2025-07-11 Thread Shilei Tian via cfe-commits

shiltian wrote:

This PR is messed up at this moment.

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


[clang] [clang][OpenMP] In 6.0, can omit length in array section (PR #148048)

2025-07-11 Thread David Pagan via cfe-commits

ddpagan wrote:

@alexey-bataev - thanks for reviewing, Alexey. I'll put together a codegen test.

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


[clang] [KeyInstr] Add release note & update option (PR #148244)

2025-07-11 Thread Nikita Popov via cfe-commits

https://github.com/nikic commented:

clang/test/DebugInfo/KeyInstructions/flag.cpp is failing.

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


[clang] [llvm] AMDGPU: Implement s_wait_asynccnt and s_wait_tensorcnt for gfx1250 (PR #148292)

2025-07-11 Thread Changpeng Fang via cfe-commits

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

None

>From c220c16d134dd1a1690e973abd4ca5b2401e6510 Mon Sep 17 00:00:00 2001
From: Changpeng Fang 
Date: Fri, 11 Jul 2025 13:20:00 -0700
Subject: [PATCH] AMDGPU: Implement s_wait_asynccnt and s_wait_tensorcnt for
 gfx1250

Co-Authored-by: Stanislav Mekhanoshin 
Co-Authored-by: Vang Thao 
---
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |  3 +++
 .../CodeGenOpenCL/builtins-amdgcn-gfx1250.cl  | 18 ++
 .../builtins-amdgcn-error-gfx1250-param.cl|  8 +++
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  | 12 ++
 llvm/lib/Target/AMDGPU/SOPInstructions.td | 23 ++
 .../AMDGPU/llvm.amdgcn.s.wait.gfx1250.ll  | 24 +++
 llvm/test/MC/AMDGPU/gfx1250_asm_sopp.s| 20 
 .../Disassembler/AMDGPU/gfx1250_dasm_sopp.txt | 15 
 8 files changed, 123 insertions(+)
 create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.wait.gfx1250.ll

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index a5ee8013adff6..4d371a9f7d6db 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -665,6 +665,9 @@ 
TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_barrier_arrive_rtn_b64, "LiLi*3Li", "n
 TARGET_BUILTIN(__builtin_amdgcn_s_setprio_inc_wg, "vIs", "n", 
"setprio-inc-wg-inst")
 TARGET_BUILTIN(__builtin_amdgcn_s_monitor_sleep,  "vIs", "n", "gfx1250-insts")
 
+TARGET_BUILTIN(__builtin_amdgcn_s_wait_asynccnt, "vIUs", "n", "gfx1250-insts")
+TARGET_BUILTIN(__builtin_amdgcn_s_wait_tensorcnt, "vIUs", "n", "gfx1250-insts")
+
 TARGET_BUILTIN(__builtin_amdgcn_cvt_f16_fp8, "hiIi", "nc", "gfx1250-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_f16_bf8, "hiIi", "nc", "gfx1250-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f16_fp8, "V2hs", "nc", "gfx1250-insts")
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl
index 421099d3876e3..a1b91d0cc38dc 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl
@@ -24,6 +24,24 @@ void test_s_monitor_sleep() {
   __builtin_amdgcn_s_monitor_sleep(10);
 }
 
+// CHECK-LABEL: @test_s_wait_asynccnt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:call void @llvm.amdgcn.s.wait.asynccnt(i16 0)
+// CHECK-NEXT:ret void
+//
+void test_s_wait_asynccnt() {
+  __builtin_amdgcn_s_wait_asynccnt(0);
+}
+
+// CHECK-LABEL: @test_s_wait_tensorcnt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:call void @llvm.amdgcn.s.wait.tensorcnt(i16 0)
+// CHECK-NEXT:ret void
+//
+void test_s_wait_tensorcnt() {
+  __builtin_amdgcn_s_wait_tensorcnt(0);
+}
+
 // CHECK-LABEL: @test_cvt_f16_fp8(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[OUT_ADDR:%.*]] = alloca ptr addrspace(1), align 8, 
addrspace(5)
diff --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl 
b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl
index 7494c4f984353..9711b3bdded6b 100644
--- a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl
+++ b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl
@@ -12,6 +12,14 @@ void test_s_monitor_sleep(short a) {
   __builtin_amdgcn_s_monitor_sleep(a); // expected-error 
{{'__builtin_amdgcn_s_monitor_sleep' must be a constant integer}}
 }
 
+void test_s_wait_asynccnt(short a) {
+  __builtin_amdgcn_s_wait_asynccnt(a); // expected-error 
{{'__builtin_amdgcn_s_wait_asynccnt' must be a constant integer}}
+}
+
+void test_s_wait_tensorcnt(short a) {
+  __builtin_amdgcn_s_wait_tensorcnt(a); // expected-error 
{{'__builtin_amdgcn_s_wait_tensorcnt' must be a constant integer}}
+}
+
 void test__builtin_amdgcn_cvt_f16_fp8(int a, int b) {
   __builtin_amdgcn_cvt_f16_fp8(a, b); // expected-error 
{{'__builtin_amdgcn_cvt_f16_fp8' must be a constant integer}}
 }
diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td 
b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index 16885f331e9dd..8016757cf0f3c 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -3510,6 +3510,18 @@ def int_amdgcn_ashr_pk_u8_i32 : 
ClangBuiltin<"__builtin_amdgcn_ashr_pk_u8_i32">,
 // gfx1250 intrinsics
 // 
===--===//
 
+// Async waits decrement ASYNCcnt and tensor waits decrement TENSORcnt which is
+// modeled as InaccessibleMem.
+class AMDGPUWaitAsyncIntrinsic :
+  Intrinsic<[], [llvm_i16_ty],
+  [IntrInaccessibleMemOnly, ImmArg>, IntrWillReturn, 
IntrNoCallback,
+   IntrNoFree]>;
+
+def int_amdgcn_s_wait_asynccnt :
+ClangBuiltin<"__builtin_amdgcn_s_wait_asynccnt">, AMDGPUWaitAsyncIntrinsic;
+def int_amdgcn_s_wait_tensorcnt :
+ClangBuiltin<"__builtin_amdgcn_s_wait_tensorcnt">, 
AMDGPUWaitAsyncIntrinsic;
+
 def int_amdgcn_ds_atomic_async_barrier_arrive_b64 :
   ClangBuiltin<"__builtin_amdgcn_ds_atomic

[clang] [llvm] AMDGPU: Implement s_wait_asynccnt and s_wait_tensorcnt for gfx1250 (PR #148292)

2025-07-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Changpeng Fang (changpeng)


Changes



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


8 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsAMDGPU.def (+3) 
- (modified) clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl (+18) 
- (modified) clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl (+8) 
- (modified) llvm/include/llvm/IR/IntrinsicsAMDGPU.td (+12) 
- (modified) llvm/lib/Target/AMDGPU/SOPInstructions.td (+23) 
- (added) llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.wait.gfx1250.ll (+24) 
- (modified) llvm/test/MC/AMDGPU/gfx1250_asm_sopp.s (+20) 
- (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_sopp.txt (+15) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index a5ee8013adff6..4d371a9f7d6db 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -665,6 +665,9 @@ 
TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_barrier_arrive_rtn_b64, "LiLi*3Li", "n
 TARGET_BUILTIN(__builtin_amdgcn_s_setprio_inc_wg, "vIs", "n", 
"setprio-inc-wg-inst")
 TARGET_BUILTIN(__builtin_amdgcn_s_monitor_sleep,  "vIs", "n", "gfx1250-insts")
 
+TARGET_BUILTIN(__builtin_amdgcn_s_wait_asynccnt, "vIUs", "n", "gfx1250-insts")
+TARGET_BUILTIN(__builtin_amdgcn_s_wait_tensorcnt, "vIUs", "n", "gfx1250-insts")
+
 TARGET_BUILTIN(__builtin_amdgcn_cvt_f16_fp8, "hiIi", "nc", "gfx1250-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_f16_bf8, "hiIi", "nc", "gfx1250-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f16_fp8, "V2hs", "nc", "gfx1250-insts")
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl
index 421099d3876e3..a1b91d0cc38dc 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl
@@ -24,6 +24,24 @@ void test_s_monitor_sleep() {
   __builtin_amdgcn_s_monitor_sleep(10);
 }
 
+// CHECK-LABEL: @test_s_wait_asynccnt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:call void @llvm.amdgcn.s.wait.asynccnt(i16 0)
+// CHECK-NEXT:ret void
+//
+void test_s_wait_asynccnt() {
+  __builtin_amdgcn_s_wait_asynccnt(0);
+}
+
+// CHECK-LABEL: @test_s_wait_tensorcnt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:call void @llvm.amdgcn.s.wait.tensorcnt(i16 0)
+// CHECK-NEXT:ret void
+//
+void test_s_wait_tensorcnt() {
+  __builtin_amdgcn_s_wait_tensorcnt(0);
+}
+
 // CHECK-LABEL: @test_cvt_f16_fp8(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[OUT_ADDR:%.*]] = alloca ptr addrspace(1), align 8, 
addrspace(5)
diff --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl 
b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl
index 7494c4f984353..9711b3bdded6b 100644
--- a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl
+++ b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl
@@ -12,6 +12,14 @@ void test_s_monitor_sleep(short a) {
   __builtin_amdgcn_s_monitor_sleep(a); // expected-error 
{{'__builtin_amdgcn_s_monitor_sleep' must be a constant integer}}
 }
 
+void test_s_wait_asynccnt(short a) {
+  __builtin_amdgcn_s_wait_asynccnt(a); // expected-error 
{{'__builtin_amdgcn_s_wait_asynccnt' must be a constant integer}}
+}
+
+void test_s_wait_tensorcnt(short a) {
+  __builtin_amdgcn_s_wait_tensorcnt(a); // expected-error 
{{'__builtin_amdgcn_s_wait_tensorcnt' must be a constant integer}}
+}
+
 void test__builtin_amdgcn_cvt_f16_fp8(int a, int b) {
   __builtin_amdgcn_cvt_f16_fp8(a, b); // expected-error 
{{'__builtin_amdgcn_cvt_f16_fp8' must be a constant integer}}
 }
diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td 
b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index 16885f331e9dd..8016757cf0f3c 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -3510,6 +3510,18 @@ def int_amdgcn_ashr_pk_u8_i32 : 
ClangBuiltin<"__builtin_amdgcn_ashr_pk_u8_i32">,
 // gfx1250 intrinsics
 // 
===--===//
 
+// Async waits decrement ASYNCcnt and tensor waits decrement TENSORcnt which is
+// modeled as InaccessibleMem.
+class AMDGPUWaitAsyncIntrinsic :
+  Intrinsic<[], [llvm_i16_ty],
+  [IntrInaccessibleMemOnly, ImmArg>, IntrWillReturn, 
IntrNoCallback,
+   IntrNoFree]>;
+
+def int_amdgcn_s_wait_asynccnt :
+ClangBuiltin<"__builtin_amdgcn_s_wait_asynccnt">, AMDGPUWaitAsyncIntrinsic;
+def int_amdgcn_s_wait_tensorcnt :
+ClangBuiltin<"__builtin_amdgcn_s_wait_tensorcnt">, 
AMDGPUWaitAsyncIntrinsic;
+
 def int_amdgcn_ds_atomic_async_barrier_arrive_b64 :
   ClangBuiltin<"__builtin_amdgcn_ds_atomic_async_barrier_arrive_b64">,
   Intrinsic<[], [local_ptr_ty],
diff --git a/llvm/lib/Target/AMDGPU/SOPInstructions.td 
b/llvm/lib/Target/AMDGPU/SOPInstructions.td
index c7c4276e0e252..2472b76fcf02c 100644
--- a/llvm/lib/Target/AMDGPU/SOPInstructions.td
+++ b/llv

[clang] [WIP][DO NOT MERGE][Clang][Driver] Emit warning when -fsanitize-trap=<...> is passed without associated -fsanitize=<...> (PR #147997)

2025-07-11 Thread Anthony Tran via cfe-commits


@@ -730,6 +754,18 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   options::OPT_fno_sanitize_recover_EQ);
   RecoverableKinds &= Kinds;
 
+  // Parse any -fsanitize-trap=<...> flags the user provided, then
+  // diagnose any which do not have a matching -fsanitize=<...>
+  if (DiagnoseErrors) {
+SanitizerMask ExplicitTrap = parseSanitizeArgs(

anthonyhatran wrote:

I tried that, but `parseSanitizeArgs` adds in the `SanitizerMask`, 
`TrappingDefault`, so it enables these bits: `SanitizerKind::CFI | 
SanitizerKind::LocalBounds` by default. This means more warnings are emitted 
than what the user actually entered. I could work around this, but I thought my 
approach would be cleaner. Let me know if you would prefer the 
`parseSanitizeTrapArgs` approach though.

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


[clang] [WIP][DO NOT MERGE][Clang][Driver] Emit warning when -fsanitize-trap=<...> is passed without associated -fsanitize=<...> (PR #147997)

2025-07-11 Thread Anthony Tran via cfe-commits

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


[clang] [llvm] [HLSL][RootSignature] Retain `SourceLocation` of `RootElement` for `SemaHLSL` diagnostics (PR #147115)

2025-07-11 Thread via cfe-commits

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


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


[clang-tools-extra] [clang-doc] Serialize record files with mangled name (PR #148021)

2025-07-11 Thread Erick Velez via cfe-commits

evelez7 wrote:

### Merge activity

* **Jul 11, 8:37 PM UTC**: A user started a stack merge that includes this pull 
request via 
[Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/148021).


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


[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Anthony Tran via cfe-commits

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


[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Anthony Tran via cfe-commits


@@ -68,9 +68,9 @@ double f1(int b, int i) {
 
 //.
 // CHECK-TRAP: [[META0:![0-9]+]] = distinct !DICompileUnit(language: 
DW_LANG_C11, file: [[META1:![0-9]+]], isOptimized: false, runtimeVersion: 0, 
emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
-// CHECK-TRAP: [[META1]] = !DIFile(filename: "", directory: {{.*}})
+// CHECK-TRAP: [[META1]] = !DIFile(filename: "{{.*}}", directory: 
{{.*}})

anthonyhatran wrote:

Removed, not needed.

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


[clang] [clang] Build argument string for clang::warn_unused_result (PR #148090)

2025-07-11 Thread via cfe-commits

https://github.com/zebullax updated 
https://github.com/llvm/llvm-project/pull/148090

>From 11909560ed6cb4e56192fbbfe4d8b1cdf58e1cb1 Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 09:12:44 +0900
Subject: [PATCH 1/2] Build argument string for clang::warn_unused_result

Preserve the argument-clause for `warn-unused-result` when under clang:: scope.
We are not touching gnu:: scope for now as it's an error for GCC to have that 
string. Personally I think it would be ok to relax it here too as we are not 
introducing breakage to currently passing code, but feedback is to go slowly 
about it.
---
 clang/lib/Sema/SemaDeclAttr.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 7ebb53318702c..221197b3849e0 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2902,7 +2902,8 @@ static void handleWarnUnusedResult(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 }
 
   StringRef Str;
-  if (AL.isStandardAttributeSyntax() && !AL.getScopeName()) {
+  if (AL.isStandardAttributeSyntax()
+  && (!AL.getScopeName() || AL.isClangScope())) {
 // The standard attribute cannot be applied to variable declarations such
 // as a function pointer.
 if (isa(D))

>From 9ecb0703fa8ff3a9ddd854a7b0d880219c61b3a7 Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 15:51:22 +0900
Subject: [PATCH 2/2] Add unit test to check reason string on clang scope

Signed-off-by: zebullax 

Fix scope in UT

Signed-off-by: zebullax 
---
 clang/test/SemaCXX/warn-unused-result.cpp | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/clang/test/SemaCXX/warn-unused-result.cpp 
b/clang/test/SemaCXX/warn-unused-result.cpp
index fa7540c116e67..1fd1d0e223a6a 100644
--- a/clang/test/SemaCXX/warn-unused-result.cpp
+++ b/clang/test/SemaCXX/warn-unused-result.cpp
@@ -364,3 +364,21 @@ void id_print_name() {
 ((int(*)())f)();
 }
 } // namespace GH117975
+
+namespace BuildStringOnClangScope {
+
+[[clang::warn_unused_result("Discarded result")]]
+bool makeClangTrue() { return true; }
+
+[[gnu::warn_unused_result("Discarded result")]]
+bool makeGccTrue() { return true; }
+
+void doClangThings() {
+  makeClangTrue(); // expected-warning {{ignoring return value of function 
declared with 'clang::warn_unused_result' attribute: Discarded result}}
+}
+
+void doGccThings() {
+  makeGccTrue(); // expected-warning {{ignoring return value of function 
declared with 'warn_unused_result' attribute}}
+}
+
+}
\ No newline at end of file

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


[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-11 Thread Anthony Tran via cfe-commits

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


[clang] AMDGPU: Remove "gws" from the “read-only” target feature list (PR #148141)

2025-07-11 Thread Changpeng Fang via cfe-commits

changpeng wrote:

Need to fix two additional LIT tests...

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


[clang] [clang] Build argument string for clang::warn_unused_result (PR #148090)

2025-07-11 Thread via cfe-commits

https://github.com/zebullax updated 
https://github.com/llvm/llvm-project/pull/148090

>From 11909560ed6cb4e56192fbbfe4d8b1cdf58e1cb1 Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 09:12:44 +0900
Subject: [PATCH 1/2] Build argument string for clang::warn_unused_result

Preserve the argument-clause for `warn-unused-result` when under clang:: scope.
We are not touching gnu:: scope for now as it's an error for GCC to have that 
string. Personally I think it would be ok to relax it here too as we are not 
introducing breakage to currently passing code, but feedback is to go slowly 
about it.
---
 clang/lib/Sema/SemaDeclAttr.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 7ebb53318702c..221197b3849e0 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2902,7 +2902,8 @@ static void handleWarnUnusedResult(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 }
 
   StringRef Str;
-  if (AL.isStandardAttributeSyntax() && !AL.getScopeName()) {
+  if (AL.isStandardAttributeSyntax()
+  && (!AL.getScopeName() || AL.isClangScope())) {
 // The standard attribute cannot be applied to variable declarations such
 // as a function pointer.
 if (isa(D))

>From 8b98b9e5cf0d88ffe7f2a9b8668e7ef0359c7c87 Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 15:51:22 +0900
Subject: [PATCH 2/2] Add unit test to check reason string on clang scope

Signed-off-by: zebullax 

Fix scope in UT

Signed-off-by: zebullax 

Fix UT

Signed-off-by: zebullax 
---
 clang/test/SemaCXX/warn-unused-result.cpp | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/warn-unused-result.cpp 
b/clang/test/SemaCXX/warn-unused-result.cpp
index fa7540c116e67..440306a235f08 100644
--- a/clang/test/SemaCXX/warn-unused-result.cpp
+++ b/clang/test/SemaCXX/warn-unused-result.cpp
@@ -249,7 +249,7 @@ void g() {
 
 namespace PR45520 {
 [[nodiscard]] bool (*f)(); // expected-warning {{'nodiscard' attribute only 
applies to functions, classes, or enumerations}}
-[[clang::warn_unused_result]] bool (*g)();
+[[clang::warn_unused_result]] bool (*g)(); // expected-warning 
{{'clang::warn_unused_result' attribute only applies to functions, classes, or 
enumerations}}
 __attribute__((warn_unused_result)) bool (*h)();
 
 void i([[nodiscard]] bool (*fp)()); // expected-warning {{'nodiscard' 
attribute only applies to functions, classes, or enumerations}}
@@ -364,3 +364,21 @@ void id_print_name() {
 ((int(*)())f)();
 }
 } // namespace GH117975
+
+namespace BuildStringOnClangScope {
+
+[[clang::warn_unused_result("Discarded result")]]
+bool makeClangTrue() { return true; }
+
+[[gnu::warn_unused_result("Discarded result")]]
+bool makeGccTrue() { return true; }
+
+void doClangThings() {
+  makeClangTrue(); // expected-warning {{ignoring return value of function 
declared with 'clang::warn_unused_result' attribute: Discarded result}}
+}
+
+void doGccThings() {
+  makeGccTrue(); // expected-warning {{ignoring return value of function 
declared with 'gnu::warn_unused_result' attribute}}
+}
+
+}
\ No newline at end of file

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


[clang] [Clang] Consider default template arguments when synthesizing CTAD guides (PR #147675)

2025-07-11 Thread Younan Zhang via cfe-commits


@@ -1061,15 +1061,36 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
   SmallVector DeduceResults(
   F->getTemplateParameters()->size());
 
+  // We don't have to deduce against the alias template specialization,
+  // if the source template is a synthesized alias deduction guide. This allows
+  // us to utilize the default template arguments from alias declaration.
+  //
+  //  template 
+  //  using Foo = A>;
+  //
+  //  template 
+  //  using Bar = Foo;
+  //
+  // In terms of Bar, we want U to appear in the synthesized deduction guide,
+  // but U would remain undeduced if we deduce against A instead of T.
+  // Also note that since the deduced results are only used for synthesizing
+  // template parameters, they should not introduce unintended behavior in
+  // theory.
+  ArrayRef Ps = FReturnType->template_arguments();
+  if (auto *DG = dyn_cast(F->getTemplatedDecl());
+  DG && DG->getSourceDeductionGuideKind() ==
+CXXDeductionGuideDecl::SourceDeductionGuideKind::Alias)
+Ps = F->getInjectedTemplateArgs(Context);

zyn0217 wrote:

I finally figured out another way to address it: we don't need to bother 
looking at the injected template arguments.

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


[clang] [Clang] Consider default template arguments when synthesizing CTAD guides (PR #147675)

2025-07-11 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/147675

>From f8b1894ad39560edb5bb0c14194a3a2d54a911ff Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Wed, 9 Jul 2025 16:29:45 +0800
Subject: [PATCH 1/3] [Clang] Consider default template arguments when
 synthesizing CTAD guides

We copy arguments from different template parameter lists depending on
the deducibility of the template parameters. In particular, we may lose
the default template argument from the original alias declaration, and
this patch helps preserve that.
---
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp | 34 +---
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  | 52 ---
 2 files changed, 74 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index bdc46a0115a45..3951813dc66dd 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -949,7 +949,7 @@ Expr *buildIsDeducibleConstraint(Sema &SemaRef,
 ReturnType = SemaRef.SubstType(
 ReturnType, Args, AliasTemplate->getLocation(),
 Context.DeclarationNames.getCXXDeductionGuideName(AliasTemplate));
-  };
+  }
 
   SmallVector IsDeducibleTypeTraitArgs = {
   Context.getTrivialTypeSourceInfo(
@@ -969,11 +969,14 @@ Expr *buildIsDeducibleConstraint(Sema &SemaRef,
 }
 
 std::pair>
-getRHSTemplateDeclAndArgs(Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate) 
{
+getRHSTemplateDeclAndArgs(Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate,
+  bool Desugar) {
   // Unwrap the sugared ElaboratedType.
   auto RhsType = AliasTemplate->getTemplatedDecl()
  ->getUnderlyingType()
  .getSingleStepDesugaredType(SemaRef.Context);
+  if (Desugar)
+RhsType = RhsType.getDesugaredType(SemaRef.Context);
   TemplateDecl *Template = nullptr;
   llvm::ArrayRef AliasRhsTemplateArgs;
   if (const auto *TST = RhsType->getAs()) {
@@ -1023,8 +1026,26 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
 
   auto &Context = SemaRef.Context;
   auto [Template, AliasRhsTemplateArgs] =
-  getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate);
+  getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate, /*Desugar=*/true);
 
+  // We need both types desugared, before we continue to perform type 
deduction.
+  // The intent is to get the template argument list 'matched', e.g. in the
+  // following case:
+  //
+  //
+  //  template 
+  //  struct A {};
+  //  template 
+  //  using Foo = A>;
+  //  template 
+  //  using Bar = Foo;
+  //
+  // In terms of Bar, we want U (which has the default argument) to appear in
+  // the synthesized deduction guide, but U would remain undeduced if we 
deduced
+  // A> using Foo directly.
+  //
+  // Instead, we need to canonicalize both against A, i.e. A> and A>,
+  // such that T can be deduced as U.
   auto RType = F->getTemplatedDecl()->getReturnType();
   // The (trailing) return type of the deduction guide.
   const TemplateSpecializationType *FReturnType =
@@ -1034,7 +1055,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
 FReturnType = InjectedCNT->getInjectedTST();
   else if (const auto *ET = RType->getAs())
 // explicit deduction guide.
-FReturnType = ET->getNamedType()->getAs();
+FReturnType = 
ET->getNamedType()->getAsNonAliasTemplateSpecializationType();
   assert(FReturnType && "expected to see a return type");
   // Deduce template arguments of the deduction guide f from the RHS of
   // the alias.
@@ -1223,7 +1244,7 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
 return;
   auto &Context = SemaRef.Context;
   auto [Template, AliasRhsTemplateArgs] =
-  getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate);
+  getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate, /*Desugar=*/false);
   if (!Template)
 return;
   auto SourceDeductionGuides = getSourceDeductionGuides(
@@ -1303,7 +1324,8 @@ FunctionTemplateDecl 
*DeclareAggregateDeductionGuideForTypeAlias(
 Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate,
 MutableArrayRef ParamTypes, SourceLocation Loc) {
   TemplateDecl *RHSTemplate =
-  getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate).first;
+  getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate, /*Desugar=*/false)
+  .first;
   if (!RHSTemplate)
 return nullptr;
 
diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp 
b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index aeb02c9e4898e..34bfa020f5baa 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -207,13 +207,14 @@ namespace test15 {
 template  struct Foo { Foo(T); };
 
 template using AFoo = Foo;
-template concept False = false;
+template concept False = false; // #test15_False
 template
-using BFoo = AFoo; // expected-note {{candidate template ignored: 
constraints not satisfied [with V = int]}} \
-  

[clang] [Clang] Consider default template arguments when synthesizing CTAD guides (PR #147675)

2025-07-11 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/147675

>From f8b1894ad39560edb5bb0c14194a3a2d54a911ff Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Wed, 9 Jul 2025 16:29:45 +0800
Subject: [PATCH 1/2] [Clang] Consider default template arguments when
 synthesizing CTAD guides

We copy arguments from different template parameter lists depending on
the deducibility of the template parameters. In particular, we may lose
the default template argument from the original alias declaration, and
this patch helps preserve that.
---
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp | 34 +---
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  | 52 ---
 2 files changed, 74 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index bdc46a0115a45..3951813dc66dd 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -949,7 +949,7 @@ Expr *buildIsDeducibleConstraint(Sema &SemaRef,
 ReturnType = SemaRef.SubstType(
 ReturnType, Args, AliasTemplate->getLocation(),
 Context.DeclarationNames.getCXXDeductionGuideName(AliasTemplate));
-  };
+  }
 
   SmallVector IsDeducibleTypeTraitArgs = {
   Context.getTrivialTypeSourceInfo(
@@ -969,11 +969,14 @@ Expr *buildIsDeducibleConstraint(Sema &SemaRef,
 }
 
 std::pair>
-getRHSTemplateDeclAndArgs(Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate) 
{
+getRHSTemplateDeclAndArgs(Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate,
+  bool Desugar) {
   // Unwrap the sugared ElaboratedType.
   auto RhsType = AliasTemplate->getTemplatedDecl()
  ->getUnderlyingType()
  .getSingleStepDesugaredType(SemaRef.Context);
+  if (Desugar)
+RhsType = RhsType.getDesugaredType(SemaRef.Context);
   TemplateDecl *Template = nullptr;
   llvm::ArrayRef AliasRhsTemplateArgs;
   if (const auto *TST = RhsType->getAs()) {
@@ -1023,8 +1026,26 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
 
   auto &Context = SemaRef.Context;
   auto [Template, AliasRhsTemplateArgs] =
-  getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate);
+  getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate, /*Desugar=*/true);
 
+  // We need both types desugared, before we continue to perform type 
deduction.
+  // The intent is to get the template argument list 'matched', e.g. in the
+  // following case:
+  //
+  //
+  //  template 
+  //  struct A {};
+  //  template 
+  //  using Foo = A>;
+  //  template 
+  //  using Bar = Foo;
+  //
+  // In terms of Bar, we want U (which has the default argument) to appear in
+  // the synthesized deduction guide, but U would remain undeduced if we 
deduced
+  // A> using Foo directly.
+  //
+  // Instead, we need to canonicalize both against A, i.e. A> and A>,
+  // such that T can be deduced as U.
   auto RType = F->getTemplatedDecl()->getReturnType();
   // The (trailing) return type of the deduction guide.
   const TemplateSpecializationType *FReturnType =
@@ -1034,7 +1055,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
 FReturnType = InjectedCNT->getInjectedTST();
   else if (const auto *ET = RType->getAs())
 // explicit deduction guide.
-FReturnType = ET->getNamedType()->getAs();
+FReturnType = 
ET->getNamedType()->getAsNonAliasTemplateSpecializationType();
   assert(FReturnType && "expected to see a return type");
   // Deduce template arguments of the deduction guide f from the RHS of
   // the alias.
@@ -1223,7 +1244,7 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
 return;
   auto &Context = SemaRef.Context;
   auto [Template, AliasRhsTemplateArgs] =
-  getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate);
+  getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate, /*Desugar=*/false);
   if (!Template)
 return;
   auto SourceDeductionGuides = getSourceDeductionGuides(
@@ -1303,7 +1324,8 @@ FunctionTemplateDecl 
*DeclareAggregateDeductionGuideForTypeAlias(
 Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate,
 MutableArrayRef ParamTypes, SourceLocation Loc) {
   TemplateDecl *RHSTemplate =
-  getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate).first;
+  getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate, /*Desugar=*/false)
+  .first;
   if (!RHSTemplate)
 return nullptr;
 
diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp 
b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index aeb02c9e4898e..34bfa020f5baa 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -207,13 +207,14 @@ namespace test15 {
 template  struct Foo { Foo(T); };
 
 template using AFoo = Foo;
-template concept False = false;
+template concept False = false; // #test15_False
 template
-using BFoo = AFoo; // expected-note {{candidate template ignored: 
constraints not satisfied [with V = int]}} \
-  

[clang] AMDGPU: Remove "gws" from the “read-only” target feature list (PR #148141)

2025-07-11 Thread Changpeng Fang via cfe-commits

https://github.com/changpeng updated 
https://github.com/llvm/llvm-project/pull/148141

>From c9cf9873e35205f9715acd545680713c0dd912aa Mon Sep 17 00:00:00 2001
From: Changpeng Fang 
Date: Fri, 11 Jul 2025 01:04:04 -0700
Subject: [PATCH 1/2] =?UTF-8?q?AMDGPU:=20Remove=20"gws"=20from=20the=20?=
 =?UTF-8?q?=E2=80=9Cread-only=E2=80=9D=20target=20feature=20list?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

  Since this feature is no longer universally available, we may need it
in the IR.

Fixes: SWDEV-541399
---
 clang/lib/Basic/Targets/AMDGPU.cpp|  2 +-
 .../CodeGenOpenCL/amdgpu-enqueue-kernel.cl|  8 +-
 .../CodeGenOpenCL/amdgpu-features-readonly.cl |  6 --
 clang/test/CodeGenOpenCL/amdgpu-features.cl   | 90 +--
 4 files changed, 50 insertions(+), 56 deletions(-)
 delete mode 100644 clang/test/CodeGenOpenCL/amdgpu-features-readonly.cl

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index cebcfa3c2bc40..4f57c92b0981b 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -266,7 +266,7 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple 
&Triple,
 
   MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
   CUMode = !(GPUFeatures & llvm::AMDGPU::FEATURE_WGP);
-  for (auto F : {"image-insts", "gws", "vmem-to-lds-load-insts"})
+  for (auto F : {"image-insts", "vmem-to-lds-load-insts"})
 ReadOnlyFeatures.insert(F);
   HalfArgsAndReturns = true;
 }
diff --git a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl 
b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
index bbb55b7e14941..c12b42bf9d950 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
@@ -816,12 +816,12 @@ kernel void test_target_features_kernel(global int *i) {
 // NOCPU: attributes #[[ATTR10]] = { convergent nounwind }
 //.
 // GFX900: attributes #[[ATTR0:[0-9]+]] = { "objc_arc_inert" }
-// GFX900: attributes #[[ATTR1]] = { convergent norecurse nounwind 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 }
-// GFX900: attributes #[[ATTR2]] = { convergent norecurse nounwind 
"amdgpu-flat-work-group-size"="1,256" 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 "uniform-work-group-size"="false" }
-// GFX900: attributes #[[ATTR3]] = { alwaysinline convergent norecurse 
nounwind "amdgpu-flat-work-group-size"="1,256" 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 }
+// GFX900: attributes #[[ATTR1]] = { convergent norecurse nounwind 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+gws,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 }
+// GFX900: attributes #[[ATTR2]] = { convergent norecurse nounwind 
"amdgpu-flat-work-group-size"="1,256" 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+gws,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 "uniform-work-group-size"="false" }
+// GFX900: attributes #[[ATTR3]] = { alwaysinline convergent norecurse 
nounwind "amdgpu-flat-work-group-size"="1,256" 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+gws,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 }
 // GFX900: attributes #[[ATTR4:[0-9]+]] = { nocallback nofree nosync nounwind 
willreturn memory(argmem: readwrite) }
 // GFX900: attributes #[[ATTR5:[0-9]+]] = { nocallback nofree nounwind 
willreturn memory(argmem: readwrite) }
-// GFX900: attributes #[[ATTR6]] = { convergent nounwind 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 }
+// GFX900: attributes #[[ATTR6]] = { convergent nounwind 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="

[clang] c042273 - [clang][bytecode] Check lambda captures before binding decls (#148130)

2025-07-11 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-07-11T10:51:59+02:00
New Revision: c0422733e3b78ae29cc41b729a2a4adafc0c63bc

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

LOG: [clang][bytecode] Check lambda captures before binding decls (#148130)

If the given decls is a lambda capture (but also a BindingDecl), handle
it as a lambda capture instead of a BindingDecl.

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index e7c085750b7ad..afa3b7ea7de7e 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6532,14 +6532,13 @@ bool Compiler::visitDeclRef(const ValueDecl 
*D, const Expr *E) {
   if (DiscardResult)
 return true;
 
-  if (const auto *ECD = dyn_cast(D)) {
+  if (const auto *ECD = dyn_cast(D))
 return this->emitConst(ECD->getInitVal(), E);
-  } else if (const auto *BD = dyn_cast(D)) {
-return this->visit(BD->getBinding());
-  } else if (const auto *FuncDecl = dyn_cast(D)) {
+  if (const auto *FuncDecl = dyn_cast(D)) {
 const Function *F = getFunction(FuncDecl);
 return F && this->emitGetFnPtr(F, E);
-  } else if (const auto *TPOD = dyn_cast(D)) {
+  }
+  if (const auto *TPOD = dyn_cast(D)) {
 if (std::optional Index = P.getOrCreateGlobal(D)) {
   if (!this->emitGetPtrGlobal(*Index, E))
 return false;
@@ -6560,13 +6559,15 @@ bool Compiler::visitDeclRef(const ValueDecl 
*D, const Expr *E) {
   // value.
   bool IsReference = D->getType()->isReferenceType();
 
-  // Check for local/global variables and parameters.
+  // Local variables.
   if (auto It = Locals.find(D); It != Locals.end()) {
 const unsigned Offset = It->second.Offset;
 if (IsReference)
   return this->emitGetLocal(classifyPrim(E), Offset, E);
 return this->emitGetPtrLocal(Offset, E);
-  } else if (auto GlobalIndex = P.getGlobal(D)) {
+  }
+  // Global variables.
+  if (auto GlobalIndex = P.getGlobal(D)) {
 if (IsReference) {
   if (!Ctx.getLangOpts().CPlusPlus11)
 return this->emitGetGlobal(classifyPrim(E), *GlobalIndex, E);
@@ -6574,7 +6575,9 @@ bool Compiler::visitDeclRef(const ValueDecl *D, 
const Expr *E) {
 }
 
 return this->emitGetPtrGlobal(*GlobalIndex, E);
-  } else if (const auto *PVD = dyn_cast(D)) {
+  }
+  // Function parameters.
+  if (const auto *PVD = dyn_cast(D)) {
 if (auto It = this->Params.find(PVD); It != this->Params.end()) {
   if (IsReference || !It->second.IsPtr)
 return this->emitGetParam(classifyPrim(E), It->second.Offset, E);
@@ -6600,7 +6603,7 @@ bool Compiler::visitDeclRef(const ValueDecl *D, 
const Expr *E) {
 return this->visitDeclRef(D, E);
   };
 
-  // Handle lambda captures.
+  // Lambda captures.
   if (auto It = this->LambdaCaptures.find(D);
   It != this->LambdaCaptures.end()) {
 auto [Offset, IsPtr] = It->second;
@@ -6608,12 +6611,17 @@ bool Compiler::visitDeclRef(const ValueDecl 
*D, const Expr *E) {
 if (IsPtr)
   return this->emitGetThisFieldPtr(Offset, E);
 return this->emitGetPtrThisField(Offset, E);
-  } else if (const auto *DRE = dyn_cast(E);
- DRE && DRE->refersToEnclosingVariableOrCapture()) {
+  }
+
+  if (const auto *DRE = dyn_cast(E);
+  DRE && DRE->refersToEnclosingVariableOrCapture()) {
 if (const auto *VD = dyn_cast(D); VD && VD->isInitCapture())
   return revisit(VD);
   }
 
+  if (const auto *BD = dyn_cast(D))
+return this->visit(BD->getBinding());
+
   // Avoid infinite recursion.
   if (D == InitializingDecl)
 return this->emitDummyPtr(D, E);
@@ -,7 +6674,7 @@ bool Compiler::visitDeclRef(const ValueDecl *D, 
const Expr *E) {
 if (VD->evaluateValue())
   return revisit(VD);
 
-if (!D->getType()->isReferenceType())
+if (!IsReference)
   return this->emitDummyPtr(D, E);
 
 return this->emitInvalidDeclRef(cast(E),

diff  --git a/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp 
b/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
index 33a6039459484..aa8d055e44971 100644
--- a/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
+++ b/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
@@ -3,6 +3,10 @@
 // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks 
-fdelayed-template-parsing %s -fcxx-exceptions
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -fblocks %s 
-DCPP14_AND_EARLIER -fcxx-exceptions
 
+// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks %s 
-fcxx-exceptions -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only -fblocks %s 
-fcxx-exceptions -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fbloc

[clang] [clang][bytecode] Check lambda captures before binding decls (PR #148130)

2025-07-11 Thread Timm Baeder via cfe-commits

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


[clang] [clang][analyzer] Add C standard streams to the internal memory space (PR #147766)

2025-07-11 Thread Balázs Kéri via cfe-commits


@@ -519,14 +519,53 @@ void reopen_std_stream(void) {
   if (!fp) return;
 
   stdout = fp; // Let's make them alias.
-  clang_analyzer_eval(fp == oldStdout); // expected-warning {{UNKNOWN}}
-  clang_analyzer_eval(fp == stdout);// expected-warning {{TRUE}} 
no-FALSE
-  clang_analyzer_eval(oldStdout == stdout); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(fp == oldStdout); // expected-warning {{FALSE}}
+  clang_analyzer_eval(fp == stdout);// expected-warning {{TRUE}}
+  clang_analyzer_eval(oldStdout == stdout); // expected-warning {{FALSE}}
 }
 
 void only_success_path_does_not_alias_with_stdout(void) {
   if (stdout) return;
   FILE *f = fopen("/tmp/foof", "r"); // no-crash
+  clang_analyzer_eval(f == 0);// expected-warning {{TRUE}} expected-warning 
{{FALSE}}
   if (!f) return;
   fclose(f);
 }
+
+extern void do_something();
+
+void test_no_invalidate_at_system_call(int use_std) {
+  FILE *fd;
+  char *buf;
+
+  if (use_std) {
+fd = stdin;
+  } else {
+if ((fd = fopen("x/y/z", "r")) == NULL)
+  return;
+
+clang_analyzer_eval(fd == stdin); // expected-warning{{FALSE}}
+buf = (char *)malloc(100);
+clang_analyzer_eval(fd == stdin); // expected-warning{{FALSE}}
+  }
+
+  if (fd != stdin)
+fclose(fd);
+}

balazske wrote:

The test can be simplified, I added this code because it looks like the real 
code where the problem was found.

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


[clang] [LifetimeSafety] Introduce intra-procedural analysis in Clang (PR #142313)

2025-07-11 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

Sorry for the trouble. Thanks @Prabhuk and @dyung for spotting and fixing this!

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


[clang] [LifetimeSafety] Introduce intra-procedural analysis in Clang (PR #142313)

2025-07-11 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-x64-windows-msvc` 
running on `windows-gcebot2` while building `clang` at step 4 "annotate".

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


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

```
Step 4 (annotate) failure: 'python 
../llvm-zorg/zorg/buildbot/builders/annotated/clang-windows.py ...' (failure)
...
[422/424] Running the Clang regression tests
llvm-lit.py: 
C:\b\slave\clang-x64-windows-msvc\llvm-project\llvm\utils\lit\lit\llvm\config.py:57:
 note: using lit tools: C:\Program Files\Git\usr\bin
llvm-lit.py: 
C:\b\slave\clang-x64-windows-msvc\llvm-project\llvm\utils\lit\lit\llvm\config.py:520:
 note: using clang: c:\b\slave\clang-x64-windows-msvc\build\stage1\bin\clang.exe
llvm-lit.py: 
C:\b\slave\clang-x64-windows-msvc\llvm-project\llvm\utils\lit\lit\llvm\subst.py:126:
 note: Did not find cir-opt in 
C:\b\slave\clang-x64-windows-msvc\build\stage1\bin;C:\b\slave\clang-x64-windows-msvc\build\stage1\bin
llvm-lit.py: 
C:\b\slave\clang-x64-windows-msvc\llvm-project\llvm\utils\lit\lit\llvm\config.py:520:
 note: using ld.lld: 
c:\b\slave\clang-x64-windows-msvc\build\stage1\bin\ld.lld.exe
llvm-lit.py: 
C:\b\slave\clang-x64-windows-msvc\llvm-project\llvm\utils\lit\lit\llvm\config.py:520:
 note: using lld-link: 
c:\b\slave\clang-x64-windows-msvc\build\stage1\bin\lld-link.exe
llvm-lit.py: 
C:\b\slave\clang-x64-windows-msvc\llvm-project\llvm\utils\lit\lit\llvm\config.py:520:
 note: using ld64.lld: 
c:\b\slave\clang-x64-windows-msvc\build\stage1\bin\ld64.lld.exe
llvm-lit.py: 
C:\b\slave\clang-x64-windows-msvc\llvm-project\llvm\utils\lit\lit\llvm\config.py:520:
 note: using wasm-ld: 
c:\b\slave\clang-x64-windows-msvc\build\stage1\bin\wasm-ld.exe
-- Testing: 22410 tests, 32 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
FAIL: Clang :: Sema/warn-lifetime-safety-dataflow.cpp (22410 of 22410)
 TEST 'Clang :: Sema/warn-lifetime-safety-dataflow.cpp' 
FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
c:\b\slave\clang-x64-windows-msvc\build\stage1\bin\clang.exe -cc1 
-internal-isystem 
C:\b\slave\clang-x64-windows-msvc\build\stage1\lib\clang\21\include 
-nostdsysteminc -mllvm -debug-only=LifetimeFacts -Wexperimental-lifetime-safety 
C:\b\slave\clang-x64-windows-msvc\llvm-project\clang\test\Sema\warn-lifetime-safety-dataflow.cpp
 2>&1 | c:\b\slave\clang-x64-windows-msvc\build\stage1\bin\filecheck.exe 
C:\b\slave\clang-x64-windows-msvc\llvm-project\clang\test\Sema\warn-lifetime-safety-dataflow.cpp
# executed command: 
'c:\b\slave\clang-x64-windows-msvc\build\stage1\bin\clang.exe' -cc1 
-internal-isystem 
'C:\b\slave\clang-x64-windows-msvc\build\stage1\lib\clang\21\include' 
-nostdsysteminc -mllvm -debug-only=LifetimeFacts -Wexperimental-lifetime-safety 
'C:\b\slave\clang-x64-windows-msvc\llvm-project\clang\test\Sema\warn-lifetime-safety-dataflow.cpp'
# note: command had no output on stdout or stderr
# error: command failed with exit status: 1
# executed command: 
'c:\b\slave\clang-x64-windows-msvc\build\stage1\bin\filecheck.exe' 
'C:\b\slave\clang-x64-windows-msvc\llvm-project\clang\test\Sema\warn-lifetime-safety-dataflow.cpp'
# .---command stderr
# | 
C:\b\slave\clang-x64-windows-msvc\llvm-project\clang\test\Sema\warn-lifetime-safety-dataflow.cpp:9:17:
 error: CHECK-LABEL: expected string not found in input
# | // CHECK-LABEL: Function: return_local_addr
# | ^
# | :1:1: note: scanning from here
# | clang (LLVM option parsing): Unknown command line argument 
'-debug-only=LifetimeFacts'. Try: 'clang (LLVM option parsing) --help'
# | ^
# | :1:105: note: possible intended match here
# | clang (LLVM option parsing): Unknown command line argument 
'-debug-only=LifetimeFacts'. Try: 'clang (LLVM option parsing) --help'
# | 
^
# | 
# | Input file: 
# | Check file: 
C:\b\slave\clang-x64-windows-msvc\llvm-project\clang\test\Sema\warn-lifetime-safety-dataflow.cpp
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<
# |1: clang (LLVM option parsing): Unknown command line argument 
'-debug-only=LifetimeFacts'. Try: 'clang (LLVM option parsing) --help' 
# | label:9'0 
X~
 error: no match found
# | label:9'1   
  ?  possible 
intended match
# |2: clang (LLVM option parsing): Did you mean 
'--debug-pass=LifetimeFacts'? 
# | label:9'0 

# | >>
# `-
# error: command failed with

[clang] [clang] Build argument string for clang::warn_unused_result (PR #148090)

2025-07-11 Thread Corentin Jabot via cfe-commits

cor3ntin wrote:

This change needs a release note.
Please add an entry to `clang/docs/ReleaseNotes.rst` in the section the most 
adapted to the change, and referencing any Github issue this change fixes. 
Thanks!

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


[clang] [clang] Build argument string for clang::warn_unused_result (PR #148090)

2025-07-11 Thread Corentin Jabot via cfe-commits

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

LGTM with a release note
Please give some time for @AaronBallman to look at this change too

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


[clang] [clang][CodeGen] Set `dead_on_return` on indirect pointer arguments (PR #148159)

2025-07-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-systemz

Author: Antonio Frighetto (antoniofrighetto)


Changes

Let Clang emit `dead_on_return` attribute on indirect pointer arguments, 
namely, large aggregates that the ABI mandates be passed by value, but lowered 
to an indirect argument. Writes to such arguments are not observable by the 
caller after the callee returns.

This should desirably enable further MemCpyOpt/DSE optimizations.

Previous discussion: 
https://discourse.llvm.org/t/rfc-add-dead-on-return-attribute/86871.

---

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


107 Files Affected:

- (modified) clang/lib/CodeGen/CGCall.cpp (+4) 
- (modified) clang/test/CodeGen/64bit-swiftcall.c (+1-1) 
- (modified) clang/test/CodeGen/AArch64/byval-temp.c (+8-8) 
- (modified) clang/test/CodeGen/AArch64/pure-scalable-args-empty-union.c (+1-1) 
- (modified) clang/test/CodeGen/AArch64/pure-scalable-args.c (+21-21) 
- (modified) clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp (+2-2) 
- (modified) 
clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c (+3-3) 
- (modified) 
clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp 
(+1-1) 
- (modified) clang/test/CodeGen/LoongArch/bitint.c (+3-3) 
- (modified) clang/test/CodeGen/PowerPC/ppc64-vector.c (+1-1) 
- (modified) clang/test/CodeGen/RISCV/riscv-abi.cpp (+4-4) 
- (modified) clang/test/CodeGen/RISCV/riscv-vector-callingconv-llvm-ir.c (+5-5) 
- (modified) clang/test/CodeGen/RISCV/riscv-vector-callingconv-llvm-ir.cpp 
(+5-5) 
- (modified) clang/test/CodeGen/RISCV/riscv32-abi.c (+37-37) 
- (modified) clang/test/CodeGen/RISCV/riscv32-vararg.c (+1-1) 
- (modified) clang/test/CodeGen/RISCV/riscv64-abi.c (+9-9) 
- (modified) clang/test/CodeGen/RISCV/riscv64-vararg.c (+1-1) 
- (modified) clang/test/CodeGen/SystemZ/systemz-abi-vector.c (+26-26) 
- (modified) clang/test/CodeGen/SystemZ/systemz-abi.c (+19-19) 
- (modified) clang/test/CodeGen/SystemZ/systemz-inline-asm.c (+1-1) 
- (modified) clang/test/CodeGen/X86/cx-complex-range.c (+1-1) 
- (modified) clang/test/CodeGen/X86/x86_32-arguments-win32.c (+7-7) 
- (modified) clang/test/CodeGen/X86/x86_64-arguments-win32.c (+1-1) 
- (modified) clang/test/CodeGen/aapcs64-align.cpp (+2-2) 
- (modified) clang/test/CodeGen/arm-aapcs-vfp.c (+1-1) 
- (modified) clang/test/CodeGen/arm-abi-vector.c (+3-3) 
- (modified) clang/test/CodeGen/arm-swiftcall.c (+1-1) 
- (modified) clang/test/CodeGen/arm64-abi-vector.c (+7-7) 
- (modified) clang/test/CodeGen/arm64-arguments.c (+13-13) 
- (modified) clang/test/CodeGen/arm64-microsoft-arguments.cpp (+1-1) 
- (modified) clang/test/CodeGen/armv7k-abi.c (+1-1) 
- (modified) clang/test/CodeGen/atomic-arm64.c (+1-1) 
- (modified) clang/test/CodeGen/attr-noundef.cpp (+4-3) 
- (modified) clang/test/CodeGen/cx-complex-range.c (+18-18) 
- (modified) clang/test/CodeGen/ext-int-cc.c (+22-22) 
- (modified) clang/test/CodeGen/isfpclass.c (+1-1) 
- (modified) clang/test/CodeGen/math-libcalls-tbaa-indirect-args.c (+43-43) 
- (modified) clang/test/CodeGen/mingw-long-double.c (+3-3) 
- (modified) clang/test/CodeGen/ms_abi.c (+2-2) 
- (modified) clang/test/CodeGen/pass-by-value-noalias.c (+2-2) 
- (modified) clang/test/CodeGen/ptrauth-in-c-struct.c (+2-2) 
- (modified) clang/test/CodeGen/regcall.c (+5-5) 
- (modified) clang/test/CodeGen/regcall2.c (+1-1) 
- (modified) clang/test/CodeGen/regcall4.c (+5-5) 
- (modified) clang/test/CodeGen/sparcv9-abi.c (+2-2) 
- (modified) clang/test/CodeGen/vectorcall.c (+23-23) 
- (modified) clang/test/CodeGen/win-fp128.c (+1-1) 
- (modified) clang/test/CodeGen/win64-i128.c (+2-2) 
- (modified) clang/test/CodeGen/windows-swiftcall.c (+1-1) 
- (modified) clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp (+2-2) 
- (modified) clang/test/CodeGenCXX/aix-alignment.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/amdgcn-func-arg.cpp (+2-2) 
- (modified) clang/test/CodeGenCXX/arm-cc.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/arm-swiftcall.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/attr-target-mv-inalloca.cpp (+4-4) 
- (modified) clang/test/CodeGenCXX/blocks.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/copy-initialization.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/cxx1z-copy-omission.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/debug-info.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/derived-to-base-conv.cpp (+2-2) 
- (modified) clang/test/CodeGenCXX/empty-nontrivially-copyable.cpp (+2-2) 
- (modified) clang/test/CodeGenCXX/fastcall.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/homogeneous-aggregates.cpp (+7-7) 
- (modified) clang/test/CodeGenCXX/inalloca-lambda.cpp (+3-3) 
- (modified) clang/test/CodeGenCXX/inalloca-overaligned.cpp (+4-4) 
- (modified) clang/test/CodeGenCXX/inalloca-vector.cpp (+2-2) 
- (modified) clang/test/CodeGenCXX/inheriting-constructor.cpp (+4-4) 
- (modified) clang/test/CodeGenCXX/member-function-pointer-calls.cpp (+2-2)

[clang] [clang] Build argument string for clang::warn_unused_result (PR #148090)

2025-07-11 Thread via cfe-commits

https://github.com/zebullax updated 
https://github.com/llvm/llvm-project/pull/148090

>From 11909560ed6cb4e56192fbbfe4d8b1cdf58e1cb1 Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 09:12:44 +0900
Subject: [PATCH 1/3] Build argument string for clang::warn_unused_result

Preserve the argument-clause for `warn-unused-result` when under clang:: scope.
We are not touching gnu:: scope for now as it's an error for GCC to have that 
string. Personally I think it would be ok to relax it here too as we are not 
introducing breakage to currently passing code, but feedback is to go slowly 
about it.
---
 clang/lib/Sema/SemaDeclAttr.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 7ebb53318702c..221197b3849e0 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2902,7 +2902,8 @@ static void handleWarnUnusedResult(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 }
 
   StringRef Str;
-  if (AL.isStandardAttributeSyntax() && !AL.getScopeName()) {
+  if (AL.isStandardAttributeSyntax()
+  && (!AL.getScopeName() || AL.isClangScope())) {
 // The standard attribute cannot be applied to variable declarations such
 // as a function pointer.
 if (isa(D))

>From 8b98b9e5cf0d88ffe7f2a9b8668e7ef0359c7c87 Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 15:51:22 +0900
Subject: [PATCH 2/3] Add unit test to check reason string on clang scope

Signed-off-by: zebullax 

Fix scope in UT

Signed-off-by: zebullax 

Fix UT

Signed-off-by: zebullax 
---
 clang/test/SemaCXX/warn-unused-result.cpp | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/warn-unused-result.cpp 
b/clang/test/SemaCXX/warn-unused-result.cpp
index fa7540c116e67..440306a235f08 100644
--- a/clang/test/SemaCXX/warn-unused-result.cpp
+++ b/clang/test/SemaCXX/warn-unused-result.cpp
@@ -249,7 +249,7 @@ void g() {
 
 namespace PR45520 {
 [[nodiscard]] bool (*f)(); // expected-warning {{'nodiscard' attribute only 
applies to functions, classes, or enumerations}}
-[[clang::warn_unused_result]] bool (*g)();
+[[clang::warn_unused_result]] bool (*g)(); // expected-warning 
{{'clang::warn_unused_result' attribute only applies to functions, classes, or 
enumerations}}
 __attribute__((warn_unused_result)) bool (*h)();
 
 void i([[nodiscard]] bool (*fp)()); // expected-warning {{'nodiscard' 
attribute only applies to functions, classes, or enumerations}}
@@ -364,3 +364,21 @@ void id_print_name() {
 ((int(*)())f)();
 }
 } // namespace GH117975
+
+namespace BuildStringOnClangScope {
+
+[[clang::warn_unused_result("Discarded result")]]
+bool makeClangTrue() { return true; }
+
+[[gnu::warn_unused_result("Discarded result")]]
+bool makeGccTrue() { return true; }
+
+void doClangThings() {
+  makeClangTrue(); // expected-warning {{ignoring return value of function 
declared with 'clang::warn_unused_result' attribute: Discarded result}}
+}
+
+void doGccThings() {
+  makeGccTrue(); // expected-warning {{ignoring return value of function 
declared with 'gnu::warn_unused_result' attribute}}
+}
+
+}
\ No newline at end of file

>From 5aedb435e2aeb0173234756df2ffa279f366751a Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 17:36:00 +0900
Subject: [PATCH 3/3] Remove warn on attaching clang scoped to var decl

Signed-off-by: zebullax 
---
 clang/lib/Sema/SemaDeclAttr.cpp   | 2 +-
 clang/test/SemaCXX/warn-unused-result.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 221197b3849e0..c9822369e8652 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2906,7 +2906,7 @@ static void handleWarnUnusedResult(Sema &S, Decl *D, 
const ParsedAttr &AL) {
   && (!AL.getScopeName() || AL.isClangScope())) {
 // The standard attribute cannot be applied to variable declarations such
 // as a function pointer.
-if (isa(D))
+if (!AL.isClangScope() && isa(D))
   S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
   << AL << AL.isRegularKeywordAttribute()
   << ExpectedFunctionOrClassOrEnum;
diff --git a/clang/test/SemaCXX/warn-unused-result.cpp 
b/clang/test/SemaCXX/warn-unused-result.cpp
index 440306a235f08..3e6851590aa5f 100644
--- a/clang/test/SemaCXX/warn-unused-result.cpp
+++ b/clang/test/SemaCXX/warn-unused-result.cpp
@@ -249,7 +249,7 @@ void g() {
 
 namespace PR45520 {
 [[nodiscard]] bool (*f)(); // expected-warning {{'nodiscard' attribute only 
applies to functions, classes, or enumerations}}
-[[clang::warn_unused_result]] bool (*g)(); // expected-warning 
{{'clang::warn_unused_result' attribute only applies to functions, classes, or 
enumerations}}
+[[clang::warn_unused_result]] bool (*g)();
 __attribute__((warn_unused_result)) bool (*h)();
 
 void i([[nodiscard]] bool (*fp)()); 

[clang] [clang] Build argument string for clang::warn_unused_result (PR #148090)

2025-07-11 Thread via cfe-commits

zebullax wrote:

Seems 🟢 
```
➜  clang git:(patch-1) ✗ build/bin/llvm-lit -sv  
clang-p2996/clang/test/SemaCXX/warn-unused-result.cpp
...

Testing Time: 0.40s

Total Discovered Tests: 1
  Passed: 1 (100.00%)
```


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


[clang] [LifetimeSafety] Implement dataflow analysis for loan propagation (PR #148065)

2025-07-11 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/148065

>From 123045c4db9ec6969fc111ab817b8f238d0ee23c Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 10 Jul 2025 22:00:01 +
Subject: [PATCH] [LifetimeSafety] Implement dataflow analysis for loan
 propagation

---
 clang/lib/Analysis/LifetimeSafety.cpp | 258 +-
 .../Sema/warn-lifetime-safety-dataflow.cpp| 188 -
 2 files changed, 444 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/LifetimeSafety.cpp 
b/clang/lib/Analysis/LifetimeSafety.cpp
index 1f18952ce96da..e72192aa92c1a 100644
--- a/clang/lib/Analysis/LifetimeSafety.cpp
+++ b/clang/lib/Analysis/LifetimeSafety.cpp
@@ -13,7 +13,10 @@
 #include "clang/Analysis/Analyses/PostOrderCFGView.h"
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
+#include "clang/Analysis/FlowSensitive/DataflowWorklist.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/ImmutableMap.h"
+#include "llvm/ADT/ImmutableSet.h"
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Debug.h"
@@ -493,7 +496,247 @@ class FactGenerator : public 
ConstStmtVisitor {
 };
 
 // = //
-//  TODO: Run dataflow analysis to propagate loans, analyse and error 
reporting.
+//  The Dataflow Lattice
+// = //
+
+// Using LLVM's immutable collections is efficient for dataflow analysis
+// as it avoids deep copies during state transitions.
+// TODO(opt): Consider using a bitset to represent the set of loans.
+using LoanSet = llvm::ImmutableSet;
+using OriginLoanMap = llvm::ImmutableMap;
+
+/// An object to hold the factories for immutable collections, ensuring
+/// that all created states share the same underlying memory management.
+struct LifetimeFactory {
+  OriginLoanMap::Factory OriginMapFact;
+  LoanSet::Factory LoanSetFact;
+
+  LoanSet createLoanSet(LoanID LID) {
+return LoanSetFact.add(LoanSetFact.getEmptySet(), LID);
+  }
+};
+
+/// LifetimeLattice represents the state of our analysis at a given program
+/// point. It is an immutable object, and all operations produce a new
+/// instance rather than modifying the existing one.
+struct LifetimeLattice {
+  /// The map from an origin to the set of loans it contains.
+  /// TODO(opt): To reduce the lattice size, propagate origins of declarations,
+  /// not expressions, because expressions are not visible across blocks.
+  OriginLoanMap Origins = OriginLoanMap(nullptr);
+
+  explicit LifetimeLattice(const OriginLoanMap &S) : Origins(S) {}
+  LifetimeLattice() = default;
+
+  bool operator==(const LifetimeLattice &Other) const {
+return Origins == Other.Origins;
+  }
+  bool operator!=(const LifetimeLattice &Other) const {
+return !(*this == Other);
+  }
+
+  LoanSet getLoans(OriginID OID, LifetimeFactory &Factory) const {
+if (auto *Loans = Origins.lookup(OID))
+  return *Loans;
+return Factory.LoanSetFact.getEmptySet();
+  }
+
+  /// Computes the union of two lattices by performing a key-wise join of
+  /// their OriginLoanMaps.
+  // TODO(opt): This key-wise join is a performance bottleneck. A more
+  // efficient merge could be implemented using a Patricia Trie or HAMT
+  // instead of the current AVL-tree-based ImmutableMap.
+  LifetimeLattice join(const LifetimeLattice &Other,
+   LifetimeFactory &Factory) const {
+/// Merge the smaller map into the larger one ensuring we iterate over the
+/// smaller map.
+if (Origins.getHeight() < Other.Origins.getHeight())
+  return Other.join(*this, Factory);
+
+OriginLoanMap JoinedState = Origins;
+// For each origin in the other map, union its loan set with ours.
+for (const auto &Entry : Other.Origins) {
+  OriginID OID = Entry.first;
+  LoanSet OtherLoanSet = Entry.second;
+  JoinedState = Factory.OriginMapFact.add(
+  JoinedState, OID,
+  join(getLoans(OID, Factory), OtherLoanSet, Factory));
+}
+return LifetimeLattice(JoinedState);
+  }
+
+  LoanSet join(LoanSet a, LoanSet b, LifetimeFactory &Factory) const {
+/// Merge the smaller set into the larger one ensuring we iterate over the
+/// smaller set.
+if (a.getHeight() < b.getHeight())
+  std::swap(a, b);
+LoanSet Result = a;
+for (LoanID LID : b) {
+  /// TODO(opt): Profiling shows that this loop is a major performance
+  /// bottleneck. Investigate using a BitVector to represent the set of
+  /// loans for improved join performance.
+  Result = Factory.LoanSetFact.add(Result, LID);
+}
+return Result;
+  }
+
+  void dump(llvm::raw_ostream &OS) const {
+OS << "LifetimeLattice State:\n";
+if (Origins.isEmpty())
+  OS << "  \n";
+for (const auto &Entry : Origins) {
+  if (Entry.second.isEmpty())

[clang] fa921d1 - [Clang][Doc] Add Changelog line for (#144886) (#147978)

2025-07-11 Thread via cfe-commits

Author: Juan Manuel Martinez Caamaño
Date: 2025-07-11T12:43:40+02:00
New Revision: fa921d166a77afbf0e1c4b2e0b4c0020da21594c

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

LOG: [Clang][Doc] Add Changelog line for (#144886) (#147978)

The patch [CUDA][HIP] Add a __device__ version of
std::__glibcxx_assert_fail() (#144886) missed a changelog line.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 542ddd5e6042c..4535f8881e406 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1076,6 +1076,8 @@ RISC-V Support
 CUDA/HIP Language Changes
 ^
 
+* Provide a __device__ version of std::__glibcxx_assert_fail() in a header 
wrapper.
+
 CUDA Support
 
 



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


[clang] [Clang][Doc] Add Changelog line for (#144886) (PR #147978)

2025-07-11 Thread Juan Manuel Martinez Caamaño via cfe-commits

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


[clang] [clang-tools-extra] [lldb] [Clang][AST][NFC] (`RecordDecl` -> `CXXRecordDecl`)`::isInjectedClassName` (PR #148195)

2025-07-11 Thread Yanzuo Liu via cfe-commits

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


[clang-tools-extra] a61ea9f - [clang-tidy] Add an option in 'readability-named-parameter' to print names without comment (#147953)

2025-07-11 Thread via cfe-commits

Author: Dmitry Polukhin
Date: 2025-07-11T11:51:20+01:00
New Revision: a61ea9fd9b9c100ce4fce9212dc85230257fd5c8

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

LOG: [clang-tidy] Add an option in 'readability-named-parameter' to print names 
without comment (#147953)

Add InsertPlainNamesInForwardDecls option to readability-named-parameter
check to insert parameter names without comments for forward
declarations only.

When enabled, forward declarations get plain parameter names (e.g., `int
param`) while function definitions continue to use commented names
(e.g., `int /*param*/`). Named parameters in forward decls don't cause
compiler warnings and some developers prefer to have names without
comments but in sync between declarations and the definition.

Default behavior remains unchanged
(InsertPlainNamesInForwardDecls=false).

Example with InsertPlainNamesInForwardDecls=true:
```cpp
// Forward declaration - gets plain name because the definition has name.
void func(int param);
void func(int param) { ... = param; }
```

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
clang-tools-extra/test/clang-tidy/checkers/readability/named-parameter.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
index ea6597dbdd617..6bb8c394f75cc 100644
--- a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
@@ -15,6 +15,17 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::readability {
 
+NamedParameterCheck::NamedParameterCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  InsertPlainNamesInForwardDecls(
+  Options.get("InsertPlainNamesInForwardDecls", false)) {}
+
+void NamedParameterCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "InsertPlainNamesInForwardDecls",
+InsertPlainNamesInForwardDecls);
+}
+
 void NamedParameterCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
   Finder->addMatcher(functionDecl().bind("decl"), this);
 }
@@ -84,7 +95,8 @@ void NamedParameterCheck::check(const 
MatchFinder::MatchResult &Result) {
 
 for (auto P : UnnamedParams) {
   // Fallback to an unused marker.
-  StringRef NewName = "unused";
+  static constexpr StringRef FallbackName = "unused";
+  StringRef NewName = FallbackName;
 
   // If the method is overridden, try to copy the name from the base method
   // into the overrider.
@@ -105,12 +117,25 @@ void NamedParameterCheck::check(const 
MatchFinder::MatchResult &Result) {
   NewName = Name;
   }
 
-  // Now insert the comment. Note that getLocation() points to the place
+  // Now insert the fix. Note that getLocation() points to the place
   // where the name would be, this allows us to also get complex cases like
   // function pointers right.
   const ParmVarDecl *Parm = P.first->getParamDecl(P.second);
-  D << FixItHint::CreateInsertion(Parm->getLocation(),
-  " /*" + NewName.str() + "*/");
+
+  // The fix depends on the InsertPlainNamesInForwardDecls option,
+  // whether this is a forward declaration and whether the parameter has
+  // a real name.
+  const bool IsForwardDeclaration = (!Definition || Function != 
Definition);
+  if (InsertPlainNamesInForwardDecls && IsForwardDeclaration &&
+  NewName != FallbackName) {
+// For forward declarations with InsertPlainNamesInForwardDecls 
enabled,
+// insert the parameter name without comments.
+D << FixItHint::CreateInsertion(Parm->getLocation(),
+" " + NewName.str());
+  } else {
+D << FixItHint::CreateInsertion(Parm->getLocation(),
+" /*" + NewName.str() + "*/");
+  }
 }
   }
 }

diff  --git a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h 
b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h
index 812d90ef7319c..f14a74d75eb49 100644
--- a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h
@@ -26,13 +26,16 @@ namespace clang::tidy::readability {
 /// Corresponding cpplint.py check name: 'readability/function'.
 class NamedParameterCheck : public ClangTidyCheck {
 publ

  1   2   3   4   5   >