[clang] [HLSL] Fix global resource initialization (PR #123394)

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

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


[clang] [HLSL] Fix global resource initialization (PR #123394)

2025-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Helena Kotas (hekota)


Changes

Create separate resource initialization function for each resource and add them 
to CodeGenModule's `CXXGlobalInits` list.
Fixes #120636 and addresses this [comment 
](https://github.com/llvm/llvm-project/pull/119755/files#r1894093603).

---

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


8 Files Affected:

- (modified) clang/lib/CodeGen/CGDeclCXX.cpp (-8) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+62-67) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.h (-5) 
- (modified) clang/lib/CodeGen/CodeGenModule.h (+2) 
- (modified) 
clang/test/CodeGenHLSL/builtins/ByteAddressBuffers-constructors.hlsl (+15-10) 
- (modified) clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl (+5-10) 
- (modified) 
clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl (+25-26) 
- (modified) clang/test/CodeGenHLSL/resource-bindings.hlsl (+13-2) 


``diff
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 96517511b21114..1c2fecea1a6ac2 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -1131,14 +1131,6 @@ 
CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
   if (Decls[i])
 EmitRuntimeCall(Decls[i]);
 
-if (getLangOpts().HLSL) {
-  CGHLSLRuntime &CGHLSL = CGM.getHLSLRuntime();
-  if (CGHLSL.needsResourceBindingInitFn()) {
-llvm::Function *ResInitFn = CGHLSL.createResourceBindingInitFn();
-Builder.CreateCall(llvm::FunctionCallee(ResInitFn), {});
-  }
-}
-
 Scope.ForceCleanup();
 
 if (ExitBlock) {
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 5679bd71581795..07149d4ed85fc2 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -536,89 +536,84 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
   }
 }
 
-void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl *VD,
-  llvm::GlobalVariable *GV) {
-  // If the global variable has resource binding, add it to the list of globals
-  // that need resource binding initialization.
-  const HLSLResourceBindingAttr *RBA = VD->getAttr();
-  if (!RBA)
-return;
-
-  if (!HLSLAttributedResourceType::findHandleTypeOnResource(
-  VD->getType().getTypePtr()))
-// FIXME: Only simple declarations of resources are supported for now.
-// Arrays of resources or resources in user defined classes are
-// not implemented yet.
-return;
-
-  ResourcesToBind.emplace_back(VD, GV);
-}
-
-bool CGHLSLRuntime::needsResourceBindingInitFn() {
-  return !ResourcesToBind.empty();
+// Returns true if the type is an HLSL resource class
+static bool isResourceRecordType(const clang::Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
 }
 
-llvm::Function *CGHLSLRuntime::createResourceBindingInitFn() {
-  // No resources to bind
-  assert(needsResourceBindingInitFn() && "no resources to bind");
-
+static void createResourceInitFn(CodeGenModule &CGM, const VarDecl *VD,
+ llvm::GlobalVariable *GV, unsigned Slot,
+ unsigned Space) {
   LLVMContext &Ctx = CGM.getLLVMContext();
   llvm::Type *Int1Ty = llvm::Type::getInt1Ty(Ctx);
 
-  llvm::Function *InitResBindingsFunc =
-  llvm::Function::Create(llvm::FunctionType::get(CGM.VoidTy, false),
- llvm::GlobalValue::InternalLinkage,
- "_init_resource_bindings", CGM.getModule());
+  llvm::Function *InitResFunc = llvm::Function::Create(
+  llvm::FunctionType::get(CGM.VoidTy, false),
+  llvm::GlobalValue::InternalLinkage,
+  ("_init_resource_" + VD->getName()).str(), CGM.getModule());
 
   llvm::BasicBlock *EntryBB =
-  llvm::BasicBlock::Create(Ctx, "entry", InitResBindingsFunc);
+  llvm::BasicBlock::Create(Ctx, "entry", InitResFunc);
   CGBuilderTy Builder(CGM, Ctx);
   const DataLayout &DL = CGM.getModule().getDataLayout();
   Builder.SetInsertPoint(EntryBB);
 
-  for (const auto &[VD, GV] : ResourcesToBind) {
-for (Attr *A : VD->getAttrs()) {
-  HLSLResourceBindingAttr *RBA = dyn_cast(A);
-  if (!RBA)
-continue;
-
-  const HLSLAttributedResourceType *AttrResType =
-  HLSLAttributedResourceType::findHandleTypeOnResource(
-  VD->getType().getTypePtr());
-
-  // FIXME: Only simple declarations of resources are supported for now.
-  // Arrays of resources or resources in user defined classes are
-  // not implemented yet.
-  assert(AttrResType != nullptr &&
- "Resource class must have a handle of 
HLSLAttributedResourceType");
-
-  llvm::Type *TargetTy =
-  CGM.getTargetCodeGenInfo().getHLSLType(CGM, AttrResType);
-  assert(TargetTy !

[clang] [HLSL] Fix global resource initialization (PR #123394)

2025-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Helena Kotas (hekota)


Changes

Create separate resource initialization function for each resource and add them 
to CodeGenModule's `CXXGlobalInits` list.
Fixes #120636 and addresses this [comment 
](https://github.com/llvm/llvm-project/pull/119755/files#r1894093603).

---

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


8 Files Affected:

- (modified) clang/lib/CodeGen/CGDeclCXX.cpp (-8) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+62-67) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.h (-5) 
- (modified) clang/lib/CodeGen/CodeGenModule.h (+2) 
- (modified) 
clang/test/CodeGenHLSL/builtins/ByteAddressBuffers-constructors.hlsl (+15-10) 
- (modified) clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl (+5-10) 
- (modified) 
clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl (+25-26) 
- (modified) clang/test/CodeGenHLSL/resource-bindings.hlsl (+13-2) 


``diff
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 96517511b21114..1c2fecea1a6ac2 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -1131,14 +1131,6 @@ 
CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
   if (Decls[i])
 EmitRuntimeCall(Decls[i]);
 
-if (getLangOpts().HLSL) {
-  CGHLSLRuntime &CGHLSL = CGM.getHLSLRuntime();
-  if (CGHLSL.needsResourceBindingInitFn()) {
-llvm::Function *ResInitFn = CGHLSL.createResourceBindingInitFn();
-Builder.CreateCall(llvm::FunctionCallee(ResInitFn), {});
-  }
-}
-
 Scope.ForceCleanup();
 
 if (ExitBlock) {
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 5679bd71581795..07149d4ed85fc2 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -536,89 +536,84 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
   }
 }
 
-void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl *VD,
-  llvm::GlobalVariable *GV) {
-  // If the global variable has resource binding, add it to the list of globals
-  // that need resource binding initialization.
-  const HLSLResourceBindingAttr *RBA = VD->getAttr();
-  if (!RBA)
-return;
-
-  if (!HLSLAttributedResourceType::findHandleTypeOnResource(
-  VD->getType().getTypePtr()))
-// FIXME: Only simple declarations of resources are supported for now.
-// Arrays of resources or resources in user defined classes are
-// not implemented yet.
-return;
-
-  ResourcesToBind.emplace_back(VD, GV);
-}
-
-bool CGHLSLRuntime::needsResourceBindingInitFn() {
-  return !ResourcesToBind.empty();
+// Returns true if the type is an HLSL resource class
+static bool isResourceRecordType(const clang::Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
 }
 
-llvm::Function *CGHLSLRuntime::createResourceBindingInitFn() {
-  // No resources to bind
-  assert(needsResourceBindingInitFn() && "no resources to bind");
-
+static void createResourceInitFn(CodeGenModule &CGM, const VarDecl *VD,
+ llvm::GlobalVariable *GV, unsigned Slot,
+ unsigned Space) {
   LLVMContext &Ctx = CGM.getLLVMContext();
   llvm::Type *Int1Ty = llvm::Type::getInt1Ty(Ctx);
 
-  llvm::Function *InitResBindingsFunc =
-  llvm::Function::Create(llvm::FunctionType::get(CGM.VoidTy, false),
- llvm::GlobalValue::InternalLinkage,
- "_init_resource_bindings", CGM.getModule());
+  llvm::Function *InitResFunc = llvm::Function::Create(
+  llvm::FunctionType::get(CGM.VoidTy, false),
+  llvm::GlobalValue::InternalLinkage,
+  ("_init_resource_" + VD->getName()).str(), CGM.getModule());
 
   llvm::BasicBlock *EntryBB =
-  llvm::BasicBlock::Create(Ctx, "entry", InitResBindingsFunc);
+  llvm::BasicBlock::Create(Ctx, "entry", InitResFunc);
   CGBuilderTy Builder(CGM, Ctx);
   const DataLayout &DL = CGM.getModule().getDataLayout();
   Builder.SetInsertPoint(EntryBB);
 
-  for (const auto &[VD, GV] : ResourcesToBind) {
-for (Attr *A : VD->getAttrs()) {
-  HLSLResourceBindingAttr *RBA = dyn_cast(A);
-  if (!RBA)
-continue;
-
-  const HLSLAttributedResourceType *AttrResType =
-  HLSLAttributedResourceType::findHandleTypeOnResource(
-  VD->getType().getTypePtr());
-
-  // FIXME: Only simple declarations of resources are supported for now.
-  // Arrays of resources or resources in user defined classes are
-  // not implemented yet.
-  assert(AttrResType != nullptr &&
- "Resource class must have a handle of 
HLSLAttributedResourceType");
-
-  llvm::Type *TargetTy =
-  CGM.getTargetCodeGenInfo().getHLSLType(CGM, AttrResType);
-  assert(TargetTy 

[clang] [llvm] [NVPTX] Add support for PTX 8.6 and CUDA 12.6 (12.8) (PR #123398)

2025-01-17 Thread Sergey Kozub via cfe-commits

https://github.com/sergey-kozub created 
https://github.com/llvm/llvm-project/pull/123398

CUDA 12.8 supports PTX 8.6 which enables architecture "sm100a" (supports 
Blackwell-specific instructions).
CUDA 12.7 technically does not exist, map it to PTX 8.5 (same as 12.6).


>From 92e4b10e940e9c08606ae4cf0a94ae77f9a11b58 Mon Sep 17 00:00:00 2001
From: Sergey Kozub 
Date: Fri, 17 Jan 2025 21:00:49 +
Subject: [PATCH] Add support for PTX 8.6 and CUDA 12.6 (12.8)

---
 clang/include/clang/Basic/BuiltinsNVPTX.def | 5 -
 clang/include/clang/Basic/Cuda.h| 6 +-
 clang/lib/Basic/Cuda.cpp| 8 ++--
 clang/lib/Basic/Targets/NVPTX.cpp   | 3 +++
 clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp| 1 +
 clang/lib/Driver/ToolChains/Cuda.cpp| 9 +
 llvm/lib/Target/NVPTX/NVPTX.td  | 2 ++
 7 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index 969dd9e41ebfa3..37b4e6ff77fda6 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -28,7 +28,9 @@
 #pragma push_macro("SM_90")
 #pragma push_macro("SM_90a")
 #pragma push_macro("SM_100")
-#define SM_100 "sm_100"
+#pragma push_macro("SM_100a")
+#define SM_100a "sm_100a"
+#define SM_100 "sm_100|" SM_100a
 #define SM_90a "sm_90a"
 #define SM_90 "sm_90|" SM_90a "|" SM_100
 #define SM_89 "sm_89|" SM_90
@@ -1091,6 +1093,7 @@ TARGET_BUILTIN(__nvvm_getctarank_shared_cluster, "iv*3", 
"", AND(SM_90,PTX78))
 #pragma pop_macro("SM_90")
 #pragma pop_macro("SM_90a")
 #pragma pop_macro("SM_100")
+#pragma pop_macro("SM_100a")
 #pragma pop_macro("PTX42")
 #pragma pop_macro("PTX60")
 #pragma pop_macro("PTX61")
diff --git a/clang/include/clang/Basic/Cuda.h b/clang/include/clang/Basic/Cuda.h
index c2a4addf488df1..1cdfc8178db843 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -44,9 +44,12 @@ enum class CudaVersion {
   CUDA_124,
   CUDA_125,
   CUDA_126,
+  CUDA_127,
+  CUDA_128,
+  CUDA_129,
   FULLY_SUPPORTED = CUDA_123,
   PARTIALLY_SUPPORTED =
-  CUDA_126, // Partially supported. Proceed with a warning.
+  CUDA_129, // Partially supported. Proceed with a warning.
   NEW = 1,  // Too new. Issue a warning, but allow using it.
 };
 const char *CudaVersionToString(CudaVersion V);
@@ -80,6 +83,7 @@ enum class OffloadArch {
   SM_90,
   SM_90a,
   SM_100,
+  SM_100a,
   GFX600,
   GFX601,
   GFX602,
diff --git a/clang/lib/Basic/Cuda.cpp b/clang/lib/Basic/Cuda.cpp
index d56609a2a8f24a..692ab7c319d8bd 100644
--- a/clang/lib/Basic/Cuda.cpp
+++ b/clang/lib/Basic/Cuda.cpp
@@ -44,6 +44,9 @@ static const CudaVersionMapEntry CudaNameVersionMap[] = {
 CUDA_ENTRY(12, 4),
 CUDA_ENTRY(12, 5),
 CUDA_ENTRY(12, 6),
+CUDA_ENTRY(12, 7),
+CUDA_ENTRY(12, 8),
+CUDA_ENTRY(12, 9),
 {"", CudaVersion::NEW, 
llvm::VersionTuple(std::numeric_limits::max())},
 {"unknown", CudaVersion::UNKNOWN, {}} // End of list tombstone.
 };
@@ -98,6 +101,7 @@ static const OffloadArchToStringMap arch_names[] = {
 SM(90),  // Hopper
 SM(90a), // Hopper
 SM(100), // Blackwell
+SM(100a),// Blackwell
 GFX(600),  // gfx600
 GFX(601),  // gfx601
 GFX(602),  // gfx602
@@ -227,8 +231,8 @@ CudaVersion MinVersionForOffloadArch(OffloadArch A) {
   case OffloadArch::SM_90a:
 return CudaVersion::CUDA_120;
   case OffloadArch::SM_100:
-return CudaVersion::NEW; // TODO: use specific CUDA version once it's
- // public.
+  case OffloadArch::SM_100a:
+return CudaVersion::CUDA_128;
   default:
 llvm_unreachable("invalid enum");
   }
diff --git a/clang/lib/Basic/Targets/NVPTX.cpp 
b/clang/lib/Basic/Targets/NVPTX.cpp
index dbc3fec3657610..56efad90cb7c84 100644
--- a/clang/lib/Basic/Targets/NVPTX.cpp
+++ b/clang/lib/Basic/Targets/NVPTX.cpp
@@ -285,6 +285,7 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   case OffloadArch::SM_90a:
 return "900";
   case OffloadArch::SM_100:
+  case OffloadArch::SM_100a:
 return "1000";
   }
   llvm_unreachable("unhandled OffloadArch");
@@ -292,6 +293,8 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__CUDA_ARCH__", CUDAArchCode);
 if (GPU == OffloadArch::SM_90a)
   Builder.defineMacro("__CUDA_ARCH_FEAT_SM90_ALL", "1");
+if (GPU == OffloadArch::SM_100a)
+  Builder.defineMacro("__CUDA_ARCH_FEAT_SM100_ALL", "1");
   }
 }
 
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 87c3635ed3f70e..c13928f61a7481 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -2277,6 +2277,7 @@ void CGOpenMPRuntimeGPU::processRequiresDirective(const 
OMPRequires

[clang] [HLSL] Fix global resource initialization (PR #123394)

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

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


[clang] [llvm] [NVPTX] Add support for PTX 8.6 and CUDA 12.6 (12.8) (PR #123398)

2025-01-17 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Sergey Kozub (sergey-kozub)


Changes

CUDA 12.8 supports PTX 8.6 which enables architecture "sm100a" (supports 
Blackwell-specific instructions).
CUDA 12.7 technically does not exist, map it to PTX 8.5 (same as 12.6).


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


7 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsNVPTX.def (+4-1) 
- (modified) clang/include/clang/Basic/Cuda.h (+5-1) 
- (modified) clang/lib/Basic/Cuda.cpp (+6-2) 
- (modified) clang/lib/Basic/Targets/NVPTX.cpp (+3) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+1) 
- (modified) clang/lib/Driver/ToolChains/Cuda.cpp (+9) 
- (modified) llvm/lib/Target/NVPTX/NVPTX.td (+2) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index 969dd9e41ebfa3..37b4e6ff77fda6 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -28,7 +28,9 @@
 #pragma push_macro("SM_90")
 #pragma push_macro("SM_90a")
 #pragma push_macro("SM_100")
-#define SM_100 "sm_100"
+#pragma push_macro("SM_100a")
+#define SM_100a "sm_100a"
+#define SM_100 "sm_100|" SM_100a
 #define SM_90a "sm_90a"
 #define SM_90 "sm_90|" SM_90a "|" SM_100
 #define SM_89 "sm_89|" SM_90
@@ -1091,6 +1093,7 @@ TARGET_BUILTIN(__nvvm_getctarank_shared_cluster, "iv*3", 
"", AND(SM_90,PTX78))
 #pragma pop_macro("SM_90")
 #pragma pop_macro("SM_90a")
 #pragma pop_macro("SM_100")
+#pragma pop_macro("SM_100a")
 #pragma pop_macro("PTX42")
 #pragma pop_macro("PTX60")
 #pragma pop_macro("PTX61")
diff --git a/clang/include/clang/Basic/Cuda.h b/clang/include/clang/Basic/Cuda.h
index c2a4addf488df1..1cdfc8178db843 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -44,9 +44,12 @@ enum class CudaVersion {
   CUDA_124,
   CUDA_125,
   CUDA_126,
+  CUDA_127,
+  CUDA_128,
+  CUDA_129,
   FULLY_SUPPORTED = CUDA_123,
   PARTIALLY_SUPPORTED =
-  CUDA_126, // Partially supported. Proceed with a warning.
+  CUDA_129, // Partially supported. Proceed with a warning.
   NEW = 1,  // Too new. Issue a warning, but allow using it.
 };
 const char *CudaVersionToString(CudaVersion V);
@@ -80,6 +83,7 @@ enum class OffloadArch {
   SM_90,
   SM_90a,
   SM_100,
+  SM_100a,
   GFX600,
   GFX601,
   GFX602,
diff --git a/clang/lib/Basic/Cuda.cpp b/clang/lib/Basic/Cuda.cpp
index d56609a2a8f24a..692ab7c319d8bd 100644
--- a/clang/lib/Basic/Cuda.cpp
+++ b/clang/lib/Basic/Cuda.cpp
@@ -44,6 +44,9 @@ static const CudaVersionMapEntry CudaNameVersionMap[] = {
 CUDA_ENTRY(12, 4),
 CUDA_ENTRY(12, 5),
 CUDA_ENTRY(12, 6),
+CUDA_ENTRY(12, 7),
+CUDA_ENTRY(12, 8),
+CUDA_ENTRY(12, 9),
 {"", CudaVersion::NEW, 
llvm::VersionTuple(std::numeric_limits::max())},
 {"unknown", CudaVersion::UNKNOWN, {}} // End of list tombstone.
 };
@@ -98,6 +101,7 @@ static const OffloadArchToStringMap arch_names[] = {
 SM(90),  // Hopper
 SM(90a), // Hopper
 SM(100), // Blackwell
+SM(100a),// Blackwell
 GFX(600),  // gfx600
 GFX(601),  // gfx601
 GFX(602),  // gfx602
@@ -227,8 +231,8 @@ CudaVersion MinVersionForOffloadArch(OffloadArch A) {
   case OffloadArch::SM_90a:
 return CudaVersion::CUDA_120;
   case OffloadArch::SM_100:
-return CudaVersion::NEW; // TODO: use specific CUDA version once it's
- // public.
+  case OffloadArch::SM_100a:
+return CudaVersion::CUDA_128;
   default:
 llvm_unreachable("invalid enum");
   }
diff --git a/clang/lib/Basic/Targets/NVPTX.cpp 
b/clang/lib/Basic/Targets/NVPTX.cpp
index dbc3fec3657610..56efad90cb7c84 100644
--- a/clang/lib/Basic/Targets/NVPTX.cpp
+++ b/clang/lib/Basic/Targets/NVPTX.cpp
@@ -285,6 +285,7 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   case OffloadArch::SM_90a:
 return "900";
   case OffloadArch::SM_100:
+  case OffloadArch::SM_100a:
 return "1000";
   }
   llvm_unreachable("unhandled OffloadArch");
@@ -292,6 +293,8 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__CUDA_ARCH__", CUDAArchCode);
 if (GPU == OffloadArch::SM_90a)
   Builder.defineMacro("__CUDA_ARCH_FEAT_SM90_ALL", "1");
+if (GPU == OffloadArch::SM_100a)
+  Builder.defineMacro("__CUDA_ARCH_FEAT_SM100_ALL", "1");
   }
 }
 
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 87c3635ed3f70e..c13928f61a7481 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -2277,6 +2277,7 @@ void CGOpenMPRuntimeGPU::processRequiresDirective(const 
OMPRequiresDecl *D) {
   case OffloadArch::SM_90:
   case OffloadArch::SM_90a:
   case OffloadArch::SM_

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

2025-01-17 Thread Sean Perry via cfe-commits

https://github.com/perry-ca created 
https://github.com/llvm/llvm-project/pull/123399

Add an option similar to the -qtarget option in XL to allow the user to say 
they want to be able to run the generated program on an older version of the LE 
environment.  This option will do two things:
- set the `__TARGET_LIBS` macro so the system headers exclude newer interfaces 
when targeting older environments
- set the arch level to match the minimum arch level for that older version of 
LE.  It some happens right now all of the supported LE versions have a the same 
minimum ach level so the option doesn't change this yet.  

The user can specify three different kinds of arguments:
1. -mzos-target=zosv*V*r*R* - where V & R are the version and release
2. -mzos-target=0x4vrr - v, r, m, p are the hex values for the version, 
release, and modlevel
3. -mzos-target=current - uses the latest version of LE the system headers have 
support for

>From 9f5763faa81691f540af42721147daf50042e549 Mon Sep 17 00:00:00 2001
From: Sean Perry 
Date: Wed, 27 Nov 2024 18:33:09 -0600
Subject: [PATCH 1/2] Add -mzos-target

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  5 ++
 clang/include/clang/Driver/Options.td |  1 +
 clang/lib/Basic/Targets/SystemZ.cpp   | 15 
 clang/lib/Driver/Driver.cpp   | 72 +++
 clang/lib/Driver/ToolChain.cpp| 15 
 clang/test/Preprocessor/zos-target.c  | 18 +
 6 files changed, 126 insertions(+)
 create mode 100644 clang/test/Preprocessor/zos-target.c

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 5155b23d151c04..140bc52af12b25 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -277,6 +277,11 @@ def err_cpu_unsupported_isa
 def err_arch_unsupported_isa
   : Error<"architecture '%0' does not support '%1' execution mode">;
 
+def err_zos_target_release_discontinued
+  : Error<"z/OS target level \"%0\" is discontinued.  Unexpected behavior 
might occur if an out-of-support target level is specified.  Use z/OS target 
level \"zOSv2r4\", or later instead">;
+def err_zos_target_unrecognized_release
+  : Error<"\"%0\" is not recognized as a valid z/OS target level.  The z/OS 
target level must be \"current\", or of the form \"zosvVrR\", where \"V\" is 
the version and \"R\" is the release, or given as a \"0x\"-prefixed eight digit 
hexadecimal value">;
+
 def err_drv_I_dash_not_supported : Error<
   "'%0' not supported, please use -iquote instead">;
 def err_drv_unknown_argument : Error<"unknown argument: '%0'">;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 40fd48761928b3..ddbd857414e714 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4734,6 +4734,7 @@ def mwatchsimulator_version_min_EQ : Joined<["-"], 
"mwatchsimulator-version-min=
 def march_EQ : Joined<["-"], "march=">, Group,
   Flags<[TargetSpecific]>, Visibility<[ClangOption, CLOption, DXCOption, 
FlangOption]>,
   HelpText<"For a list of available architectures for the target use 
'-mcpu=help'">;
+def mzos_target_EQ : Joined<["-"], "mzos-target=">, Group, 
Visibility<[ClangOption, CC1Option]>, HelpText<"Set the z/OS release of the 
runtime environment">;
 def masm_EQ : Joined<["-"], "masm=">, Group, Visibility<[ClangOption, 
FlangOption]>;
 def inline_asm_EQ : Joined<["-"], "inline-asm=">, Group,
   Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Basic/Targets/SystemZ.cpp 
b/clang/lib/Basic/Targets/SystemZ.cpp
index 06f08db2eadd47..2c749c0ba76937 100644
--- a/clang/lib/Basic/Targets/SystemZ.cpp
+++ b/clang/lib/Basic/Targets/SystemZ.cpp
@@ -168,6 +168,21 @@ void SystemZTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__VX__");
   if (Opts.ZVector)
 Builder.defineMacro("__VEC__", "10304");
+
+  /* Set __TARGET_LIB__ only if a value was given.  If no value was given  */
+  /* we rely on the LE headers to define __TARGET_LIB__.   */
+  if (!getTriple().getOSVersion().empty()) {
+llvm::VersionTuple V = getTriple().getOSVersion();
+// Create string with form: 0xPVRR, where P=4
+std::string Str("0x");
+unsigned int Librel = 0x4000;
+Librel |= V.getMajor() << 24;
+Librel |= (V.getMinor() ? V.getMinor().value() : 1) << 16;
+Librel |= V.getSubminor() ? V.getSubminor().value() : 0;
+Str += llvm::utohexstr(Librel);
+
+Builder.defineMacro("__TARGET_LIB__", Str.c_str());
+  }
 }
 
 ArrayRef SystemZTargetInfo::getTargetBuiltins() const {
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ad14b5c9b6dc80..eebe60648ed22b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -517,6 +517,72 @@ DerivedArgList *Driver::TranslateInputArgs(const 
InputArgList &Args) const {
   return DAL

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

2025-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Sean Perry (perry-ca)


Changes

Add an option similar to the -qtarget option in XL to allow the user to say 
they want to be able to run the generated program on an older version of the LE 
environment.  This option will do two things:
- set the `__TARGET_LIBS` macro so the system headers exclude newer interfaces 
when targeting older environments
- set the arch level to match the minimum arch level for that older version of 
LE.  It some happens right now all of the supported LE versions have a the same 
minimum ach level so the option doesn't change this yet.  

The user can specify three different kinds of arguments:
1. -mzos-target=zosv*V*r*R* - where V & R are the version and release
2. -mzos-target=0x4vrr - v, r, m, p are the hex values for the version, 
release, and modlevel
3. -mzos-target=current - uses the latest version of LE the system headers have 
support for

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


6 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+5) 
- (modified) clang/include/clang/Driver/Options.td (+1) 
- (modified) clang/lib/Basic/Targets/SystemZ.cpp (+16) 
- (modified) clang/lib/Driver/Driver.cpp (+72) 
- (modified) clang/lib/Driver/ToolChain.cpp (+20-4) 
- (added) clang/test/Preprocessor/zos-target.c (+18) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 42c39ac6606c7f..603b6656ee8cb1 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -277,6 +277,11 @@ def err_cpu_unsupported_isa
 def err_arch_unsupported_isa
   : Error<"architecture '%0' does not support '%1' execution mode">;
 
+def err_zos_target_release_discontinued
+  : Error<"z/OS target level \"%0\" is discontinued.  Unexpected behavior 
might occur if an out-of-support target level is specified.  Use z/OS target 
level \"zOSv2r4\", or later instead">;
+def err_zos_target_unrecognized_release
+  : Error<"\"%0\" is not recognized as a valid z/OS target level.  The z/OS 
target level must be \"current\", or of the form \"zosvVrR\", where \"V\" is 
the version and \"R\" is the release, or given as a \"0x\"-prefixed eight digit 
hexadecimal value">;
+
 def err_drv_I_dash_not_supported : Error<
   "'%0' not supported, please use -iquote instead">;
 def err_drv_unknown_argument : Error<"unknown argument: '%0'">;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d38dd2b4e3cf09..2023764287092a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4774,6 +4774,7 @@ def mwatchsimulator_version_min_EQ : Joined<["-"], 
"mwatchsimulator-version-min=
 def march_EQ : Joined<["-"], "march=">, Group,
   Flags<[TargetSpecific]>, Visibility<[ClangOption, CLOption, DXCOption, 
FlangOption]>,
   HelpText<"For a list of available architectures for the target use 
'-mcpu=help'">;
+def mzos_target_EQ : Joined<["-"], "mzos-target=">, Group, 
Visibility<[ClangOption, CC1Option]>, HelpText<"Set the z/OS release of the 
runtime environment">;
 def masm_EQ : Joined<["-"], "masm=">, Group, Visibility<[ClangOption, 
FlangOption]>;
 def inline_asm_EQ : Joined<["-"], "inline-asm=">, Group,
   Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Basic/Targets/SystemZ.cpp 
b/clang/lib/Basic/Targets/SystemZ.cpp
index 06f08db2eadd47..2731cb596fd27a 100644
--- a/clang/lib/Basic/Targets/SystemZ.cpp
+++ b/clang/lib/Basic/Targets/SystemZ.cpp
@@ -15,6 +15,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 
 using namespace clang;
@@ -168,6 +169,21 @@ void SystemZTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__VX__");
   if (Opts.ZVector)
 Builder.defineMacro("__VEC__", "10304");
+
+  /* Set __TARGET_LIB__ only if a value was given.  If no value was given  */
+  /* we rely on the LE headers to define __TARGET_LIB__.   */
+  if (!getTriple().getOSVersion().empty()) {
+llvm::VersionTuple V = getTriple().getOSVersion();
+// Create string with form: 0xPVRR, where P=4
+std::string Str("0x");
+unsigned int Librel = 0x4000;
+Librel |= V.getMajor() << 24;
+Librel |= (V.getMinor() ? V.getMinor().value() : 1) << 16;
+Librel |= V.getSubminor() ? V.getSubminor().value() : 0;
+Str += llvm::utohexstr(Librel);
+
+Builder.defineMacro("__TARGET_LIB__", Str.c_str());
+  }
 }
 
 ArrayRef SystemZTargetInfo::getTargetBuiltins() const {
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 87855fdb799710..bea16edb152f52 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -564,6 +564,72 @@ DerivedArgList *Driver

[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)

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

farzonl wrote:

> Will a follow-up issue be created to move the useful `Sema` helpers into a 
> common file?

I'm fine if you want to do this as a follow up.


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


[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)

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

farzonl wrote:

> This pr LGTM once the graceful exit comment is handled.
> 
> With respect to [this 
> comment](https://github.com/llvm/llvm-project/pull/122992#discussion_r1917127000).
>  Is the final solution to just gracefully exit or is this an intermediate 
> step and an issue will be used to track an update using inst combine later?

The graceful exit should be sufficient. We don't expose the clang builtin when 
targeting spirv32 or spirv64 and for now we are the only consumers of this 
intrinsic. Like I said in the last comment to only way to trigger this crash is 
with hand spun llvmir. To me making this not crash if you aren't in a supported 
environment is good enough. 

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


[clang] [HIP] Move HIP to the new driver by default (PR #123359)

2025-01-17 Thread via cfe-commits

b-sumner wrote:

> I'd like to avoid modifying this struct to avoid breaking ABI with OpenMP. 
> Perhaps I should make `addr` a pointer to a struct and just GEP the two 
> values.

Are we trying to jam a square HIP peg into a round OpenMP hole, or are we truly 
wanting to move to a language neutral base?  If the latter, why don't we fix 
the base if it isn't sufficient?

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Richard Smith via cfe-commits


@@ -951,28 +959,124 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator 
&D,
   return New;
 }
 
+// CheckBindingsCount
+//  - Checks the arity of the structured bindings
+//  - Creates the resolved pack expr if there is
+//one
+static bool CheckBindingsCount(Sema &S, DecompositionDecl *DD,
+   QualType DecompType,
+   ArrayRef Bindings,
+   unsigned MemberCount) {
+  auto BindingWithPackItr =
+  std::find_if(Bindings.begin(), Bindings.end(),
+   [](BindingDecl *D) -> bool { return D->isParameterPack(); 
});
+  bool HasPack = BindingWithPackItr != Bindings.end();
+  bool IsValid;
+  if (!HasPack) {
+IsValid = Bindings.size() == MemberCount;
+  } else {
+// there may not be more members than non-pack bindings
+IsValid = MemberCount >= Bindings.size() - 1;
+  }
+
+  if (IsValid && HasPack) {
+// create the pack expr and assign it to the binding
+unsigned PackSize = MemberCount - Bindings.size() + 1;
+QualType PackType = S.Context.getPackExpansionType(
+S.Context.DependentTy, std::nullopt, /*ExpectsPackInType=*/false);
+BindingDecl *BD = (*BindingWithPackItr);
+BD->setBinding(PackType,
+   ResolvedUnexpandedPackExpr::Create(
+   S.Context, DD->getBeginLoc(), DecompType, PackSize));

zygoloid wrote:

Instead of creating a single binding with a pack of values, I think template 
instantiation should be creating `N` `BindingDecl`s each with a single value, 
like we do when we instantiate a function parameter pack or a template 
parameter pack. I think that would simplify a lot of what you're doing here.

(During the initial parse, we should treat a structured binding declaration 
with a binding pack as being dependent, just like we treat a case where the 
initializer has an unexpanded pack as dependent.)

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Richard Smith via cfe-commits


@@ -5321,6 +5321,59 @@ class BuiltinBitCastExpr final
   }
 };
 
+// Represents an unexpanded pack where the list of expressions are
+// known. These are used when structured bindings introduce a pack.
+class ResolvedUnexpandedPackExpr final

zygoloid wrote:

This seems to be doing the same job as `SubstNonTypeTemplateParmPackExpr` and 
`FunctionParmPackExpr`. Do we need all three? If so, mentioning the 
relationship between the three in this comment might be nice -- but I do wonder 
if `FunctionParmPackExpr` could be generalized to cover the case of a binding 
declaration too.

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Richard Smith via cfe-commits


@@ -1099,6 +1099,13 @@ def err_lambda_capture_misplaced_ellipsis : Error<
   "the name of the capture">;
 def err_lambda_capture_multiple_ellipses : Error<
   "multiple ellipses in pack capture">;
+def err_binding_multiple_ellipses : Error<
+  "multiple ellipses in structured binding declaration">;
+def note_previous_ellipsis : Note<
+  "previous ellipsis specified here">;

zygoloid wrote:

It seems a little strange to talk about ellipses rather than packs here. Maybe 
"multiple binding packs in [...]" instead?

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


[clang] [scan-build-py] use explicit compiler wrapper paths for intercept (PR #123252)

2025-01-17 Thread László Nagy via cfe-commits

rizsotto wrote:

@obiwac LGTM!

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Jason Rice via cfe-commits


@@ -5321,6 +5321,59 @@ class BuiltinBitCastExpr final
   }
 };
 
+// Represents an unexpanded pack where the list of expressions are
+// known. These are used when structured bindings introduce a pack.
+class ResolvedUnexpandedPackExpr final

ricejasonf wrote:

I definitely think they could be generalized which is what I had in mind with 
`ResolvedUnexpandedPackExpr`. This is originally what I had for parmexprs 
(P1221).

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


[clang] [llvm] [HLSL][SPIRV][DXIL] Implement `WaveActiveMax` intrinsic (PR #123428)

2025-01-17 Thread Adam Yang via cfe-commits

https://github.com/adam-yang created 
https://github.com/llvm/llvm-project/pull/123428

```- add clang builtin to Builtins.td
  - link builtin in hlsl_intrinsics
  - add codegen for spirv intrinsic and two directx intrinsics to retain
signedness information of the operands in CGBuiltin.cpp
  - add semantic analysis in SemaHLSL.cpp
  - add lowering of spirv intrinsic to spirv backend in
SPIRVInstructionSelector.cpp
  - add lowering of directx intrinsics to WaveActiveOp dxil op in
DXIL.td

  - add test cases to illustrate passespendent pr merges.
```
Resolves #99170

>From 9a0cf138d99ebc9ae18db054b4d8eaa34e8174a8 Mon Sep 17 00:00:00 2001
From: Adam Yang <31109344+adam-y...@users.noreply.github.com>
Date: Fri, 17 Jan 2025 16:14:44 -0800
Subject: [PATCH] Added WaveActiveMax

---
 clang/include/clang/Basic/Builtins.td |   6 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  36 +
 clang/lib/Sema/SemaHLSL.cpp   |   1 +
 .../CodeGenHLSL/builtins/WaveActiveMax.hlsl   |  46 ++
 .../BuiltIns/WaveActiveMax-errors.hlsl|  29 
 llvm/include/llvm/IR/IntrinsicsDirectX.td |   2 +
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |   2 +
 llvm/lib/Target/DirectX/DXIL.td   |   6 +
 .../DirectX/DirectXTargetTransformInfo.cpp|   2 +
 .../Target/SPIRV/SPIRVInstructionSelector.cpp |  33 
 llvm/test/CodeGen/DirectX/WaveActiveMax.ll| 143 ++
 .../SPIRV/hlsl-intrinsics/WaveActiveMax.ll|  55 +++
 12 files changed, 361 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/WaveActiveMax.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/WaveActiveMax-errors.hlsl
 create mode 100644 llvm/test/CodeGen/DirectX/WaveActiveMax.ll
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveMax.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index bbf4886b5cf053..a7f17ec4c8ef8f 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4795,6 +4795,12 @@ def HLSLWaveActiveCountBits : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "unsigned int(bool)";
 }
 
+def HLSLWaveActiveMax : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_wave_active_max"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void (...)";
+}
+
 def HLSLWaveActiveSum : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_wave_active_sum"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index b80833fd91884d..57d8eec24a5a0b 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19203,6 +19203,25 @@ static Intrinsic::ID 
getWaveActiveSumIntrinsic(llvm::Triple::ArchType Arch,
   }
 }
 
+// Return wave active sum that corresponds to the QT scalar type
+static Intrinsic::ID getWaveActiveMaxIntrinsic(llvm::Triple::ArchType Arch,
+   CGHLSLRuntime &RT, QualType QT) 
{
+  switch (Arch) {
+  case llvm::Triple::spirv:
+if (QT->isUnsignedIntegerType())
+  return llvm::Intrinsic::spv_wave_reduce_umax;
+return llvm::Intrinsic::spv_wave_reduce_max;
+  case llvm::Triple::dxil: {
+if (QT->isUnsignedIntegerType())
+  return llvm::Intrinsic::dx_wave_reduce_umax;
+return llvm::Intrinsic::dx_wave_reduce_max;
+  }
+  default:
+llvm_unreachable("Intrinsic WaveActiveMax"
+ " not supported by target architecture");
+  }
+}
+
 Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
 const CallExpr *E,
 ReturnValueSlot ReturnValue) {
@@ -19532,6 +19551,23 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
  
/*AssumeConvergent=*/true),
ArrayRef{OpExpr}, "hlsl.wave.active.sum");
   }
+  case Builtin::BI__builtin_hlsl_wave_active_max: {
+// Due to the use of variadic arguments, explicitly retreive argument
+Value *OpExpr = EmitScalarExpr(E->getArg(0));
+llvm::FunctionType *FT = llvm::FunctionType::get(
+OpExpr->getType(), ArrayRef{OpExpr->getType()}, false);
+Intrinsic::ID IID = getWaveActiveMaxIntrinsic(
+getTarget().getTriple().getArch(), CGM.getHLSLRuntime(),
+E->getArg(0)->getType());
+
+// Get overloaded name
+std::string Name =
+Intrinsic::getName(IID, ArrayRef{OpExpr->getType()}, &CGM.getModule());
+return EmitRuntimeCall(CGM.CreateRuntimeFunction(FT, Name, {},
+ /*Local=*/false,
+ 
/*AssumeConvergent=*/true),
+   ArrayRef{OpExpr}, "hlsl.wave.active.max");
+  }
   case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
 // We don't define a SPIR-V intrinsic, ins

[clang] [llvm] [HLSL][SPIRV][DXIL] Implement `WaveActiveMax` intrinsic (PR #123428)

2025-01-17 Thread via cfe-commits

github-actions[bot] wrote:

⚠️ We detected that you are using a GitHub private e-mail address to contribute 
to the repo. Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account. See 
[LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.

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


[clang] [llvm] [HLSL][SPIRV][DXIL] Implement `WaveActiveMax` intrinsic (PR #123428)

2025-01-17 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 22d4ff155aadf0f098dd5dc48d9038da15108937 
9a0cf138d99ebc9ae18db054b4d8eaa34e8174a8 --extensions cpp -- 
clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Sema/SemaHLSL.cpp 
llvm/lib/Target/DirectX/DirectXTargetTransformInfo.cpp 
llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp 
b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 6cdbff45d4..059bbce26e 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -2137,7 +2137,8 @@ bool SPIRVInstructionSelector::selectWaveActiveCountBits(
 
 bool SPIRVInstructionSelector::selectWaveReduceMax(Register ResVReg,
const SPIRVType *ResType,
-   MachineInstr &I, bool 
IsUnsigned) const {
+   MachineInstr &I,
+   bool IsUnsigned) const {
   assert(I.getNumOperands() == 3);
   assert(I.getOperand(2).isReg());
   MachineBasicBlock &BB = *I.getParent();
@@ -2150,9 +2151,9 @@ bool 
SPIRVInstructionSelector::selectWaveReduceMax(Register ResVReg,
   SPIRVType *IntTy = GR.getOrCreateSPIRVIntegerType(32, I, TII);
   // Retreive the operation to use based on input type
   bool IsFloatTy = GR.isScalarOrVectorOfType(InputRegister, 
SPIRV::OpTypeFloat);
-  auto IntegerOpcodeType = IsUnsigned ? SPIRV::OpGroupNonUniformUMax : 
SPIRV::OpGroupNonUniformSMax;
-  auto Opcode =
-  IsFloatTy ? SPIRV::OpGroupNonUniformFMax : IntegerOpcodeType;
+  auto IntegerOpcodeType =
+  IsUnsigned ? SPIRV::OpGroupNonUniformUMax : SPIRV::OpGroupNonUniformSMax;
+  auto Opcode = IsFloatTy ? SPIRV::OpGroupNonUniformFMax : IntegerOpcodeType;
   return BuildMI(BB, I, I.getDebugLoc(), TII.get(Opcode))
   .addDef(ResVReg)
   .addUse(GR.getSPIRVTypeID(ResType))
@@ -3116,9 +3117,9 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register 
ResVReg,
   case Intrinsic::spv_wave_is_first_lane:
 return selectWaveOpInst(ResVReg, ResType, I, 
SPIRV::OpGroupNonUniformElect);
   case Intrinsic::spv_wave_reduce_umax:
-return selectWaveReduceMax(ResVReg, ResType, I, /*IsUnsigned*/true);
+return selectWaveReduceMax(ResVReg, ResType, I, /*IsUnsigned*/ true);
   case Intrinsic::spv_wave_reduce_max:
-return selectWaveReduceMax(ResVReg, ResType, I, /*IsUnsigned*/false);
+return selectWaveReduceMax(ResVReg, ResType, I, /*IsUnsigned*/ false);
   case Intrinsic::spv_wave_reduce_sum:
 return selectWaveReduceSum(ResVReg, ResType, I);
   case Intrinsic::spv_wave_readlane:

``




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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Jason Rice via cfe-commits


@@ -951,28 +959,124 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator 
&D,
   return New;
 }
 
+// CheckBindingsCount
+//  - Checks the arity of the structured bindings
+//  - Creates the resolved pack expr if there is
+//one
+static bool CheckBindingsCount(Sema &S, DecompositionDecl *DD,
+   QualType DecompType,
+   ArrayRef Bindings,
+   unsigned MemberCount) {
+  auto BindingWithPackItr =
+  std::find_if(Bindings.begin(), Bindings.end(),
+   [](BindingDecl *D) -> bool { return D->isParameterPack(); 
});
+  bool HasPack = BindingWithPackItr != Bindings.end();
+  bool IsValid;
+  if (!HasPack) {
+IsValid = Bindings.size() == MemberCount;
+  } else {
+// there may not be more members than non-pack bindings
+IsValid = MemberCount >= Bindings.size() - 1;
+  }
+
+  if (IsValid && HasPack) {
+// create the pack expr and assign it to the binding
+unsigned PackSize = MemberCount - Bindings.size() + 1;
+QualType PackType = S.Context.getPackExpansionType(
+S.Context.DependentTy, std::nullopt, /*ExpectsPackInType=*/false);
+BindingDecl *BD = (*BindingWithPackItr);
+BD->setBinding(PackType,
+   ResolvedUnexpandedPackExpr::Create(
+   S.Context, DD->getBeginLoc(), DecompType, PackSize));

ricejasonf wrote:

The problem is that we do not know the length of the pack until the initializer 
expression is created. This happens in various locations depending on context 
such as range based for loops. I am not saying it isn't possible, but I think 
it would require creating the init expression up front which I do not know if 
that would be problematic with how variables are checked. We could also do 
Bindings in a separate allocation, but that would require keeping the 
DecompositionDeclarator around somehow, and there would need to be that extra 
information in the DecompositionDecl which would have a cost for Decomps that 
do not have a pack. (I don't know if that is an issue.)

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


[clang] [HIP] Move HIP to the new driver by default (PR #123359)

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

jhuber6 wrote:

Fixed the managed stuff in https://github.com/llvm/llvm-project/pull/123437, 
should be good enough for the foreseeable future.

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


[clang] [Clang] Add [[clang::no_specializations]] (PR #101469)

2025-01-17 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

Flagging what looks like a bug

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


[clang] a7bca18 - [clang-format] Correctly annotate braces in macro definitions (#123279)

2025-01-17 Thread via cfe-commits

Author: Owen Pan
Date: 2025-01-17T19:26:00-08:00
New Revision: a7bca1861bfcd1490319115c1027166e27f4ae27

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

LOG: [clang-format] Correctly annotate braces in macro definitions (#123279)

Fixes #123179.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 317717241c17cd..198c05fd9dcd8d 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -503,14 +503,14 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 auto *NextTok = Tokens->getNextNonComment();
 
 if (!Line->InMacroBody && !Style.isTableGen()) {
-  // Skip PPDirective lines and comments.
+  // Skip PPDirective lines (except macro definitions) and comments.
   while (NextTok->is(tok::hash)) {
 NextTok = Tokens->getNextToken();
-if (NextTok->is(tok::pp_not_keyword))
+if (NextTok->isOneOf(tok::pp_not_keyword, tok::pp_define))
   break;
 do {
   NextTok = Tokens->getNextToken();
-} while (!NextTok->HasUnescapedNewline && NextTok->isNot(tok::eof));
+} while (NextTok->NewlinesBefore == 0 && NextTok->isNot(tok::eof));
 
 while (NextTok->is(tok::comment))
   NextTok = Tokens->getNextToken();

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 4d48bcacddead8..d3c97319abb947 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5732,23 +5732,12 @@ TEST_F(FormatTest, HashInMacroDefinition) {
 
   verifyFormat("#define A void # ## #", getLLVMStyleWithColumns(22));
 
-#if 0
-  // FIXME: The correct format is:
   verifyFormat("{\n"
"  {\n"
"#define GEN_ID(_x) char *_x{#_x}\n"
"GEN_ID(one);\n"
"  }\n"
"}");
-#endif
-  verifyFormat("{\n"
-   "  {\n"
-   "#define GEN_ID(_x) \\\n"
-   "  char *_x { #_x }\n"
-   "GEN_ID(one);\n"
-   "  }\n"
-   "}",
-   getGoogleStyle());
 }
 
 TEST_F(FormatTest, RespectWhitespaceInMacroDefinitions) {

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 399502db52cbf6..9ac60ce73750bf 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3413,14 +3413,27 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[0], BK_Block);
   EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_BlockLBrace);
   EXPECT_BRACE_KIND(Tokens[1], BK_Block);
-#if 0
-  // FIXME:
   EXPECT_BRACE_KIND(Tokens[11], BK_BracedInit);
   EXPECT_BRACE_KIND(Tokens[14], BK_BracedInit);
-#endif
   EXPECT_BRACE_KIND(Tokens[20], BK_Block);
   EXPECT_BRACE_KIND(Tokens[21], BK_Block);
 
+  Tokens = annotate("{\n"
+"#define FOO \\\n"
+"  { \\\n"
+"case bar: { \\\n"
+"  break; \\\n"
+"} \\\n"
+"  }\n"
+"}");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_BlockLBrace);
+  EXPECT_BRACE_KIND(Tokens[4], BK_Block);
+  EXPECT_TOKEN(Tokens[7], tok::colon, TT_CaseLabelColon);
+  EXPECT_BRACE_KIND(Tokens[8], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[11], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[12], BK_Block);
+
   Tokens = annotate("a = class extends goog.a {};",
 getGoogleStyle(FormatStyle::LK_JavaScript));
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;



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


[clang] [llvm] [Clang] Match MSVC handling of duplicate header search paths in Microsoft compatibility modes. (PR #105738)

2025-01-17 Thread Tom Honermann via cfe-commits

https://github.com/tahonermann updated 
https://github.com/llvm/llvm-project/pull/105738

>From 1c9813eef03380f0013eaedf669612566a97bce1 Mon Sep 17 00:00:00 2001
From: Tom Honermann 
Date: Thu, 22 Aug 2024 09:44:56 -0700
Subject: [PATCH] [Clang] Support for MSVC compatible header search path
 ordering.

Clang has historically matched GCC's behavior for header search path order
and pruning of duplicate paths. That traditional behavior is to order user
search paths before system search paths, to ignore user search paths that
duplicate a (later) system search path, and to ignore search paths that
duplicate an earlier search path of the same user/system kind. This differs
from MSVC and can result in inconsistent header file resolution for `#include`
directives.

MSVC orders header search paths as follows:
1) Paths specified by the `/I` and `/external:I` options are processed in
   the order that they appear. Paths specified by `/I` that duplicate a path
   specified by `/external:I` are ignored regardless of the order of the
   options. Paths specified by `/I` that duplicate a path from a prior `/I`
   option are ignored. Paths specified by `/external:I` that duplicate a
   path from a later `/external:I` option are ignored.
2) Paths specified by `/external:env` are processed in the order that they
   appear. Paths that duplicate a path from a `/I` or `/external:I` option
   are ignored regardless of the order of the options. Paths that duplicate a
   path from a prior `/external:env` option or an earlier path from the same
   `/external:env` option are ignored.
3) Paths specified by the `INCLUDE` environment variable are processed in
   the order they appear. Paths that duplicate a path from a `/I`,
   `/external:I`, or `/external:env` option are ignored. Paths that
   duplicate an earlier path in the `INCLUDE` environment variable are
   ignored.
4) Paths specified by the `EXTERNAL_INCLUDE` environment variable are
   processed in the order they appear. Paths that duplicate a path from a
   `/I`, `/external:I`, or `/external:env` option are ignored. Paths that
   duplicate a path from the `INCLUDE` environment variable are ignored.
   Paths that duplicate an earlier path in the `EXTERNAL_INCLUDE
   environment variable are ignored.

Prior to this change, Clang handled the MSVC `/external:I` and `/external:env`
options and the paths present in the `INCLUDE` and `EXTERNAL_INCLUDE`
environment variables as though they were specified with the `-isystem` option.
The GCC behavior described above then lead to a command line such as
`/external:I dir1 /Idir2` having a header search order of `dir2` followed by
`dir1`; contrary to MSVC behavior.

Paths specified by the MSVC `/external:I` or `/external:env` options or by the
`EXTERNAL_INCLUDE` environment variable are not just used to nominate a header
search path. MSVC also uses these paths as external directory prefixes to mark
paths that are to be treated as system directories. When a header file is
resolved to a path for which one of these paths is a prefix match, that header
file is treated as a system header regardless of whether the header file was
resolved against a `/I` specified path. Note that it is not necessary for the
final path component of the external path to match a directory in the filesystem
in order to be used as an external directory prefix, though trailing path
separators are significant. For example:

   Include directive Command line System header
     --   -
   #include   /I. /external:Ifoo   Yes
   #include   /I. /external:Ifoo\  No

This change adds support for the MSVC external path concept through the addition
of new driver options with the following option syntax.
   clang clang-cl
     ---
   -iexternal   /external:I 
   -iexternal-env=  /external:env:

Paths specified by these options are treated as system paths. That is, whether
warnings are issued in header files found via these paths remains subject to
use of the `-Wsystem-headers` and `-Wno-system-headers` options. Note that the
MSVC `/external:W` options are mapped to these options.

The MSVC behavior described above implies that (system) paths present in the
`INCLUDE` and `EXTERNAL_INCLUDE` environment variables do not suppress matching
user paths specified via `/I`. This contrasts with GCC's behavior, and Clang's
historical behavior, of suppressing user paths that match a system path
regardless of how each is specified. In order to support both behaviors, the
following driver option has been added. The option arguments shown reflect the
default behavior for each driver.

   clang clang-cl
     -
   -fheader-search=gcc   -fheader-search=microsoft

Use of the MSVC compatible header search path order by default for `clang-cl`
is a change in behavior with potential to cause p

[clang] [llvm] [HIP] Support managed variables using the new driver (PR #123437)

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


@@ -1221,12 +1221,31 @@ void CGNVCUDARuntime::createOffloadingEntries() {
  ? static_cast(llvm::offloading::OffloadGlobalNormalized)
  : 0);
 if (I.Flags.getKind() == DeviceVarFlags::Variable) {
-  llvm::offloading::emitOffloadingEntry(
-  M, I.Var, getDeviceSideName(I.D), VarSize,
-  (I.Flags.isManaged() ? llvm::offloading::OffloadGlobalManagedEntry
-   : llvm::offloading::OffloadGlobalEntry) |
-  Flags,
-  /*Data=*/0, Section);
+  if (I.Flags.isManaged()) {
+assert(I.Var->getName().ends_with(".managed") &&
+   "HIP managed variables not transformed");
+
+// Create a struct to contain the two variables.
+auto *ManagedVar = M.getNamedGlobal(
+I.Var->getName().drop_back(StringRef(".managed").size()));
+llvm::Constant *StructData[] = {ManagedVar, I.Var};
+llvm::Constant *Initializer = llvm::ConstantStruct::get(
+llvm::offloading::getManagedTy(M), StructData);
+auto *Struct = new llvm::GlobalVariable(
+M, llvm::offloading::getManagedTy(M),
+/*IsConstant=*/true, llvm::GlobalValue::PrivateLinkage, 
Initializer,

arsenm wrote:

Should set the address space, probably to the default globals one 

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


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

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

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

Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect ValueOrInherited to be nonnull.  Note that isSet
checks to see if ValueOrInherited is nonnull.


>From 217e63888adcc9f6bf917707943a9437152eb027 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Fri, 17 Jan 2025 09:18:21 -0800
Subject: [PATCH] [AST] Migrate away from PointerUnion::dyn_cast (NFC)

Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect ValueOrInherited to be nonnull.  Note that isSet
checks to see if ValueOrInherited is nonnull.
---
 clang/include/clang/AST/DeclTemplate.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index d3a466a8617bb1..8c2da97c07a3bf 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -367,12 +367,11 @@ class DefaultArgStorage {
 if (!isSet())
   ValueOrInherited = InheritedFrom;
 else if ([[maybe_unused]] auto *D =
- ValueOrInherited.template dyn_cast()) {
+ dyn_cast(ValueOrInherited)) {
   assert(C.isSameDefaultTemplateArgument(D, InheritedFrom));
   ValueOrInherited =
   new (allocateDefaultArgStorageChain(C)) Chain{InheritedFrom, get()};
-} else if (auto *Inherited =
-   ValueOrInherited.template dyn_cast()) {
+} else if (auto *Inherited = dyn_cast(ValueOrInherited)) {
   assert(C.isSameDefaultTemplateArgument(Inherited->PrevDeclWithDefaultArg,
  InheritedFrom));
   Inherited->PrevDeclWithDefaultArg = InheritedFrom;

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


[clang] [ByteCode] Migrate away from PointerUnion::dyn_cast (NFC) (PR #123445)

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

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

Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect D to be nonnull.


>From c87b28836e95b3b407cbf2a2d2120e9af0d7d98d Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Fri, 17 Jan 2025 09:01:37 -0800
Subject: [PATCH] [ByteCode] Migrate away from PointerUnion::dyn_cast (NFC)

Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect D to be nonnull.
---
 clang/lib/AST/ByteCode/Program.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/Program.cpp 
b/clang/lib/AST/ByteCode/Program.cpp
index c98a3506b0a90b..7d8862d606ba3c 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -155,7 +155,7 @@ unsigned Program::getOrCreateDummy(const DeclTy &D) {
 
   QualType QT;
   bool IsWeak = false;
-  if (const auto *E = D.dyn_cast()) {
+  if (const auto *E = dyn_cast(D)) {
 QT = E->getType();
   } else {
 const ValueDecl *VD = cast(cast(D));

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


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

2025-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect ValueOrInherited to be nonnull.  Note that isSet
checks to see if ValueOrInherited is nonnull.


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


1 Files Affected:

- (modified) clang/include/clang/AST/DeclTemplate.h (+2-3) 


``diff
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index d3a466a8617bb1..8c2da97c07a3bf 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -367,12 +367,11 @@ class DefaultArgStorage {
 if (!isSet())
   ValueOrInherited = InheritedFrom;
 else if ([[maybe_unused]] auto *D =
- ValueOrInherited.template dyn_cast()) {
+ dyn_cast(ValueOrInherited)) {
   assert(C.isSameDefaultTemplateArgument(D, InheritedFrom));
   ValueOrInherited =
   new (allocateDefaultArgStorageChain(C)) Chain{InheritedFrom, get()};
-} else if (auto *Inherited =
-   ValueOrInherited.template dyn_cast()) {
+} else if (auto *Inherited = dyn_cast(ValueOrInherited)) {
   assert(C.isSameDefaultTemplateArgument(Inherited->PrevDeclWithDefaultArg,
  InheritedFrom));
   Inherited->PrevDeclWithDefaultArg = InheritedFrom;

``




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


[clang] [ByteCode] Migrate away from PointerUnion::dyn_cast (NFC) (PR #123445)

2025-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect D to be nonnull.


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


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/Program.cpp (+1-1) 


``diff
diff --git a/clang/lib/AST/ByteCode/Program.cpp 
b/clang/lib/AST/ByteCode/Program.cpp
index c98a3506b0a90b..7d8862d606ba3c 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -155,7 +155,7 @@ unsigned Program::getOrCreateDummy(const DeclTy &D) {
 
   QualType QT;
   bool IsWeak = false;
-  if (const auto *E = D.dyn_cast()) {
+  if (const auto *E = dyn_cast(D)) {
 QT = E->getType();
   } else {
 const ValueDecl *VD = cast(cast(D));

``




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


[clang] 90696d1 - [clang][bytecode][NFC] Simplify visitDeclRef (#123380)

2025-01-17 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-01-18T06:18:46+01:00
New Revision: 90696d17f2d6fda87d1cb4f75cc35015ba2795c9

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

LOG: [clang][bytecode][NFC] Simplify visitDeclRef (#123380)

Try to reduce indentation here.

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 3ef2b0858e667b..7afae97f308ad5 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6194,60 +6194,67 @@ bool Compiler::visitDeclRef(const ValueDecl 
*D, const Expr *E) {
   return revisit(VD);
   }
 
-  if (D != InitializingDecl) {
-// Try to lazily visit (or emit dummy pointers for) declarations
-// we haven't seen yet.
-if (Ctx.getLangOpts().CPlusPlus) {
-  if (const auto *VD = dyn_cast(D)) {
-const auto typeShouldBeVisited = [&](QualType T) -> bool {
-  if (T.isConstant(Ctx.getASTContext()))
-return true;
-  return T->isReferenceType();
-};
+  // Avoid infinite recursion.
+  if (D == InitializingDecl)
+return this->emitDummyPtr(D, E);
+
+  // Try to lazily visit (or emit dummy pointers for) declarations
+  // we haven't seen yet.
+  // For C.
+  if (!Ctx.getLangOpts().CPlusPlus) {
+if (const auto *VD = dyn_cast(D);
+VD && VD->getAnyInitializer() &&
+VD->getType().isConstant(Ctx.getASTContext()) && !VD->isWeak())
+  return revisit(VD);
+return this->emitDummyPtr(D, E);
+  }
 
-// DecompositionDecls are just proxies for us.
-if (isa(VD))
-  return revisit(VD);
-
-if ((VD->hasGlobalStorage() || VD->isStaticDataMember()) &&
-typeShouldBeVisited(VD->getType())) {
-  if (const Expr *Init = VD->getAnyInitializer();
-  Init && !Init->isValueDependent()) {
-// Whether or not the evaluation is successul doesn't really matter
-// here -- we will create a global variable in any case, and that
-// will have the state of initializer evaluation attached.
-APValue V;
-SmallVector Notes;
-(void)Init->EvaluateAsInitializer(V, Ctx.getASTContext(), VD, 
Notes,
-  true);
-return this->visitDeclRef(D, E);
-  }
-  return revisit(VD);
-}
+  // ... and C++.
+  const auto *VD = dyn_cast(D);
+  if (!VD)
+return this->emitDummyPtr(D, E);
 
-// FIXME: The evaluateValue() check here is a little ridiculous, since
-// it will ultimately call into Context::evaluateAsInitializer(). In
-// other words, we're evaluating the initializer, just to know if we 
can
-// evaluate the initializer.
-if (VD->isLocalVarDecl() && typeShouldBeVisited(VD->getType()) &&
-VD->getInit() && !VD->getInit()->isValueDependent()) {
+  const auto typeShouldBeVisited = [&](QualType T) -> bool {
+if (T.isConstant(Ctx.getASTContext()))
+  return true;
+return T->isReferenceType();
+  };
 
-  if (VD->evaluateValue())
-return revisit(VD);
+  // DecompositionDecls are just proxies for us.
+  if (isa(VD))
+return revisit(VD);
+
+  if ((VD->hasGlobalStorage() || VD->isStaticDataMember()) &&
+  typeShouldBeVisited(VD->getType())) {
+if (const Expr *Init = VD->getAnyInitializer();
+Init && !Init->isValueDependent()) {
+  // Whether or not the evaluation is successul doesn't really matter
+  // here -- we will create a global variable in any case, and that
+  // will have the state of initializer evaluation attached.
+  APValue V;
+  SmallVector Notes;
+  (void)Init->EvaluateAsInitializer(V, Ctx.getASTContext(), VD, Notes,
+true);
+  return this->visitDeclRef(D, E);
+}
+return revisit(VD);
+  }
+
+  // FIXME: The evaluateValue() check here is a little ridiculous, since
+  // it will ultimately call into Context::evaluateAsInitializer(). In
+  // other words, we're evaluating the initializer, just to know if we can
+  // evaluate the initializer.
+  if (VD->isLocalVarDecl() && typeShouldBeVisited(VD->getType()) &&
+  VD->getInit() && !VD->getInit()->isValueDependent()) {
+
+if (VD->evaluateValue())
+  return revisit(VD);
 
-  if (!D->getType()->isReferenceType())
-return this->emitDummyPtr(D, E);
+if (!D->getType()->isReferenceType())
+  return this->emitDummyPtr(D, E);
 
-  return this->emitInvalidDeclRef(cast(E),
-  /*InitializerFailed=*/true, E);
-}
-  }
-} else {
-  if (const auto *VD = dyn_cast(D

[clang] [clang][bytecode][NFC] Simplify visitDeclRef (PR #123380)

2025-01-17 Thread Timm Baeder via cfe-commits

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


[clang] [clang-format] Fix option `BreakBinaryOperations` for operator `>>` (PR #122282)

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

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


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


[clang] [clang-format] Fix option `BreakBinaryOperations` for operator `>>` (PR #122282)

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

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


[clang] [clang-format] Correctly annotate braces in macro definitions (PR #123279)

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

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


[clang] [clang-format] Fix option `BreakBinaryOperations` for operator `>>` (PR #122282)

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

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


[clang] e240261 - [clang-format] Fix option `BreakBinaryOperations` for operator `>>` (#122282)

2025-01-17 Thread via cfe-commits

Author: Ander
Date: 2025-01-17T19:45:10-08:00
New Revision: e2402615a5a76d46a433dfcc1de10b38a1263c9d

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

LOG: [clang-format] Fix option `BreakBinaryOperations` for operator `>>` 
(#122282)

Fixes #106228.

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 554b55fa75c926..c311deaa17bb0e 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -148,6 +148,7 @@ static bool startsNextOperand(const FormatToken &Current) {
 static bool mustBreakBinaryOperation(const FormatToken &Current,
  const FormatStyle &Style) {
   return Style.BreakBinaryOperations != FormatStyle::BBO_Never &&
+ Current.CanBreakBefore &&
  (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None
   ? startsNextOperand
   : isAlignableBinaryOperator)(Current);

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index d3c97319abb947..f8d13cd0ce2506 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -27976,6 +27976,11 @@ TEST_F(FormatTest, BreakBinaryOperations) {
"operand1 + operand2 - (operand3 + operand4);",
Style);
 
+  // Check operator>> special case.
+  verifyFormat("std::cin >> longOperand_1 >> longOperand_2 >>\n"
+   "longOperand_3_;",
+   Style);
+
   Style.BreakBinaryOperations = FormatStyle::BBO_OnePerLine;
 
   // Logical operations
@@ -28054,6 +28059,13 @@ TEST_F(FormatTest, BreakBinaryOperations) {
" operand6->member;",
Style);
 
+  // Check operator>> special case.
+  verifyFormat("std::cin >>\n"
+   "longOperand_1 >>\n"
+   "longOperand_2 >>\n"
+   "longOperand_3_;",
+   Style);
+
   Style.BreakBinaryOperations = FormatStyle::BBO_RespectPrecedence;
   verifyFormat("result = op1 + op2 * op3 - op4;", Style);
 
@@ -28079,6 +28091,13 @@ TEST_F(FormatTest, BreakBinaryOperations) {
"  byte_buffer[3] << 24;",
Style);
 
+  // Check operator>> special case.
+  verifyFormat("std::cin >>\n"
+   "longOperand_1 >>\n"
+   "longOperand_2 >>\n"
+   "longOperand_3_;",
+   Style);
+
   Style.BreakBinaryOperations = FormatStyle::BBO_OnePerLine;
   Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
 
@@ -28153,6 +28172,13 @@ TEST_F(FormatTest, BreakBinaryOperations) {
"  << 24;",
Style);
 
+  // Check operator>> special case.
+  verifyFormat("std::cin\n"
+   ">> longOperand_1\n"
+   ">> longOperand_2\n"
+   ">> longOperand_3_;",
+   Style);
+
   Style.BreakBinaryOperations = FormatStyle::BBO_RespectPrecedence;
   verifyFormat("result = op1 + op2 * op3 - op4;", Style);
 
@@ -28177,6 +28203,13 @@ TEST_F(FormatTest, BreakBinaryOperations) {
"  | byte_buffer[2] << 16\n"
"  | byte_buffer[3] << 24;",
Style);
+
+  // Check operator>> special case.
+  verifyFormat("std::cin\n"
+   ">> longOperand_1\n"
+   ">> longOperand_2\n"
+   ">> longOperand_3_;",
+   Style);
 }
 
 TEST_F(FormatTest, RemoveEmptyLinesInUnwrappedLines) {



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


[clang] [clang-format] Fix option `BreakBinaryOperations` for operator `>>` (PR #122282)

2025-01-17 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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


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


[clang] [clang-format] Fix option `BreakBinaryOperations` for operator `>>` (PR #122282)

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

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Younan Zhang via cfe-commits


@@ -15991,6 +15998,24 @@ 
TreeTransform::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
   return E;
 }
 
+template 
+ExprResult TreeTransform::TransformResolvedUnexpandedPackExpr(
+ResolvedUnexpandedPackExpr *E) {
+  bool ArgumentChanged = false;
+  SmallVector NewExprs;
+  if (TransformExprs(E->getExprs().begin(), E->getNumExprs(),
+ /*IsCall=*/false, NewExprs, &ArgumentChanged))
+return ExprError();
+
+  if (!AlwaysRebuild() && !ArgumentChanged)
+return E;
+
+  // NOTE: The type is just a superficial PackExpansionType
+  //   that needs no substitution.

zyn0217 wrote:

NVM ResolvedUnexpandedPackExpr is not supposed to be present in the eventual 
instantiation - it's like FunctionParmPackExpr and I was just momentarily 
confused by the name "Resolved".

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


[clang] [clang][bytecode][NFC] Simplify visitDeclRef (PR #123380)

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

llvm-ci wrote:

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

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
[182/186] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.aarch64-with-call.o
[183/186] Generating Msan-aarch64-with-call-Test
[184/186] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.aarch64.o
[185/186] Generating Msan-aarch64-Test
[185/186] Running compiler_rt regression tests
llvm-lit: 
/home/b/sanitizer-aarch64-linux/build/llvm-project/llvm/utils/lit/lit/discovery.py:276:
 warning: input 
'/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/interception/Unit'
 contained no tests
llvm-lit: 
/home/b/sanitizer-aarch64-linux/build/llvm-project/llvm/utils/lit/lit/discovery.py:276:
 warning: input 
'/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/Unit'
 contained no tests
llvm-lit: 
/home/b/sanitizer-aarch64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 6204 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90
FAIL: libFuzzer-aarch64-default-Linux :: reduce_inputs.test (5856 of 6204)
 TEST 'libFuzzer-aarch64-default-Linux :: 
reduce_inputs.test' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: rm -rf 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/fuzzer/AARCH64DefaultLinuxConfig/Output/reduce_inputs.test.tmp/C
+ rm -rf 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/fuzzer/AARCH64DefaultLinuxConfig/Output/reduce_inputs.test.tmp/C
RUN: at line 4: mkdir -p 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/fuzzer/AARCH64DefaultLinuxConfig/Output/reduce_inputs.test.tmp/C
+ mkdir -p 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/fuzzer/AARCH64DefaultLinuxConfig/Output/reduce_inputs.test.tmp/C
RUN: at line 5: /home/b/sanitizer-aarch64-linux/build/build_default/./bin/clang 
   -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/lib/fuzzer  
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta  
/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/fuzzer/ShrinkControlFlowSimpleTest.cpp
 -o 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/fuzzer/AARCH64DefaultLinuxConfig/Output/reduce_inputs.test.tmp-ShrinkControlFlowSimpleTest
+ /home/b/sanitizer-aarch64-linux/build/build_default/./bin/clang 
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta 
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/lib/fuzzer 
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta 
/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/fuzzer/ShrinkControlFlowSimpleTest.cpp
 -o 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/fuzzer/AARCH64DefaultLinuxConfig/Output/reduce_inputs.test.tmp-ShrinkControlFlowSimpleTest
RUN: at line 6: /home/b/sanitizer-aarch64-linux/build/build_default/./bin/clang 
   -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/lib/fuzzer  
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta  
/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/fuzzer/ShrinkControlFlowTest.cpp
 -o 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/fuzzer/AARCH64DefaultLinuxConfig/Output/reduce_inputs.test.tmp-ShrinkControlFlowTest
+ /home/b/sanitizer-aarch64-linux/build/build_default/./bin/clang 
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta 
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/lib/fuzzer 
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta 
/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/fuzzer/ShrinkControlFlowTest.cpp
 -o 
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/r

[clang] [clang-tools-extra] [ast matcher] use `Matcher` instead of `DynTypedMatcher` in `TypeLocTypeMatcher` (PR #123450)

2025-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)


Changes

There are no template in `TypeLocTypeMatcher`. So we do not need to use 
`DynTypedMatcher` which can improve performance


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


2 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp (+1) 
- (modified) clang/include/clang/ASTMatchers/ASTMatchersInternal.h (+2-3) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 1ff61bae46b1ed..4448e9ccba80d9 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 1f7b5e7cac8465..55a925bf869091 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1804,7 +1804,7 @@ class LocMatcher : public MatcherInterface {
 ///
 /// Used to implement the \c loc() matcher.
 class TypeLocTypeMatcher : public MatcherInterface {
-  DynTypedMatcher InnerMatcher;
+  Matcher InnerMatcher;
 
 public:
   explicit TypeLocTypeMatcher(const Matcher &InnerMatcher)
@@ -1814,8 +1814,7 @@ class TypeLocTypeMatcher : public 
MatcherInterface {
BoundNodesTreeBuilder *Builder) const override {
 if (!Node)
   return false;
-return this->InnerMatcher.matches(DynTypedNode::create(Node.getType()),
-  Finder, Builder);
+return this->InnerMatcher.matches(Node.getType(), Finder, Builder);
   }
 };
 

``




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


[clang] [clang-tools-extra] [ast matcher] use `Matcher` instead of `DynTypedMatcher` in `TypeLocTypeMatcher` (PR #123450)

2025-01-17 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/123450

There are no template in `TypeLocTypeMatcher`. So we do not need to use 
`DynTypedMatcher` which can improve performance


>From 959949cd5170a538e1c93d00366014f6aaf3a232 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 18 Jan 2025 14:00:31 +0800
Subject: [PATCH] [ast matcher] use `Matcher` instead of
 `DynTypedMatcher` in

There are no template in
---
 clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 1 +
 clang/include/clang/ASTMatchers/ASTMatchersInternal.h   | 5 ++---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 1ff61bae46b1ed..4448e9ccba80d9 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 1f7b5e7cac8465..55a925bf869091 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1804,7 +1804,7 @@ class LocMatcher : public MatcherInterface {
 ///
 /// Used to implement the \c loc() matcher.
 class TypeLocTypeMatcher : public MatcherInterface {
-  DynTypedMatcher InnerMatcher;
+  Matcher InnerMatcher;
 
 public:
   explicit TypeLocTypeMatcher(const Matcher &InnerMatcher)
@@ -1814,8 +1814,7 @@ class TypeLocTypeMatcher : public 
MatcherInterface {
BoundNodesTreeBuilder *Builder) const override {
 if (!Node)
   return false;
-return this->InnerMatcher.matches(DynTypedNode::create(Node.getType()),
-  Finder, Builder);
+return this->InnerMatcher.matches(Node.getType(), Finder, Builder);
   }
 };
 

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


[clang] [clang-tools-extra] [ast matcher] use `Matcher` instead of `DynTypedMatcher` in `TypeLocTypeMatcher` (PR #123450)

2025-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Congcong Cai (HerrCai0907)


Changes

There are no template in `TypeLocTypeMatcher`. So we do not need to use 
`DynTypedMatcher` which can improve performance


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


2 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp (+1) 
- (modified) clang/include/clang/ASTMatchers/ASTMatchersInternal.h (+2-3) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 1ff61bae46b1ed..4448e9ccba80d9 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 1f7b5e7cac8465..55a925bf869091 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1804,7 +1804,7 @@ class LocMatcher : public MatcherInterface {
 ///
 /// Used to implement the \c loc() matcher.
 class TypeLocTypeMatcher : public MatcherInterface {
-  DynTypedMatcher InnerMatcher;
+  Matcher InnerMatcher;
 
 public:
   explicit TypeLocTypeMatcher(const Matcher &InnerMatcher)
@@ -1814,8 +1814,7 @@ class TypeLocTypeMatcher : public 
MatcherInterface {
BoundNodesTreeBuilder *Builder) const override {
 if (!Node)
   return false;
-return this->InnerMatcher.matches(DynTypedNode::create(Node.getType()),
-  Finder, Builder);
+return this->InnerMatcher.matches(Node.getType(), Finder, Builder);
   }
 };
 

``




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


[clang] [HLSL] Fix global resource initialization (PR #123394)

2025-01-17 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 8fa0f0efce5fb81eb422e6d7eec74c66dafef4a3 
1d04bfa8e1b138a13acf30c3fc46428d3b260569 --extensions cpp,h -- 
clang/lib/CodeGen/CGDeclCXX.cpp clang/lib/CodeGen/CGHLSLRuntime.cpp 
clang/lib/CodeGen/CGHLSLRuntime.h clang/lib/CodeGen/CodeGenModule.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index c01416bcd3..e262a99403 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -602,7 +602,8 @@ void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl 
*VD,
   // for the resource
   const HLSLResourceBindingAttr *RBA = VD->getAttr();
   if (!RBA)
-// FIXME: collect unbound resources for implicit binding resolution later 
on?
+// FIXME: collect unbound resources for implicit binding resolution later
+// on?
 return;
 
   if (!isResourceRecordType(VD->getType().getTypePtr()))

``




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


[clang] 10fdd09 - [clang][DebugInfo] Emit DW_AT_object_pointer on function declarations with explicit `this` (#122928)

2025-01-17 Thread via cfe-commits

Author: Michael Buch
Date: 2025-01-17T19:51:14Z
New Revision: 10fdd09c3bda8bfc532cecf4f11babaf356554f3

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

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

In https://github.com/llvm/llvm-project/pull/122897 we started attaching
`DW_AT_object_pointer` to function definitions. This patch does the same
but for function declarations (which we do for implicit object pointers
already).

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-object-pointer.cpp
llvm/include/llvm-c/DebugInfo.h
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/DebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index f88f56c98186da..6cbcaf03844102 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2016,13 +2016,15 @@ llvm::DISubroutineType 
*CGDebugInfo::getOrCreateInstanceMethodType(
   // First element is always return type. For 'void' functions it is NULL.
   Elts.push_back(Args[0]);
 
-  // "this" pointer is always first argument.
-  // ThisPtr may be null if the member function has an explicit 'this'
-  // parameter.
-  if (!ThisPtr.isNull()) {
+  const bool HasExplicitObjectParameter = ThisPtr.isNull();
+
+  // "this" pointer is always first argument. For explicit "this"
+  // parameters, it will already be in Args[1].
+  if (!HasExplicitObjectParameter) {
 llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
 TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType);
-ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
+ThisPtrType =
+DBuilder.createObjectPointerType(ThisPtrType, /*Implicit=*/true);
 Elts.push_back(ThisPtrType);
   }
 
@@ -2030,6 +2032,13 @@ llvm::DISubroutineType 
*CGDebugInfo::getOrCreateInstanceMethodType(
   for (unsigned i = 1, e = Args.size(); i != e; ++i)
 Elts.push_back(Args[i]);
 
+  // Attach FlagObjectPointer to the explicit "this" parameter.
+  if (HasExplicitObjectParameter) {
+assert(Elts.size() >= 2 && Args.size() >= 2 &&
+   "Expected at least return type and object parameter.");
+Elts[1] = DBuilder.createObjectPointerType(Args[1], /*Implicit=*/false);
+  }
+
   llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
 
   return DBuilder.createSubroutineType(EltTypeArray, OriginalFunc->getFlags(),
@@ -5118,7 +5127,7 @@ llvm::DIType *CGDebugInfo::CreateSelfType(const QualType 
&QualTy,
   llvm::DIType *CachedTy = getTypeOrNull(QualTy);
   if (CachedTy)
 Ty = CachedTy;
-  return DBuilder.createObjectPointerType(Ty);
+  return DBuilder.createObjectPointerType(Ty, /*Implicit=*/true);
 }
 
 void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(

diff  --git a/clang/test/CodeGenCXX/debug-info-object-pointer.cpp 
b/clang/test/CodeGenCXX/debug-info-object-pointer.cpp
index 594d4da791ee84..49079f59909968 100644
--- a/clang/test/CodeGenCXX/debug-info-object-pointer.cpp
+++ b/clang/test/CodeGenCXX/debug-info-object-pointer.cpp
@@ -5,12 +5,11 @@
 // CHECK: !DIDerivedType(tag: DW_TAG_pointer_type
 // CHECK-SAME:   flags: DIFlagArtificial | DIFlagObjectPointer
 //
-// // FIXME: DIFlagObjectPointer not attached to the explicit object
-// // argument in the subprogram declaration.
 // CHECK: !DISubprogram(name: "explicit_this",
 //  flags: DIFlagPrototyped
-// CHECK-NOT: DIFlagObjectPointer
-// CHECK-NOT: DIFlagArtificial
+//
+// CHECK: !DIDerivedType(tag: DW_TAG_rvalue_reference_type
+// CHECK-SAME:   flags: DIFlagObjectPointer)
 //
 // CHECK: !DILocalVariable(name: "this", arg: 1
 // CHECK-SAME: flags: DIFlagArtificial | DIFlagObjectPointer

diff  --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index 07f87d44088e7e..ac7ee5a7cc9a19 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -870,13 +870,16 @@ LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder,
 LLVMMetadataRef Ty);
 
 /**
- * Create a uniqued DIType* clone with FlagObjectPointer and FlagArtificial 
set.
+ * Create a uniqued DIType* clone with FlagObjectPointer. If \c Implicit
+ * is true, then also set FlagArtificial.
  * \param Builder   The DIBuilder.
  * \param Type  The underlying type to which this pointer points.
+ * \param Implicit  Indicates whether this pointer was implicitly generated
+ *  (i.e., not spelled out in source).
  */
-LLVMMetadataRef
-LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
-   

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

2025-01-17 Thread Michael Buch via cfe-commits

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


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

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


@@ -179,13 +179,15 @@ static bool isLanguageDefinedBuiltin(const SourceManager 
&SourceMgr,
 static bool isReservedCXXAttributeName(Preprocessor &PP, IdentifierInfo *II) {
   const LangOptions &Lang = PP.getLangOpts();
   if (Lang.CPlusPlus &&
-  hasAttribute(AttributeCommonInfo::Syntax::AS_CXX11, /*Scope*/ nullptr, 
II,
-   PP.getTargetInfo(), Lang) > 0) {
-AttributeCommonInfo::Kind AttrKind = AttributeCommonInfo::getParsedKind(
-II, /*Scope*/ nullptr, AttributeCommonInfo::Syntax::AS_CXX11);
-return !((AttrKind == AttributeCommonInfo::Kind::AT_Likely ||
-  AttrKind == AttributeCommonInfo::Kind::AT_Unlikely) &&
- PP.isNextPPTokenLParen());
+  hasAttribute(AttributeCommonInfo::AS_CXX11, /* Scope*/ nullptr, II,
+   PP.getTargetInfo(), Lang, /*CheckPlugins*/ false) > 0) {
+AttributeCommonInfo::AttrArgsInfo AttrArgsInfo =
+AttributeCommonInfo::getCXX11AttrArgsInfo(II);
+if (AttrArgsInfo == AttributeCommonInfo::AttrArgsInfo::Required)

a-tarasyuk wrote:

Yes. I added attribute arg information to eliminate the need for additional 
logic to define how certain attributes should behave. For the new attributes, 
everything will work based on the TG information, with no additional logic 
needed.


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


[clang] [HLSL][Sema] Fixed Diagnostics that assumed only two arguments (PR #122772)

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

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


[clang] [HLSL] Fix global resource initialization (PR #123394)

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

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

>From 1d04bfa8e1b138a13acf30c3fc46428d3b260569 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Fri, 17 Jan 2025 12:40:21 -0800
Subject: [PATCH 1/2] [HLSL] Fix global resource initialization

Fixes #120636
---
 clang/lib/CodeGen/CGDeclCXX.cpp   |   8 --
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 128 +-
 clang/lib/CodeGen/CGHLSLRuntime.h |   5 -
 clang/lib/CodeGen/CodeGenModule.h |   2 +
 .../ByteAddressBuffers-constructors.hlsl  |  26 ++--
 .../builtins/RWBuffer-constructor.hlsl|  15 +-
 .../StructuredBuffers-constructors.hlsl   |  51 ---
 clang/test/CodeGenHLSL/resource-bindings.hlsl |  15 +-
 8 files changed, 122 insertions(+), 128 deletions(-)

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 96517511b21114..1c2fecea1a6ac2 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -1131,14 +1131,6 @@ 
CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
   if (Decls[i])
 EmitRuntimeCall(Decls[i]);
 
-if (getLangOpts().HLSL) {
-  CGHLSLRuntime &CGHLSL = CGM.getHLSLRuntime();
-  if (CGHLSL.needsResourceBindingInitFn()) {
-llvm::Function *ResInitFn = CGHLSL.createResourceBindingInitFn();
-Builder.CreateCall(llvm::FunctionCallee(ResInitFn), {});
-  }
-}
-
 Scope.ForceCleanup();
 
 if (ExitBlock) {
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 5679bd71581795..c01416bcd36368 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -536,89 +536,83 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
   }
 }
 
-void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl *VD,
-  llvm::GlobalVariable *GV) {
-  // If the global variable has resource binding, add it to the list of globals
-  // that need resource binding initialization.
-  const HLSLResourceBindingAttr *RBA = VD->getAttr();
-  if (!RBA)
-return;
-
-  if (!HLSLAttributedResourceType::findHandleTypeOnResource(
-  VD->getType().getTypePtr()))
-// FIXME: Only simple declarations of resources are supported for now.
-// Arrays of resources or resources in user defined classes are
-// not implemented yet.
-return;
-
-  ResourcesToBind.emplace_back(VD, GV);
-}
-
-bool CGHLSLRuntime::needsResourceBindingInitFn() {
-  return !ResourcesToBind.empty();
+// Returns true if the record type is an HLSL resource class
+static bool isResourceRecordType(const clang::Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
 }
 
-llvm::Function *CGHLSLRuntime::createResourceBindingInitFn() {
-  // No resources to bind
-  assert(needsResourceBindingInitFn() && "no resources to bind");
-
+static void createResourceInitFn(CodeGenModule &CGM, const VarDecl *VD,
+ llvm::GlobalVariable *GV, unsigned Slot,
+ unsigned Space) {
   LLVMContext &Ctx = CGM.getLLVMContext();
   llvm::Type *Int1Ty = llvm::Type::getInt1Ty(Ctx);
 
-  llvm::Function *InitResBindingsFunc =
-  llvm::Function::Create(llvm::FunctionType::get(CGM.VoidTy, false),
- llvm::GlobalValue::InternalLinkage,
- "_init_resource_bindings", CGM.getModule());
+  llvm::Function *InitResFunc = llvm::Function::Create(
+  llvm::FunctionType::get(CGM.VoidTy, false),
+  llvm::GlobalValue::InternalLinkage,
+  ("_init_resource_" + VD->getName()).str(), CGM.getModule());
 
   llvm::BasicBlock *EntryBB =
-  llvm::BasicBlock::Create(Ctx, "entry", InitResBindingsFunc);
+  llvm::BasicBlock::Create(Ctx, "entry", InitResFunc);
   CGBuilderTy Builder(CGM, Ctx);
   const DataLayout &DL = CGM.getModule().getDataLayout();
   Builder.SetInsertPoint(EntryBB);
 
-  for (const auto &[VD, GV] : ResourcesToBind) {
-for (Attr *A : VD->getAttrs()) {
-  HLSLResourceBindingAttr *RBA = dyn_cast(A);
-  if (!RBA)
-continue;
-
-  const HLSLAttributedResourceType *AttrResType =
-  HLSLAttributedResourceType::findHandleTypeOnResource(
-  VD->getType().getTypePtr());
-
-  // FIXME: Only simple declarations of resources are supported for now.
-  // Arrays of resources or resources in user defined classes are
-  // not implemented yet.
-  assert(AttrResType != nullptr &&
- "Resource class must have a handle of 
HLSLAttributedResourceType");
-
-  llvm::Type *TargetTy =
-  CGM.getTargetCodeGenInfo().getHLSLType(CGM, AttrResType);
-  assert(TargetTy != nullptr &&
- "Failed to convert resource handle to target type");
-
-  auto *Space = llvm::ConstantInt::get(CGM.IntTy, RBA->getSpaceNumber());
-  auto *Slot = llvm::ConstantInt::get(CGM.

[clang] [Clang] Correctly propagate type aliases' unexpanded flags up to lambda (PR #122875)

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

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

I think the change is ok, but I don't think this fixes the underlying issue. 
There is something generally wrong with type aliases which don't use all of 
their parameters, and this needs more thought.

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


[clang] [llvm] [NVPTX] Add support for PTX 8.6 and CUDA 12.6 (12.8) (PR #123398)

2025-01-17 Thread Durgadoss R via cfe-commits

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

The updates look good to me.

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


[clang-tools-extra] [clang-tidy][NFC] remove unused field in UnusedUsingDeclsCheck (PR #123451)

2025-01-17 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/123451

None

>From ebeac6c8a91fea794e25540d40356be313a82799 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 18 Jan 2025 14:13:05 +0800
Subject: [PATCH] [clang-tidy][NFC] remove unused field in
 UnusedUsingDeclsCheck

---
 clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
index 7bdaf12e8aecee..e5f766dbac56b8 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
@@ -51,7 +51,6 @@ class UnusedUsingDeclsCheck : public ClangTidyCheck {
   std::vector Contexts;
   llvm::SmallPtrSet UsingTargetDeclsCache;
 
-  StringRef RawStringHeaderFileExtensions;
   FileExtensionsSet HeaderFileExtensions;
 };
 

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


[clang-tools-extra] [clang-tidy][NFC] remove unused field in UnusedUsingDeclsCheck (PR #123451)

2025-01-17 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)


Changes



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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h (-1) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
index 7bdaf12e8aecee..e5f766dbac56b8 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
@@ -51,7 +51,6 @@ class UnusedUsingDeclsCheck : public ClangTidyCheck {
   std::vector Contexts;
   llvm::SmallPtrSet UsingTargetDeclsCache;
 
-  StringRef RawStringHeaderFileExtensions;
   FileExtensionsSet HeaderFileExtensions;
 };
 

``




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


[clang-tools-extra] 909bf38 - [clang-tidy][NFC] remove unused field in UnusedUsingDeclsCheck (#123451)

2025-01-17 Thread via cfe-commits

Author: Congcong Cai
Date: 2025-01-18T14:14:50+08:00
New Revision: 909bf38c1fea56aab91b1eb43b8c00c515157a53

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

LOG: [clang-tidy][NFC] remove unused field in UnusedUsingDeclsCheck (#123451)

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
index 7bdaf12e8aecee..e5f766dbac56b8 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
@@ -51,7 +51,6 @@ class UnusedUsingDeclsCheck : public ClangTidyCheck {
   std::vector Contexts;
   llvm::SmallPtrSet UsingTargetDeclsCache;
 
-  StringRef RawStringHeaderFileExtensions;
   FileExtensionsSet HeaderFileExtensions;
 };
 



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


[clang-tools-extra] [clang-tidy][NFC] remove unused field in UnusedUsingDeclsCheck (PR #123451)

2025-01-17 Thread Congcong Cai via cfe-commits

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


[clang] [clang-tools-extra] [ASTMatchers][NFC] use `Matcher` instead of `DynTypedMatcher` in `TypeLocTypeMatcher` (PR #123450)

2025-01-17 Thread Congcong Cai via cfe-commits

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Younan Zhang via cfe-commits


@@ -757,23 +775,40 @@ bool Sema::CheckParameterPacksForExpansion(
   bool HaveFirstPack = false;
   std::optional NumPartialExpansions;
   SourceLocation PartiallySubstitutedPackLoc;
+  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
 
   for (UnexpandedParameterPack ParmPack : Unexpanded) {
 // Compute the depth and index for this parameter pack.
 unsigned Depth = 0, Index = 0;
 IdentifierInfo *Name;
 bool IsVarDeclPack = false;
+ResolvedUnexpandedPackExpr *ResolvedPack = nullptr;
 
 if (const TemplateTypeParmType *TTP =
 ParmPack.first.dyn_cast()) {
   Depth = TTP->getDepth();
   Index = TTP->getIndex();
   Name = TTP->getIdentifier();
+} else if (auto *RP =
+   ParmPack.first.dyn_cast()) {
+  ResolvedPack = RP;
 } else {
   NamedDecl *ND = cast(ParmPack.first);
   if (isa(ND))
 IsVarDeclPack = true;
-  else
+  else if (isa(ND)) {
+// Find the instantiated BindingDecl and check it for a resolved pack.
+llvm::PointerUnion *Instantiation =
+CurrentInstantiationScope->findInstantiationOf(ND);
+Decl *B = cast(*Instantiation);
+Expr *BindingExpr = cast(B)->getBinding();
+ResolvedPack =
+dyn_cast_if_present(BindingExpr);
+if (!ResolvedPack) {
+  ShouldExpand = false;
+  continue;
+}

zyn0217 wrote:

Oh yes indeed. I missed something in CheckCompleteDecompositionDeclaration() - 
we wouldn't create ResolvedUnexpandedPackExpr for dependent types.

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


[clang-tools-extra] [clang-tidy][NFC] improve performance misc-unused-using-decls (PR #123454)

2025-01-17 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/123454

skip header file before register AST Matchers
it can avoid to matcher lots of ast node when lint header file


>From 3d4b7e8776af4a51618febb45ba55e3f3428ca64 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 18 Jan 2025 15:42:07 +0800
Subject: [PATCH] [clang-tidy][NFC] improve performance misc-unused-using-decls

skip header file before register AST Matchers
it can avoid to matcher lots of ast node when lint header file
---
 .../clang-tidy/misc/UnusedUsingDeclsCheck.cpp  | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 1ff61bae46b1ed..ebf9e7c19ca842 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -50,6 +50,10 @@ UnusedUsingDeclsCheck::UnusedUsingDeclsCheck(StringRef Name,
   HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
 
 void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
+  // We don't emit warnings on unused-using-decls from headers, so bail out if
+  // the main file is a header.
+  if (utils::isFileExtension(getCurrentMainFile(), HeaderFileExtensions))
+return;
   Finder->addMatcher(usingDecl(isExpansionInMainFile()).bind("using"), this);
   auto DeclMatcher = hasDeclaration(namedDecl().bind("used"));
   Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
@@ -82,12 +86,6 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder 
*Finder) {
 void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
   if (Result.Context->getDiagnostics().hasUncompilableErrorOccurred())
 return;
-  // We don't emit warnings on unused-using-decls from headers, so bail out if
-  // the main file is a header.
-  if (auto MainFile = Result.SourceManager->getFileEntryRefForID(
-  Result.SourceManager->getMainFileID());
-  utils::isFileExtension(MainFile->getName(), HeaderFileExtensions))
-return;
 
   if (const auto *Using = Result.Nodes.getNodeAs("using")) {
 // Ignores using-declarations defined in macros.

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


[clang-tools-extra] [clang-tidy][NFC] improve performance misc-unused-using-decls (PR #123454)

2025-01-17 Thread via cfe-commits

llvmbot wrote:




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

Author: Congcong Cai (HerrCai0907)


Changes

skip header file before register AST Matchers
it can avoid to matcher lots of ast node when lint header file


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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp (+4-6) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 1ff61bae46b1ed..ebf9e7c19ca842 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -50,6 +50,10 @@ UnusedUsingDeclsCheck::UnusedUsingDeclsCheck(StringRef Name,
   HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
 
 void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
+  // We don't emit warnings on unused-using-decls from headers, so bail out if
+  // the main file is a header.
+  if (utils::isFileExtension(getCurrentMainFile(), HeaderFileExtensions))
+return;
   Finder->addMatcher(usingDecl(isExpansionInMainFile()).bind("using"), this);
   auto DeclMatcher = hasDeclaration(namedDecl().bind("used"));
   Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
@@ -82,12 +86,6 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder 
*Finder) {
 void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
   if (Result.Context->getDiagnostics().hasUncompilableErrorOccurred())
 return;
-  // We don't emit warnings on unused-using-decls from headers, so bail out if
-  // the main file is a header.
-  if (auto MainFile = Result.SourceManager->getFileEntryRefForID(
-  Result.SourceManager->getMainFileID());
-  utils::isFileExtension(MainFile->getName(), HeaderFileExtensions))
-return;
 
   if (const auto *Using = Result.Nodes.getNodeAs("using")) {
 // Ignores using-declarations defined in macros.

``




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


[clang] Mechanically convert NVPTX builtins to use TableGen (PR #122873)

2025-01-17 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

Pushed an update that rebases on main, and more notably use an improved script 
that preserves the grouping of builtins and the comments describing them. I 
noticed that there were interesting and important comments here, so I reworked 
things so we don't lose any information.

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


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

2025-01-17 Thread Michał Górny via cfe-commits

mgorny wrote:

I'm going to revert because of the buildbot failures.

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


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

2025-01-17 Thread Michał Górny via cfe-commits

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


[clang] c3a935e - Revert "[clang][DebugInfo] Emit DW_AT_object_pointer on function declarations with explicit `this`" (#123455)

2025-01-17 Thread via cfe-commits

Author: Michał Górny
Date: 2025-01-18T07:59:30Z
New Revision: c3a935e3f967f8f22f5db240d145459ee621c1e0

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

LOG: Revert "[clang][DebugInfo] Emit DW_AT_object_pointer on function 
declarations with explicit `this`" (#123455)

Reverts llvm/llvm-project#122928

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-object-pointer.cpp
llvm/include/llvm-c/DebugInfo.h
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/DebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 6cbcaf03844102..f88f56c98186da 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2016,15 +2016,13 @@ llvm::DISubroutineType 
*CGDebugInfo::getOrCreateInstanceMethodType(
   // First element is always return type. For 'void' functions it is NULL.
   Elts.push_back(Args[0]);
 
-  const bool HasExplicitObjectParameter = ThisPtr.isNull();
-
-  // "this" pointer is always first argument. For explicit "this"
-  // parameters, it will already be in Args[1].
-  if (!HasExplicitObjectParameter) {
+  // "this" pointer is always first argument.
+  // ThisPtr may be null if the member function has an explicit 'this'
+  // parameter.
+  if (!ThisPtr.isNull()) {
 llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
 TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType);
-ThisPtrType =
-DBuilder.createObjectPointerType(ThisPtrType, /*Implicit=*/true);
+ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
 Elts.push_back(ThisPtrType);
   }
 
@@ -2032,13 +2030,6 @@ llvm::DISubroutineType 
*CGDebugInfo::getOrCreateInstanceMethodType(
   for (unsigned i = 1, e = Args.size(); i != e; ++i)
 Elts.push_back(Args[i]);
 
-  // Attach FlagObjectPointer to the explicit "this" parameter.
-  if (HasExplicitObjectParameter) {
-assert(Elts.size() >= 2 && Args.size() >= 2 &&
-   "Expected at least return type and object parameter.");
-Elts[1] = DBuilder.createObjectPointerType(Args[1], /*Implicit=*/false);
-  }
-
   llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
 
   return DBuilder.createSubroutineType(EltTypeArray, OriginalFunc->getFlags(),
@@ -5127,7 +5118,7 @@ llvm::DIType *CGDebugInfo::CreateSelfType(const QualType 
&QualTy,
   llvm::DIType *CachedTy = getTypeOrNull(QualTy);
   if (CachedTy)
 Ty = CachedTy;
-  return DBuilder.createObjectPointerType(Ty, /*Implicit=*/true);
+  return DBuilder.createObjectPointerType(Ty);
 }
 
 void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(

diff  --git a/clang/test/CodeGenCXX/debug-info-object-pointer.cpp 
b/clang/test/CodeGenCXX/debug-info-object-pointer.cpp
index 49079f59909968..594d4da791ee84 100644
--- a/clang/test/CodeGenCXX/debug-info-object-pointer.cpp
+++ b/clang/test/CodeGenCXX/debug-info-object-pointer.cpp
@@ -5,11 +5,12 @@
 // CHECK: !DIDerivedType(tag: DW_TAG_pointer_type
 // CHECK-SAME:   flags: DIFlagArtificial | DIFlagObjectPointer
 //
+// // FIXME: DIFlagObjectPointer not attached to the explicit object
+// // argument in the subprogram declaration.
 // CHECK: !DISubprogram(name: "explicit_this",
 //  flags: DIFlagPrototyped
-//
-// CHECK: !DIDerivedType(tag: DW_TAG_rvalue_reference_type
-// CHECK-SAME:   flags: DIFlagObjectPointer)
+// CHECK-NOT: DIFlagObjectPointer
+// CHECK-NOT: DIFlagArtificial
 //
 // CHECK: !DILocalVariable(name: "this", arg: 1
 // CHECK-SAME: flags: DIFlagArtificial | DIFlagObjectPointer

diff  --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index ac7ee5a7cc9a19..07f87d44088e7e 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -870,16 +870,13 @@ LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder,
 LLVMMetadataRef Ty);
 
 /**
- * Create a uniqued DIType* clone with FlagObjectPointer. If \c Implicit
- * is true, then also set FlagArtificial.
+ * Create a uniqued DIType* clone with FlagObjectPointer and FlagArtificial 
set.
  * \param Builder   The DIBuilder.
  * \param Type  The underlying type to which this pointer points.
- * \param Implicit  Indicates whether this pointer was implicitly generated
- *  (i.e., not spelled out in source).
  */
-LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
- LLVMMetadataRef Type,
- LLVMBool Implicit);
+LLVMMetadataRef
+LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
+ LLVM

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

2025-01-17 Thread Michał Górny via cfe-commits

https://github.com/mgorny created 
https://github.com/llvm/llvm-project/pull/123455

Reverts llvm/llvm-project#122928

From ce83c9470ba1a9860c107d39e60d9148ac009e91 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= 
Date: Sat, 18 Jan 2025 07:59:09 +
Subject: [PATCH] =?UTF-8?q?Revert=20"[clang][DebugInfo]=20Emit=20DW=5FAT?=
 =?UTF-8?q?=5Fobject=5Fpointer=20on=20function=20declarations=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 10fdd09c3bda8bfc532cecf4f11babaf356554f3.
---
 clang/lib/CodeGen/CGDebugInfo.cpp | 21 ++-
 .../CodeGenCXX/debug-info-object-pointer.cpp  |  7 ---
 llvm/include/llvm-c/DebugInfo.h   | 11 --
 llvm/include/llvm/IR/DIBuilder.h  |  6 +++---
 llvm/lib/IR/DIBuilder.cpp |  8 ++-
 llvm/lib/IR/DebugInfo.cpp |  9 
 6 files changed, 23 insertions(+), 39 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 6cbcaf03844102..f88f56c98186da 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2016,15 +2016,13 @@ llvm::DISubroutineType 
*CGDebugInfo::getOrCreateInstanceMethodType(
   // First element is always return type. For 'void' functions it is NULL.
   Elts.push_back(Args[0]);
 
-  const bool HasExplicitObjectParameter = ThisPtr.isNull();
-
-  // "this" pointer is always first argument. For explicit "this"
-  // parameters, it will already be in Args[1].
-  if (!HasExplicitObjectParameter) {
+  // "this" pointer is always first argument.
+  // ThisPtr may be null if the member function has an explicit 'this'
+  // parameter.
+  if (!ThisPtr.isNull()) {
 llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
 TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType);
-ThisPtrType =
-DBuilder.createObjectPointerType(ThisPtrType, /*Implicit=*/true);
+ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
 Elts.push_back(ThisPtrType);
   }
 
@@ -2032,13 +2030,6 @@ llvm::DISubroutineType 
*CGDebugInfo::getOrCreateInstanceMethodType(
   for (unsigned i = 1, e = Args.size(); i != e; ++i)
 Elts.push_back(Args[i]);
 
-  // Attach FlagObjectPointer to the explicit "this" parameter.
-  if (HasExplicitObjectParameter) {
-assert(Elts.size() >= 2 && Args.size() >= 2 &&
-   "Expected at least return type and object parameter.");
-Elts[1] = DBuilder.createObjectPointerType(Args[1], /*Implicit=*/false);
-  }
-
   llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
 
   return DBuilder.createSubroutineType(EltTypeArray, OriginalFunc->getFlags(),
@@ -5127,7 +5118,7 @@ llvm::DIType *CGDebugInfo::CreateSelfType(const QualType 
&QualTy,
   llvm::DIType *CachedTy = getTypeOrNull(QualTy);
   if (CachedTy)
 Ty = CachedTy;
-  return DBuilder.createObjectPointerType(Ty, /*Implicit=*/true);
+  return DBuilder.createObjectPointerType(Ty);
 }
 
 void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
diff --git a/clang/test/CodeGenCXX/debug-info-object-pointer.cpp 
b/clang/test/CodeGenCXX/debug-info-object-pointer.cpp
index 49079f59909968..594d4da791ee84 100644
--- a/clang/test/CodeGenCXX/debug-info-object-pointer.cpp
+++ b/clang/test/CodeGenCXX/debug-info-object-pointer.cpp
@@ -5,11 +5,12 @@
 // CHECK: !DIDerivedType(tag: DW_TAG_pointer_type
 // CHECK-SAME:   flags: DIFlagArtificial | DIFlagObjectPointer
 //
+// // FIXME: DIFlagObjectPointer not attached to the explicit object
+// // argument in the subprogram declaration.
 // CHECK: !DISubprogram(name: "explicit_this",
 //  flags: DIFlagPrototyped
-//
-// CHECK: !DIDerivedType(tag: DW_TAG_rvalue_reference_type
-// CHECK-SAME:   flags: DIFlagObjectPointer)
+// CHECK-NOT: DIFlagObjectPointer
+// CHECK-NOT: DIFlagArtificial
 //
 // CHECK: !DILocalVariable(name: "this", arg: 1
 // CHECK-SAME: flags: DIFlagArtificial | DIFlagObjectPointer
diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index ac7ee5a7cc9a19..07f87d44088e7e 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -870,16 +870,13 @@ LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder,
 LLVMMetadataRef Ty);
 
 /**
- * Create a uniqued DIType* clone with FlagObjectPointer. If \c Implicit
- * is true, then also set FlagArtificial.
+ * Create a uniqued DIType* clone with FlagObjectPointer and FlagArtificial 
set.
  * \param Builder   The DIBuilder.
  * \param Type  The underlying type to which this pointer points.
- * \param Implicit  Indicates whether this pointer was implicitly generated
- *  (i.e., not spelled out in source).
  */
-LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
- LLVMMetadataR

[clang] [llvm] [StrTable] Switch diag group names to `llvm::StringTable` (PR #123302)

2025-01-17 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

> You mention the performance tradeoff of pascal strings v null terminated ones 
> doesn't seem too important - I guess that's based on some judgement about 
> where/how these are used/where the strlens end up happening that you've 
> looked into? Could you summarize that in a bit more detail (like they only 
> happen during diagnostic processing, or something?)

I've not dug deeply, but the only code using it is updated in this PR. The 
biggest use is right before copying the string contents into a `std::string` 
(potentially including allocation), so the `strlen` seems definitively no 
problem there. The other one is a binary search for a string which is already 
somewhat unoptimized, but doesn't seem like a critical path of anything that 
needs to be optimized heavily. The pascal size there doesn't really help either 
as the search looks at the string content first for order.

I'm moderately confident this isn't a problem, just mentioned it in case there 
was something really weird I missed that means I need to take the other 
approach.

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


[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)

2025-01-17 Thread Deric Cheung via cfe-commits

https://github.com/Icohedron updated 
https://github.com/llvm/llvm-project/pull/122992

>From 7ddd5b264731ef375d99d012d9fbfd54c744e5b2 Mon Sep 17 00:00:00 2001
From: Icohedron 
Date: Mon, 13 Jan 2025 21:23:31 +
Subject: [PATCH 1/5] Implement `reflect` HLSL function

---
 clang/include/clang/Basic/BuiltinsSPIRV.td|   6 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  13 ++
 clang/lib/Headers/hlsl/hlsl_detail.h  |  17 ++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  43 
 clang/lib/Sema/SemaSPIRV.cpp  |  32 +++
 clang/test/CodeGenHLSL/builtins/reflect.hlsl  | 195 ++
 clang/test/CodeGenSPIRV/Builtins/reflect.c|  32 +++
 .../SemaHLSL/BuiltIns/reflect-errors.hlsl |  33 +++
 .../test/SemaSPIRV/BuiltIns/reflect-errors.c  |  23 +++
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |   1 +
 .../Target/SPIRV/SPIRVInstructionSelector.cpp |   2 +
 .../CodeGen/SPIRV/hlsl-intrinsics/reflect.ll  |  33 +++
 12 files changed, 430 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/reflect.hlsl
 create mode 100644 clang/test/CodeGenSPIRV/Builtins/reflect.c
 create mode 100644 clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl
 create mode 100644 clang/test/SemaSPIRV/BuiltIns/reflect-errors.c
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reflect.ll

diff --git a/clang/include/clang/Basic/BuiltinsSPIRV.td 
b/clang/include/clang/Basic/BuiltinsSPIRV.td
index f72c555921dfe68..34933e889ba314b 100644
--- a/clang/include/clang/Basic/BuiltinsSPIRV.td
+++ b/clang/include/clang/Basic/BuiltinsSPIRV.td
@@ -19,3 +19,9 @@ def SPIRVLength : Builtin {
   let Attributes = [NoThrow, Const];
   let Prototype = "void(...)";
 }
+
+def SPIRVReflect : Builtin {
+  let Spellings = ["__builtin_spirv_reflect"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index b80833fd91884d8..ab61609ab35a99f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20538,6 +20538,19 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_length,
 ArrayRef{X}, nullptr, "spv.length");
   }
+  case SPIRV::BI__builtin_spirv_reflect: {
+Value *I = EmitScalarExpr(E->getArg(0));
+Value *N = EmitScalarExpr(E->getArg(1));
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+   E->getArg(1)->getType()->hasFloatingRepresentation() &&
+   "Reflect operands must have a float representation");
+assert(E->getArg(0)->getType()->isVectorType() &&
+   E->getArg(1)->getType()->isVectorType() &&
+   "Reflect operands must be a vector");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/I->getType(), Intrinsic::spv_reflect,
+ArrayRef{I, N}, nullptr, "spv.reflect");
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index b2c8cc6c5c3dbb0..3e09f8b10735122 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -79,6 +79,23 @@ constexpr enable_if_t::value || 
is_same::value, T>
 distance_vec_impl(vector X, vector Y) {
   return length_vec_impl(X - Y);
 }
+
+template 
+constexpr enable_if_t::value || is_same::value, T>
+reflect_impl(T I, T N) {
+  return I - 2 * N * I * N;
+}
+
+template 
+constexpr enable_if_t::value || is_same::value, T>
+reflect_vec_impl(vector I, vector N) {
+#if (__has_builtin(__builtin_spirv_reflect))
+  return __builtin_spirv_reflect(I, N);
+#else
+  return I - 2 * N * __builtin_hlsl_dot(I, N);
+#endif
+}
+
 } // namespace __detail
 } // namespace hlsl
 #endif //_HLSL_HLSL_DETAILS_H_
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d1e4eb08aa7646a..54454cf0ea0d0bd 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -2008,6 +2008,49 @@ double3 rcp(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
 double4 rcp(double4);
 
+//===--===//
+// reflect builtin
+//===--===//
+
+/// \fn T reflect(T I, T N)
+/// \brief Returns a reflection using an incident ray, \a I, and a surface
+/// normal, \a N.
+/// \param I The incident ray.
+/// \param N The surface normal.
+///
+/// The return value is a floating-point vector that represents the reflection
+/// of the incident ray, \a I, off a surface with the normal \a N.
+///
+/// This function calculates the reflection vector using the following formula:
+/// V = I - 2 * N * dot(I N) .
+///
+/// N must already be normalized in order to achieve the desired result.
+///
+/// The operands must all be a scalar or vector whose component type is
+/// floating-point.
+///
+/// Result type 

[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Jason Rice via cfe-commits


@@ -951,28 +959,124 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator 
&D,
   return New;
 }
 
+// CheckBindingsCount
+//  - Checks the arity of the structured bindings
+//  - Creates the resolved pack expr if there is
+//one
+static bool CheckBindingsCount(Sema &S, DecompositionDecl *DD,
+   QualType DecompType,
+   ArrayRef Bindings,
+   unsigned MemberCount) {
+  auto BindingWithPackItr =
+  std::find_if(Bindings.begin(), Bindings.end(),
+   [](BindingDecl *D) -> bool { return D->isParameterPack(); 
});
+  bool HasPack = BindingWithPackItr != Bindings.end();
+  bool IsValid;
+  if (!HasPack) {
+IsValid = Bindings.size() == MemberCount;
+  } else {
+// there may not be more members than non-pack bindings
+IsValid = MemberCount >= Bindings.size() - 1;
+  }
+
+  if (IsValid && HasPack) {
+// create the pack expr and assign it to the binding
+unsigned PackSize = MemberCount - Bindings.size() + 1;
+QualType PackType = S.Context.getPackExpansionType(
+S.Context.DependentTy, std::nullopt, /*ExpectsPackInType=*/false);
+BindingDecl *BD = (*BindingWithPackItr);
+BD->setBinding(PackType,
+   ResolvedUnexpandedPackExpr::Create(
+   S.Context, DD->getBeginLoc(), DecompType, PackSize));

ricejasonf wrote:

>(During the initial parse, we should treat a structured binding declaration 
>with a binding pack as being dependent, just like we treat a case where the 
>initializer has an unexpanded pack as dependent.)

The BindingDecls are still created even when the initializer is dependent, and 
still the init expression is created after the DecompositionDecl even in 
template instantiation. (I remember trying this, but template instantation does 
not like instantiation of the same local decl twice.)

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


[clang] [llvm] [StrTable] Switch diag group names to `llvm::StringTable` (PR #123302)

2025-01-17 Thread Chandler Carruth via cfe-commits

https://github.com/chandlerc updated 
https://github.com/llvm/llvm-project/pull/123302

>From c78d4a2fd8d04aa79bab0c65044781aa0b8ca004 Mon Sep 17 00:00:00 2001
From: Chandler Carruth 
Date: Fri, 17 Jan 2025 08:31:45 +
Subject: [PATCH] Switch diagnostic group names to use `llvm::StringTable`

Previously, they used a hand-rolled Pascal-string encoding different
from all the other string tables produced from TableGen. This moves them
to use the newly introduced runtime abstraction, and enhances that
abstraction to support iterating over the string table as used in this
case.

>From what I can tell the Pascal-string encoding isn't critical here to
avoid expensive `strlen` calls, so I think this is a simpler and more
consistent model. But if folks would prefer a Pascal-string style
encoding, I can instead work to switch the `StringTable` abstraction
towards that. It would require some tricky tradeoffs though to make it
reasonably general: either using 4 bytes instead of 1 byte to encode the
size, or having a fallback to `strlen` for long strings.
---
 clang/lib/Basic/DiagnosticIDs.cpp | 18 +++
 clang/tools/diagtool/DiagnosticNames.cpp  |  3 +-
 .../TableGen/ClangDiagnosticsEmitter.cpp  | 28 ---
 llvm/include/llvm/ADT/StringTable.h   | 50 ++-
 4 files changed, 69 insertions(+), 30 deletions(-)

diff --git a/clang/lib/Basic/DiagnosticIDs.cpp 
b/clang/lib/Basic/DiagnosticIDs.cpp
index d77f28c80b2eb2..55f868147134b7 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -16,6 +16,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringTable.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Path.h"
 #include 
@@ -618,11 +619,7 @@ namespace {
 uint16_t SubGroups;
 StringRef Documentation;
 
-// String is stored with a pascal-style length byte.
-StringRef getName() const {
-  return StringRef(DiagGroupNames + NameOffset + 1,
-   DiagGroupNames[NameOffset]);
-}
+StringRef getName() const { return DiagGroupNames[NameOffset]; }
   };
 }
 
@@ -669,11 +666,12 @@ StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned 
DiagID) {
 
 std::vector DiagnosticIDs::getDiagnosticFlags() {
   std::vector Res{"-W", "-Wno-"};
-  for (size_t I = 1; DiagGroupNames[I] != '\0';) {
-std::string Diag(DiagGroupNames + I + 1, DiagGroupNames[I]);
-I += DiagGroupNames[I] + 1;
-Res.push_back("-W" + Diag);
-Res.push_back("-Wno-" + Diag);
+  for (StringRef Name : DiagGroupNames) {
+if (Name.empty())
+  continue;
+
+Res.push_back((Twine("-W") + Name).str());
+Res.push_back((Twine("-Wno-") + Name).str());
   }
 
   return Res;
diff --git a/clang/tools/diagtool/DiagnosticNames.cpp 
b/clang/tools/diagtool/DiagnosticNames.cpp
index eb90f082437b33..1004e7bf2063b1 100644
--- a/clang/tools/diagtool/DiagnosticNames.cpp
+++ b/clang/tools/diagtool/DiagnosticNames.cpp
@@ -9,6 +9,7 @@
 #include "DiagnosticNames.h"
 #include "clang/Basic/AllDiagnostics.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringTable.h"
 
 using namespace clang;
 using namespace diagtool;
@@ -74,7 +75,7 @@ static const GroupRecord OptionTable[] = {
 };
 
 llvm::StringRef GroupRecord::getName() const {
-  return StringRef(DiagGroupNames + NameOffset + 1, 
DiagGroupNames[NameOffset]);
+  return DiagGroupNames[NameOffset];
 }
 
 GroupRecord::subgroup_iterator GroupRecord::subgroup_begin() const {
diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp 
b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index fb00c640d6b144..5f03efdb804344 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1782,19 +1782,12 @@ static void emitDiagArrays(DiagsInGroupTy &DiagsInGroup,
 
 /// Emit a list of group names.
 ///
-/// This creates a long string which by itself contains a list of pascal style
-/// strings, which consist of a length byte directly followed by the string.
-///
-/// \code
-///   static const char DiagGroupNames[] = {
-/// \000\020#pragma-messages\t#warnings\020CFString-literal"
-///   };
-/// \endcode
+/// This creates an `llvm::StringTable` of all the diagnostic group names.
 static void emitDiagGroupNames(const StringToOffsetTable &GroupNames,
raw_ostream &OS) {
-  OS << "static const char DiagGroupNames[] = {\n";
-  GroupNames.EmitString(OS);
-  OS << "};\n\n";
+  GroupNames.EmitStringLiteralDef(
+  OS, "static constexpr llvm::StringTable DiagGroupNames");
+  OS << "\n";
 }
 
 /// Emit diagnostic arrays and related data structures.
@@ -1806,7 +1799,7 @@ static void emitDiagGroupNames(const StringToOffsetTable 
&GroupNames,
 ///  #ifdef GET_DIAG_ARRAYS
 /// static const int16_t DiagArrays[];
 /// static const int16_t DiagSubGroups[];
-/// static const char DiagGroupNames[];
+

[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Jason Rice via cfe-commits

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Jason Rice via cfe-commits

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Jason Rice via cfe-commits

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


[clang] [llvm] [IR] Don't set strictfp on irrelevant calls (PR #122735)

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

andykaylor wrote:

What's the motivation for this change? Was the strictfp attribute blocking some 
optimization?

My understanding of the attribute is that it only indicates that strict 
floating-point semantics are (potentially?) required at the call site. It 
doesn't indicate that the called function does access the floating-point 
environment.

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


[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)

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


@@ -0,0 +1,22 @@
+; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s 
-o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s 
-o /dev/null 2>&1 | FileCheck %s
+; RUN: not %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o 
/dev/null 2>&1 -filetype=obj %}
+; RUN: not %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o 
/dev/null 2>&1 -filetype=obj %}
+
+; CHECK: LLVM ERROR: Intrinsic selection not supported for this instruction 
set: %{{.*}} = G_INTRINSIC intrinsic(@llvm.spv.reflect), %{{.*}}, %{{.*}}

farzonl wrote:

This is my bad now that I'm seeing it  the lannguage is a bit obtuse and it 
doesn't look like instruction is encoded. We should simplify this error message.

Maybe:
```suggestion
; CHECK: LLVM ERROR: %{{.*}} = G_INTRINSIC intrinsic(@llvm.spv.reflect), % is 
only supported for GL instructions.
```
Or if you have something better go with that.

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


[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)

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

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


[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)

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


@@ -0,0 +1,22 @@
+; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s 
-o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s 
-o /dev/null 2>&1 | FileCheck %s
+; RUN: not %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o 
/dev/null 2>&1 -filetype=obj %}
+; RUN: not %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o 
/dev/null 2>&1 -filetype=obj %}
+
+; CHECK: LLVM ERROR: Intrinsic selection not supported for this instruction 
set: %{{.*}} = G_INTRINSIC intrinsic(@llvm.spv.reflect), %{{.*}}, %{{.*}}
+
+define noundef <4 x half> @reflect_half4(<4 x half> noundef %a, <4 x half> 
noundef %b) {
+entry:
+  %spv.reflect = call <4 x half> @llvm.spv.reflect.f16(<4 x half> %a, <4 x 
half> %b)
+  ret <4 x half> %spv.reflect
+}
+
+define noundef <4 x float> @reflect_float4(<4 x float> noundef %a, <4 x float> 
noundef %b) {
+entry:
+  %spv.reflect = call <4 x float> @llvm.spv.reflect.f32(<4 x float> %a, <4 x 
float> %b)

farzonl wrote:

This function will never be evaluated. The `report_fatal_error` means we stop 
codegen after line 10. Please delete.

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


[clang] [llvm] [StrTable] Switch diag group names to `llvm::StringTable` (PR #123302)

2025-01-17 Thread Chandler Carruth via cfe-commits


@@ -51,6 +53,14 @@ class StringTable {
 constexpr Offset() = default;
 constexpr Offset(unsigned Value) : Value(Value) {}
 
+constexpr bool operator==(const Offset &RHS) const {

chandlerc wrote:

Doh, done. Forgot to go back to this after the iterator facade wanted a member 
`==`.

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


[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)

2025-01-17 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 22d4ff155aadf0f098dd5dc48d9038da15108937 
782e1a28d4f8ddbeb92a9c57b3f071ba837ce129 --extensions h,cpp,c -- 
clang/test/CodeGenSPIRV/Builtins/reflect.c 
clang/test/SemaSPIRV/BuiltIns/reflect-errors.c clang/lib/CodeGen/CGBuiltin.cpp 
clang/lib/Headers/hlsl/hlsl_detail.h clang/lib/Headers/hlsl/hlsl_intrinsics.h 
clang/lib/Sema/SemaSPIRV.cpp llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp 
b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 960c51e952..720494e45d 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -3032,11 +3032,13 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register 
ResVReg,
   case Intrinsic::spv_normalize:
 return selectExtInst(ResVReg, ResType, I, CL::normalize, GL::Normalize);
   case Intrinsic::spv_reflect:
-if 
(!STI.canUseExtInstSet(SPIRV::InstructionSet::InstructionSet::GLSL_std_450)) {
+if (!STI.canUseExtInstSet(
+SPIRV::InstructionSet::InstructionSet::GLSL_std_450)) {
   std::string DiagMsg;
   raw_string_ostream OS(DiagMsg);
   I.print(OS);
-  DiagMsg = "Intrinsic selection not supported for this instruction set: " 
+ DiagMsg;
+  DiagMsg = "Intrinsic selection not supported for this instruction set: " 
+
+DiagMsg;
   report_fatal_error(DiagMsg.c_str(), false);
 }
 return selectExtInst(ResVReg, ResType, I, GL::Reflect);

``




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


[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)

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


@@ -3030,6 +3031,15 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register 
ResVReg,
 return selectExtInst(ResVReg, ResType, I, CL::fract, GL::Fract);
   case Intrinsic::spv_normalize:
 return selectExtInst(ResVReg, ResType, I, CL::normalize, GL::Normalize);
+  case Intrinsic::spv_reflect:
+if 
(!STI.canUseExtInstSet(SPIRV::InstructionSet::InstructionSet::GLSL_std_450)) {

farzonl wrote:

I was hoping to put this conditional in the GL overloaded version of 
selectExtInst so that other GL only extention instructions could benefit.

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


[clang] [HIP] Move HIP to the new driver by default (PR #123359)

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

jhuber6 wrote:

I somehow totally forgot that I implemented surfaces and textures, it was 
`managed` that I was having problems with.

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


[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)

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


@@ -0,0 +1,32 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+
+// RUN: %clang_cc1 -O1 -triple spirv-pc-vulkan-compute %s -emit-llvm -o - | 
FileCheck %s

farzonl wrote:

The clang codgen tests should be sufficient. Thats one of the advantages of 
moving the intrinsics into the header. 

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


[clang] [llvm] [SPIRV] add pre legalization instruction combine (PR #122839)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building 
`clang,llvm` at step 6 "test-openmp".

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


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

```
Step 6 (test-openmp) failure: test (failure)
 TEST 'libomp :: tasking/issue-94260-2.c' FAILED 

Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp   -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test
 -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -fno-omit-frame-pointer -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/ompt
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic && 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test
 -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -fno-omit-frame-pointer -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/ompt
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--




```



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


[clang] [HIP] Move HIP to the new driver by default (PR #123359)

2025-01-17 Thread via cfe-commits

b-sumner wrote:

> For now, it's probably easier just to put some indirection in this and pass a 
> struct to the first argument.

It would be even easier to not make the move.  Does "addr" have different 
meanings in each context where an offload_entry is used?  Is this going to 
confuse the debugger?



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


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

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

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

>From ef0f3551dbb3ce61c57a5ad044d86b504c7742e0 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 10 Sep 2024 02:35:43 +0300
Subject: [PATCH 1/7] [Clang] restrict use of attribute names reserved by the
 C++ standard

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 .../include/clang/Basic/AttributeCommonInfo.h |  2 +-
 clang/include/clang/Basic/CMakeLists.txt  |  5 +++
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../include/clang/Basic/DiagnosticLexKinds.td |  2 ++
 clang/include/clang/Lex/Preprocessor.h| 10 +++---
 clang/include/clang/Sema/CMakeLists.txt   |  5 ---
 clang/lib/Lex/PPDirectives.cpp| 26 +-
 .../Preprocessor/macro-reserved-attrs1.cpp| 34 +++
 .../Preprocessor/macro-reserved-attrs2.cpp| 34 +++
 .../gn/secondary/clang/lib/Basic/BUILD.gn |  5 +--
 .../gn/secondary/clang/lib/Sema/BUILD.gn  |  2 +-
 .../llvm-project-overlay/clang/BUILD.bazel|  9 +++--
 13 files changed, 115 insertions(+), 22 deletions(-)
 create mode 100644 clang/test/Preprocessor/macro-reserved-attrs1.cpp
 create mode 100644 clang/test/Preprocessor/macro-reserved-attrs2.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 61aa955ca9b9d4..09a0e46014476a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -788,6 +788,8 @@ Improvements to Clang's diagnostics
   require(scope); // Warning!  Requires mu1.
 }
 
+- Clang now diagnoses the use of attribute names reserved by the C++ standard 
(#GH92196).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 11c64547721739..4fee781fb9c5a1 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -61,7 +61,7 @@ class AttributeCommonInfo {
   };
   enum Kind {
 #define PARSED_ATTR(NAME) AT_##NAME,
-#include "clang/Sema/AttrParsedAttrList.inc"
+#include "clang/Basic/AttrParsedAttrList.inc"
 #undef PARSED_ATTR
 NoSemaHandlerAttribute,
 IgnoredAttribute,
diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 897a610b7f9089..f4843189348b8d 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -31,6 +31,11 @@ clang_tablegen(AttrList.inc -gen-clang-attr-list
   SOURCE Attr.td
   TARGET ClangAttrList)
 
+clang_tablegen(AttrParsedAttrList.inc -gen-clang-attr-parsed-attr-list
+  -I ${CMAKE_CURRENT_SOURCE_DIR}/../../
+  SOURCE Attr.td
+  TARGET ClangAttrParsedAttrList)
+
 clang_tablegen(AttrSubMatchRulesList.inc 
-gen-clang-attr-subject-match-rule-list
   -I ${CMAKE_CURRENT_SOURCE_DIR}/../../
   SOURCE Attr.td
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index b0ad76026fdb35..14d85696cc0089 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -760,6 +760,7 @@ def AmbiguousMacro : DiagGroup<"ambiguous-macro">;
 def KeywordAsMacro : DiagGroup<"keyword-macro">;
 def ReservedIdAsMacro : DiagGroup<"reserved-macro-identifier">;
 def ReservedIdAsMacroAlias : DiagGroup<"reserved-id-macro", 
[ReservedIdAsMacro]>;
+def ReservedAttributeIdentifier : DiagGroup<"reserved-attribute-identifier">;
 def RestrictExpansionMacro : DiagGroup<"restrict-expansion">;
 def FinalMacro : DiagGroup<"final-macro">;
 
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 959376b0847216..9b28e28f59506d 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -407,6 +407,8 @@ def warn_pp_macro_hides_keyword : Extension<
 def warn_pp_macro_is_reserved_id : Warning<
   "macro name is a reserved identifier">, DefaultIgnore,
   InGroup;
+def warn_pp_macro_is_reserved_attribute_id : Warning<
+  "%0 is a reserved attribute identifier">, 
InGroup;
 def warn_pp_objc_macro_redef_ignored : Warning<
   "ignoring redefinition of Objective-C qualifier macro">,
   InGroup>;
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 3d223c345ea156..8ddc5b56eedbd4 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2271,6 +2271,11 @@ class Preprocessor {
 }
   }
 
+  /// Determine whether the next preprocessor token to be
+  /// lexed is a '('.  If so, consume the token and return true, if not, this
+  /// method should have no observable side-effect on the lexed tokens.
+  bool isNextPPTokenLParen();
+
 private:
   /// Identifiers used for SEH handling in Borland. These are only
   /// allowed in particular circumstances
@@ -2648,11 +2653,6

[clang] [NFC] Avoid potential nullptr deref by using castAs<> (PR #123395)

2025-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: None (schittir)


Changes

Use castAs<> instead of getAs<>

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+4-4) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2385f2a320b625..d87528c432a360 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19297,9 +19297,9 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 assert(T0->isVectorTy() && T1->isVectorTy() &&
"Dot product of vector and scalar is not supported.");
 
-auto *VecTy0 = E->getArg(0)->getType()->getAs();
+auto *VecTy0 = E->getArg(0)->getType()->castAs();
 [[maybe_unused]] auto *VecTy1 =
-E->getArg(1)->getType()->getAs();
+E->getArg(1)->getType()->castAs();
 
 assert(VecTy0->getElementType() == VecTy1->getElementType() &&
"Dot product of vectors need the same element types.");
@@ -19392,7 +19392,7 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 llvm::Type *Xty = Op0->getType();
 llvm::Type *retType = llvm::Type::getInt1Ty(this->getLLVMContext());
 if (Xty->isVectorTy()) {
-  auto *XVecTy = E->getArg(0)->getType()->getAs();
+  auto *XVecTy = E->getArg(0)->getType()->castAs();
   retType = llvm::VectorType::get(
   retType, ElementCount::getFixed(XVecTy->getNumElements()));
 }
@@ -19578,7 +19578,7 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 llvm::Type *Xty = Op0->getType();
 llvm::Type *retType = llvm::Type::getInt32Ty(this->getLLVMContext());
 if (Xty->isVectorTy()) {
-  auto *XVecTy = Arg0->getType()->getAs();
+  auto *XVecTy = Arg0->getType()->castAs();
   retType = llvm::VectorType::get(
   retType, ElementCount::getFixed(XVecTy->getNumElements()));
 }

``




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


[clang] [NFC] Avoid potential nullptr deref by using castAs<> (PR #123395)

2025-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (schittir)


Changes

Use castAs<> instead of getAs<>

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+4-4) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2385f2a320b625..d87528c432a360 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19297,9 +19297,9 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 assert(T0->isVectorTy() && T1->isVectorTy() &&
"Dot product of vector and scalar is not supported.");
 
-auto *VecTy0 = E->getArg(0)->getType()->getAs();
+auto *VecTy0 = E->getArg(0)->getType()->castAs();
 [[maybe_unused]] auto *VecTy1 =
-E->getArg(1)->getType()->getAs();
+E->getArg(1)->getType()->castAs();
 
 assert(VecTy0->getElementType() == VecTy1->getElementType() &&
"Dot product of vectors need the same element types.");
@@ -19392,7 +19392,7 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 llvm::Type *Xty = Op0->getType();
 llvm::Type *retType = llvm::Type::getInt1Ty(this->getLLVMContext());
 if (Xty->isVectorTy()) {
-  auto *XVecTy = E->getArg(0)->getType()->getAs();
+  auto *XVecTy = E->getArg(0)->getType()->castAs();
   retType = llvm::VectorType::get(
   retType, ElementCount::getFixed(XVecTy->getNumElements()));
 }
@@ -19578,7 +19578,7 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 llvm::Type *Xty = Op0->getType();
 llvm::Type *retType = llvm::Type::getInt32Ty(this->getLLVMContext());
 if (Xty->isVectorTy()) {
-  auto *XVecTy = Arg0->getType()->getAs();
+  auto *XVecTy = Arg0->getType()->castAs();
   retType = llvm::VectorType::get(
   retType, ElementCount::getFixed(XVecTy->getNumElements()));
 }

``




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


[clang] [NFC] Avoid potential nullptr deref by using castAs<> (PR #123395)

2025-01-17 Thread via cfe-commits

https://github.com/schittir created 
https://github.com/llvm/llvm-project/pull/123395

Use castAs<> instead of getAs<>

>From f689f19bdb7db00e6adc0db25e407e20c9c7e695 Mon Sep 17 00:00:00 2001
From: Sindhu Chittireddy 
Date: Fri, 17 Jan 2025 12:52:39 -0800
Subject: [PATCH] [NFC] Avoid potential nullptr deref by using castAs<>

Use castAs<> instead of getAs<>
---
 clang/lib/CodeGen/CGBuiltin.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2385f2a320b625..d87528c432a360 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19297,9 +19297,9 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 assert(T0->isVectorTy() && T1->isVectorTy() &&
"Dot product of vector and scalar is not supported.");
 
-auto *VecTy0 = E->getArg(0)->getType()->getAs();
+auto *VecTy0 = E->getArg(0)->getType()->castAs();
 [[maybe_unused]] auto *VecTy1 =
-E->getArg(1)->getType()->getAs();
+E->getArg(1)->getType()->castAs();
 
 assert(VecTy0->getElementType() == VecTy1->getElementType() &&
"Dot product of vectors need the same element types.");
@@ -19392,7 +19392,7 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 llvm::Type *Xty = Op0->getType();
 llvm::Type *retType = llvm::Type::getInt1Ty(this->getLLVMContext());
 if (Xty->isVectorTy()) {
-  auto *XVecTy = E->getArg(0)->getType()->getAs();
+  auto *XVecTy = E->getArg(0)->getType()->castAs();
   retType = llvm::VectorType::get(
   retType, ElementCount::getFixed(XVecTy->getNumElements()));
 }
@@ -19578,7 +19578,7 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 llvm::Type *Xty = Op0->getType();
 llvm::Type *retType = llvm::Type::getInt32Ty(this->getLLVMContext());
 if (Xty->isVectorTy()) {
-  auto *XVecTy = Arg0->getType()->getAs();
+  auto *XVecTy = Arg0->getType()->castAs();
   retType = llvm::VectorType::get(
   retType, ElementCount::getFixed(XVecTy->getNumElements()));
 }

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


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

2025-01-17 Thread Jonas Paulsson via cfe-commits

JonPsson1 wrote:

> Both clear_cache and enable_execute_stack should just be empty no-op 
> functions on our platform.
ah - ok. I fixed clear_cache.c, and this also took care of the other test case 
which was calling it.


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


[clang] eddeb36 - [SPIRV] add pre legalization instruction combine (#122839)

2025-01-17 Thread via cfe-commits

Author: Farzon Lotfi
Date: 2025-01-17T14:46:14-05:00
New Revision: eddeb36cf1ced0e14e17ac90f60922366e382100

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

LOG: [SPIRV] add pre legalization instruction combine (#122839)

- Add the boilerplate to support instcombine in SPIRV
- instcombine length(X-Y) to distance(X,Y)
- switch HLSL's distance intrinsic to not special case for SPIRV.
- fixes #122766
- This RFC we were requested to add in the infra for pattern matching:
https://discourse.llvm.org/t/rfc-add-targetbuiltins-for-spirv-to-support-hlsl/83329/13

Added: 
clang/test/CodeGenSPIRV/Builtins/length.c
clang/test/SemaSPIRV/BuiltIns/length-errors.c
llvm/lib/Target/SPIRV/SPIRVCombine.td
llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp

llvm/test/CodeGen/SPIRV/GlobalISel/InstCombine/prelegalizercombiner-length-to-distance.mir

Modified: 
clang/include/clang/Basic/BuiltinsSPIRV.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/hlsl/hlsl_detail.h
clang/lib/Sema/SemaSPIRV.cpp
clang/test/CodeGenHLSL/builtins/distance.hlsl
clang/test/CodeGenHLSL/builtins/length.hlsl
llvm/lib/Target/SPIRV/CMakeLists.txt
llvm/lib/Target/SPIRV/SPIRV.h
llvm/lib/Target/SPIRV/SPIRV.td
llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp
llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/distance.ll
llvm/test/CodeGen/SPIRV/opencl/distance.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsSPIRV.td 
b/clang/include/clang/Basic/BuiltinsSPIRV.td
index 1e66939b822ef8..f72c555921dfe6 100644
--- a/clang/include/clang/Basic/BuiltinsSPIRV.td
+++ b/clang/include/clang/Basic/BuiltinsSPIRV.td
@@ -13,3 +13,9 @@ def SPIRVDistance : Builtin {
   let Attributes = [NoThrow, Const];
   let Prototype = "void(...)";
 }
+
+def SPIRVLength : Builtin {
+  let Spellings = ["__builtin_spirv_length"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2385f2a320b625..b80833fd91884d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20528,6 +20528,16 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_distance,
 ArrayRef{X, Y}, nullptr, "spv.distance");
   }
+  case SPIRV::BI__builtin_spirv_length: {
+Value *X = EmitScalarExpr(E->getArg(0));
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+   "length operand must have a float representation");
+assert(E->getArg(0)->getType()->isVectorType() &&
+   "length operand must be a vector");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_length,
+ArrayRef{X}, nullptr, "spv.length");
+  }
   }
   return nullptr;
 }

diff  --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 3eb4a3dc861e36..b2c8cc6c5c3dbb 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -61,7 +61,11 @@ length_impl(T X) {
 template 
 constexpr enable_if_t::value || is_same::value, T>
 length_vec_impl(vector X) {
+#if (__has_builtin(__builtin_spirv_length))
+  return __builtin_spirv_length(X);
+#else
   return __builtin_elementwise_sqrt(__builtin_hlsl_dot(X, X));
+#endif
 }
 
 template 
@@ -73,11 +77,7 @@ distance_impl(T X, T Y) {
 template 
 constexpr enable_if_t::value || is_same::value, T>
 distance_vec_impl(vector X, vector Y) {
-#if (__has_builtin(__builtin_spirv_distance))
-  return __builtin_spirv_distance(X, Y);
-#else
   return length_vec_impl(X - Y);
-#endif
 }
 } // namespace __detail
 } // namespace hlsl

diff  --git a/clang/lib/Sema/SemaSPIRV.cpp b/clang/lib/Sema/SemaSPIRV.cpp
index d2de64826c6eb3..dc49fc79073572 100644
--- a/clang/lib/Sema/SemaSPIRV.cpp
+++ b/clang/lib/Sema/SemaSPIRV.cpp
@@ -51,6 +51,24 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(unsigned 
BuiltinID,
 TheCall->setType(RetTy);
 break;
   }
+  case SPIRV::BI__builtin_spirv_length: {
+if (SemaRef.checkArgCount(TheCall, 1))
+  return true;
+ExprResult A = TheCall->getArg(0);
+QualType ArgTyA = A.get()->getType();
+auto *VTy = ArgTyA->getAs();
+if (VTy == nullptr) {
+  SemaRef.Diag(A.get()->getBeginLoc(),
+   diag::err_typecheck_convert_incompatible)
+  << ArgTyA
+  << SemaRef.Context.getVectorType(ArgTyA, 2, VectorKind::Generic) << 1
+  << 0 << 0;
+  return true;
+}
+QualType RetTy = VTy->getElementType();
+TheCall->setType(RetTy);
+break;
+  }
   }
   return false;
 }

diff  --git a/clang/test/CodeGenHLSL/builtins/di

[clang] [clang][C23] N3006 Underspecified object declarations (PR #79845)

2025-01-17 Thread Guillot Tony via cfe-commits

https://github.com/to268 updated https://github.com/llvm/llvm-project/pull/79845

>From 16328b43eac2ddd6fe999eac68e8ae07d040f54a Mon Sep 17 00:00:00 2001
From: Guillot Tony 
Date: Mon, 9 Dec 2024 01:46:40 +0100
Subject: [PATCH] N3006 base

---
 clang/docs/ReleaseNotes.rst   |  3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/lib/Sema/SemaExpr.cpp   | 34 +-
 clang/test/C/C23/n3006.c  | 66 +++
 clang/test/Parser/c23-underspecified-decls.c  | 12 
 clang/www/c_status.html   |  2 +-
 6 files changed, 114 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/C/C23/n3006.c
 create mode 100644 clang/test/Parser/c23-underspecified-decls.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index aa1c02d04f7caa..ba727240998aec 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -423,6 +423,7 @@ C23 Feature Support
 - Clang now officially supports `N3030 
`_ Enhancements to 
Enumerations. Clang already supported it as an extension, so there were no 
changes to compiler behavior.
 - Fixed the value of ``BOOL_WIDTH`` in  to return ``1``
   explicitly, as mandated by the standard. Fixes #GH117348
+- Clang now supports `N3006 
`_ Underspecified 
object declarations.
 
 Non-comprehensive list of changes in this release
 -
@@ -717,7 +718,7 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses dangling references for C++20's parenthesized aggregate 
initialization (#101957).
 
-- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings 
when an unrelated class 
+- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings 
when an unrelated class
   defined a defaulted comparison operator (#GH116270).
 
   .. code-block:: c++
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index db54312ad965e8..1fea7c1814a881 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7901,6 +7901,8 @@ def err_attribute_arm_mve_polymorphism : Error<
   "'__clang_arm_mve_strict_polymorphism' attribute can only be applied to an 
MVE/NEON vector type">;
 def err_attribute_webassembly_funcref : Error<
   "'__funcref' attribute can only be applied to a function pointer type">;
+def err_c23_underspecified_object_declaration: Error<
+  "'%select{struct||union||enum}0 %1' is defined as an 
underspecified object initializer">;
 
 def warn_setter_getter_impl_required : Warning<
   "property %0 requires method %1 to be defined - "
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ae40895980d90a..c70603ce9ff246 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7087,10 +7087,38 @@ Sema::BuildCompoundLiteralExpr(SourceLocation 
LParenLoc, TypeSourceInfo *TInfo,
diagID))
 return ExprError();
 }
+  } else if (LangOpts.C23 &&
+ (literalType->isRecordType() || literalType->isEnumeralType())) {
+// C23 6.2.1p7: Structure, union, and enumeration tags have scope that
+// begins just after the appearance of the tag in a type specifier that
+// declares the tag.
+// [...]
+// An ordinary identifier that has an underspecified definition has scope
+// that starts when the definition is completed; if the same ordinary
+// identifier declares another entity with a scope that encloses the 
current
+// block, that declaration is hidden as soon as the inner declarator is
+// completed*.)
+// [...]
+// *) That means, that the outer declaration is not visible for the
+// initializer.
+auto Range = SourceRange(LParenLoc, RParenLoc);
+const auto *Tag = literalType->castAs();
+const auto &TagRange = Tag->getDecl()->getSourceRange();
+
+// We should diagnose underspecified declaration, unless the identifier has
+// been diagnosed as being a redefinition, since the tag is made anonymous.
+if (Range.fullyContains(TagRange) && Tag->getDecl()->getIdentifier()) {
+  Diag(TagRange.getBegin(), 
diag::err_c23_underspecified_object_declaration)
+  << (unsigned)Tag->getDecl()->getTagKind() << 
Tag->getDecl()->getName()
+  << TagRange;
+  return ExprError();
+}
   } else if (!literalType->isDependentType() &&
- RequireCompleteType(LParenLoc, literalType,
-   diag::err_typecheck_decl_incomplete_type,
-   SourceRange(LParenLoc, LiteralExpr->getSourceRange().getEnd(
+ RequireCompleteType(
+ LParenLoc, literalType,
+ diag::err_typecheck_decl_incomplete_type,
+ SourceRa

[clang] [llvm] [SPIRV] add pre legalization instruction combine (PR #122839)

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

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2025-01-17 Thread Paul Kirth via cfe-commits

ilovepi wrote:

@PeterChou1 We're looking at using clang-doc's HTML output more seriously for 
Fuchsia's official documentation. If you don't have time to work on this I can 
devote some cycles to addressing the existing review comments and get this 
landed, so that we can use the new template output in clang-doc. Let me know if 
you plan to address this, otherwise, I'll probably start  updating the patch on 
Monday.

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


[clang] [HLSL] Fix global resource initialization (PR #123394)

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

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/123394

Create separate resource initialization function for each resource and add them 
to CodeGenModule's `CXXGlobalInits` list. fixes Fixes #120636 and addresses 
this [comment 
](https://github.com/llvm/llvm-project/pull/119755/files#r1894093603).

>From 1d04bfa8e1b138a13acf30c3fc46428d3b260569 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Fri, 17 Jan 2025 12:40:21 -0800
Subject: [PATCH] [HLSL] Fix global resource initialization

Fixes #120636
---
 clang/lib/CodeGen/CGDeclCXX.cpp   |   8 --
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 128 +-
 clang/lib/CodeGen/CGHLSLRuntime.h |   5 -
 clang/lib/CodeGen/CodeGenModule.h |   2 +
 .../ByteAddressBuffers-constructors.hlsl  |  26 ++--
 .../builtins/RWBuffer-constructor.hlsl|  15 +-
 .../StructuredBuffers-constructors.hlsl   |  51 ---
 clang/test/CodeGenHLSL/resource-bindings.hlsl |  15 +-
 8 files changed, 122 insertions(+), 128 deletions(-)

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 96517511b21114..1c2fecea1a6ac2 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -1131,14 +1131,6 @@ 
CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
   if (Decls[i])
 EmitRuntimeCall(Decls[i]);
 
-if (getLangOpts().HLSL) {
-  CGHLSLRuntime &CGHLSL = CGM.getHLSLRuntime();
-  if (CGHLSL.needsResourceBindingInitFn()) {
-llvm::Function *ResInitFn = CGHLSL.createResourceBindingInitFn();
-Builder.CreateCall(llvm::FunctionCallee(ResInitFn), {});
-  }
-}
-
 Scope.ForceCleanup();
 
 if (ExitBlock) {
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 5679bd71581795..c01416bcd36368 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -536,89 +536,83 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
   }
 }
 
-void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl *VD,
-  llvm::GlobalVariable *GV) {
-  // If the global variable has resource binding, add it to the list of globals
-  // that need resource binding initialization.
-  const HLSLResourceBindingAttr *RBA = VD->getAttr();
-  if (!RBA)
-return;
-
-  if (!HLSLAttributedResourceType::findHandleTypeOnResource(
-  VD->getType().getTypePtr()))
-// FIXME: Only simple declarations of resources are supported for now.
-// Arrays of resources or resources in user defined classes are
-// not implemented yet.
-return;
-
-  ResourcesToBind.emplace_back(VD, GV);
-}
-
-bool CGHLSLRuntime::needsResourceBindingInitFn() {
-  return !ResourcesToBind.empty();
+// Returns true if the record type is an HLSL resource class
+static bool isResourceRecordType(const clang::Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
 }
 
-llvm::Function *CGHLSLRuntime::createResourceBindingInitFn() {
-  // No resources to bind
-  assert(needsResourceBindingInitFn() && "no resources to bind");
-
+static void createResourceInitFn(CodeGenModule &CGM, const VarDecl *VD,
+ llvm::GlobalVariable *GV, unsigned Slot,
+ unsigned Space) {
   LLVMContext &Ctx = CGM.getLLVMContext();
   llvm::Type *Int1Ty = llvm::Type::getInt1Ty(Ctx);
 
-  llvm::Function *InitResBindingsFunc =
-  llvm::Function::Create(llvm::FunctionType::get(CGM.VoidTy, false),
- llvm::GlobalValue::InternalLinkage,
- "_init_resource_bindings", CGM.getModule());
+  llvm::Function *InitResFunc = llvm::Function::Create(
+  llvm::FunctionType::get(CGM.VoidTy, false),
+  llvm::GlobalValue::InternalLinkage,
+  ("_init_resource_" + VD->getName()).str(), CGM.getModule());
 
   llvm::BasicBlock *EntryBB =
-  llvm::BasicBlock::Create(Ctx, "entry", InitResBindingsFunc);
+  llvm::BasicBlock::Create(Ctx, "entry", InitResFunc);
   CGBuilderTy Builder(CGM, Ctx);
   const DataLayout &DL = CGM.getModule().getDataLayout();
   Builder.SetInsertPoint(EntryBB);
 
-  for (const auto &[VD, GV] : ResourcesToBind) {
-for (Attr *A : VD->getAttrs()) {
-  HLSLResourceBindingAttr *RBA = dyn_cast(A);
-  if (!RBA)
-continue;
-
-  const HLSLAttributedResourceType *AttrResType =
-  HLSLAttributedResourceType::findHandleTypeOnResource(
-  VD->getType().getTypePtr());
-
-  // FIXME: Only simple declarations of resources are supported for now.
-  // Arrays of resources or resources in user defined classes are
-  // not implemented yet.
-  assert(AttrResType != nullptr &&
- "Resource class must have a handle of 
HLSLAttributedResourceType");
-
-  llvm::Type *TargetTy =
-  CGM.getTargetCodeGenInfo().getHLSLType(CGM, AttrR

[clang] [HIP] Move HIP to the new driver by default (PR #123359)

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

jhuber6 wrote:

> > I'd like to avoid modifying this struct to avoid breaking ABI with OpenMP. 
> > Perhaps I should make `addr` a pointer to a struct and just GEP the two 
> > values.
> 
> Are we trying to jam a square HIP peg into a round OpenMP hole, or are we 
> truly wanting to move to a language neutral base? If the latter, why don't we 
> fix the base if it isn't sufficient?

At some point I wanted to update the struct to be more generic, but it was a 
surprising amount of work without breaking backward compatibility w/ the OpenMP 
runtime. Though honestly, I forget if we ever even guaranteed that kind of 
backward compatibility. Long term what I wanted is that instead of using 
`hip_offloading_entries` and `omp_offloading_entires` we'd just have 
`offloading_entries` as a section and each entry has a `kind` in it when we 
register them.

For now, it's probably easier just to put some indirection in this and pass a 
struct to the first argument.

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


[clang] 04383d6 - [Static analysis] Encodes a filename before inserting it into a URL. (#120810)

2025-01-17 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2025-01-17T13:31:56-08:00
New Revision: 04383d63130a72c1280d80ec3f5a09dfdf607462

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

LOG: [Static analysis] Encodes a filename before inserting it into a URL. 
(#120810)

This fixes a bug where report links generated from files such as
StylePrimitiveNumericTypes+Conversions.h in WebKit result in an error.

-

Co-authored-by: Brianna Fan 

Added: 


Modified: 
clang/tools/scan-build/bin/scan-build

Removed: 




diff  --git a/clang/tools/scan-build/bin/scan-build 
b/clang/tools/scan-build/bin/scan-build
index 37241c6d85c5b2..b90e635d31757b 100755
--- a/clang/tools/scan-build/bin/scan-build
+++ b/clang/tools/scan-build/bin/scan-build
@@ -820,7 +820,8 @@ ENDTEXT
   }
 
   # Emit the "View" link.
-  print OUT "View Report";
+  my $EncodedReport = URLEscape($ReportFile);
+  print OUT "View Report";
 
   # Emit REPORTBUG markers.
   print OUT "\n\n";
@@ -1465,6 +1466,16 @@ sub HtmlEscape {
   return $tmp;
 }
 
+####
+# URLEscape - encode characters that are special in URLs
+####
+
+sub URLEscape {
+  my $arg = shift || '';
+  $arg =~ s/\+/%2B/g;
+  return $arg;
+}
+
 
####
 # ShellEscape - backslash escape characters that are special to the shell
 
####



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


[clang] [Static analysis] Encodes a filename before inserting it into a URL. (PR #120810)

2025-01-17 Thread Ryosuke Niwa via cfe-commits

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Jason Rice via cfe-commits


@@ -15991,6 +15998,24 @@ 
TreeTransform::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
   return E;
 }
 
+template 
+ExprResult TreeTransform::TransformResolvedUnexpandedPackExpr(
+ResolvedUnexpandedPackExpr *E) {
+  bool ArgumentChanged = false;
+  SmallVector NewExprs;
+  if (TransformExprs(E->getExprs().begin(), E->getNumExprs(),
+ /*IsCall=*/false, NewExprs, &ArgumentChanged))
+return ExprError();
+
+  if (!AlwaysRebuild() && !ArgumentChanged)
+return E;
+
+  // NOTE: The type is just a superficial PackExpansionType
+  //   that needs no substitution.

ricejasonf wrote:

I am not sure I understand what you mean here. It is still an unexpanded pack 
that were are just rebuilding.

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Jason Rice via cfe-commits


@@ -1166,26 +1166,54 @@ 
TemplateDeclInstantiator::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
 
 Decl *TemplateDeclInstantiator::VisitBindingDecl(BindingDecl *D) {
   auto *NewBD = BindingDecl::Create(SemaRef.Context, Owner, D->getLocation(),
-D->getIdentifier());
+D->getIdentifier(), D->getType());
   NewBD->setReferenced(D->isReferenced());
   SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewBD);
+
   return NewBD;
 }
 
 Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) {
   // Transform the bindings first.
+  // The transformed DD will have all of the concrete BindingDecls.
   SmallVector NewBindings;
-  for (auto *OldBD : D->bindings())
+  ResolvedUnexpandedPackExpr *OldResolvedPack = nullptr;
+  for (auto *OldBD : D->bindings()) {
+Expr *BindingExpr = OldBD->getBinding();
+if (auto *RP = 
dyn_cast_if_present(BindingExpr))
+  OldResolvedPack = RP;

ricejasonf wrote:

The `isa` call would fail on a null type so I just left a 
comment.

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Jason Rice via cfe-commits


@@ -50,17 +50,29 @@ class CollectUnexpandedParameterPacksVisitor
 auto *FTD = FD ? FD->getDescribedFunctionTemplate() : nullptr;
 if (FTD && FTD->getTemplateParameters()->getDepth() >= DepthLimit)
   return;
-  } else if (getDepthAndIndex(ND).first >= DepthLimit)
+  } else if (auto *BD = dyn_cast(ND)) {
+Expr *E = BD->getBinding();
+if (auto *RP = dyn_cast_if_present(E)) {
+  addUnexpanded(RP);
+  return;
+}

ricejasonf wrote:

I changed it to `cast_if_present` since a dependent decomposition leaves the 
binding expr as nullptr.

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Jason Rice via cfe-commits


@@ -1166,26 +1166,54 @@ 
TemplateDeclInstantiator::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
 
 Decl *TemplateDeclInstantiator::VisitBindingDecl(BindingDecl *D) {
   auto *NewBD = BindingDecl::Create(SemaRef.Context, Owner, D->getLocation(),
-D->getIdentifier());
+D->getIdentifier(), D->getType());
   NewBD->setReferenced(D->isReferenced());
   SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewBD);
+
   return NewBD;
 }
 
 Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) {
   // Transform the bindings first.
+  // The transformed DD will have all of the concrete BindingDecls.
   SmallVector NewBindings;
-  for (auto *OldBD : D->bindings())
+  ResolvedUnexpandedPackExpr *OldResolvedPack = nullptr;
+  for (auto *OldBD : D->bindings()) {
+Expr *BindingExpr = OldBD->getBinding();
+if (auto *RP = 
dyn_cast_if_present(BindingExpr))
+  OldResolvedPack = RP;
 NewBindings.push_back(cast(VisitBindingDecl(OldBD)));
+  }
   ArrayRef NewBindingArray = NewBindings;
 
-  auto *NewDD = cast_or_null(
+  auto *NewDD = cast_if_present(
   VisitVarDecl(D, /*InstantiatingVarTemplate=*/false, &NewBindingArray));
 
   if (!NewDD || NewDD->isInvalidDecl())
 for (auto *NewBD : NewBindings)
   NewBD->setInvalidDecl();
 
+  if (OldResolvedPack) {
+// Mark the holding vars (if any) in the pack as instantiated since
+// they are created implicitly.
+auto Bindings = NewDD->bindings();
+auto BPack = std::find_if(
+Bindings.begin(), Bindings.end(),
+[](BindingDecl *D) -> bool { return D->isParameterPack(); });
+auto *NewResolvedPack =
+cast((*BPack)->getBinding());
+auto OldExprs = OldResolvedPack->getExprs();
+auto NewExprs = NewResolvedPack->getExprs();

ricejasonf wrote:

added

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-17 Thread Jason Rice via cfe-commits


@@ -757,23 +775,40 @@ bool Sema::CheckParameterPacksForExpansion(
   bool HaveFirstPack = false;
   std::optional NumPartialExpansions;
   SourceLocation PartiallySubstitutedPackLoc;
+  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
 
   for (UnexpandedParameterPack ParmPack : Unexpanded) {
 // Compute the depth and index for this parameter pack.
 unsigned Depth = 0, Index = 0;
 IdentifierInfo *Name;
 bool IsVarDeclPack = false;
+ResolvedUnexpandedPackExpr *ResolvedPack = nullptr;
 
 if (const TemplateTypeParmType *TTP =
 ParmPack.first.dyn_cast()) {
   Depth = TTP->getDepth();
   Index = TTP->getIndex();
   Name = TTP->getIdentifier();
+} else if (auto *RP =
+   ParmPack.first.dyn_cast()) {
+  ResolvedPack = RP;
 } else {
   NamedDecl *ND = cast(ParmPack.first);
   if (isa(ND))
 IsVarDeclPack = true;
-  else
+  else if (isa(ND)) {
+// Find the instantiated BindingDecl and check it for a resolved pack.
+llvm::PointerUnion *Instantiation =
+CurrentInstantiationScope->findInstantiationOf(ND);
+Decl *B = cast(*Instantiation);
+Expr *BindingExpr = cast(B)->getBinding();
+ResolvedPack =
+dyn_cast_if_present(BindingExpr);
+if (!ResolvedPack) {
+  ShouldExpand = false;
+  continue;
+}

ricejasonf wrote:

This case is definitely reached. (I tried it.) I think I could make this 
`cast_if_present`.

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


  1   2   3   4   >