[libclc] libclc: frexp: fix implementation regarding denormals (PR #134823)

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


@@ -26,7 +26,7 @@ __clc_frexp(__CLC_GENTYPE x, __CLC_ADDRESS_SPACE __CLC_INTN 
*ep) {
   (ai & (__CLC_INTN)MANTBITS_SP32);
 
   __CLC_INTN is_inf_nan_or_zero =
-  x == __CLC_FP_LIT(0.0) || __clc_isinf(x) || __clc_isnan(x);
+  ai == (__CLC_INTN)0 || __clc_isinf(x) || __clc_isnan(x);

frasercrmck wrote:

I know this was in the original code that we're essentially reverting to, but 
do we know this is correct for `-0.0`?

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


[clang] [clang] consistently quote expressions in diagnostics (PR #134769)

2025-04-08 Thread via cfe-commits


@@ -11683,7 +11683,10 @@ static void DiagnoseIntInBoolContext(Sema &S, Expr *E) 
{
 S.Diag(ExprLoc, diag::warn_left_shift_always)
 << (Result.Val.getInt() != 0);
   else if (E->getType()->isSignedIntegerType())
-S.Diag(ExprLoc, diag::warn_left_shift_in_bool_context) << E;
+S.Diag(ExprLoc, diag::warn_left_shift_in_bool_context)
+<< FixItHint::CreateInsertion(E->getBeginLoc(), "(")
+<< 
FixItHint::CreateInsertion(S.getLocForEndOfToken(E->getEndLoc()),
+  ") != 0");

cor3ntin wrote:

How is that related?

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


[clang] [clang] consistently quote expressions in diagnostics (PR #134769)

2025-04-08 Thread via cfe-commits


@@ -1144,20 +1144,25 @@ FormatDiagnostic(const char *DiagStr, const char 
*DiagEnd,
 
 switch (Kind) {
 //  STRINGS 
-case DiagnosticsEngine::ak_std_string: {
-  const std::string &S = getArgStdStr(ArgNo);
-  assert(ModifierLen == 0 && "No modifiers for strings yet");
-  EscapeStringForDiagnostic(S, OutStr);
-  break;
-}
+case DiagnosticsEngine::ak_std_string:
 case DiagnosticsEngine::ak_c_string: {
-  const char *S = getArgCStr(ArgNo);
-  assert(ModifierLen == 0 && "No modifiers for strings yet");
-
-  // Don't crash if get passed a null pointer by accident.
-  if (!S)
-S = "(null)";
+  StringRef S = [&]() -> StringRef {
+if (Kind == DiagnosticsEngine::ak_std_string)
+  return getArgStdStr(ArgNo);
+const char *SZ = getArgCStr(ArgNo);
+// Don't crash if get passed a null pointer by accident.
+return SZ ? SZ : "(null)";
+  }();
+  bool Quoted = false;
+  if (ModifierIs(Modifier, ModifierLen, "quoted")) {
+Quoted = true;
+OutStr.push_back('\'');
+  } else {
+assert(ModifierLen == 0 && "unknown modifier for string");
+  }

cor3ntin wrote:

Do we want to assert we don't end up with double quotes?

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

choikwa wrote:

Updated and addressed feedback except the triplet check. At the moment, I'm 
unsure if there is better way than to query using llvm::isLibFuncEmittable, but 
that requires TLI.

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-tools-extra] [clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers (PR #134774)

2025-04-08 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

> I found interesting was the fact that you could access the 
> implementation-defined internal array field

Yes, this is required in order for `std::array` to be an aggregate type.

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


[clang] [Clang] Handle default template arguments for alias CTAD guides (PR #134807)

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

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


[clang] [Clang] Handle default template arguments for alias CTAD guides (PR #134807)

2025-04-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

It's possible that some deduced template arguments come from default arguments, 
not just from the return type. So we need to recursively visit the default 
arguments of the parameter if it's referenced, thereby the template parameter 
referenced by the defualt arguments could come along to the synthesized 
deduction guide.

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

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Sema/SemaTemplateDeductionGuide.cpp (+17) 
- (modified) clang/test/SemaTemplate/deduction-guide.cpp (+39) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e671183522565..aa57b995a6433 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -390,6 +390,7 @@ Bug Fixes to C++ Support
 - Clang no longer crashes when trying to unify the types of arrays with
   certain differences in qualifiers (this could happen during template argument
   deduction or when building a ternary operator). (#GH97005)
+- Fixed type alias CTAD issues involving default template arguments. 
(#GH134471)
 - The initialization kind of elements of structured bindings
   direct-list-initialized from an array is corrected to direct-initialization.
 - Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. 
(#GH127327)
diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index b4863cefc3fb4..30376ca774384 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -690,6 +690,23 @@ SmallVector 
TemplateParamsReferencedInTemplateArgumentList(
   SemaRef.MarkUsedTemplateParameters(
   DeducedArgs, TemplateParamsList->getDepth(), ReferencedTemplateParams);
 
+  auto MarkDefaultArgs = [&](auto *Param) {
+if (!Param || !Param->hasDefaultArgument())
+  return;
+SemaRef.MarkUsedTemplateParameters(
+Param->getDefaultArgument().getArgument(),
+TemplateParamsList->getDepth(), ReferencedTemplateParams);
+  };
+
+  for (unsigned Index = 0; Index < TemplateParamsList->size(); ++Index) {
+if (!ReferencedTemplateParams[Index])
+  continue;
+auto *Param = TemplateParamsList->getParam(Index);
+MarkDefaultArgs(dyn_cast(Param));
+MarkDefaultArgs(dyn_cast(Param));
+MarkDefaultArgs(dyn_cast(Param));
+  }
+
   SmallVector Results;
   for (unsigned Index = 0; Index < TemplateParamsList->size(); ++Index) {
 if (ReferencedTemplateParams[Index])
diff --git a/clang/test/SemaTemplate/deduction-guide.cpp 
b/clang/test/SemaTemplate/deduction-guide.cpp
index 6db132ca37c7e..76b6cb051b7dd 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -771,3 +771,42 @@ D d(24);
 // CHECK-NEXT:  `-ParmVarDecl {{.+}} 'U'
 
 } // namespace GH132616_DeductionGuide
+
+namespace GH133132 {
+
+template 
+struct A {};
+
+template 
+using AA = A;
+
+AA a{};
+
+// CHECK-LABEL: Dumping GH133132:::
+// CHECK-NEXT:  FunctionTemplateDecl {{.+}} implicit 
+// CHECK-NEXT:  |-TemplateTypeParmDecl {{.+}} class depth 0 index 0 T
+// CHECK-NEXT:  | `-TemplateArgument type 'int'
+// CHECK-NEXT:  |   `-BuiltinType {{.+}} 'int'
+// CHECK-NEXT:  |-TemplateTypeParmDecl {{.+}} class depth 0 index 1 U
+// CHECK-NEXT:  | `-TemplateArgument type 'T':'type-parameter-0-0'
+// CHECK-NEXT:  |   `-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0
+// CHECK-NEXT:  | `-TemplateTypeParm {{.+}} 'T'
+// CHECK-NEXT:  |-TypeTraitExpr {{.+}} 'bool' __is_deducible
+// CHECK-NEXT:  | |-DeducedTemplateSpecializationType {{.+}} 'GH133132::AA' 
dependent
+// CHECK-NEXT:  | | `-name: 'GH133132::AA'
+// CHECK-NEXT:  | |   `-TypeAliasTemplateDecl {{.+}} AA
+// CHECK-NEXT:  | `-TemplateSpecializationType {{.+}} 'A' dependent
+// CHECK-NEXT:  |   |-name: 'A':'GH133132::A' qualified
+// CHECK-NEXT:  |   | `-ClassTemplateDecl {{.+}} A
+// CHECK-NEXT:  |   `-TemplateArgument type 'U':'type-parameter-0-1'
+// CHECK-NEXT:  | `-SubstTemplateTypeParmType {{.+}} 'U' sugar dependent 
class depth 0 index 0 _Ty
+// CHECK-NEXT:  |   |-FunctionTemplate {{.+}} ''
+// CHECK-NEXT:  |   `-TemplateTypeParmType {{.+}} 'U' dependent depth 0 
index 1
+// CHECK-NEXT:  | `-TemplateTypeParm {{.+}} 'U'
+// CHECK-NEXT:  |-CXXDeductionGuideDecl {{.+}} implicit  'auto () -> A'
+// CHECK-NEXT:  `-CXXDeductionGuideDecl {{.+}} implicit used  'auto () -> A' implicit_instantiation
+// CHECK-NEXT:|-TemplateArgument type 'int'
+// CHECK-NEXT:| `-BuiltinType {{.+}} 'int'
+// CHECK-NEXT:`-TemplateArgument type 'int'
+// CHECK-NEXT:  `-BuiltinType {{.+}} 'int'
+}

``




https://github.com/llvm/llvm-project/pull/134807
___
cfe-commits mailing list
c

[clang] [Clang][CodeGen] Respect -fwrapv-pointer when emitting struct GEPs (PR #134269)

2025-04-08 Thread Yingwei Zheng via cfe-commits


@@ -10,3 +10,24 @@ void test(void) {
   // DEFAULT: getelementptr inbounds nuw i32, ptr
   // FWRAPV-POINTER: getelementptr i32, ptr
 }
+
+struct S {
+  int a;
+  int b;
+  int c: 10;

dtcxzyw wrote:

Bitfields are handled by a different code path: 
https://github.com/llvm/llvm-project/blob/2c1bdd4a0811af89eb9631935fbd90f13a04eacb/clang/lib/CodeGen/CGExpr.cpp#L4977

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


[clang] [WIP] Implement `-dump-deserialized-declaration-ranges` flag. (PR #133910)

2025-04-08 Thread Viktoriia Bakalova via cfe-commits

https://github.com/VitaNuo updated 
https://github.com/llvm/llvm-project/pull/133910

>From cfa057b4d43ebe7f94ccd4f387a94359beaa29b2 Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Fri, 4 Apr 2025 17:45:24 +0200
Subject: [PATCH 1/4] This commit implements a CC1 flag
 `-dump-deserialized-declaration-ranges`. The flag allows to specify a file
 path to dump ranges of deserialized declarations in `ASTReader`. Example
 usage:

```
clang -Xclang=-dump-deserialized-declaration-ranges=/tmp/decls -c file.cc -o 
file.o
```

Example output:
```
// /tmp/decls
{
  "required_ranges": [
{
  "file": "foo.h",
  "range": [
{
  "from": {
"line": 26,
"column": 1
  },
  "to": {
"line": 27,
"column": 77
  }
}
  ]
},
{
  "file": "bar.h",
  "range": [
{
  "from": {
"line": 30,
"column": 1
  },
  "to": {
"line": 35,
"column": 1
  }
},
{
  "from": {
"line": 92,
"column": 1
  },
  "to": {
"line": 95,
"column": 1
  }
}
  ]
}
  ]
}

```
Specifying the flag creates an instance of `DeserializedDeclsLineRangePrinter`, 
which dumps ranges of deserialized declarations to aid debugging and bug 
minimization.

Required ranges are computed from source ranges of Decls. 
`TranslationUnitDecl`, `LinkageSpecDecl` and `NamespaceDecl` are ignored for 
the sake of this PR.

Technical details:
* `DeserializedDeclsLineRangePrinter` implements `ASTConsumer` and 
`ASTDeserializationListener`, so that an object of 
`DeserializedDeclsLineRangePrinter` registers as its own listener.
* `ASTDeserializationListener` interface provides the `DeclRead` callback that 
we use to collect the deserialized Decls.
Printing or otherwise processing them as this point is dangerous, since that 
could trigger additional deserialization and crash compilation.
* The collected Decls are processed in `HandleTranslationUnit` method of 
`ASTConsumer`. This is a safe point, since we know that by this point all the 
Decls needed by the compiler frontend have been deserialized.
*  In case our processing causes further deserialization, `DeclRead` from the 
listener might be called again. However, at that point we don't accept any more 
Decls for processing.
---
 clang/include/clang/Driver/Options.td |   4 +
 .../include/clang/Frontend/FrontendOptions.h  |   3 +
 clang/lib/Frontend/FrontendAction.cpp | 190 +-
 .../dump-deserialized-declaration-ranges.cpp  | 118 +++
 4 files changed, 310 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Frontend/dump-deserialized-declaration-ranges.cpp

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3af072242d039..1737e40b776e1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -7968,6 +7968,10 @@ def print_dependency_directives_minimized_source : 
Flag<["-"],
   "print-dependency-directives-minimized-source">,
   HelpText<"Print the output of the dependency directives source minimizer">;
 }
+def dump_deserialized_declaration_ranges : Joined<["-"],
+  "dump-deserialized-declaration-ranges=">,
+  HelpText<"Dump ranges of deserialized declarations to aid debugging and 
minimization">,
+  MarshallingInfoString>;
 
 defm emit_llvm_uselists : BoolOption<"", "emit-llvm-uselists",
   CodeGenOpts<"EmitLLVMUseLists">, DefaultFalse,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index a9c9849ff52ab..8ef9ce9db8783 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -530,6 +530,9 @@ class FrontendOptions {
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
+  /// Output path to dump ranges of deserialized declarations.
+  std::string DumpDeserializedDeclarationRangesPath;
+
 public:
   FrontendOptions()
   : DisableFree(false), RelocatablePCH(false), ShowHelp(false),
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 2d77f06be7446..1f939f7722d19 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -15,6 +15,8 @@
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/LangStandard.h"
 #include "clang/Basic/Sarif.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Stack.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -35,6 +37,7 @@
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/

[clang] bb50061 - [CodeGen] Change placeholder from `undef` to `poison` (#134731)

2025-04-08 Thread via cfe-commits

Author: Pedro Lobo
Date: 2025-04-08T09:50:48+01:00
New Revision: bb5006169f9f72a87b4358356976e0fa33353728

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

LOG: [CodeGen] Change placeholder from `undef` to `poison` (#134731)

Fill default values of a map with `poison` instead of `undef`. There
should be no functional difference as the default values are overridden
later.

Added: 


Modified: 
clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index ba5f74f153d59..7bef436302526 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -370,7 +370,7 @@ class MicrosoftCXXABI : public CGCXXABI {
 MicrosoftVTableContext &VTContext = CGM.getMicrosoftVTableContext();
 unsigned NumEntries = 1 + SrcRD->getNumVBases();
 SmallVector Map(NumEntries,
- llvm::UndefValue::get(CGM.IntTy));
+ llvm::PoisonValue::get(CGM.IntTy));
 Map[0] = llvm::ConstantInt::get(CGM.IntTy, 0);
 bool AnyDifferent = false;
 for (const auto &I : SrcRD->vbases()) {



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


[clang] [CodeGen] Change placeholder from `undef` to `poison` (PR #134731)

2025-04-08 Thread Pedro Lobo via cfe-commits

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


[clang] [llvm] Add clang driver changes to support MTI RISC-V (PR #134065)

2025-04-08 Thread Djordje Todorovic via cfe-commits

djtodoro wrote:

> There's a lot going on here that has absolutely no explanation (no comments 
> in the code, and the commit message is a single sentence that tells me 
> nothing of use), and it's doing multiple different things. There's changing 
> default arch strings, which makes some sense (well, it makes sense for you to 
> want, I just don't love that changing the vendor changes -march, it's already 
> confusing enough that baremetal and Unix-y triples have different defaults, 
> but that ship has sailed). There's a whole bunch of -EL/-EB flag handling 
> which doesn't make sense, I don't understand why MIPS triples need it when 
> all the other vendors don't. Then there's extra sysroot stuff where again I 
> don't understand why there are cases where only MIPS wants --sysroot= to 
> work. Plus unexplained multilib changes.
> 
> I really don't want to see a proliferation of undocumented vendor-specific 
> quirks. If there are things the generic RISC-V code currently omits then 
> those should be added via standalone, well-documented (including in the 
> commit message) commits. If there are things that need to be vendor-specific 
> then they need explaining why they are there.

@jrtc27 Well, I do agree with the comment. We have some kind of an initial 
support for BE, and I left those lines there, which are NOOPs at the moment, 
but that can serve as a placeholder where we need to add BE related code in the 
future, but, I agree, it should have been added either with a decent comment, 
or not at all. Now that I think again, it introduces confusion only, so I will 
remove that part, and plan to post a new patch (or patch series) that will 
handle BE in a non-vendor specific way. Thanks!

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


[clang] [llvm] [NVPTX] Add builtins and intrinsics for conversions of new FP types (PR #134345)

2025-04-08 Thread Srinivasa Ravi via cfe-commits


@@ -1021,6 +1036,174 @@ __device__ void nvvm_cvt_sm89() {
   __nvvm_e5m2x2_to_f16x2_rn(0x4c4c);
   // CHECK_PTX81_SM89: call <2 x half> @llvm.nvvm.e5m2x2.to.f16x2.rn.relu(i16 
19532)
   __nvvm_e5m2x2_to_f16x2_rn_relu(0x4c4c);
+
+  // CHECK_PTX81_SM89: call i32 @llvm.nvvm.f2tf32.rna.satfinite(float 
1.00e+00)
+  __nvvm_f2tf32_rna_satfinite(1.0f);
+#endif
+  // CHECK: ret void
+}
+
+// CHECK-LABEL: nvvm_cvt_sm90
+__device__ void nvvm_cvt_sm90() {
+#if (PTX >= 78) && (__CUDA_ARCH__ >= 900)
+  // CHECK_PTX78_SM90: call i32 @llvm.nvvm.f2tf32.rn(float 1.00e+00)
+  __nvvm_f2tf32_rn(1.0f); 
+  // CHECK_PTX78_SM90: call i32 @llvm.nvvm.f2tf32.rn.relu(float 1.00e+00)
+  __nvvm_f2tf32_rn_relu(1.0f); 
+  // CHECK_PTX78_SM90: call i32 @llvm.nvvm.f2tf32.rz(float 1.00e+00)
+  __nvvm_f2tf32_rz(1.0f); 
+  // CHECK_PTX78_SM90: call i32 @llvm.nvvm.f2tf32.rz.relu(float 1.00e+00)
+  __nvvm_f2tf32_rz_relu(1.0f); 
+#endif
+  // CHECK: ret void
+}
+
+// CHECK-LABEL: nvvm_cvt_sm100
+__device__ void nvvm_cvt_sm100() {
+#if (PTX >= 86) && (__CUDA_ARCH__ >= 1000)
+  // CHECK_PTX86_SM100: call i32 @llvm.nvvm.f2tf32.rn.satfinite(float 
1.00e+00)
+  __nvvm_f2tf32_rn_satfinite(1.0f); 
+  // CHECK_PTX86_SM100: call i32 @llvm.nvvm.f2tf32.rn.relu.satfinite(float 
1.00e+00)
+  __nvvm_f2tf32_rn_relu_satfinite(1.0f); 
+  // CHECK_PTX86_SM100: call i32 @llvm.nvvm.f2tf32.rz.satfinite(float 
1.00e+00)
+  __nvvm_f2tf32_rz_satfinite(1.0f); 
+  // CHECK_PTX86_SM100: call i32 @llvm.nvvm.f2tf32.rz.relu.satfinite(float 
1.00e+00)
+  __nvvm_f2tf32_rz_relu_satfinite(1.0f); 
+#endif
+  // CHECK: ret void
+}
+
+// CHECK-LABEL: nvvm_cvt_sm100a
+__device__ void nvvm_cvt_sm100a() {
+#if (PTX >= 86) && __CUDA_ARCH_FEAT_SM100_ALL

Wolfram70 wrote:

Oh yes, that’s better. I combined all these checks into a single function in 
the latest revision. Thanks!

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


[clang] [clang] fp options fix for __builtin_convertvector (PR #134102)

2025-04-08 Thread Jakub Ficek via cfe-commits

ficol wrote:

@shafik @tbaederr thanks, can you help with merging this PR?

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


[clang] [llvm] Define pointer layout for AVR program address space (PR #134254)

2025-04-08 Thread Ben Shi via cfe-commits

benshi001 wrote:

Is this change necessary? I find there is not change in the size of addrspace 
0/1 pointers, before and after your patch.

for program 
```c++
clang a.c --target=avr -mmcu=atmega2560
int gf(int a);
int (*p)(int) = gf;
int f;
int *p1 = &f;
```

the generated assembly is unique by before/after applying your patch.

```assembly
.type   p,@object   ; @p
.data
.globl  p
p:
.short  pm(gf)
.size   p, 2

.type   f,@object   ; @f
.section.bss,"aw",@nobits
.globl  f
f:
.short  0   ; 0x0
.size   f, 2

.type   p1,@object  ; @p1
.data
.globl  p1
p1:
.short  f
.size   p1, 2
```

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


[clang] [Clang][Docs] Add release note for execute-only support on AArch64 (PR #134802)

2025-04-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Csanád Hajdú (Il-Capitano)


Changes



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


1 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e671183522565..2ca9b0e4b0ae1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -190,6 +190,9 @@ Modified Compiler Flags
 
 - The compiler flag `-fbracket-depth` default value is increased from 256 to 
2048. (#GH94728)
 
+- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for 
AArch64 targets,
+  allowing the generation of binaries with executable-only code sections. 
(#GH125688)
+
 Removed Compiler Flags
 -
 

``




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


[clang] [Clang] Handle default template arguments for alias CTAD guides (PR #134807)

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

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/134807

It's possible that some deduced template arguments come from default arguments, 
not just from the return type. So we need to recursively visit the default 
arguments of the parameter if it's referenced, thereby the template parameter 
referenced by the defualt arguments could come along to the synthesized 
deduction guide.

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

>From d93117d955ba3a94c68cba1ec968662ae2eed572 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 8 Apr 2025 16:16:53 +0800
Subject: [PATCH] [Clang] Handle default template arguments for alias CTAD
 guides

It's possible that some deduced template arguments come from default
arguments, not just from the return type. So we need to recursively
visit the default arguments if the parameter is referenced, thereby the
template parameter referenced by the defualt arguments could come along
to the synthesized deduction guide.
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp | 17 
 clang/test/SemaTemplate/deduction-guide.cpp   | 39 +++
 3 files changed, 57 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5217e04b5e83f..a914657731dba 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -384,6 +384,7 @@ Bug Fixes to C++ Support
 - Clang no longer crashes when trying to unify the types of arrays with
   certain differences in qualifiers (this could happen during template argument
   deduction or when building a ternary operator). (#GH97005)
+- Fixed type alias CTAD issues involving default template arguments. 
(#GH133132)
 - The initialization kind of elements of structured bindings
   direct-list-initialized from an array is corrected to direct-initialization.
 - Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. 
(#GH127327)
diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index b4863cefc3fb4..30376ca774384 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -690,6 +690,23 @@ SmallVector 
TemplateParamsReferencedInTemplateArgumentList(
   SemaRef.MarkUsedTemplateParameters(
   DeducedArgs, TemplateParamsList->getDepth(), ReferencedTemplateParams);
 
+  auto MarkDefaultArgs = [&](auto *Param) {
+if (!Param || !Param->hasDefaultArgument())
+  return;
+SemaRef.MarkUsedTemplateParameters(
+Param->getDefaultArgument().getArgument(),
+TemplateParamsList->getDepth(), ReferencedTemplateParams);
+  };
+
+  for (unsigned Index = 0; Index < TemplateParamsList->size(); ++Index) {
+if (!ReferencedTemplateParams[Index])
+  continue;
+auto *Param = TemplateParamsList->getParam(Index);
+MarkDefaultArgs(dyn_cast(Param));
+MarkDefaultArgs(dyn_cast(Param));
+MarkDefaultArgs(dyn_cast(Param));
+  }
+
   SmallVector Results;
   for (unsigned Index = 0; Index < TemplateParamsList->size(); ++Index) {
 if (ReferencedTemplateParams[Index])
diff --git a/clang/test/SemaTemplate/deduction-guide.cpp 
b/clang/test/SemaTemplate/deduction-guide.cpp
index 6db132ca37c7e..76b6cb051b7dd 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -771,3 +771,42 @@ D d(24);
 // CHECK-NEXT:  `-ParmVarDecl {{.+}} 'U'
 
 } // namespace GH132616_DeductionGuide
+
+namespace GH133132 {
+
+template 
+struct A {};
+
+template 
+using AA = A;
+
+AA a{};
+
+// CHECK-LABEL: Dumping GH133132:::
+// CHECK-NEXT:  FunctionTemplateDecl {{.+}} implicit 
+// CHECK-NEXT:  |-TemplateTypeParmDecl {{.+}} class depth 0 index 0 T
+// CHECK-NEXT:  | `-TemplateArgument type 'int'
+// CHECK-NEXT:  |   `-BuiltinType {{.+}} 'int'
+// CHECK-NEXT:  |-TemplateTypeParmDecl {{.+}} class depth 0 index 1 U
+// CHECK-NEXT:  | `-TemplateArgument type 'T':'type-parameter-0-0'
+// CHECK-NEXT:  |   `-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0
+// CHECK-NEXT:  | `-TemplateTypeParm {{.+}} 'T'
+// CHECK-NEXT:  |-TypeTraitExpr {{.+}} 'bool' __is_deducible
+// CHECK-NEXT:  | |-DeducedTemplateSpecializationType {{.+}} 'GH133132::AA' 
dependent
+// CHECK-NEXT:  | | `-name: 'GH133132::AA'
+// CHECK-NEXT:  | |   `-TypeAliasTemplateDecl {{.+}} AA
+// CHECK-NEXT:  | `-TemplateSpecializationType {{.+}} 'A' dependent
+// CHECK-NEXT:  |   |-name: 'A':'GH133132::A' qualified
+// CHECK-NEXT:  |   | `-ClassTemplateDecl {{.+}} A
+// CHECK-NEXT:  |   `-TemplateArgument type 'U':'type-parameter-0-1'
+// CHECK-NEXT:  | `-SubstTemplateTypeParmType {{.+}} 'U' sugar dependent 
class depth 0 index 0 _Ty
+// CHECK-NEXT:  |   |-FunctionTemplate {{.+}} ''
+// CHECK-NEXT:  |   `-TemplateTypeParmType {{.+}} 'U' dependent depth 0 
index 1
+// CHECK-NEXT:  | `-TemplateTypeParm {{.+}} 'U'
+// CHECK-NEXT:  |-CXXDeductionGuideDecl 

[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

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

https://github.com/frederick-vs-ja edited 
https://github.com/llvm/llvm-project/pull/93046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] ExprSequence: Handle ternary operators. (PR #132913)

2025-04-08 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle updated 
https://github.com/llvm/llvm-project/pull/132913

>From dcb97b74e78148e03f7749f436f01d5488c11ae1 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Tue, 25 Mar 2025 09:42:53 +
Subject: [PATCH 1/3] [clang-tidy] ExprSequence: Handle ternary operators.

The first operand in the conditional operator `?:` is sequenced before
the second or third operand.

This was probably not implemented because it did not fit in the "single
successor" model of `getSuccessor` (the conditional operator has two
unsequenced successors). Switch to potentially returning several
successors in `getSuccessors` and implement the conditional operator.

Add unit tests.
---
 .../clang-tidy/utils/ExprSequence.cpp |  51 +---
 .../clang-tidy/utils/ExprSequence.h   |   9 +-
 .../unittests/clang-tidy/CMakeLists.txt   |   2 +
 .../unittests/clang-tidy/ExprSequenceTest.cpp | 112 ++
 4 files changed, 150 insertions(+), 24 deletions(-)
 create mode 100644 clang-tools-extra/unittests/clang-tidy/ExprSequenceTest.cpp

diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp 
b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
index 145a5fe378b3e..07a02702f8571 100644
--- a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
@@ -95,10 +95,17 @@ bool ExprSequence::inSequence(const Stmt *Before, const 
Stmt *After) const {
 
   // If 'After' is in the subtree of the siblings that follow 'Before' in the
   // chain of successors, we know that 'After' is sequenced after 'Before'.
-  for (const Stmt *Successor = getSequenceSuccessor(Before); Successor;
-   Successor = getSequenceSuccessor(Successor)) {
-if (isDescendantOrEqual(After, Successor, Context))
-  return true;
+  {
+SmallVector Stack = {Before};
+while (!Stack.empty()) {
+  const Stmt *Node = Stack.back();
+  Stack.pop_back();
+  for (const Stmt *Successor : getSequenceSuccessors(Node)) {
+if (isDescendantOrEqual(After, Successor, Context))
+  return true;
+Stack.push_back(Successor);
+  }
+}
   }
 
   SmallVector BeforeParents = getParentStmts(Before, Context);
@@ -166,7 +173,8 @@ bool ExprSequence::potentiallyAfter(const Stmt *After,
   return !inSequence(After, Before);
 }
 
-const Stmt *ExprSequence::getSequenceSuccessor(const Stmt *S) const {
+llvm::SmallVector
+ExprSequence::getSequenceSuccessors(const Stmt *S) const {
   for (const Stmt *Parent : getParentStmts(S, Context)) {
 // If a statement has multiple parents, make sure we're using the parent
 // that lies within the sub-tree under Root.
@@ -176,14 +184,14 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
 if (const auto *BO = dyn_cast(Parent)) {
   // Comma operator: Right-hand side is sequenced after the left-hand side.
   if (BO->getLHS() == S && BO->getOpcode() == BO_Comma)
-return BO->getRHS();
+return {BO->getRHS()};
 } else if (const auto *InitList = dyn_cast(Parent)) {
   // Initializer list: Each initializer clause is sequenced after the
   // clauses that precede it.
   for (const InitListExpr *Form : getAllInitListForms(InitList)) {
 for (unsigned I = 1; I < Form->getNumInits(); ++I) {
   if (Form->getInit(I - 1) == S) {
-return Form->getInit(I);
+return {Form->getInit(I)};
   }
 }
   }
@@ -193,7 +201,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
   if (ConstructExpr->isListInitialization()) {
 for (unsigned I = 1; I < ConstructExpr->getNumArgs(); ++I) {
   if (ConstructExpr->getArg(I - 1) == S) {
-return ConstructExpr->getArg(I);
+return {ConstructExpr->getArg(I)};
   }
 }
   }
@@ -203,7 +211,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
   const Stmt *Previous = nullptr;
   for (const auto *Child : Compound->body()) {
 if (Previous == S)
-  return Child;
+  return {Child};
 Previous = Child;
   }
 } else if (const auto *TheDeclStmt = dyn_cast(Parent)) {
@@ -214,7 +222,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
 if (const auto *TheVarDecl = dyn_cast(TheDecl)) {
   if (const Expr *Init = TheVarDecl->getInit()) {
 if (PreviousInit == S)
-  return Init;
+  return {Init};
 PreviousInit = Init;
   }
 }
@@ -224,7 +232,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
   // body. (We need this rule because these get placed in the same
   // CFGBlock.)
   if (S == ForRange->getLoopVarStmt())
-return ForRange->getBody();
+return {ForRange->getBody()};
 } else if (const auto *TheIfStmt = dyn_cast(Parent)) {
   // If statement:
   // - Seq

[clang] [WIP] Implement `-dump-deserialized-declaration-ranges` flag. (PR #133910)

2025-04-08 Thread Viktoriia Bakalova via cfe-commits

https://github.com/VitaNuo updated 
https://github.com/llvm/llvm-project/pull/133910

>From cfa057b4d43ebe7f94ccd4f387a94359beaa29b2 Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Fri, 4 Apr 2025 17:45:24 +0200
Subject: [PATCH 1/5] This commit implements a CC1 flag
 `-dump-deserialized-declaration-ranges`. The flag allows to specify a file
 path to dump ranges of deserialized declarations in `ASTReader`. Example
 usage:

```
clang -Xclang=-dump-deserialized-declaration-ranges=/tmp/decls -c file.cc -o 
file.o
```

Example output:
```
// /tmp/decls
{
  "required_ranges": [
{
  "file": "foo.h",
  "range": [
{
  "from": {
"line": 26,
"column": 1
  },
  "to": {
"line": 27,
"column": 77
  }
}
  ]
},
{
  "file": "bar.h",
  "range": [
{
  "from": {
"line": 30,
"column": 1
  },
  "to": {
"line": 35,
"column": 1
  }
},
{
  "from": {
"line": 92,
"column": 1
  },
  "to": {
"line": 95,
"column": 1
  }
}
  ]
}
  ]
}

```
Specifying the flag creates an instance of `DeserializedDeclsLineRangePrinter`, 
which dumps ranges of deserialized declarations to aid debugging and bug 
minimization.

Required ranges are computed from source ranges of Decls. 
`TranslationUnitDecl`, `LinkageSpecDecl` and `NamespaceDecl` are ignored for 
the sake of this PR.

Technical details:
* `DeserializedDeclsLineRangePrinter` implements `ASTConsumer` and 
`ASTDeserializationListener`, so that an object of 
`DeserializedDeclsLineRangePrinter` registers as its own listener.
* `ASTDeserializationListener` interface provides the `DeclRead` callback that 
we use to collect the deserialized Decls.
Printing or otherwise processing them as this point is dangerous, since that 
could trigger additional deserialization and crash compilation.
* The collected Decls are processed in `HandleTranslationUnit` method of 
`ASTConsumer`. This is a safe point, since we know that by this point all the 
Decls needed by the compiler frontend have been deserialized.
*  In case our processing causes further deserialization, `DeclRead` from the 
listener might be called again. However, at that point we don't accept any more 
Decls for processing.
---
 clang/include/clang/Driver/Options.td |   4 +
 .../include/clang/Frontend/FrontendOptions.h  |   3 +
 clang/lib/Frontend/FrontendAction.cpp | 190 +-
 .../dump-deserialized-declaration-ranges.cpp  | 118 +++
 4 files changed, 310 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Frontend/dump-deserialized-declaration-ranges.cpp

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3af072242d039..1737e40b776e1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -7968,6 +7968,10 @@ def print_dependency_directives_minimized_source : 
Flag<["-"],
   "print-dependency-directives-minimized-source">,
   HelpText<"Print the output of the dependency directives source minimizer">;
 }
+def dump_deserialized_declaration_ranges : Joined<["-"],
+  "dump-deserialized-declaration-ranges=">,
+  HelpText<"Dump ranges of deserialized declarations to aid debugging and 
minimization">,
+  MarshallingInfoString>;
 
 defm emit_llvm_uselists : BoolOption<"", "emit-llvm-uselists",
   CodeGenOpts<"EmitLLVMUseLists">, DefaultFalse,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index a9c9849ff52ab..8ef9ce9db8783 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -530,6 +530,9 @@ class FrontendOptions {
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
+  /// Output path to dump ranges of deserialized declarations.
+  std::string DumpDeserializedDeclarationRangesPath;
+
 public:
   FrontendOptions()
   : DisableFree(false), RelocatablePCH(false), ShowHelp(false),
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 2d77f06be7446..1f939f7722d19 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -15,6 +15,8 @@
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/LangStandard.h"
 #include "clang/Basic/Sarif.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Stack.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -35,6 +37,7 @@
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/

[clang] [WIP] Implement `-dump-deserialized-declaration-ranges` flag. (PR #133910)

2025-04-08 Thread Viktoriia Bakalova via cfe-commits

https://github.com/VitaNuo updated 
https://github.com/llvm/llvm-project/pull/133910

>From cfa057b4d43ebe7f94ccd4f387a94359beaa29b2 Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Fri, 4 Apr 2025 17:45:24 +0200
Subject: [PATCH 1/6] This commit implements a CC1 flag
 `-dump-deserialized-declaration-ranges`. The flag allows to specify a file
 path to dump ranges of deserialized declarations in `ASTReader`. Example
 usage:

```
clang -Xclang=-dump-deserialized-declaration-ranges=/tmp/decls -c file.cc -o 
file.o
```

Example output:
```
// /tmp/decls
{
  "required_ranges": [
{
  "file": "foo.h",
  "range": [
{
  "from": {
"line": 26,
"column": 1
  },
  "to": {
"line": 27,
"column": 77
  }
}
  ]
},
{
  "file": "bar.h",
  "range": [
{
  "from": {
"line": 30,
"column": 1
  },
  "to": {
"line": 35,
"column": 1
  }
},
{
  "from": {
"line": 92,
"column": 1
  },
  "to": {
"line": 95,
"column": 1
  }
}
  ]
}
  ]
}

```
Specifying the flag creates an instance of `DeserializedDeclsLineRangePrinter`, 
which dumps ranges of deserialized declarations to aid debugging and bug 
minimization.

Required ranges are computed from source ranges of Decls. 
`TranslationUnitDecl`, `LinkageSpecDecl` and `NamespaceDecl` are ignored for 
the sake of this PR.

Technical details:
* `DeserializedDeclsLineRangePrinter` implements `ASTConsumer` and 
`ASTDeserializationListener`, so that an object of 
`DeserializedDeclsLineRangePrinter` registers as its own listener.
* `ASTDeserializationListener` interface provides the `DeclRead` callback that 
we use to collect the deserialized Decls.
Printing or otherwise processing them as this point is dangerous, since that 
could trigger additional deserialization and crash compilation.
* The collected Decls are processed in `HandleTranslationUnit` method of 
`ASTConsumer`. This is a safe point, since we know that by this point all the 
Decls needed by the compiler frontend have been deserialized.
*  In case our processing causes further deserialization, `DeclRead` from the 
listener might be called again. However, at that point we don't accept any more 
Decls for processing.
---
 clang/include/clang/Driver/Options.td |   4 +
 .../include/clang/Frontend/FrontendOptions.h  |   3 +
 clang/lib/Frontend/FrontendAction.cpp | 190 +-
 .../dump-deserialized-declaration-ranges.cpp  | 118 +++
 4 files changed, 310 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Frontend/dump-deserialized-declaration-ranges.cpp

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3af072242d039..1737e40b776e1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -7968,6 +7968,10 @@ def print_dependency_directives_minimized_source : 
Flag<["-"],
   "print-dependency-directives-minimized-source">,
   HelpText<"Print the output of the dependency directives source minimizer">;
 }
+def dump_deserialized_declaration_ranges : Joined<["-"],
+  "dump-deserialized-declaration-ranges=">,
+  HelpText<"Dump ranges of deserialized declarations to aid debugging and 
minimization">,
+  MarshallingInfoString>;
 
 defm emit_llvm_uselists : BoolOption<"", "emit-llvm-uselists",
   CodeGenOpts<"EmitLLVMUseLists">, DefaultFalse,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index a9c9849ff52ab..8ef9ce9db8783 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -530,6 +530,9 @@ class FrontendOptions {
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
+  /// Output path to dump ranges of deserialized declarations.
+  std::string DumpDeserializedDeclarationRangesPath;
+
 public:
   FrontendOptions()
   : DisableFree(false), RelocatablePCH(false), ShowHelp(false),
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 2d77f06be7446..1f939f7722d19 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -15,6 +15,8 @@
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/LangStandard.h"
 #include "clang/Basic/Sarif.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Stack.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -35,6 +37,7 @@
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/

[clang] [Clang][Docs] Add release note for execute-only support on AArch64 (PR #134802)

2025-04-08 Thread Csanád Hajdú via cfe-commits

https://github.com/Il-Capitano updated 
https://github.com/llvm/llvm-project/pull/134802

From c48168df95781b8fe5d6f72c9bdcbe1ad6a94fe5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= 
Date: Tue, 8 Apr 2025 09:47:46 +0200
Subject: [PATCH 1/2] [Clang][Docs] Add release note for execute-only support
 on AArch64

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e671183522565..2ca9b0e4b0ae1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -190,6 +190,9 @@ Modified Compiler Flags
 
 - The compiler flag `-fbracket-depth` default value is increased from 256 to 
2048. (#GH94728)
 
+- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for 
AArch64 targets,
+  allowing the generation of binaries with executable-only code sections. 
(#GH125688)
+
 Removed Compiler Flags
 -
 

From e3a97bca7622846ad1b55829c8242dc91fa55ee7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= 
Date: Tue, 8 Apr 2025 11:54:30 +0200
Subject: [PATCH 2/2] Add note in "Arm and AArch64 support" section too

---
 clang/docs/ReleaseNotes.rst | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2ca9b0e4b0ae1..17e18eae9e36b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -190,8 +190,7 @@ Modified Compiler Flags
 
 - The compiler flag `-fbracket-depth` default value is increased from 256 to 
2048. (#GH94728)
 
-- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for 
AArch64 targets,
-  allowing the generation of binaries with executable-only code sections. 
(#GH125688)
+- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for 
AArch64 targets. (#GH125688)
 
 Removed Compiler Flags
 -
@@ -474,6 +473,9 @@ X86 Support
 Arm and AArch64 Support
 ^^^
 
+- For AArch64, added support for generating executable-only code sections by 
using the
+  ``-mexecute-only`` or ``-mpure-code`` compiler flags. (#GH125688)
+
 Android Support
 ^^^
 

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


[clang] [Clang][Docs] Add release note for execute-only support on AArch64 (PR #134802)

2025-04-08 Thread Csanád Hajdú via cfe-commits

Il-Capitano wrote:

> There is a `Arm and AArch64 Support` section too, is it worth adding a note 
> there either instead or as well? It could maybe just be a note that points 
> back to the Modified Compiler Flags section.

Thanks, I didn't notice that section.

I simplified the note in "Modified Compiler Flags" and added one in "Arm and 
AArch64 Support".

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


[clang] Implement `-dump-deserialized-declaration-ranges` flag. (PR #133910)

2025-04-08 Thread Viktoriia Bakalova via cfe-commits

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


[clang] Codegen for Reduction over private variables with reduction clause (PR #134709)

2025-04-08 Thread CHANDRA GHALE via cfe-commits

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


[clang] [clang-format] Add 'cl' to enable OpenCL kernel file formatting (PR #134529)

2025-04-08 Thread Wenju He via cfe-commits

https://github.com/wenju-he updated 
https://github.com/llvm/llvm-project/pull/134529

>From ac389b8b92fbb77c8884515d8f7293b4af17dfa5 Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Sun, 6 Apr 2025 18:30:42 +0800
Subject: [PATCH 1/4] [clang-format] Add 'cl' to enable OpenCL kernel file
 formatting

---
 clang/tools/clang-format/git-clang-format | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 85eff4761e289..ba324b14ab80d 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -126,6 +126,7 @@ def main():
 "pb.txt",
 "textproto",
 "asciipb",  # TextProto
+"cl", # OpenCL
 ]
 )
 

>From 88c11747fcc8db1921dfd8f73c9330c662f7fd91 Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Mon, 7 Apr 2025 16:17:39 -0700
Subject: [PATCH 2/4] return C language format style for OpenCL

---
 clang/lib/Format/Format.cpp   | 5 +
 clang/test/Format/dump-config-opencl-stdin.cl | 7 +++
 clang/test/Format/lit.local.cfg   | 3 ++-
 clang/unittests/Format/FormatTest.cpp | 3 +++
 4 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Format/dump-config-opencl-stdin.cl

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 226d39f635676..0565d6d46eb32 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -4094,6 +4094,9 @@ static FormatStyle::LanguageKind 
getLanguageByFileName(StringRef FileName) {
   FileName.ends_with_insensitive(".vh")) {
 return FormatStyle::LK_Verilog;
   }
+  // OpenCL is based on C99 and C11.
+  if (FileName.ends_with(".cl"))
+return FormatStyle::LK_C;
   return FormatStyle::LK_Cpp;
 }
 
@@ -4121,6 +4124,8 @@ static FormatStyle::LanguageKind 
getLanguageByComment(const Environment &Env) {
   return FormatStyle::LK_Cpp;
 if (Text == "ObjC")
   return FormatStyle::LK_ObjC;
+if (Text == "OpenCL")
+  return FormatStyle::LK_C;
   }
 
   return FormatStyle::LK_None;
diff --git a/clang/test/Format/dump-config-opencl-stdin.cl 
b/clang/test/Format/dump-config-opencl-stdin.cl
new file mode 100644
index 0..d02a3fb287a42
--- /dev/null
+++ b/clang/test/Format/dump-config-opencl-stdin.cl
@@ -0,0 +1,7 @@
+// RUN: clang-format -assume-filename=foo.cl -dump-config | FileCheck %s
+
+// RUN: clang-format -dump-config - < %s | FileCheck %s
+
+// CHECK: Language: C
+
+void foo() {}
diff --git a/clang/test/Format/lit.local.cfg b/clang/test/Format/lit.local.cfg
index b060c79226cbd..3717ee0dac577 100644
--- a/clang/test/Format/lit.local.cfg
+++ b/clang/test/Format/lit.local.cfg
@@ -20,7 +20,8 @@ config.suffixes = [
 ".textpb",
 ".asciipb",
 ".td",
-".test"
+".test",
+".cl"
 ]
 
 # AIX 'diff' command doesn't support --strip-trailing-cr, but the internal
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 69c9ee1d1dcb2..146ec9e0a1616 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25187,6 +25187,9 @@ TEST_F(FormatTest, GetLanguageByComment) {
   EXPECT_EQ(FormatStyle::LK_ObjC,
 guessLanguage("foo.h", "// clang-format Language: ObjC\n"
"int i;"));
+  EXPECT_EQ(FormatStyle::LK_C,
+guessLanguage("foo.h", "// clang-format Language: OpenCL\n"
+   "int i;"));
 }
 
 TEST_F(FormatTest, TypenameMacros) {

>From 69825a4bd73df7bdfaf21c52880ed1441c1d4d6b Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Mon, 7 Apr 2025 23:48:38 -0700
Subject: [PATCH 3/4] Revert "return C language format style for OpenCL"

This reverts commit 88c11747fcc8db1921dfd8f73c9330c662f7fd91.
---
 clang/lib/Format/Format.cpp   | 5 -
 clang/test/Format/dump-config-opencl-stdin.cl | 7 ---
 clang/test/Format/lit.local.cfg   | 3 +--
 clang/unittests/Format/FormatTest.cpp | 3 ---
 4 files changed, 1 insertion(+), 17 deletions(-)
 delete mode 100644 clang/test/Format/dump-config-opencl-stdin.cl

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 0565d6d46eb32..226d39f635676 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -4094,9 +4094,6 @@ static FormatStyle::LanguageKind 
getLanguageByFileName(StringRef FileName) {
   FileName.ends_with_insensitive(".vh")) {
 return FormatStyle::LK_Verilog;
   }
-  // OpenCL is based on C99 and C11.
-  if (FileName.ends_with(".cl"))
-return FormatStyle::LK_C;
   return FormatStyle::LK_Cpp;
 }
 
@@ -4124,8 +4121,6 @@ static FormatStyle::LanguageKind 
getLanguageByComment(const Environment &Env) {
   return FormatStyle::LK_Cpp;
 if (Text == "ObjC")
   return FormatStyle::LK_ObjC;
-if (Text == "OpenCL")
-  return FormatStyle::LK_C;
   }
 
   return FormatStyle

[clang] [clang-format] Add 'cl' to enable OpenCL kernel file formatting (PR #134529)

2025-04-08 Thread Wenju He via cfe-commits


@@ -126,6 +126,7 @@ def main():
 "pb.txt",
 "textproto",
 "asciipb",  # TextProto
+"cl", # OpenCL

wenju-he wrote:

done, moved after line 108. 
> Do we want to add "clcpp", # OpenCL C++?

I actually don't know about the current development status of C++ for OpenCL in 
clang. So If there is such request, I think it can be added in a separate PR.

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


[clang] clang/AMDGPU: Stop looking for hip.bc in device libs (PR #134801)

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

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


[clang] clang/AMDGPU: Stop looking for hip.bc in device libs (PR #134801)

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

https://github.com/arsenm created 
https://github.com/llvm/llvm-project/pull/134801

This has been an empty library since January 2023

>From b46b307e034fed518437f8e28ce05704d1c20560 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Tue, 8 Apr 2025 14:00:34 +0700
Subject: [PATCH] clang/AMDGPU: Stop looking for hip.bc in device libs

This has been an empty library since January 2023
---
 clang/lib/Driver/ToolChains/AMDGPU.cpp | 2 --
 clang/lib/Driver/ToolChains/HIPAMD.cpp | 3 ---
 clang/lib/Driver/ToolChains/ROCm.h | 8 +---
 clang/test/Driver/hip-device-libs.hip  | 5 ++---
 clang/test/Driver/hip-sanitize-options.hip | 4 ++--
 5 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index dffc70d5e5b69..e12531330a8e6 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -59,8 +59,6 @@ void 
RocmInstallationDetector::scanLibDevicePath(llvm::StringRef Path) {
   OCKL = FilePath;
 } else if (BaseName == "opencl") {
   OpenCL = FilePath;
-} else if (BaseName == "hip") {
-  HIP = FilePath;
 } else if (BaseName == "asanrtl") {
   AsanRTL = FilePath;
 } else if (BaseName == "oclc_finite_only_off") {
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index abb83701759ce..52b8a4510792f 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -392,9 +392,6 @@ HIPAMDToolChain::getDeviceLibs(const llvm::opt::ArgList 
&DriverArgs) const {
 StringRef GpuArch = getGPUArch(DriverArgs);
 assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
 
-// Add the HIP specific bitcode library.
-BCLibs.emplace_back(RocmInstallation->getHIPPath());
-
 // Add common device libraries like ocml etc.
 for (auto N : getCommonDeviceLibNames(DriverArgs, GpuArch.str()))
   BCLibs.emplace_back(N);
diff --git a/clang/lib/Driver/ToolChains/ROCm.h 
b/clang/lib/Driver/ToolChains/ROCm.h
index a6cc41db383b6..b82e30df4e024 100644
--- a/clang/lib/Driver/ToolChains/ROCm.h
+++ b/clang/lib/Driver/ToolChains/ROCm.h
@@ -127,7 +127,6 @@ class RocmInstallationDetector {
 
   // Libraries that are always linked depending on the language
   SmallString<0> OpenCL;
-  SmallString<0> HIP;
 
   // Asan runtime library
   SmallString<0> AsanRTL;
@@ -149,7 +148,7 @@ class RocmInstallationDetector {
   bool Verbose;
 
   bool allGenericLibsValid() const {
-return !OCML.empty() && !OCKL.empty() && !OpenCL.empty() && !HIP.empty() &&
+return !OCML.empty() && !OCKL.empty() && !OpenCL.empty() &&
WavefrontSize64.isValid() && FiniteOnly.isValid() &&
UnsafeMath.isValid() && DenormalsAreZero.isValid() &&
CorrectlyRoundedSqrt.isValid();
@@ -229,11 +228,6 @@ class RocmInstallationDetector {
 return OpenCL;
   }
 
-  StringRef getHIPPath() const {
-assert(!HIP.empty());
-return HIP;
-  }
-
   /// Returns empty string of Asan runtime library is not available.
   StringRef getAsanRTLPath() const { return AsanRTL; }
 
diff --git a/clang/test/Driver/hip-device-libs.hip 
b/clang/test/Driver/hip-device-libs.hip
index c7cafd0027bc5..e8a13547dfb3c 100644
--- a/clang/test/Driver/hip-device-libs.hip
+++ b/clang/test/Driver/hip-device-libs.hip
@@ -208,10 +208,9 @@
 // ALL-NOT: error:
 // ALL: {{"[^"]*clang[^"]*"}}
 
-// RESDIR-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|)rocm_resource_dir(/|)lib(64)?(/|)amdgcn(/|).*]]hip.bc"
-// ROCMDIR-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|)rocm(/|)amdgcn(/|).*]]hip.bc"
+// RESDIR-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|)rocm_resource_dir(/|)lib(64)?(/|)amdgcn(/|).*]]ocml.bc"
+// ROCMDIR-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|)rocm(/|)amdgcn(/|).*]]ocml.bc"
 
-// ALL-SAME: "-mlink-builtin-bitcode" "[[DEVICELIB_DIR]]ocml.bc"
 // ALL-SAME: "-mlink-builtin-bitcode" "[[DEVICELIB_DIR]]ockl.bc"
 
 // FLUSHD-SAME: "-mlink-builtin-bitcode" "[[DEVICELIB_DIR]]oclc_daz_opt_on.bc"
diff --git a/clang/test/Driver/hip-sanitize-options.hip 
b/clang/test/Driver/hip-sanitize-options.hip
index 8de0ee9e18426..0c9c15b61fdc9 100644
--- a/clang/test/Driver/hip-sanitize-options.hip
+++ b/clang/test/Driver/hip-sanitize-options.hip
@@ -52,12 +52,12 @@
 // CHECK-NOT: {{"[^"]*lld(\.exe){0,1}".* ".*hip.bc"}}
 // CHECK: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* 
"-fsanitize=address"}}
 
-// NORDC: {{"[^"]*clang[^"]*".* "-emit-obj".* "-fcuda-is-device".* 
"-mlink-builtin-bitcode" ".*hip.bc".* "-mlink-bitcode-file" ".*asanrtl.bc".* 
"-fsanitize=address".*}} "-o" "[[OUT:[^"]*.o]]"
+// NORDC: {{"[^"]*clang[^"]*".* "-emit-obj".* "-fcuda-is-device".* .* 
"-mlink-bitcode-file" ".*asanrtl.bc".* "-fsanitize=address".*}} "-o" 
"[[OUT:[^"]*.o]]"
 // NORDC-NOT: {{"[^"]*lld(\.exe){0,1}".*}} "[[

[clang] [Clang][Docs] Add release note for execute-only support on AArch64 (PR #134802)

2025-04-08 Thread Csanád Hajdú via cfe-commits

https://github.com/Il-Capitano created 
https://github.com/llvm/llvm-project/pull/134802

None

From c48168df95781b8fe5d6f72c9bdcbe1ad6a94fe5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= 
Date: Tue, 8 Apr 2025 09:47:46 +0200
Subject: [PATCH] [Clang][Docs] Add release note for execute-only support on
 AArch64

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e671183522565..2ca9b0e4b0ae1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -190,6 +190,9 @@ Modified Compiler Flags
 
 - The compiler flag `-fbracket-depth` default value is increased from 256 to 
2048. (#GH94728)
 
+- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for 
AArch64 targets,
+  allowing the generation of binaries with executable-only code sections. 
(#GH125688)
+
 Removed Compiler Flags
 -
 

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


[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu-V2R2 (PR #123193)

2025-04-08 Thread Yangyu Chen via cfe-commits

cyyself wrote:

I think some feature is missing here, such as "Zvbb".

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


[clang] [Clang] Handle default template arguments for alias CTAD guides (PR #134807)

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

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

>From 3f09d114d6c4c51bd879a19caaf1c73c531cfedd Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 8 Apr 2025 16:16:53 +0800
Subject: [PATCH] [Clang] Handle default template arguments for alias CTAD
 guides

It's possible that some deduced template arguments come from default
arguments, not just from the return type. So we need to recursively
visit the default arguments if the parameter is referenced, thereby the
template parameter referenced by the defualt arguments could come along
to the synthesized deduction guide.
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp | 17 
 clang/test/SemaTemplate/deduction-guide.cpp   | 39 +++
 3 files changed, 57 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5217e04b5e83f..d9b1cd16a85d3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -384,6 +384,7 @@ Bug Fixes to C++ Support
 - Clang no longer crashes when trying to unify the types of arrays with
   certain differences in qualifiers (this could happen during template argument
   deduction or when building a ternary operator). (#GH97005)
+- Fixed type alias CTAD issues involving default template arguments. 
(#GH134471)
 - The initialization kind of elements of structured bindings
   direct-list-initialized from an array is corrected to direct-initialization.
 - Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. 
(#GH127327)
diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index b4863cefc3fb4..30376ca774384 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -690,6 +690,23 @@ SmallVector 
TemplateParamsReferencedInTemplateArgumentList(
   SemaRef.MarkUsedTemplateParameters(
   DeducedArgs, TemplateParamsList->getDepth(), ReferencedTemplateParams);
 
+  auto MarkDefaultArgs = [&](auto *Param) {
+if (!Param || !Param->hasDefaultArgument())
+  return;
+SemaRef.MarkUsedTemplateParameters(
+Param->getDefaultArgument().getArgument(),
+TemplateParamsList->getDepth(), ReferencedTemplateParams);
+  };
+
+  for (unsigned Index = 0; Index < TemplateParamsList->size(); ++Index) {
+if (!ReferencedTemplateParams[Index])
+  continue;
+auto *Param = TemplateParamsList->getParam(Index);
+MarkDefaultArgs(dyn_cast(Param));
+MarkDefaultArgs(dyn_cast(Param));
+MarkDefaultArgs(dyn_cast(Param));
+  }
+
   SmallVector Results;
   for (unsigned Index = 0; Index < TemplateParamsList->size(); ++Index) {
 if (ReferencedTemplateParams[Index])
diff --git a/clang/test/SemaTemplate/deduction-guide.cpp 
b/clang/test/SemaTemplate/deduction-guide.cpp
index 6db132ca37c7e..76b6cb051b7dd 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -771,3 +771,42 @@ D d(24);
 // CHECK-NEXT:  `-ParmVarDecl {{.+}} 'U'
 
 } // namespace GH132616_DeductionGuide
+
+namespace GH133132 {
+
+template 
+struct A {};
+
+template 
+using AA = A;
+
+AA a{};
+
+// CHECK-LABEL: Dumping GH133132:::
+// CHECK-NEXT:  FunctionTemplateDecl {{.+}} implicit 
+// CHECK-NEXT:  |-TemplateTypeParmDecl {{.+}} class depth 0 index 0 T
+// CHECK-NEXT:  | `-TemplateArgument type 'int'
+// CHECK-NEXT:  |   `-BuiltinType {{.+}} 'int'
+// CHECK-NEXT:  |-TemplateTypeParmDecl {{.+}} class depth 0 index 1 U
+// CHECK-NEXT:  | `-TemplateArgument type 'T':'type-parameter-0-0'
+// CHECK-NEXT:  |   `-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0
+// CHECK-NEXT:  | `-TemplateTypeParm {{.+}} 'T'
+// CHECK-NEXT:  |-TypeTraitExpr {{.+}} 'bool' __is_deducible
+// CHECK-NEXT:  | |-DeducedTemplateSpecializationType {{.+}} 'GH133132::AA' 
dependent
+// CHECK-NEXT:  | | `-name: 'GH133132::AA'
+// CHECK-NEXT:  | |   `-TypeAliasTemplateDecl {{.+}} AA
+// CHECK-NEXT:  | `-TemplateSpecializationType {{.+}} 'A' dependent
+// CHECK-NEXT:  |   |-name: 'A':'GH133132::A' qualified
+// CHECK-NEXT:  |   | `-ClassTemplateDecl {{.+}} A
+// CHECK-NEXT:  |   `-TemplateArgument type 'U':'type-parameter-0-1'
+// CHECK-NEXT:  | `-SubstTemplateTypeParmType {{.+}} 'U' sugar dependent 
class depth 0 index 0 _Ty
+// CHECK-NEXT:  |   |-FunctionTemplate {{.+}} ''
+// CHECK-NEXT:  |   `-TemplateTypeParmType {{.+}} 'U' dependent depth 0 
index 1
+// CHECK-NEXT:  | `-TemplateTypeParm {{.+}} 'U'
+// CHECK-NEXT:  |-CXXDeductionGuideDecl {{.+}} implicit  'auto () -> A'
+// CHECK-NEXT:  `-CXXDeductionGuideDecl {{.+}} implicit used  'auto () -> A' implicit_instantiation
+// CHECK-NEXT:|-TemplateArgument type 'int'
+// CHECK-NEXT:| `-BuiltinType {{.+}} 'int'
+// CHECK-NEXT:`-TemplateArgument type 'int'
+// CHECK-NEXT:  `-BuiltinType {{.+}} 'int'
+}

___
cfe-co

[libclc] [libclc] Reduce bithacking in CLC frexp (PR #129871)

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

rjodinchr wrote:

I'm clearly seeing those devices returning true when comparing subnormals to 
zero. So either they all have a bug, or the SPIR-V code produced by `clspv` is 
buggy.
If it ends up being a bug from the device, we might want to have something more 
architecture friendly, or at least a way to fallback on a less efficient but 
always working implementation.
Let's hope it can be dealt with clspv

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


[clang] [llvm] [NVPTX] Add builtins and intrinsics for conversions of new FP types (PR #134345)

2025-04-08 Thread Srinivasa Ravi via cfe-commits

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


[clang] [clang][llvm] Fix AArch64 MOP4{A/S} intrinsic tests (NFC) (PR #134746)

2025-04-08 Thread Jonathan Thackray via cfe-commits

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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #131838)

2025-04-08 Thread Alexey Bataev via cfe-commits


@@ -4528,6 +4528,115 @@ void CodeGenFunction::EmitOMPMasterDirective(const 
OMPMasterDirective &S) {
   emitMaster(*this, S);
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {

alexey-bataev wrote:

Why do you need it? CapturedExpr should be emitted as is

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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #131838)

2025-04-08 Thread Alexey Bataev via cfe-commits


@@ -537,6 +537,10 @@ Python Binding Changes
 
 OpenMP Support
 --
+- Added support for 'omp assume' directive.
+- Added support for 'omp scope' directive.
+- Added support for allocator-modifier in 'allocate' clause.

alexey-bataev wrote:

Unrelated to this patch

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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #131838)

2025-04-08 Thread Alexey Bataev via cfe-commits

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


[clang] [Clang] [NFC] Tablegen component diags headers (PR #134777)

2025-04-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Sirraide)


Changes

The component diagnostic headers (i.e. `DiagnosticAST.h` and friends) all 
follow the same format, and there’s enough of them (and in them) to where 
updating all of them has become rather tedious (at least it was for me while 
working on #132348), so this patch instead generates all of them (or 
rather their contents) via Tablegen.

Also, it seems that `%enum_select` currently woudln’t work in 
`DiagnosticCommonKinds.td` because the infrastructure for that was missing from 
`DiagnosticIDs.h`; this patch should fix that as well.

---

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


17 Files Affected:

- (modified) clang/include/clang/Basic/CMakeLists.txt (+5) 
- (modified) clang/include/clang/Basic/DiagnosticAST.h (+1-39) 
- (modified) clang/include/clang/Basic/DiagnosticAnalysis.h (+1-38) 
- (modified) clang/include/clang/Basic/DiagnosticComment.h (+1-39) 
- (modified) clang/include/clang/Basic/DiagnosticCrossTU.h (+1-39) 
- (modified) clang/include/clang/Basic/DiagnosticDriver.h (+1-39) 
- (modified) clang/include/clang/Basic/DiagnosticFrontend.h (+1-39) 
- (modified) clang/include/clang/Basic/DiagnosticIDs.h (+5-23) 
- (modified) clang/include/clang/Basic/DiagnosticInstallAPI.h (+1-37) 
- (modified) clang/include/clang/Basic/DiagnosticLex.h (+1-38) 
- (modified) clang/include/clang/Basic/DiagnosticParse.h (+1-39) 
- (modified) clang/include/clang/Basic/DiagnosticRefactoring.h (+1-39) 
- (modified) clang/include/clang/Basic/DiagnosticSema.h (+1-40) 
- (modified) clang/include/clang/Basic/DiagnosticSerialization.h (+1-39) 
- (modified) clang/utils/TableGen/ClangDiagnosticsEmitter.cpp (+51) 
- (modified) clang/utils/TableGen/TableGen.cpp (+6) 
- (modified) clang/utils/TableGen/TableGenBackends.h (+2) 


``diff
diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 4d5e1eaa3facb..265ea1fc06494 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -13,6 +13,11 @@ macro(clang_diag_gen component)
 -gen-clang-diags-compat-ids -clang-component=${component}
 SOURCE Diagnostic.td
 TARGET ClangDiagnostic${component}CompatIDs)
+
+  clang_tablegen(Diagnostic${component}Interface.inc
+-gen-clang-diags-iface -clang-component=${component}
+SOURCE Diagnostic.td
+TARGET ClangDiagnostic${component}Interface)
 endmacro(clang_diag_gen)
 
 clang_diag_gen(Analysis)
diff --git a/clang/include/clang/Basic/DiagnosticAST.h 
b/clang/include/clang/Basic/DiagnosticAST.h
index 41e2598f7cc3b..be9e303d92629 100644
--- a/clang/include/clang/Basic/DiagnosticAST.h
+++ b/clang/include/clang/Basic/DiagnosticAST.h
@@ -10,44 +10,6 @@
 #define LLVM_CLANG_BASIC_DIAGNOSTICAST_H
 
 #include "clang/Basic/Diagnostic.h"
-
-namespace clang {
-namespace diag {
-enum {
-#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  
\
- SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY)
\
-  ENUM,
-#define ASTSTART
-#include "clang/Basic/DiagnosticASTKinds.inc"
-#undef DIAG
-  NUM_BUILTIN_AST_DIAGNOSTICS
-};
-
-#define DIAG_ENUM(ENUM_NAME)   
\
-  namespace ENUM_NAME {
\
-  enum {
-#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
-#define DIAG_ENUM_END()
\
-  }
\
-  ;
\
-  }
-#include "clang/Basic/DiagnosticASTEnums.inc"
-#undef DIAG_ENUM_END
-#undef DIAG_ENUM_ITEM
-#undef DIAG_ENUM
-} // end namespace diag
-
-namespace diag_compat {
-#define DIAG_COMPAT_IDS_BEGIN() enum {
-#define DIAG_COMPAT_IDS_END()  
\
-  }
\
-  ;
-#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
-#include "clang/Basic/DiagnosticASTCompatIDs.inc"
-#undef DIAG_COMPAT_ID
-#undef DIAG_COMPAT_IDS_BEGIN
-#undef DIAG_COMPAT_IDS_END
-} // end namespace diag_compat
-} // end namespace clang
+#include "clang/Basic/DiagnosticASTInterface.inc"
 
 #endif // LLVM_CLANG_BASIC_DIAGNOSTICAST_H
diff --git a/clang/include/clang/Basic/DiagnosticAnalysis.h 
b/clang/include/clang/Basic/DiagnosticAnalysis.h
index 5ead092b946c5..8e2635ffbd78d 100644
--- a/clang/include/clang/Basic/DiagnosticAnalysis.h
+++ b/clang/include/clang/Basic/DiagnosticAnalysis.h
@@ -10,43 +10,6 @@
 #define LLVM_CLANG_BASIC_DIAGNOSTICANALYSIS_H
 
 #include "clang/Basic/Diagnostic.h"
-
-namespace clang {
-namespace diag {
-enum {
-#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  
\
- SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY)  

[clang] clang/AMDGPU: Stop looking for hip.bc in device libs (PR #134801)

2025-04-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Matt Arsenault (arsenm)


Changes

This has been an empty library since January 2023

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


5 Files Affected:

- (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (-2) 
- (modified) clang/lib/Driver/ToolChains/HIPAMD.cpp (-3) 
- (modified) clang/lib/Driver/ToolChains/ROCm.h (+1-7) 
- (modified) clang/test/Driver/hip-device-libs.hip (+2-3) 
- (modified) clang/test/Driver/hip-sanitize-options.hip (+2-2) 


``diff
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index dffc70d5e5b69..e12531330a8e6 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -59,8 +59,6 @@ void 
RocmInstallationDetector::scanLibDevicePath(llvm::StringRef Path) {
   OCKL = FilePath;
 } else if (BaseName == "opencl") {
   OpenCL = FilePath;
-} else if (BaseName == "hip") {
-  HIP = FilePath;
 } else if (BaseName == "asanrtl") {
   AsanRTL = FilePath;
 } else if (BaseName == "oclc_finite_only_off") {
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index abb83701759ce..52b8a4510792f 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -392,9 +392,6 @@ HIPAMDToolChain::getDeviceLibs(const llvm::opt::ArgList 
&DriverArgs) const {
 StringRef GpuArch = getGPUArch(DriverArgs);
 assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
 
-// Add the HIP specific bitcode library.
-BCLibs.emplace_back(RocmInstallation->getHIPPath());
-
 // Add common device libraries like ocml etc.
 for (auto N : getCommonDeviceLibNames(DriverArgs, GpuArch.str()))
   BCLibs.emplace_back(N);
diff --git a/clang/lib/Driver/ToolChains/ROCm.h 
b/clang/lib/Driver/ToolChains/ROCm.h
index a6cc41db383b6..b82e30df4e024 100644
--- a/clang/lib/Driver/ToolChains/ROCm.h
+++ b/clang/lib/Driver/ToolChains/ROCm.h
@@ -127,7 +127,6 @@ class RocmInstallationDetector {
 
   // Libraries that are always linked depending on the language
   SmallString<0> OpenCL;
-  SmallString<0> HIP;
 
   // Asan runtime library
   SmallString<0> AsanRTL;
@@ -149,7 +148,7 @@ class RocmInstallationDetector {
   bool Verbose;
 
   bool allGenericLibsValid() const {
-return !OCML.empty() && !OCKL.empty() && !OpenCL.empty() && !HIP.empty() &&
+return !OCML.empty() && !OCKL.empty() && !OpenCL.empty() &&
WavefrontSize64.isValid() && FiniteOnly.isValid() &&
UnsafeMath.isValid() && DenormalsAreZero.isValid() &&
CorrectlyRoundedSqrt.isValid();
@@ -229,11 +228,6 @@ class RocmInstallationDetector {
 return OpenCL;
   }
 
-  StringRef getHIPPath() const {
-assert(!HIP.empty());
-return HIP;
-  }
-
   /// Returns empty string of Asan runtime library is not available.
   StringRef getAsanRTLPath() const { return AsanRTL; }
 
diff --git a/clang/test/Driver/hip-device-libs.hip 
b/clang/test/Driver/hip-device-libs.hip
index c7cafd0027bc5..e8a13547dfb3c 100644
--- a/clang/test/Driver/hip-device-libs.hip
+++ b/clang/test/Driver/hip-device-libs.hip
@@ -208,10 +208,9 @@
 // ALL-NOT: error:
 // ALL: {{"[^"]*clang[^"]*"}}
 
-// RESDIR-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|)rocm_resource_dir(/|)lib(64)?(/|)amdgcn(/|).*]]hip.bc"
-// ROCMDIR-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|)rocm(/|)amdgcn(/|).*]]hip.bc"
+// RESDIR-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|)rocm_resource_dir(/|)lib(64)?(/|)amdgcn(/|).*]]ocml.bc"
+// ROCMDIR-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|)rocm(/|)amdgcn(/|).*]]ocml.bc"
 
-// ALL-SAME: "-mlink-builtin-bitcode" "[[DEVICELIB_DIR]]ocml.bc"
 // ALL-SAME: "-mlink-builtin-bitcode" "[[DEVICELIB_DIR]]ockl.bc"
 
 // FLUSHD-SAME: "-mlink-builtin-bitcode" "[[DEVICELIB_DIR]]oclc_daz_opt_on.bc"
diff --git a/clang/test/Driver/hip-sanitize-options.hip 
b/clang/test/Driver/hip-sanitize-options.hip
index 8de0ee9e18426..0c9c15b61fdc9 100644
--- a/clang/test/Driver/hip-sanitize-options.hip
+++ b/clang/test/Driver/hip-sanitize-options.hip
@@ -52,12 +52,12 @@
 // CHECK-NOT: {{"[^"]*lld(\.exe){0,1}".* ".*hip.bc"}}
 // CHECK: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* 
"-fsanitize=address"}}
 
-// NORDC: {{"[^"]*clang[^"]*".* "-emit-obj".* "-fcuda-is-device".* 
"-mlink-builtin-bitcode" ".*hip.bc".* "-mlink-bitcode-file" ".*asanrtl.bc".* 
"-fsanitize=address".*}} "-o" "[[OUT:[^"]*.o]]"
+// NORDC: {{"[^"]*clang[^"]*".* "-emit-obj".* "-fcuda-is-device".* .* 
"-mlink-bitcode-file" ".*asanrtl.bc".* "-fsanitize=address".*}} "-o" 
"[[OUT:[^"]*.o]]"
 // NORDC-NOT: {{"[^"]*lld(\.exe){0,1}".*}} "[[OUT]]" {{".*asanrtl.bc" 
".*hip.bc"}}
 // NORDC: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* 
"-fsanitize=address"}}
 
 // RDC: {{"[^"]*clang[^"

[clang] [OpenMP 6.0 ]Codegen for Reduction over private variables with reduction clause (PR #134709)

2025-04-08 Thread Alexey Bataev via cfe-commits


@@ -4899,6 +4899,150 @@ void 
CGOpenMPRuntime::emitSingleReductionCombiner(CodeGenFunction &CGF,
   }
 }
 
+void CGOpenMPRuntime::emitPrivateReduction(
+CodeGenFunction &CGF, SourceLocation Loc, ArrayRef Privates,
+ArrayRef LHSExprs, ArrayRef RHSExprs,
+ArrayRef ReductionOps) {
+
+  if (LHSExprs.empty() || Privates.empty() || ReductionOps.empty())
+return;
+
+  if (LHSExprs.size() != Privates.size() ||
+  LHSExprs.size() != ReductionOps.size())
+return;
+
+  QualType PrivateType = Privates[0]->getType();
+  llvm::Type *LLVMType = CGF.ConvertTypeForMem(PrivateType);
+
+  BinaryOperatorKind MainBO = BO_Comma;
+  if (const auto *BinOp = dyn_cast(ReductionOps[0])) {
+if (const auto *RHSExpr = BinOp->getRHS()) {
+  if (const auto *BORHS =
+  dyn_cast(RHSExpr->IgnoreParenImpCasts())) {
+MainBO = BORHS->getOpcode();
+  }
+}
+  }
+
+  llvm::Constant *InitVal = llvm::Constant::getNullValue(LLVMType);
+  const Expr *Private = Privates[0];
+
+  if (const auto *DRE = dyn_cast(Private)) {
+if (const auto *VD = dyn_cast(DRE->getDecl())) {
+  if (const Expr *Init = VD->getInit()) {
+if (Init->isConstantInitializer(CGF.getContext(), false)) {
+  Expr::EvalResult Result;
+  if (Init->EvaluateAsRValue(Result, CGF.getContext())) {
+APValue &InitValue = Result.Val;
+if (InitValue.isInt()) {
+  InitVal = llvm::ConstantInt::get(LLVMType, InitValue.getInt());
+}
+  }
+}
+  }
+}
+  }
+
+  // Create an internal shared variable
+  std::string SharedName = getName({"internal_private_var"});
+  llvm::GlobalVariable *SharedVar = new llvm::GlobalVariable(
+  CGM.getModule(), LLVMType, false, llvm::GlobalValue::CommonLinkage,
+  InitVal, ".omp.reduction." + SharedName, nullptr,
+  llvm::GlobalVariable::NotThreadLocal);
+
+  SharedVar->setAlignment(
+  llvm::MaybeAlign(CGF.getContext().getTypeAlign(PrivateType) / 8));
+
+  Address SharedResult(SharedVar, SharedVar->getValueType(),
+   CGF.getContext().getTypeAlignInChars(PrivateType));
+
+  llvm::Value *ThreadId = getThreadID(CGF, Loc);
+  llvm::Value *BarrierLoc = emitUpdateLocation(CGF, Loc, OMP_ATOMIC_REDUCE);
+  llvm::Value *BarrierArgs[] = {BarrierLoc, ThreadId};
+
+  CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
+  CGM.getModule(), OMPRTL___kmpc_barrier),
+  BarrierArgs);
+
+  llvm::BasicBlock *InitBB = CGF.createBasicBlock("init");
+  llvm::BasicBlock *InitEndBB = CGF.createBasicBlock("init.end");
+
+  llvm::Value *IsWorker = CGF.Builder.CreateICmpEQ(
+  ThreadId, llvm::ConstantInt::get(ThreadId->getType(), 0));
+  CGF.Builder.CreateCondBr(IsWorker, InitBB, InitEndBB);
+
+  CGF.EmitBlock(InitBB);
+  CGF.Builder.CreateStore(InitVal, SharedResult);
+  CGF.Builder.CreateBr(InitEndBB);
+
+  CGF.EmitBlock(InitEndBB);
+
+  CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
+  CGM.getModule(), OMPRTL___kmpc_barrier),
+  BarrierArgs);
+
+  for (unsigned I = 0; I < ReductionOps.size(); ++I) {
+if (I >= LHSExprs.size()) {
+  break;
+}
+
+const auto *BinOp = dyn_cast(ReductionOps[I]);
+if (!BinOp || BinOp->getOpcode() != BO_Assign)
+  continue;
+
+const Expr *RHSExpr = BinOp->getRHS();
+if (!RHSExpr)
+  continue;
+
+BinaryOperatorKind BO = BO_Comma;
+if (const auto *BORHS =
+dyn_cast(RHSExpr->IgnoreParenImpCasts())) {
+  BO = BORHS->getOpcode();
+}
+
+LValue SharedLV = CGF.MakeAddrLValue(SharedResult, PrivateType);
+LValue LHSLV = CGF.EmitLValue(LHSExprs[I]);
+RValue PrivateRV = CGF.EmitLoadOfLValue(LHSLV, Loc);
+auto &&UpdateOp = [&CGF, PrivateRV, BinOp, BO](RValue OldVal) {
+  if (BO == BO_Mul) {
+llvm::Value *OldScalar = OldVal.getScalarVal();
+llvm::Value *PrivateScalar = PrivateRV.getScalarVal();
+llvm::Value *Result = CGF.Builder.CreateMul(OldScalar, PrivateScalar);
+return RValue::get(Result);
+  } else {
+OpaqueValueExpr OVE(BinOp->getLHS()->getExprLoc(),
+BinOp->getLHS()->getType(),
+ExprValueKind::VK_PRValue);
+CodeGenFunction::OpaqueValueMapping OldValMapping(CGF, &OVE, OldVal);
+return CGF.EmitAnyExpr(BinOp->getRHS());
+  }
+};
+
+(void)CGF.EmitOMPAtomicSimpleUpdateExpr(
+SharedLV, PrivateRV, BO, true,
+llvm::AtomicOrdering::SequentiallyConsistent, Loc, UpdateOp);
+  }
+
+  // Final barrier
+  CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
+  CGM.getModule(), OMPRTL___kmpc_barrier),
+  BarrierArgs);
+
+  // Broadcast final result
+  llvm::Value *FinalResult = CGF.Builder.CreateLoad(SharedResult);
+
+  // Update private variables with final result
+  for (unsigned I = 0; I < Pr

[clang] [HLSL] Add separate handle for the counter (PR #134864)

2025-04-08 Thread Steven Perron via cfe-commits

https://github.com/s-perron updated 
https://github.com/llvm/llvm-project/pull/134864

>From 496aaf5a3265793fc0b4b5a1a6dfb526531d825c Mon Sep 17 00:00:00 2001
From: Steven Perron 
Date: Wed, 2 Apr 2025 15:53:50 -0400
Subject: [PATCH 1/3] [HLSL] Add separate handle for the counter

In DXIL, the counters associated with some types of structured buffers
are accessed using the same handle as the buffer. That is not the case
for SPIR-V. This PR creates a separate handle for the coutner buffer.

Implements wg-hlsl proposal
[#0023](https://github.com/llvm/wg-hlsl/blob/main/proposals/0023-typed-buffer-counters.md).
---
 clang/include/clang/AST/Type.h|  9 +-
 clang/include/clang/Basic/Attr.td |  6 ++
 clang/lib/AST/ItaniumMangle.cpp   |  2 +
 clang/lib/AST/TypePrinter.cpp |  3 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 84 ---
 clang/lib/CodeGen/Targets/SPIR.cpp| 15 +++-
 clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp | 65 --
 clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h   |  4 +
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 11 ++-
 clang/lib/Sema/SemaHLSL.cpp   |  7 ++
 .../test/AST/HLSL/ByteAddressBuffers-AST.hlsl |  5 ++
 .../test/AST/HLSL/StructuredBuffers-AST.hlsl  | 17 +++-
 .../ByteAddressBuffers-constructors.hlsl  |  4 +-
 .../RWStructuredBuffer-elementtype.hlsl   | 26 +++---
 ...erOrderedStructuredBuffer-elementtype.hlsl | 26 +++---
 .../StructuredBuffers-constructors.hlsl   | 29 +--
 .../StructuredBuffers-methods-lib.hlsl|  6 +-
 .../StructuredBuffers-methods-ps.hlsl |  2 +-
 18 files changed, 231 insertions(+), 90 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 9f6189440fabf..18438e33fc0b4 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -6277,6 +6277,9 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 LLVM_PREFERRED_TYPE(bool)
 uint8_t RawBuffer : 1;
 
+LLVM_PREFERRED_TYPE(bool)
+uint8_t Counter : 1;
+
 Attributes(llvm::dxil::ResourceClass ResourceClass, bool IsROV = false,
bool RawBuffer = false)
 : ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer) {}
@@ -6284,8 +6287,9 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 Attributes() : Attributes(llvm::dxil::ResourceClass::UAV, false, false) {}
 
 friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
-  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer) ==
- std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer);
+  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer,
+  LHS.Counter) ==
+ std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer, 
LHS.Counter);
 }
 friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
   return !(LHS == RHS);
@@ -6326,6 +6330,7 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 ID.AddInteger(static_cast(Attrs.ResourceClass));
 ID.AddBoolean(Attrs.IsROV);
 ID.AddBoolean(Attrs.RawBuffer);
+ID.AddBoolean(Attrs.Counter);
   }
 
   static bool classof(const Type *T) {
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fd9e686485552..e36b513b7c926 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4845,6 +4845,12 @@ def HLSLRawBuffer : TypeAttr {
   let Documentation = [InternalOnly];
 }
 
+def HLSLCounter : TypeAttr {
+  let Spellings = [CXX11<"hlsl", "counter">];
+  let LangOpts = [HLSL];
+  let Documentation = [InternalOnly];
+}
+
 def HLSLGroupSharedAddressSpace : TypeAttr {
   let Spellings = [CustomKeyword<"groupshared">];
   let Subjects = SubjectList<[Var]>;
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index eb25b19bbdc74..0365d13700928 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -4659,6 +4659,8 @@ void CXXNameMangler::mangleType(const 
HLSLAttributedResourceType *T) {
 Str += "_ROV";
   if (Attrs.RawBuffer)
 Str += "_Raw";
+  if (Attrs.Counter)
+Str += "_CNT";
   if (T->hasContainedType())
 Str += "_CT";
   mangleVendorQualifier(Str);
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 4ec252e3f89b5..4bb7d10d1588e 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1981,6 +1981,7 @@ void TypePrinter::printAttributedAfter(const 
AttributedType *T,
   case attr::HLSLROV:
   case attr::HLSLRawBuffer:
   case attr::HLSLContainedType:
+  case attr::HLSLCounter:
 llvm_unreachable("HLSL resource type attributes handled separately");
 
   case attr::OpenCLPrivateAddressSpace:
@@ -2125,6 +2126,8 @@ void TypePrinter::printHLSLAttributedResourceAfter(
 OS << " [[hlsl::is_rov]]

[clang] [flang] [driver] Generalize the code that adds the path of libflang_rt.runtime.a. (PR #134362)

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

https://github.com/DanielCChen updated 
https://github.com/llvm/llvm-project/pull/134362

>From cd100a70479adbb4619d685e345485eea99987c5 Mon Sep 17 00:00:00 2001
From: Daniel Chen 
Date: Fri, 4 Apr 2025 06:10:56 -0400
Subject: [PATCH 1/4] [driver] Generalize adding the path of
 libflang_rt.runtime.a.

---
 clang/include/clang/Driver/ToolChain.h   |  4 
 clang/lib/Driver/ToolChain.cpp   | 20 ++--
 clang/lib/Driver/ToolChains/AIX.cpp  |  8 
 clang/lib/Driver/ToolChains/AIX.h|  3 ---
 clang/lib/Driver/ToolChains/PPCLinux.cpp | 16 
 clang/lib/Driver/ToolChains/PPCLinux.h   |  3 ---
 flang/test/Driver/linker-flags.f90   |  2 +-
 7 files changed, 23 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 076e4296c3090..d0059673d6a67 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -521,6 +521,10 @@ class ToolChain {
   addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;
 
+  /// Add the path for libflang_rt.runtime.a
+  void addFlangRTLibPath(const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs) const;
+
   const char *getCompilerRTArgString(const llvm::opt::ArgList &Args,
  StringRef Component,
  FileType Type = ToolChain::FT_Static,
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 36d0ae34dec86..054618a44d7bc 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -816,8 +816,7 @@ void ToolChain::addFortranRuntimeLibs(const ArgList &Args,
   if (AsNeeded)
 addAsNeededOption(*this, Args, CmdArgs, /*as_needed=*/false);
 }
-CmdArgs.push_back("-lflang_rt.runtime");
-addArchSpecificRPath(*this, Args, CmdArgs);
+addFlangRTLibPath(Args, CmdArgs);
 
 // needs libexecinfo for backtrace functions
 if (getTriple().isOSFreeBSD() || getTriple().isOSNetBSD() ||
@@ -850,6 +849,23 @@ void ToolChain::addFortranRuntimeLibraryPath(const 
llvm::opt::ArgList &Args,
 CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
 }
 
+void ToolChain::addFlangRTLibPath(const ArgList &Args,
+  llvm::opt::ArgStringList &CmdArgs) const {
+  // Link static flang_rt.runtime.a or shared flang_rt.runtime.so
+  const char *Path;
+  if (getVFS().exists(Twine(Path = getCompilerRTArgString(
+Args, "runtime", ToolChain::FT_Static, true
+CmdArgs.push_back(Path);
+  else if (getVFS().exists(
+   Twine(Path = getCompilerRTArgString(
+ Args, "runtime", ToolChain::FT_Shared, true
+CmdArgs.push_back(Path);
+  else {
+CmdArgs.push_back("-lflang_rt.runtime");
+addArchSpecificRPath(*this, Args, CmdArgs);
+  }
+}
+
 // Android target triples contain a target version. If we don't have libraries
 // for the exact target version, we should fall back to the next newest version
 // or a versionless path, if any.
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index 26b9d4c772be6..5dc80bc5a3d25 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -608,14 +608,6 @@ void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args,
   ToolChain::addProfileRTLibs(Args, CmdArgs);
 }
 
-void AIX::addFortranRuntimeLibs(const ArgList &Args,
-llvm::opt::ArgStringList &CmdArgs) const {
-  // Link flang_rt.runtime.a. On AIX, the static and shared library are all
-  // named .a
-  CmdArgs.push_back(
-  getCompilerRTArgString(Args, "runtime", ToolChain::FT_Static, true));
-}
-
 ToolChain::CXXStdlibType AIX::GetDefaultCXXStdlibType() const {
   return ToolChain::CST_Libcxx;
 }
diff --git a/clang/lib/Driver/ToolChains/AIX.h 
b/clang/lib/Driver/ToolChains/AIX.h
index 17e8370cd1218..8f130f6b54547 100644
--- a/clang/lib/Driver/ToolChains/AIX.h
+++ b/clang/lib/Driver/ToolChains/AIX.h
@@ -87,9 +87,6 @@ class LLVM_LIBRARY_VISIBILITY AIX : public ToolChain {
   void addProfileRTLibs(const llvm::opt::ArgList &Args,
 llvm::opt::ArgStringList &CmdArgs) const override;
 
-  void addFortranRuntimeLibs(const llvm::opt::ArgList &Args,
- llvm::opt::ArgStringList &CmdArgs) const override;
-
   CXXStdlibType GetDefaultCXXStdlibType() const override;
 
   RuntimeLibType GetDefaultRuntimeLibType() const override;
diff --git a/clang/lib/Driver/ToolChains/PPCLinux.cpp 
b/clang/lib/Driver/ToolChains/PPCLinux.cpp
index 575e88c6ab124..0ed0f91ad166c 100644
--- a/clang/lib/Driver/ToolChains/PPCLinux.cpp
+++ b/clang/lib/Driver/ToolChains/PPCLinux.cpp
@@ -12,7 +12,6 @@
 #include "clang/Driver/Options.h"
 #include "llvm/Support/FileSystem.h"

[clang] [CIR] Upstream initial function call support (PR #134673)

2025-04-08 Thread Sirui Mu via cfe-commits


@@ -1242,6 +1242,43 @@ def FuncOp : CIR_Op<"func", [
   let hasVerifier = 1;
 }
 
+//===--===//
+// CallOp
+//===--===//
+
+class CIR_CallOp extra_traits = []>
+: Op,
+  DeclareOpInterfaceMethods])> {
+  let hasCustomAssemblyFormat = 1;
+  let skipDefaultBuilders = 1;
+  let hasVerifier = 0;

Lancern wrote:

Updated.

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


[clang] [CIR] Upstream initial function call support (PR #134673)

2025-04-08 Thread Sirui Mu via cfe-commits


@@ -304,6 +305,102 @@ RValue CIRGenFunction::emitAnyExpr(const Expr *e) {
   llvm_unreachable("bad evaluation kind");
 }
 
+static cir::FuncOp emitFunctionDeclPointer(CIRGenModule &cgm, GlobalDecl gd) {
+  assert(!cir::MissingFeatures::weakRefReference());
+  return cgm.getAddrOfFunction(gd);
+}
+
+static CIRGenCallee emitDirectCallee(CIRGenModule &cgm, GlobalDecl gd) {
+  assert(!cir::MissingFeatures::opCallBuiltinFunc());
+
+  cir::FuncOp callee = emitFunctionDeclPointer(cgm, gd);
+
+  assert(!cir::MissingFeatures::hip());
+
+  return CIRGenCallee::forDirect(callee, gd);
+}
+
+RValue CIRGenFunction::emitCall(clang::QualType calleeTy,
+const CIRGenCallee &callee,
+const clang::CallExpr *e) {
+  // Get the actual function type. The callee type will always be a pointer to
+  // function type or a block pointer type.
+  assert(calleeTy->isFunctionPointerType() &&
+ "Callee must have function pointer type!");
+
+  calleeTy = getContext().getCanonicalType(calleeTy);
+
+  if (getLangOpts().CPlusPlus)
+assert(!cir::MissingFeatures::sanitizers());
+
+  assert(!cir::MissingFeatures::sanitizers());
+  assert(!cir::MissingFeatures::opCallArgs());
+
+  const CIRGenFunctionInfo &funcInfo = 
cgm.getTypes().arrangeFreeFunctionCall();
+
+  assert(!cir::MissingFeatures::opCallNoPrototypeFunc());
+  assert(!cir::MissingFeatures::opCallChainCall());
+  assert(!cir::MissingFeatures::hip());
+  assert(!cir::MissingFeatures::opCallMustTail());
+
+  cir::CIRCallOpInterface callOp;
+  RValue callResult =
+  emitCall(funcInfo, callee, &callOp, getLoc(e->getExprLoc()));
+
+  assert(!cir::MissingFeatures::generateDebugInfo());
+
+  return callResult;
+}
+
+CIRGenCallee CIRGenFunction::emitCallee(const clang::Expr *e) {
+  e = e->IgnoreParens();
+
+  // Look through function-to-pointer decay.
+  if (const auto *implicitCast = dyn_cast(e)) {
+if (implicitCast->getCastKind() == CK_FunctionToPointerDecay ||
+implicitCast->getCastKind() == CK_BuiltinFnToFnPtr) {
+  return emitCallee(implicitCast->getSubExpr());
+}
+// Resolve direct calls.
+  } else if (const auto *declRef = dyn_cast(e)) {
+const auto *funcDecl = dyn_cast(declRef->getDecl());
+assert(
+funcDecl &&
+"DeclRef referring to FunctionDecl is the only thing supported so 
far");
+return emitDirectCallee(cgm, funcDecl);
+  }
+
+  llvm_unreachable("Nothing else supported yet!");
+}
+
+RValue CIRGenFunction::emitCallExpr(const clang::CallExpr *e) {
+  assert(!cir::MissingFeatures::objCBlocks());
+
+  if (isa(e)) {
+cgm.errorNYI(e->getSourceRange(), "call to member function");
+return RValue::get(nullptr);
+  }
+
+  if (isa(e)) {
+cgm.errorNYI(e->getSourceRange(), "call to CUDA kernel");
+return RValue::get(nullptr);
+  }
+
+  if (const auto *operatorCall = dyn_cast(e)) {
+if (isa_and_nonnull(operatorCall->getCalleeDecl())) {
+  cgm.errorNYI(e->getSourceRange(), "call to member operator");
+  return RValue::get(nullptr);
+}
+  }
+
+  CIRGenCallee callee = emitCallee(e->getCallee());
+

Lancern wrote:

Updated.

BTW, I'm curious about the principles of handling NYI during the upstreaming 
process. In the incubator we typically put an `assert(false)` or a 
`MissingFeatures` check on the NYI paths. But during upstreaming it seems like:

1. We don't like the `assert(false)` approach apparently.
2. We are still using `MissingFeatures` to track the NYI parts.
3. We now have a new mechanism that emits a diagnostic upon NYI paths.

I'm actually a bit confused about how to choose between 2) and 3). Are there 
any guidelines or principles? Besides, both of 2) and 3) does not abort normal 
execution, is it possible that this may break some assumptions dependent by 
code that follows NYI check points, and eventually lead to clang crashing on 
strange program points?

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


[clang] [CIR] Upstream initial function call support (PR #134673)

2025-04-08 Thread Sirui Mu via cfe-commits


@@ -304,6 +305,102 @@ RValue CIRGenFunction::emitAnyExpr(const Expr *e) {
   llvm_unreachable("bad evaluation kind");
 }
 
+static cir::FuncOp emitFunctionDeclPointer(CIRGenModule &cgm, GlobalDecl gd) {
+  assert(!cir::MissingFeatures::weakRefReference());
+  return cgm.getAddrOfFunction(gd);
+}
+
+static CIRGenCallee emitDirectCallee(CIRGenModule &cgm, GlobalDecl gd) {
+  assert(!cir::MissingFeatures::opCallBuiltinFunc());
+
+  cir::FuncOp callee = emitFunctionDeclPointer(cgm, gd);
+
+  assert(!cir::MissingFeatures::hip());
+
+  return CIRGenCallee::forDirect(callee, gd);
+}
+
+RValue CIRGenFunction::emitCall(clang::QualType calleeTy,
+const CIRGenCallee &callee,
+const clang::CallExpr *e) {
+  // Get the actual function type. The callee type will always be a pointer to
+  // function type or a block pointer type.
+  assert(calleeTy->isFunctionPointerType() &&
+ "Callee must have function pointer type!");
+
+  calleeTy = getContext().getCanonicalType(calleeTy);
+
+  if (getLangOpts().CPlusPlus)
+assert(!cir::MissingFeatures::sanitizers());
+
+  assert(!cir::MissingFeatures::sanitizers());
+  assert(!cir::MissingFeatures::opCallArgs());
+
+  const CIRGenFunctionInfo &funcInfo = 
cgm.getTypes().arrangeFreeFunctionCall();
+
+  assert(!cir::MissingFeatures::opCallNoPrototypeFunc());
+  assert(!cir::MissingFeatures::opCallChainCall());
+  assert(!cir::MissingFeatures::hip());
+  assert(!cir::MissingFeatures::opCallMustTail());
+
+  cir::CIRCallOpInterface callOp;
+  RValue callResult =
+  emitCall(funcInfo, callee, &callOp, getLoc(e->getExprLoc()));
+
+  assert(!cir::MissingFeatures::generateDebugInfo());
+
+  return callResult;
+}
+
+CIRGenCallee CIRGenFunction::emitCallee(const clang::Expr *e) {
+  e = e->IgnoreParens();
+
+  // Look through function-to-pointer decay.
+  if (const auto *implicitCast = dyn_cast(e)) {
+if (implicitCast->getCastKind() == CK_FunctionToPointerDecay ||
+implicitCast->getCastKind() == CK_BuiltinFnToFnPtr) {
+  return emitCallee(implicitCast->getSubExpr());
+}
+// Resolve direct calls.
+  } else if (const auto *declRef = dyn_cast(e)) {
+const auto *funcDecl = dyn_cast(declRef->getDecl());
+assert(
+funcDecl &&
+"DeclRef referring to FunctionDecl is the only thing supported so 
far");
+return emitDirectCallee(cgm, funcDecl);
+  }
+
+  llvm_unreachable("Nothing else supported yet!");

Lancern wrote:

Updated.

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


[clang] [CIR] Upstream initial function call support (PR #134673)

2025-04-08 Thread Sirui Mu via cfe-commits


@@ -304,6 +305,102 @@ RValue CIRGenFunction::emitAnyExpr(const Expr *e) {
   llvm_unreachable("bad evaluation kind");
 }
 
+static cir::FuncOp emitFunctionDeclPointer(CIRGenModule &cgm, GlobalDecl gd) {
+  assert(!cir::MissingFeatures::weakRefReference());
+  return cgm.getAddrOfFunction(gd);
+}
+
+static CIRGenCallee emitDirectCallee(CIRGenModule &cgm, GlobalDecl gd) {
+  assert(!cir::MissingFeatures::opCallBuiltinFunc());
+
+  cir::FuncOp callee = emitFunctionDeclPointer(cgm, gd);
+
+  assert(!cir::MissingFeatures::hip());
+
+  return CIRGenCallee::forDirect(callee, gd);
+}
+
+RValue CIRGenFunction::emitCall(clang::QualType calleeTy,
+const CIRGenCallee &callee,
+const clang::CallExpr *e) {
+  // Get the actual function type. The callee type will always be a pointer to
+  // function type or a block pointer type.
+  assert(calleeTy->isFunctionPointerType() &&
+ "Callee must have function pointer type!");
+
+  calleeTy = getContext().getCanonicalType(calleeTy);
+
+  if (getLangOpts().CPlusPlus)
+assert(!cir::MissingFeatures::sanitizers());
+
+  assert(!cir::MissingFeatures::sanitizers());
+  assert(!cir::MissingFeatures::opCallArgs());
+
+  const CIRGenFunctionInfo &funcInfo = 
cgm.getTypes().arrangeFreeFunctionCall();
+
+  assert(!cir::MissingFeatures::opCallNoPrototypeFunc());
+  assert(!cir::MissingFeatures::opCallChainCall());
+  assert(!cir::MissingFeatures::hip());
+  assert(!cir::MissingFeatures::opCallMustTail());
+
+  cir::CIRCallOpInterface callOp;
+  RValue callResult =
+  emitCall(funcInfo, callee, &callOp, getLoc(e->getExprLoc()));
+
+  assert(!cir::MissingFeatures::generateDebugInfo());
+
+  return callResult;
+}
+
+CIRGenCallee CIRGenFunction::emitCallee(const clang::Expr *e) {
+  e = e->IgnoreParens();
+
+  // Look through function-to-pointer decay.
+  if (const auto *implicitCast = dyn_cast(e)) {
+if (implicitCast->getCastKind() == CK_FunctionToPointerDecay ||
+implicitCast->getCastKind() == CK_BuiltinFnToFnPtr) {
+  return emitCallee(implicitCast->getSubExpr());
+}
+// Resolve direct calls.
+  } else if (const auto *declRef = dyn_cast(e)) {
+const auto *funcDecl = dyn_cast(declRef->getDecl());
+assert(

Lancern wrote:

Yes, updated to follow classic codegen approach.

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


[clang] [CIR] Upstream initial function call support (PR #134673)

2025-04-08 Thread Sirui Mu via cfe-commits


@@ -304,6 +305,102 @@ RValue CIRGenFunction::emitAnyExpr(const Expr *e) {
   llvm_unreachable("bad evaluation kind");
 }
 
+static cir::FuncOp emitFunctionDeclPointer(CIRGenModule &cgm, GlobalDecl gd) {
+  assert(!cir::MissingFeatures::weakRefReference());
+  return cgm.getAddrOfFunction(gd);
+}
+
+static CIRGenCallee emitDirectCallee(CIRGenModule &cgm, GlobalDecl gd) {
+  assert(!cir::MissingFeatures::opCallBuiltinFunc());
+
+  cir::FuncOp callee = emitFunctionDeclPointer(cgm, gd);
+
+  assert(!cir::MissingFeatures::hip());
+
+  return CIRGenCallee::forDirect(callee, gd);
+}
+
+RValue CIRGenFunction::emitCall(clang::QualType calleeTy,
+const CIRGenCallee &callee,
+const clang::CallExpr *e) {
+  // Get the actual function type. The callee type will always be a pointer to
+  // function type or a block pointer type.
+  assert(calleeTy->isFunctionPointerType() &&
+ "Callee must have function pointer type!");
+
+  calleeTy = getContext().getCanonicalType(calleeTy);
+
+  if (getLangOpts().CPlusPlus)
+assert(!cir::MissingFeatures::sanitizers());
+
+  assert(!cir::MissingFeatures::sanitizers());
+  assert(!cir::MissingFeatures::opCallArgs());
+
+  const CIRGenFunctionInfo &funcInfo = 
cgm.getTypes().arrangeFreeFunctionCall();
+
+  assert(!cir::MissingFeatures::opCallNoPrototypeFunc());
+  assert(!cir::MissingFeatures::opCallChainCall());
+  assert(!cir::MissingFeatures::hip());
+  assert(!cir::MissingFeatures::opCallMustTail());
+
+  cir::CIRCallOpInterface callOp;
+  RValue callResult =
+  emitCall(funcInfo, callee, &callOp, getLoc(e->getExprLoc()));
+
+  assert(!cir::MissingFeatures::generateDebugInfo());
+
+  return callResult;
+}
+
+CIRGenCallee CIRGenFunction::emitCallee(const clang::Expr *e) {
+  e = e->IgnoreParens();
+
+  // Look through function-to-pointer decay.
+  if (const auto *implicitCast = dyn_cast(e)) {
+if (implicitCast->getCastKind() == CK_FunctionToPointerDecay ||
+implicitCast->getCastKind() == CK_BuiltinFnToFnPtr) {
+  return emitCallee(implicitCast->getSubExpr());
+}
+// Resolve direct calls.

Lancern wrote:

Updated.

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


[clang] [libcxx] [Clang] Add __builtin_invoke and use it in libc++ (PR #116709)

2025-04-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/116709

>From 613ef41a6e3bfa3a24e45ce7761918639143cf82 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 1 Oct 2024 11:08:02 +0200
Subject: [PATCH] [Clang] Add __builtin_invoke and recognize std::invoke as a
 builtin

---
 clang/include/clang/Basic/Builtins.td |   6 +
 clang/include/clang/Sema/Sema.h   |   9 ++
 clang/lib/Sema/SemaChecking.cpp   |  97 +++
 clang/lib/Sema/SemaExprCXX.cpp| 105 ++--
 clang/test/CodeGenCXX/builtin-invoke.cpp  |  61 +++
 clang/test/SemaCXX/builtin-invoke.cpp | 133 +++
 libcxx/include/__type_traits/invoke.h | 152 ++
 .../__type_traits/is_core_convertible.h   |  11 ++
 8 files changed, 495 insertions(+), 79 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/builtin-invoke.cpp
 create mode 100644 clang/test/SemaCXX/builtin-invoke.cpp

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 2e077176ac7e9..f671cfbb9d306 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4254,6 +4254,12 @@ def MoveIfNsoexcept : CxxLibBuiltin<"utility"> {
   let Namespace = "std";
 }
 
+def Invoke : Builtin {
+  let Spellings = ["__builtin_invoke"];
+  let Attributes = [CustomTypeChecking, Constexpr];
+  let Prototype = "void(...)";
+}
+
 def Annotation : Builtin {
   let Spellings = ["__builtin_annotation"];
   let Attributes = [NoThrow, CustomTypeChecking];
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6bf1caf6bdd18..a4e675b8424ee 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2212,6 +2212,8 @@ class Sema final : public SemaBase {
SourceLocation BuiltinLoc,
SourceLocation RParenLoc);
 
+  ExprResult BuiltinInvoke(CallExpr *TheCall);
+
   enum FormatStringType {
 FST_Scanf,
 FST_Printf,
@@ -15090,11 +15092,18 @@ class Sema final : public SemaBase {
SourceLocation Loc);
   QualType BuiltinRemoveReference(QualType BaseType, UTTKind UKind,
   SourceLocation Loc);
+
+  QualType BuiltinRemoveCVRef(QualType BaseType, SourceLocation Loc) {
+return BuiltinRemoveReference(BaseType, UTTKind::RemoveCVRef, Loc);
+  }
+
   QualType BuiltinChangeCVRQualifiers(QualType BaseType, UTTKind UKind,
   SourceLocation Loc);
   QualType BuiltinChangeSignedness(QualType BaseType, UTTKind UKind,
SourceLocation Loc);
 
+  bool BuiltinIsBaseOf(SourceLocation RhsTLoc, QualType LhsT, QualType RhsT);
+
   /// Ensure that the type T is a literal type.
   ///
   /// This routine checks whether the type @p T is a literal type. If @p T is 
an
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 5a4fa97366809..8dddc8d760f08 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2273,6 +2273,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 return BuiltinShuffleVector(TheCall);
 // TheCall will be freed by the smart pointer here, but that's fine, since
 // BuiltinShuffleVector guts it, but then doesn't release it.
+  case Builtin::BI__builtin_invoke:
+return BuiltinInvoke(TheCall);
   case Builtin::BI__builtin_prefetch:
 if (BuiltinPrefetch(TheCall))
   return ExprError();
@@ -5290,6 +5292,101 @@ ExprResult Sema::ConvertVectorExpr(Expr *E, 
TypeSourceInfo *TInfo,
RParenLoc, CurFPFeatureOverrides());
 }
 
+ExprResult Sema::BuiltinInvoke(CallExpr *TheCall) {
+  auto Loc = TheCall->getBeginLoc();
+  auto Args = MutableArrayRef(TheCall->getArgs(), TheCall->getNumArgs());
+  assert(llvm::none_of(Args,
+   [](Expr *Arg) { return Arg->isTypeDependent(); }));
+
+  if (Args.size() == 0) {
+Diag(TheCall->getBeginLoc(), 
diag::err_typecheck_call_too_few_args_at_least)
+<< 0 << 1 << 0 << 0 << TheCall->getSourceRange();
+return ExprError();
+  }
+
+  auto FuncT = Args[0]->getType();
+
+  if (auto *MPT = FuncT->getAs()) {
+if (Args.size() < 2) {
+  Diag(TheCall->getBeginLoc(),
+diag::err_typecheck_call_too_few_args_at_least)
+  << 0 << 2 << 1 << 0 << TheCall->getSourceRange();
+  return ExprError();
+}
+
+auto *MemPtrClass = MPT->getQualifier()->getAsType();
+auto ObjectT = Args[1]->getType();
+
+
+if (MPT->isMemberDataPointer() && Args.size() != 2) {
+  Diag(TheCall->getBeginLoc(), diag::err_typecheck_call_too_many_args)
+  << 0 << 2 << Args.size() << 0 << TheCall->getSourceRange();
+  return ExprError();
+}
+
+ExprResult ObjectArg = [&]() -> ExprResult {
+  // (1.1): (t1.*f)(t2, …, tN) when f is a point

[clang] [clang-tools-extra] [libcxx] [clang] fix diagnostic printing of expressions ignoring LangOpts (PR #134693)

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


@@ -7379,6 +7379,14 @@ class RecoveryExpr final : public Expr,
   friend class ASTStmtWriter;
 };
 
+/// Insertion operator for diagnostics.  This allows sending
+/// Expr into a diagnostic with <<.
+inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
+ const Expr *E) {
+  DB.AddTaggedVal(reinterpret_cast(E), DiagnosticsEngine::ak_expr);

erichkeane wrote:

`intptr_t` /`uintptr_t` I think avoids any 'round trip' errors by standard, but 
I think `uint64_t` is going to be the same type ANYWAY so this is probably 
harmless at least.  I think the suggestion to use `intptr_t`/`uintptr_t` is a 
good one that should happen.

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


[clang] Mark CXX module initializer with PACBTI attributes (PR #133716)

2025-04-08 Thread Victor Campos via cfe-commits


@@ -447,6 +447,8 @@ llvm::Function 
*CodeGenModule::CreateGlobalInitOrCleanUpFunction(
 
   if (Linkage == llvm::GlobalVariable::InternalLinkage)
 SetInternalFunctionAttributes(GlobalDecl(), Fn, FI);
+  else
+getTargetCodeGenInfo().setTargetAttributes(nullptr, Fn, *this);

vhscampos wrote:

Done

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


[clang] [llvm] [IR] Mark convergence intrins as has-side-effect (PR #134844)

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

arsenm wrote:

> I suspect the long-term change to change the default IR to assume convergent 
> will take some time as it will impact many subprojects. 

Turns out not really, I ran spec with this about 2 years ago and the only 
non-noise change was a mild improvement 

> Would you be OK with me patching the several DCE functions to not drop 
> convergence intrinsics instead? It would solve this issue in practice, 
> allowing us to move forward with addrspace cast legalization.

This is still trying to fix this in a roundabout way. You should be stopping 
the strip of the convergent attribute, not the intrinsic uses that happen to be 
in the function 

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


[clang] Implement `-dump-deserialized-declaration-ranges` flag. (PR #133910)

2025-04-08 Thread Viktoriia Bakalova via cfe-commits

https://github.com/VitaNuo updated 
https://github.com/llvm/llvm-project/pull/133910

>From cfa057b4d43ebe7f94ccd4f387a94359beaa29b2 Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Fri, 4 Apr 2025 17:45:24 +0200
Subject: [PATCH 1/9] This commit implements a CC1 flag
 `-dump-deserialized-declaration-ranges`. The flag allows to specify a file
 path to dump ranges of deserialized declarations in `ASTReader`. Example
 usage:

```
clang -Xclang=-dump-deserialized-declaration-ranges=/tmp/decls -c file.cc -o 
file.o
```

Example output:
```
// /tmp/decls
{
  "required_ranges": [
{
  "file": "foo.h",
  "range": [
{
  "from": {
"line": 26,
"column": 1
  },
  "to": {
"line": 27,
"column": 77
  }
}
  ]
},
{
  "file": "bar.h",
  "range": [
{
  "from": {
"line": 30,
"column": 1
  },
  "to": {
"line": 35,
"column": 1
  }
},
{
  "from": {
"line": 92,
"column": 1
  },
  "to": {
"line": 95,
"column": 1
  }
}
  ]
}
  ]
}

```
Specifying the flag creates an instance of `DeserializedDeclsLineRangePrinter`, 
which dumps ranges of deserialized declarations to aid debugging and bug 
minimization.

Required ranges are computed from source ranges of Decls. 
`TranslationUnitDecl`, `LinkageSpecDecl` and `NamespaceDecl` are ignored for 
the sake of this PR.

Technical details:
* `DeserializedDeclsLineRangePrinter` implements `ASTConsumer` and 
`ASTDeserializationListener`, so that an object of 
`DeserializedDeclsLineRangePrinter` registers as its own listener.
* `ASTDeserializationListener` interface provides the `DeclRead` callback that 
we use to collect the deserialized Decls.
Printing or otherwise processing them as this point is dangerous, since that 
could trigger additional deserialization and crash compilation.
* The collected Decls are processed in `HandleTranslationUnit` method of 
`ASTConsumer`. This is a safe point, since we know that by this point all the 
Decls needed by the compiler frontend have been deserialized.
*  In case our processing causes further deserialization, `DeclRead` from the 
listener might be called again. However, at that point we don't accept any more 
Decls for processing.
---
 clang/include/clang/Driver/Options.td |   4 +
 .../include/clang/Frontend/FrontendOptions.h  |   3 +
 clang/lib/Frontend/FrontendAction.cpp | 190 +-
 .../dump-deserialized-declaration-ranges.cpp  | 118 +++
 4 files changed, 310 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Frontend/dump-deserialized-declaration-ranges.cpp

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3af072242d039..1737e40b776e1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -7968,6 +7968,10 @@ def print_dependency_directives_minimized_source : 
Flag<["-"],
   "print-dependency-directives-minimized-source">,
   HelpText<"Print the output of the dependency directives source minimizer">;
 }
+def dump_deserialized_declaration_ranges : Joined<["-"],
+  "dump-deserialized-declaration-ranges=">,
+  HelpText<"Dump ranges of deserialized declarations to aid debugging and 
minimization">,
+  MarshallingInfoString>;
 
 defm emit_llvm_uselists : BoolOption<"", "emit-llvm-uselists",
   CodeGenOpts<"EmitLLVMUseLists">, DefaultFalse,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index a9c9849ff52ab..8ef9ce9db8783 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -530,6 +530,9 @@ class FrontendOptions {
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
+  /// Output path to dump ranges of deserialized declarations.
+  std::string DumpDeserializedDeclarationRangesPath;
+
 public:
   FrontendOptions()
   : DisableFree(false), RelocatablePCH(false), ShowHelp(false),
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 2d77f06be7446..1f939f7722d19 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -15,6 +15,8 @@
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/LangStandard.h"
 #include "clang/Basic/Sarif.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Stack.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -35,6 +37,7 @@
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/

[clang] [clang-tools-extra] [libcxx] [clang] fix diagnostic printing of expressions ignoring LangOpts (PR #134693)

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


@@ -7379,6 +7379,14 @@ class RecoveryExpr final : public Expr,
   friend class ASTStmtWriter;
 };
 
+/// Insertion operator for diagnostics.  This allows sending
+/// Expr into a diagnostic with <<.
+inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
+ const Expr *E) {
+  DB.AddTaggedVal(reinterpret_cast(E), DiagnosticsEngine::ak_expr);

erichkeane wrote:

> If we care that uint64_t might not round trip a pointer in theory, even 
> though it should always in practice, then do we care uintptr_t is not 
> guaranteed to be provided in theory, even though it should always be in 
> practice?

THAT we don't care about because : 1- it is a compile-time diagnosed missing 
'thing', and 2- We know all our supported host platforms have (and presumably 
always will have) that type.

So it is a matter of "potentially ill-formed" vs "potential-UB".

Either way, it doesn't MATTER very much, but from a 'most correct' perspective 
(as frankly, `uint64_t` and `uintptr_t` are probably the same type, and I would 
bet good money that none of our platforms would ever change that/never give 
`uintptr_t` its own representation to take advantage of this UB), but just 
changing the cast type here is the right thing to do.

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


[clang] [Clang][Sema] Fix -Whigher-precision-for-complex-division (PR #131477)

2025-04-08 Thread Zahira Ammarguellat via cfe-commits
=?utf-8?q?Mészáros?= Gergely 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 %s -complex-range=promoted -triple x86_64-unknown-linux 
-verify=no-diag \
+// RUN: -DDIV_CC -DDIV_RC -DDIVASSIGN -DDIVMIXEDFD -DDIVMIXEDID
+
+// RUN: %clang_cc1 %s -complex-range=promoted -triple x86_64-unknown-windows 
-verify=no-diag
+// RUN: %clang_cc1 %s -complex-range=promoted -triple x86_64-unknown-windows 
-verify -DDIV_CC
+// RUN: %clang_cc1 %s -complex-range=promoted -triple x86_64-unknown-windows 
-verify -DDIV_RC
+// RUN: %clang_cc1 %s -complex-range=promoted -triple x86_64-unknown-windows 
-verify -DDIVASSIGN
+// RUN: %clang_cc1 %s -complex-range=promoted -triple x86_64-unknown-windows 
-verify -DDIVMIXEDFD
+// RUN: %clang_cc1 %s -complex-range=promoted -triple x86_64-unknown-windows 
-verify -DDIVMIXEDID
+
+_Complex double div_ccf(_Complex float a, _Complex float b) {
+return a / b;
+}
+
+_Complex double div_cr(_Complex double a, double b) {
+return a / b;
+}
+
+_Complex double div_rr(double a, double b) {
+return a / b;
+}
+
+_Complex int div_ii(_Complex int a, _Complex int b) {
+return a / b;
+}
+
+#ifdef DIV_CC
+_Complex double div_cc(_Complex double a, const _Complex double b) {
+return a / b; // #1
+}
+#endif // DIV_CC
+
+#ifdef DIV_RC
+_Complex double div_rc(double a, _Complex float b) {
+return a / b; // #1
+}
+#endif // DIV_RC
+
+#ifdef DIVASSIGN
+_Complex double divassign(_Complex double a, _Complex double b) {
+return a /= b; // #1

zahiraam wrote:

How about the `/=` with different input types?

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


[clang] [Clang][Sema] Fix -Whigher-precision-for-complex-division (PR #131477)

2025-04-08 Thread Zahira Ammarguellat via cfe-commits
=?utf-8?q?Mészáros?= Gergely 
Message-ID:
In-Reply-To: 



@@ -10591,6 +10591,45 @@ static void checkArithmeticNull(Sema &S, ExprResult 
&LHS, ExprResult &RHS,
   << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
 }
 
+static void DetectPrecisionLossInComplexDivision(Sema &S, QualType DivisorTy,
+ SourceLocation OpLoc) {
+  // If the divisor is real, then this is real/real or complex/real division.
+  // Either way there can be no precision loss.
+  auto *CT = DivisorTy->getAs();
+  if (!CT)
+return;

zahiraam wrote:

But that's only true if the target doesn't support higher precision types 
right? At this point this is not known.

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


[clang] [clang-tools-extra] [libcxx] [clang] fix diagnostic printing of expressions ignoring LangOpts (PR #134693)

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


@@ -7379,6 +7379,14 @@ class RecoveryExpr final : public Expr,
   friend class ASTStmtWriter;
 };
 
+/// Insertion operator for diagnostics.  This allows sending
+/// Expr into a diagnostic with <<.
+inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
+ const Expr *E) {
+  DB.AddTaggedVal(reinterpret_cast(E), DiagnosticsEngine::ak_expr);

mizvekov wrote:

It's not just here though, this is the same for all other kinds, and the same 
for the parameter type, and the same for where we store this.

It wouldn't change much regarding potential UB if we wrote uintptr_t here, but 
then this would implicitly cast to uint64_t anyway.

Now if we change that to uintptr_t, then that would be bad in 32 bit platforms, 
as this is used to pack other things besides pointers. So presumably we want to 
change the parameter and structure types here to something that's at least as 
big as both types, which would be uintmax perhaps?

Or maybe just assert somewhere that uint64 is at least as big as uintptr?

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


[clang] [Clang] add ext warning for missing return in 'main' for C89 mode (PR #134617)

2025-04-08 Thread Oleksandr T. via cfe-commits


@@ -1031,6 +1031,8 @@ def err_mainlike_template_decl : Error<"%0 cannot be a 
template">;
 def err_main_returns_nonint : Error<"'main' must return 'int'">;
 def ext_main_returns_nonint : ExtWarn<"return type of 'main' is not 'int'">,
 InGroup;
+def ext_main_no_return : Extension<"implicit '0' return value from 'main' is a 
C99 extension">,
+InGroup;

a-tarasyuk wrote:

@AaronBallman Thanks. I've updated formatting.

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


[clang] [clang][DependencyScanning] Track dependencies from prebuilt modules to determine IsInStableDir (PR #132237)

2025-04-08 Thread Jan Svoboda via cfe-commits

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


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


[clang] [CIR] Upstream CmpOp (PR #133159)

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

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

lgtm

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


[clang] [CIR] Upstream CmpOp (PR #133159)

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

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


[clang] [Clang][Docs] Add release note for execute-only support on AArch64 (PR #134802)

2025-04-08 Thread David Green via cfe-commits
=?utf-8?q?Csan=C3=A1d_Hajd=C3=BA?= 
Message-ID:
In-Reply-To: 


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

Thanks, LGTM

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


[libclc] [NFC][libclc] Merge atomic extension built-ins with identical name into a single file (PR #134489)

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


@@ -0,0 +1,36 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include 
+#include 
+
+// cl_khr_global_int32_base_atomics
+_CLC_OVERLOAD _CLC_DECL int atom_cmpxchg(volatile global int *p, int cmp,
+ int val);
+_CLC_OVERLOAD _CLC_DECL unsigned int
+atom_cmpxchg(volatile global unsigned int *p, unsigned int cmp,
+ unsigned int val);
+
+// cl_khr_local_int32_base_atomics
+_CLC_OVERLOAD _CLC_DECL int atom_cmpxchg(volatile local int *p, int cmp,
+ int val);
+_CLC_OVERLOAD _CLC_DECL unsigned int
+atom_cmpxchg(volatile local unsigned int *p, unsigned int cmp,
+ unsigned int val);
+
+// cl_khr_int64_base_atomics
+_CLC_OVERLOAD _CLC_DECL long atom_cmpxchg(volatile global long *p, long cmp,

frasercrmck wrote:

Should this not be guarded by `#if cl_khr_int64_extended_atomics`? I don't 
think we can have unguarded `long` types.

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


[libclc] [NFC][libclc] Merge atomic extension built-ins with identical name into a single file (PR #134489)

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


@@ -6,7 +6,28 @@
 //
 
//===--===//
 
-#include 
+#include 
+#include 
+
+// cl_khr_global_int32_base_atomics
+#define IMPL(TYPE) \

frasercrmck wrote:

This doesn't look clang-formatted.

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


[libclc] [NFC][libclc] Merge atomic extension built-ins with identical name into a single file (PR #134489)

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

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


[clang] [clang-tools-extra] [libcxx] [clang] improved preservation of template keyword (PR #133610)

2025-04-08 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

#134748 doesn't fix errors in the original code, unfortunately. Now we're 
getting `out-of-line definition of 'X' does not match any declaration in 'Y'`. 
It's hard to tell whether the original code is correct, but I suppose that the 
purpose of this change was not to make Clang stricter?

I'm re-running reduction with Clang after #134748

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


[clang] [llvm][Stmt]:Fix musttail attribute on a function with not_tail_called attribute has no warning/error (PR #134465)

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

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

First:
The title of this PR has `llvm` and `stmt` in it, neither of which should be 
used here, so don't bother with a tag.

Second:
The PR message (which we use as a commit message) needs a ton more detail.

Third:
Please add a release note to this.

Four:
This needs tests to show that what it is doing is correct.

Five: 
I don't think this is really a good idea to make this an error, not a warning 
under `IgnoredAttributes`.  It seems more reasonable to just warn here.

Six: 
The diagnostic I think needs rewording.  It isn't clear that it is referring to 
either the `musttail` attribute nor the `not_tail_called` attribute.

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


[clang] [Clang] [NFC] Tablegen component diags headers (PR #134777)

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

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


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


[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

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


@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const 
UnaryOperator *e) {
   llvm_unreachable("Unknown unary operator kind!");
 }
 
+/// If the specified expr is a simple decay from an array to pointer,
+/// return the array subexpression.
+/// FIXME: this could be abstracted into a common AST helper.
+static const Expr *isSimpleArrayDecayOperand(const Expr *e) {
+  // If this isn't just an array->pointer decay, bail out.
+  const auto *castExpr = dyn_cast(e);
+  if (!castExpr || castExpr->getCastKind() != CK_ArrayToPointerDecay)
+return nullptr;
+
+  // If this is a decay from variable width array, bail out.
+  const Expr *subExpr = castExpr->getSubExpr();
+  if (subExpr->getType()->isVariableArrayType())
+return nullptr;
+
+  return subExpr;
+}
+
+static mlir::IntegerAttr getConstantIndexOrNull(mlir::Value idx) {
+  // TODO(cir): should we consider using MLIRs IndexType instead of 
IntegerAttr?
+  if (auto constantOp = dyn_cast(idx.getDefiningOp()))
+return mlir::dyn_cast(constantOp.getValue());
+  return {};
+}
+
+static CharUnits getArrayElementAlign(CharUnits arrayAlign, mlir::Value idx,
+  CharUnits eltSize) {
+  // If we have a constant index, we can use the exact offset of the
+  // element we're accessing.
+  const mlir::IntegerAttr constantIdx = getConstantIndexOrNull(idx);
+  if (constantIdx) {
+const CharUnits offset = constantIdx.getValue().getZExtValue() * eltSize;
+return arrayAlign.alignmentAtOffset(offset);
+  }
+  // Otherwise, use the worst-case alignment for any element.
+  return arrayAlign.alignmentOfArrayElement(eltSize);
+}
+
+static QualType getFixedSizeElementType(const ASTContext &astContext,
+const VariableArrayType *vla) {
+  QualType eltType;
+  do {
+eltType = vla->getElementType();
+  } while ((vla = astContext.getAsVariableArrayType(eltType)));
+  return eltType;
+}
+
+static mlir::Value
+emitArraySubscriptPtr(CIRGenFunction &cgf, mlir::Location beginLoc,
+  mlir::Location endLoc, mlir::Value ptr, mlir::Type eltTy,
+  ArrayRef indices, bool inbounds,
+  bool signedIndices, bool shouldDecay,
+  const llvm::Twine &name = "arrayidx") {
+  if (indices.size() > 1) {
+cgf.cgm.errorNYI("emitArraySubscriptPtr: handle multiple indices");
+return {};
+  }
+
+  const mlir::Value idx = indices.back();
+  CIRGenModule &cgm = cgf.getCIRGenModule();
+  // TODO(cir): LLVM codegen emits in bound gep check here, is there anything
+  // that would enhance tracking this later in CIR?
+  if (inbounds)
+assert(!cir::MissingFeatures::emitCheckedInBoundsGEP() && "NYI");
+  return cgm.getBuilder().getArrayElement(beginLoc, endLoc, ptr, eltTy, idx,
+  shouldDecay);
+}
+
+static Address emitArraySubscriptPtr(
+CIRGenFunction &cgf, mlir::Location beginLoc, mlir::Location endLoc,
+Address addr, ArrayRef indices, QualType eltType,
+bool inbounds, bool signedIndices, mlir::Location loc, bool shouldDecay,
+QualType *arrayType = nullptr, const Expr *base = nullptr,
+const llvm::Twine &name = "arrayidx") {
+
+  // Determine the element size of the statically-sized base.  This is
+  // the thing that the indices are expressed in terms of.
+  if (const VariableArrayType *vla =
+  cgf.getContext().getAsVariableArrayType(eltType)) {
+eltType = getFixedSizeElementType(cgf.getContext(), vla);
+  }
+
+  // We can use that to compute the best alignment of the element.
+  const CharUnits eltSize = cgf.getContext().getTypeSizeInChars(eltType);
+  const CharUnits eltAlign =
+  getArrayElementAlign(addr.getAlignment(), indices.back(), eltSize);
+
+  mlir::Value eltPtr;
+  const mlir::IntegerAttr lastIndex = getConstantIndexOrNull(indices.back());
+  if (!lastIndex) {
+eltPtr = emitArraySubscriptPtr(cgf, beginLoc, endLoc, addr.getPointer(),
+   addr.getElementType(), indices, inbounds,
+   signedIndices, shouldDecay, name);
+  }

andykaylor wrote:

This needs an `else` case with `errorNYI`, right?

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


[clang] [Clang][Sema] Handle invalid variable template specialization whose type depends on itself (PR #134522)

2025-04-08 Thread Yanzuo Liu via cfe-commits


@@ -47,3 +47,21 @@ namespace InvalidInsertPos {
   template<> int v;
   int k = v;
 }
+
+namespace GH51347 {
+  template 
+  auto p = p; // expected-error {{the type of variable template 
specialization 'p'}}

zwuis wrote:

I think this pattern is always illegal. But it's a big work (compared with this 
PR) to recognize this pattern (as something like current instantiation).

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


[libclc] libclc: frexp: fix implementation regarding denormals (PR #134823)

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


@@ -26,7 +26,7 @@ __clc_frexp(__CLC_GENTYPE x, __CLC_ADDRESS_SPACE __CLC_INTN 
*ep) {
   (ai & (__CLC_INTN)MANTBITS_SP32);
 
   __CLC_INTN is_inf_nan_or_zero =
-  x == __CLC_FP_LIT(0.0) || __clc_isinf(x) || __clc_isnan(x);
+  ai == (__CLC_INTN)0 || __clc_isinf(x) || __clc_isnan(x);

rjodinchr wrote:

This is passing the CTS on all platforms I could put my hand on.

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


[clang] [CIR] Handle NullStmt (PR #134889)

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

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


[clang] [Clang][OpenCL][AMDGPU] Use `byref` for OpenCL kernel arguments (PR #134892)

2025-04-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Shilei Tian (shiltian)


Changes

Due to a previous workaround allowing kernels to be called from other functions,
Clang currently doesn't use the `byref` attribute for aggregate kernel
arguments. The issue was recently resolved in
https://github.com/llvm/llvm-project/pull/115821. With that fix, we can now
enable the use of `byref` consistently across all languages.

Co-authored-by: Matt Arsenault 

---

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


5 Files Affected:

- (modified) clang/lib/CodeGen/Targets/AMDGPU.cpp (+1-5) 
- (modified) clang/test/CodeGenOpenCL/addr-space-struct-arg.cl (+54-102) 
- (modified) clang/test/CodeGenOpenCL/amdgpu-abi-struct-arg-byref.cl (+22-34) 
- (modified) clang/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl (+16-8) 
- (modified) clang/test/CodeGenOpenCL/opencl-kernel-call.cl (+23-47) 


``diff
diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index db2a2c5740646..bcf039d9f268a 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -198,14 +198,10 @@ ABIArgInfo 
AMDGPUABIInfo::classifyKernelArgumentType(QualType Ty) const {
 /*ToAS=*/getContext().getTargetAddressSpace(LangAS::cuda_device));
   }
 
-  // FIXME: Should also use this for OpenCL, but it requires addressing the
-  // problem of kernels being called.
-  //
   // FIXME: This doesn't apply the optimization of coercing pointers in structs
   // to global address space when using byref. This would require implementing 
a
   // new kind of coercion of the in-memory type when for indirect arguments.
-  if (!getContext().getLangOpts().OpenCL && LTy == OrigLTy &&
-  isAggregateTypeForABI(Ty)) {
+  if (LTy == OrigLTy && isAggregateTypeForABI(Ty)) {
 return ABIArgInfo::getIndirectAliased(
 getContext().getTypeAlignInChars(Ty),
 getContext().getTargetAddressSpace(LangAS::opencl_constant),
diff --git a/clang/test/CodeGenOpenCL/addr-space-struct-arg.cl 
b/clang/test/CodeGenOpenCL/addr-space-struct-arg.cl
index 789aae7a5c34c..49604c6c5e61b 100644
--- a/clang/test/CodeGenOpenCL/addr-space-struct-arg.cl
+++ b/clang/test/CodeGenOpenCL/addr-space-struct-arg.cl
@@ -546,12 +546,10 @@ kernel void KernelLargeTwoMember(struct 
LargeStructTwoMember u) {
 //
 //
 // AMDGCN-LABEL: define dso_local amdgpu_kernel void @KernelLargeOneMember(
-// AMDGCN-SAME: [[STRUCT_LARGESTRUCTONEMEMBER:%.*]] [[U_COERCE:%.*]]) 
#[[ATTR1]] !kernel_arg_addr_space [[META10]] !kernel_arg_access_qual [[META11]] 
!kernel_arg_type [[META16:![0-9]+]] !kernel_arg_base_type [[META16]] 
!kernel_arg_type_qual [[META13]] {
+// AMDGCN-SAME: ptr addrspace(4) noundef 
byref([[STRUCT_LARGESTRUCTONEMEMBER:%.*]]) align 8 [[TMP0:%.*]]) #[[ATTR1]] 
!kernel_arg_addr_space [[META10]] !kernel_arg_access_qual [[META11]] 
!kernel_arg_type [[META16:![0-9]+]] !kernel_arg_base_type [[META16]] 
!kernel_arg_type_qual [[META13]] {
 // AMDGCN-NEXT:  [[ENTRY:.*:]]
 // AMDGCN-NEXT:[[U:%.*]] = alloca [[STRUCT_LARGESTRUCTONEMEMBER]], align 
8, addrspace(5)
-// AMDGCN-NEXT:[[TMP0:%.*]] = getelementptr inbounds nuw 
[[STRUCT_LARGESTRUCTONEMEMBER]], ptr addrspace(5) [[U]], i32 0, i32 0
-// AMDGCN-NEXT:[[TMP1:%.*]] = extractvalue [[STRUCT_LARGESTRUCTONEMEMBER]] 
[[U_COERCE]], 0
-// AMDGCN-NEXT:store [100 x <2 x i32>] [[TMP1]], ptr addrspace(5) 
[[TMP0]], align 8
+// AMDGCN-NEXT:call void @llvm.memcpy.p5.p4.i64(ptr addrspace(5) align 8 
[[U]], ptr addrspace(4) align 8 [[TMP0]], i64 800, i1 false)
 // AMDGCN-NEXT:call void @__clang_ocl_kern_imp_KernelLargeOneMember(ptr 
addrspace(5) noundef byref([[STRUCT_LARGESTRUCTONEMEMBER]]) align 8 [[U]]) 
#[[ATTR4]]
 // AMDGCN-NEXT:ret void
 //
@@ -596,20 +594,15 @@ kernel void KernelLargeTwoMember(struct 
LargeStructTwoMember u) {
 //
 //
 // AMDGCN-LABEL: define dso_local amdgpu_kernel void @KernelTwoMember(
-// AMDGCN-SAME: [[STRUCT_STRUCTTWOMEMBER:%.*]] [[U_COERCE:%.*]]) #[[ATTR1]] 
!kernel_arg_addr_space [[META10]] !kernel_arg_access_qual [[META11]] 
!kernel_arg_type [[META17:![0-9]+]] !kernel_arg_base_type [[META17]] 
!kernel_arg_type_qual [[META13]] {
+// AMDGCN-SAME: ptr addrspace(4) noundef byref([[STRUCT_STRUCTTWOMEMBER:%.*]]) 
align 8 [[TMP0:%.*]]) #[[ATTR1]] !kernel_arg_addr_space [[META10]] 
!kernel_arg_access_qual [[META11]] !kernel_arg_type [[META17:![0-9]+]] 
!kernel_arg_base_type [[META17]] !kernel_arg_type_qual [[META13]] {
 // AMDGCN-NEXT:  [[ENTRY:.*:]]
 // AMDGCN-NEXT:[[U:%.*]] = alloca [[STRUCT_STRUCTTWOMEMBER]], align 8, 
addrspace(5)
-// AMDGCN-NEXT:[[TMP0:%.*]] = getelementptr inbounds nuw 
[[STRUCT_STRUCTTWOMEMBER]], ptr addrspace(5) [[U]], i32 0, i32 0
-// AMDGCN-NEXT:[[TMP1:%.*]] = extractvalue [[STRUCT_STRUCTTWOMEMBER]] 
[[U_COERCE]], 0
-// AMDGCN-NEXT:store <2 x i32> [[TMP1]], ptr addrspace(5) [[TMP0]], al

[clang] [Clang][OpenCL][AMDGPU] Use `byref` for OpenCL kernel arguments (PR #134892)

2025-04-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Shilei Tian (shiltian)


Changes

Due to a previous workaround allowing kernels to be called from other functions,
Clang currently doesn't use the `byref` attribute for aggregate kernel
arguments. The issue was recently resolved in
https://github.com/llvm/llvm-project/pull/115821. With that fix, we can now
enable the use of `byref` consistently across all languages.

Co-authored-by: Matt Arsenault 

---

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


5 Files Affected:

- (modified) clang/lib/CodeGen/Targets/AMDGPU.cpp (+1-5) 
- (modified) clang/test/CodeGenOpenCL/addr-space-struct-arg.cl (+54-102) 
- (modified) clang/test/CodeGenOpenCL/amdgpu-abi-struct-arg-byref.cl (+22-34) 
- (modified) clang/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl (+16-8) 
- (modified) clang/test/CodeGenOpenCL/opencl-kernel-call.cl (+23-47) 


``diff
diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index db2a2c5740646..bcf039d9f268a 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -198,14 +198,10 @@ ABIArgInfo 
AMDGPUABIInfo::classifyKernelArgumentType(QualType Ty) const {
 /*ToAS=*/getContext().getTargetAddressSpace(LangAS::cuda_device));
   }
 
-  // FIXME: Should also use this for OpenCL, but it requires addressing the
-  // problem of kernels being called.
-  //
   // FIXME: This doesn't apply the optimization of coercing pointers in structs
   // to global address space when using byref. This would require implementing 
a
   // new kind of coercion of the in-memory type when for indirect arguments.
-  if (!getContext().getLangOpts().OpenCL && LTy == OrigLTy &&
-  isAggregateTypeForABI(Ty)) {
+  if (LTy == OrigLTy && isAggregateTypeForABI(Ty)) {
 return ABIArgInfo::getIndirectAliased(
 getContext().getTypeAlignInChars(Ty),
 getContext().getTargetAddressSpace(LangAS::opencl_constant),
diff --git a/clang/test/CodeGenOpenCL/addr-space-struct-arg.cl 
b/clang/test/CodeGenOpenCL/addr-space-struct-arg.cl
index 789aae7a5c34c..49604c6c5e61b 100644
--- a/clang/test/CodeGenOpenCL/addr-space-struct-arg.cl
+++ b/clang/test/CodeGenOpenCL/addr-space-struct-arg.cl
@@ -546,12 +546,10 @@ kernel void KernelLargeTwoMember(struct 
LargeStructTwoMember u) {
 //
 //
 // AMDGCN-LABEL: define dso_local amdgpu_kernel void @KernelLargeOneMember(
-// AMDGCN-SAME: [[STRUCT_LARGESTRUCTONEMEMBER:%.*]] [[U_COERCE:%.*]]) 
#[[ATTR1]] !kernel_arg_addr_space [[META10]] !kernel_arg_access_qual [[META11]] 
!kernel_arg_type [[META16:![0-9]+]] !kernel_arg_base_type [[META16]] 
!kernel_arg_type_qual [[META13]] {
+// AMDGCN-SAME: ptr addrspace(4) noundef 
byref([[STRUCT_LARGESTRUCTONEMEMBER:%.*]]) align 8 [[TMP0:%.*]]) #[[ATTR1]] 
!kernel_arg_addr_space [[META10]] !kernel_arg_access_qual [[META11]] 
!kernel_arg_type [[META16:![0-9]+]] !kernel_arg_base_type [[META16]] 
!kernel_arg_type_qual [[META13]] {
 // AMDGCN-NEXT:  [[ENTRY:.*:]]
 // AMDGCN-NEXT:[[U:%.*]] = alloca [[STRUCT_LARGESTRUCTONEMEMBER]], align 
8, addrspace(5)
-// AMDGCN-NEXT:[[TMP0:%.*]] = getelementptr inbounds nuw 
[[STRUCT_LARGESTRUCTONEMEMBER]], ptr addrspace(5) [[U]], i32 0, i32 0
-// AMDGCN-NEXT:[[TMP1:%.*]] = extractvalue [[STRUCT_LARGESTRUCTONEMEMBER]] 
[[U_COERCE]], 0
-// AMDGCN-NEXT:store [100 x <2 x i32>] [[TMP1]], ptr addrspace(5) 
[[TMP0]], align 8
+// AMDGCN-NEXT:call void @llvm.memcpy.p5.p4.i64(ptr addrspace(5) align 8 
[[U]], ptr addrspace(4) align 8 [[TMP0]], i64 800, i1 false)
 // AMDGCN-NEXT:call void @__clang_ocl_kern_imp_KernelLargeOneMember(ptr 
addrspace(5) noundef byref([[STRUCT_LARGESTRUCTONEMEMBER]]) align 8 [[U]]) 
#[[ATTR4]]
 // AMDGCN-NEXT:ret void
 //
@@ -596,20 +594,15 @@ kernel void KernelLargeTwoMember(struct 
LargeStructTwoMember u) {
 //
 //
 // AMDGCN-LABEL: define dso_local amdgpu_kernel void @KernelTwoMember(
-// AMDGCN-SAME: [[STRUCT_STRUCTTWOMEMBER:%.*]] [[U_COERCE:%.*]]) #[[ATTR1]] 
!kernel_arg_addr_space [[META10]] !kernel_arg_access_qual [[META11]] 
!kernel_arg_type [[META17:![0-9]+]] !kernel_arg_base_type [[META17]] 
!kernel_arg_type_qual [[META13]] {
+// AMDGCN-SAME: ptr addrspace(4) noundef byref([[STRUCT_STRUCTTWOMEMBER:%.*]]) 
align 8 [[TMP0:%.*]]) #[[ATTR1]] !kernel_arg_addr_space [[META10]] 
!kernel_arg_access_qual [[META11]] !kernel_arg_type [[META17:![0-9]+]] 
!kernel_arg_base_type [[META17]] !kernel_arg_type_qual [[META13]] {
 // AMDGCN-NEXT:  [[ENTRY:.*:]]
 // AMDGCN-NEXT:[[U:%.*]] = alloca [[STRUCT_STRUCTTWOMEMBER]], align 8, 
addrspace(5)
-// AMDGCN-NEXT:[[TMP0:%.*]] = getelementptr inbounds nuw 
[[STRUCT_STRUCTTWOMEMBER]], ptr addrspace(5) [[U]], i32 0, i32 0
-// AMDGCN-NEXT:[[TMP1:%.*]] = extractvalue [[STRUCT_STRUCTTWOMEMBER]] 
[[U_COERCE]], 0
-// AMDGCN-NEXT:store <2 x i32> [[TMP1]], ptr addrspace(5) [[TMP0]], align 8
-//

[libcxx] [libcxxabi] [libunwind] [llvm] [libcxxabi][libunwind] Support for using LLVM libc (PR #134893)

2025-04-08 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-libcxx

@llvm/pr-subscribers-libunwind

Author: Petr Hosek (petrhosek)


Changes

This generalizes the support added in #99287 renaming the option to 
RUNTIMES_USE_LIBC and integrating the module into libc++abi and libunwind as 
well.

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


11 Files Affected:

- (modified) libcxx/CMakeLists.txt (-8) 
- (removed) libcxx/cmake/Modules/HandleLibC.cmake (-39) 
- (modified) libcxx/include/CMakeLists.txt (+1-1) 
- (modified) libcxx/src/CMakeLists.txt (+2-2) 
- (modified) libcxxabi/CMakeLists.txt (+2) 
- (added) libcxxabi/cmake/Modules/HandleLibC.cmake (+39) 
- (modified) libcxxabi/src/CMakeLists.txt (+8-6) 
- (modified) libunwind/CMakeLists.txt (+2) 
- (added) libunwind/cmake/Modules/HandleLibC.cmake (+39) 
- (modified) libunwind/src/CMakeLists.txt (+8-6) 
- (added) runtimes/cmake/Modules/HandleLibC.cmake (+46) 


``diff
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index ebaa6e9fd0e97..d3003cbec3889 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -225,14 +225,6 @@ set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon 
separated list of ABI macros
 set(LIBCXX_EXTRA_SITE_DEFINES "" CACHE STRING "Extra defines to add into 
__config_site")
 option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
 
-# C Library options ---
-
-set(LIBCXX_SUPPORTED_C_LIBRARIES system llvm-libc)
-set(LIBCXX_LIBC "system" CACHE STRING "Specify C library to use. Supported 
values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
-if (NOT "${LIBCXX_LIBC}" IN_LIST LIBCXX_SUPPORTED_C_LIBRARIES)
-  message(FATAL_ERROR "Unsupported C library: '${LIBCXX_CXX_ABI}'. Supported 
values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
-endif()
-
 # ABI Library options -
 if (MSVC)
   set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime")
diff --git a/libcxx/cmake/Modules/HandleLibC.cmake 
b/libcxx/cmake/Modules/HandleLibC.cmake
deleted file mode 100644
index 1b0564ae6fcc6..0
--- a/libcxx/cmake/Modules/HandleLibC.cmake
+++ /dev/null
@@ -1,39 +0,0 @@
-#===
-# Define targets for linking against the selected C library
-#
-# After including this file, the following targets are defined:
-# - libcxx-libc-headers: An interface target that allows getting access to the
-#headers of the selected C library.
-# - libcxx-libc-shared: A target representing the selected shared C library.
-# - libcxx-libc-static: A target representing the selected static C library.
-#===
-
-# Link against a system-provided libc
-if (LIBCXX_LIBC STREQUAL "system")
-  add_library(libcxx-libc-headers INTERFACE)
-
-  add_library(libcxx-libc-static INTERFACE)
-  add_library(libcxx-libc-shared INTERFACE)
-
-# Link against the in-tree LLVM libc
-elseif (LIBCXX_LIBC STREQUAL "llvm-libc")
-  add_library(libcxx-libc-headers INTERFACE)
-  target_link_libraries(libcxx-libc-headers INTERFACE libc-headers)
-  if(CXX_SUPPORTS_NOSTDLIBINC_FLAG)
-target_compile_options(libcxx-libc-headers INTERFACE "-nostdlibinc")
-  endif()
-
-  add_library(libcxx-libc-static INTERFACE)
-  if (TARGET libc)
-target_link_libraries(libcxx-libc-static INTERFACE libc)
-  endif()
-  if (TARGET libm)
-target_link_libraries(libcxx-libc-static INTERFACE libm)
-  endif()
-  if (CXX_SUPPORTS_NOLIBC_FLAG)
-target_link_options(libcxx-libc-static INTERFACE "-nolibc")
-  endif()
-
-  # TODO: There's no support for building LLVM libc as a shared library yet.
-  add_library(libcxx-libc-shared INTERFACE)
-endif()
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index a021b9bb44d67..9058a72ea75ab 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -2121,7 +2121,7 @@ list(APPEND _all_includes 
"${LIBCXX_GENERATED_INCLUDE_DIR}/libcxx.imp")
 add_custom_target(generate-cxx-headers ALL DEPENDS ${_all_includes})
 
 add_library(cxx-headers INTERFACE)
-target_link_libraries(cxx-headers INTERFACE libcxx-libc-headers 
libcxx-abi-headers)
+target_link_libraries(cxx-headers INTERFACE runtimes-libc-headers 
libcxx-abi-headers)
 add_dependencies(cxx-headers generate-cxx-headers)
 # It's important that the arch directory be included first so that its header 
files
 # which interpose on the default include dir be included instead of the 
default ones.
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 4e9bf900af4c5..97fe57a5f24f8 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -175,7 +175,7 @@ include(FindLibcCommonUtils)
 # Build the shared library.
 add_library(cxx_shared SHARED ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
 target_include_directories(cxx_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
-target_link_librarie

[libcxx] [libcxxabi] [libunwind] [llvm] [libcxxabi][libunwind] Support for using LLVM libc (PR #134893)

2025-04-08 Thread Petr Hosek via cfe-commits

https://github.com/petrhosek created 
https://github.com/llvm/llvm-project/pull/134893

This generalizes the support added in #99287 renaming the option to 
RUNTIMES_USE_LIBC and integrating the module into libc++abi and libunwind as 
well.

>From 1677ee5c547018472a1f6a29282d3af3500abcd7 Mon Sep 17 00:00:00 2001
From: Petr Hosek 
Date: Fri, 2 Aug 2024 08:25:53 -0700
Subject: [PATCH] [libcxxabi][libunwind] Support for using LLVM libc

This generalizes the support added in #99287 renaming the option to
RUNTIMES_USE_LIBC and integrating the module into libc++abi and
libunwind as well.
---
 libcxx/CMakeLists.txt|  8 -
 libcxx/cmake/Modules/HandleLibC.cmake| 39 
 libcxx/include/CMakeLists.txt|  2 +-
 libcxx/src/CMakeLists.txt|  4 +--
 libcxxabi/CMakeLists.txt |  2 ++
 libcxxabi/cmake/Modules/HandleLibC.cmake | 39 
 libcxxabi/src/CMakeLists.txt | 14 
 libunwind/CMakeLists.txt |  2 ++
 libunwind/cmake/Modules/HandleLibC.cmake | 39 
 libunwind/src/CMakeLists.txt | 14 
 runtimes/cmake/Modules/HandleLibC.cmake  | 46 
 11 files changed, 147 insertions(+), 62 deletions(-)
 delete mode 100644 libcxx/cmake/Modules/HandleLibC.cmake
 create mode 100644 libcxxabi/cmake/Modules/HandleLibC.cmake
 create mode 100644 libunwind/cmake/Modules/HandleLibC.cmake
 create mode 100644 runtimes/cmake/Modules/HandleLibC.cmake

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index ebaa6e9fd0e97..d3003cbec3889 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -225,14 +225,6 @@ set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon 
separated list of ABI macros
 set(LIBCXX_EXTRA_SITE_DEFINES "" CACHE STRING "Extra defines to add into 
__config_site")
 option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
 
-# C Library options ---
-
-set(LIBCXX_SUPPORTED_C_LIBRARIES system llvm-libc)
-set(LIBCXX_LIBC "system" CACHE STRING "Specify C library to use. Supported 
values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
-if (NOT "${LIBCXX_LIBC}" IN_LIST LIBCXX_SUPPORTED_C_LIBRARIES)
-  message(FATAL_ERROR "Unsupported C library: '${LIBCXX_CXX_ABI}'. Supported 
values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
-endif()
-
 # ABI Library options -
 if (MSVC)
   set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime")
diff --git a/libcxx/cmake/Modules/HandleLibC.cmake 
b/libcxx/cmake/Modules/HandleLibC.cmake
deleted file mode 100644
index 1b0564ae6fcc6..0
--- a/libcxx/cmake/Modules/HandleLibC.cmake
+++ /dev/null
@@ -1,39 +0,0 @@
-#===
-# Define targets for linking against the selected C library
-#
-# After including this file, the following targets are defined:
-# - libcxx-libc-headers: An interface target that allows getting access to the
-#headers of the selected C library.
-# - libcxx-libc-shared: A target representing the selected shared C library.
-# - libcxx-libc-static: A target representing the selected static C library.
-#===
-
-# Link against a system-provided libc
-if (LIBCXX_LIBC STREQUAL "system")
-  add_library(libcxx-libc-headers INTERFACE)
-
-  add_library(libcxx-libc-static INTERFACE)
-  add_library(libcxx-libc-shared INTERFACE)
-
-# Link against the in-tree LLVM libc
-elseif (LIBCXX_LIBC STREQUAL "llvm-libc")
-  add_library(libcxx-libc-headers INTERFACE)
-  target_link_libraries(libcxx-libc-headers INTERFACE libc-headers)
-  if(CXX_SUPPORTS_NOSTDLIBINC_FLAG)
-target_compile_options(libcxx-libc-headers INTERFACE "-nostdlibinc")
-  endif()
-
-  add_library(libcxx-libc-static INTERFACE)
-  if (TARGET libc)
-target_link_libraries(libcxx-libc-static INTERFACE libc)
-  endif()
-  if (TARGET libm)
-target_link_libraries(libcxx-libc-static INTERFACE libm)
-  endif()
-  if (CXX_SUPPORTS_NOLIBC_FLAG)
-target_link_options(libcxx-libc-static INTERFACE "-nolibc")
-  endif()
-
-  # TODO: There's no support for building LLVM libc as a shared library yet.
-  add_library(libcxx-libc-shared INTERFACE)
-endif()
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index a021b9bb44d67..9058a72ea75ab 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -2121,7 +2121,7 @@ list(APPEND _all_includes 
"${LIBCXX_GENERATED_INCLUDE_DIR}/libcxx.imp")
 add_custom_target(generate-cxx-headers ALL DEPENDS ${_all_includes})
 
 add_library(cxx-headers INTERFACE)
-target_link_libraries(cxx-headers INTERFACE libcxx-libc-headers 
libcxx-abi-headers)
+target_link_libraries(cxx-headers INTERFACE runtimes-libc-headers 
libcxx-abi-headers)
 add_dependencies(cxx-headers generate-cxx-headers)

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

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


@@ -29,8 +29,15 @@ int f[5] = {1, 2};
 
 void func() {
   int arr[10];
-
   // CHECK: %[[ARR:.*]] = cir.alloca !cir.array, 
!cir.ptr>, ["arr"]
+
+  int e = arr[1];
+  // CHECK: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr, ["e", init]
+  // CHECK: %[[IDX:.*]] = cir.const #cir.int<1> : !s32i
+  // CHECK: %[[ARR_PTR:.*]] = cir.cast(array_to_ptrdecay, %[[ARR]] : 
!cir.ptr>), !cir.ptr
+  // CHECK: %[[ELE_PTR:.*]] = cir.ptr_stride(%[[ARR_PTR]] : !cir.ptr, 
%[[IDX]] : !s32i), !cir.ptr
+  // CHECK: %[[TMP:.*]] = cir.load %[[ELE_PTR]] : !cir.ptr, !s32i
+  // CHECK" cir.store %[[TMP]], %[[INIT]] : !s32i, !cir.ptr

AmrDeveloper wrote:

In this case, do we still need `lowering/array.cpp`? can we use this file for 
the 3 tests together and remove the other one

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


[clang] [Clang][OpenCL][AMDGPU] Use `byref` for OpenCL kernel arguments (PR #134892)

2025-04-08 Thread Shilei Tian via cfe-commits

shiltian wrote:

* **#134892** https://app.graphite.dev/github/pr/llvm/llvm-project/134892?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134892?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


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


[clang] [CIR] Handle NullStmt (PR #134889)

2025-04-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Andy Kaylor (andykaylor)


Changes

The handling for NullStmt was going to an error saying the statement handling 
wasn't implemented. It doesn't need any implementation. It is sufficient for 
emitSimpleStmt to just return success for that statement class. This change 
does that.

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


2 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenStmt.cpp (+6-1) 
- (modified) clang/test/CIR/CodeGen/basic.c (+15) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenStmt.cpp 
b/clang/lib/CIR/CodeGen/CIRGenStmt.cpp
index 00d33e7feddff..072370ffeb4c8 100644
--- a/clang/lib/CIR/CodeGen/CIRGenStmt.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenStmt.cpp
@@ -57,6 +57,7 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
 
   switch (s->getStmtClass()) {
   case Stmt::BreakStmtClass:
+  case Stmt::NullStmtClass:
   case Stmt::CompoundStmtClass:
   case Stmt::ContinueStmtClass:
   case Stmt::DeclStmtClass:
@@ -93,7 +94,6 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
   case Stmt::SEHExceptStmtClass:
   case Stmt::SEHFinallyStmtClass:
   case Stmt::MSDependentExistsStmtClass:
-  case Stmt::NullStmtClass:
   case Stmt::LabelStmtClass:
   case Stmt::AttributedStmtClass:
   case Stmt::GotoStmtClass:
@@ -231,6 +231,11 @@ mlir::LogicalResult CIRGenFunction::emitSimpleStmt(const 
Stmt *s,
 break;
   case Stmt::ContinueStmtClass:
 return emitContinueStmt(cast(*s));
+
+  // NullStmt doesn't need any handling, but we need to say we handled it.
+  case Stmt::NullStmtClass:
+break;
+
   case Stmt::BreakStmtClass:
 return emitBreakStmt(cast(*s));
   case Stmt::ReturnStmtClass:
diff --git a/clang/test/CIR/CodeGen/basic.c b/clang/test/CIR/CodeGen/basic.c
index 673ff256c22af..6365dc2158138 100644
--- a/clang/test/CIR/CodeGen/basic.c
+++ b/clang/test/CIR/CodeGen/basic.c
@@ -90,3 +90,18 @@ int f3(void) {
 // OGCG-NEXT:   store i32 3, ptr %[[I_PTR]], align 4
 // OGCG-NEXT:   %[[I:.*]] = load i32, ptr %[[I_PTR]], align 4
 // OGCG-NEXT:   ret i32 %[[I]]
+
+// Verify null statement handling.
+void f4(void) {
+  ;
+}
+
+//  CIR: cir.func @f4()
+// CIR-NEXT:   cir.return
+
+//  LLVM: define void @f4()
+// LLVM-NEXT:   ret void
+
+//  OGCG: define{{.*}} void @f4()
+// OGCG-NEXT: entry:
+// OGCG-NEXT:   ret void

``




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


[clang] Reject invalid integer constants in unevaluated preprocessor operands (PR #134884)

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

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

>From 2661b9381e0a182fb53a81c8bf66cecd51c73b0f Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Tue, 8 Apr 2025 13:17:32 -0400
Subject: [PATCH 1/2] Reject invalid integer constants in unevaluated
 preprocessor operands

Clang was previously accepting invalid code like:

  #if 1 ? 1 : 9
  #endif

because the integer constant (which is too large to fit into any
standard or extended integer type) was in an unevaluated branch of the
conditional operator. Similar invalid code involving || or && was also
accepted and is now rejected.

Fixes #134658
---
 clang/docs/ReleaseNotes.rst |  8 ++
 clang/lib/Lex/PPExpressions.cpp |  5 ++--
 clang/test/Preprocessor/constants.c | 40 +
 3 files changed, 50 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Preprocessor/constants.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f8f4dfbafb4f8..6c86406ef36db 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -351,6 +351,14 @@ Bug Fixes in This Version
 - Defining an integer literal suffix (e.g., ``LL``) before including
    in a freestanding build no longer causes invalid token pasting
   when using the ``INTn_C`` macros. (#GH85995)
+- Clang no longer accepts invalid integer constants which are too large to fit
+  into any (standard or extended) integer type when the constant is 
unevaluated.
+  Merely forming the token is sufficient to render the program invalid. Code
+  like this was previously accepted and is now rejected (#GH134658):
+  .. code-block:: c
+
+#if 1 ? 1 : 9
+#endif
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Lex/PPExpressions.cpp b/clang/lib/Lex/PPExpressions.cpp
index b031571907441..6a6762828a20e 100644
--- a/clang/lib/Lex/PPExpressions.cpp
+++ b/clang/lib/Lex/PPExpressions.cpp
@@ -345,9 +345,8 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, 
DefinedTracker &DT,
 // Parse the integer literal into Result.
 if (Literal.GetIntegerValue(Result.Val)) {
   // Overflow parsing integer literal.
-  if (ValueLive)
-PP.Diag(PeekTok, diag::err_integer_literal_too_large)
-<< /* Unsigned */ 1;
+  PP.Diag(PeekTok, diag::err_integer_literal_too_large)
+  << /* Unsigned */ 1;
   Result.Val.setIsUnsigned(true);
 } else {
   // Set the signedness of the result to match whether there was a U suffix
diff --git a/clang/test/Preprocessor/constants.c 
b/clang/test/Preprocessor/constants.c
new file mode 100644
index 0..d6241a4f1ceee
--- /dev/null
+++ b/clang/test/Preprocessor/constants.c
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -E -verify %s
+
+// C++ [lex.icon]p4 and C 6.4.4.1p2 + 6.4.4.2p7 both require C and C++ to
+// validate the integer constant value when converting a preprocessing token
+// into a token for semantic analysis, even within the preprocessor itself.
+
+// Plain integer constant.
+#if 9 // expected-error {{integer literal is too large to 
be represented in any integer type}}
+#endif
+
+// These cases were previously incorrectly accepted. See GH134658.
+
+// Integer constant in an unevaluated branch of a conditional.
+#if 1 ? 1 : 9 // expected-error {{integer literal is too 
large to be represented in any integer type}}
+#endif
+
+// Integer constant in an unevaluated operand of a logical operator.
+#if 0 && 9 // expected-error {{integer literal is too 
large to be represented in any integer type}}
+#endif
+
+#if 1 || 9 // expected-error {{integer literal is too 
large to be represented in any integer type}}
+#endif
+
+// Make sure we also catch it in an elif condition.
+#if 0
+#elif 1 || 9 // expected-error {{integer literal is too 
large to be represented in any integer type}}
+#endif
+
+// However, if the block is skipped entirely, then it doesn't matter how
+// invalid the constant value is.
+#if 0
+int x = 9;
+
+#if 9
+#endif
+
+#if 0 && 9
+#endif
+
+#endif

>From a4329eec3ff4dc1d8a343637428f1a67d87e24e5 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Tue, 8 Apr 2025 13:43:09 -0400
Subject: [PATCH 2/2] Fix formatting, NFC

---
 clang/lib/Lex/PPExpressions.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Lex/PPExpressions.cpp b/clang/lib/Lex/PPExpressions.cpp
index 6a6762828a20e..48835121b40e9 100644
--- a/clang/lib/Lex/PPExpressions.cpp
+++ b/clang/lib/Lex/PPExpressions.cpp
@@ -345,8 +345,7 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, 
DefinedTracker &DT,
 // Parse the integer literal into Result.
 if (Literal.GetIntegerValue(Result.Val)) {
   // Overflow parsing integer literal.
-  PP.Diag(PeekTok, diag

[clang] Reject invalid integer constants in unevaluated preprocessor operands (PR #134884)

2025-04-08 Thread Richard Smith via cfe-commits

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

LGTM.

I suppose if people complain, we can make the non-live value case a warning 
rather than an error, but given no other implementation does, I think it makes 
sense not to do that speculatively.

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


[clang] [CIR] Handle NullStmt (PR #134889)

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


@@ -57,6 +57,7 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
 
   switch (s->getStmtClass()) {
   case Stmt::BreakStmtClass:
+  case Stmt::NullStmtClass:

andykaylor wrote:

Sure. Do you know what code leads to `NoStmtClass`?

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


[clang] [CIR] Handle NullStmt (PR #134889)

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


@@ -57,6 +57,7 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
 
   switch (s->getStmtClass()) {
   case Stmt::BreakStmtClass:
+  case Stmt::NullStmtClass:

erichkeane wrote:

I'm about 99.9% sure that there is no code that can result in it, barring some 
error in the compiler.  It is the 'class' of `Stmt`, which isn't `virtual`, but 
is effectively abstract (other than by language rule).

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


[clang] [CIR] Handle NullStmt (PR #134889)

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


@@ -90,3 +90,18 @@ int f3(void) {
 // OGCG-NEXT:   store i32 3, ptr %[[I_PTR]], align 4
 // OGCG-NEXT:   %[[I:.*]] = load i32, ptr %[[I_PTR]], align 4
 // OGCG-NEXT:   ret i32 %[[I]]
+
+// Verify null statement handling.
+void f4(void) {
+  ;

erichkeane wrote:

The trailing one does.  The `{}` is a compound-stmt.  I notice in class-codegen 
we do some stuff to figure out if the `for` loop is empty (or `while` loop/etc) 
that checks it IIRC.  

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


[clang] [llvm] [HIP][HIPSTDPAR][NFC] Re-order & adapt `hipstdpar` specific passes (PR #134753)

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

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

>From a988ecf63dc79d226c2f7aa1430f65d08256888b Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 8 Apr 2025 00:20:27 +0100
Subject: [PATCH 1/3] Re-order & adapt `hipstdpar` specific passes.

---
 clang/lib/CodeGen/BackendUtil.cpp |  8 
 clang/lib/Driver/ToolChains/HIPAMD.cpp|  7 ---
 .../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 20 ---
 3 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7557cb8408921..fa5e12d4033a5 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1115,6 +1115,10 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   if (CodeGenOpts.LinkBitcodePostopt)
 MPM.addPass(LinkInModulesPass(BC));
 
+  if (LangOpts.HIPStdPar && !LangOpts.CUDAIsDevice &&
+  LangOpts.HIPStdParInterposeAlloc)
+  MPM.addPass(HipStdParAllocationInterpositionPass());
+
   // Add a verifier pass if requested. We don't have to do this if the action
   // requires code generation because there will already be a verifier pass in
   // the code-generation pipeline.
@@ -1178,10 +1182,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 return;
   }
 
-  if (LangOpts.HIPStdPar && !LangOpts.CUDAIsDevice &&
-  LangOpts.HIPStdParInterposeAlloc)
-MPM.addPass(HipStdParAllocationInterpositionPass());
-
   // Now that we have all of the passes ready, run them.
   {
 PrettyStackTraceString CrashInfo("Optimizer");
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index abb83701759ce..52e35a01be58d 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -231,10 +231,11 @@ void HIPAMDToolChain::addClangTargetOptions(
   CC1Args.append({"-fcuda-is-device", "-fno-threadsafe-statics"});
 
   if (!DriverArgs.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
-  false))
+  false)) {
 CC1Args.append({"-mllvm", "-amdgpu-internalize-symbols"});
-  if (DriverArgs.hasArgNoClaim(options::OPT_hipstdpar))
-CC1Args.append({"-mllvm", "-amdgpu-enable-hipstdpar"});
+if (DriverArgs.hasArgNoClaim(options::OPT_hipstdpar))
+  CC1Args.append({"-mllvm", "-amdgpu-enable-hipstdpar"});
+  }
 
   StringRef MaxThreadsPerBlock =
   DriverArgs.getLastArgValue(options::OPT_gpu_max_threads_per_block_EQ);
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 4b5c70f09155f..03b1693244879 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -802,17 +802,17 @@ void 
AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
 #define GET_PASS_REGISTRY "AMDGPUPassRegistry.def"
 #include "llvm/Passes/TargetPassRegistry.inc"
 
-  PB.registerPipelineStartEPCallback(
-  [](ModulePassManager &PM, OptimizationLevel Level) {
-if (EnableHipStdPar)
-  PM.addPass(HipStdParAcceleratorCodeSelectionPass());
-  });
-
   PB.registerPipelineEarlySimplificationEPCallback(
   [](ModulePassManager &PM, OptimizationLevel Level,
  ThinOrFullLTOPhase Phase) {
-if (!isLTOPreLink(Phase))
+if (!isLTOPreLink(Phase)) {
+  // When we are not using -fgpu-rdc, we can run accelerator code
+  // selection relatively early, but still after linking to prevent
+  // eager removal of potentially reachable symbols.
+  if (EnableHipStdPar)
+PM.addPass(HipStdParAcceleratorCodeSelectionPass());
   PM.addPass(AMDGPUPrintfRuntimeBindingPass());
+}
 
 if (Level == OptimizationLevel::O0)
   return;
@@ -883,6 +883,12 @@ void 
AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
 
   PB.registerFullLinkTimeOptimizationLastEPCallback(
   [this](ModulePassManager &PM, OptimizationLevel Level) {
+// When we are using -fgpu-rdc, we can onky run accelerator code
+// selection after linking to prevent, otherwise we end up removing
+// potentially reachable symbols that were exported as external in 
other
+// modules.
+if (EnableHipStdPar)
+  PM.addPass(HipStdParAcceleratorCodeSelectionPass());
 // We want to support the -lto-partitions=N option as "best effort".
 // For that, we need to lower LDS earlier in the pipeline before the
 // module is partitioned for codegen.

>From 5cd1abb217d7fb2dd1f33c94a4f285b9aacd8dde Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 8 Apr 2025 00:27:18 +0100
Subject: [PATCH 2/3] Fix formatting.

---
 clang/lib/CodeGen/BackendUtil.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index fa5e12d4033a

[clang] [llvm] [HIP][HIPSTDPAR][NFC] Re-order & adapt `hipstdpar` specific passes (PR #134753)

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

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


[clang] cuda clang: Move nvptx-surface.cu test to CodeGenCUDA (PR #134758)

2025-04-08 Thread Artem Belevich via cfe-commits

https://github.com/Artem-B requested changes to this pull request.

Hold on a sec.

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


[clang] [CIR] Handle NullStmt (PR #134889)

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


@@ -57,6 +57,7 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
 
   switch (s->getStmtClass()) {
   case Stmt::BreakStmtClass:
+  case Stmt::NullStmtClass:

andykaylor wrote:

I just looked at classic codegen. It puts NoStmtClass (along with 
CXXCatchStmtClass, SEHExceptStmtClass, SEHFinallyStmtClass, and 
MSDependentExistsStmtClass) in a different group just above this that leads to 
`llvm_unreachable("invalid statement class to emit generically");` rather than 
`llvm_unreachable("should have emitted these statements as simple");` as we 
have here. I can still do that here if you want, but it's currently in the 
group below that goes to an NYI error.

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


[clang] cuda clang: Move nvptx-surface.cu test to CodeGenCUDA (PR #134758)

2025-04-08 Thread Artem Belevich via cfe-commits


@@ -2,6 +2,170 @@
 // RUN: %clang_cc1 -triple nvptx64-unknown-unknown -fcuda-is-device -O3 -o - 
%s -emit-llvm | FileCheck %s
 #include "Inputs/cuda.h"
 
+struct char1 {

Artem-B wrote:

These type declarations should go into Inputs/cuda.h

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


[clang-tools-extra] [clang-tidy] ExprSequence: Handle ternary operators. (PR #132913)

2025-04-08 Thread Clement Courbet via cfe-commits

legrosbuffle wrote:

ping

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


[clang] [clang][DependencyScanning] Track dependencies from prebuilt modules to determine IsInStableDir (PR #132237)

2025-04-08 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/132237

>From 3aaaf3371215de0f214836da32f862518f223760 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 12 Mar 2025 21:26:36 -0700
Subject: [PATCH 1/3] [clang][DependencyScanning] Track dependencies from
 prebuilt modules to determine IsInStableDir

When a module is being scanned, it can depend on modules that have
already been built from a pch dependency. When this happens, the
pcm files are reused for the module dependencies. When this is the case,
check if input files recorded from the PCMs come from the provided stable 
directories transitively,
since the scanner will not have access to the full set of file dependencies 
from prebuilt modules.
---
 clang/include/clang/Serialization/ASTReader.h |  11 ++
 .../DependencyScanning/ModuleDepCollector.h   |  59 -
 clang/lib/Frontend/FrontendActions.cpp|   7 +-
 clang/lib/Serialization/ASTReader.cpp |   6 +-
 .../DependencyScanningWorker.cpp  | 112 +++---
 .../DependencyScanning/ModuleDepCollector.cpp |  89 --
 .../prebuilt-modules-in-stable-dirs.c |  24 +++-
 7 files changed, 237 insertions(+), 71 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 57ae4aa104d9a..617ac23984b60 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -237,6 +237,17 @@ class ASTReaderListener {
 return true;
   }
 
+  /// Overloaded member function of \c visitInputFile that should
+  /// be defined when the input file contains both the virtual and external
+  /// paths, for example when deserializing input files from AST files.
+  ///
+  /// \returns true to continue receiving the next input file, false to stop.
+  virtual bool visitInputFile(StringRef FilenameAsRequested, StringRef 
Filename,
+  bool isSystem, bool isOverridden,
+  bool isExplicitModule) {
+return true;
+  }
+
   /// Returns true if this \c ASTReaderListener wants to receive the
   /// imports of the AST file via \c visitImport, false otherwise.
   virtual bool needsImportVisitation() const { return false; }
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h 
b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index ed150b467e3a1..ce5e67d2624d9 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -33,6 +33,7 @@ namespace dependencies {
 
 class DependencyActionController;
 class DependencyConsumer;
+class PrebuiltModuleASTAttrs;
 
 /// Modular dependency that has already been built prior to the dependency 
scan.
 struct PrebuiltModuleDep {
@@ -46,6 +47,47 @@ struct PrebuiltModuleDep {
 ModuleMapFile(M->PresumedModuleMapFile) {}
 };
 
+/// Attributes loaded from AST files of prebuilt modules collected prior to
+/// ModuleDepCollector creation.
+using PrebuiltModulesAttrsMap = llvm::StringMap;
+class PrebuiltModuleASTAttrs {
+public:
+  /// When a module is discovered to not be in stable directories, traverse &
+  /// update all modules that depend on it.
+  void
+  updateDependentsNotInStableDirs(PrebuiltModulesAttrsMap &PrebuiltModulesMap);
+
+  /// Read-only access to whether the module is made up of dependencies in
+  /// stable directories.
+  bool isInStableDir() const { return IsInStableDirs; }
+
+  /// Read-only access to vfs map files.
+  const llvm::StringSet<> &getVFS() const { return VFSMap; }
+
+  /// Update the VFSMap to the one discovered from serializing the AST file.
+  void setVFS(llvm::StringSet<> &&VFS) { VFSMap = std::move(VFS); }
+
+  /// Add a direct dependent module file, so it can be updated if the current
+  /// module is from stable directores.
+  void addDependent(StringRef ModuleFile) {
+ModuleFileDependents.insert(ModuleFile);
+  }
+
+  /// Update whether the prebuilt module resolves entirely in a stable
+  /// directories.
+  void setInStableDir(bool V = false) {
+// Cannot reset attribute once it's false.
+if (!IsInStableDirs)
+  return;
+IsInStableDirs = V;
+  }
+
+private:
+  llvm::StringSet<> VFSMap;
+  bool IsInStableDirs = true;
+  std::set ModuleFileDependents;
+};
+
 /// This is used to identify a specific module.
 struct ModuleID {
   /// The name of the module. This may include `:` for C++20 module partitions,
@@ -171,8 +213,6 @@ struct ModuleDeps {
   BuildInfo;
 };
 
-using PrebuiltModuleVFSMapT = llvm::StringMap>;
-
 class ModuleDepCollector;
 
 /// Callback that records textual includes and direct modular includes/imports
@@ -242,7 +282,7 @@ class ModuleDepCollector final : public DependencyCollector 
{
  CompilerInstance &ScanInstance, DependencyConsumer &C,
  DependencyActionController &Controlle

[clang] [CIR] Handle NullStmt (PR #134889)

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


@@ -57,6 +57,7 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
 
   switch (s->getStmtClass()) {
   case Stmt::BreakStmtClass:
+  case Stmt::NullStmtClass:

andykaylor wrote:

I'm fine with that. Trying to avoid doing multiple things, but this is all 
basically doing nothing in the correct place, so it sort of makes sense.

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


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

2025-04-08 Thread Kaitlin Peng via cfe-commits

https://github.com/kmpeng updated 
https://github.com/llvm/llvm-project/pull/134171

>From 719bb94279f64f134c826faa22898e4e549bb23c Mon Sep 17 00:00:00 2001
From: kmpeng 
Date: Thu, 27 Mar 2025 14:39:27 -0700
Subject: [PATCH 01/12] finished lit implementation, added codegen and sema
 tests

---
 .../lib/Headers/hlsl/hlsl_intrinsic_helpers.h | 12 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 31 
 clang/test/CodeGenHLSL/builtins/lit.hlsl  | 36 +
 clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl  | 50 +++
 4 files changed, 129 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/lit.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
index 8cdd63d7e07bb..619d4c59f8074 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
@@ -101,6 +101,18 @@ constexpr vector smoothstep_vec_impl(vector 
Min, vector Max,
 #endif
 }
 
+template 
+constexpr vector lit_impl(T N_dot_l, T N_dot_h, T M) {
+  bool Cond1 = N_dot_l < 0;
+  T ClampedP1 = select(Cond1, 0, N_dot_l);
+  vector Result = {1, ClampedP1, 0, 1};
+  bool CombinedCond = or (Cond1, (N_dot_h < 0));
+  T LogP2 = log(N_dot_h);
+  T Exp = exp(LogP2 * M);
+  Result[2] = select(CombinedCond, 0, Exp);
+  return Result;
+}
+
 } // namespace __detail
 } // namespace hlsl
 
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index fd799b8d874ae..5b6692d2a4281 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -253,6 +253,37 @@ const inline float 
length(__detail::HLSL_FIXED_VECTOR X) {
   return __detail::length_vec_impl(X);
 }
 
+//===--===//
+// lit builtins
+//===--===//
+
+/// \fn vector lit(T x, T y)
+/// \brief Returns a lighting coefficient vector.
+/// \param N_dot_l The dot product of the normalized surface normal and the
+/// light vector.
+/// \param N_dot_h The dot product of the half-angle vector and the surface
+/// normal.
+/// \param M A specular exponent.
+///
+/// This function returns a lighting coefficient vector (ambient, diffuse,
+/// specular, 1).
+
+template 
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+const inline __detail::enable_if_t<__detail::is_arithmetic::Value &&
+ __detail::is_same::value,
+ vector> lit(T N_dot_l, T N_dot_h, T M) {
+  return __detail::lit_impl(N_dot_l, N_dot_h, M);
+}
+
+template 
+const inline __detail::enable_if_t<__detail::is_arithmetic::Value &&
+   __detail::is_same::value,
+   vector>
+lit(T N_dot_l, T N_dot_h, T M) {
+  return __detail::lit_impl(N_dot_l, N_dot_h, M);
+}
+
 
//===--===//
 // D3DCOLORtoUBYTE4 builtin
 
//===--===//
diff --git a/clang/test/CodeGenHLSL/builtins/lit.hlsl 
b/clang/test/CodeGenHLSL/builtins/lit.hlsl
new file mode 100644
index 0..3fb0a2c5b5d6f
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/lit.hlsl
@@ -0,0 +1,36 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -O1 -o - | 
FileCheck %s
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x half> 
@_Z13test_lit_halfDhDhDh(
+// CHECK-SAME: half noundef nofpclass(nan inf) [[N_DOT_L:%.*]], half noundef 
nofpclass(nan inf) [[N_DOT_H:%.*]], half noundef nofpclass(nan inf) [[M:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[CMP_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt half 
[[N_DOT_L]], 0xH
+// CHECK-NEXT:[[HLSL_SELECT_I:%.*]] = tail call reassoc nnan ninf nsz arcp 
afn half @llvm.maxnum.f16(half [[N_DOT_L]], half 0xH)
+// CHECK-NEXT:[[VECINIT2_I:%.*]] = insertelement <4 x half> , half [[HLSL_SELECT_I]], i64 1
+// CHECK-NEXT:[[CMP4_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt 
half [[N_DOT_H]], 0xH
+// CHECK-NEXT:[[HLSL_OR_I:%.*]] = or i1 [[CMP_I]], [[CMP4_I]]
+// CHECK-NEXT:[[ELT_LOG_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn 
half @llvm.log.f16(half [[N_DOT_H]])
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half 
[[ELT_LOG_I]], [[M]]
+// CHECK-NEXT:[[ELT_EXP_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn 
half @llvm.exp.f16(half [[MUL_I]])
+// CHECK-NEXT:[[HLSL_SELECT7_I:%.*]] = select reassoc nnan ninf nsz arcp 
afn i1 [[HLSL_OR_I]], half 0xH, half [[ELT_EXP_I

[clang] [clang] Add comment about misleading alloc_size argument names (PR #134899)

2025-04-08 Thread via cfe-commits

https://github.com/thejh created 
https://github.com/llvm/llvm-project/pull/134899

Attr.td names the first alloc_size argument "ElemSizeParam" and the second 
optional argument "NumElemsParam"; but the semantics of how the two-argument 
version is used in practice is the opposite of that.

glibc declares calloc() like this, so the second alloc_size argument is the 
element size:
```
extern void *calloc (size_t __nmemb, size_t __size)
__THROW __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __wur;
```

The Linux kernel declares array allocation functions like 
`kmalloc_array_noprof()` the same way.

Add a comment explaining that the names used inside clang are misleading.

>From b395bb99917022e8da4a101f47d0fec2b8555628 Mon Sep 17 00:00:00 2001
From: Jann Horn 
Date: Tue, 8 Apr 2025 20:05:15 +0200
Subject: [PATCH] [clang] Add comment about misleading alloc_size argument
 names

Attr.td names the first alloc_size argument "ElemSizeParam" and the
second optional argument "NumElemsParam"; but the semantics of how the
two-argument version is used in practice is the opposite of that.

glibc declares calloc() like this, so the second alloc_size argument is
the element size:
```
extern void *calloc (size_t __nmemb, size_t __size)
__THROW __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __wur;
```

The Linux kernel declares array allocation functions like
`kmalloc_array_noprof()` the same way.

Add a comment explaining that the names used inside clang are
misleading.
---
 clang/include/clang/Basic/Attr.td | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fd9e686485552..b7ad432738b29 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1709,6 +1709,13 @@ def EmptyBases : InheritableAttr, 
TargetSpecificAttr {
 def AllocSize : InheritableAttr {
   let Spellings = [GCC<"alloc_size">];
   let Subjects = SubjectList<[HasFunctionProto]>;
+  // The parameter names here are a bit misleading.
+  // When used with a single argument, the first argument is obviously the
+  // allocation size; but when used with two arguments, the first argument is
+  // usually the number of elements, while the second argument is usually the
+  // element size - the reverse of how they are named here.
+  // The documentation of both GCC and clang does not describe any semantic
+  // difference between the first and second argument.
   let Args = [ParamIdxArgument<"ElemSizeParam">,
   ParamIdxArgument<"NumElemsParam", /*opt*/ 1>];
   let TemplateDependent = 1;

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


[clang] [clang] Add comment about misleading alloc_size argument names (PR #134899)

2025-04-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jann (thejh)


Changes

Attr.td names the first alloc_size argument "ElemSizeParam" and the second 
optional argument "NumElemsParam"; but the semantics of how the two-argument 
version is used in practice is the opposite of that.

glibc declares calloc() like this, so the second alloc_size argument is the 
element size:
```
extern void *calloc (size_t __nmemb, size_t __size)
__THROW __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __wur;
```

The Linux kernel declares array allocation functions like 
`kmalloc_array_noprof()` the same way.

Add a comment explaining that the names used inside clang are misleading.

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


1 Files Affected:

- (modified) clang/include/clang/Basic/Attr.td (+7) 


``diff
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fd9e686485552..b7ad432738b29 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1709,6 +1709,13 @@ def EmptyBases : InheritableAttr, 
TargetSpecificAttr {
 def AllocSize : InheritableAttr {
   let Spellings = [GCC<"alloc_size">];
   let Subjects = SubjectList<[HasFunctionProto]>;
+  // The parameter names here are a bit misleading.
+  // When used with a single argument, the first argument is obviously the
+  // allocation size; but when used with two arguments, the first argument is
+  // usually the number of elements, while the second argument is usually the
+  // element size - the reverse of how they are named here.
+  // The documentation of both GCC and clang does not describe any semantic
+  // difference between the first and second argument.
   let Args = [ParamIdxArgument<"ElemSizeParam">,
   ParamIdxArgument<"NumElemsParam", /*opt*/ 1>];
   let TemplateDependent = 1;

``




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


[clang] [CIR] Add if statement support (PR #134333)

2025-04-08 Thread via cfe-commits


@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-linux-gnu -fclangir 
-emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
+// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-linux-gnu -fclangir 
-emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM
+// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-linux-gnu -emit-llvm %s 
-o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG
+
+void f() {
+  int result = 0;
+
+  if consteval {
+result = 10; 
+// CIR-NOT: cir.const #cir.int<10> : !s32i
+// LLVM-NOT: store i32 10, ptr %1, align 4

Andres-Salamanca wrote:

🤯🤯 I hadn’t thought of that

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


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

2025-04-08 Thread Kaitlin Peng via cfe-commits


@@ -0,0 +1,9 @@
+// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1  | 
FileCheck %s -DTEST_TYPE=half
+// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1  | 
FileCheck %s -DTEST_TYPE=int16_t
+// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1  | 
FileCheck %s -DTEST_TYPE=uint16_t
+
+// check we error on 16 bit type if shader model is too old
+// CHECK: '-enable-16bit-types' option requires target HLSL Version >= 2018 
and shader model >= 6.2, but HLSL Version is 'hlsl202x' and shader model is 
'6.0'
+vector test_error(TEST_TYPE p0) {

kmpeng wrote:

Code updated.

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


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

2025-04-08 Thread Kaitlin Peng via cfe-commits


@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify
+
+float4 test_no_second_arg(float p0) {
+  return lit(p0);
+  // expected-error@-1 {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function 
template not viable: requires 3 arguments, but 1 was provided}}
+}
+
+float4 test_no_third_arg(float p0) {
+  return lit(p0, p0);
+  // expected-error@-1 {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function 
template not viable: requires 3 arguments, but 2 were provided}}
+}
+
+float4 test_too_many_arg(float p0) {
+  return lit(p0, p0, p0, p0);
+  // expected-error@-1 {{no matching function for call to 'lit'}}

kmpeng wrote:

Code updated.

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


[clang] [CIR] Handle NullStmt (PR #134889)

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


@@ -57,6 +57,7 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
 
   switch (s->getStmtClass()) {
   case Stmt::BreakStmtClass:
+  case Stmt::NullStmtClass:

erichkeane wrote:

Ah, i missed that it wasn't just the same unreachable.  No real reason to do it 
now, but as it was a 'move this line 10 lines' sorta thing, i thought it was a 
decent 'while we are here'.

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


[clang] [llvm] [HIP][HIPSTDPAR][NFC] Re-order & adapt `hipstdpar` specific passes (PR #134753)

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

https://github.com/AlexVlx commented:

> Needs test  

Done.

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


  1   2   3   4   5   >