[clang] [Clang][diagnostics] Fix structured binding shadows template param loc (PR #129116)

2025-02-28 Thread Amr Hesham via cfe-commits


@@ -162,3 +162,10 @@ struct A {
 };
 A<0>::B a;
 }
+
+template  void shadow() {  // expected-note{{template parameter is 
declared here}}

AmrDeveloper wrote:

You mean something like 'template  void shadow2() { ... }` or creating a 
sample with function call

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


[clang] [Clang][diagnostics] Fix structured binding shadows template param loc (PR #129116)

2025-02-28 Thread Amr Hesham via cfe-commits

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

>From ed0cf3f026e439288f8334f27555ad26825fd56a Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Thu, 27 Feb 2025 21:49:32 +0100
Subject: [PATCH 1/3] [Clang][diagnostics] Fix structured binding shadows
 template parameter location

---
 clang/lib/Sema/SemaDeclCXX.cpp | 3 +--
 clang/test/CXX/temp/temp.res/temp.local/p6.cpp | 5 +
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 664d48ccbc382..a3a028b9485d6 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -883,8 +883,7 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator &D,
 // It's not permitted to shadow a template parameter name.
 if (Previous.isSingleResult() &&
 Previous.getFoundDecl()->isTemplateParameter()) {
-  DiagnoseTemplateParameterShadow(D.getIdentifierLoc(),
-  Previous.getFoundDecl());
+  DiagnoseTemplateParameterShadow(B.NameLoc, Previous.getFoundDecl());
   Previous.clear();
 }
 
diff --git a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
index 00bb35813c39a..e464bb5e7eaef 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
@@ -162,3 +162,8 @@ struct A {
 };
 A<0>::B a;
 }
+
+template  void shadow9() {  // expected-note{{template parameter 
is declared here}}
+  using arr = int[1]; // expected-warning@+1 {{decomposition declarations are 
a C++17 extension}}
+  auto [T] = arr{}; // expected-error {{declaration of 'T' shadows template 
parameter}}
+}

>From 7712fc1c2406974d64e6fa8c162d12b6090903f2 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Fri, 28 Feb 2025 18:43:54 +0100
Subject: [PATCH 2/3] Add release note and improve testing

---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/test/CXX/temp/temp.res/temp.local/p6.cpp | 6 --
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2b72143482943..b1ea63a01b914 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -214,6 +214,8 @@ Improvements to Clang's diagnostics
   :doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
   feature will be default-enabled with ``-Wthread-safety`` in a future release.
 
+- Improve the diagnostics for shadows template parameter.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
index e464bb5e7eaef..aa00e1b8811ec 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
@@ -163,7 +163,9 @@ struct A {
 A<0>::B a;
 }
 
-template  void shadow9() {  // expected-note{{template parameter 
is declared here}}
+template  void shadow() {  // expected-note{{template parameter is 
declared here}}
   using arr = int[1]; // expected-warning@+1 {{decomposition declarations are 
a C++17 extension}}
-  auto [T] = arr{}; // expected-error {{declaration of 'T' shadows template 
parameter}}
+  auto [
+T // expected-error {{declaration of 'T' shadows template parameter}}
+] = arr{};
 }

>From 780a3b259283834e72dccd1ac34cbeafb0a301d9 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Fri, 28 Feb 2025 19:38:21 +0100
Subject: [PATCH 3/3] Address code review comments

---
 clang/docs/ReleaseNotes.rst| 2 +-
 clang/test/CXX/temp/temp.res/temp.local/p6.cpp | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b1ea63a01b914..6c9eacbb0751d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -214,7 +214,7 @@ Improvements to Clang's diagnostics
   :doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
   feature will be default-enabled with ``-Wthread-safety`` in a future release.
 
-- Improve the diagnostics for shadows template parameter.
+- Improve the diagnostics for shadows template parameter to report correct 
location (#GH129060).
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
index aa00e1b8811ec..ee23bf103d450 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
@@ -164,7 +164,8 @@ A<0>::B a;
 }
 
 template  void shadow() {  // expected-note{{template parameter is 
declared here}}
-  using arr = int[1]; // expected-warning@+1 {{decomposition declarations are 
a C++17 extension}}
+  using arr = int[1];
+  // expected-warning@+1 {{decomposition declarations are a C++17 extension}}
   auto [
 T // expected-err

[clang] [HLSL] Add additional overloads for min and max to allow for mixed scalar and vector arguments (PR #129334)

2025-02-28 Thread Joshua Batista via cfe-commits


@@ -131,3 +157,9 @@ double3 test_min_double3(double3 p0, double3 p1) { return 
min(p0, p1); }
 // CHECK-LABEL: define noundef nofpclass(nan inf) <4 x double> 
@_Z16test_min_double4
 // CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.minnum.v4f64
 double4 test_min_double4(double4 p0, double4 p1) { return min(p0, p1); }
+// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x double> 
{{.*}}test_min_double4_mismatch
+// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.minnum.v4f64
+double4 test_min_double4_mismatch(double4 p0, double p1) { return min(p0, p1); 
}
+// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x double> 
{{.*}}test_min_double4_mismatch2
+// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.minnum.v4f64
+double4 test_min_double4_mismatch2(double4 p0, double p1) { return min(p1, 
p0); }

bob80905 wrote:

Shouldn't this parameter swap test be applicable to all the rest of the tests? 
Why just double?

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


[clang] [llvm] [clang][CodeGen][AA] Add `!llvm.errno.tbaa` gathering int-compatible TBAA nodes (PR #125258)

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

nikic wrote:

> > > so IIUC !llvm.errno.tbaa should just be a module-level list of 
> > > int-compatible TBAA nodes.
> > 
> > 
> > Yes, exactly. It should be a module level MD node, not on individual 
> > instructions.
> 
> Thank you, I'm updating this. I've been contemplating this, and thought 
> originally we needed to extend TBAA (like aliasErrno as per tmp commit, 
> provided it is correct), but TBAA seems to take care of this already (as 
> clang propagates int TBAA correctly to the call), so I think this shouldn't 
> be needed.

The fact that clang currently places TBAA on FP libcalls is a hack that we want 
to remove. It doesn't work for libcalls that also access other memory.


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


[clang] [HLSL] Add additional overloads for min and max to allow for mixed scalar and vector arguments (PR #129334)

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


@@ -131,3 +157,9 @@ double3 test_min_double3(double3 p0, double3 p1) { return 
min(p0, p1); }
 // CHECK-LABEL: define noundef nofpclass(nan inf) <4 x double> 
@_Z16test_min_double4
 // CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.minnum.v4f64
 double4 test_min_double4(double4 p0, double4 p1) { return min(p0, p1); }
+// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x double> 
{{.*}}test_min_double4_mismatch
+// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.minnum.v4f64
+double4 test_min_double4_mismatch(double4 p0, double p1) { return min(p0, p1); 
}
+// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x double> 
{{.*}}test_min_double4_mismatch2
+// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.minnum.v4f64
+double4 test_min_double4_mismatch2(double4 p0, double p1) { return min(p1, 
p0); }

spall wrote:

Yes, I just didn't want to add tons of tests; I also didn't add a test for each 
size of vector, only the vec4s. I can add more tests if you think its 
important. 

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


[clang] [CUDA][HIP] fix virtual dtor host/device attr (PR #128926)

2025-02-28 Thread Artem Belevich via cfe-commits


@@ -32,22 +32,24 @@ public:
 template class B;
 }
 
-// The implicit host/device attrs of virtual dtor B::~B() is inferred to
-// have implicit device attr since dtors of its members and parent classes can
-// be executed on device. This causes a diagnostic since B::~B() must
-// be emitted, and it eventually causes host_fun() called on device side.
+// The implicit host/device attrs of virtual dtor ~B() should be
+// conservatively inferred, where constexpr member dtor's should
+// not be considered device since they may call host functions.
+// Therefore B::~B() should not have implicit device attr.
+// However C::~C() should have implicit device attr since
+// it is trivial.
 namespace ExplicitInstantiationDtorNoAttr {
-void host_fun() // dev-note {{'host_fun' declared here}}
+void host_fun()

Artem-B wrote:

Do I understand it correctly that the code is still expected to error out as a 
deferred diag at codegen phase? 

If so, it would be great to mention that in the comment, and, maybe, add a 
codegen case if it's not done already in the deferred diags part of the patch 
we split off.

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


[clang] [CUDA][HIP] fix virtual dtor host/device attr (PR #128926)

2025-02-28 Thread Artem Belevich via cfe-commits

https://github.com/Artem-B approved this pull request.


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


[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

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


@@ -218,12 +221,31 @@ mlir::LogicalResult 
CIRToLLVMGlobalOpLowering::matchAndRewrite(
   SmallVector attributes;
 
   if (init.has_value()) {
-GlobalInitAttrRewriter initRewriter(llvmType, rewriter);
-init = initRewriter.rewriteInitAttr(init.value());
-// If initRewriter returned a null attribute, init will have a value but
-// the value will be null. If that happens, initRewriter didn't handle the
-// attribute type. It probably needs to be added to GlobalInitAttrRewriter.
-if (!init.value()) {
+if (mlir::isa(init.value())) {

erichkeane wrote:

Ah, cool :D  I was beginning to think I was missing something, like another use 
of it!  I don't mind which you do (remove it and leave inline, or switch to the 
type).  There is a 'line' I suspect where 'leave inline' becomes too 
big/annoying and we want to move it, but we are far from it at the moment.

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


[clang] [HLSL] Add additional overloads for min and max to allow for mixed scalar and vector arguments (PR #129334)

2025-02-28 Thread Joshua Batista via cfe-commits

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

I can approve this, though it might be worth considering adding a macro at the 
top of hlsl_intrinsics.h, along with some of the other macros there, to shrink 
the change and possibly simplify future changes that need these types of sets 
of overloads.

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


[clang] [clang] Pass fp128 indirectly and return in xmm0 on Windows (PR #115052)

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

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


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


[clang] Reapply "[clang][HIP] Make some math not not work with AMDGCN SPIR-V #128360" (PR #129306)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-x86_64-debian-dylib` 
running on `gribozavr4` while building `clang` at step 7 
"test-build-unified-tree-check-llvm".

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


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

```
Step 7 (test-build-unified-tree-check-llvm) failure: test (failure)
 TEST 'LLVM :: 
tools/llvm-exegesis/RISCV/rvv/reduction.test' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /b/1/llvm-x86_64-debian-dylib/build/bin/llvm-exegesis 
-mtriple=riscv64 -mcpu=sifive-p670 -benchmark-phase=assemble-measured-code 
--mode=latency --opcode-name=PseudoVWREDSUMU_VS_M8_E32 --min-instructions=100 | 
/b/1/llvm-x86_64-debian-dylib/build/bin/FileCheck 
/b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/test/tools/llvm-exegesis/RISCV/rvv/reduction.test
+ /b/1/llvm-x86_64-debian-dylib/build/bin/FileCheck 
/b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/test/tools/llvm-exegesis/RISCV/rvv/reduction.test
+ /b/1/llvm-x86_64-debian-dylib/build/bin/llvm-exegesis -mtriple=riscv64 
-mcpu=sifive-p670 -benchmark-phase=assemble-measured-code --mode=latency 
--opcode-name=PseudoVWREDSUMU_VS_M8_E32 --min-instructions=100
/b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/test/tools/llvm-exegesis/RISCV/rvv/reduction.test:7:14:
 error: CHECK-NOT: excluded string found in input
# CHECK-NOT: V[[REG:[0-9]+]] V[[REG]] V{{[0-9]+}}M8 V[[REG]]
 ^
:5:31: note: found here
 - 'PseudoVWREDSUMU_VS_M8_E32 V7 V7 V0M8 V7 i_0x i_0x5 i_0x0'
  ^
:5:32: note: captured var "REG"
 - 'PseudoVWREDSUMU_VS_M8_E32 V7 V7 V0M8 V7 i_0x i_0x5 i_0x0'
   ^

Input file: 
Check file: 
/b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/test/tools/llvm-exegesis/RISCV/rvv/reduction.test

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

Input was:
<<
 1: --- 
 2: mode: latency 
 3: key: 
 4:  instructions: 
 5:  - 'PseudoVWREDSUMU_VS_M8_E32 V7 V7 V0M8 V7 i_0x 
i_0x5 i_0x0' 
not:7'0   ! 
   error: no match expected
not:7'1!
   captured var "REG"
 6:  config: 'vtype = {AVL: VLMAX, SEW: e32, Policy: tu/mu}' 
 7:  register_initial_values: 
 8:  - 'V7=0x0' 
 9:  - 'V0M8=0x0' 
10: cpu_name: sifive-p670 
 .
 .
 .
>>

--




```



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


[clang] [CIR] Upstream global variable linkage types (PR #129072)

2025-02-28 Thread Bruno Cardoso Lopes via cfe-commits


@@ -210,6 +223,193 @@ void CIRGenModule::emitGlobalDefinition(clang::GlobalDecl 
gd,
   llvm_unreachable("Invalid argument to CIRGenModule::emitGlobalDefinition");
 }
 
+static bool shouldBeInCOMDAT(CIRGenModule &cgm, const Decl &d) {
+  assert(!cir::MissingFeatures::supportComdat());
+
+  if (d.hasAttr())
+return true;
+
+  GVALinkage linkage;
+  if (auto *vd = dyn_cast(&d))
+linkage = cgm.getASTContext().GetGVALinkageForVariable(vd);
+  else
+linkage =
+cgm.getASTContext().GetGVALinkageForFunction(cast(&d));
+
+  switch (linkage) {
+  case clang::GVA_Internal:
+  case clang::GVA_AvailableExternally:
+  case clang::GVA_StrongExternal:
+return false;
+  case clang::GVA_DiscardableODR:
+  case clang::GVA_StrongODR:
+return true;
+  }
+  llvm_unreachable("No such linkage");
+}
+
+// TODO(CIR): this could be a common method between LLVM codegen.
+static bool isVarDeclStrongDefinition(const ASTContext &astContext,

bcardosolopes wrote:

I have annotated tons of these functions around, I think they resemble the idea 
of `ASTCodegenHelpers`, since they allow AST queries that have no dependency to 
codegen and are also useful to other tools (each these days implement their 
own). Not sure where exactly the implementation should live, but it would be 
nice if those can be exposed on a public header

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


[clang] [clang] Pass fp128 indirectly and return in xmm0 on Windows (PR #115052)

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

rnk wrote:

If you take the two PRs together, we're going to implement the indirection 
logic at both the frontend and backend level. If we do it in the backend, I 
think it's technically necessary to do it in the frontend, but it is consistent 
with how we handle all other types. I'd like to see that explained in the 
commit message: why should this be in the frontend as well?

To answer that question, there are tradeoffs, but it's generally good for 
memory optimizations to be able to observe ABI details. For example, the 
backend lowering creates extra stack objects if we need to pass the same fp128 
argument twice to two functions, whereas mid-level optimizations might be able 
to remove that.

Otherwise, I think this is good to go. I suppose Rust folks are watching this 
PR, otherwise, I'd say loop them in.

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


[clang] [llvm] [memprof] Export __memprof_default_options_str on Darwin (PR #128920)

2025-02-28 Thread Ellis Hoag via cfe-commits

https://github.com/ellishg updated 
https://github.com/llvm/llvm-project/pull/128920

>From 2e1946730f7ae2473a4fc94f8918eb3d9d225d17 Mon Sep 17 00:00:00 2001
From: Ellis Hoag 
Date: Wed, 26 Feb 2025 09:48:46 -0800
Subject: [PATCH 1/3] [memprof] Export __memprof_default_options_str on Darwin

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 4 
 clang/test/Driver/fmemprof.cpp | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 75f126965e0ac..a2aeef4c4c475 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1617,6 +1617,10 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 }
   }
 
+  if (Sanitize.needsMemProfRt())
+if (hasExportSymbolDirective(Args))
+  addExportedSymbol(CmdArgs, "___memprof_default_options_str");
+
   const XRayArgs &XRay = getXRayArgs();
   if (XRay.needsXRayRt()) {
 AddLinkRuntimeLib(Args, CmdArgs, "xray");
diff --git a/clang/test/Driver/fmemprof.cpp b/clang/test/Driver/fmemprof.cpp
index 5165c4452fd57..b464320e58a94 100644
--- a/clang/test/Driver/fmemprof.cpp
+++ b/clang/test/Driver/fmemprof.cpp
@@ -17,3 +17,11 @@
 
 // RUN: not %clangxx --target=x86_64-linux-gnu -fprofile-generate 
-fmemory-profile-use=foo %s -### 2>&1 | FileCheck %s 
--check-prefix=CONFLICTWITHPGOINSTR
 // CONFLICTWITHPGOINSTR: error: invalid argument '-fmemory-profile-use=foo' 
not allowed with '-fprofile-generate'
+
+// Test that we export the __memprof_default_options_str on Darwin because it 
has WeakAnyLinkage
+// RUN: %clangxx --target=arm64-apple-ios -fmemory-profile %s -### 2>&1 | 
FileCheck %s -check-prefix=EXPORT-BASE --implicit-check-not=exported_symbol
+// RUN: %clangxx --target=x86_64-linux-gnu -fmemory-profile %s -### 2>&1 | 
FileCheck %s -check-prefix=EXPORT-BASE --implicit-check-not=exported_symbol
+// RUN: %clangxx --target=arm64-apple-ios -fmemory-profile 
-exported_symbols_list /dev/null %s -### 2>&1 | FileCheck %s 
--check-prefixes=EXPORT-BASE,EXPORT
+// FIXME: Darwin needs to link in the runtime, then we can use the regular 
CHECK prefix
+// EXPORT-BASE: "-cc1" {{.*}} "-fmemory-profile"
+// EXPORT: "-exported_symbol" "___memprof_default_options_str"

>From f5b85a00fd2d148bbe552ab7916954d75236ef75 Mon Sep 17 00:00:00 2001
From: Ellis Hoag 
Date: Fri, 28 Feb 2025 09:01:00 -0800
Subject: [PATCH 2/3] Add helper functions and comment

---
 clang/lib/Driver/ToolChains/Darwin.cpp  |  5 -
 llvm/include/llvm/ProfileData/MemProf.h | 11 +++
 llvm/lib/Transforms/Instrumentation/MemProfiler.cpp |  7 +++
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index a2aeef4c4c475..e67997314da36 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -21,6 +21,7 @@
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/ProfileData/MemProf.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/Threading.h"
@@ -1619,7 +1620,9 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 
   if (Sanitize.needsMemProfRt())
 if (hasExportSymbolDirective(Args))
-  addExportedSymbol(CmdArgs, "___memprof_default_options_str");
+  addExportedSymbol(
+  CmdArgs,
+  llvm::memprof::getMemprofOptionsSymbolDarwinLinkageName().data());
 
   const XRayArgs &XRay = getXRayArgs();
   if (XRay.needsXRayRt()) {
diff --git a/llvm/include/llvm/ProfileData/MemProf.h 
b/llvm/include/llvm/ProfileData/MemProf.h
index da0cb47508e32..71e3faa506741 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -6,6 +6,7 @@
 #include "llvm/ADT/STLForwardCompat.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/ProfileData/MemProfData.inc"
 #include "llvm/Support/BLAKE3.h"
@@ -42,6 +43,16 @@ constexpr uint64_t MaximumSupportedVersion = Version3;
 // Verify that the minimum and maximum satisfy the obvious constraint.
 static_assert(MinimumSupportedVersion <= MaximumSupportedVersion);
 
+inline llvm::StringRef getMemprofOptionsSymbolDarwinLinkageName() {
+  return "___memprof_default_options_str";
+}
+
+inline llvm::StringRef getMemprofOptionsSymbolName() {
+  // Darwin linkage names are prefixed with an extra "_". See
+  // DataLayout::getGlobalPrefix().
+  return getMemprofOptionsSymbolDarwinLinkageName().drop_front();
+}
+
 enum class Meta : uint64_t {
   Start = 0,
 #define MIBEntryDef(NameTag, Name, Type) NameTag,
diff --git a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp 
b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
index 7d8bc3aa4c589..6f58a2315547a 100644
--- a/llvm/lib/Tran

[clang] [CIR] Upstream global variable linkage types (PR #129072)

2025-02-28 Thread Bruno Cardoso Lopes via cfe-commits


@@ -210,6 +223,193 @@ void CIRGenModule::emitGlobalDefinition(clang::GlobalDecl 
gd,
   llvm_unreachable("Invalid argument to CIRGenModule::emitGlobalDefinition");
 }
 
+static bool shouldBeInCOMDAT(CIRGenModule &cgm, const Decl &d) {
+  assert(!cir::MissingFeatures::supportComdat());
+
+  if (d.hasAttr())
+return true;
+
+  GVALinkage linkage;
+  if (auto *vd = dyn_cast(&d))
+linkage = cgm.getASTContext().GetGVALinkageForVariable(vd);
+  else
+linkage =
+cgm.getASTContext().GetGVALinkageForFunction(cast(&d));
+
+  switch (linkage) {
+  case clang::GVA_Internal:
+  case clang::GVA_AvailableExternally:
+  case clang::GVA_StrongExternal:
+return false;
+  case clang::GVA_DiscardableODR:
+  case clang::GVA_StrongODR:
+return true;
+  }
+  llvm_unreachable("No such linkage");
+}
+
+// TODO(CIR): this could be a common method between LLVM codegen.
+static bool isVarDeclStrongDefinition(const ASTContext &astContext,
+  CIRGenModule &cgm, const VarDecl *vd,
+  bool noCommon) {
+  // Don't give variables common linkage if -fno-common was specified unless it
+  // was overridden by a NoCommon attribute.
+  if ((noCommon || vd->hasAttr()) && !vd->hasAttr())
+return true;
+
+  // C11 6.9.2/2:
+  //   A declaration of an identifier for an object that has file scope without
+  //   an initializer, and without a storage-class specifier or with the
+  //   storage-class specifier static, constitutes a tentative definition.
+  if (vd->getInit() || vd->hasExternalStorage())
+return true;
+
+  // A variable cannot be both common and exist in a section.
+  if (vd->hasAttr())
+return true;
+
+  // A variable cannot be both common and exist in a section.
+  // We don't try to determine which is the right section in the front-end.
+  // If no specialized section name is applicable, it will resort to default.
+  if (vd->hasAttr() ||
+  vd->hasAttr() ||
+  vd->hasAttr() ||
+  vd->hasAttr())
+return true;
+
+  // Thread local vars aren't considered common linkage.
+  if (vd->getTLSKind())
+return true;
+
+  // Tentative definitions marked with WeakImportAttr are true definitions.
+  if (vd->hasAttr())
+return true;
+
+  // A variable cannot be both common and exist in a comdat.
+  if (shouldBeInCOMDAT(cgm, *vd))
+return true;
+
+  // Declarations with a required alignment do not have common linkage in MSVC
+  // mode.
+  if (astContext.getTargetInfo().getCXXABI().isMicrosoft()) {
+if (vd->hasAttr())
+  return true;
+QualType varType = vd->getType();
+if (astContext.isAlignmentRequired(varType))
+  return true;
+
+if (const auto *rt = varType->getAs()) {
+  const RecordDecl *rd = rt->getDecl();
+  for (const FieldDecl *fd : rd->fields()) {
+if (fd->isBitField())
+  continue;
+if (fd->hasAttr())
+  return true;
+if (astContext.isAlignmentRequired(fd->getType()))
+  return true;
+  }
+}
+  }
+
+  // Microsoft's link.exe doesn't support alignments greater than 32 bytes for
+  // common symbols, so symbols with greater alignment requirements cannot be
+  // common.
+  // Other COFF linkers (ld.bfd and LLD) support arbitrary power-of-two
+  // alignments for common symbols via the aligncomm directive, so this
+  // restriction only applies to MSVC environments.
+  if (astContext.getTargetInfo().getTriple().isKnownWindowsMSVCEnvironment() &&
+  astContext.getTypeAlignIfKnown(vd->getType()) >
+  astContext.toBits(CharUnits::fromQuantity(32)))
+return true;
+
+  return false;
+}
+
+cir::GlobalLinkageKind CIRGenModule::getCIRLinkageForDeclarator(

bcardosolopes wrote:

> this would require changes to the incubator and CodeGen first, as some 
> functions are private methods or rely on langOpts from CodeGen. So this is 
> more of a question for @erichkeane and @bcardosolopes—would this be feasible?

I'm not a big fan of depending on LLVM stuff at the CIR level, given we can get 
all info we need from the AST and even though it'd be a practical solution - my 
take is to keep that at the lowering level.

> This is likely a general policy question: how tightly should CodeGens be 
> coupled, and should we modify main CodeGen to better support API reuse for 
> CIRCodeGen? I expect many similar copies, independent of the actual CIR and 
> MLIR, to appear during upstreaming.

I believe reuse is always great, but IMO I don't think we need to generate 
extra work for upstreaming on anything other than things like a 
`ASTCodegenHelpers` atm.

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


[clang] [CIR] Upstream floating point literal expressions (PR #129304)

2025-02-28 Thread Bruno Cardoso Lopes via cfe-commits


@@ -57,3 +57,15 @@ bool boolfunc() { return true; }
 // CHECK:   %0 = cir.const #true
 // CHECK:   cir.return %0 : !cir.bool
 // CHECK: }
+
+float floatfunc() { return 42.42f; }
+// CHECK: cir.func @floatfunc() -> !cir.float {
+// CHECK:   %0 = cir.const #cir.fp<4.242000e+01> : !cir.float

bcardosolopes wrote:

> How consistent is CIR with literal representation across platforms?

We the same as MLIR LLVM dialect those (which is MLIR's own parsing/printing), 
we haven't tested much past AArch64 and x86_64 so not a lot of data to say much 
more - we haven't had issues so far though.

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


[clang] [CIR] Upstream floating point literal expressions (PR #129304)

2025-02-28 Thread Bruno Cardoso Lopes via cfe-commits

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


[clang] [HLSL] Add additional overloads for min and max to allow for mixed scalar and vector arguments (PR #129334)

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

https://github.com/spall updated 
https://github.com/llvm/llvm-project/pull/129334

>From ebaef38c40cba83d4b446a5320d57c86038f8286 Mon Sep 17 00:00:00 2001
From: Sarah Spall 
Date: Fri, 28 Feb 2025 11:18:03 -0800
Subject: [PATCH 1/3] new max overloads + new min overloads

---
 clang/lib/Headers/hlsl/hlsl_intrinsics.h | 360 +++
 1 file changed, 360 insertions(+)

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 239d7a3f59b77..68acdf1720318 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1678,6 +1678,30 @@ half3 max(half3, half3);
 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 half4 max(half4, half4);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half2 max(half2 p0, half p1) {
+  return __builtin_elementwise_max(p0, (half2)p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half2 max(half p0, half2 p1) {
+  return __builtin_elementwise_max((half2)p0, p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half3 max(half3 p0, half p1) {
+  return __builtin_elementwise_max(p0, (half3)p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half3 max(half p0, half3 p1) {
+  return __builtin_elementwise_max((half3)p0, p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half4 max(half4 p0, half p1) {
+  return __builtin_elementwise_max(p0, (half4)p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half4 max(half p0, half4 p1) {
+  return __builtin_elementwise_max((half4)p0, p1);
+}
 
 #ifdef __HLSL_ENABLE_16_BIT
 _HLSL_AVAILABILITY(shadermodel, 6.2)
@@ -1692,6 +1716,30 @@ int16_t3 max(int16_t3, int16_t3);
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int16_t4 max(int16_t4, int16_t4);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t2 max(int16_t2 p0, int16_t p1) {
+  return __builtin_elementwise_max(p0, (int16_t2)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t2 max(int16_t p0, int16_t2 p1) {
+  return __builtin_elementwise_max((int16_t2)p0, p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t3 max(int16_t3 p0, int16_t p1) {
+  return __builtin_elementwise_max(p0, (int16_t3)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t3 max(int16_t p0, int16_t3 p1) {
+  return __builtin_elementwise_max((int16_t3)p0, p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t4 max(int16_t4 p0, int16_t p1) {
+  return __builtin_elementwise_max(p0, (int16_t4)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t4 max(int16_t p0, int16_t4 p1) {
+  return __builtin_elementwise_max((int16_t4)p0, p1);
+}
 
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
@@ -1705,6 +1753,30 @@ uint16_t3 max(uint16_t3, uint16_t3);
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint16_t4 max(uint16_t4, uint16_t4);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t2 max(uint16_t2 p0, uint16_t p1) {
+  return __builtin_elementwise_max(p0, (uint16_t2)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t2 max(uint16_t p0, uint16_t2 p1) {
+  return __builtin_elementwise_max((uint16_t2)p0, p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t3 max(uint16_t3 p0, uint16_t p1) {
+  return __builtin_elementwise_max(p0, (uint16_t3)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t3 max(uint16_t p0, uint16_t3 p1) {
+  return __builtin_elementwise_max((uint16_t3)p0, p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t4 max(uint16_t4 p0, uint16_t p1) {
+  return __builtin_elementwise_max(p0, (uint16_t4)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t4 max(uint16_t p0, uint16_t4 p1) {
+  return __builtin_elementwise_max((uint16_t4)p0, p1);
+}
 #endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
@@ -1715,6 +1787,24 @@ _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int3 max(int3, int3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int4 max(int4, int4);
+constexpr int2 max(int2 p0, int p1) {
+  return __builtin_elementwise_max(p0, (int2)p1);
+}
+constexpr int2 max(int p0, int2 p1) {
+  return __builtin_elementwise_max((int2)p0, p1);
+}
+constexpr int3 max(int3 p0, int p1) {
+  return __builtin_elementwise_max(p0, (int3)p1);
+}
+constexpr int3 max(int p0, int3 p1) {
+  return __builtin_elementwise_max((int3)p0, p1);
+}
+constexpr int4 max(int4 p0, int p1) {
+  return __builtin_elementwise_max(p0, (int4)p1);
+}
+constexpr int4 max(int p0, int4 p1) {
+  return __builtin_elementwise_max((int4)p0, p1);
+}
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint max(uint, uint);
@@ -1724,6 +1814,24 @@ _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint3 max(uint3, uint3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint4 max(uint4, uint4);
+constexpr uint2 max(uint2 p0, uint p

[clang] [HLSL] Add additional overloads for min and max to allow for mixed scalar and vector arguments (PR #129334)

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

spall wrote:

> Are there any error conditions that need testing as well?

I don't think there were error tests for min and max originally. I could add 
some to make sure things like min(int4, int3) are still now allowed.

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


[clang] [HLSL] Add additional overloads for min and max to allow for mixed scalar and vector arguments (PR #129334)

2025-02-28 Thread Joshua Batista via cfe-commits

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


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


[clang] [NFC] Ensure the SPIRV target is enabled for test that uses AMDGCNSPIRV (PR #129298)

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

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


[clang] [llvm] [memprof] Export __memprof_default_options_str on Darwin (PR #128920)

2025-02-28 Thread Ellis Hoag via cfe-commits

https://github.com/ellishg updated 
https://github.com/llvm/llvm-project/pull/128920

>From 2e1946730f7ae2473a4fc94f8918eb3d9d225d17 Mon Sep 17 00:00:00 2001
From: Ellis Hoag 
Date: Wed, 26 Feb 2025 09:48:46 -0800
Subject: [PATCH 1/2] [memprof] Export __memprof_default_options_str on Darwin

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 4 
 clang/test/Driver/fmemprof.cpp | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 75f126965e0ac..a2aeef4c4c475 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1617,6 +1617,10 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 }
   }
 
+  if (Sanitize.needsMemProfRt())
+if (hasExportSymbolDirective(Args))
+  addExportedSymbol(CmdArgs, "___memprof_default_options_str");
+
   const XRayArgs &XRay = getXRayArgs();
   if (XRay.needsXRayRt()) {
 AddLinkRuntimeLib(Args, CmdArgs, "xray");
diff --git a/clang/test/Driver/fmemprof.cpp b/clang/test/Driver/fmemprof.cpp
index 5165c4452fd57..b464320e58a94 100644
--- a/clang/test/Driver/fmemprof.cpp
+++ b/clang/test/Driver/fmemprof.cpp
@@ -17,3 +17,11 @@
 
 // RUN: not %clangxx --target=x86_64-linux-gnu -fprofile-generate 
-fmemory-profile-use=foo %s -### 2>&1 | FileCheck %s 
--check-prefix=CONFLICTWITHPGOINSTR
 // CONFLICTWITHPGOINSTR: error: invalid argument '-fmemory-profile-use=foo' 
not allowed with '-fprofile-generate'
+
+// Test that we export the __memprof_default_options_str on Darwin because it 
has WeakAnyLinkage
+// RUN: %clangxx --target=arm64-apple-ios -fmemory-profile %s -### 2>&1 | 
FileCheck %s -check-prefix=EXPORT-BASE --implicit-check-not=exported_symbol
+// RUN: %clangxx --target=x86_64-linux-gnu -fmemory-profile %s -### 2>&1 | 
FileCheck %s -check-prefix=EXPORT-BASE --implicit-check-not=exported_symbol
+// RUN: %clangxx --target=arm64-apple-ios -fmemory-profile 
-exported_symbols_list /dev/null %s -### 2>&1 | FileCheck %s 
--check-prefixes=EXPORT-BASE,EXPORT
+// FIXME: Darwin needs to link in the runtime, then we can use the regular 
CHECK prefix
+// EXPORT-BASE: "-cc1" {{.*}} "-fmemory-profile"
+// EXPORT: "-exported_symbol" "___memprof_default_options_str"

>From f5b85a00fd2d148bbe552ab7916954d75236ef75 Mon Sep 17 00:00:00 2001
From: Ellis Hoag 
Date: Fri, 28 Feb 2025 09:01:00 -0800
Subject: [PATCH 2/2] Add helper functions and comment

---
 clang/lib/Driver/ToolChains/Darwin.cpp  |  5 -
 llvm/include/llvm/ProfileData/MemProf.h | 11 +++
 llvm/lib/Transforms/Instrumentation/MemProfiler.cpp |  7 +++
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index a2aeef4c4c475..e67997314da36 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -21,6 +21,7 @@
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/ProfileData/MemProf.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/Threading.h"
@@ -1619,7 +1620,9 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 
   if (Sanitize.needsMemProfRt())
 if (hasExportSymbolDirective(Args))
-  addExportedSymbol(CmdArgs, "___memprof_default_options_str");
+  addExportedSymbol(
+  CmdArgs,
+  llvm::memprof::getMemprofOptionsSymbolDarwinLinkageName().data());
 
   const XRayArgs &XRay = getXRayArgs();
   if (XRay.needsXRayRt()) {
diff --git a/llvm/include/llvm/ProfileData/MemProf.h 
b/llvm/include/llvm/ProfileData/MemProf.h
index da0cb47508e32..71e3faa506741 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -6,6 +6,7 @@
 #include "llvm/ADT/STLForwardCompat.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/ProfileData/MemProfData.inc"
 #include "llvm/Support/BLAKE3.h"
@@ -42,6 +43,16 @@ constexpr uint64_t MaximumSupportedVersion = Version3;
 // Verify that the minimum and maximum satisfy the obvious constraint.
 static_assert(MinimumSupportedVersion <= MaximumSupportedVersion);
 
+inline llvm::StringRef getMemprofOptionsSymbolDarwinLinkageName() {
+  return "___memprof_default_options_str";
+}
+
+inline llvm::StringRef getMemprofOptionsSymbolName() {
+  // Darwin linkage names are prefixed with an extra "_". See
+  // DataLayout::getGlobalPrefix().
+  return getMemprofOptionsSymbolDarwinLinkageName().drop_front();
+}
+
 enum class Meta : uint64_t {
   Start = 0,
 #define MIBEntryDef(NameTag, Name, Type) NameTag,
diff --git a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp 
b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
index 7d8bc3aa4c589..6f58a2315547a 100644
--- a/llvm/lib/Tran

[clang] [llvm] [win][x64] Unwind v2 3/n: Add support for emitting unwind v2 information (equivalent to MSVC /d2epilogunwind) (PR #129142)

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

efriedma-quic wrote:

> we can't have epilogs in chained unwind tables, since they are only for 
> additional savereg codes.

How do epilogs work in chained unwind tables?  Do the epilog opcodes from the 
original table get ignored?  If they do get ignored, can you specify different 
opcodes in the chained table?  If they don't get ignored, are the specified 
offsets relative to the chained unwind table?

Also, you don't actually have to chain the unwind tables; you can just specify 
the prolog is size zero, I think?

> the only other place we'd need it is for functions with more than 256 unwind 
> codes

I suspect you can hit the 4KB limit before you hit the opcode limit.

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


[clang] [Clang][Docs][NFC] Correct documentation for the CPATH environment variable (PR #129113)

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


@@ -733,16 +733,17 @@ ENVIRONMENT
 
 .. envvar:: CPATH
 
-  If this environment variable is present, it is treated as a delimited list of
-  paths to be added to the default system include path list. The delimiter is
-  the platform dependent delimiter, as used in the PATH environment variable.
-
-  Empty components in the environment variable are ignored.
+  This environment variable specifies additional header file search paths which
+  behave as if they were specified with the :option:`-I\` option at
+  the end of the driver command line. Paths are delimited by the platform

erichkeane wrote:

I don't mind a quick 'high level' view of what that means, even if it means 
copying slightly from the -I option.  As far as the GCC docs, those aren't 
particularly good either, so we can aim for better than that.

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


[clang] Reapply "[clang][HIP] Make some math not not work with AMDGCN SPIR-V #128360" (PR #129306)

2025-02-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alex Voicu (AlexVlx)


Changes

This reapplies #128360, the only change being that the modified tests 
also checks for the availability of the SPIRV target.

---

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


3 Files Affected:

- (modified) clang/lib/Headers/__clang_hip_libdevice_declares.h (+12-20) 
- (modified) clang/lib/Headers/__clang_hip_math.h (+12-16) 
- (modified) clang/test/Headers/__clang_hip_math.hip (+1656) 


``diff
diff --git a/clang/lib/Headers/__clang_hip_libdevice_declares.h 
b/clang/lib/Headers/__clang_hip_libdevice_declares.h
index f15198b3d9f93..fa8d918248dd0 100644
--- a/clang/lib/Headers/__clang_hip_libdevice_declares.h
+++ b/clang/lib/Headers/__clang_hip_libdevice_declares.h
@@ -14,6 +14,8 @@
 #include "hip/hip_version.h"
 #endif // __has_include("hip/hip_version.h")
 
+#define __PRIVATE_AS __attribute__((opencl_private))
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -55,8 +57,7 @@ __device__ __attribute__((const)) float 
__ocml_fmax_f32(float, float);
 __device__ __attribute__((const)) float __ocml_fmin_f32(float, float);
 __device__ __attribute__((const)) __device__ float __ocml_fmod_f32(float,
float);
-__device__ float __ocml_frexp_f32(float,
-  __attribute__((address_space(5))) int *);
+__device__ float __ocml_frexp_f32(float, __PRIVATE_AS int *);
 __device__ __attribute__((const)) float __ocml_hypot_f32(float, float);
 __device__ __attribute__((const)) int __ocml_ilogb_f32(float);
 __device__ __attribute__((const)) int __ocml_isfinite_f32(float);
@@ -74,8 +75,7 @@ __device__ __attribute__((pure)) float 
__ocml_native_log2_f32(float);
 __device__ __attribute__((const)) float __ocml_logb_f32(float);
 __device__ __attribute__((pure)) float __ocml_log_f32(float);
 __device__ __attribute__((pure)) float __ocml_native_log_f32(float);
-__device__ float __ocml_modf_f32(float,
- __attribute__((address_space(5))) float *);
+__device__ float __ocml_modf_f32(float, __PRIVATE_AS float *);
 __device__ __attribute__((const)) float __ocml_nearbyint_f32(float);
 __device__ __attribute__((const)) float __ocml_nextafter_f32(float, float);
 __device__ __attribute__((const)) float __ocml_len3_f32(float, float, float);
@@ -87,8 +87,7 @@ __device__ __attribute__((pure)) float __ocml_pow_f32(float, 
float);
 __device__ __attribute__((pure)) float __ocml_pown_f32(float, int);
 __device__ __attribute__((pure)) float __ocml_rcbrt_f32(float);
 __device__ __attribute__((const)) float __ocml_remainder_f32(float, float);
-__device__ float __ocml_remquo_f32(float, float,
-   __attribute__((address_space(5))) int *);
+__device__ float __ocml_remquo_f32(float, float, __PRIVATE_AS int *);
 __device__ __attribute__((const)) float __ocml_rhypot_f32(float, float);
 __device__ __attribute__((const)) float __ocml_rint_f32(float);
 __device__ __attribute__((const)) float __ocml_rlen3_f32(float, float, float);
@@ -99,10 +98,8 @@ __device__ __attribute__((pure)) float 
__ocml_rsqrt_f32(float);
 __device__ __attribute__((const)) float __ocml_scalb_f32(float, float);
 __device__ __attribute__((const)) float __ocml_scalbn_f32(float, int);
 __device__ __attribute__((const)) int __ocml_signbit_f32(float);
-__device__ float __ocml_sincos_f32(float,
-   __attribute__((address_space(5))) float *);
-__device__ float __ocml_sincospi_f32(float,
- __attribute__((address_space(5))) float 
*);
+__device__ float __ocml_sincos_f32(float, __PRIVATE_AS float *);
+__device__ float __ocml_sincospi_f32(float, __PRIVATE_AS float *);
 __device__ float __ocml_sin_f32(float);
 __device__ float __ocml_native_sin_f32(float);
 __device__ __attribute__((pure)) float __ocml_sinh_f32(float);
@@ -176,8 +173,7 @@ __device__ __attribute__((const)) double 
__ocml_fma_f64(double, double, double);
 __device__ __attribute__((const)) double __ocml_fmax_f64(double, double);
 __device__ __attribute__((const)) double __ocml_fmin_f64(double, double);
 __device__ __attribute__((const)) double __ocml_fmod_f64(double, double);
-__device__ double __ocml_frexp_f64(double,
-   __attribute__((address_space(5))) int *);
+__device__ double __ocml_frexp_f64(double, __PRIVATE_AS int *);
 __device__ __attribute__((const)) double __ocml_hypot_f64(double, double);
 __device__ __attribute__((const)) int __ocml_ilogb_f64(double);
 __device__ __attribute__((const)) int __ocml_isfinite_f64(double);
@@ -192,8 +188,7 @@ __device__ __attribute__((pure)) double 
__ocml_log1p_f64(double);
 __device__ __attribute__((pure)) double __ocml_log2_f64(double);
 __device__ __attribute__((const)) double __ocml_logb_f64(double);
 __device__ __attribute__((pure)) double __ocml_log_f64(double);
-__de

[clang] [Clang][Docs][NFC] Correct documentation for the CPATH environment variable (PR #129113)

2025-02-28 Thread Tom Honermann via cfe-commits


@@ -733,16 +733,17 @@ ENVIRONMENT
 
 .. envvar:: CPATH
 
-  If this environment variable is present, it is treated as a delimited list of
-  paths to be added to the default system include path list. The delimiter is
-  the platform dependent delimiter, as used in the PATH environment variable.
-
-  Empty components in the environment variable are ignored.
+  This environment variable specifies additional header file search paths which
+  behave as if they were specified with the :option:`-I\` option at
+  the end of the driver command line. Paths are delimited by the platform
+  dependent delimiter as used in the ``PATH`` environment variable. Empty
+  components in the environment variable are ignored.

tahonermann wrote:

I also found that wording a little awkward, but I wasn't able to come up with 
anything better. We could say something like "empty entries in the delimited 
path list are ignored". Is that an improvement? I dunno.

Separately, and interestingly, gcc treats such empty components/entries as if 
"." were specified. I find that horrifying and am glad that clang doesn't 
emulate that behavior! We could document this deviation from gcc behavior 
though.

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


[clang] [CIR] Upstream floating point literal expressions (PR #129304)

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


@@ -57,3 +57,15 @@ bool boolfunc() { return true; }
 // CHECK:   %0 = cir.const #true
 // CHECK:   cir.return %0 : !cir.bool
 // CHECK: }
+
+float floatfunc() { return 42.42f; }
+// CHECK: cir.func @floatfunc() -> !cir.float {
+// CHECK:   %0 = cir.const #cir.fp<4.242000e+01> : !cir.float

erichkeane wrote:

At least in LLVM-IR we are shockingly inconsistent with how we output floating 
point literals in IR.  So I'm not sure if we need to make the format a little 
less 'strict' here?  How consistent is CIR with literal representation across 
platforms?

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


[clang] [flang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)

2025-02-28 Thread via cfe-commits

GeorgeKA wrote:

- I should draw attention to a change I made when it comes to option prefixes. 
Put simply, I had to switch to using prefix "-" instead of "/" because of 
different error output for "/". I describe it 
[here](https://github.com/llvm/llvm-project/blob/1e6150bc23c3410945cddb9d1d33f6e57f5c3f60/clang/utils/generate_unsupported_in_drivermode.py#L404).

- Secondly, I had to add handling for matching option names, which was 
distinguished before by differing prefixes. Described 
[here](https://github.com/llvm/llvm-project/blob/1e6150bc23c3410945cddb9d1d33f6e57f5c3f60/clang/utils/generate_unsupported_in_drivermode.py#L450)

- Also, I moved the flang fc1 testing to 
_flang/test/Driver/unsupported_in_flang_fc1.f90_ in order to use `%flang_fc1`

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


[clang] a19e685 - [CIR] Realign CIR-to-LLVM IR lowering code with incubator (#129293)

2025-02-28 Thread via cfe-commits

Author: Andy Kaylor
Date: 2025-02-28T14:43:39-08:00
New Revision: a19e685ea228ec367a7fa01bbf811c3cded37a83

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

LOG: [CIR] Realign CIR-to-LLVM IR lowering code with incubator (#129293)

The previously upstreamed lowering from ClangIR to LLVM IR diverged from
the incubator implementation, but when the incubator was updated to
incorporate these changes some issues arose which require the upstream
implementation to be modified to re-align with the incubator.

First, in the earlier upstream implementation a CIRAttrVisitor class was
introduced with the intention that an mlir-tblgen based extension would
be created to automatically add all CIR attributes to the visitor. When
I proposed this in mlir-tblgen a reviewer suggested that what I wanted
could be better accomplished with TypeSwitch.

See https://github.com/llvm/llvm-project/pull/126332

This was done in the incubator, and here I am bringing that
implementation upstream.

The other issue was that the global op initialization in the incubator
had more cases than I had accounted for in my previous upstream
refactoring. I did still refactor the incubator code, but not in quite
the same way as the upstream code. This change re-aligns the two.

Added: 


Modified: 
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h

Removed: 
clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h



diff  --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h
deleted file mode 100644
index bbba89cb7e3fd..0
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h
+++ /dev/null
@@ -1,52 +0,0 @@
-//===- CIRAttrVisitor.h - Visitor for CIR attributes *- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// This file defines the CirAttrVisitor interface.
-//
-//===--===//
-
-#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
-#define LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
-
-#include "clang/CIR/Dialect/IR/CIRAttrs.h"
-
-namespace cir {
-
-template  class CirAttrVisitor {
-public:
-  // FIXME: Create a TableGen list to automatically handle new attributes
-  RetTy visit(mlir::Attribute attr) {
-if (const auto intAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirIntAttr(intAttr);
-if (const auto fltAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirFPAttr(fltAttr);
-if (const auto ptrAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirConstPtrAttr(ptrAttr);
-llvm_unreachable("unhandled attribute type");
-  }
-
-  // If the implementation chooses not to implement a certain visit
-  // method, fall back to the parent.
-  RetTy visitCirIntAttr(cir::IntAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-  RetTy visitCirFPAttr(cir::FPAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-  RetTy visitCirConstPtrAttr(cir::ConstPtrAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-
-  RetTy visitCirAttr(mlir::Attribute attr) { return RetTy(); }
-
-  ImplClass &getImpl() { return *static_cast(this); }
-};
-
-} // namespace cir
-
-#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H

diff  --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index ba7fab2865116..6f7cae8fa7fa3 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -24,10 +24,10 @@
 #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Export.h"
 #include "mlir/Transforms/DialectConversion.h"
-#include "clang/CIR/Dialect/IR/CIRAttrVisitor.h"
 #include "clang/CIR/Dialect/IR/CIRDialect.h"
 #include "clang/CIR/MissingFeatures.h"
 #include "clang/CIR/Passes.h"
+#include "llvm/ADT/TypeSwitch.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/TimeProfiler.h"
 
@@ -37,41 +37,23 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
-class CIRAttrToValue : public CirAttrVisitor {
+class CIRAttrToValue {
 public:
   CIRAttrToValue(mlir::Operation *parentOp,
  mlir::ConversionPatternRewriter &rewriter,
  const mlir::TypeConverter *converter)
   : parentOp(parentOp), rewriter(rewriter), converter(converter) {}
 
-  mlir::Value lowerCirAttrAsValue(mlir::Attribute attr) { return visit(attr); }
-
-  mlir::Value vi

[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

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

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


[clang] [CUDA][HIP] fix virtual dtor host/device attr (PR #128926)

2025-02-28 Thread Artem Belevich via cfe-commits


@@ -32,22 +32,24 @@ public:
 template class B;
 }
 
-// The implicit host/device attrs of virtual dtor B::~B() is inferred to
-// have implicit device attr since dtors of its members and parent classes can
-// be executed on device. This causes a diagnostic since B::~B() must
-// be emitted, and it eventually causes host_fun() called on device side.
+// The implicit host/device attrs of virtual dtor ~B() should be
+// conservatively inferred, where constexpr member dtor's should
+// not be considered device since they may call host functions.
+// Therefore B::~B() should not have implicit device attr.
+// However C::~C() should have implicit device attr since
+// it is trivial.
 namespace ExplicitInstantiationDtorNoAttr {
-void host_fun() // dev-note {{'host_fun' declared here}}
+void host_fun()
 {}
 
 template 
 constexpr void hd_fun() {
-  host_fun(); // dev-error{{reference to __host__ function 'host_fun' in 
__host__ __device__ function}}

Artem-B wrote:

For some reason I can not reproduce any of the errors in this test on godbolt, 
even with older clang: https://godbolt.org/z/4fMh5jxKd

What am I missing?





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


[clang] Reapply "[clang][HIP] Make some math not not work with AMDGCN SPIR-V #128360" (PR #129306)

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

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


[clang-tools-extra] [clang-tidy] warn when `true` is used as a preprocessor keyword in C (PR #128265)

2025-02-28 Thread via cfe-commits


@@ -0,0 +1,38 @@
+//===--- TrueMacroCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_TRUEMACROCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_TRUEMACROCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// In C++, `true` is considered a keyword by the preprocessor so an `#if
+/// true` enters the true branch, while in C, `true` is not treated as a
+/// special keyword by the preprocessor, so the false branch is entered.
+///
+/// The check identifies such cases, when `true` is used without being
+/// defined first and also offers fix-its in some cases.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/true-macro.html
+class TrueMacroCheck : public ClangTidyCheck {
+public:
+  TrueMacroCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+return LangOpts.C99 || LangOpts.C11 || LangOpts.C17;

isuckatcs wrote:

We have no such `LANGOPT`.

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


[clang] [clang][analyzer] Add checker 'alpha.core.FixedAddressDereference' (PR #127191)

2025-02-28 Thread Balázs Kéri via cfe-commits

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/127191

From 1f2ad6d5ce6f11fb031ec2175527f56ea86761ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Mon, 3 Feb 2025 15:35:31 +0100
Subject: [PATCH 1/6] [clang][analyzer] Add checker
 'alpha.core.FixedAddressDereference'

---
 clang/docs/analyzer/checkers.rst  |  38 
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  26 +--
 .../Checkers/DereferenceChecker.cpp   |  63 ++-
 clang/test/Analysis/concrete-address.c| 162 +-
 clang/test/Analysis/misc-ps.m |   4 +-
 5 files changed, 271 insertions(+), 22 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 707067358fdfe..c5e10f5a8bbf2 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -129,6 +129,8 @@ The ``SuppressAddressSpaces`` option suppresses
 warnings for null dereferences of all pointers with address spaces. You can
 disable this behavior with the option
 ``-analyzer-config core.NullDereference:SuppressAddressSpaces=false``.
+Value of this option is used for checker :ref:`_core-FixedAddressDereference`
+too.
 *Defaults to true*.
 
 .. code-block:: objc
@@ -2919,6 +2921,42 @@ Check for assignment of a fixed address to a pointer.
p = (int *) 0x1; // warn
  }
 
+.. _alpha-core-FixedAddressDereference:
+
+alpha.core.FixedAddressDereference (C, C++, ObjC)
+"
+Check for dereferences of fixed values used as pointers.
+
+Similarly as at :ref:`_core-NullDereference`, the checker specifically does
+not report dereferences for x86 and x86-64 targets when the
+address space is 256 (x86 GS Segment), 257 (x86 FS Segment), or 258 (x86 SS
+segment). (See `X86/X86-64 Language Extensions
+`__
+for reference.)
+
+If you want to disable this behavior, set the ``SuppressAddressSpaces`` option
+of checker ``core.NullDereference`` to false, like
+``-analyzer-config core.NullDereference:SuppressAddressSpaces=false``. The 
value
+of this option is used for both checkers.
+
+.. code-block:: c
+
+ void test1() {
+   int *p = (int *)0x020;
+   int x = p[0]; // warn
+ }
+
+ void test2(int *p) {
+   if (p == (int *)-1)
+ *p = 0; // warn
+ }
+
+ void test3() {
+   int (*p_function)(char, char);
+   p_function = (int (*)(char, char))0x04080;
+   int x = (*p_function)('x', 'y'); // NO warning yet at functon pointer calls
+ }
+
 .. _alpha-core-PointerArithm:
 
 alpha.core.PointerArithm (C)
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 9bf491eac1e0e..44ca28c003b06 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -211,17 +211,15 @@ def DereferenceModeling : Checker<"DereferenceModeling">,
   Documentation,
   Hidden;
 
-def NullDereferenceChecker : Checker<"NullDereference">,
-  HelpText<"Check for dereferences of null pointers">,
-  CheckerOptions<[
-CmdLineOption
-  ]>,
-  Documentation,
-  Dependencies<[DereferenceModeling]>;
+def NullDereferenceChecker
+: Checker<"NullDereference">,
+  HelpText<"Check for dereferences of null pointers">,
+  CheckerOptions<[CmdLineOption<
+  Boolean, "SuppressAddressSpaces",
+  "Suppresses warning when pointer dereferences an address space",
+  "true", Released>]>,
+  Documentation,
+  Dependencies<[DereferenceModeling]>;
 
 def NonNullParamChecker : Checker<"NonNullParamChecker">,
   HelpText<"Check for null pointers passed as arguments to a function whose "
@@ -285,6 +283,12 @@ def FixedAddressChecker : Checker<"FixedAddr">,
   HelpText<"Check for assignment of a fixed address to a pointer">,
   Documentation;
 
+def FixedAddressDereferenceChecker
+: Checker<"FixedAddressDereference">,
+  HelpText<"Check for dereferences of fixed values used as pointers">,
+  Documentation,
+  Dependencies<[DereferenceModeling]>;
+
 def PointerArithChecker : Checker<"PointerArithm">,
   HelpText<"Check for pointer arithmetic on locations other than array "
"elements">,
diff --git a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
index e9e2771c739b6..6a3f70e62e77b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
@@ -31,7 +31,12 @@ class DereferenceChecker
 : public Checker< check::Location,
   check::Bind,
   EventDispatcher > {
-  enum DerefKind { NullPointer, UndefinedPointerValue, AddressOfLabel };
+  enum DerefKind {
+NullPointer,
+UndefinedPointerValue,
+AddressOfLabel,
+FixedAddress
+  };
 
   void reportBu

[clang] [HLSL] Add HLSLResourceBindingAttr to default constant buffer numeric declarations ($Globals) (PR #128981)

2025-02-28 Thread Helena Kotas via cfe-commits

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


[clang-tools-extra] [clang-tidy] Contributing.rst update snippet and docs (PR #129209)

2025-02-28 Thread via cfe-commits

llvmbot wrote:




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

Author: Marco C. (Marcondiro)


Changes

This reflects the add_new_check.py changes: isLanguageVersionSupported is now 
overridden by default by the script

The changes were instroduced in https://github.com/llvm/llvm-project/pull/100129

Thanks

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


1 Files Affected:

- (modified) clang-tools-extra/docs/clang-tidy/Contributing.rst (+9-9) 


``diff
diff --git a/clang-tools-extra/docs/clang-tidy/Contributing.rst 
b/clang-tools-extra/docs/clang-tidy/Contributing.rst
index 4f1df8d11..ed28df0e9887a 100644
--- a/clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ b/clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -171,9 +171,7 @@ Let's see in more detail at the check class definition:
 
   #include "../ClangTidyCheck.h"
 
-  namespace clang {
-  namespace tidy {
-  namespace readability {
+  namespace clang::tidy::readability {
 
   ...
   class AwesomeFunctionNamesCheck : public ClangTidyCheck {
@@ -182,11 +180,12 @@ Let's see in more detail at the check class definition:
 : ClangTidyCheck(Name, Context) {}
 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+bool isLanguageVersionSupported(const LangOptions &LangOpts) const 
override {
+  return LangOpts.CPlusPlus;
+}
   };
 
-  } // namespace readability
-  } // namespace tidy
-  } // namespace clang
+  } // namespace clang::tidy::readability
 
   ...
 
@@ -203,6 +202,10 @@ for more information) that will find the pattern in the 
AST that we want to
 inspect. The results of the matching are passed to the ``check`` method, which
 can further inspect them and report diagnostics.
 
+By default, the new check applies only to C++ code. If it should apply under 
+different language options, be sure to update the 
``isLanguageVersionSupported``
+method accordingly.
+
 .. code-block:: c++
 
   using namespace ast_matchers;
@@ -231,9 +234,6 @@ override the method ``registerPPCallbacks``.  The 
``add_new_check.py`` script
 does not generate an override for this method in the starting point for your
 new check.
 
-If your check applies only under a specific set of language options, be sure
-to override the method ``isLanguageVersionSupported`` to reflect that.
-
 Check development tips
 --
 

``




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


[clang] [llvm] [Coroutines] Mark parameter allocas with coro.outside.frame metadata (PR #127653)

2025-02-28 Thread Hans Wennborg via cfe-commits

https://github.com/zmodem updated 
https://github.com/llvm/llvm-project/pull/127653

>From cde82a27139c39406a9afb5b471fa527e52e5bca Mon Sep 17 00:00:00 2001
From: Hans Wennborg 
Date: Tue, 18 Feb 2025 15:27:37 +0100
Subject: [PATCH 1/8] [Coroutines] Mark parameter allocas with
 coro.outside.frame metadata

Parameters to a coroutine get copied (moved) to coroutine-local
instances which code inside the coroutine then uses.

The original parameters should not be part of the frame. Normally
CoroSplit figures that out by itself, but for [[clang::trivial_abi]]
parameters which, get destructed at the end of the ramp function,
it does not (see bug), causing use-after-free's if the frame is
destroyed before the end of the ramp (as happens if it doesn't suspend).

Since Clang knows these should never be part of the frame, use metadata
to make it so.

Fixes #127499
---
 clang/lib/CodeGen/CGCoroutine.cpp| 10 +
 clang/test/CodeGenCoroutines/coro-params.cpp | 39 +++-
 2 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 9abf2e8c9190d..cdc61676524b4 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -855,6 +855,16 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt &S) {
 // Create parameter copies. We do it before creating a promise, since an
 // evolution of coroutine TS may allow promise constructor to observe
 // parameter copies.
+for (const ParmVarDecl *Parm : FnArgs) {
+  // If the original param is in an alloca, exclude it from the coroutine
+  // frame. The parameter copy will be part of the frame.
+  Address ParmAddr = GetAddrOfLocalVar(Parm);
+  if (auto *ParmAlloca =
+  dyn_cast(ParmAddr.getBasePointer())) {
+ParmAlloca->setMetadata(llvm::LLVMContext::MD_coro_outside_frame,
+llvm::MDNode::get(CGM.getLLVMContext(), {}));
+  }
+}
 for (auto *PM : S.getParamMoves()) {
   EmitStmt(PM);
   ParamReplacer.addCopy(cast(PM));
diff --git a/clang/test/CodeGenCoroutines/coro-params.cpp 
b/clang/test/CodeGenCoroutines/coro-params.cpp
index b318f2f52ac09..9e640fb2c5c62 100644
--- a/clang/test/CodeGenCoroutines/coro-params.cpp
+++ b/clang/test/CodeGenCoroutines/coro-params.cpp
@@ -59,13 +59,22 @@ struct MoveAndCopy {
   ~MoveAndCopy();
 };
 
-void consume(int,int,int) noexcept;
+struct [[clang::trivial_abi]] TrivialABI {
+  int val;
+  TrivialABI(MoveAndCopy&&) noexcept;
+  ~TrivialABI();
+};
+
+void consume(int,int,int,int) noexcept;
 
 // TODO: Add support for CopyOnly params
-// CHECK: define{{.*}} void @_Z1fi8MoveOnly11MoveAndCopy(i32 noundef %val, ptr 
noundef %[[MoParam:.+]], ptr noundef %[[McParam:.+]]) #0 personality ptr 
@__gxx_personality_v0
-void f(int val, MoveOnly moParam, MoveAndCopy mcParam) {
+// CHECK: define{{.*}} void @_Z1fi8MoveOnly11MoveAndCopy10TrivialABI(i32 
noundef %val, ptr noundef %[[MoParam:.+]], ptr noundef %[[McParam:.+]], i32 
%[[TrivialParam:.+]]) #0 personality ptr @__gxx_personality_v0
+void f(int val, MoveOnly moParam, MoveAndCopy mcParam, TrivialABI 
trivialParam) {
+  // CHECK: %[[TrivialAlloca:.+]] = alloca %struct.TrivialABI,
+  // CHECK-SAME: !coro.outside.frame
   // CHECK: %[[MoCopy:.+]] = alloca %struct.MoveOnly,
   // CHECK: %[[McCopy:.+]] = alloca %struct.MoveAndCopy,
+  // CHECK: %[[TrivialCopy:.+]] = alloca %struct.TrivialABI,
   // CHECK: store i32 %val, ptr %[[ValAddr:.+]]
 
   // CHECK: call ptr @llvm.coro.begin(
@@ -73,25 +82,33 @@ void f(int val, MoveOnly moParam, MoveAndCopy mcParam) {
   // CHECK-NEXT: call void @llvm.lifetime.start.p0(
   // CHECK-NEXT: call void @_ZN11MoveAndCopyC1EOS_(ptr {{[^,]*}} %[[McCopy]], 
ptr noundef nonnull align 4 dereferenceable(4) %[[McParam]]) #
   // CHECK-NEXT: call void @llvm.lifetime.start.p0(
-  // CHECK-NEXT: invoke void 
@_ZNSt16coroutine_traitsIJvi8MoveOnly11MoveAndCopyEE12promise_typeC1Ev(
+  // CHECK-NEXT: call void @llvm.memcpy
+  // CHECK-SAME: %[[TrivialCopy]]
+  // CHECK-SAME: %[[TrivialAlloca]]
+  // CHECK-NEXT: call void @llvm.lifetime.start.p0(
+  // CHECK-NEXT: invoke void 
@_ZNSt16coroutine_traitsIJvi8MoveOnly11MoveAndCopy10TrivialABIEE12promise_typeC1Ev(
 
   // CHECK: call void @_ZN14suspend_always12await_resumeEv(
   // CHECK: %[[IntParam:.+]] = load i32, ptr %{{.*}}
   // CHECK: %[[MoGep:.+]] = getelementptr inbounds nuw %struct.MoveOnly, ptr 
%[[MoCopy]], i32 0, i32 0
   // CHECK: %[[MoVal:.+]] = load i32, ptr %[[MoGep]]
-  // CHECK: %[[McGep:.+]] =  getelementptr inbounds nuw %struct.MoveAndCopy, 
ptr %[[McCopy]], i32 0, i32 0
+  // CHECK: %[[McGep:.+]] = getelementptr inbounds nuw %struct.MoveAndCopy, 
ptr %[[McCopy]], i32 0, i32 0
   // CHECK: %[[McVal:.+]] = load i32, ptr %[[McGep]]
-  // CHECK: call void @_Z7consumeiii(i32 noundef %[[IntParam]], i32 noundef 
%[[MoVal]], i32 noundef %[[McVal]])
+  // CHECK: %[[TrivialGep:.+]] = getelemen

[clang-tools-extra] [clang-tidy] Contributing.rst update snippet and docs (PR #129209)

2025-02-28 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] d0edd93 - [Coroutines] Mark parameter allocas with coro.outside.frame metadata (#127653)

2025-02-28 Thread via cfe-commits

Author: Hans Wennborg
Date: 2025-02-28T09:54:47+01:00
New Revision: d0edd931bcc328b9502289d346f2b2219341f853

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

LOG: [Coroutines] Mark parameter allocas with coro.outside.frame metadata 
(#127653)

Parameters to a coroutine get copied (moved) to coroutine-local
instances which code inside the coroutine then uses.

The original parameters should not be part of the frame. Normally
CoroSplit figures that out by itself, but for [[clang::trivial_abi]]
parameters which, get destructed at the end of the ramp function, it
does not (see bug), causing use-after-free's if the frame is destroyed
before the end of the ramp (as happens if it doesn't suspend).

Since Clang knows these should never be part of the frame, use metadata
to make it so.

Fixes #127499

Added: 


Modified: 
clang/lib/CodeGen/CGCoroutine.cpp
clang/test/CodeGenCoroutines/coro-params.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 058ec01f8ce0e..a9795c2c0dc8f 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -855,6 +855,20 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt &S) {
 // Create parameter copies. We do it before creating a promise, since an
 // evolution of coroutine TS may allow promise constructor to observe
 // parameter copies.
+for (const ParmVarDecl *Parm : FnArgs) {
+  // If the original param is in an alloca, exclude it from the coroutine
+  // frame. The parameter copy will be part of the frame, but the original
+  // parameter memory should remain on the stack. This is necessary to
+  // ensure that parameters destroyed in callees, as with `trivial_abi` or
+  // in the MSVC C++ ABI, are appropriately destroyed after setting up the
+  // coroutine.
+  Address ParmAddr = GetAddrOfLocalVar(Parm);
+  if (auto *ParmAlloca =
+  dyn_cast(ParmAddr.getBasePointer())) {
+ParmAlloca->setMetadata(llvm::LLVMContext::MD_coro_outside_frame,
+llvm::MDNode::get(CGM.getLLVMContext(), {}));
+  }
+}
 for (auto *PM : S.getParamMoves()) {
   EmitStmt(PM);
   ParamReplacer.addCopy(cast(PM));

diff  --git a/clang/test/CodeGenCoroutines/coro-params.cpp 
b/clang/test/CodeGenCoroutines/coro-params.cpp
index b318f2f52ac09..719726cca29c5 100644
--- a/clang/test/CodeGenCoroutines/coro-params.cpp
+++ b/clang/test/CodeGenCoroutines/coro-params.cpp
@@ -3,6 +3,7 @@
 // Vefifies that parameter copies are used in the body of the coroutine
 // Verifies that parameter copies are used to construct the promise type, if 
that type has a matching constructor
 // RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - 
%s -disable-llvm-passes -fexceptions | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-pc-win32  -emit-llvm -o - 
%s -disable-llvm-passes -fexceptions | FileCheck %s --check-prefix=MSABI
 
 namespace std {
 template  struct coroutine_traits;
@@ -59,13 +60,22 @@ struct MoveAndCopy {
   ~MoveAndCopy();
 };
 
-void consume(int,int,int) noexcept;
+struct [[clang::trivial_abi]] TrivialABI {
+  int val;
+  TrivialABI(TrivialABI&&) noexcept;
+  ~TrivialABI();
+};
+
+void consume(int,int,int,int) noexcept;
 
 // TODO: Add support for CopyOnly params
-// CHECK: define{{.*}} void @_Z1fi8MoveOnly11MoveAndCopy(i32 noundef %val, ptr 
noundef %[[MoParam:.+]], ptr noundef %[[McParam:.+]]) #0 personality ptr 
@__gxx_personality_v0
-void f(int val, MoveOnly moParam, MoveAndCopy mcParam) {
+// CHECK: define{{.*}} void @_Z1fi8MoveOnly11MoveAndCopy10TrivialABI(i32 
noundef %val, ptr noundef %[[MoParam:.+]], ptr noundef %[[McParam:.+]], i32 
%[[TrivialParam:.+]]) #0 personality ptr @__gxx_personality_v0
+void f(int val, MoveOnly moParam, MoveAndCopy mcParam, TrivialABI 
trivialParam) {
+  // CHECK: %[[TrivialAlloca:.+]] = alloca %struct.TrivialABI,
+  // CHECK-SAME: !coro.outside.frame
   // CHECK: %[[MoCopy:.+]] = alloca %struct.MoveOnly,
   // CHECK: %[[McCopy:.+]] = alloca %struct.MoveAndCopy,
+  // CHECK: %[[TrivialCopy:.+]] = alloca %struct.TrivialABI,
   // CHECK: store i32 %val, ptr %[[ValAddr:.+]]
 
   // CHECK: call ptr @llvm.coro.begin(
@@ -73,25 +83,31 @@ void f(int val, MoveOnly moParam, MoveAndCopy mcParam) {
   // CHECK-NEXT: call void @llvm.lifetime.start.p0(
   // CHECK-NEXT: call void @_ZN11MoveAndCopyC1EOS_(ptr {{[^,]*}} %[[McCopy]], 
ptr noundef nonnull align 4 dereferenceable(4) %[[McParam]]) #
   // CHECK-NEXT: call void @llvm.lifetime.start.p0(
-  // CHECK-NEXT: invoke void 
@_ZNSt16coroutine_traitsIJvi8MoveOnly11MoveAndCopyEE12promise_typeC1Ev(
+  // CHECK-NEXT: call void @_ZN10TrivialABIC1EOS_(ptr {{[

[clang] [llvm] [Coroutines] Mark parameter allocas with coro.outside.frame metadata (PR #127653)

2025-02-28 Thread Hans Wennborg via cfe-commits

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


[clang] Clang: Add minnum/maxnum builtin functions (PR #129207)

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


@@ -209,6 +209,18 @@ def FmaxF16F128 : Builtin, F16F128MathTemplate {
   let Prototype = "T(T, T)";
 }
 
+def MinNum : Builtin {

arsenm wrote:

Should the keep the f prefix convention? I suppose we aren't following a libm 
function, so it might make sense to drop it 

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


[clang] [CIR] Upstream func args alloca handling (PR #129167)

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

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


[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

2025-02-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Andy Kaylor (andykaylor)


Changes

The previously upstreamed lowering from ClangIR to LLVM IR diverged from the 
incubator implementation, but when the incubator was updated to incorporate 
these changes some issues arose which require the upstream implementation to be 
modified to re-align with the incubator.

First, in the earlier upstream implementation a CIRAttrVisitor class was 
introduced with the intention that an mlir-tblgen based extension would be 
created to automatically add all CIR attributes to the visitor. When I proposed 
this in mlir-tblgen a reviewer suggested that what I wanted could be better 
accomplished with TypeSwitch.

See https://github.com/llvm/llvm-project/pull/126332

This was done in the incubator, and here I am bringing that implementation 
upstream.

The other issue was that the global op initialization in the incubator had more 
cases than I had accounted for in my previous upstream refactoring. I did still 
refactor the incubator code, but not in quite the same way as the upstream 
code. This change re-aligns the two.

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


3 Files Affected:

- (removed) clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h (-52) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+75-53) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h (-2) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h
deleted file mode 100644
index bbba89cb7e3fd..0
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h
+++ /dev/null
@@ -1,52 +0,0 @@
-//===- CIRAttrVisitor.h - Visitor for CIR attributes *- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// This file defines the CirAttrVisitor interface.
-//
-//===--===//
-
-#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
-#define LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
-
-#include "clang/CIR/Dialect/IR/CIRAttrs.h"
-
-namespace cir {
-
-template  class CirAttrVisitor {
-public:
-  // FIXME: Create a TableGen list to automatically handle new attributes
-  RetTy visit(mlir::Attribute attr) {
-if (const auto intAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirIntAttr(intAttr);
-if (const auto fltAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirFPAttr(fltAttr);
-if (const auto ptrAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirConstPtrAttr(ptrAttr);
-llvm_unreachable("unhandled attribute type");
-  }
-
-  // If the implementation chooses not to implement a certain visit
-  // method, fall back to the parent.
-  RetTy visitCirIntAttr(cir::IntAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-  RetTy visitCirFPAttr(cir::FPAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-  RetTy visitCirConstPtrAttr(cir::ConstPtrAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-
-  RetTy visitCirAttr(mlir::Attribute attr) { return RetTy(); }
-
-  ImplClass &getImpl() { return *static_cast(this); }
-};
-
-} // namespace cir
-
-#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index ba7fab2865116..5d083efcdda6f 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -24,10 +24,10 @@
 #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Export.h"
 #include "mlir/Transforms/DialectConversion.h"
-#include "clang/CIR/Dialect/IR/CIRAttrVisitor.h"
 #include "clang/CIR/Dialect/IR/CIRDialect.h"
 #include "clang/CIR/MissingFeatures.h"
 #include "clang/CIR/Passes.h"
+#include "llvm/ADT/TypeSwitch.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/TimeProfiler.h"
 
@@ -37,41 +37,23 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
-class CIRAttrToValue : public CirAttrVisitor {
+class CIRAttrToValue {
 public:
   CIRAttrToValue(mlir::Operation *parentOp,
  mlir::ConversionPatternRewriter &rewriter,
  const mlir::TypeConverter *converter)
   : parentOp(parentOp), rewriter(rewriter), converter(converter) {}
 
-  mlir::Value lowerCirAttrAsValue(mlir::Attribute attr) { return visit(attr); }
-
-  mlir::Value visitCirIntAttr(cir::IntAttr intAttr) {
-mlir::Location loc = parentOp->getLoc();
-return rewriter.create(
-loc, converter->convertType(intAttr.getType()), intAttr.getValue());
-  }
-
-  mlir::Value visitCirFPAttr(cir::

[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

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

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

The previously upstreamed lowering from ClangIR to LLVM IR diverged from the 
incubator implementation, but when the incubator was updated to incorporate 
these changes some issues arose which require the upstream implementation to be 
modified to re-align with the incubator.

First, in the earlier upstream implementation a CIRAttrVisitor class was 
introduced with the intention that an mlir-tblgen based extension would be 
created to automatically add all CIR attributes to the visitor. When I proposed 
this in mlir-tblgen a reviewer suggested that what I wanted could be better 
accomplished with TypeSwitch.

See https://github.com/llvm/llvm-project/pull/126332

This was done in the incubator, and here I am bringing that implementation 
upstream.

The other issue was that the global op initialization in the incubator had more 
cases than I had accounted for in my previous upstream refactoring. I did still 
refactor the incubator code, but not in quite the same way as the upstream 
code. This change re-aligns the two.

>From bb41af68d0d0f66c5610c69d6deb8a615d644fe5 Mon Sep 17 00:00:00 2001
From: Andy Kaylor 
Date: Fri, 28 Feb 2025 10:54:09 -0800
Subject: [PATCH 1/2] [CIR] Replace CIRAttrVisitor with TypeSwitch

We previously discussed having an mlir-tblgen utility to complete the
CIRAttrVisitor implementation with all support attribute types, but
when I proposed an implementation to do this, a reviewer suggested
using TypeSwitch instead, and I have done that in the incubator.

See https://github.com/llvm/llvm-project/pull/126332

This change brings the TypeSwitch implementation into the upstream repo
to replace the visitor class.
---
 .../clang/CIR/Dialect/IR/CIRAttrVisitor.h | 52 ---
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 31 +++
 2 files changed, 22 insertions(+), 61 deletions(-)
 delete mode 100644 clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h
deleted file mode 100644
index bbba89cb7e3fd..0
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h
+++ /dev/null
@@ -1,52 +0,0 @@
-//===- CIRAttrVisitor.h - Visitor for CIR attributes *- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// This file defines the CirAttrVisitor interface.
-//
-//===--===//
-
-#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
-#define LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
-
-#include "clang/CIR/Dialect/IR/CIRAttrs.h"
-
-namespace cir {
-
-template  class CirAttrVisitor {
-public:
-  // FIXME: Create a TableGen list to automatically handle new attributes
-  RetTy visit(mlir::Attribute attr) {
-if (const auto intAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirIntAttr(intAttr);
-if (const auto fltAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirFPAttr(fltAttr);
-if (const auto ptrAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirConstPtrAttr(ptrAttr);
-llvm_unreachable("unhandled attribute type");
-  }
-
-  // If the implementation chooses not to implement a certain visit
-  // method, fall back to the parent.
-  RetTy visitCirIntAttr(cir::IntAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-  RetTy visitCirFPAttr(cir::FPAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-  RetTy visitCirConstPtrAttr(cir::ConstPtrAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-
-  RetTy visitCirAttr(mlir::Attribute attr) { return RetTy(); }
-
-  ImplClass &getImpl() { return *static_cast(this); }
-};
-
-} // namespace cir
-
-#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index ba7fab2865116..7bf4b5fd27b61 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -24,10 +24,10 @@
 #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Export.h"
 #include "mlir/Transforms/DialectConversion.h"
-#include "clang/CIR/Dialect/IR/CIRAttrVisitor.h"
 #include "clang/CIR/Dialect/IR/CIRDialect.h"
 #include "clang/CIR/MissingFeatures.h"
 #include "clang/CIR/Passes.h"
+#include "llvm/ADT/TypeSwitch.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/TimeProfiler.h"
 
@@ -37,7 +37,7 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
-class CIRAttrToValue : public CirAttrVisitor {
+class CIRAttrToValue {
 public:
   CIRAttr

[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

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


@@ -218,12 +221,31 @@ mlir::LogicalResult 
CIRToLLVMGlobalOpLowering::matchAndRewrite(
   SmallVector attributes;
 
   if (init.has_value()) {
-GlobalInitAttrRewriter initRewriter(llvmType, rewriter);
-init = initRewriter.rewriteInitAttr(init.value());
-// If initRewriter returned a null attribute, init will have a value but
-// the value will be null. If that happens, initRewriter didn't handle the
-// attribute type. It probably needs to be added to GlobalInitAttrRewriter.
-if (!init.value()) {
+if (mlir::isa(init.value())) {

erichkeane wrote:

This section is a bit worse unfortunately.  We might consider extracting this 
type at one point.  

Why did we remove the use of `GlobalInitAttrRewriter` (or am I missing a use 
elsewhere?), and do we intend to bring it back?Could it be used here 
instead like it was before?

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


[clang] [llvm] [win][x64] Unwind v2 3/n: Add support for emitting unwind v2 information (equivalent to MSVC /d2epilogunwind) (PR #129142)

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


@@ -500,7 +500,8 @@ MCSymbol *MCStreamer::emitLineTableLabel() {
 MCSymbol *MCStreamer::emitCFILabel() {
   // Return a dummy non-null value so that label fields appear filled in when
   // generating textual assembly.
-  return (MCSymbol *)1;
+  static size_t DummyLabelValue = 0;

efriedma-quic wrote:

(Also, non-const static variables are basically banned in LLVM code: in 
contexts like LTO, we run multiple instances of the compiler in parallel, and a 
static variable will explode if you do that.)

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


[clang-tools-extra] [clang-tidy] Fix invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (PR #127162)

2025-02-28 Thread via cfe-commits

https://github.com/Andrewyuan34 updated 
https://github.com/llvm/llvm-project/pull/127162

>From 09b809d803ca319f194eba6b6d8a78fa6dbbf9f3 Mon Sep 17 00:00:00 2001
From: Andrewyuan34 
Date: Thu, 13 Feb 2025 22:35:36 -0500
Subject: [PATCH] [clang-tidy] Fix invalid fixit from modernize-use-ranges for
 nullptr used with std::unique_ptr

---
 .../clang-tidy/utils/UseRangesCheck.cpp   | 13 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../checkers/modernize/use-ranges.cpp | 26 ---
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index aba4d17ccd035..f7a19cd72d500 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -215,6 +215,19 @@ void UseRangesCheck::check(const MatchFinder::MatchResult 
&Result) {
 const auto *Call = Result.Nodes.getNodeAs(Buffer);
 if (!Call)
   continue;
+
+// FIXME: This check specifically handles `CXXNullPtrLiteralExpr`, but
+// a more general solution might be needed.
+if (Function->getName() == "find") {
+  const unsigned ValueArgIndex = 2;
+  if (Call->getNumArgs() <= ValueArgIndex)
+continue;
+  const Expr *ValueExpr =
+  Call->getArg(ValueArgIndex)->IgnoreParenImpCasts();
+  if (isa(ValueExpr))
+return;
+}
+
 auto Diag = createDiag(*Call);
 if (auto ReplaceName = Replacer->getReplaceName(*Function))
   Diag << FixItHint::CreateReplacement(Call->getCallee()->getSourceRange(),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a8d17d19fda1d..becd3713e6ad0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -126,6 +126,10 @@ Changes in existing checks
 - Improved :doc:`misc-redundant-expression
   ` check by providing additional
   examples and fixing some macro related false positives.
+  
+- Improved :doc:`modernize-use-ranges
+  ` check by updating suppress 
+  warnings logic for ``nullptr`` in ``std::find``.
 
 - Improved :doc:`performance/unnecessary-value-param
   ` check performance by
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
index b022efebfdf4d..5aa026038b1cd 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
@@ -1,14 +1,25 @@
-// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I 
%S/Inputs/use-ranges/
-// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t 
-check-suffixes=,CPP23 -- -I %S/Inputs/use-ranges/
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I 
%S/Inputs/
+// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t 
-check-suffixes=,CPP23 -- -I %S/Inputs/
+// Example: ./check_clang_tidy.py -std=c++20 checkers/modernize/use-ranges.cpp 
modernize-use-ranges temp.txt -- -- -I 
~/llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/
 
 // CHECK-FIXES: #include 
 // CHECK-FIXES-CPP23: #include 
 // CHECK-FIXES: #include 
 
-#include "fake_std.h"
+#include "use-ranges/fake_std.h"
+#include "smart-ptr/unique_ptr.h"
 
 void Positives() {
   std::vector I, J;
+  std::vector> K;
+
+  // Expect to have no check messages
+  std::find(K.begin(), K.end(), nullptr);
+
+  std::find(K.begin(), K.end(), std::unique_ptr());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(K, std::unique_ptr());
+
   std::find(I.begin(), I.end(), 0);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(I, 0);
@@ -76,6 +87,15 @@ void Positives() {
 
 void Reverse(){
   std::vector I, J;
+  std::vector> K;
+  
+  // Expect to have no check messages
+  std::find(K.rbegin(), K.rend(), nullptr);
+
+  std::find(K.rbegin(), K.rend(), std::unique_ptr());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(K), 
std::unique_ptr());
+
   std::find(I.rbegin(), I.rend(), 0);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(I), 0);

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


[clang] [CUDA][HIP] fix virtual dtor host/device attr (PR #128926)

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


@@ -32,22 +32,24 @@ public:
 template class B;
 }
 
-// The implicit host/device attrs of virtual dtor B::~B() is inferred to
-// have implicit device attr since dtors of its members and parent classes can
-// be executed on device. This causes a diagnostic since B::~B() must
-// be emitted, and it eventually causes host_fun() called on device side.
+// The implicit host/device attrs of virtual dtor ~B() should be
+// conservatively inferred, where constexpr member dtor's should
+// not be considered device since they may call host functions.
+// Therefore B::~B() should not have implicit device attr.
+// However C::~C() should have implicit device attr since
+// it is trivial.
 namespace ExplicitInstantiationDtorNoAttr {
-void host_fun() // dev-note {{'host_fun' declared here}}
+void host_fun()
 {}
 
 template 
 constexpr void hd_fun() {
-  host_fun(); // dev-error{{reference to __host__ function 'host_fun' in 
__host__ __device__ function}}

yxsamliu wrote:

For the old clang, there is no deferred diag for dtors, and the compilation 
stops at device assembly, so you won't see the link error. For the trunk clang, 
it is not new enough (-v shows abe1ecff5428871ea79be41b6db38e585dbd79e8). I 
think it may be updated once daily.

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


[clang] [CIR] Upstream floating point literal expressions (PR #129304)

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


@@ -57,3 +57,15 @@ bool boolfunc() { return true; }
 // CHECK:   %0 = cir.const #true
 // CHECK:   cir.return %0 : !cir.bool
 // CHECK: }
+
+float floatfunc() { return 42.42f; }
+// CHECK: cir.func @floatfunc() -> !cir.float {
+// CHECK:   %0 = cir.const #cir.fp<4.242000e+01> : !cir.float

andykaylor wrote:

I haven't looked into how these values get printed, but I would expect the 
behavior to be similar to LLVM IR, which while it is as you note inconsistent 
is generally stable.

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


[clang] 56cc929 - [CIR] Upstream func args alloca handling (#129167)

2025-02-28 Thread via cfe-commits

Author: Andy Kaylor
Date: 2025-02-28T11:43:53-08:00
New Revision: 56cc9299b7804257549edb4a7ba15999cbb5

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

LOG: [CIR] Upstream func args alloca handling (#129167)

This change adds support for collecting function arguments and storing
them in alloca memory slots.

Added: 
clang/lib/CIR/CodeGen/CIRGenCall.h

Modified: 
clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
clang/include/clang/CIR/Dialect/IR/CIROps.td
clang/include/clang/CIR/MissingFeatures.h
clang/lib/CIR/CodeGen/Address.h
clang/lib/CIR/CodeGen/CIRGenDecl.cpp
clang/lib/CIR/CodeGen/CIRGenFunction.cpp
clang/lib/CIR/CodeGen/CIRGenFunction.h
clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
clang/test/CIR/CodeGen/basic.cpp

Removed: 




diff  --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index 14afdfc2758ea..b65797e40d5f9 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -69,6 +69,11 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return create(loc, ptr);
   }
 
+  cir::StoreOp createStore(mlir::Location loc, mlir::Value val,
+   mlir::Value dst) {
+return create(loc, val, dst);
+  }
+
   //
   // Block handling helpers
   // --

diff  --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 083cf46a93ae6..48178b0ff247d 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -228,6 +228,45 @@ def LoadOp : CIR_Op<"load", [
   // FIXME: add verifier.
 }
 
+//===--===//
+// StoreOp
+//===--===//
+
+def StoreOp : CIR_Op<"store", [
+  TypesMatchWith<"type of 'value' matches pointee type of 'addr'",
+ "addr", "value",
+ "cast($_self).getPointee()">,
+ DeclareOpInterfaceMethods]> {
+
+  let summary = "Store value to memory address";
+  let description = [{
+`cir.store` stores a value (first operand) to the memory address specified
+in the second operand. A unit attribute `volatile` can be used to indicate
+a volatile store. Store's can be marked atomic by using
+`atomic()`.
+
+`align` can be used to specify an alignment that's 
diff erent from the
+default, which is computed from `result`'s type ABI data layout.
+
+Example:
+
+```mlir
+// Store a function argument to local storage, address in %0.
+cir.store %arg0, %0 : i32, !cir.ptr
+```
+  }];
+
+  let arguments = (ins CIR_AnyType:$value,
+   Arg:$addr);
+
+  let assemblyFormat = [{
+$value `,` $addr attr-dict `:` type($value) `,` qualified(type($addr))
+  }];
+
+  // FIXME: add verifier.
+}
+
 
//===--===//
 // ReturnOp
 
//===--===//

diff  --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index 5c7e10d018809..9b416ef61055e 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -59,6 +59,7 @@ struct MissingFeatures {
   // Misc
   static bool scalarConversionOpts() { return false; }
   static bool tryEmitAsConstant() { return false; }
+  static bool constructABIArgDirectExtend() { return false; }
 };
 
 } // namespace cir

diff  --git a/clang/lib/CIR/CodeGen/Address.h b/clang/lib/CIR/CodeGen/Address.h
index 72e7e1dcf1560..fba1ffd90877b 100644
--- a/clang/lib/CIR/CodeGen/Address.h
+++ b/clang/lib/CIR/CodeGen/Address.h
@@ -52,6 +52,14 @@ class Address {
elementType);
   }
 
+  Address(mlir::Value pointer, clang::CharUnits alignment)
+  : Address(pointer,
+mlir::cast(pointer.getType()).getPointee(),
+alignment) {
+assert((!alignment.isZero() || pointer == nullptr) &&
+   "creating valid address with invalid alignment");
+  }
+
   static Address invalid() { return Address(nullptr); }
   bool isValid() const {
 return pointerAndKnownNonNull.getPointer() != nullptr;

diff  --git a/clang/lib/CIR/CodeGen/CIRGenCall.h 
b/clang/lib/CIR/CodeGen/CIRGenCall.h
new file mode 100644
index 0..0996167feeef6
--- /dev/null
+++ b/clang/lib/CIR/CodeGen/CIRGenCall.h
@@ -0,0 +1,28 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Excepti

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

2025-02-28 Thread via cfe-commits


@@ -376,6 +376,24 @@ let SMETargetGuard = "sme2" in {
 // Outer product and accumulate/subtract
 //
 
+multiclass MOP4 checks> {
+  def NAME # "_1x1" : Inst<"svmop4" # name # "_1x1_" # n # "[_{d}_{d}]", 
"vidd", t, MergeNone, i # wide # "_1x1", [IsInOutZA, IsStreaming], checks>;

Lukacma wrote:

```suggestion
  def _1x1 : Inst<"svmop4" # name # "_1x1_" # n # "[_{d}_{d}]", "vidd", t, 
MergeNone, i # wide # "_1x1", [IsInOutZA, IsStreaming], checks>;
```

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


[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

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


@@ -37,63 +37,78 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
-class CIRAttrToValue : public CirAttrVisitor {
+class CIRAttrToValue {
 public:
   CIRAttrToValue(mlir::Operation *parentOp,
  mlir::ConversionPatternRewriter &rewriter,
  const mlir::TypeConverter *converter)
   : parentOp(parentOp), rewriter(rewriter), converter(converter) {}
 
-  mlir::Value lowerCirAttrAsValue(mlir::Attribute attr) { return visit(attr); }
-
-  mlir::Value visitCirIntAttr(cir::IntAttr intAttr) {
-mlir::Location loc = parentOp->getLoc();
-return rewriter.create(
-loc, converter->convertType(intAttr.getType()), intAttr.getValue());
-  }
-
-  mlir::Value visitCirFPAttr(cir::FPAttr fltAttr) {
-mlir::Location loc = parentOp->getLoc();
-return rewriter.create(
-loc, converter->convertType(fltAttr.getType()), fltAttr.getValue());
+  mlir::Value visit(mlir::Attribute attr) {
+return llvm::TypeSwitch(attr)
+.Case(

andykaylor wrote:

I think it needs to be a manual list because it's never going to be the 
complete list. These are just the types we intend to handle here, with other 
types going to the Default() handler.

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


[clang] Reapply "[clang][HIP] Make some math not not work with AMDGCN SPIR-V #128360" (PR #129306)

2025-02-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Alex Voicu (AlexVlx)


Changes

This reapplies #128360, the only change being that the modified tests 
also checks for the availability of the SPIRV target.

---

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


3 Files Affected:

- (modified) clang/lib/Headers/__clang_hip_libdevice_declares.h (+12-20) 
- (modified) clang/lib/Headers/__clang_hip_math.h (+12-16) 
- (modified) clang/test/Headers/__clang_hip_math.hip (+1656) 


``diff
diff --git a/clang/lib/Headers/__clang_hip_libdevice_declares.h 
b/clang/lib/Headers/__clang_hip_libdevice_declares.h
index f15198b3d9f93..fa8d918248dd0 100644
--- a/clang/lib/Headers/__clang_hip_libdevice_declares.h
+++ b/clang/lib/Headers/__clang_hip_libdevice_declares.h
@@ -14,6 +14,8 @@
 #include "hip/hip_version.h"
 #endif // __has_include("hip/hip_version.h")
 
+#define __PRIVATE_AS __attribute__((opencl_private))
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -55,8 +57,7 @@ __device__ __attribute__((const)) float 
__ocml_fmax_f32(float, float);
 __device__ __attribute__((const)) float __ocml_fmin_f32(float, float);
 __device__ __attribute__((const)) __device__ float __ocml_fmod_f32(float,
float);
-__device__ float __ocml_frexp_f32(float,
-  __attribute__((address_space(5))) int *);
+__device__ float __ocml_frexp_f32(float, __PRIVATE_AS int *);
 __device__ __attribute__((const)) float __ocml_hypot_f32(float, float);
 __device__ __attribute__((const)) int __ocml_ilogb_f32(float);
 __device__ __attribute__((const)) int __ocml_isfinite_f32(float);
@@ -74,8 +75,7 @@ __device__ __attribute__((pure)) float 
__ocml_native_log2_f32(float);
 __device__ __attribute__((const)) float __ocml_logb_f32(float);
 __device__ __attribute__((pure)) float __ocml_log_f32(float);
 __device__ __attribute__((pure)) float __ocml_native_log_f32(float);
-__device__ float __ocml_modf_f32(float,
- __attribute__((address_space(5))) float *);
+__device__ float __ocml_modf_f32(float, __PRIVATE_AS float *);
 __device__ __attribute__((const)) float __ocml_nearbyint_f32(float);
 __device__ __attribute__((const)) float __ocml_nextafter_f32(float, float);
 __device__ __attribute__((const)) float __ocml_len3_f32(float, float, float);
@@ -87,8 +87,7 @@ __device__ __attribute__((pure)) float __ocml_pow_f32(float, 
float);
 __device__ __attribute__((pure)) float __ocml_pown_f32(float, int);
 __device__ __attribute__((pure)) float __ocml_rcbrt_f32(float);
 __device__ __attribute__((const)) float __ocml_remainder_f32(float, float);
-__device__ float __ocml_remquo_f32(float, float,
-   __attribute__((address_space(5))) int *);
+__device__ float __ocml_remquo_f32(float, float, __PRIVATE_AS int *);
 __device__ __attribute__((const)) float __ocml_rhypot_f32(float, float);
 __device__ __attribute__((const)) float __ocml_rint_f32(float);
 __device__ __attribute__((const)) float __ocml_rlen3_f32(float, float, float);
@@ -99,10 +98,8 @@ __device__ __attribute__((pure)) float 
__ocml_rsqrt_f32(float);
 __device__ __attribute__((const)) float __ocml_scalb_f32(float, float);
 __device__ __attribute__((const)) float __ocml_scalbn_f32(float, int);
 __device__ __attribute__((const)) int __ocml_signbit_f32(float);
-__device__ float __ocml_sincos_f32(float,
-   __attribute__((address_space(5))) float *);
-__device__ float __ocml_sincospi_f32(float,
- __attribute__((address_space(5))) float 
*);
+__device__ float __ocml_sincos_f32(float, __PRIVATE_AS float *);
+__device__ float __ocml_sincospi_f32(float, __PRIVATE_AS float *);
 __device__ float __ocml_sin_f32(float);
 __device__ float __ocml_native_sin_f32(float);
 __device__ __attribute__((pure)) float __ocml_sinh_f32(float);
@@ -176,8 +173,7 @@ __device__ __attribute__((const)) double 
__ocml_fma_f64(double, double, double);
 __device__ __attribute__((const)) double __ocml_fmax_f64(double, double);
 __device__ __attribute__((const)) double __ocml_fmin_f64(double, double);
 __device__ __attribute__((const)) double __ocml_fmod_f64(double, double);
-__device__ double __ocml_frexp_f64(double,
-   __attribute__((address_space(5))) int *);
+__device__ double __ocml_frexp_f64(double, __PRIVATE_AS int *);
 __device__ __attribute__((const)) double __ocml_hypot_f64(double, double);
 __device__ __attribute__((const)) int __ocml_ilogb_f64(double);
 __device__ __attribute__((const)) int __ocml_isfinite_f64(double);
@@ -192,8 +188,7 @@ __device__ __attribute__((pure)) double 
__ocml_log1p_f64(double);
 __device__ __attribute__((pure)) double __ocml_log2_f64(double);
 __device__ __attribute__((const)) double __ocml_logb_f64(double);
 __device__ __attribute__((pure)) double __ocml_log_f64(double);

[clang] [Clang][Docs][NFC] Correct documentation for the CPATH environment variable (PR #129113)

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


@@ -733,16 +733,17 @@ ENVIRONMENT
 
 .. envvar:: CPATH
 
-  If this environment variable is present, it is treated as a delimited list of
-  paths to be added to the default system include path list. The delimiter is
-  the platform dependent delimiter, as used in the PATH environment variable.
-
-  Empty components in the environment variable are ignored.
+  This environment variable specifies additional header file search paths which
+  behave as if they were specified with the :option:`-I\` option at
+  the end of the driver command line. Paths are delimited by the platform
+  dependent delimiter as used in the ``PATH`` environment variable. Empty
+  components in the environment variable are ignored.

erichkeane wrote:

'entries' is actually way nicer I think, I'd prefer that instead.  `components` 
makes me wonder whether that means parts of a path/etc.

Documenting that deviation is a good idea too IMO.

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

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


@@ -51,18 +51,18 @@ namespace disabled_dtor {
   union disable_dtor {
 T val;
 template
-disable_dtor(U &&...u) : val(forward(u)...) {}
+disable_dtor(U &&...u) : val(forward(u)...) {} // expected-error 
{{attempt to use a deleted function}}

efriedma-quic wrote:

I think this error is correct: if the body of the constructor throws, we call 
the destructor for val.

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

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


@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+namespace t1{
+template  struct VSX {
+  ~VSX() { static_assert(sizeof(T) != 4, ""); } // expected-error {{static 
assertion failed due to requirement 'sizeof(int) != 4':}} \
+// expected-note {{expression 
evaluates to '4 != 4'}}
+};
+struct VS {
+  union {
+VSX _Tail;
+  };
+  ~VS() { }
+  VS(short);
+};
+VS::VS(short) : _Tail() { } // expected-note {{in instantiation of member 
function 't1::VSX::~VSX' requested here}}
+}
+
+
+namespace t2 {
+template  struct VSX {
+  ~VSX() { static_assert(sizeof(T) != 4, ""); } // expected-error {{static 
assertion failed due to requirement 'sizeof(int) != 4':}} \
+// expected-note {{expression 
evaluates to '4 != 4'}}
+};
+struct VS {
+  union {
+struct {
+  VSX _Tail;
+};
+  };
+  ~VS() { }
+  VS(short);
+};
+VS::VS(short) : _Tail() { } // expected-note {{in instantiation of member 
function 't2::VSX::~VSX' requested here}}
+}
+
+
+namespace t3 {
+template  struct VSX {
+  ~VSX() { static_assert(sizeof(T) != 4, ""); } // expected-error {{static 
assertion failed due to requirement 'sizeof(int) != 4':}} \
+// expected-note {{expression 
evaluates to '4 != 4'}}
+};
+union VS {
+  VSX _Tail;
+  ~VS() { }
+  VS(short);
+};
+VS::VS(short) : _Tail() { } // expected-note {{in instantiation of member 
function 't3::VSX::~VSX' requested here}}
+}

efriedma-quic wrote:

Missing newline?

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

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


@@ -5451,10 +5451,31 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl 
*Constructor, bool AnyErrors,
NumInitializers * sizeof(CXXCtorInitializer*));
 Constructor->setCtorInitializers(baseOrMemberInitializers);
 
+SourceLocation Location = Constructor->getLocation();
+
+for (CXXCtorInitializer *Initializer : Info.AllToInit) {

efriedma-quic wrote:

Instead of trying to detect the specific fields not handled by 
MarkBaseAndMemberDestructorsReferenced, I think it would be more 
straightforward to split MarkBaseDestructorsReferenced and 
MarkMemberDestructorsReferenced into separate functions, and just don't call 
MarkMemberDestructorsReferenced from here.

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


[clang] [memprof] Export __memprof_default_options_str on Darwin (PR #128920)

2025-02-28 Thread Teresa Johnson via cfe-commits


@@ -1617,6 +1617,10 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 }
   }
 
+  if (Sanitize.needsMemProfRt())
+if (hasExportSymbolDirective(Args))
+  addExportedSymbol(CmdArgs, "___memprof_default_options_str");

teresajohnson wrote:

Can you add a comment about the added `_` prefix? Also, I think it would be 
nice to just move the name to ProfileData/MemProf.h. If I look at the 
ProfileData/InstrProf.h included here for example, it contains helper functions 
to get runtime function names, so this would seem like a good equivalent place 
for memprof.

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


[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

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


@@ -218,12 +221,31 @@ mlir::LogicalResult 
CIRToLLVMGlobalOpLowering::matchAndRewrite(
   SmallVector attributes;
 
   if (init.has_value()) {
-GlobalInitAttrRewriter initRewriter(llvmType, rewriter);
-init = initRewriter.rewriteInitAttr(init.value());
-// If initRewriter returned a null attribute, init will have a value but
-// the value will be null. If that happens, initRewriter didn't handle the
-// attribute type. It probably needs to be added to GlobalInitAttrRewriter.
-if (!init.value()) {
+if (mlir::isa(init.value())) {

andykaylor wrote:

In fact, I see that I did both -- I modified `GlobalInitAttrRewriter` to use 
`TypeSwitch` but I rewrote this code to not use it. I guess that was an 
incomplete refactoring, but the good new is that it will make it easy to update 
it as you've suggested.

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


[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

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


@@ -218,12 +221,31 @@ mlir::LogicalResult 
CIRToLLVMGlobalOpLowering::matchAndRewrite(
   SmallVector attributes;
 
   if (init.has_value()) {
-GlobalInitAttrRewriter initRewriter(llvmType, rewriter);
-init = initRewriter.rewriteInitAttr(init.value());
-// If initRewriter returned a null attribute, init will have a value but
-// the value will be null. If that happens, initRewriter didn't handle the
-// attribute type. It probably needs to be added to GlobalInitAttrRewriter.
-if (!init.value()) {
+if (mlir::isa(init.value())) {

andykaylor wrote:

The `GlobalInitAttrRewriter` would have used a `TypeSwitch` for its internal 
implementation, and since each type being handled/visited is just a single line 
I thought it was just as clean to put it inline here. I can move it back to 
using a separate class if you like.

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


[clang] [Clang][diagnostics] Improve the diagnostics for chained comparisons (PR #129285)

2025-02-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)


Changes

Improve the diagnostics for chained comparisons to report actual expressions 
and operators

Fixes #129069

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


9 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+2-1) 
- (modified) clang/test/Sema/bool-compare.c (+2-2) 
- (modified) clang/test/Sema/parentheses.cpp (+4-4) 
- (modified) clang/test/SemaCXX/bool-compare.cpp (+2-2) 
- (modified) clang/test/SemaCXX/cxx2a-adl-only-template-id.cpp (+1-1) 
- (modified) clang/test/SemaTemplate/typo-dependent-name.cpp (+1-1) 
- (modified) clang/test/SemaTemplate/typo-template-name.cpp (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2b72143482943..a98200f9e931a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -214,6 +214,8 @@ Improvements to Clang's diagnostics
   :doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
   feature will be default-enabled with ``-Wthread-safety`` in a future release.
 
+- Improve the diagnostics for chained comparisons to report actual expressions 
and operators.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d094c075ecee2..b247a4a6e6dfe 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7157,7 +7157,7 @@ def note_precedence_conditional_first : Note<
   "place parentheses around the '?:' expression to evaluate it first">;
 
 def warn_consecutive_comparison : Warning<
-  "comparisons like 'X<=Y<=Z' don't have their mathematical meaning">,
+  "comparisons like '%0 %1 %2' don't have their mathematical meaning">,
   InGroup, DefaultError;
 
 def warn_enum_constant_in_bool_context : Warning<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 1738663327453..e417fc669314d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -14924,7 +14924,8 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation 
OpLoc,
 
 if (const auto *BI = dyn_cast(LHSExpr);
 BI && BI->isComparisonOp())
-  Diag(OpLoc, diag::warn_consecutive_comparison);
+  Diag(OpLoc, diag::warn_consecutive_comparison)
+  << LHS.get() << BinaryOperator::getOpcodeStr(Opc) << RHS.get();
 
 break;
   case BO_EQ:
diff --git a/clang/test/Sema/bool-compare.c b/clang/test/Sema/bool-compare.c
index 861f47864ddd9..4949da1cb501f 100644
--- a/clang/test/Sema/bool-compare.c
+++ b/clang/test/Sema/bool-compare.c
@@ -85,7 +85,7 @@ void f(int x, int y, int z) {
   if ((ayy y < z' don't 
have their mathematical meaning}}
   if ((a z)  {} // no warning
   if((a(zy)  {} // expected-error {{comparisons like 'X<=Y<=Z' don't have 
their mathematical meaning}}
+  if (zy)  {} // expected-error {{comparisons like 'z < a > y' don't 
have their mathematical meaning}}
   if (z > (a(a z);  // expected-warning {{comparisons like 'X<=Y<=Z' don't 
have their mathematical meaning}}
-  (void)(x < y <= z); // expected-warning {{comparisons like 'X<=Y<=Z' don't 
have their mathematical meaning}}
-  (void)(x <= y > z); // expected-warning {{comparisons like 'X<=Y<=Z' don't 
have their mathematical meaning}}
+  (void)(x < y < z);  // expected-warning {{comparisons like 'x < y < z' don't 
have their mathematical meaning}}
+  (void)(x < y > z);  // expected-warning {{comparisons like 'x < y > z' don't 
have their mathematical meaning}}
+  (void)(x < y <= z); // expected-warning {{comparisons like 'x < y <= z' 
don't have their mathematical meaning}}
+  (void)(x <= y > z); // expected-warning {{comparisons like 'x <= y > z' 
don't have their mathematical meaning}}
   (void)((x < y) < z);  // no-warning
   (void)((x < y) >= z); // no-warning
 
diff --git a/clang/test/SemaCXX/bool-compare.cpp 
b/clang/test/SemaCXX/bool-compare.cpp
index 077d55ff9367d..0de8b3a994508 100644
--- a/clang/test/SemaCXX/bool-compare.cpp
+++ b/clang/test/SemaCXX/bool-compare.cpp
@@ -98,7 +98,7 @@ void f(int x, int y, int z) {
   if ((ayy y < z' don't 
have their mathematical meaning}}
   if ((a z)  {} // no warning
   if((a(zy)  {} // expected-error {{comparisons like 'X<=Y<=Z' don't have 
their mathematical meaning}}
+  if (zy)  {} // expected-error {{comparisons like 'z < a > y' don't 
have their mathematical meaning}}
   if (z > (a(a(q); // ok, found by unqualified lookup
 void fn() {
   f<0>(q);
   int f;
-  f<0>(q); // expected-error {{invalid operands to binary expression}} // 
expected-error {{comparisons like 'X<=Y<=Z' don't have their mathematical 
meaning}}
+  f<0>(q); // expected-error {{invalid operands to binary expression}} // 
expected-error {{compari

[clang] [Clang][diagnostics] Fix structured binding shadows template param loc (PR #129116)

2025-02-28 Thread Amr Hesham via cfe-commits

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

>From ed0cf3f026e439288f8334f27555ad26825fd56a Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Thu, 27 Feb 2025 21:49:32 +0100
Subject: [PATCH 1/4] [Clang][diagnostics] Fix structured binding shadows
 template parameter location

---
 clang/lib/Sema/SemaDeclCXX.cpp | 3 +--
 clang/test/CXX/temp/temp.res/temp.local/p6.cpp | 5 +
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 664d48ccbc382..a3a028b9485d6 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -883,8 +883,7 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator &D,
 // It's not permitted to shadow a template parameter name.
 if (Previous.isSingleResult() &&
 Previous.getFoundDecl()->isTemplateParameter()) {
-  DiagnoseTemplateParameterShadow(D.getIdentifierLoc(),
-  Previous.getFoundDecl());
+  DiagnoseTemplateParameterShadow(B.NameLoc, Previous.getFoundDecl());
   Previous.clear();
 }
 
diff --git a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
index 00bb35813c39a..e464bb5e7eaef 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
@@ -162,3 +162,8 @@ struct A {
 };
 A<0>::B a;
 }
+
+template  void shadow9() {  // expected-note{{template parameter 
is declared here}}
+  using arr = int[1]; // expected-warning@+1 {{decomposition declarations are 
a C++17 extension}}
+  auto [T] = arr{}; // expected-error {{declaration of 'T' shadows template 
parameter}}
+}

>From 7712fc1c2406974d64e6fa8c162d12b6090903f2 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Fri, 28 Feb 2025 18:43:54 +0100
Subject: [PATCH 2/4] Add release note and improve testing

---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/test/CXX/temp/temp.res/temp.local/p6.cpp | 6 --
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2b72143482943..b1ea63a01b914 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -214,6 +214,8 @@ Improvements to Clang's diagnostics
   :doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
   feature will be default-enabled with ``-Wthread-safety`` in a future release.
 
+- Improve the diagnostics for shadows template parameter.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
index e464bb5e7eaef..aa00e1b8811ec 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
@@ -163,7 +163,9 @@ struct A {
 A<0>::B a;
 }
 
-template  void shadow9() {  // expected-note{{template parameter 
is declared here}}
+template  void shadow() {  // expected-note{{template parameter is 
declared here}}
   using arr = int[1]; // expected-warning@+1 {{decomposition declarations are 
a C++17 extension}}
-  auto [T] = arr{}; // expected-error {{declaration of 'T' shadows template 
parameter}}
+  auto [
+T // expected-error {{declaration of 'T' shadows template parameter}}
+] = arr{};
 }

>From 780a3b259283834e72dccd1ac34cbeafb0a301d9 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Fri, 28 Feb 2025 19:38:21 +0100
Subject: [PATCH 3/4] Address code review comments

---
 clang/docs/ReleaseNotes.rst| 2 +-
 clang/test/CXX/temp/temp.res/temp.local/p6.cpp | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b1ea63a01b914..6c9eacbb0751d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -214,7 +214,7 @@ Improvements to Clang's diagnostics
   :doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
   feature will be default-enabled with ``-Wthread-safety`` in a future release.
 
-- Improve the diagnostics for shadows template parameter.
+- Improve the diagnostics for shadows template parameter to report correct 
location (#GH129060).
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
index aa00e1b8811ec..ee23bf103d450 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
@@ -164,7 +164,8 @@ A<0>::B a;
 }
 
 template  void shadow() {  // expected-note{{template parameter is 
declared here}}
-  using arr = int[1]; // expected-warning@+1 {{decomposition declarations are 
a C++17 extension}}
+  using arr = int[1];
+  // expected-warning@+1 {{decomposition declarations are a C++17 extension}}
   auto [
 T // expected-err

[clang] Revert "[clang][HIP] Make some math not not work with AMDGCN SPIR-V" (PR #129280)

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

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


[clang] [llvm] [RISCV] Remove Last Traces of User Interrupts (PR #129300)

2025-02-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Sam Elliott (lenary)


Changes

These were left over from when Craig removed 
`__attribute__((interrupt("user")))` support in 
05d0caef6081e1a6cb23a5a5afe43dc82e8ca558.

The tests change "interrupt"="user" into "interrupt"="machine" as they are 
still intending to be interrupt tests. ISelLowering will now reject 
"interrupt"="user". The docs no longer mention "user" as a possible interrupt 
attribute argument.

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


4 Files Affected:

- (modified) clang/include/clang/Basic/AttrDocs.td (+2-2) 
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+1-1) 
- (modified) llvm/test/CodeGen/RISCV/lpad.ll (+1-1) 
- (modified) llvm/test/CodeGen/RISCV/push-pop-popret.ll (+2-2) 


``diff
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index d6d43df44fb21..6e0932f82be20 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2828,8 +2828,8 @@ targets. This attribute may be attached to a function 
definition and instructs
 the backend to generate appropriate function entry/exit code so that it can be
 used directly as an interrupt service routine.
 
-Permissible values for this parameter are ``user``, ``supervisor``,
-and ``machine``. If there is no parameter, then it defaults to machine.
+Permissible values for this parameter are ``supervisor`` and ``machine``. If
+there is no parameter, then it defaults to ``machine``.
 
 Repeated interrupt attribute on the same declaration will cause a warning
 to be emitted. In case of repeated declarations, the last one prevails.
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 4e6b3a224b79b..99977f713d2a0 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -20777,7 +20777,7 @@ SDValue RISCVTargetLowering::LowerFormalArguments(
 StringRef Kind =
   MF.getFunction().getFnAttribute("interrupt").getValueAsString();
 
-if (!(Kind == "user" || Kind == "supervisor" || Kind == "machine"))
+if (!(Kind == "supervisor" || Kind == "machine"))
   report_fatal_error(
 "Function interrupt attribute argument not supported!");
   }
diff --git a/llvm/test/CodeGen/RISCV/lpad.ll b/llvm/test/CodeGen/RISCV/lpad.ll
index f5d06f0924c54..93eda6f10eedb 100644
--- a/llvm/test/CodeGen/RISCV/lpad.ll
+++ b/llvm/test/CodeGen/RISCV/lpad.ll
@@ -279,7 +279,7 @@ define internal void @internal2() {
 }
 
 ; Check interrupt function does not need landing pad.
-define void @interrupt() "interrupt"="user" {
+define void @interrupt() "interrupt"="machine" {
 ; CHECK-LABEL: interrupt:
 ; CHECK:   # %bb.0:
 ; CHECK-NEXT:mret
diff --git a/llvm/test/CodeGen/RISCV/push-pop-popret.ll 
b/llvm/test/CodeGen/RISCV/push-pop-popret.ll
index 1fbdaa76dfb68..65f58d0ecbf24 100644
--- a/llvm/test/CodeGen/RISCV/push-pop-popret.ll
+++ b/llvm/test/CodeGen/RISCV/push-pop-popret.ll
@@ -1769,7 +1769,7 @@ define void @alloca(i32 %n) {
 declare i32 @foo_test_irq(...)
 @var_test_irq = global [32 x i32] zeroinitializer
 
-define void @foo_with_irq() "interrupt"="user" {
+define void @foo_with_irq() "interrupt"="machine" {
 ; RV32IZCMP-LABEL: foo_with_irq:
 ; RV32IZCMP:   # %bb.0:
 ; RV32IZCMP-NEXT:cm.push {ra}, -64
@@ -2273,7 +2273,7 @@ define void @foo_no_irq() {
   ret void
 }
 
-define void @callee_with_irq() "interrupt"="user" {
+define void @callee_with_irq() "interrupt"="machine" {
 ; RV32IZCMP-LABEL: callee_with_irq:
 ; RV32IZCMP:   # %bb.0:
 ; RV32IZCMP-NEXT:cm.push {ra, s0-s11}, -112

``




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


[clang] [llvm] [RISCV] Remove Last Traces of User Interrupts (PR #129300)

2025-02-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sam Elliott (lenary)


Changes

These were left over from when Craig removed 
`__attribute__((interrupt("user")))` support in 
05d0caef6081e1a6cb23a5a5afe43dc82e8ca558.

The tests change "interrupt"="user" into "interrupt"="machine" as they are 
still intending to be interrupt tests. ISelLowering will now reject 
"interrupt"="user". The docs no longer mention "user" as a possible interrupt 
attribute argument.

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


4 Files Affected:

- (modified) clang/include/clang/Basic/AttrDocs.td (+2-2) 
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+1-1) 
- (modified) llvm/test/CodeGen/RISCV/lpad.ll (+1-1) 
- (modified) llvm/test/CodeGen/RISCV/push-pop-popret.ll (+2-2) 


``diff
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index d6d43df44fb21..6e0932f82be20 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2828,8 +2828,8 @@ targets. This attribute may be attached to a function 
definition and instructs
 the backend to generate appropriate function entry/exit code so that it can be
 used directly as an interrupt service routine.
 
-Permissible values for this parameter are ``user``, ``supervisor``,
-and ``machine``. If there is no parameter, then it defaults to machine.
+Permissible values for this parameter are ``supervisor`` and ``machine``. If
+there is no parameter, then it defaults to ``machine``.
 
 Repeated interrupt attribute on the same declaration will cause a warning
 to be emitted. In case of repeated declarations, the last one prevails.
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 4e6b3a224b79b..99977f713d2a0 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -20777,7 +20777,7 @@ SDValue RISCVTargetLowering::LowerFormalArguments(
 StringRef Kind =
   MF.getFunction().getFnAttribute("interrupt").getValueAsString();
 
-if (!(Kind == "user" || Kind == "supervisor" || Kind == "machine"))
+if (!(Kind == "supervisor" || Kind == "machine"))
   report_fatal_error(
 "Function interrupt attribute argument not supported!");
   }
diff --git a/llvm/test/CodeGen/RISCV/lpad.ll b/llvm/test/CodeGen/RISCV/lpad.ll
index f5d06f0924c54..93eda6f10eedb 100644
--- a/llvm/test/CodeGen/RISCV/lpad.ll
+++ b/llvm/test/CodeGen/RISCV/lpad.ll
@@ -279,7 +279,7 @@ define internal void @internal2() {
 }
 
 ; Check interrupt function does not need landing pad.
-define void @interrupt() "interrupt"="user" {
+define void @interrupt() "interrupt"="machine" {
 ; CHECK-LABEL: interrupt:
 ; CHECK:   # %bb.0:
 ; CHECK-NEXT:mret
diff --git a/llvm/test/CodeGen/RISCV/push-pop-popret.ll 
b/llvm/test/CodeGen/RISCV/push-pop-popret.ll
index 1fbdaa76dfb68..65f58d0ecbf24 100644
--- a/llvm/test/CodeGen/RISCV/push-pop-popret.ll
+++ b/llvm/test/CodeGen/RISCV/push-pop-popret.ll
@@ -1769,7 +1769,7 @@ define void @alloca(i32 %n) {
 declare i32 @foo_test_irq(...)
 @var_test_irq = global [32 x i32] zeroinitializer
 
-define void @foo_with_irq() "interrupt"="user" {
+define void @foo_with_irq() "interrupt"="machine" {
 ; RV32IZCMP-LABEL: foo_with_irq:
 ; RV32IZCMP:   # %bb.0:
 ; RV32IZCMP-NEXT:cm.push {ra}, -64
@@ -2273,7 +2273,7 @@ define void @foo_no_irq() {
   ret void
 }
 
-define void @callee_with_irq() "interrupt"="user" {
+define void @callee_with_irq() "interrupt"="machine" {
 ; RV32IZCMP-LABEL: callee_with_irq:
 ; RV32IZCMP:   # %bb.0:
 ; RV32IZCMP-NEXT:cm.push {ra, s0-s11}, -112

``




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


[clang] [CodeGen] Ensure relative vtables use llvm.type.checked.load.relative (PR #126785)

2025-02-28 Thread via cfe-commits

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


[clang] 23efe73 - [HLSL] Add "or" intrinsic (#128979)

2025-02-28 Thread via cfe-commits

Author: metkarpoonam
Date: 2025-02-28T13:54:13-07:00
New Revision: 23efe734fc27544b473ad60ea6eecbd2ec66d20c

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

LOG: [HLSL] Add "or" intrinsic (#128979)

Include HLSL or_intrinsic, add codegen in CGBuiltin, and the
corresponding tests in or.hlsl. Additionally, incorporate
logical-operator-errors to handle both 'and' and 'or' semantic
diagnostics.

Added: 
clang/test/CodeGenHLSL/builtins/or.hlsl
clang/test/SemaHLSL/BuiltIns/logical-operator-errors.hlsl

Modified: 
clang/include/clang/Basic/Builtins.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/hlsl/hlsl_intrinsics.h
clang/lib/Sema/SemaHLSL.cpp

Removed: 
clang/test/SemaHLSL/BuiltIns/and-errors.hlsl



diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 598ae171b1389..f7027331cd6c5 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4783,6 +4783,12 @@ def HLSLAnd : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLOr : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_or"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 def HLSLAny : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_any"];
   let Attributes = [NoThrow, Const];

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 13bffd542e78e..03b8d16b76e0d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19493,6 +19493,11 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 Value *Op1 = EmitScalarExpr(E->getArg(1));
 return Builder.CreateAnd(Op0, Op1, "hlsl.and");
   }
+  case Builtin::BI__builtin_hlsl_or: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+Value *Op1 = EmitScalarExpr(E->getArg(1));
+return Builder.CreateOr(Op0, Op1, "hlsl.or");
+  }
   case Builtin::BI__builtin_hlsl_any: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 return Builder.CreateIntrinsic(

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 239d7a3f59b77..ed008eeb04ba8 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -290,6 +290,28 @@ _HLSL_BUILTIN_ALIAS(__builtin_hlsl_and)
 bool4 and(bool4 x, bool4 y);
 // clang-format on
 
+//===--===//
+// or builtins
+//===--===//
+
+/// \fn bool or(bool x, bool y)
+/// \brief Logically ors two boolean vectors elementwise and produces a bool
+/// vector output.
+
+// TODO: Clean up clang-format marker once we've resolved
+//   https://github.com/llvm/llvm-project/issues/127851
+//
+// clang-format off
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool or(bool, bool);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool2 or(bool2, bool2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool3 or(bool3, bool3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool4 or(bool4, bool4);
+// clang-format on
+
 
//===--===//
 // any builtins
 
//===--===//

diff  --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index ffc3ac1b65854..bfe84b16218b7 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2293,7 +2293,8 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
 
 break;
   }
-  case Builtin::BI__builtin_hlsl_and: {
+  case Builtin::BI__builtin_hlsl_and:
+  case Builtin::BI__builtin_hlsl_or: {
 if (SemaRef.checkArgCount(TheCall, 2))
   return true;
 if (CheckVectorElementCallArgs(&SemaRef, TheCall))

diff  --git a/clang/test/CodeGenHLSL/builtins/or.hlsl 
b/clang/test/CodeGenHLSL/builtins/or.hlsl
new file mode 100644
index 0..69c57c5455f7d
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/or.hlsl
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+//CHECK-LABEL: define noundef i1 @_Z14test_or_scalarbb(
+//CHECK-SAME: i1 noundef [[X:%.*]], i1 noundef [[Y:%.*]]) #[[ATTR0:[0-9]+]] {
+//CHECK-NEXT:  entry:
+//CHECK: [[HLSL_OR:%.*]] = or i1 [[A:%.*]], [[B:%.*]]
+//CHECK: ret i1 [[HLSL_OR]]
+bool test_or_scalar(bool x, bool y)
+{
+return or(x, y);
+}
+
+//CHECK-LABEL: define noundef <2 x i1> @_Z13test_or_bool2Dv2_bS_(
+//CHECK-SAME: <2 x i1> noundef [[X:%.*]], <2 x i1> noundef [[Y:%.*]]) 
#[[ATTR0]] {
+//CHECK-NEXT:  entry:
+//C

[clang] [HLSL] Add "or" intrinsic (PR #128979)

2025-02-28 Thread via cfe-commits

github-actions[bot] wrote:



@metkarpoonam 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/128979
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Docs][NFC] Correct documentation for the CPATH environment variable (PR #129113)

2025-02-28 Thread Tom Honermann via cfe-commits


@@ -733,16 +733,17 @@ ENVIRONMENT
 
 .. envvar:: CPATH
 
-  If this environment variable is present, it is treated as a delimited list of
-  paths to be added to the default system include path list. The delimiter is
-  the platform dependent delimiter, as used in the PATH environment variable.
-
-  Empty components in the environment variable are ignored.
+  This environment variable specifies additional header file search paths which
+  behave as if they were specified with the :option:`-I\` option at
+  the end of the driver command line. Paths are delimited by the platform

tahonermann wrote:

Hmm, I don't have any particularly good ideas that wouldn't duplicate what is 
(or should be) in the referenced description of the `-I` option. What I have 
now is pretty similar to what [gcc 
documents](https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html#index-CPATH).

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


[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

2025-02-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Andy Kaylor (andykaylor)


Changes

The previously upstreamed lowering from ClangIR to LLVM IR diverged from the 
incubator implementation, but when the incubator was updated to incorporate 
these changes some issues arose which require the upstream implementation to be 
modified to re-align with the incubator.

First, in the earlier upstream implementation a CIRAttrVisitor class was 
introduced with the intention that an mlir-tblgen based extension would be 
created to automatically add all CIR attributes to the visitor. When I proposed 
this in mlir-tblgen a reviewer suggested that what I wanted could be better 
accomplished with TypeSwitch.

See https://github.com/llvm/llvm-project/pull/126332

This was done in the incubator, and here I am bringing that implementation 
upstream.

The other issue was that the global op initialization in the incubator had more 
cases than I had accounted for in my previous upstream refactoring. I did still 
refactor the incubator code, but not in quite the same way as the upstream 
code. This change re-aligns the two.

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


3 Files Affected:

- (removed) clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h (-52) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+75-53) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h (-2) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h
deleted file mode 100644
index bbba89cb7e3fd..0
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h
+++ /dev/null
@@ -1,52 +0,0 @@
-//===- CIRAttrVisitor.h - Visitor for CIR attributes *- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// This file defines the CirAttrVisitor interface.
-//
-//===--===//
-
-#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
-#define LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
-
-#include "clang/CIR/Dialect/IR/CIRAttrs.h"
-
-namespace cir {
-
-template  class CirAttrVisitor {
-public:
-  // FIXME: Create a TableGen list to automatically handle new attributes
-  RetTy visit(mlir::Attribute attr) {
-if (const auto intAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirIntAttr(intAttr);
-if (const auto fltAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirFPAttr(fltAttr);
-if (const auto ptrAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirConstPtrAttr(ptrAttr);
-llvm_unreachable("unhandled attribute type");
-  }
-
-  // If the implementation chooses not to implement a certain visit
-  // method, fall back to the parent.
-  RetTy visitCirIntAttr(cir::IntAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-  RetTy visitCirFPAttr(cir::FPAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-  RetTy visitCirConstPtrAttr(cir::ConstPtrAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-
-  RetTy visitCirAttr(mlir::Attribute attr) { return RetTy(); }
-
-  ImplClass &getImpl() { return *static_cast(this); }
-};
-
-} // namespace cir
-
-#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index ba7fab2865116..5d083efcdda6f 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -24,10 +24,10 @@
 #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Export.h"
 #include "mlir/Transforms/DialectConversion.h"
-#include "clang/CIR/Dialect/IR/CIRAttrVisitor.h"
 #include "clang/CIR/Dialect/IR/CIRDialect.h"
 #include "clang/CIR/MissingFeatures.h"
 #include "clang/CIR/Passes.h"
+#include "llvm/ADT/TypeSwitch.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/TimeProfiler.h"
 
@@ -37,41 +37,23 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
-class CIRAttrToValue : public CirAttrVisitor {
+class CIRAttrToValue {
 public:
   CIRAttrToValue(mlir::Operation *parentOp,
  mlir::ConversionPatternRewriter &rewriter,
  const mlir::TypeConverter *converter)
   : parentOp(parentOp), rewriter(rewriter), converter(converter) {}
 
-  mlir::Value lowerCirAttrAsValue(mlir::Attribute attr) { return visit(attr); }
-
-  mlir::Value visitCirIntAttr(cir::IntAttr intAttr) {
-mlir::Location loc = parentOp->getLoc();
-return rewriter.create(
-loc, converter->convertType(intAttr.getType()), intAttr.getValue());
-  }
-
-  mlir::Value visitCirFPAttr(cir::FP

[clang-tools-extra] [clang-tidy] Add new check `readability-use-numeric-limits` (PR #127430)

2025-02-28 Thread Baranov Victor via cfe-commits

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


[clang] [HLSL] Add additional overloads for min and max to allow for mixed scalar and vector arguments (PR #129334)

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

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

Add additional overloads for min and max to support
min(vector, T) and min(T, vector)
max(vector, T) and max(T, vector)
Add tests
Closes #128231 

>From ebaef38c40cba83d4b446a5320d57c86038f8286 Mon Sep 17 00:00:00 2001
From: Sarah Spall 
Date: Fri, 28 Feb 2025 11:18:03 -0800
Subject: [PATCH 1/2] new max overloads + new min overloads

---
 clang/lib/Headers/hlsl/hlsl_intrinsics.h | 360 +++
 1 file changed, 360 insertions(+)

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 239d7a3f59b77..68acdf1720318 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1678,6 +1678,30 @@ half3 max(half3, half3);
 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 half4 max(half4, half4);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half2 max(half2 p0, half p1) {
+  return __builtin_elementwise_max(p0, (half2)p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half2 max(half p0, half2 p1) {
+  return __builtin_elementwise_max((half2)p0, p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half3 max(half3 p0, half p1) {
+  return __builtin_elementwise_max(p0, (half3)p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half3 max(half p0, half3 p1) {
+  return __builtin_elementwise_max((half3)p0, p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half4 max(half4 p0, half p1) {
+  return __builtin_elementwise_max(p0, (half4)p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half4 max(half p0, half4 p1) {
+  return __builtin_elementwise_max((half4)p0, p1);
+}
 
 #ifdef __HLSL_ENABLE_16_BIT
 _HLSL_AVAILABILITY(shadermodel, 6.2)
@@ -1692,6 +1716,30 @@ int16_t3 max(int16_t3, int16_t3);
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int16_t4 max(int16_t4, int16_t4);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t2 max(int16_t2 p0, int16_t p1) {
+  return __builtin_elementwise_max(p0, (int16_t2)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t2 max(int16_t p0, int16_t2 p1) {
+  return __builtin_elementwise_max((int16_t2)p0, p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t3 max(int16_t3 p0, int16_t p1) {
+  return __builtin_elementwise_max(p0, (int16_t3)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t3 max(int16_t p0, int16_t3 p1) {
+  return __builtin_elementwise_max((int16_t3)p0, p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t4 max(int16_t4 p0, int16_t p1) {
+  return __builtin_elementwise_max(p0, (int16_t4)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t4 max(int16_t p0, int16_t4 p1) {
+  return __builtin_elementwise_max((int16_t4)p0, p1);
+}
 
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
@@ -1705,6 +1753,30 @@ uint16_t3 max(uint16_t3, uint16_t3);
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint16_t4 max(uint16_t4, uint16_t4);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t2 max(uint16_t2 p0, uint16_t p1) {
+  return __builtin_elementwise_max(p0, (uint16_t2)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t2 max(uint16_t p0, uint16_t2 p1) {
+  return __builtin_elementwise_max((uint16_t2)p0, p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t3 max(uint16_t3 p0, uint16_t p1) {
+  return __builtin_elementwise_max(p0, (uint16_t3)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t3 max(uint16_t p0, uint16_t3 p1) {
+  return __builtin_elementwise_max((uint16_t3)p0, p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t4 max(uint16_t4 p0, uint16_t p1) {
+  return __builtin_elementwise_max(p0, (uint16_t4)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t4 max(uint16_t p0, uint16_t4 p1) {
+  return __builtin_elementwise_max((uint16_t4)p0, p1);
+}
 #endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
@@ -1715,6 +1787,24 @@ _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int3 max(int3, int3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int4 max(int4, int4);
+constexpr int2 max(int2 p0, int p1) {
+  return __builtin_elementwise_max(p0, (int2)p1);
+}
+constexpr int2 max(int p0, int2 p1) {
+  return __builtin_elementwise_max((int2)p0, p1);
+}
+constexpr int3 max(int3 p0, int p1) {
+  return __builtin_elementwise_max(p0, (int3)p1);
+}
+constexpr int3 max(int p0, int3 p1) {
+  return __builtin_elementwise_max((int3)p0, p1);
+}
+constexpr int4 max(int4 p0, int p1) {
+  return __builtin_elementwise_max(p0, (int4)p1);
+}
+constexpr int4 max(int p0, int4 p1) {
+  return __builtin_elementwise_max((int4)p0, p1);
+}
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint max(uint, uint);
@@ -1724,6 +1814,24 @@ _HLSL_BUILTIN_ALIAS(__builtin_element

[clang] [HLSL] Add additional overloads for min and max to allow for mixed scalar and vector arguments (PR #129334)

2025-02-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Sarah Spall (spall)


Changes

Add additional overloads for min and max to support
min(vector, T) and min(T, vector)
max(vector, T) and max(T, vector)
Add tests
Closes #128231 

---

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


3 Files Affected:

- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+360) 
- (modified) clang/test/CodeGenHLSL/builtins/max.hlsl (+32) 
- (modified) clang/test/CodeGenHLSL/builtins/min.hlsl (+32) 


``diff
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 239d7a3f59b77..68acdf1720318 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1678,6 +1678,30 @@ half3 max(half3, half3);
 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 half4 max(half4, half4);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half2 max(half2 p0, half p1) {
+  return __builtin_elementwise_max(p0, (half2)p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half2 max(half p0, half2 p1) {
+  return __builtin_elementwise_max((half2)p0, p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half3 max(half3 p0, half p1) {
+  return __builtin_elementwise_max(p0, (half3)p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half3 max(half p0, half3 p1) {
+  return __builtin_elementwise_max((half3)p0, p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half4 max(half4 p0, half p1) {
+  return __builtin_elementwise_max(p0, (half4)p1);
+}
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half4 max(half p0, half4 p1) {
+  return __builtin_elementwise_max((half4)p0, p1);
+}
 
 #ifdef __HLSL_ENABLE_16_BIT
 _HLSL_AVAILABILITY(shadermodel, 6.2)
@@ -1692,6 +1716,30 @@ int16_t3 max(int16_t3, int16_t3);
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int16_t4 max(int16_t4, int16_t4);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t2 max(int16_t2 p0, int16_t p1) {
+  return __builtin_elementwise_max(p0, (int16_t2)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t2 max(int16_t p0, int16_t2 p1) {
+  return __builtin_elementwise_max((int16_t2)p0, p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t3 max(int16_t3 p0, int16_t p1) {
+  return __builtin_elementwise_max(p0, (int16_t3)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t3 max(int16_t p0, int16_t3 p1) {
+  return __builtin_elementwise_max((int16_t3)p0, p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t4 max(int16_t4 p0, int16_t p1) {
+  return __builtin_elementwise_max(p0, (int16_t4)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr int16_t4 max(int16_t p0, int16_t4 p1) {
+  return __builtin_elementwise_max((int16_t4)p0, p1);
+}
 
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
@@ -1705,6 +1753,30 @@ uint16_t3 max(uint16_t3, uint16_t3);
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint16_t4 max(uint16_t4, uint16_t4);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t2 max(uint16_t2 p0, uint16_t p1) {
+  return __builtin_elementwise_max(p0, (uint16_t2)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t2 max(uint16_t p0, uint16_t2 p1) {
+  return __builtin_elementwise_max((uint16_t2)p0, p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t3 max(uint16_t3 p0, uint16_t p1) {
+  return __builtin_elementwise_max(p0, (uint16_t3)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t3 max(uint16_t p0, uint16_t3 p1) {
+  return __builtin_elementwise_max((uint16_t3)p0, p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t4 max(uint16_t4 p0, uint16_t p1) {
+  return __builtin_elementwise_max(p0, (uint16_t4)p1);
+}
+_HLSL_AVAILABILITY(shadermodel, 6.2)
+constexpr uint16_t4 max(uint16_t p0, uint16_t4 p1) {
+  return __builtin_elementwise_max((uint16_t4)p0, p1);
+}
 #endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
@@ -1715,6 +1787,24 @@ _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int3 max(int3, int3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 int4 max(int4, int4);
+constexpr int2 max(int2 p0, int p1) {
+  return __builtin_elementwise_max(p0, (int2)p1);
+}
+constexpr int2 max(int p0, int2 p1) {
+  return __builtin_elementwise_max((int2)p0, p1);
+}
+constexpr int3 max(int3 p0, int p1) {
+  return __builtin_elementwise_max(p0, (int3)p1);
+}
+constexpr int3 max(int p0, int3 p1) {
+  return __builtin_elementwise_max((int3)p0, p1);
+}
+constexpr int4 max(int4 p0, int p1) {
+  return __builtin_elementwise_max(p0, (int4)p1);
+}
+constexpr int4 max(int p0, int4 p1) {
+  return __builtin_elementwise_max((int4)p0, p1);
+}
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 uint max(

[clang] [Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` (PR #128409)

2025-02-28 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

I get that we are allowing constexpr unknown values into codegen and that is a 
mistake but I don't totally follow the fix. Can you go into more details?

If I am reading the code correctly there should be some constexpr cases that 
generate a diagnostic, can we verify that with a test?

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


[clang] [HLSL] Add additional overloads for min and max to allow for mixed scalar and vector arguments (PR #129334)

2025-02-28 Thread Joshua Batista via cfe-commits


@@ -1678,6 +1678,30 @@ half3 max(half3, half3);
 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 half4 max(half4, half4);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half2 max(half2 p0, half p1) {

bob80905 wrote:

If a user were to call the max function with, say, a half2 and a half3, is it 
our intention to reject that / emit an error?

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


[clang] [HLSL] Add additional overloads for min and max to allow for mixed scalar and vector arguments (PR #129334)

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


@@ -1678,6 +1678,30 @@ half3 max(half3, half3);
 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 half4 max(half4, half4);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half2 max(half2 p0, half p1) {

spall wrote:

Yes that is my understanding


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


[clang] [HLSL] Add additional overloads for min and max to allow for mixed scalar and vector arguments (PR #129334)

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


@@ -1678,6 +1678,30 @@ half3 max(half3, half3);
 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_max)
 half4 max(half4, half4);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+constexpr half2 max(half2 p0, half p1) {

spall wrote:

We only want to allow things of the form max(vector, T) or max(T, 
vector)

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


[clang] [HLSL] Add additional overloads for min and max to allow for mixed scalar and vector arguments (PR #129334)

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

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


[clang] [CIR] Upstream floating point literal expressions (PR #129304)

2025-02-28 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper created 
https://github.com/llvm/llvm-project/pull/129304

This change adds support for floating point literal expressions

>From d13f2d0d40987302243efad7304a1a006fdb2dde Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Fri, 28 Feb 2025 21:42:36 +0100
Subject: [PATCH] [CIR] Upstream floating point literal expressions

---
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp |  9 +
 clang/test/CIR/func-simple.cpp | 12 
 2 files changed, 21 insertions(+)

diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 24a959108f73b..1b2861ddcedb5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -59,6 +59,15 @@ class ScalarExprEmitter : public 
StmtVisitor {
 builder.getAttr(type, e->getValue()));
   }
 
+  mlir::Value VisitFloatingLiteral(const FloatingLiteral *e) {
+mlir::Type type = cgf.convertType(e->getType());
+assert(mlir::isa(type) &&
+   "expect floating-point type");
+return builder.create(
+cgf.getLoc(e->getExprLoc()), type,
+builder.getAttr(type, e->getValue()));
+  }
+
   mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
 mlir::Type type = cgf.convertType(e->getType());
 return builder.create(
diff --git a/clang/test/CIR/func-simple.cpp b/clang/test/CIR/func-simple.cpp
index 3947055e300a0..5927d90a2e548 100644
--- a/clang/test/CIR/func-simple.cpp
+++ b/clang/test/CIR/func-simple.cpp
@@ -57,3 +57,15 @@ bool boolfunc() { return true; }
 // CHECK:   %0 = cir.const #true
 // CHECK:   cir.return %0 : !cir.bool
 // CHECK: }
+
+float floatfunc() { return 42.42f; }
+// CHECK: cir.func @floatfunc() -> !cir.float {
+// CHECK:   %0 = cir.const #cir.fp<4.242000e+01> : !cir.float
+// CHECK:   cir.return %0 : !cir.float
+// CHECK: }
+
+double doublefunc() { return 42.42; }
+// CHECK: cir.func @doublefunc() -> !cir.double {
+// CHECK:   %0 = cir.const #cir.fp<4.242000e+01> : !cir.double
+// CHECK:   cir.return %0 : !cir.double
+// CHECK: }

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


[clang] [CIR] Upstream floating point literal expressions (PR #129304)

2025-02-28 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clangir

@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)


Changes

This change adds support for floating point literal expressions

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


2 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+9) 
- (modified) clang/test/CIR/func-simple.cpp (+12) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 24a959108f73b..1b2861ddcedb5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -59,6 +59,15 @@ class ScalarExprEmitter : public 
StmtVisitor {
 builder.getAttr(type, e->getValue()));
   }
 
+  mlir::Value VisitFloatingLiteral(const FloatingLiteral *e) {
+mlir::Type type = cgf.convertType(e->getType());
+assert(mlir::isa(type) &&
+   "expect floating-point type");
+return builder.create(
+cgf.getLoc(e->getExprLoc()), type,
+builder.getAttr(type, e->getValue()));
+  }
+
   mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
 mlir::Type type = cgf.convertType(e->getType());
 return builder.create(
diff --git a/clang/test/CIR/func-simple.cpp b/clang/test/CIR/func-simple.cpp
index 3947055e300a0..5927d90a2e548 100644
--- a/clang/test/CIR/func-simple.cpp
+++ b/clang/test/CIR/func-simple.cpp
@@ -57,3 +57,15 @@ bool boolfunc() { return true; }
 // CHECK:   %0 = cir.const #true
 // CHECK:   cir.return %0 : !cir.bool
 // CHECK: }
+
+float floatfunc() { return 42.42f; }
+// CHECK: cir.func @floatfunc() -> !cir.float {
+// CHECK:   %0 = cir.const #cir.fp<4.242000e+01> : !cir.float
+// CHECK:   cir.return %0 : !cir.float
+// CHECK: }
+
+double doublefunc() { return 42.42; }
+// CHECK: cir.func @doublefunc() -> !cir.double {
+// CHECK:   %0 = cir.const #cir.fp<4.242000e+01> : !cir.double
+// CHECK:   cir.return %0 : !cir.double
+// CHECK: }

``




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


[clang] d9edca4 - [CodeGen] Ensure relative vtables use llvm.type.checked.load.relative (#126785)

2025-02-28 Thread via cfe-commits

Author: PiJoules
Date: 2025-02-28T12:26:29-08:00
New Revision: d9edca4fe05245ace93f7f1577a2eb79ec6898b1

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

LOG: [CodeGen] Ensure relative vtables use llvm.type.checked.load.relative 
(#126785)

This intrinsic is used when whole program vtables is used in conjunction
with either CFI or virtual function elimination. The
`llvm.type.checked.load` is unconditionally used, but we need to use the
relative intrinsic for WPD and CFI to work correctly.

Added: 


Modified: 
clang/lib/CodeGen/CGClass.cpp
clang/lib/CodeGen/CGVTables.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/test/CodeGen/fat-lto-objects-cfi.cpp
clang/test/CodeGenCXX/type-metadata.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 7a1096fcbca82..fa69caa41936c 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -2937,9 +2937,13 @@ llvm::Value *CodeGenFunction::EmitVTableTypeCheckedLoad(
   CGM.CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));
   llvm::Value *TypeId = llvm::MetadataAsValue::get(CGM.getLLVMContext(), MD);
 
+  auto CheckedLoadIntrinsic = CGM.getVTables().useRelativeLayout()
+  ? llvm::Intrinsic::type_checked_load_relative
+  : llvm::Intrinsic::type_checked_load;
   llvm::Value *CheckedLoad = Builder.CreateCall(
-  CGM.getIntrinsic(llvm::Intrinsic::type_checked_load),
+  CGM.getIntrinsic(CheckedLoadIntrinsic),
   {VTable, llvm::ConstantInt::get(Int32Ty, VTableByteOffset), TypeId});
+
   llvm::Value *CheckResult = Builder.CreateExtractValue(CheckedLoad, 1);
 
   std::string TypeName = RD->getQualifiedNameAsString();

diff  --git a/clang/lib/CodeGen/CGVTables.h b/clang/lib/CodeGen/CGVTables.h
index c06bf7a525d9f..5c45e355fb145 100644
--- a/clang/lib/CodeGen/CGVTables.h
+++ b/clang/lib/CodeGen/CGVTables.h
@@ -75,10 +75,6 @@ class CodeGenVTables {
 bool vtableHasLocalLinkage,
 bool isCompleteDtor) const;
 
-  bool useRelativeLayout() const;
-
-  llvm::Type *getVTableComponentType() const;
-
 public:
   /// Add vtable components for the given vtable layout to the given
   /// global initializer.
@@ -151,6 +147,12 @@ class CodeGenVTables {
 
   /// Specify a global should not be instrumented with hwasan.
   void RemoveHwasanMetadata(llvm::GlobalValue *GV) const;
+
+  /// Return the type used as components for a vtable.
+  llvm::Type *getVTableComponentType() const;
+
+  /// Return true if the relative vtable layout is used.
+  bool useRelativeLayout() const;
 };
 
 } // end namespace CodeGen

diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index a84412bd5c045..bb9b6fd210667 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2189,12 +2189,14 @@ CGCallee 
ItaniumCXXABI::getVirtualFunctionPointer(CodeGenFunction &CGF,
   uint64_t VTableIndex = 
CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
   llvm::Value *VFunc, *VTableSlotPtr = nullptr;
   auto &Schema = CGM.getCodeGenOpts().PointerAuth.CXXVirtualFunctionPointers;
+
+  llvm::Type *ComponentTy = CGM.getVTables().getVTableComponentType();
+  uint64_t ByteOffset =
+  VTableIndex * CGM.getDataLayout().getTypeSizeInBits(ComponentTy) / 8;
+
   if (!Schema && CGF.ShouldEmitVTableTypeCheckedLoad(MethodDecl->getParent())) 
{
-VFunc = CGF.EmitVTableTypeCheckedLoad(
-MethodDecl->getParent(), VTable, PtrTy,
-VTableIndex *
-CGM.getContext().getTargetInfo().getPointerWidth(LangAS::Default) /
-8);
+VFunc = CGF.EmitVTableTypeCheckedLoad(MethodDecl->getParent(), VTable,
+  PtrTy, ByteOffset);
   } else {
 CGF.EmitTypeMetadataCodeForVCall(MethodDecl->getParent(), VTable, Loc);
 
@@ -2202,7 +2204,7 @@ CGCallee 
ItaniumCXXABI::getVirtualFunctionPointer(CodeGenFunction &CGF,
 if (CGM.getItaniumVTableContext().isRelativeLayout()) {
   VFuncLoad = CGF.Builder.CreateCall(
   CGM.getIntrinsic(llvm::Intrinsic::load_relative, {CGM.Int32Ty}),
-  {VTable, llvm::ConstantInt::get(CGM.Int32Ty, 4 * VTableIndex)});
+  {VTable, llvm::ConstantInt::get(CGM.Int32Ty, ByteOffset)});
 } else {
   VTableSlotPtr = CGF.Builder.CreateConstInBoundsGEP1_64(
   PtrTy, VTable, VTableIndex, "vfn");

diff  --git a/clang/test/CodeGen/fat-lto-objects-cfi.cpp 
b/clang/test/CodeGen/fat-lto-objects-cfi.cpp
index 6eee4229f..a41412e0d5148 100644
--- a/clang/test/CodeGen/fat-lto-objects-cfi.cpp
+++ b/clang/test/CodeGen/fat-lto-objects-cfi.cpp
@@ -70,9 +70,9 @@ void foo(const void* ptr, size_t len

[clang-tools-extra] [clang-tidy] Fix invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (PR #127162)

2025-02-28 Thread via cfe-commits

https://github.com/Andrewyuan34 updated 
https://github.com/llvm/llvm-project/pull/127162

>From 879ef53b6a79f649dd1854c50d55cd6798a06dec Mon Sep 17 00:00:00 2001
From: Andrewyuan34 
Date: Thu, 13 Feb 2025 22:35:36 -0500
Subject: [PATCH] [clang-tidy] Fix invalid fixit from modernize-use-ranges for
 nullptr used with std::unique_ptr

---
 .../clang-tidy/utils/UseRangesCheck.cpp   | 13 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../checkers/modernize/use-ranges.cpp | 26 ---
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index aba4d17ccd035..f7a19cd72d500 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -215,6 +215,19 @@ void UseRangesCheck::check(const MatchFinder::MatchResult 
&Result) {
 const auto *Call = Result.Nodes.getNodeAs(Buffer);
 if (!Call)
   continue;
+
+// FIXME: This check specifically handles `CXXNullPtrLiteralExpr`, but
+// a more general solution might be needed.
+if (Function->getName() == "find") {
+  const unsigned ValueArgIndex = 2;
+  if (Call->getNumArgs() <= ValueArgIndex)
+continue;
+  const Expr *ValueExpr =
+  Call->getArg(ValueArgIndex)->IgnoreParenImpCasts();
+  if (isa(ValueExpr))
+return;
+}
+
 auto Diag = createDiag(*Call);
 if (auto ReplaceName = Replacer->getReplaceName(*Function))
   Diag << FixItHint::CreateReplacement(Call->getCallee()->getSourceRange(),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6b8fe22242417..4fdb5aa367c68 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -109,6 +109,10 @@ Changes in existing checks
 - Improved :doc:`misc-redundant-expression
   ` check by providing additional
   examples and fixing some macro related false positives.
+  
+- Improved :doc:`modernize-use-ranges
+  ` check by updating suppress 
+  warnings logic for ``nullptr`` in ``std::find``.
 
 Removed checks
 ^^
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
index b022efebfdf4d..5aa026038b1cd 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
@@ -1,14 +1,25 @@
-// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I 
%S/Inputs/use-ranges/
-// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t 
-check-suffixes=,CPP23 -- -I %S/Inputs/use-ranges/
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I 
%S/Inputs/
+// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t 
-check-suffixes=,CPP23 -- -I %S/Inputs/
+// Example: ./check_clang_tidy.py -std=c++20 checkers/modernize/use-ranges.cpp 
modernize-use-ranges temp.txt -- -- -I 
~/llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/
 
 // CHECK-FIXES: #include 
 // CHECK-FIXES-CPP23: #include 
 // CHECK-FIXES: #include 
 
-#include "fake_std.h"
+#include "use-ranges/fake_std.h"
+#include "smart-ptr/unique_ptr.h"
 
 void Positives() {
   std::vector I, J;
+  std::vector> K;
+
+  // Expect to have no check messages
+  std::find(K.begin(), K.end(), nullptr);
+
+  std::find(K.begin(), K.end(), std::unique_ptr());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(K, std::unique_ptr());
+
   std::find(I.begin(), I.end(), 0);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(I, 0);
@@ -76,6 +87,15 @@ void Positives() {
 
 void Reverse(){
   std::vector I, J;
+  std::vector> K;
+  
+  // Expect to have no check messages
+  std::find(K.rbegin(), K.rend(), nullptr);
+
+  std::find(K.rbegin(), K.rend(), std::unique_ptr());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(K), 
std::unique_ptr());
+
   std::find(I.rbegin(), I.rend(), 0);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(I), 0);

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


[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

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


@@ -218,12 +221,31 @@ mlir::LogicalResult 
CIRToLLVMGlobalOpLowering::matchAndRewrite(
   SmallVector attributes;
 
   if (init.has_value()) {
-GlobalInitAttrRewriter initRewriter(llvmType, rewriter);
-init = initRewriter.rewriteInitAttr(init.value());
-// If initRewriter returned a null attribute, init will have a value but
-// the value will be null. If that happens, initRewriter didn't handle the
-// attribute type. It probably needs to be added to GlobalInitAttrRewriter.
-if (!init.value()) {
+if (mlir::isa(init.value())) {

andykaylor wrote:

The incubator only has three types that get handled here, but it does look a 
bit cleaner with these being handled separately. There is a possibility that 
the `if` above could get out of sync with the types handled in 
`GlobalInitAttrRewriter` but that would trigger the error below, so we'd catch 
it in development.

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

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


@@ -5451,10 +5451,23 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl 
*Constructor, bool AnyErrors,
NumInitializers * sizeof(CXXCtorInitializer*));
 Constructor->setCtorInitializers(baseOrMemberInitializers);
 
+SourceLocation Location = Constructor->getLocation();
+
+for (CXXCtorInitializer *Initializer : Info.AllToInit) {
+  FieldDecl *Field = Initializer->getAnyMember();
+  if (!Field)
+continue;
+
+  RecordDecl *FieldRecordDecl = Field->getParent();
+  if (!FieldRecordDecl->isUnion() ||

efriedma-quic wrote:

The `member with destructor not allowed in anonymous aggregate` error is 
separate from what we're trying to do here; I'd say don't worry about it.

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


[clang] [ubsan] Remove -fsanitizer=vptr from -fsanitizer=undefined (PR #121115)

2025-02-28 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/121115

>From bca319184733b4bad1eb6b83aaac18a75be40b8c Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 25 Dec 2024 14:22:10 -0800
Subject: [PATCH 1/5] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 clang/test/Driver/sanitizer-ld.c | 303 ++-
 1 file changed, 174 insertions(+), 129 deletions(-)

diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c
index 8f2f7a5997ab4..0c36da1773c9f 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -1,14 +1,17 @@
 // Test sanitizers ld flags.
 
+// RUN: export FILECHECK_OPTS="--implicit-check-not=\"/libclang_rt\""
+
 // RUN: %clang -### %s 2>&1 \
 // RUN: --target=i386-unknown-linux -fuse-ld=ld -fsanitize=address \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-LINUX %s
 //
-// CHECK-ASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld"
 // CHECK-ASAN-LINUX-NOT: "-lc"
-// CHECK-ASAN-LINUX: libclang_rt.asan.a"
+// CHECK-ASAN-LINUX: "--whole-archive" "{{.*}}libclang_rt.asan_static.a" 
"--no-whole-archive"
+// CHECK-ASAN-LINUX: "--whole-archive" "{{.*}}libclang_rt.asan.a" 
"--no-whole-archive"
 // CHECK-ASAN-LINUX-NOT: "--export-dynamic"
 // CHECK-ASAN-LINUX: "--dynamic-list={{.*}}libclang_rt.asan.a.syms"
 // CHECK-ASAN-LINUX-NOT: "--export-dynamic"
@@ -23,17 +26,16 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-LINUX %s
 //
-// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan_static-x86_64
-// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan-x86_64
+// CHECK-ASAN-NO-LINK-RUNTIME-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld"
 
-// RUN: %clang -fsanitize=address -fno-sanitize-link-runtime -### %s 2>&1 \
+// RUN: %clang -fsanitize=address -fsanitize-link-runtime -### %s 2>&1 \
 // RUN: --target=arm64e-apple-macosx -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-DARWIN %s
 //
-// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.asan_static
-// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.asan
+// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: /libclang_rt.asan_osx_dynamic.dylib
+// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: /libclang_rt.osx.a
 
 // RUN: %clang -fsanitize=address -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -41,8 +43,9 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-EXECUTABLE-LINUX %s
 //
-// CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan_static
-// CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan
+// CHECK-ASAN-EXECUTABLE-LINUX: "--whole-archive" 
"{{.*}}libclang_rt.asan_static.a" "--no-whole-archive"
+// CHECK-ASAN-EXECUTABLE-LINUX: "--whole-archive" "{{.*}}libclang_rt.asan.a" 
"--no-whole-archive"
+// CHECK-ASAN-EXECUTABLE-LINUX: "--dynamic-list={{.*}}libclang_rt.asan.a.syms"
 
 // RUN: %clang -fsanitize=address -shared -### %s 2>&1  \
 // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -51,7 +54,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-SHARED-LINUX %s
 //
 // CHECK-ASAN-SHARED-LINUX: libclang_rt.asan_static
-// CHECK-ASAN-SHARED-LINUX-NOT: libclang_rt.asan
 
 // RUN: %clang -### %s 2>&1 \
 // RUN: --target=i386-unknown-linux -fuse-ld=ld -fsanitize=address 
-shared-libsan \
@@ -72,11 +74,11 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-SHARED-ASAN-LINUX %s
 //
-// CHECK-SHARED-ASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-SHARED-ASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld"
 // CHECK-SHARED-ASAN-LINUX-NOT: "-lc"
-// CHECK-SHARED-ASAN-LINUX-NOT: libclang_rt.asan.a"
 // CHECK-SHARED-ASAN-LINUX: libclang_rt.asan.so"
 // CHECK-SHARED-ASAN-LINUX: "--whole-archive" 
"{{.*}}libclang_rt.asan-preinit.a" "--no-whole-archive"
+// CHECK-SHARED-ASAN-LINUX: "--whole-archive" 
"{{.*}}libclang_rt.asan_static.a" "--no-whole-archive"
 // CHECK-SHARED-ASAN-LINUX-NOT: "-lpthread"
 // CHECK-SHARED-ASAN-LINUX-NOT: "-lrt"
 // CHECK-SHARED-ASAN-LINUX-NOT: "-ldl"
@@ -90,11 +92,10 @@
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-DSO-SHARED-ASAN-LINUX %s
 //
-// CHECK-DSO-SHARED-ASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-DSO-SHARED-ASAN-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld"
 // CHECK-DSO-SHARED-ASAN-LINUX-NOT: "-lc"
-// CHECK-DSO-SHARED-ASAN-LINUX-NOT: libclang_rt.asan.a"
-// CHECK-DSO-SHARED-ASAN-LINUX-NOT: "libclang_rt

[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

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


@@ -218,12 +221,31 @@ mlir::LogicalResult 
CIRToLLVMGlobalOpLowering::matchAndRewrite(
   SmallVector attributes;
 
   if (init.has_value()) {
-GlobalInitAttrRewriter initRewriter(llvmType, rewriter);
-init = initRewriter.rewriteInitAttr(init.value());
-// If initRewriter returned a null attribute, init will have a value but
-// the value will be null. If that happens, initRewriter didn't handle the
-// attribute type. It probably needs to be added to GlobalInitAttrRewriter.
-if (!init.value()) {
+if (mlir::isa(init.value())) {

erichkeane wrote:

I am just asking for 1 or the other.  IF we don't need `GlobalInitAttrRewriter` 
(It looks like we don't as you've removed its usage?) we should remove it, not 
update it.  

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


[clang] Add `pragma clang scope [push|pop]` (PR #121025)

2025-02-28 Thread Michael Spencer via cfe-commits


@@ -254,7 +285,7 @@ void Preprocessor::updateModuleMacroInfo(const 
IdentifierInfo *II,
 }
 
 void Preprocessor::dumpMacroInfo(const IdentifierInfo *II) {
-  ArrayRef Leaf;
+  ArrayRef Leaf;

Bigcheese wrote:

This patch has a bunch of unrelated formatting changes, so I'm not sure if 
anything else in this file actually changes.

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


[clang] Add `pragma clang scope [push|pop]` (PR #121025)

2025-02-28 Thread Michael Spencer via cfe-commits

Bigcheese wrote:

Given that some `#pragma`s also impact Sema things, I think `scope` is a bit 
confusing for what it applies to. I think something like `macro_scope` would be 
a better name.

As for the extension itself, I think it could be useful, but I'm not sure how 
our language extension policy applies here for pragmas. This is kind of a 
general purpose extension and would make the code only usable with Clang, as 
conditionally applying the pragma would mean the macros still show up and your 
code breaks (otherwise why would you have the pragma in the first place).

This also hides include guards, and I don't think it does anything about 
include skipping, so it may behave as if the include guard was still there.

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


[clang-tools-extra] [clang-tidy] Add new check `readability-use-numeric-limits` (PR #127430)

2025-02-28 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,84 @@
+// RUN: %check_clang_tidy %s readability-use-numeric-limits %t
+#include 
+
+void constants() {
+  // CHECK-MESSAGES: :[[@LINE+2]]:14: warning: The constant -128 is being 
utilized. Consider using std::numeric_limits::min() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: int8_t a = std::numeric_limits::min();
+  int8_t a = -128;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:14: warning: The constant 127 is being 
utilized. Consider using std::numeric_limits::max() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: int8_t b = std::numeric_limits::max();
+  int8_t b = +127;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:14: warning: The constant 127 is being 
utilized. Consider using std::numeric_limits::max() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: int8_t c = std::numeric_limits::max();
+  int8_t c = 127;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant -32768 is being 
utilized. Consider using std::numeric_limits::min() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: int16_t d = std::numeric_limits::min();
+  int16_t d = -32768;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 32767 is being 
utilized. Consider using std::numeric_limits::max() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: int16_t e = std::numeric_limits::max();
+  int16_t e = +32767;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 32767 is being 
utilized. Consider using std::numeric_limits::max() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: int16_t f = std::numeric_limits::max();
+  int16_t f = 32767;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant -2147483648 is 
being utilized. Consider using std::numeric_limits::min() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: int32_t g = std::numeric_limits::min();
+  int32_t g = -2147483648;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 2147483647 is 
being utilized. Consider using std::numeric_limits::max() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: int32_t h = std::numeric_limits::max();
+  int32_t h = +2147483647;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 2147483647 is 
being utilized. Consider using std::numeric_limits::max() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: int32_t i = std::numeric_limits::max();
+  int32_t i = 2147483647;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 
-9223372036854775808 is being utilized. Consider using 
std::numeric_limits::min() instead [readability-use-numeric-limits]
+  // CHECK-FIXES: int64_t j = std::numeric_limits::min();
+  int64_t j = -9223372036854775808;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 
9223372036854775807 is being utilized. Consider using 
std::numeric_limits::max() instead [readability-use-numeric-limits]
+  // CHECK-FIXES: int64_t k = std::numeric_limits::max();
+  int64_t k = +9223372036854775807;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 
9223372036854775807 is being utilized. Consider using 
std::numeric_limits::max() instead [readability-use-numeric-limits]
+  // CHECK-FIXES: int64_t l = std::numeric_limits::max();
+  int64_t l = 9223372036854775807;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 255 is being 
utilized. Consider using std::numeric_limits::max() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: uint8_t m = std::numeric_limits::max();
+  uint8_t m = 255;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 255 is being 
utilized. Consider using std::numeric_limits::max() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: uint8_t n = std::numeric_limits::max();
+  uint8_t n = +255;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 65535 is being 
utilized. Consider using std::numeric_limits::max() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: uint16_t o = std::numeric_limits::max();
+  uint16_t o = 65535;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 65535 is being 
utilized. Consider using std::numeric_limits::max() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: uint16_t p = std::numeric_limits::max();
+  uint16_t p = +65535;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 4294967295 is 
being utilized. Consider using std::numeric_limits::max() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: uint32_t q = std::numeric_limits::max();
+  uint32_t q = 4294967295;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 4294967295 is 
being utilized. Consider using std::numeric_limits::max() instead 
[readability-use-numeric-limits]
+  // CHECK-FIXES: uint32_t r = std::numeric_limits::max();
+  uint32_t r = +4294967295;
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 
18446744073709551615 is being utilized. Consider using 
std::numeric_limits::max() instead [readabilit

[clang] [Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` (PR #128409)

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

efriedma-quic wrote:

Here's a testcase that's should generate a diagnostic, but doesn't without this 
patch:

```
int &ff(); int &x = ff(); constinit int &z = x;
```

Some related testcases are a little weird... consider the following:

```
extern int &x; int &z = x;
```

There's a gap between checking for constant expressions, and codegen, due to 
the following diagnostic; it triggers in constexpr, but allows evaluating for 
the value because a CCEDiag doesn't stop the evaluation: 
https://github.com/llvm/llvm-project/blob/52c81598da38532c119db9c06fcc3d7f9c332a8e/clang/lib/AST/ExprConstant.cpp#L3607
 .

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


[clang] [analyzer] Do list initialization for CXXNewExpr with initializer list arg (PR #127702)

2025-02-28 Thread Michael Flanders via cfe-commits

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


[clang] Fix fp8-init-list.c test failure (PR #129259)

2025-02-28 Thread via cfe-commits

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


[clang] [HLSL] Add "or" intrinsic (PR #128979)

2025-02-28 Thread Ashley Coleman via cfe-commits

https://github.com/V-FEXrt approved this pull request.


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


[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

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


@@ -37,63 +37,78 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
-class CIRAttrToValue : public CirAttrVisitor {
+class CIRAttrToValue {
 public:
   CIRAttrToValue(mlir::Operation *parentOp,
  mlir::ConversionPatternRewriter &rewriter,
  const mlir::TypeConverter *converter)
   : parentOp(parentOp), rewriter(rewriter), converter(converter) {}
 
-  mlir::Value lowerCirAttrAsValue(mlir::Attribute attr) { return visit(attr); }
-
-  mlir::Value visitCirIntAttr(cir::IntAttr intAttr) {
-mlir::Location loc = parentOp->getLoc();
-return rewriter.create(
-loc, converter->convertType(intAttr.getType()), intAttr.getValue());
-  }
-
-  mlir::Value visitCirFPAttr(cir::FPAttr fltAttr) {
-mlir::Location loc = parentOp->getLoc();
-return rewriter.create(
-loc, converter->convertType(fltAttr.getType()), fltAttr.getValue());
+  mlir::Value visit(mlir::Attribute attr) {
+return llvm::TypeSwitch(attr)
+.Case(

erichkeane wrote:

Its a shame this is such a manual list/sub-par interface here :/  it would be 
way neater if it was able to deduce these.  *sigh*

That said, I think this is quite a bit of a nicer interface, so I'm ok with it.

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


[clang-tools-extra] [clang-tidy] warn when `true` is used as a preprocessor keyword in C (PR #128265)

2025-02-28 Thread Richard Smith via cfe-commits

zygoloid wrote:

> > 2. Create check that forbids usage of true/false in processor as an 
> > non-portable thing (could be in portability category)
> > 3. Extracting 'true' case from -Wundef into separate warning like 
> > -Wundef-true
> 
> I like both of these approaches, though I prefer the 2. one because even if 
> we extract `-Wundef-true`, `gcc` won't have the same option.

That's true, but somewhat irrelevant, especially if we enable `-Wundef-true` in 
clang by default.

Clang-tidy uses clang to process the source file, so any warning implemented in 
clang is available to all clang-tidy users regardless of whether they compile 
with clang or GCC or something else. So if we implement this in clang, then any 
clang user gets the warning, and any clang-tidy user gets the warning too (even 
if they compile with GCC). But if we implement it in clang-tidy, then clang 
users who don't use clang-tidy only get the warning if they enable `-Wundef`, 
which is less useful and probably not something people can realistically 
enable. So it's no worse for any user, and better for some, to implement this 
as a compiler warning. And that's the right place for it anyway.

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


[clang-tools-extra] [clang-tidy] warn when `true` is used as a preprocessor keyword in C (PR #128265)

2025-02-28 Thread Richard Smith via cfe-commits

zygoloid wrote:

Perhaps we could split off a warning from `-Wundef` for the specific case where 
the undefined macro name is `true`, and enable it by default? Doing this in a 
clang-tidy check seems like the wrong place -- this check is much better suited 
to being implemented as a compiler warning.

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


[clang] [HLSL] Add "or" intrinsic (PR #128979)

2025-02-28 Thread Ashley Coleman via cfe-commits

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


[clang-tools-extra] [clang-tidy] warn when `true` is used as a preprocessor keyword in C (PR #128265)

2025-02-28 Thread Richard Smith via cfe-commits

zygoloid wrote:

> 1. Not adding check if -Wundef is sufficient
> 2. Create check that forbids usage of true/false in processor as an 
> non-portable thing (could be in portability category)
> 3. Extracting 'true' case from -Wundef into separate warning like -Wundef-true

Option 3 seems best to me. This check is much better suited to being done in 
the compiler rather than after the fact in a checker, and indeed we are already 
warning in the preprocessor. Splitting out a sub-warning `-Wundef-true` and 
enabling it by default seems like a great choice here.

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


[clang] [AMDGPU][clang] provide device implementation for __builtin_logb and … (PR #129347)

2025-02-28 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: choikwa (choikwa)


Changes

…__builtin_scalbn

Clang generates library calls for __builtin_* functions which can be a problem 
for GPUs that cannot handle them. This patch generates call to device 
implementation for __builtin_logb and ldexp intrinsic for __builtin_scalbn.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+48-1) 
- (modified) clang/lib/CodeGen/CodeGenModule.h (+5) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 03b8d16b76e0d..6a0497df7acfb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -259,6 +259,26 @@ Value *readX18AsPtr(CodeGenFunction &CGF) {
   return CGF.Builder.CreateIntToPtr(X18, CGF.Int8PtrTy);
 }
 
+llvm::Constant *CodeGenModule::getDeviceLibFunction(const FunctionDecl *FD,
+unsigned BuiltinID) {
+  GlobalDecl D(FD);
+  llvm::SmallString<64> Name;
+  if (getTarget().getTriple().isAMDGCN()) {
+switch (BuiltinID) {
+default: return nullptr;
+case Builtin::BIlogb:
+case Builtin::BI__builtin_logb:
+  Name = "__ocml_logb_f64";
+}
+  }
+  if (Name.empty())
+return nullptr;
+
+  llvm::FunctionType *Ty =
+cast(getTypes().ConvertType(FD->getType()));
+  return GetOrCreateLLVMFunction(Name, Ty, D, /*ForVTable*/false);
+}
+
 /// getBuiltinLibFunction - Given a builtin id for a function like
 /// "__builtin_fabsf", return a Function* for "fabsf".
 llvm::Constant *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD,
@@ -6579,10 +6599,32 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
   }
   }
 
+  // Some targets like GPUs do not support library call and must provide
+  // device overload implementation.
+  if (getTarget().getTriple().isAMDGCN())
+// Emit library call to device-lib implementation
+if (auto *DevLibFunc = CGM.getDeviceLibFunction(FD, BuiltinID))
+  return emitLibraryCall(*this, FD, E, DevLibFunc);
+
+  // These will be emitted as Intrinsic later.
+  auto NeedsDeviceOverloadToIntrin = [&](unsigned BuiltinID) {
+if (getTarget().getTriple().isAMDGCN()) {
+  switch (BuiltinID) {
+  default:
+return false;
+  case Builtin::BIscalbn:
+  case Builtin::BI__builtin_scalbn:
+return true;
+  }
+}
+return false;
+  };
+
   // If this is an alias for a lib function (e.g. __builtin_sin), emit
   // the call using the normal call path, but using the unmangled
   // version of the function name.
-  if (getContext().BuiltinInfo.isLibFunction(BuiltinID))
+  if (!NeedsDeviceOverloadToIntrin(BuiltinID) &&
+  getContext().BuiltinInfo.isLibFunction(BuiltinID))
 return emitLibraryCall(*this, FD, E,
CGM.getBuiltinLibFunction(FD, BuiltinID));
 
@@ -20804,6 +20846,11 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_s_prefetch_data:
 return emitBuiltinWithOneOverloadedType<2>(
 *this, E, Intrinsic::amdgcn_s_prefetch_data);
+  case Builtin::BIscalbn:
+  case Builtin::BI__builtin_scalbn:
+return emitBinaryExpMaybeConstrainedFPBuiltin(
+*this, E, Intrinsic::ldexp,
+Intrinsic::experimental_constrained_ldexp);
   default:
 return nullptr;
   }
diff --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index 4a269f622ece4..890dc8556cc1c 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1231,6 +1231,11 @@ class CodeGenModule : public CodeGenTypeCache {
   llvm::FunctionType *FnType = nullptr, bool DontDefer = false,
   ForDefinition_t IsForDefinition = NotForDefinition);
 
+  /// Given a builtin id for a function, return a Function* for device
+  /// overload implementation.
+  llvm::Constant *getDeviceLibFunction(const FunctionDecl *FD,
+   unsigned BuiltinID);
+
   /// Given a builtin id for a function like "__builtin_fabsf", return a
   /// Function* for "fabsf".
   llvm::Constant *getBuiltinLibFunction(const FunctionDecl *FD,

``




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


[clang] [AMDGPU][clang] provide device implementation for __builtin_logb and … (PR #129347)

2025-02-28 Thread via cfe-commits

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


  1   2   3   4   >