[clang] d67013a - [Flang][AArch64][VecLib] Add libmvec support for Flang/AArch64 (#146453)

2025-07-02 Thread via cfe-commits

Author: KAWASHIMA Takahiro
Date: 2025-07-03T14:38:45+09:00
New Revision: d67013a2b44295e7558b6678f07c7f3a7ef9601c

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

LOG: [Flang][AArch64][VecLib] Add libmvec support for Flang/AArch64 (#146453)

`-fveclib=libmvec` for AArch64 (NEON and SVE) in Clang was supported by
#143696. This patch does the same for Flang.

Vector functions defined in `libmvec` are used for the following Fortran
operator and functions currently.

- Power operator (`**`)
- Fortran intrinsic functions listed below for `real(kind=4)` and
`real(kind=8)` (including their coresponding specific intrinsic
functions)
- Fortran intrinsic functions which are expanded using functions listed
below (for example, `sin` for `complex(kind=8)`)

```
sin
tan
cos
asin
acos
atan (both atan(x) and atan(y, x))
atan2
cosh
tanh
asinh
acosh
atanh
erf
erfc
exp
log
log10
```

As with Clang/AArch64, glibc 2.40 or higher is required to use all these
functions.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/docs/ReleaseNotes.md
flang/test/Driver/fveclib-codegen.f90
flang/test/Driver/fveclib.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5831ea73561ff..697117c06a6b2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3489,7 +3489,8 @@ def fno_experimental_isel : Flag<["-"], 
"fno-experimental-isel">, Group;
 def fveclib : Joined<["-"], "fveclib=">, Group,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
-HelpText<"Use the given vector functions library">,
+HelpText<"Use the given vector functions library.\n"
+ "  Note: -fveclib=libmvec on AArch64 requires GLIBC 2.40 or 
newer.">,
 HelpTextForVariants<[ClangOption, CC1Option],
   "Use the given vector functions library.\n"
   "  Note: -fveclib={ArmPL,SLEEF,libmvec} implies -fno-math-errno.\n"

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index e4e321ba1e195..75ba2af543c7a 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -484,11 +484,18 @@ void Flang::addTargetOptions(const ArgList &Args,
   Triple.getArch() != llvm::Triple::x86_64)
 D.Diag(diag::err_drv_unsupported_opt_for_target)
 << Name << Triple.getArchName();
-} else if (Name == "libmvec" || Name == "AMDLIBM") {
+} else if (Name == "AMDLIBM") {
   if (Triple.getArch() != llvm::Triple::x86 &&
   Triple.getArch() != llvm::Triple::x86_64)
 D.Diag(diag::err_drv_unsupported_opt_for_target)
 << Name << Triple.getArchName();
+} else if (Name == "libmvec") {
+  if (Triple.getArch() != llvm::Triple::x86 &&
+  Triple.getArch() != llvm::Triple::x86_64 &&
+  Triple.getArch() != llvm::Triple::aarch64 &&
+  Triple.getArch() != llvm::Triple::aarch64_be)
+D.Diag(diag::err_drv_unsupported_opt_for_target)
+<< Name << Triple.getArchName();
 } else if (Name == "SLEEF" || Name == "ArmPL") {
   if (Triple.getArch() != llvm::Triple::aarch64 &&
   Triple.getArch() != llvm::Triple::aarch64_be)

diff  --git a/flang/docs/ReleaseNotes.md b/flang/docs/ReleaseNotes.md
index 35da8323e0a10..b2dbbcb5630f4 100644
--- a/flang/docs/ReleaseNotes.md
+++ b/flang/docs/ReleaseNotes.md
@@ -34,6 +34,8 @@ page](https://llvm.org/releases/).
 
 * -floop-interchange is now recognized by flang.
 * -floop-interchange is enabled by default at -O2 and above.
+* -fveclib=libmvec is supported for AArch64 (same as Flang/x86 and
+  Clang/AArch64) (requires GLIBC 2.40 or newer)
 
 ## Windows Support
 

diff  --git a/flang/test/Driver/fveclib-codegen.f90 
b/flang/test/Driver/fveclib-codegen.f90
index 4cbb1e284f18e..88b31da40167e 100644
--- a/flang/test/Driver/fveclib-codegen.f90
+++ b/flang/test/Driver/fveclib-codegen.f90
@@ -1,6 +1,8 @@
 ! test that -fveclib= is passed to the backend
 ! RUN: %if aarch64-registered-target %{ %flang -S -Ofast -target 
aarch64-unknown-linux-gnu -fveclib=SLEEF -o - %s | FileCheck %s 
--check-prefix=SLEEF %}
 ! RUN: %if x86-registered-target %{ %flang -S -Ofast -target 
x86_64-unknown-linux-gnu -fveclib=libmvec -o - %s | FileCheck %s %}
+! RUN: %if aarch64-registered-target %{ %flang -S -Ofast -target 
aarch64-unknown-linux-gnu -fveclib=libmvec -march=armv8.2-a+nosve -o - %s | 
FileCheck %s --check-prefix=LIBMVEC-AARCH64-NEON %}
+! RUN: %if aarch64-registered-target %{ %flang -S -Ofast -target 
aarch64-unknown-linux-gnu -fveclib=libmvec -march=armv8.2-a+sve -o - %s | 
FileCheck %s --check-prefix=LIBMVEC-AARCH64-SVE %}
 ! RUN: %if x86-registered-target

[clang] [flang] [Flang][AArch64][VecLib] Add libmvec support for Flang/AArch64 (PR #146453)

2025-07-02 Thread KAWASHIMA Takahiro via cfe-commits

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


[clang] [flang] [Flang][AArch64][VecLib] Add libmvec support for Flang/AArch64 (PR #146453)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-hip-vega20` running 
on `hip-vega20-0` while building `clang,flang` at step 3 "annotate".

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


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

```
Step 3 (annotate) failure: 
'../llvm-zorg/zorg/buildbot/builders/annotated/hip-build.sh --jobs=' (failure)
...
[57/59] Linking CXX executable External/HIP/cmath-hip-6.3.0
[58/59] Building CXX object 
External/HIP/CMakeFiles/TheNextWeek-hip-6.3.0.dir/workload/ray-tracing/TheNextWeek/main.cc.o
[59/59] Linking CXX executable External/HIP/TheNextWeek-hip-6.3.0
+ build_step 'Testing HIP test-suite'
+ echo '@@@BUILD_STEP Testing HIP test-suite@@@'
@@@BUILD_STEP Testing HIP test-suite@@@
+ ninja check-hip-simple
[0/1] cd 
/home/botworker/bbot/clang-hip-vega20/botworker/clang-hip-vega20/test-suite-build/External/HIP
 && 
/home/botworker/bbot/clang-hip-vega20/botworker/clang-hip-vega20/llvm/bin/llvm-lit
 -sv array-hip-6.3.0.test empty-hip-6.3.0.test with-fopenmp-hip-6.3.0.test 
saxpy-hip-6.3.0.test memmove-hip-6.3.0.test split-kernel-args-hip-6.3.0.test 
builtin-logb-scalbn-hip-6.3.0.test TheNextWeek-hip-6.3.0.test 
algorithm-hip-6.3.0.test cmath-hip-6.3.0.test complex-hip-6.3.0.test 
math_h-hip-6.3.0.test new-hip-6.3.0.test blender.test
-- Testing: 14 tests, 14 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90
FAIL: test-suite :: External/HIP/blender.test (14 of 14)
 TEST 'test-suite :: External/HIP/blender.test' FAILED 


/home/botworker/bbot/clang-hip-vega20/botworker/clang-hip-vega20/test-suite-build/tools/timeit-target
 --timeout 7200 --limit-core 0 --limit-cpu 7200 --limit-file-size 209715200 
--limit-rss-size 838860800 --append-exitstatus --redirect-output 
/home/botworker/bbot/clang-hip-vega20/botworker/clang-hip-vega20/test-suite-build/External/HIP/Output/blender.test.out
 --redirect-input /dev/null --summary 
/home/botworker/bbot/clang-hip-vega20/botworker/clang-hip-vega20/test-suite-build/External/HIP/Output/blender.test.time
 /bin/bash test_blender.sh
/bin/bash verify_blender.sh 
/home/botworker/bbot/clang-hip-vega20/botworker/clang-hip-vega20/test-suite-build/External/HIP/Output/blender.test.out
Begin Blender test.
TEST_SUITE_HIP_ROOT=/opt/botworker/llvm/External/hip
Render /opt/botworker/llvm/External/hip/Blender_Scenes/290skydemo_release.blend
Blender 4.1.1 (hash e1743a0317bc built 2024-04-15 23:47:45)
Read blend: 
"/opt/botworker/llvm/External/hip/Blender_Scenes/290skydemo_release.blend"
Could not open as Ogawa file from provided streams.
Unable to open 
/opt/botworker/llvm/External/hip/Blender_Scenes/290skydemo2_flags.abc
WARN (bke.modifier): source/blender/blenkernel/intern/modifier.cc:425 
BKE_modifier_set_error: Object: "GEO-flag.002", Modifier: "MeshSequenceCache", 
Could not create reader for file //290skydemo2_flags.abc
WARN (bke.modifier): source/blender/blenkernel/intern/modifier.cc:425 
BKE_modifier_set_error: Object: "GEO-flag.003", Modifier: "MeshSequenceCache", 
Could not create reader for file //290skydemo2_flags.abc
WARN (bke.modifier): source/blender/blenkernel/intern/modifier.cc:425 
BKE_modifier_set_error: Object: "GEO-flag", Modifier: "MeshSequenceCache", 
Could not create reader for file //290skydemo2_flags.abc
WARN (bke.modifier): source/blender/blenkernel/intern/modifier.cc:425 
BKE_modifier_set_error: Object: "GEO-flag.004", Modifier: "MeshSequenceCache", 
Could not create reader for file //290skydemo2_flags.abc
WARN (bke.modifier): source/blender/blenkernel/intern/modifier.cc:425 
BKE_modifier_set_error: Object: "GEO-flag.001", Modifier: "MeshSequenceCache", 
Could not create reader for file //290skydemo2_flags.abc
Could not open as Ogawa file from provided streams.
Unable to open 
/opt/botworker/llvm/External/hip/Blender_Scenes/290skydemo2_flags.abc
WARN (bke.modifier): source/blender/blenkernel/intern/modifier.cc:425 
BKE_modifier_set_error: Object: "GEO-flag.003", Modifier: "MeshSequenceCache", 
Could not create reader for file //290skydemo2_flags.abc
WARN (bke.modifier): source/blender/blenkernel/intern/modifier.cc:425 
BKE_modifier_set_error: Object: "GEO-flag.002", Modifier: "MeshSequenceCache", 
Could not create reader for file //290skydemo2_flags.abc
WARN (bke.modifier): source/blender/blenkernel/intern/modifier.cc:425 
BKE_modifier_set_error: Object: "GEO-flag", Modifier: "MeshSequenceCache", 
Could not create reader for file //290skydemo2_flags.abc
WARN (bke.modifier): source/blender/blenkernel/intern/modifier.cc:425 
BKE_modifier_set_error: Object: "GEO-flag.004", Modifier: "MeshSequenceCache", 
Could not create reader for file //290skydemo2_flags.abc
WARN (bke.modifier): source/blender/blenkernel/intern/modifier.cc:425 
BKE_modifier_set_error: Object: "GEO-flag.001", Modifier: "MeshSequenceCache", 
Could not create reader for file //290skydemo2_flags.abc
I0703 05:43:26.044307 3931561 dev

[clang] [C23] Fix typeof handling in enum declarations (PR #146394)

2025-07-02 Thread via cfe-commits

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


[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-02 Thread Ben Shi via cfe-commits


@@ -651,8 +651,19 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   // This is almost always required because otherwise avr-ld
   // will assume 'avr2' and warn about the program being larger
   // than the bare minimum supports.
-  if (Linker.find("avr-ld") != std::string::npos && FamilyName)
-CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
+  if (Linker.find("avr-ld") != std::string::npos && FamilyName) {
+// Option to use mapped memory for modern devices with >32kB flash.
+// This is the only option for modern devices with <= 32kB flash,
+// but the larger default to a copy from flash to RAM (avr-ld version < 14)
+// or map the highest 32kB to RAM (avr-ld version >= 14).
+if (Args.hasFlag(options::OPT_mflmap, options::OPT_mrodata_in_ram, false)) 
{
+  CmdArgs.push_back(
+  Args.MakeArgString(std::string("-m") + *FamilyName + "_flmap"));

benshi001 wrote:

I agree, so I think I need more time to understand the whole picture what gcc 
did.

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


[clang] 44bed1a - [RISCV] Add negative pre-defined macro test for XAndesVBFHCvt

2025-07-02 Thread Jim Lin via cfe-commits

Author: Jim Lin
Date: 2025-07-03T09:06:01+08:00
New Revision: 44bed1af0fb641ce169262ab9fdb15ad76fe72a1

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

LOG: [RISCV] Add negative pre-defined macro test for XAndesVBFHCvt

Added: 


Modified: 
clang/test/Preprocessor/riscv-target-features-andes.c

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features-andes.c 
b/clang/test/Preprocessor/riscv-target-features-andes.c
index c66d4427b5cf2..e2b783f200766 100644
--- a/clang/test/Preprocessor/riscv-target-features-andes.c
+++ b/clang/test/Preprocessor/riscv-target-features-andes.c
@@ -4,6 +4,7 @@
 // RUN:   -o - | FileCheck %s
 
 // CHECK-NOT: __riscv_xandesperf {{.*$}}
+// CHECK-NOT: __riscv_xandesvbfhcvt {{.*$}}
 // CHECK-NOT: __riscv_xandesvpackfph {{.*$}}
 // CHECK-NOT: __riscv_xandesvdot {{.*$}}
 



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


[clang] [clang-scan-deps] Fix "unterminated conditional directive" bug (PR #146645)

2025-07-02 Thread Naveen Seth Hanig via cfe-commits

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


[clang] [clang] Use range-based for loops (NFC) (PR #146811)

2025-07-02 Thread Kazu Hirata via cfe-commits

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

Note that LLVM Coding Standards discourages std::for_each and
llvm::for_each unless the callable object already exists.


>From b8285abad935fd37196719b7f3b81cf0af0767b5 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Wed, 2 Jul 2025 09:56:20 -0700
Subject: [PATCH] [clang] Use range-based for loops (NFC)

Note that LLVM Coding Standards discourages std::for_each and
llvm::for_each unless the callable object already exists.
---
 clang/include/clang/Sema/DeclSpec.h  |  4 ++--
 clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp| 15 +--
 clang/lib/Driver/ToolChains/HIPSPV.cpp   |  8 +++-
 clang/tools/clang-installapi/ClangInstallAPI.cpp |  4 ++--
 clang/tools/clang-installapi/Options.cpp | 12 ++--
 5 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/clang/include/clang/Sema/DeclSpec.h 
b/clang/include/clang/Sema/DeclSpec.h
index 6c4a32c4ac2f0..567ad2d5934d4 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -1821,8 +1821,8 @@ class DecompositionDeclarator {
 if (DeleteBindings)
   delete[] Bindings;
 else
-  llvm::for_each(llvm::MutableArrayRef(Bindings, NumBindings),
- [](Binding &B) { B.Attrs.reset(); });
+  for (Binding &B : llvm::MutableArrayRef(Bindings, NumBindings))
+B.Attrs.reset();
 Bindings = nullptr;
 NumBindings = 0;
 DeleteBindings = false;
diff --git a/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp 
b/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
index 2623b9bffe6ae..70172d44845a3 100644
--- a/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
@@ -75,11 +75,8 @@ class OpenACCClauseCIREmitter final
   void setLastDeviceTypeClause(const OpenACCDeviceTypeClause &clause) {
 lastDeviceTypeValues.clear();
 
-llvm::for_each(clause.getArchitectures(),
-   [this](const DeviceTypeArgument &arg) {
- lastDeviceTypeValues.push_back(
- decodeDeviceType(arg.getIdentifierInfo()));
-   });
+for (const DeviceTypeArgument &arg : clause.getArchitectures())
+  
lastDeviceTypeValues.push_back(decodeDeviceType(arg.getIdentifierInfo()));
   }
 
   mlir::Value emitIntExpr(const Expr *intExpr) {
@@ -511,11 +508,9 @@ class OpenACCClauseCIREmitter final
 
 if constexpr (isOneOfTypes) {
-  llvm::for_each(
-  clause.getArchitectures(), [this](const DeviceTypeArgument &arg) {
-operation.addDeviceType(builder.getContext(),
-decodeDeviceType(arg.getIdentifierInfo()));
-  });
+  for (const DeviceTypeArgument &arg : clause.getArchitectures())
+operation.addDeviceType(builder.getContext(),
+decodeDeviceType(arg.getIdentifierInfo()));
 } else if constexpr (isOneOfTypes) {
   assert(!operation.getDeviceTypeAttr() && "already have device-type?");
   assert(clause.getArchitectures().size() <= 1);
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp 
b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index c86790f66a79e..7c83ebcface2a 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -149,11 +149,9 @@ void HIPSPVToolChain::addClangTargetOptions(
 CC1Args.append(
 {"-fvisibility=hidden", "-fapply-global-visibility-to-externs"});
 
-  llvm::for_each(getDeviceLibs(DriverArgs),
- [&](const BitCodeLibraryInfo &BCFile) {
-   CC1Args.append({"-mlink-builtin-bitcode",
-   DriverArgs.MakeArgString(BCFile.Path)});
- });
+  for (const BitCodeLibraryInfo &BCFile : getDeviceLibs(DriverArgs))
+CC1Args.append(
+{"-mlink-builtin-bitcode", DriverArgs.MakeArgString(BCFile.Path)});
 }
 
 Tool *HIPSPVToolChain::buildLinker() const {
diff --git a/clang/tools/clang-installapi/ClangInstallAPI.cpp 
b/clang/tools/clang-installapi/ClangInstallAPI.cpp
index f68236abaa6c9..60e9fc4354be4 100644
--- a/clang/tools/clang-installapi/ClangInstallAPI.cpp
+++ b/clang/tools/clang-installapi/ClangInstallAPI.cpp
@@ -102,8 +102,8 @@ static bool run(ArrayRef Args, const char 
*ProgName) {
 
   if (!Opts.DriverOpts.DylibToVerify.empty()) {
 TargetList Targets;
-llvm::for_each(Opts.DriverOpts.Targets,
-   [&](const auto &T) { Targets.push_back(T.first); });
+for (const auto &T : Opts.DriverOpts.Targets)
+  Targets.push_back(T.first);
 if (!Ctx.Verifier->verifyBinaryAttrs(Targets, Ctx.BA, Ctx.Reexports,
  Opts.LinkerOpts.AllowableClients,
  Opts.LinkerOpts.RPaths, Ctx.FT))
diff --git a/clang/tools/clang-installapi/Options.cpp 
b/clang/tools/clang-installapi/Options.cpp
index 52b48a34d361c..64324a3f8b010 1006

[clang] [Sema] Remove an unnecessary cast (NFC) (PR #146808)

2025-07-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

The only use of BW is to initialize BitWidth.  This patch renames BW
to BitWdith while removing the cast statement.


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


1 Files Affected:

- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+1-3) 


``diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e8c65025bfe6d..773148500f0af 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -3431,7 +3431,7 @@ static bool IsUnusedPrivateField(const FieldDecl *FD) {
 NamedDecl *
 Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
MultiTemplateParamsArg TemplateParameterLists,
-   Expr *BW, const VirtSpecifiers &VS,
+   Expr *BitWidth, const VirtSpecifiers &VS,
InClassInitStyle InitStyle) {
   const DeclSpec &DS = D.getDeclSpec();
   DeclarationNameInfo NameInfo = GetNameForDeclarator(D);
@@ -3442,8 +3442,6 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier 
AS, Declarator &D,
   if (Loc.isInvalid())
 Loc = D.getBeginLoc();
 
-  Expr *BitWidth = static_cast(BW);
-
   assert(isa(CurContext));
   assert(!DS.isFriendSpecified());
 

``




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


[clang] [clang] Use range-based for loops (NFC) (PR #146811)

2025-07-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

Note that LLVM Coding Standards discourages std::for_each and
llvm::for_each unless the callable object already exists.


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


5 Files Affected:

- (modified) clang/include/clang/Sema/DeclSpec.h (+2-2) 
- (modified) clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp (+5-10) 
- (modified) clang/lib/Driver/ToolChains/HIPSPV.cpp (+3-5) 
- (modified) clang/tools/clang-installapi/ClangInstallAPI.cpp (+2-2) 
- (modified) clang/tools/clang-installapi/Options.cpp (+6-6) 


``diff
diff --git a/clang/include/clang/Sema/DeclSpec.h 
b/clang/include/clang/Sema/DeclSpec.h
index 6c4a32c4ac2f0..567ad2d5934d4 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -1821,8 +1821,8 @@ class DecompositionDeclarator {
 if (DeleteBindings)
   delete[] Bindings;
 else
-  llvm::for_each(llvm::MutableArrayRef(Bindings, NumBindings),
- [](Binding &B) { B.Attrs.reset(); });
+  for (Binding &B : llvm::MutableArrayRef(Bindings, NumBindings))
+B.Attrs.reset();
 Bindings = nullptr;
 NumBindings = 0;
 DeleteBindings = false;
diff --git a/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp 
b/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
index 2623b9bffe6ae..70172d44845a3 100644
--- a/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
@@ -75,11 +75,8 @@ class OpenACCClauseCIREmitter final
   void setLastDeviceTypeClause(const OpenACCDeviceTypeClause &clause) {
 lastDeviceTypeValues.clear();
 
-llvm::for_each(clause.getArchitectures(),
-   [this](const DeviceTypeArgument &arg) {
- lastDeviceTypeValues.push_back(
- decodeDeviceType(arg.getIdentifierInfo()));
-   });
+for (const DeviceTypeArgument &arg : clause.getArchitectures())
+  
lastDeviceTypeValues.push_back(decodeDeviceType(arg.getIdentifierInfo()));
   }
 
   mlir::Value emitIntExpr(const Expr *intExpr) {
@@ -511,11 +508,9 @@ class OpenACCClauseCIREmitter final
 
 if constexpr (isOneOfTypes) {
-  llvm::for_each(
-  clause.getArchitectures(), [this](const DeviceTypeArgument &arg) {
-operation.addDeviceType(builder.getContext(),
-decodeDeviceType(arg.getIdentifierInfo()));
-  });
+  for (const DeviceTypeArgument &arg : clause.getArchitectures())
+operation.addDeviceType(builder.getContext(),
+decodeDeviceType(arg.getIdentifierInfo()));
 } else if constexpr (isOneOfTypes) {
   assert(!operation.getDeviceTypeAttr() && "already have device-type?");
   assert(clause.getArchitectures().size() <= 1);
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp 
b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index c86790f66a79e..7c83ebcface2a 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -149,11 +149,9 @@ void HIPSPVToolChain::addClangTargetOptions(
 CC1Args.append(
 {"-fvisibility=hidden", "-fapply-global-visibility-to-externs"});
 
-  llvm::for_each(getDeviceLibs(DriverArgs),
- [&](const BitCodeLibraryInfo &BCFile) {
-   CC1Args.append({"-mlink-builtin-bitcode",
-   DriverArgs.MakeArgString(BCFile.Path)});
- });
+  for (const BitCodeLibraryInfo &BCFile : getDeviceLibs(DriverArgs))
+CC1Args.append(
+{"-mlink-builtin-bitcode", DriverArgs.MakeArgString(BCFile.Path)});
 }
 
 Tool *HIPSPVToolChain::buildLinker() const {
diff --git a/clang/tools/clang-installapi/ClangInstallAPI.cpp 
b/clang/tools/clang-installapi/ClangInstallAPI.cpp
index f68236abaa6c9..60e9fc4354be4 100644
--- a/clang/tools/clang-installapi/ClangInstallAPI.cpp
+++ b/clang/tools/clang-installapi/ClangInstallAPI.cpp
@@ -102,8 +102,8 @@ static bool run(ArrayRef Args, const char 
*ProgName) {
 
   if (!Opts.DriverOpts.DylibToVerify.empty()) {
 TargetList Targets;
-llvm::for_each(Opts.DriverOpts.Targets,
-   [&](const auto &T) { Targets.push_back(T.first); });
+for (const auto &T : Opts.DriverOpts.Targets)
+  Targets.push_back(T.first);
 if (!Ctx.Verifier->verifyBinaryAttrs(Targets, Ctx.BA, Ctx.Reexports,
  Opts.LinkerOpts.AllowableClients,
  Opts.LinkerOpts.RPaths, Ctx.FT))
diff --git a/clang/tools/clang-installapi/Options.cpp 
b/clang/tools/clang-installapi/Options.cpp
index 52b48a34d361c..64324a3f8b010 100644
--- a/clang/tools/clang-installapi/Options.cpp
+++ b/clang/tools/clang-installapi/Options.cpp
@@ -100,8 +100,8 @@ getArgListFromJSON(const StringRef Input, 
llvm::opt::OptTable *Table,
   }
 
   std::vector CArgs(Storage.size());
-  llvm::for_each(Storage,

[clang] [clang] Use range-based for loops (NFC) (PR #146811)

2025-07-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Kazu Hirata (kazutakahirata)


Changes

Note that LLVM Coding Standards discourages std::for_each and
llvm::for_each unless the callable object already exists.


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


5 Files Affected:

- (modified) clang/include/clang/Sema/DeclSpec.h (+2-2) 
- (modified) clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp (+5-10) 
- (modified) clang/lib/Driver/ToolChains/HIPSPV.cpp (+3-5) 
- (modified) clang/tools/clang-installapi/ClangInstallAPI.cpp (+2-2) 
- (modified) clang/tools/clang-installapi/Options.cpp (+6-6) 


``diff
diff --git a/clang/include/clang/Sema/DeclSpec.h 
b/clang/include/clang/Sema/DeclSpec.h
index 6c4a32c4ac2f0..567ad2d5934d4 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -1821,8 +1821,8 @@ class DecompositionDeclarator {
 if (DeleteBindings)
   delete[] Bindings;
 else
-  llvm::for_each(llvm::MutableArrayRef(Bindings, NumBindings),
- [](Binding &B) { B.Attrs.reset(); });
+  for (Binding &B : llvm::MutableArrayRef(Bindings, NumBindings))
+B.Attrs.reset();
 Bindings = nullptr;
 NumBindings = 0;
 DeleteBindings = false;
diff --git a/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp 
b/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
index 2623b9bffe6ae..70172d44845a3 100644
--- a/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
@@ -75,11 +75,8 @@ class OpenACCClauseCIREmitter final
   void setLastDeviceTypeClause(const OpenACCDeviceTypeClause &clause) {
 lastDeviceTypeValues.clear();
 
-llvm::for_each(clause.getArchitectures(),
-   [this](const DeviceTypeArgument &arg) {
- lastDeviceTypeValues.push_back(
- decodeDeviceType(arg.getIdentifierInfo()));
-   });
+for (const DeviceTypeArgument &arg : clause.getArchitectures())
+  
lastDeviceTypeValues.push_back(decodeDeviceType(arg.getIdentifierInfo()));
   }
 
   mlir::Value emitIntExpr(const Expr *intExpr) {
@@ -511,11 +508,9 @@ class OpenACCClauseCIREmitter final
 
 if constexpr (isOneOfTypes) {
-  llvm::for_each(
-  clause.getArchitectures(), [this](const DeviceTypeArgument &arg) {
-operation.addDeviceType(builder.getContext(),
-decodeDeviceType(arg.getIdentifierInfo()));
-  });
+  for (const DeviceTypeArgument &arg : clause.getArchitectures())
+operation.addDeviceType(builder.getContext(),
+decodeDeviceType(arg.getIdentifierInfo()));
 } else if constexpr (isOneOfTypes) {
   assert(!operation.getDeviceTypeAttr() && "already have device-type?");
   assert(clause.getArchitectures().size() <= 1);
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp 
b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index c86790f66a79e..7c83ebcface2a 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -149,11 +149,9 @@ void HIPSPVToolChain::addClangTargetOptions(
 CC1Args.append(
 {"-fvisibility=hidden", "-fapply-global-visibility-to-externs"});
 
-  llvm::for_each(getDeviceLibs(DriverArgs),
- [&](const BitCodeLibraryInfo &BCFile) {
-   CC1Args.append({"-mlink-builtin-bitcode",
-   DriverArgs.MakeArgString(BCFile.Path)});
- });
+  for (const BitCodeLibraryInfo &BCFile : getDeviceLibs(DriverArgs))
+CC1Args.append(
+{"-mlink-builtin-bitcode", DriverArgs.MakeArgString(BCFile.Path)});
 }
 
 Tool *HIPSPVToolChain::buildLinker() const {
diff --git a/clang/tools/clang-installapi/ClangInstallAPI.cpp 
b/clang/tools/clang-installapi/ClangInstallAPI.cpp
index f68236abaa6c9..60e9fc4354be4 100644
--- a/clang/tools/clang-installapi/ClangInstallAPI.cpp
+++ b/clang/tools/clang-installapi/ClangInstallAPI.cpp
@@ -102,8 +102,8 @@ static bool run(ArrayRef Args, const char 
*ProgName) {
 
   if (!Opts.DriverOpts.DylibToVerify.empty()) {
 TargetList Targets;
-llvm::for_each(Opts.DriverOpts.Targets,
-   [&](const auto &T) { Targets.push_back(T.first); });
+for (const auto &T : Opts.DriverOpts.Targets)
+  Targets.push_back(T.first);
 if (!Ctx.Verifier->verifyBinaryAttrs(Targets, Ctx.BA, Ctx.Reexports,
  Opts.LinkerOpts.AllowableClients,
  Opts.LinkerOpts.RPaths, Ctx.FT))
diff --git a/clang/tools/clang-installapi/Options.cpp 
b/clang/tools/clang-installapi/Options.cpp
index 52b48a34d361c..64324a3f8b010 100644
--- a/clang/tools/clang-installapi/Options.cpp
+++ b/clang/tools/clang-installapi/Options.cpp
@@ -100,8 +100,8 @@ getArgListFromJSON(const StringRef Input, 
llvm::opt::OptTable *Table,
   }
 
   std::vector CArgs(Storage.size());
-  llvm::for_each(St

[clang] [clang] Use range-based for loops (NFC) (PR #146811)

2025-07-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Kazu Hirata (kazutakahirata)


Changes

Note that LLVM Coding Standards discourages std::for_each and
llvm::for_each unless the callable object already exists.


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


5 Files Affected:

- (modified) clang/include/clang/Sema/DeclSpec.h (+2-2) 
- (modified) clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp (+5-10) 
- (modified) clang/lib/Driver/ToolChains/HIPSPV.cpp (+3-5) 
- (modified) clang/tools/clang-installapi/ClangInstallAPI.cpp (+2-2) 
- (modified) clang/tools/clang-installapi/Options.cpp (+6-6) 


``diff
diff --git a/clang/include/clang/Sema/DeclSpec.h 
b/clang/include/clang/Sema/DeclSpec.h
index 6c4a32c4ac2f0..567ad2d5934d4 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -1821,8 +1821,8 @@ class DecompositionDeclarator {
 if (DeleteBindings)
   delete[] Bindings;
 else
-  llvm::for_each(llvm::MutableArrayRef(Bindings, NumBindings),
- [](Binding &B) { B.Attrs.reset(); });
+  for (Binding &B : llvm::MutableArrayRef(Bindings, NumBindings))
+B.Attrs.reset();
 Bindings = nullptr;
 NumBindings = 0;
 DeleteBindings = false;
diff --git a/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp 
b/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
index 2623b9bffe6ae..70172d44845a3 100644
--- a/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
@@ -75,11 +75,8 @@ class OpenACCClauseCIREmitter final
   void setLastDeviceTypeClause(const OpenACCDeviceTypeClause &clause) {
 lastDeviceTypeValues.clear();
 
-llvm::for_each(clause.getArchitectures(),
-   [this](const DeviceTypeArgument &arg) {
- lastDeviceTypeValues.push_back(
- decodeDeviceType(arg.getIdentifierInfo()));
-   });
+for (const DeviceTypeArgument &arg : clause.getArchitectures())
+  
lastDeviceTypeValues.push_back(decodeDeviceType(arg.getIdentifierInfo()));
   }
 
   mlir::Value emitIntExpr(const Expr *intExpr) {
@@ -511,11 +508,9 @@ class OpenACCClauseCIREmitter final
 
 if constexpr (isOneOfTypes) {
-  llvm::for_each(
-  clause.getArchitectures(), [this](const DeviceTypeArgument &arg) {
-operation.addDeviceType(builder.getContext(),
-decodeDeviceType(arg.getIdentifierInfo()));
-  });
+  for (const DeviceTypeArgument &arg : clause.getArchitectures())
+operation.addDeviceType(builder.getContext(),
+decodeDeviceType(arg.getIdentifierInfo()));
 } else if constexpr (isOneOfTypes) {
   assert(!operation.getDeviceTypeAttr() && "already have device-type?");
   assert(clause.getArchitectures().size() <= 1);
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp 
b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index c86790f66a79e..7c83ebcface2a 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -149,11 +149,9 @@ void HIPSPVToolChain::addClangTargetOptions(
 CC1Args.append(
 {"-fvisibility=hidden", "-fapply-global-visibility-to-externs"});
 
-  llvm::for_each(getDeviceLibs(DriverArgs),
- [&](const BitCodeLibraryInfo &BCFile) {
-   CC1Args.append({"-mlink-builtin-bitcode",
-   DriverArgs.MakeArgString(BCFile.Path)});
- });
+  for (const BitCodeLibraryInfo &BCFile : getDeviceLibs(DriverArgs))
+CC1Args.append(
+{"-mlink-builtin-bitcode", DriverArgs.MakeArgString(BCFile.Path)});
 }
 
 Tool *HIPSPVToolChain::buildLinker() const {
diff --git a/clang/tools/clang-installapi/ClangInstallAPI.cpp 
b/clang/tools/clang-installapi/ClangInstallAPI.cpp
index f68236abaa6c9..60e9fc4354be4 100644
--- a/clang/tools/clang-installapi/ClangInstallAPI.cpp
+++ b/clang/tools/clang-installapi/ClangInstallAPI.cpp
@@ -102,8 +102,8 @@ static bool run(ArrayRef Args, const char 
*ProgName) {
 
   if (!Opts.DriverOpts.DylibToVerify.empty()) {
 TargetList Targets;
-llvm::for_each(Opts.DriverOpts.Targets,
-   [&](const auto &T) { Targets.push_back(T.first); });
+for (const auto &T : Opts.DriverOpts.Targets)
+  Targets.push_back(T.first);
 if (!Ctx.Verifier->verifyBinaryAttrs(Targets, Ctx.BA, Ctx.Reexports,
  Opts.LinkerOpts.AllowableClients,
  Opts.LinkerOpts.RPaths, Ctx.FT))
diff --git a/clang/tools/clang-installapi/Options.cpp 
b/clang/tools/clang-installapi/Options.cpp
index 52b48a34d361c..64324a3f8b010 100644
--- a/clang/tools/clang-installapi/Options.cpp
+++ b/clang/tools/clang-installapi/Options.cpp
@@ -100,8 +100,8 @@ getArgListFromJSON(const StringRef Input, 
llvm::opt::OptTable *Table,
   }
 
   std::vector CArgs(Storage.size());
-  llvm::for_each(Storage

[clang] [Clang] [Diagnostics] Simplify filenames that contain '..' (PR #143520)

2025-07-02 Thread Richard Thomson via cfe-commits

LegalizeAdulthood wrote:

My expectation would be that if I specify a header filter I'm not going to use 
weird paths like a/b/../foo.h, but just a/foo.h because that is where foo.h 
lives.

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


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

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

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

This (mostly) removes one of the largest remaining limitations of `hipstdpar` 
based algorithm acceleration, by adding support for global variable usage in 
offloaded algorithms. It is mean to compose with a run time component that will 
live in the support library, and fires iff a special variable is provided by 
the latter. In short, things work as follows:

- We replace uses some global `G` with an indirect access via an implicitly 
created anonymous global `F`, which is of pointer type and is expected to hold 
the program-wide address of `G`;
- We append 'F', alongside 'G''s name, to an table structure;
- At run-time, the support library uses the table to look-up the program-wide 
address of a contained symbol based on its name, and then stores the address 
via the paired pointer.

This doesn't handle internal linkage symbols (`static foo` or `namespace { foo 
}`) if they are not unique i.e. if there's a name clash that is solved by the 
linker, as the resolution would not be visible. Also, initially we will only 
support "true" globals in RDC mode. Things would be much simpler if we had 
direct access to the accelerator loader, but since the expectation is to 
compose at the HIP RT level we have to jump through additional hoops.

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

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

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

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

2025-07-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alex Voicu (AlexVlx)


Changes

This (mostly) removes one of the largest remaining limitations of `hipstdpar` 
based algorithm acceleration, by adding support for global variable usage in 
offloaded algorithms. It is mean to compose with a run time component that will 
live in the support library, and fires iff a special variable is provided by 
the latter. In short, things work as follows:

- We replace uses some global `G` with an indirect access via an implicitly 
created anonymous global `F`, which is of pointer type and is expected to hold 
the program-wide address of `G`;
- We append 'F', alongside 'G''s name, to an table structure;
- At run-time, the support library uses the table to look-up the program-wide 
address of a contained symbol based on its name, and then stores the address 
via the paired pointer.

This doesn't handle internal linkage symbols (`static foo` or `namespace { foo 
}`) if they are not unique i.e. if there's a name clash that is solved by the 
linker, as the resolution would not be visible. Also, initially we will only 
support "true" globals in RDC mode. Things would be much simpler if we had 
direct access to the accelerator loader, but since the expectation is to 
compose at the HIP RT level we have to jump through additional hoops.

---

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


9 Files Affected:

- (modified) clang/docs/HIPSupport.rst (+11-45) 
- (modified) llvm/lib/Transforms/HipStdPar/HipStdPar.cpp (+210-10) 
- (added) 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-member-0.ll 
(+15) 
- (added) 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-member-1.ll 
(+15) 
- (added) 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-member-2.ll 
(+15) 
- (added) 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-member-count.ll
 (+14) 
- (added) 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-type.ll (+13) 
- (added) llvm/test/Transforms/HipStdPar/global-var-indirection.ll (+87) 
- (modified) llvm/test/Transforms/HipStdPar/global-var.ll (+2-2) 


``diff
diff --git a/clang/docs/HIPSupport.rst b/clang/docs/HIPSupport.rst
index 406e1c8e5a2fe..bffb8f2348490 100644
--- a/clang/docs/HIPSupport.rst
+++ b/clang/docs/HIPSupport.rst
@@ -537,7 +537,7 @@ We define two modes in which runtime execution can occur:
directly accessible to the accelerator and it follows the C++ memory model;
 2. **Interposition Mode** - this is a fallback mode for cases where transparent
on-demand paging is unavailable (e.g. in the Windows OS), which means that
-   memory must be allocated via an accelerator aware mechanism, and system
+   memory must be allocated via an accelerator aware mechanism, and some system
allocated memory is inaccessible for the accelerator.
 
 The following restrictions imposed on user code apply to both modes:
@@ -545,27 +545,8 @@ The following restrictions imposed on user code apply to 
both modes:
 1. Pointers to function, and all associated features, such as e.g. dynamic
polymorphism, cannot be used (directly or transitively) by the user provided
callable passed to an algorithm invocation;
-2. Global / namespace scope / ``static`` / ``thread`` storage duration 
variables
-   cannot be used (directly or transitively) in name by the user provided
-   callable;
-
-   - When executing in **HMM Mode** they can be used in address e.g.:
-
- .. code-block:: C++
-
-namespace { int foo = 42; }
-
-bool never(const std::vector& v) {
-  return std::any_of(std::execution::par_unseq, std::cbegin(v), 
std::cend(v), [](auto&& x) {
-return x == foo;
-  });
-}
-
-bool only_in_hmm_mode(const std::vector& v) {
-  return std::any_of(std::execution::par_unseq, std::cbegin(v), 
std::cend(v),
- [p = &foo](auto&& x) { return x == *p; });
-}
-
+2. ``static`` / ``thread`` storage duration variables cannot be used (directly
+   or transitively) in name by the user provided callable;
 3. Only algorithms that are invoked with the ``parallel_unsequenced_policy`` 
are
candidates for offload;
 4. Only algorithms that are invoked with iterator arguments that model
@@ -585,15 +566,6 @@ additional restrictions:
 1. All code that is expected to interoperate has to be recompiled with the
``--hipstdpar-interpose-alloc`` flag i.e. it is not safe to compose 
libraries
that have been independently compiled;
-2. automatic storage duration (i.e. stack allocated) variables cannot be used
-   (directly or transitively) by the user provided callable e.g.
-
-   .. code-block:: c++
-
-  bool never(const std::vector& v, int n) {
-return std::any_of(std::execution::par_unseq, std::cbegin(v), 
std::cend(v),
-   [p = &n](auto&& x) { ret

[clang] [Sema] Remove an unnecessary cast (NFC) (PR #146808)

2025-07-02 Thread Kazu Hirata via cfe-commits

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

The only use of BW is to initialize BitWidth.  This patch renames BW
to BitWdith while removing the cast statement.


>From 27461a27118922c384e6bd97b9d0a9d6848960dc Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Wed, 2 Jul 2025 09:39:56 -0700
Subject: [PATCH] [Sema] Remove an unnecessary cast (NFC)

The only use of BW is to initialize BitWidth.  This patch renames BW
to BitWdith while removing the cast statement.
---
 clang/lib/Sema/SemaDeclCXX.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e8c65025bfe6d..773148500f0af 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -3431,7 +3431,7 @@ static bool IsUnusedPrivateField(const FieldDecl *FD) {
 NamedDecl *
 Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
MultiTemplateParamsArg TemplateParameterLists,
-   Expr *BW, const VirtSpecifiers &VS,
+   Expr *BitWidth, const VirtSpecifiers &VS,
InClassInitStyle InitStyle) {
   const DeclSpec &DS = D.getDeclSpec();
   DeclarationNameInfo NameInfo = GetNameForDeclarator(D);
@@ -3442,8 +3442,6 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier 
AS, Declarator &D,
   if (Loc.isInvalid())
 Loc = D.getBeginLoc();
 
-  Expr *BitWidth = static_cast(BW);
-
   assert(isa(CurContext));
   assert(!DS.isFriendSpecified());
 

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


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

2025-07-02 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp -- 
llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp 
b/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
index 87fbcd40b..41d5b2cc4 100644
--- a/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
+++ b/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
@@ -115,8 +115,8 @@ static inline void clearModule(Module &M) { // TODO: 
simplify.
 eraseFromModule(*M.ifuncs().begin());
 }
 
-static inline SmallVector> collectIndirectableUses(
-  GlobalVariable *G) {
+static inline SmallVector>
+collectIndirectableUses(GlobalVariable *G) {
   // We are interested only in use chains that end in an Instruction.
   SmallVector> Uses;
 
@@ -127,9 +127,8 @@ static inline SmallVector> 
collectIndirectableUses(
 if (isa(U.getUser()))
   Uses.emplace_back(U);
 else
-  transform(U.getUser()->uses(), std::back_inserter(Tmp), [](auto &&U) {
-return std::ref(U);
-  });
+  transform(U.getUser()->uses(), std::back_inserter(Tmp),
+[](auto &&U) { return std::ref(U); });
   }
 
   return Uses;
@@ -153,9 +152,8 @@ static inline GlobalVariable *getIndirectionGlobal(Module 
*M) {
   // Create an anonymous global which stores a pointer to a pointer, which will
   // be externally initialised by the HIPSTDPAR runtime with the address of the
   // program-wide symbol.
-  Type *PtrTy =
-  PointerType::get(M->getContext(),
-   M->getDataLayout().getDefaultGlobalsAddressSpace());
+  Type *PtrTy = PointerType::get(
+  M->getContext(), M->getDataLayout().getDefaultGlobalsAddressSpace());
   GlobalVariable *NewG = M->getOrInsertGlobal("", PtrTy);
 
   NewG->setInitializer(PoisonValue::get(NewG->getValueType()));
@@ -166,10 +164,10 @@ static inline GlobalVariable *getIndirectionGlobal(Module 
*M) {
   return NewG;
 }
 
-static inline Constant *appendIndirectedGlobal(
-const GlobalVariable *IndirectionTable,
-SmallVector &SymbolIndirections,
-GlobalVariable *ToIndirect) {
+static inline Constant *
+appendIndirectedGlobal(const GlobalVariable *IndirectionTable,
+   SmallVector &SymbolIndirections,
+   GlobalVariable *ToIndirect) {
   Module *M = ToIndirect->getParent();
 
   auto *InitTy = cast(IndirectionTable->getValueType());
@@ -201,8 +199,8 @@ static void fillIndirectionTable(GlobalVariable 
*IndirectionTable,
   GlobalVariable *Symbols =
   M->getOrInsertGlobal("", ArrayType::get(SymbolTy, SymCnt));
   Symbols->setLinkage(GlobalValue::LinkageTypes::PrivateLinkage);
-  Symbols->setInitializer(ConstantArray::get(ArrayType::get(SymbolTy, SymCnt),
- {Indirections}));
+  Symbols->setInitializer(
+  ConstantArray::get(ArrayType::get(SymbolTy, SymCnt), {Indirections}));
   Symbols->setConstant(true);
 
   Constant *ASCSymbols = ConstantExpr::getAddrSpaceCast(Symbols, SymbolListTy);
@@ -226,7 +224,7 @@ static void replaceWithIndirectUse(const Use &U, const 
GlobalVariable *G,
 assert((CE->getOpcode() == Instruction::GetElementPtr ||
 CE->getOpcode() == Instruction::AddrSpaceCast ||
 CE->getOpcode() == Instruction::PtrToInt) &&
-"Only GEP, ASCAST or PTRTOINT constant uses supported!");
+   "Only GEP, ASCAST or PTRTOINT constant uses supported!");
 
 Instruction *NewI = Builder.Insert(CE->getAsInstruction());
 I->replaceUsesOfWith(Op, NewI);
@@ -237,8 +235,8 @@ static void replaceWithIndirectUse(const Use &U, const 
GlobalVariable *G,
 
   assert(Op == G && "Must reach indirected global!");
 
-  Builder.GetInsertPoint()->setOperand(0, Builder.CreateLoad(G->getType(),
- IndirectedG));
+  Builder.GetInsertPoint()->setOperand(
+  0, Builder.CreateLoad(G->getType(), IndirectedG));
 }
 
 static inline bool isValidIndirectionTable(GlobalVariable *IndirectionTable) {
@@ -254,7 +252,7 @@ static inline bool isValidIndirectionTable(GlobalVariable 
*IndirectionTable) {
 OS << " is incorrect.\n";
   } else if (cast(Ty)->getNumElements() != 3u) {
 OS << "The Indirection Table must have 3 elements; "
-  << cast(Ty)->getNumElements() << " is incorrect.\n";
+   << cast(Ty)->getNumElements() << " is incorrect.\n";
   } else if (!isa(cast(Ty)->getStructElementType(0))) 
{
 OS << "The first element in the Indirection Table must be an integer; ";
 cast(Ty)->getStructElementType(0)->print(OS);
@@ -289,8 +287,8 @@ static void indirectGlobals(GlobalVariable 
*IndirectionTable,
 if (Uses.empty())
   continue;
 
-Constant *IndirectedGlobal = appendIndirectedGlobal(IndirectionTable,
-

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

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

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

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

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

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

[clang] [clang-tools-extra] [clang][CodeComplete] skip explicit obj param in SignatureHelp (PR #146649)

2025-07-02 Thread Mythreya Kuricheti via cfe-commits

MythreyaK wrote:

Seems to be working as expected. I'll add a test case for this as well. 

![image](https://github.com/user-attachments/assets/f736c68f-a64d-4af6-876a-d647d0d6541e)
![image](https://github.com/user-attachments/assets/e40ee898-a161-4564-869c-b566e7b3452b)


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


[clang] [clang-tools-extra] [clang][modules] Serialize `CodeGenOptions` (PR #146422)

2025-07-02 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> I'm not suggesting to treat CodeGenOptions as incompatible by default. For 
> now I'm just trying to remove the duplication and improve the 
> infrastructure.CodeGenOptions are still benign by default, and can only be 
> marked as compatible, which doesn't have any impact on explicitly-built 
> modules. This PR is intended to be an NFC.

Then it sounds good to me.

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


[clang] [llvm] [OptBisect][IR] Adding a new OptPassGate for disabling passes via name (PR #145059)

2025-07-02 Thread Mircea Trofin via cfe-commits

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


[clang] 1f8f477 - [ARM] Add neon vector support for trunc

2025-07-02 Thread David Green via cfe-commits

Author: David Green
Date: 2025-07-03T07:41:13+01:00
New Revision: 1f8f477bd03869a9b5b2e7ff0c24c74397aba486

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

LOG: [ARM] Add neon vector support for trunc

As per #142559, this marks ftrunc as legal for Neon and upgrades the existing
arm.neon.vrintz intrinsics.

Added: 


Modified: 
clang/lib/CodeGen/TargetBuiltins/ARM.cpp
clang/test/CodeGen/arm-neon-directed-rounding.c
clang/test/CodeGen/arm-v8.2a-neon-intrinsics.c
llvm/include/llvm/IR/IntrinsicsARM.td
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/Target/ARM/ARMISelLowering.cpp
llvm/lib/Target/ARM/ARMInstrNEON.td
llvm/test/CodeGen/ARM/vrint.ll

Removed: 




diff  --git a/clang/lib/CodeGen/TargetBuiltins/ARM.cpp 
b/clang/lib/CodeGen/TargetBuiltins/ARM.cpp
index 318c92f07b780..b21ff28da099e 100644
--- a/clang/lib/CodeGen/TargetBuiltins/ARM.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/ARM.cpp
@@ -838,7 +838,7 @@ static const ARMVectorIntrinsicInfo ARMSIMDIntrinsicMap [] 
= {
   NEONMAP1(vrecpsq_v, arm_neon_vrecps, Add1ArgType),
   NEONMAP2(vrhadd_v, arm_neon_vrhaddu, arm_neon_vrhadds, Add1ArgType | 
UnsignedAlts),
   NEONMAP2(vrhaddq_v, arm_neon_vrhaddu, arm_neon_vrhadds, Add1ArgType | 
UnsignedAlts),
-  NEONMAP1(vrnd_v, arm_neon_vrintz, Add1ArgType),
+  NEONMAP1(vrnd_v, trunc, Add1ArgType),
   NEONMAP1(vrnda_v, round, Add1ArgType),
   NEONMAP1(vrndaq_v, round, Add1ArgType),
   NEONMAP0(vrndi_v),
@@ -849,7 +849,7 @@ static const ARMVectorIntrinsicInfo ARMSIMDIntrinsicMap [] 
= {
   NEONMAP1(vrndnq_v, arm_neon_vrintn, Add1ArgType),
   NEONMAP1(vrndp_v, ceil, Add1ArgType),
   NEONMAP1(vrndpq_v, ceil, Add1ArgType),
-  NEONMAP1(vrndq_v, arm_neon_vrintz, Add1ArgType),
+  NEONMAP1(vrndq_v, trunc, Add1ArgType),
   NEONMAP1(vrndx_v, arm_neon_vrintx, Add1ArgType),
   NEONMAP1(vrndxq_v, arm_neon_vrintx, Add1ArgType),
   NEONMAP2(vrshl_v, arm_neon_vrshiftu, arm_neon_vrshifts, Add1ArgType | 
UnsignedAlts),

diff  --git a/clang/test/CodeGen/arm-neon-directed-rounding.c 
b/clang/test/CodeGen/arm-neon-directed-rounding.c
index 60332405a678a..27b7be6a81fad 100644
--- a/clang/test/CodeGen/arm-neon-directed-rounding.c
+++ b/clang/test/CodeGen/arm-neon-directed-rounding.c
@@ -266,7 +266,7 @@ float32x4_t test_vrndxq_f32(float32x4_t a) {
 // CHECK-A32-NEXT:[[TMP0:%.*]] = bitcast <2 x float> [[A]] to <2 x i32>
 // CHECK-A32-NEXT:[[TMP1:%.*]] = bitcast <2 x i32> [[TMP0]] to <8 x i8>
 // CHECK-A32-NEXT:[[VRND_V_I:%.*]] = bitcast <8 x i8> [[TMP1]] to <2 x 
float>
-// CHECK-A32-NEXT:[[VRND_V1_I:%.*]] = call <2 x float> 
@llvm.arm.neon.vrintz.v2f32(<2 x float> [[VRND_V_I]])
+// CHECK-A32-NEXT:[[VRND_V1_I:%.*]] = call <2 x float> 
@llvm.trunc.v2f32(<2 x float> [[VRND_V_I]])
 // CHECK-A32-NEXT:[[VRND_V2_I:%.*]] = bitcast <2 x float> [[VRND_V1_I]] to 
<8 x i8>
 // CHECK-A32-NEXT:[[TMP2:%.*]] = bitcast <8 x i8> [[VRND_V2_I]] to <2 x 
i32>
 // CHECK-A32-NEXT:[[TMP3:%.*]] = bitcast <2 x i32> [[TMP2]] to <2 x float>
@@ -291,7 +291,7 @@ float32x2_t test_vrnd_f32(float32x2_t a) {
 // CHECK-A32-NEXT:[[TMP0:%.*]] = bitcast <4 x float> [[A]] to <4 x i32>
 // CHECK-A32-NEXT:[[TMP1:%.*]] = bitcast <4 x i32> [[TMP0]] to <16 x i8>
 // CHECK-A32-NEXT:[[VRNDQ_V_I:%.*]] = bitcast <16 x i8> [[TMP1]] to <4 x 
float>
-// CHECK-A32-NEXT:[[VRNDQ_V1_I:%.*]] = call <4 x float> 
@llvm.arm.neon.vrintz.v4f32(<4 x float> [[VRNDQ_V_I]])
+// CHECK-A32-NEXT:[[VRNDQ_V1_I:%.*]] = call <4 x float> 
@llvm.trunc.v4f32(<4 x float> [[VRNDQ_V_I]])
 // CHECK-A32-NEXT:[[VRNDQ_V2_I:%.*]] = bitcast <4 x float> [[VRNDQ_V1_I]] 
to <16 x i8>
 // CHECK-A32-NEXT:[[TMP2:%.*]] = bitcast <16 x i8> [[VRNDQ_V2_I]] to <4 x 
i32>
 // CHECK-A32-NEXT:[[TMP3:%.*]] = bitcast <4 x i32> [[TMP2]] to <4 x float>

diff  --git a/clang/test/CodeGen/arm-v8.2a-neon-intrinsics.c 
b/clang/test/CodeGen/arm-v8.2a-neon-intrinsics.c
index 3277a760733b4..096be51b3d03f 100644
--- a/clang/test/CodeGen/arm-v8.2a-neon-intrinsics.c
+++ b/clang/test/CodeGen/arm-v8.2a-neon-intrinsics.c
@@ -522,7 +522,7 @@ float16x8_t test_vrecpeq_f16(float16x8_t a) {
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x half> [[A]] to <4 x i16>
 // CHECK-NEXT:[[TMP1:%.*]] = bitcast <4 x i16> [[TMP0]] to <8 x i8>
 // CHECK-NEXT:[[VRND_V_I:%.*]] = bitcast <8 x i8> [[TMP1]] to <4 x half>
-// CHECK-NEXT:[[VRND_V1_I:%.*]] = call <4 x half> 
@llvm.arm.neon.vrintz.v4f16(<4 x half> [[VRND_V_I]])
+// CHECK-NEXT:[[VRND_V1_I:%.*]] = call <4 x half> @llvm.trunc.v4f16(<4 x 
half> [[VRND_V_I]])
 // CHECK-NEXT:[[VRND_V2_I:%.*]] = bitcast <4 x half> [[VRND_V1_I]] to <8 x 
i8>
 // CHECK-NEXT:[[TMP2:%.*]] = bitcast <8 x i8> [[VRND_V2_I]] to <4 x i16>
 // CHECK-NEXT:[[TMP3:%.*]] = bitcast <4 x i16> [[TMP2]] to <4 x half>
@@ -5

[clang] [clang][analyzer] Fix the false positive ArgInitializedness warning on unnamed bit-field (PR #145066)

2025-07-02 Thread Balazs Benics via cfe-commits

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


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


[clang] [OpenMP-5.2] deprecate delimited form of 'declare target' (PR #145854)

2025-07-02 Thread Urvi Rav via cfe-commits

ravurvi20 wrote:

@alexey-bataev I have updated Release notes. Since it's just a deprecation it 
is not there in support file.


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


[clang] [llvm] [ORC] Replace ThreadSafeContext::getContext with withContextDo. (PR #146819)

2025-07-02 Thread Lang Hames via cfe-commits

https://github.com/lhames created 
https://github.com/llvm/llvm-project/pull/146819

This removes ThreadSafeContext::Lock, ThreadSafeContext::getLock, and 
ThreadSafeContext::getContext, and replaces them with a 
ThreadSafeContext::withContextDo method (and const override).

The new method can be used to access an existing ThreadSafeContext-wrapped 
LLVMContext in a safe way:

ThreadSafeContext TSCtx = ... ;
TSCtx.withContextDo([](LLVMContext *Ctx) {
  // this closure has exclusive access to Ctx.
});

The new API enforces correct locking, whereas the old APIs relied on manual 
locking (which almost no in-tree code preformed, relying instead on incidental 
exclusive access to the ThreadSafeContext).

>From bc2a43f9b08d4221cd62ac739ba26d01ad3b6369 Mon Sep 17 00:00:00 2001
From: Lang Hames 
Date: Thu, 3 Jul 2025 15:00:35 +1000
Subject: [PATCH] [ORC] Replace ThreadSafeContext::getContext with a
 withContextDo operation.

This removes ThreadSafeContext::Lock, ThreadSafeContext::getLock, and
ThreadSafeContext::getContext, and replaces them with a
ThreadSafeContext::withContextDo method (and const override).

The new method can be used to access an existing ThreadSafeContext-wrapped
LLVMContext in a safe way:

ThreadSafeContext TSCtx = ... ;
TSCtx.withContextDo([](LLVMContext *Ctx) {
  // this closure has exclusive access to Ctx.
});

The new API enforces correct locking, whereas the old APIs relied on manual
locking (which almost no in-tree code preformed, relying instead on incidental
exclusive access to the ThreadSafeContext).
---
 clang/lib/Interpreter/Interpreter.cpp | 13 ++--
 .../LLJITWithThinLTOSummaries.cpp |  4 +-
 .../OrcV2CBindingsBasicUsage.c| 10 +--
 .../OrcV2CBindingsDumpObjects.c   |  5 +-
 .../OrcV2CBindingsIRTransforms.c  |  4 +-
 .../OrcV2CBindingsLazy/OrcV2CBindingsLazy.c   | 10 ++-
 .../OrcV2CBindingsMCJITLikeMemoryManager.c| 11 +--
 .../OrcV2CBindingsRemovableCode.c | 11 +--
 .../OrcV2CBindingsVeryLazy.c  | 10 +--
 llvm/include/llvm-c/Orc.h | 26 +--
 .../ExecutionEngine/Orc/ThreadSafeModule.h| 72 +++---
 .../ExecutionEngine/Orc/OrcV2CBindings.cpp|  6 +-
 llvm/lib/ExecutionEngine/Orc/Speculation.cpp  |  2 -
 .../ExecutionEngine/Orc/ThreadSafeModule.cpp  |  8 +-
 llvm/tools/lli/lli.cpp|  3 +-
 .../Orc/RTDyldObjectLinkingLayerTest.cpp  | 42 +--
 .../Orc/ReOptimizeLayerTest.cpp   |  4 +-
 .../Orc/ThreadSafeModuleTest.cpp  | 74 ---
 18 files changed, 151 insertions(+), 164 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 2f110659d19a4..98fc0a5e383a3 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -373,8 +373,11 @@ Interpreter::Interpreter(std::unique_ptr 
Instance,
   auto LLVMCtx = std::make_unique();
   TSCtx = std::make_unique(std::move(LLVMCtx));
 
-  Act = std::make_unique(*CI, *TSCtx->getContext(), ErrOut,
-*this, std::move(Consumer));
+  Act = TSCtx->withContextDo([&](llvm::LLVMContext *Ctx) {
+return std::make_unique(*CI, *Ctx, ErrOut, *this,
+   std::move(Consumer));
+  });
+
   if (ErrOut)
 return;
   CI->ExecuteAction(*Act);
@@ -495,10 +498,10 @@ 
Interpreter::createWithCUDA(std::unique_ptr CI,
   std::unique_ptr Interp = std::move(*InterpOrErr);
 
   llvm::Error Err = llvm::Error::success();
-  llvm::LLVMContext &LLVMCtx = *Interp->TSCtx->getContext();
 
-  auto DeviceAct =
-  std::make_unique(*DCI, LLVMCtx, Err, *Interp);
+  auto DeviceAct = Interp->TSCtx->withContextDo([&](llvm::LLVMContext *Ctx) {
+return std::make_unique(*DCI, *Ctx, Err, *Interp);
+  });
 
   if (Err)
 return std::move(Err);
diff --git 
a/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
 
b/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
index c55aa73d50277..84f17871c03e4 100644
--- 
a/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
+++ 
b/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
@@ -169,7 +169,9 @@ Expected loadModule(StringRef Path,
 
   MemoryBufferRef BitcodeBufferRef = (**BitcodeBuffer).getMemBufferRef();
   Expected> M =
-  parseBitcodeFile(BitcodeBufferRef, *TSCtx.getContext());
+  TSCtx.withContextDo([&](LLVMContext *Ctx) {
+return parseBitcodeFile(BitcodeBufferRef, *Ctx);
+  });
   if (!M)
 return M.takeError();
 
diff --git 
a/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicUsage.c
 
b/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicUsage.c
index 286fa8baac4f8..b95462f340f2f 100644
--- 
a/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicU

[clang] [llvm] [ORC] Replace ThreadSafeContext::getContext with withContextDo. (PR #146819)

2025-07-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Lang Hames (lhames)


Changes

This removes ThreadSafeContext::Lock, ThreadSafeContext::getLock, and 
ThreadSafeContext::getContext, and replaces them with a 
ThreadSafeContext::withContextDo method (and const override).

The new method can be used to access an existing ThreadSafeContext-wrapped 
LLVMContext in a safe way:

ThreadSafeContext TSCtx = ... ;
TSCtx.withContextDo([](LLVMContext *Ctx) {
  // this closure has exclusive access to Ctx.
});

The new API enforces correct locking, whereas the old APIs relied on manual 
locking (which almost no in-tree code preformed, relying instead on incidental 
exclusive access to the ThreadSafeContext).

---

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


18 Files Affected:

- (modified) clang/lib/Interpreter/Interpreter.cpp (+8-5) 
- (modified) 
llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
 (+3-1) 
- (modified) 
llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicUsage.c 
(+5-5) 
- (modified) 
llvm/examples/OrcV2Examples/OrcV2CBindingsDumpObjects/OrcV2CBindingsDumpObjects.c
 (+3-2) 
- (modified) 
llvm/examples/OrcV2Examples/OrcV2CBindingsIRTransforms/OrcV2CBindingsIRTransforms.c
 (+2-2) 
- (modified) 
llvm/examples/OrcV2Examples/OrcV2CBindingsLazy/OrcV2CBindingsLazy.c (+6-4) 
- (modified) 
llvm/examples/OrcV2Examples/OrcV2CBindingsMCJITLikeMemoryManager/OrcV2CBindingsMCJITLikeMemoryManager.c
 (+6-5) 
- (modified) 
llvm/examples/OrcV2Examples/OrcV2CBindingsRemovableCode/OrcV2CBindingsRemovableCode.c
 (+6-5) 
- (modified) 
llvm/examples/OrcV2Examples/OrcV2CBindingsVeryLazy/OrcV2CBindingsVeryLazy.c 
(+5-5) 
- (modified) llvm/include/llvm-c/Orc.h (+19-7) 
- (modified) llvm/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h (+28-44) 
- (modified) llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp (+3-3) 
- (modified) llvm/lib/ExecutionEngine/Orc/Speculation.cpp (-2) 
- (modified) llvm/lib/ExecutionEngine/Orc/ThreadSafeModule.cpp (+5-3) 
- (modified) llvm/tools/lli/lli.cpp (+2-1) 
- (modified) 
llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp (+17-25) 
- (modified) llvm/unittests/ExecutionEngine/Orc/ReOptimizeLayerTest.cpp (+2-2) 
- (modified) llvm/unittests/ExecutionEngine/Orc/ThreadSafeModuleTest.cpp 
(+31-43) 


``diff
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 2f110659d19a4..98fc0a5e383a3 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -373,8 +373,11 @@ Interpreter::Interpreter(std::unique_ptr 
Instance,
   auto LLVMCtx = std::make_unique();
   TSCtx = std::make_unique(std::move(LLVMCtx));
 
-  Act = std::make_unique(*CI, *TSCtx->getContext(), ErrOut,
-*this, std::move(Consumer));
+  Act = TSCtx->withContextDo([&](llvm::LLVMContext *Ctx) {
+return std::make_unique(*CI, *Ctx, ErrOut, *this,
+   std::move(Consumer));
+  });
+
   if (ErrOut)
 return;
   CI->ExecuteAction(*Act);
@@ -495,10 +498,10 @@ 
Interpreter::createWithCUDA(std::unique_ptr CI,
   std::unique_ptr Interp = std::move(*InterpOrErr);
 
   llvm::Error Err = llvm::Error::success();
-  llvm::LLVMContext &LLVMCtx = *Interp->TSCtx->getContext();
 
-  auto DeviceAct =
-  std::make_unique(*DCI, LLVMCtx, Err, *Interp);
+  auto DeviceAct = Interp->TSCtx->withContextDo([&](llvm::LLVMContext *Ctx) {
+return std::make_unique(*DCI, *Ctx, Err, *Interp);
+  });
 
   if (Err)
 return std::move(Err);
diff --git 
a/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
 
b/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
index c55aa73d50277..84f17871c03e4 100644
--- 
a/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
+++ 
b/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
@@ -169,7 +169,9 @@ Expected loadModule(StringRef Path,
 
   MemoryBufferRef BitcodeBufferRef = (**BitcodeBuffer).getMemBufferRef();
   Expected> M =
-  parseBitcodeFile(BitcodeBufferRef, *TSCtx.getContext());
+  TSCtx.withContextDo([&](LLVMContext *Ctx) {
+return parseBitcodeFile(BitcodeBufferRef, *Ctx);
+  });
   if (!M)
 return M.takeError();
 
diff --git 
a/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicUsage.c
 
b/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicUsage.c
index 286fa8baac4f8..b95462f340f2f 100644
--- 
a/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicUsage.c
+++ 
b/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicUsage.c
@@ -22,11 +22,8 @@ int handleError(LLVMErrorRef Err) {
 }
 
 LLVMOrcThreadSafeModuleRef createDemoModule(void) {
-  // Create a new ThreadSafeConte

[clang] [OpenMP-5.2] deprecate delimited form of 'declare target' (PR #145854)

2025-07-02 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/145854

>From 15935b92827c26a7697084201980f23305f3b348 Mon Sep 17 00:00:00 2001
From: urvi-rav 
Date: Thu, 26 Jun 2025 03:19:50 -0500
Subject: [PATCH 1/2] deprecate delimited form of 'declare target'

---
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 clang/lib/Parse/ParseOpenMP.cpp   |  2 ++
 .../OpenMP/Inputs/declare_target_include.h|  2 +-
 .../test/OpenMP/declare_target_ast_print.cpp  | 28 +--
 clang/test/OpenMP/declare_target_messages.cpp | 24 
 clang/test/OpenMP/target_ast_print.cpp|  2 +-
 6 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6c30da376dafb..3b55980f57c03 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1571,6 +1571,9 @@ def err_omp_declare_target_multiple : Error<
   "%0 appears multiple times in clauses on the same declare target directive">;
 def err_omp_declare_target_indirect_device_type: Error<
   "only 'device_type(any)' clause is allowed with indirect clause">;
+def warn_omp_deprecated_declare_target_delimited_form :
+  Warning<"the delimited form of '#pragma omp declare target' without clauses 
is deprecated; use '#pragma omp begin declare target' instead">,
+  InGroup;
 def err_omp_expected_clause: Error<
   "expected at least one clause on '#pragma omp %0' directive">;
 def err_omp_mapper_illegal_identifier : Error<
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index f694ae1d0d112..d7efc0bb8bc90 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2309,6 +2309,8 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
 SourceLocation DTLoc = ConsumeAnyToken();
 bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end);
 SemaOpenMP::DeclareTargetContextInfo DTCI(DKind, DTLoc);
+if (DKind == OMPD_declare_target && !HasClauses && getLangOpts().OpenMP >= 
52)
+ Diag(DTLoc, diag::warn_omp_deprecated_declare_target_delimited_form);
 if (HasClauses)
   ParseOMPDeclareTargetClauses(DTCI);
 bool HasImplicitMappings = DKind == OMPD_begin_declare_target ||
diff --git a/clang/test/OpenMP/Inputs/declare_target_include.h 
b/clang/test/OpenMP/Inputs/declare_target_include.h
index b74cd00819db3..6a6a01ab81526 100644
--- a/clang/test/OpenMP/Inputs/declare_target_include.h
+++ b/clang/test/OpenMP/Inputs/declare_target_include.h
@@ -1,3 +1,3 @@
-#pragma omp declare target
+#pragma omp begin declare target
   void zyx();
 #pragma omp end declare target
diff --git a/clang/test/OpenMP/declare_target_ast_print.cpp 
b/clang/test/OpenMP/declare_target_ast_print.cpp
index 27d7a9fe21e52..68f73d5433595 100644
--- a/clang/test/OpenMP/declare_target_ast_print.cpp
+++ b/clang/test/OpenMP/declare_target_ast_print.cpp
@@ -133,7 +133,7 @@ int out_decl_target = 0;
 // CHECK: void lambda()
 // CHECK: #pragma omp end declare target{{$}}
 
-#pragma omp declare target
+#pragma omp begin declare target
 void lambda () {
 #ifdef __cpp_lambdas
   (void)[&] { ++out_decl_target; };
@@ -144,7 +144,7 @@ void lambda () {
 };
 #pragma omp end declare target
 
-#pragma omp declare target
+#pragma omp begin declare target
 // CHECK: #pragma omp declare target{{$}}
 void foo() {}
 // CHECK-NEXT: void foo()
@@ -152,7 +152,7 @@ void foo() {}
 // CHECK: #pragma omp end declare target{{$}}
 
 extern "C" {
-#pragma omp declare target
+#pragma omp begin declare target
 // CHECK: #pragma omp declare target
 void foo_c() {}
 // CHECK-NEXT: void foo_c()
@@ -161,7 +161,7 @@ void foo_c() {}
 }
 
 extern "C++" {
-#pragma omp declare target
+#pragma omp begin declare target
 // CHECK: #pragma omp declare target
 void foo_cpp() {}
 // CHECK-NEXT: void foo_cpp()
@@ -169,7 +169,7 @@ void foo_cpp() {}
 // CHECK: #pragma omp end declare target
 }
 
-#pragma omp declare target
+#pragma omp begin declare target
 template 
 struct C {
 // CHECK: template  struct C {
@@ -262,7 +262,7 @@ int c1, c2, c3;
 // CHECK: #pragma omp end declare target{{$}}
 
 struct SSSt {
-#pragma omp declare target
+#pragma omp begin declare target
   static int a;
   int b;
 #pragma omp end declare target
@@ -276,7 +276,7 @@ struct SSSt {
 
 template 
 struct SSSTt {
-#pragma omp declare target
+#pragma omp begin declare target
   static T a;
   int b;
 #pragma omp end declare target
@@ -288,7 +288,7 @@ struct SSSTt {
 // CHECK: #pragma omp end declare target
 // CHECK: int b;
 
-#pragma omp declare target
+#pragma omp begin declare target
 template 
 T baz() { return T(); }
 #pragma omp end declare target
@@ -310,7 +310,7 @@ int baz() { return 1; }
 // CHECK: }
 // CHECK: #pragma omp end declare target
 
-#pragma omp declare target
+#pragma omp begin declare target
   #include "declare_target_include.h"
   vo

[clang] [clang-tools-extra] [clang][modules] Serialize `CodeGenOptions` (PR #146422)

2025-07-02 Thread Jan Svoboda via cfe-commits

jansvoboda11 wrote:

> > I'm not suggesting to treat CodeGenOptions as incompatible by default.
> 
> I think the naming might be adding to the confusion here. We now have 
> `COMPATIBLE_..._CODEGENOPT`, but it's the "compatible" ones that are 
> impacting the AST and not being cleared in `resetNonModularOptions`. We have 
> no non-compatible but affecting options to compare to. I think the old name 
> was easier to understand.

That's a good point. Would you have a different opinion if I told you that the 
next PR in my queue re-introduces `AFFECTING_*_CODEGENOPT` to represent the 
affecting `ENUM_LANGOPT(ExceptionHandling, ...`? Then we'd have:
* `LANGOPT` == `AFFECTING_CODEGENOPT`
* `COMPATIBLE_LANGOPT` == `COMPATIBLE_CODEGENOPT`
* `BENIGN_LANGOPT` == `CODEGENOPT`

This makes `COMPATIBLE_` have the same semantic in both, with defaults being 
different. I'm fine with the defaults being different, since in my mind, 
language options typically do affect the AST, while codegen options typically 
do not.)

(FWIW I'm, working on simplifying the hierarchy of `LANGOPT` macros so that the 
"effect on AST" is an explicit argument to the X macro. If we apply the same 
concept on `CODEGENOPT`, I think that gets us into a reasonable place where the 
naming is consistent between both and everything is explicit. 
https://github.com/jansvoboda11/llvm-project/commit/3789122f0475cf4217e1fe1028b9079ca4d4200b)

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


[clang] [CIR] Upstream SubstNonTypeTemplateParmExpr support for ComplexType (PR #146755)

2025-07-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)


Changes

Upstream SubstNonTypeTemplateParmExpr support for ComplexType

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

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


2 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp (+7) 
- (modified) clang/test/CIR/CodeGen/complex.cpp (+23-4) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
index 3dc47dd205244..c5679fcaad0a7 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
@@ -50,6 +50,8 @@ class ComplexExprEmitter : public 
StmtVisitor {
   mlir::Value VisitInitListExpr(const InitListExpr *e);
   mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *il);
   mlir::Value VisitParenExpr(ParenExpr *e);
+  mlir::Value
+  VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *e);
 };
 } // namespace
 
@@ -231,6 +233,11 @@ mlir::Value ComplexExprEmitter::VisitParenExpr(ParenExpr 
*e) {
   return Visit(e->getSubExpr());
 }
 
+mlir::Value ComplexExprEmitter::VisitSubstNonTypeTemplateParmExpr(
+SubstNonTypeTemplateParmExpr *e) {
+  return Visit(e->getReplacement());
+}
+
 LValue CIRGenFunction::emitComplexAssignmentLValue(const BinaryOperator *e) {
   assert(e->getOpcode() == BO_Assign && "Expected assign op");
 
diff --git a/clang/test/CIR/CodeGen/complex.cpp 
b/clang/test/CIR/CodeGen/complex.cpp
index 78d7a2024490b..8528292c60fef 100644
--- a/clang/test/CIR/CodeGen/complex.cpp
+++ b/clang/test/CIR/CodeGen/complex.cpp
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value 
-fclangir -emit-cir %s -o %t.cir
-// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value 
-fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu 
-Wno-unused-value -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck  --input-file=%t.cir %s -check-prefix=CIR
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu 
-Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
 // RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value 
-emit-llvm %s -o %t.ll
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu 
-Wno-unused-value -emit-llvm %s -o %t.ll
 // RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
 
 int _Complex ci;
@@ -607,3 +607,22 @@ void foo24() {
 // OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, 
ptr %[[RESULT]], i32 0, i32 1
 // OGCG: store i32 %[[ELEM_REAL]], ptr %[[RESULT_REAL_PTR]], align 4
 // OGCG: store i32 %[[ELEM_IMAG]], ptr %[[RESULT_IMAG_PTR]], align 4
+
+template  void template_foo() { double _Complex C = N; }
+
+void foo25() {
+  template_foo<__builtin_complex(1.0, 2.0)>();
+}
+
+// CIR: %[[INIT:.*]] = cir.alloca !cir.complex, 
!cir.ptr>, ["C", init]
+// CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.fp<1.00e+00> : 
!cir.double, #cir.fp<2.00e+00> : !cir.double> : !cir.complex
+// CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex, 
!cir.ptr>
+
+// LLVM: %[[INIT:.*]] = alloca { double, double }, i64 1, align 8
+// LLVM: store { double, double } { double 1.00e+00, double 2.00e+00 
}, ptr %[[INIT]], align 8
+
+// OGCG: %[[INIT:.*]] = alloca { double, double }, align 8
+// OGCG: %[[INIT_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double 
}, ptr %[[INIT]], i32 0, i32 0
+// OGCG: %[[INIT_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double 
}, ptr %[[INIT]], i32 0, i32 1
+// OGCG: store double 1.00e+00, ptr %[[INIT_REAL_PTR]], align 8
+// OGCG: store double 2.00e+00, ptr %[[INIT_IMAG_PTR]], align 8

``




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


[clang] [CIR] Upstream UnaryDeref support for ComplexType (PR #146757)

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

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

Upstream UnaryDeref support for ComplexType

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

>From 235488566fe6a12e2da2310337ae682b97ee359a Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Wed, 2 Jul 2025 20:48:36 +0200
Subject: [PATCH] [CIR] Upstream UnaryDeref support for ComplexType

---
 clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp |  5 
 clang/test/CIR/CodeGen/complex.cpp  | 28 +
 2 files changed, 33 insertions(+)

diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
index 3dc47dd205244..3220d849f04c5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
@@ -50,6 +50,7 @@ class ComplexExprEmitter : public 
StmtVisitor {
   mlir::Value VisitInitListExpr(const InitListExpr *e);
   mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *il);
   mlir::Value VisitParenExpr(ParenExpr *e);
+  mlir::Value VisitUnaryDeref(const Expr *e);
 };
 } // namespace
 
@@ -231,6 +232,10 @@ mlir::Value ComplexExprEmitter::VisitParenExpr(ParenExpr 
*e) {
   return Visit(e->getSubExpr());
 }
 
+mlir::Value ComplexExprEmitter::VisitUnaryDeref(const Expr *e) {
+  return emitLoadOfLValue(e);
+}
+
 LValue CIRGenFunction::emitComplexAssignmentLValue(const BinaryOperator *e) {
   assert(e->getOpcode() == BO_Assign && "Expected assign op");
 
diff --git a/clang/test/CIR/CodeGen/complex.cpp 
b/clang/test/CIR/CodeGen/complex.cpp
index 78d7a2024490b..530c6292351ce 100644
--- a/clang/test/CIR/CodeGen/complex.cpp
+++ b/clang/test/CIR/CodeGen/complex.cpp
@@ -607,3 +607,31 @@ void foo24() {
 // OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, 
ptr %[[RESULT]], i32 0, i32 1
 // OGCG: store i32 %[[ELEM_REAL]], ptr %[[RESULT_REAL_PTR]], align 4
 // OGCG: store i32 %[[ELEM_IMAG]], ptr %[[RESULT_IMAG_PTR]], align 4
+
+void foo26(int _Complex* a) {
+  int _Complex b = *a;
+}
+
+// CIR: %[[COMPLEX_A_PTR:.*]] = cir.alloca !cir.ptr>, 
!cir.ptr>>, ["a", init]
+// CIR: %[[COMPLEX_B:.*]] = cir.alloca !cir.complex, 
!cir.ptr>, ["b", init]
+// CIR: %[[COMPLEX_A:.*]] = cir.load deref {{.*}} %[[COMPLEX_A_PTR]] : 
!cir.ptr>>, !cir.ptr>
+// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX_A]] : 
!cir.ptr>, !cir.complex
+// CIR: cir.store{{.*}} %[[TMP]], %[[COMPLEX_B]] : !cir.complex, 
!cir.ptr>
+
+// LLVM: %[[COMPLEX_A_PTR:.*]] = alloca ptr, i64 1, align 8
+// LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
+// LLVM: %[[COMPLEX_A:.*]] = load ptr, ptr %[[COMPLEX_A_PTR]], align 8
+// LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[COMPLEX_A]], align 4
+// LLVM: store { i32, i32 } %[[TMP]], ptr %[[COMPLEX_B]], align 4
+
+// OGCG: %[[COMPLEX_A_PTR:.*]] = alloca ptr, align 8
+// OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
+// OGCG: %[[COMPLEX_A:.*]] = load ptr, ptr %[[COMPLEX_A_PTR]], align 8
+// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[COMPLEX_A]], i32 0, i32 0
+// OGCG: %[[A_REAL:.*]] = load i32, ptr %[[A_REAL_PTR]], align 4
+// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[COMPLEX_A]], i32 0, i32 1
+// OGCG: %[[A_IMAG:.*]] = load i32, ptr %[[A_IMAG_PTR]], align 4
+// OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[COMPLEX_B]], i32 0, i32 0
+// OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[COMPLEX_B]], i32 0, i32 1
+// OGCG: store i32 %[[A_REAL]], ptr %[[B_REAL_PTR]], align 4
+// OGCG: store i32 %[[A_IMAG]], ptr %[[B_IMAG_PTR]], align 4

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


[clang] [CIR] Upstream UnaryDeref support for ComplexType (PR #146757)

2025-07-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Amr Hesham (AmrDeveloper)


Changes

Upstream UnaryDeref support for ComplexType

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

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


2 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp (+5) 
- (modified) clang/test/CIR/CodeGen/complex.cpp (+28) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
index 3dc47dd205244..3220d849f04c5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
@@ -50,6 +50,7 @@ class ComplexExprEmitter : public 
StmtVisitor {
   mlir::Value VisitInitListExpr(const InitListExpr *e);
   mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *il);
   mlir::Value VisitParenExpr(ParenExpr *e);
+  mlir::Value VisitUnaryDeref(const Expr *e);
 };
 } // namespace
 
@@ -231,6 +232,10 @@ mlir::Value ComplexExprEmitter::VisitParenExpr(ParenExpr 
*e) {
   return Visit(e->getSubExpr());
 }
 
+mlir::Value ComplexExprEmitter::VisitUnaryDeref(const Expr *e) {
+  return emitLoadOfLValue(e);
+}
+
 LValue CIRGenFunction::emitComplexAssignmentLValue(const BinaryOperator *e) {
   assert(e->getOpcode() == BO_Assign && "Expected assign op");
 
diff --git a/clang/test/CIR/CodeGen/complex.cpp 
b/clang/test/CIR/CodeGen/complex.cpp
index 78d7a2024490b..530c6292351ce 100644
--- a/clang/test/CIR/CodeGen/complex.cpp
+++ b/clang/test/CIR/CodeGen/complex.cpp
@@ -607,3 +607,31 @@ void foo24() {
 // OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, 
ptr %[[RESULT]], i32 0, i32 1
 // OGCG: store i32 %[[ELEM_REAL]], ptr %[[RESULT_REAL_PTR]], align 4
 // OGCG: store i32 %[[ELEM_IMAG]], ptr %[[RESULT_IMAG_PTR]], align 4
+
+void foo26(int _Complex* a) {
+  int _Complex b = *a;
+}
+
+// CIR: %[[COMPLEX_A_PTR:.*]] = cir.alloca !cir.ptr>, 
!cir.ptr>>, ["a", init]
+// CIR: %[[COMPLEX_B:.*]] = cir.alloca !cir.complex, 
!cir.ptr>, ["b", init]
+// CIR: %[[COMPLEX_A:.*]] = cir.load deref {{.*}} %[[COMPLEX_A_PTR]] : 
!cir.ptr>>, !cir.ptr>
+// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX_A]] : 
!cir.ptr>, !cir.complex
+// CIR: cir.store{{.*}} %[[TMP]], %[[COMPLEX_B]] : !cir.complex, 
!cir.ptr>
+
+// LLVM: %[[COMPLEX_A_PTR:.*]] = alloca ptr, i64 1, align 8
+// LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
+// LLVM: %[[COMPLEX_A:.*]] = load ptr, ptr %[[COMPLEX_A_PTR]], align 8
+// LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[COMPLEX_A]], align 4
+// LLVM: store { i32, i32 } %[[TMP]], ptr %[[COMPLEX_B]], align 4
+
+// OGCG: %[[COMPLEX_A_PTR:.*]] = alloca ptr, align 8
+// OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
+// OGCG: %[[COMPLEX_A:.*]] = load ptr, ptr %[[COMPLEX_A_PTR]], align 8
+// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[COMPLEX_A]], i32 0, i32 0
+// OGCG: %[[A_REAL:.*]] = load i32, ptr %[[A_REAL_PTR]], align 4
+// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[COMPLEX_A]], i32 0, i32 1
+// OGCG: %[[A_IMAG:.*]] = load i32, ptr %[[A_IMAG_PTR]], align 4
+// OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[COMPLEX_B]], i32 0, i32 0
+// OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[COMPLEX_B]], i32 0, i32 1
+// OGCG: store i32 %[[A_REAL]], ptr %[[B_REAL_PTR]], align 4
+// OGCG: store i32 %[[A_IMAG]], ptr %[[B_IMAG_PTR]], align 4

``




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


[clang] [CIR] Upstream UnaryDeref support for ComplexType (PR #146757)

2025-07-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)


Changes

Upstream UnaryDeref support for ComplexType

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

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


2 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp (+5) 
- (modified) clang/test/CIR/CodeGen/complex.cpp (+28) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
index 3dc47dd205244..3220d849f04c5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
@@ -50,6 +50,7 @@ class ComplexExprEmitter : public 
StmtVisitor {
   mlir::Value VisitInitListExpr(const InitListExpr *e);
   mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *il);
   mlir::Value VisitParenExpr(ParenExpr *e);
+  mlir::Value VisitUnaryDeref(const Expr *e);
 };
 } // namespace
 
@@ -231,6 +232,10 @@ mlir::Value ComplexExprEmitter::VisitParenExpr(ParenExpr 
*e) {
   return Visit(e->getSubExpr());
 }
 
+mlir::Value ComplexExprEmitter::VisitUnaryDeref(const Expr *e) {
+  return emitLoadOfLValue(e);
+}
+
 LValue CIRGenFunction::emitComplexAssignmentLValue(const BinaryOperator *e) {
   assert(e->getOpcode() == BO_Assign && "Expected assign op");
 
diff --git a/clang/test/CIR/CodeGen/complex.cpp 
b/clang/test/CIR/CodeGen/complex.cpp
index 78d7a2024490b..530c6292351ce 100644
--- a/clang/test/CIR/CodeGen/complex.cpp
+++ b/clang/test/CIR/CodeGen/complex.cpp
@@ -607,3 +607,31 @@ void foo24() {
 // OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, 
ptr %[[RESULT]], i32 0, i32 1
 // OGCG: store i32 %[[ELEM_REAL]], ptr %[[RESULT_REAL_PTR]], align 4
 // OGCG: store i32 %[[ELEM_IMAG]], ptr %[[RESULT_IMAG_PTR]], align 4
+
+void foo26(int _Complex* a) {
+  int _Complex b = *a;
+}
+
+// CIR: %[[COMPLEX_A_PTR:.*]] = cir.alloca !cir.ptr>, 
!cir.ptr>>, ["a", init]
+// CIR: %[[COMPLEX_B:.*]] = cir.alloca !cir.complex, 
!cir.ptr>, ["b", init]
+// CIR: %[[COMPLEX_A:.*]] = cir.load deref {{.*}} %[[COMPLEX_A_PTR]] : 
!cir.ptr>>, !cir.ptr>
+// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX_A]] : 
!cir.ptr>, !cir.complex
+// CIR: cir.store{{.*}} %[[TMP]], %[[COMPLEX_B]] : !cir.complex, 
!cir.ptr>
+
+// LLVM: %[[COMPLEX_A_PTR:.*]] = alloca ptr, i64 1, align 8
+// LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
+// LLVM: %[[COMPLEX_A:.*]] = load ptr, ptr %[[COMPLEX_A_PTR]], align 8
+// LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[COMPLEX_A]], align 4
+// LLVM: store { i32, i32 } %[[TMP]], ptr %[[COMPLEX_B]], align 4
+
+// OGCG: %[[COMPLEX_A_PTR:.*]] = alloca ptr, align 8
+// OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
+// OGCG: %[[COMPLEX_A:.*]] = load ptr, ptr %[[COMPLEX_A_PTR]], align 8
+// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[COMPLEX_A]], i32 0, i32 0
+// OGCG: %[[A_REAL:.*]] = load i32, ptr %[[A_REAL_PTR]], align 4
+// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[COMPLEX_A]], i32 0, i32 1
+// OGCG: %[[A_IMAG:.*]] = load i32, ptr %[[A_IMAG_PTR]], align 4
+// OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[COMPLEX_B]], i32 0, i32 0
+// OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[COMPLEX_B]], i32 0, i32 1
+// OGCG: store i32 %[[A_REAL]], ptr %[[B_REAL_PTR]], align 4
+// OGCG: store i32 %[[A_IMAG]], ptr %[[B_IMAG_PTR]], align 4

``




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


[clang] [llvm] [NFC][HLSL][DirectX] Let `HLSLRootSignature` reuse the `dxbc` defined enums (PR #145986)

2025-07-02 Thread Justin Bogner via cfe-commits


@@ -127,6 +127,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
 }
 
 TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
+  using FlagT = llvm::dxbc::DescriptorRangeFlags;

bogner wrote:

I wouldn't rename this to `FlagT`, but instead just introduce the 
`DescriptorRangeFlags` name to the scope. That is:
```suggestion
  using llvm::dxbc::DescriptorRangeFlags;
```

Then we can use `DescriptorRangeFlags::DataStaticWhileSetAtExecute` and the 
like without explicitly writing out the `llvm::dxbc::` namespace every time, 
which improves readability and in this case actually simplifies the diff quite 
a bit.

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


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

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

AlexVlx wrote:

> I think Eli is suggesting something like the rule for 
> [@available](https://clang.llvm.org/docs/LanguageExtensions.html#objective-c-available):
> 
> * If a builtin is unconditionally available, you can always use it without 
> any diagnostics.
> * If a builtin is only available on specific subtargets, you can only use it 
> in a block that's guarded by an `if (some_intrinsic(...))` condition that 
> will only pass if you're running on one of those subtargets.
> 
> So it's not that adding a check for the builtin will suddenly cause 
> un-checked calls to it to fail, it's that you have to have such a check to 
> use it in the first place, which makes sense because it's not always 
> available on the target.
> 

This is interesting, and I had / have looked at `@available` (albeit I am far 
from being a scholar on the topic). It makes logical sense, but I expect users 
will simply ignore it since it is very restrictive if we go with **you have to 
have a check to use a builtin**. It's not as if all builtin uses today which 
are present in user code are guarded by `__has_builtin` or by a check against 
an architecture macro. I will also note that as far as I can see 
__builtin_available, which we also provide for C & C++, at most warns 
, with the warning being opt-in. It also 
does not appear to generate any sort of special IR construct, it's just sugar 
over a call to a runtime provided interface, AFAICT. Furthermore, unlike for 
`__builtin_available`, there's no immediately apparent way to provide an useful 
warning here:

- if we're compiling for concrete we already know which builtins are available 
/ what target is present, so whether something is legal or not is fully 
determined;
- conversely, for the abstract case we are targeting a generic target which has 
all the features, so at most we could be somewhat spammy and say "be sure to 
wrap this in a `__builtin_amdgcn_is_invocable` call;
- this only covers a subset of cases, since there are also e.g. per target 
resource allocation choices, so now we have to hoist into Clang even more 
architecture details such as the size of shared memory i.e. we'd have to warn;
- this'd probably balloon into a non-trivial amount of checking (think the Sema 
footprint for `@available` is not exactly petite), we'd still at most get to 
warn, and would still have to run the IR pass, which is actually in a position 
to correctly diagnose an error state.

If the added warning is considered I can loot at adding that but I think that 
should be a separate patch / conversation since it'd mess with established 
builtin behaviour (as mentioned, one can reach for an unguarded builtin today 
without any additional diagnostics / invitation to touch `__has_builtin`, and 
there are examples where builtins that the FE believes work are actually not 
available on a target, see, for example, the math ones).

> Note that the `@available` model also includes an attribute for marking your 
> own functions as conditionally available, in which case (1) the entire body 
> of the function is considered guarded but (2) you have to guard calls to it. 
> That might be a necessary enhancement for your feature, too.

Unless I am missing something obvious, this brings us dangerously close to 
re-inventing language subsetting / restrictions, that are already present in 
single-source(-ish) offload languages. It ends up being `__device__` / 
`restrict(amp)` / `omp declare target` in slightly different clothes. I don't 
think that is a desirable effect here. At least for our use case (which is what 
these are trying to support), we need a mechanism that just works with what is 
already there, and can be directly used from C / C++, with existing C / C++ 
codebases i.e. has to work with what our library authors have, using idioms 
they are familiar with.


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


[clang] [Clang][Driver][SamplePGO] Introduce -fno_sample_profile_use_profi flag for SamplePGO (PR #145957)

2025-07-02 Thread Nilanjana Basu via cfe-commits


@@ -1,4 +1,19 @@
-/// Test if profi flat is enabled in frontend as user-facing feature.
-// RUN: %clang --target=x86_64 -c -fsample-profile-use-profi 
-fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s
+/// Ensure that profi flag is enabled by default in frontend for SamplePGO

nilanjana87 wrote:

Done

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


[clang] [clang-format] Propagate `LeadingEmptyLinesAffected` when joining lines (PR #146761)

2025-07-02 Thread Eric Li via cfe-commits


@@ -988,6 +988,8 @@ class LineJoiner {
 assert(!B.First->Previous);
 if (B.Affected)
   A.Affected = true;
+else if (B.LeadingEmptyLinesAffected && A.Last->Children.empty())

tJener wrote:

Done.

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


[clang] [clang] Speedup getFileIDLocal with a separate offset table. (PR #146604)

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

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

LGTM

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


[clang-tools-extra] [clang-tidy] add modernize-use-constexpr check (PR #146553)

2025-07-02 Thread Sean McBride via cfe-commits

seanm wrote:

I've tried another project: [opencv](https://github.com/opencv/opencv) and the 
result also fails to compile.

One case I think is because two variables are declared together. i.e.:

```
int foo, bar;
```

instead of:

```
int foo;
int bar;
```

Concretely:

```c++
const char * const borderMap[] = { "BORDER_CONSTANT", "BORDER_REPLICATE", 
"BORDER_REFLECT", "BORDER_WRAP", "BORDER_REFLECT_101" },
* const btype = borderMap[borderType & ~BORDER_ISOLATED];
```

Got changed to:

```
constexpr const char * borderMap[] = { "BORDER_CONSTANT", 
"BORDER_REPLICATE", "BORDER_REFLECT", "BORDER_WRAP", "BORDER_REFLECT_101" },
* const btype = borderMap[borderType & ~BORDER_ISOLATED];
```

which is fine for `borderMap` but not for `btype`.

Resulting in:

```
/Users/sean/external/opencv/modules/imgproc/src/filter.dispatch.cpp:757:17: 
error: constexpr variable 'btype' must be initialized by a constant expression
  757 | * const btype = borderMap[borderType & ~BORDER_ISOLATED];
  | ^   
```




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


[clang] [analyzer] Improve cache locality by using separate allocators (PR #138295)

2025-07-02 Thread via cfe-commits

tigbr wrote:

@steakhal As we have discussed in person, unfortunately, I could not reproduce 
the big improvements for the three problematic translation units.

On the bright side, however, I was able to reproduce an average improvement 
between 0.5% and 1%. This is in the ballpark that I have measured for the vim 
project originally. I could also measure a decrease in the number of LLC misses 
with perf (with and without ASLR). Here are the results of these measurements: 
[perf-LLC-miss-measurements.zip](https://github.com/user-attachments/files/21024564/perf-LLC-miss-measurements.zip)

FYI: @NagyDonat

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


[clang] [clang][analyzer] Fix the false positive ArgInitializedness warning on unnamed bit-field (PR #145066)

2025-07-02 Thread Balazs Benics via cfe-commits

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


[clang] 6504c96 - [clang][analyzer] Fix the false positive ArgInitializedness warning on unnamed bit-field (#145066)

2025-07-02 Thread via cfe-commits

Author: Tedlion
Date: 2025-07-03T08:42:10+02:00
New Revision: 6504c96b1d865c69888a2a17aa8fe479987c00f0

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

LOG: [clang][analyzer] Fix the false positive ArgInitializedness warning on 
unnamed bit-field (#145066)

For the following code in C mode: https://godbolt.org/z/3eo1MeGhe
(There is no warning in C++ mode though).
```c++
struct B {
  int i : 2;
  int : 30;  // unnamed bit-field
};

extern void consume_B(struct B);

void bitfield_B_init(void) {
  struct B b1;
  b1.i = 1; // b1 is initialized
  consume_B(b1); // FP: Passed-by-value struct argument contains uninitialized 
data (e.g., field: '') [core.CallAndMessage]
}
```

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
clang/test/Analysis/call-and-message.c
clang/test/Analysis/call-and-message.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
index 86476b32309c3..23935647a5826 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
@@ -253,6 +253,8 @@ class FindUninitializedField {
   const RecordDecl *RD = RT->getDecl()->getDefinition();
   assert(RD && "Referred record has no definition");
   for (const auto *I : RD->fields()) {
+if (I->isUnnamedBitField())
+  continue;
 const FieldRegion *FR = MrMgr.getFieldRegion(I, R);
 FieldChain.push_back(I);
 T = I->getType();

diff  --git a/clang/test/Analysis/call-and-message.c 
b/clang/test/Analysis/call-and-message.c
index b79ec8c344b6c..ade51145e2a93 100644
--- a/clang/test/Analysis/call-and-message.c
+++ b/clang/test/Analysis/call-and-message.c
@@ -1,12 +1,19 @@
 // RUN: %clang_analyze_cc1 %s -verify \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=true \
+// RUN:   -analyzer-config core.CallAndMessage:ArgInitializedness=false \
 // RUN:   -analyzer-output=plist -o %t.plist
 // RUN: cat %t.plist | FileCheck %s
 
 // RUN: %clang_analyze_cc1 %s -verify=no-pointee \
 // RUN:   -analyzer-checker=core \
-// RUN:   -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=false
+// RUN:   -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=false 
\
+// RUN:   -analyzer-config core.CallAndMessage:ArgInitializedness=false
+
+// RUN: %clang_analyze_cc1 %s -verify=arg-init \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=false 
\
+// RUN:   -analyzer-config core.CallAndMessage:ArgInitializedness=true
 
 // no-pointee-no-diagnostics
 
@@ -22,3 +29,21 @@ void pointee_uninit(void) {
 // checker, as described in the CallAndMessage comments!
 // CHECK: issue_hash_content_of_line_in_context
 // CHECK-SAME: 97a74322d64dca40aa57303842c745a1
+
+typedef struct {
+  int i  :2;
+  int:30;  // unnamed bit-field
+} B;
+
+extern void consume_B(B);
+
+void bitfield_B_init(void) {
+  B b1;
+  b1.i = 1; // b1 is initialized
+  consume_B(b1);
+}
+
+void bitfield_B_uninit(void) {
+  B b2;
+  consume_B(b2); // arg-init-warning{{Passed-by-value struct argument contains 
uninitialized data (e.g., field: 'i') [core.CallAndMessage]}}
+}

diff  --git a/clang/test/Analysis/call-and-message.cpp 
b/clang/test/Analysis/call-and-message.cpp
index 25ae23833478b..1e76973f49e13 100644
--- a/clang/test/Analysis/call-and-message.cpp
+++ b/clang/test/Analysis/call-and-message.cpp
@@ -169,4 +169,20 @@ void record_uninit() {
 // CHECK-SAME: a46bb5c1ee44d4611ffeb13f7f499605
 // CHECK: issue_hash_content_of_line_in_context
 // CHECK-SAME: e0e0d30ea5a7b2e3a71e1931fa0768a5
+
+struct B{
+  int i  :2;
+  int:30;  // unnamed bit-field
+};
+
+void bitfield_B_init(void) {
+  B b1;
+  b1.i = 1; // b1 is initialized
+  consume(b1);
+}
+
+void bitfield_B_uninit(void) {
+  B b2;
+  consume(b2); // arg-init-warning{{Passed-by-value struct argument contains 
uninitialized data (e.g., field: 'i') [core.CallAndMessage]}}
+}
 } // namespace uninit_arg



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


[clang] [clang][analyzer] Fix the false positive ArgInitializedness warning on unnamed bit-field (PR #145066)

2025-07-02 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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


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


[clang] [clang][analyzer] Fix the false positive ArgInitializedness warning on unnamed bit-field (PR #145066)

2025-07-02 Thread Balazs Benics via cfe-commits


@@ -2122,8 +2122,21 @@ SVal 
RegionStoreManager::getBindingForField(RegionBindingsConstRef B,
   if (const std::optional &V = B.getDirectBinding(R))
 return *V;
 
-  // If the containing record was initialized, try to get its constant value.
+  // UnnamedBitField is always Undefined unless using memory operation such
+  // as 'memset'.
+  // For example, for code
+  //typedef struct {
+  //  int i  :2;
+  //  int:30;  // unnamed bit-field
+  //} A;
+  //A a = {1};
+  // The bits of the unnamed bit-field in local variable a can be anything.
   const FieldDecl *FD = R->getDecl();
+  if (FD->isUnnamedBitField()) {
+  return UndefinedVal();
+  }
+
+  // If the containing record was initialized, try to get its constant value.

steakhal wrote:

>From reading this, it seems to me that `StackArgumentsSpaceRegion` is wrong, 
>as this is not an argument.
What was `R->dump()` in that case?

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


[clang] [llvm] Add __attribute__((visibility("default"))) attribute to certain symbols to stop them being hidden when linking clangInterpreter library to other libraries during Emscripten build (PR #1

2025-07-02 Thread via cfe-commits

https://github.com/mcbarton updated 
https://github.com/llvm/llvm-project/pull/146786

>From d528fe6474cf233ed024a1479ede12545e59b4c2 Mon Sep 17 00:00:00 2001
From: mcbarton <150042563+mcbar...@users.noreply.github.com>
Date: Wed, 2 Jul 2025 22:17:30 +0100
Subject: [PATCH] Add __attribute__((visibility("default"))) attribute to stop
 symbols being hidden when linking clangInterpreter library to other libraries
 during Emscripten build

Currently CppInterOp links its Emscripten shared library to the Emscripten 
static library libclangInterpreter.a . Certain symbols get hidden in 
libclangInterOp.a due to the -fvisibility-inlines-hidden flag when building an 
Emscripten build of llvm. This causes the CppInterOp to have to manually export 
these in a non Emscripten recommended way (see 
https://github.com/compiler-research/CppInterOp/blob/main/lib/CppInterOp/exports.ld
 ). This patch would allow us to avoid this method, by marking these symbols 
are visible, instead of hidden.
---
 clang/lib/AST/ASTContext.cpp  |  8 
 clang/lib/AST/Decl.cpp| 11 ++-
 clang/lib/AST/DeclBase.cpp| 15 ---
 clang/lib/AST/DeclTemplate.cpp|  5 -
 clang/lib/AST/Mangle.cpp  |  5 +++--
 clang/lib/AST/Type.cpp|  9 ++---
 clang/lib/Interpreter/Interpreter.cpp | 10 +++---
 clang/lib/Interpreter/InterpreterValuePrinter.cpp |  9 +
 clang/lib/Sema/SemaDeclCXX.cpp|  3 ++-
 llvm/include/llvm/ADT/SmallVector.h   |  2 +-
 llvm/lib/Support/APInt.cpp| 12 +++-
 llvm/lib/Support/Debug.cpp|  3 ++-
 llvm/lib/Support/Error.cpp|  6 --
 llvm/lib/Support/ErrorHandling.cpp|  5 +++--
 llvm/lib/Support/MemAlloc.cpp |  2 ++
 llvm/lib/Support/StringMap.cpp| 11 +++
 llvm/lib/Support/Valgrind.cpp | 11 ---
 llvm/lib/Support/raw_ostream.cpp  | 14 +++---
 18 files changed, 82 insertions(+), 59 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index b13bdd5642977..d79dac5558894 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3895,7 +3895,7 @@ void ASTContext::adjustExceptionSpec(
 
 /// getComplexType - Return the uniqued reference to the type for a complex
 /// number with the specified element type.
-QualType ASTContext::getComplexType(QualType T) const {
+LLVM_ABI QualType ASTContext::getComplexType(QualType T) const {
   // Unique pointers, to guarantee there is only one pointer of a particular
   // structure.
   llvm::FoldingSetNodeID ID;
@@ -4079,7 +4079,7 @@ QualType ASTContext::getBlockPointerType(QualType T) 
const {
 
 /// getLValueReferenceType - Return the uniqued reference to the type for an
 /// lvalue reference to the specified type.
-QualType
+LLVM_ABI QualType
 ASTContext::getLValueReferenceType(QualType T, bool SpelledAsLValue) const {
   assert((!T->isPlaceholderType() ||
   T->isSpecificPlaceholderType(BuiltinType::UnknownAny)) &&
@@ -5251,7 +5251,7 @@ QualType 
ASTContext::getInjectedClassNameType(CXXRecordDecl *Decl,
 
 /// getTypeDeclType - Return the unique reference to the type for the
 /// specified type declaration.
-QualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) const {
+LLVM_ABI QualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) const {
   assert(Decl && "Passed null for Decl param");
   assert(!Decl->TypeForDecl && "TypeForDecl present in slow case");
 
@@ -13125,7 +13125,7 @@ VTableContextBase *ASTContext::getVTableContext() {
   return VTContext.get();
 }
 
-MangleContext *ASTContext::createMangleContext(const TargetInfo *T) {
+LLVM_ABI MangleContext *ASTContext::createMangleContext(const TargetInfo *T) {
   if (!T)
 T = Target;
   switch (T->getCXXABI().getKind()) {
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 5cdf75d71e4d7..ac728295a7c26 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -59,6 +59,7 @@
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Triple.h"
@@ -2255,7 +2256,7 @@ bool VarDecl::isInExternCXXContext() const {
 
 VarDecl *VarDecl::getCanonicalDecl() { return getFirstDecl(); }
 
-VarDecl::DefinitionKind
+LLVM_ABI VarDecl::DefinitionKind
 VarDecl::isThisDeclarationADefinition(ASTContext &C) const {
   if (isThisDeclarationADemotedDefinition())
 return DeclarationOnly;
@@ -3763,7 +3764,7 @@ unsigned FunctionDecl::getBuiltinID(bool 
ConsiderWrapperFunctions) const {
 /// getNumParams - Return the number of parameters this function must have

[clang] [OpenMP-5.2] deprecate delimited form of 'declare target' (PR #145854)

2025-07-02 Thread Urvi Rav via cfe-commits

https://github.com/ravurvi20 updated 
https://github.com/llvm/llvm-project/pull/145854

>From 15935b92827c26a7697084201980f23305f3b348 Mon Sep 17 00:00:00 2001
From: urvi-rav 
Date: Thu, 26 Jun 2025 03:19:50 -0500
Subject: [PATCH 1/3] deprecate delimited form of 'declare target'

---
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 clang/lib/Parse/ParseOpenMP.cpp   |  2 ++
 .../OpenMP/Inputs/declare_target_include.h|  2 +-
 .../test/OpenMP/declare_target_ast_print.cpp  | 28 +--
 clang/test/OpenMP/declare_target_messages.cpp | 24 
 clang/test/OpenMP/target_ast_print.cpp|  2 +-
 6 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6c30da376dafb..3b55980f57c03 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1571,6 +1571,9 @@ def err_omp_declare_target_multiple : Error<
   "%0 appears multiple times in clauses on the same declare target directive">;
 def err_omp_declare_target_indirect_device_type: Error<
   "only 'device_type(any)' clause is allowed with indirect clause">;
+def warn_omp_deprecated_declare_target_delimited_form :
+  Warning<"the delimited form of '#pragma omp declare target' without clauses 
is deprecated; use '#pragma omp begin declare target' instead">,
+  InGroup;
 def err_omp_expected_clause: Error<
   "expected at least one clause on '#pragma omp %0' directive">;
 def err_omp_mapper_illegal_identifier : Error<
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index f694ae1d0d112..d7efc0bb8bc90 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2309,6 +2309,8 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
 SourceLocation DTLoc = ConsumeAnyToken();
 bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end);
 SemaOpenMP::DeclareTargetContextInfo DTCI(DKind, DTLoc);
+if (DKind == OMPD_declare_target && !HasClauses && getLangOpts().OpenMP >= 
52)
+ Diag(DTLoc, diag::warn_omp_deprecated_declare_target_delimited_form);
 if (HasClauses)
   ParseOMPDeclareTargetClauses(DTCI);
 bool HasImplicitMappings = DKind == OMPD_begin_declare_target ||
diff --git a/clang/test/OpenMP/Inputs/declare_target_include.h 
b/clang/test/OpenMP/Inputs/declare_target_include.h
index b74cd00819db3..6a6a01ab81526 100644
--- a/clang/test/OpenMP/Inputs/declare_target_include.h
+++ b/clang/test/OpenMP/Inputs/declare_target_include.h
@@ -1,3 +1,3 @@
-#pragma omp declare target
+#pragma omp begin declare target
   void zyx();
 #pragma omp end declare target
diff --git a/clang/test/OpenMP/declare_target_ast_print.cpp 
b/clang/test/OpenMP/declare_target_ast_print.cpp
index 27d7a9fe21e52..68f73d5433595 100644
--- a/clang/test/OpenMP/declare_target_ast_print.cpp
+++ b/clang/test/OpenMP/declare_target_ast_print.cpp
@@ -133,7 +133,7 @@ int out_decl_target = 0;
 // CHECK: void lambda()
 // CHECK: #pragma omp end declare target{{$}}
 
-#pragma omp declare target
+#pragma omp begin declare target
 void lambda () {
 #ifdef __cpp_lambdas
   (void)[&] { ++out_decl_target; };
@@ -144,7 +144,7 @@ void lambda () {
 };
 #pragma omp end declare target
 
-#pragma omp declare target
+#pragma omp begin declare target
 // CHECK: #pragma omp declare target{{$}}
 void foo() {}
 // CHECK-NEXT: void foo()
@@ -152,7 +152,7 @@ void foo() {}
 // CHECK: #pragma omp end declare target{{$}}
 
 extern "C" {
-#pragma omp declare target
+#pragma omp begin declare target
 // CHECK: #pragma omp declare target
 void foo_c() {}
 // CHECK-NEXT: void foo_c()
@@ -161,7 +161,7 @@ void foo_c() {}
 }
 
 extern "C++" {
-#pragma omp declare target
+#pragma omp begin declare target
 // CHECK: #pragma omp declare target
 void foo_cpp() {}
 // CHECK-NEXT: void foo_cpp()
@@ -169,7 +169,7 @@ void foo_cpp() {}
 // CHECK: #pragma omp end declare target
 }
 
-#pragma omp declare target
+#pragma omp begin declare target
 template 
 struct C {
 // CHECK: template  struct C {
@@ -262,7 +262,7 @@ int c1, c2, c3;
 // CHECK: #pragma omp end declare target{{$}}
 
 struct SSSt {
-#pragma omp declare target
+#pragma omp begin declare target
   static int a;
   int b;
 #pragma omp end declare target
@@ -276,7 +276,7 @@ struct SSSt {
 
 template 
 struct SSSTt {
-#pragma omp declare target
+#pragma omp begin declare target
   static T a;
   int b;
 #pragma omp end declare target
@@ -288,7 +288,7 @@ struct SSSTt {
 // CHECK: #pragma omp end declare target
 // CHECK: int b;
 
-#pragma omp declare target
+#pragma omp begin declare target
 template 
 T baz() { return T(); }
 #pragma omp end declare target
@@ -310,7 +310,7 @@ int baz() { return 1; }
 // CHECK: }
 // CHECK: #pragma omp end declare target
 
-#pragma omp declare target
+#pragma omp begin declare target
   #include "declare_target_include.h"
   vo

[clang] [llvm] [analyzer] Correct Z3 test cases, fix exposed crashes (PR #146597)

2025-07-02 Thread Donát Nagy via cfe-commits

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


[clang] [flang] [Clang] Introduce `--offload-targets` for `-fopenmp-targets` (PR #146594)

2025-07-02 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/146594

>From 8db1344221d36408663b684cd5217a112bbe26fe Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Mon, 3 Feb 2025 12:46:27 -0600
Subject: [PATCH 1/2] [Clang] Introduce '--offload-targets' for
 `-fopenmp-targets`

Summary:
This patch is mostly an NFC that renames the existing `-fopenmp-targets`
into `--offload-targets`. Doing this early to simplify a follow-up patch
that will hopefully allow this syntax to be used more generically over
the existing `--offload` syntax (which I think is mostly unmaintained
now.). Following in the well-trodden path of trying to pull language
specific offload options into generic ones, but right now this is still
just OpenMP specific.
---
 clang/include/clang/Basic/DiagnosticDriverKinds.td | 2 ++
 clang/include/clang/Driver/Options.td  | 6 +-
 clang/lib/Driver/Driver.cpp| 8 
 clang/lib/Driver/ToolChain.cpp | 2 +-
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 2 +-
 clang/lib/Frontend/CompilerInvocation.cpp  | 6 +++---
 clang/test/CodeGen/ibm128-unsupported.c| 2 +-
 clang/test/Driver/amdgpu-openmp-sanitize-options.c | 4 ++--
 clang/test/Driver/hip-options.hip  | 2 +-
 flang/lib/Frontend/CompilerInvocation.cpp  | 2 +-
 flang/test/Driver/omp-driver-offload.f90   | 6 +++---
 11 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 34b6c0d7a8acd..759ba0419bd45 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -116,6 +116,8 @@ def err_drv_cuda_host_arch : Error<
   "unsupported architecture '%0' for host compilation">;
 def err_drv_mix_cuda_hip : Error<
   "mixed CUDA and HIP compilation is not supported">;
+def err_drv_mix_offload : Error<
+  "mixed %0 and %1 offloading compilation is not supported">;
 def err_drv_bad_target_id : Error<
   "invalid target ID '%0'; format is a processor name followed by an optional "
   "colon-delimited list of features followed by an enable/disable sign (e.g., "
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9911d752966e3..f359df55e0508 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1138,6 +1138,10 @@ def fno_convergent_functions : Flag<["-"], 
"fno-convergent-functions">,
 
 // Common offloading options
 let Group = offload_Group in {
+def offload_targets_EQ : Joined<["--"], "offload-targets=">,
+  Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option, FlangOption, 
FC1Option]>,
+  HelpText<"Specify a list of target architectures to use for offloading.">;
+
 def offload_arch_EQ : Joined<["--"], "offload-arch=">,
   Visibility<[ClangOption, FlangOption]>,
   HelpText<"Specify an offloading device architecture for CUDA, HIP, or 
OpenMP. (e.g. sm_35). "
@@ -3678,7 +3682,7 @@ def fopenmp_use_tls : Flag<["-"], "fopenmp-use-tls">, 
Group,
   Flags<[NoArgumentUnused, HelpHidden]>;
 def fnoopenmp_use_tls : Flag<["-"], "fnoopenmp-use-tls">, Group,
   Flags<[NoArgumentUnused, HelpHidden]>, Visibility<[ClangOption, CC1Option]>;
-def fopenmp_targets_EQ : CommaJoined<["-"], "fopenmp-targets=">,
+def fopenmp_targets_EQ : CommaJoined<["-"], "fopenmp-targets=">, 
Alias,
   Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option, FlangOption, 
FC1Option]>,
   HelpText<"Specify comma-separated list of triples OpenMP offloading targets 
to be supported">;
 def fopenmp_relocatable_target : Flag<["-"], "fopenmp-relocatable-target">,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 775f3f029861c..930a678aa8923 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -991,7 +991,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation 
&C,
 /*SpecificToolchain=*/true);
   } else if (IsHIP && !UseLLVMOffload) {
 if (auto *OMPTargetArg =
-C.getInputArgs().getLastArg(options::OPT_fopenmp_targets_EQ)) {
+C.getInputArgs().getLastArg(options::OPT_offload_targets_EQ)) {
   Diag(clang::diag::err_drv_unsupported_opt_for_language_mode)
   << OMPTargetArg->getSpelling() << "HIP";
   return;
@@ -1025,7 +1025,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation 
&C,
   ((IsCuda || IsHIP) && UseLLVMOffload) ||
   (C.getInputArgs().hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
 options::OPT_fno_openmp, false) &&
-   (C.getInputArgs().hasArg(options::OPT_fopenmp_targets_EQ) ||
+   (C.getInputArgs().hasArg(options::OPT_offload_targets_EQ) ||
 C.getInputArgs().hasArg(options::OPT_offload_arch_EQ)));
   if (IsOpenMPOffloading) {
 // We expect that -fopenmp-targets is

[clang] [llvm] [analyzer] Correct Z3 test cases, fix exposed crashes (PR #146597)

2025-07-02 Thread Balazs Benics via cfe-commits


@@ -932,7 +932,8 @@ class Z3Statistics final : public SMTSolverStatistics {
   };
   unsigned getUnsigned(StringRef Key) const override {
 auto It = UnsignedValues.find(Key.str());
-assert(It != UnsignedValues.end());
+if (It == UnsignedValues.end())
+  return 0;

steakhal wrote:

Why did this assertion fail? I thought the "rlimit" must exist on the required 
Z3 versions.

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


[clang] [clang] Speedup getFileIDLocal with a separate offset table. (PR #146604)

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

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

1 suggestion, else LGTM.  Please make sure aaron gets a chance to look if he 
wants.

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


[clang] [clang-scan-deps] Fix "unterminated conditional directive" bug (PR #146645)

2025-07-02 Thread Naveen Seth Hanig via cfe-commits

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


[clang-tools-extra] [clang-tidy] add modernize-use-constexpr check (PR #146553)

2025-07-02 Thread via cfe-commits


@@ -0,0 +1,64 @@
+.. title:: clang-tidy - modernize-use-constexpr
+
+modernize-use-constexpr
+===
+
+Finds functions and variables that can be declared 'constexpr'.
+
+The check analyses any function and variable according to the rules defined
+for the language version that the code is compiled with.
+Changing to a newer language standard may therefore offer additional 
opportunity
+to declare a function or variable as ``constexpr``.
+Furthermore, this check can be incremental in terms of its diagnostics. For
+example, declaring a function ``constepxr`` might create new opportunities of
+marking additional variables or function ``constexpr``, which can only be found
+in subsequent runs of this check.
+
+For variables, the check will only detect variables that can be declared
+``constexpr`` if they are already ``const``.
+This is because this check would have to duplicate the expensive analysis of 
the
+:doc:`misc-const-correctness<../misc/const-correctness>` check.
+Therefore, it is recommended to have 
+:doc:`misc-const-correctness<../misc/const-correctness>` enabled
+in the Clang-Tidy config when this check is, so that all opportunities for
+``const`` and also ``constexpr`` are explored.
+
+Options
+---
+
+.. option:: ConservativeLiteralType
+
+  With this option enabled, only literal types that can be constructed at
+  compile-time are considered to supoprt ``constexpr``.
+
+  .. code-block:: c++
+
+struct NonLiteral{
+  NonLiteral();
+  ~NonLiteral();
+  int &ref;
+};
+
+  This type is a literal type, but can not be constructed at compile-time.
+  With `ConservativeLiteralType` equal to `true`, variables or funtions
+  with this type are not diagnosed to add ``constexpr``. Default is
+  `true`.
+
+.. option:: AddConstexprToMethodOfClassWithoutConstexprConstructor
+
+  While a function of a class or struct could be declared ``constexpr``, when
+  the class itself can never be constructed at compile-time, then adding
+  ``constexpr`` to a member function is superfluous. This option controls if
+  ``constexpr`` should be added anyways. Default is ``false``.

EugeneZelenko wrote:

```suggestion
  ``constexpr`` should be added anyways. Default is `false`.
```

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


[clang-tools-extra] [clang-tidy] add modernize-use-constexpr check (PR #146553)

2025-07-02 Thread via cfe-commits


@@ -0,0 +1,64 @@
+.. title:: clang-tidy - modernize-use-constexpr
+
+modernize-use-constexpr
+===
+
+Finds functions and variables that can be declared 'constexpr'.
+
+The check analyses any function and variable according to the rules defined
+for the language version that the code is compiled with.
+Changing to a newer language standard may therefore offer additional 
opportunity
+to declare a function or variable as ``constexpr``.
+Furthermore, this check can be incremental in terms of its diagnostics. For
+example, declaring a function ``constepxr`` might create new opportunities of
+marking additional variables or function ``constexpr``, which can only be found
+in subsequent runs of this check.
+
+For variables, the check will only detect variables that can be declared
+``constexpr`` if they are already ``const``.
+This is because this check would have to duplicate the expensive analysis of 
the
+:doc:`misc-const-correctness<../misc/const-correctness>` check.
+Therefore, it is recommended to have 
+:doc:`misc-const-correctness<../misc/const-correctness>` enabled
+in the Clang-Tidy config when this check is, so that all opportunities for
+``const`` and also ``constexpr`` are explored.
+
+Options
+---
+
+.. option:: ConservativeLiteralType
+
+  With this option enabled, only literal types that can be constructed at
+  compile-time are considered to supoprt ``constexpr``.
+
+  .. code-block:: c++
+
+struct NonLiteral{
+  NonLiteral();
+  ~NonLiteral();
+  int &ref;
+};
+
+  This type is a literal type, but can not be constructed at compile-time.
+  With `ConservativeLiteralType` equal to `true`, variables or funtions
+  with this type are not diagnosed to add ``constexpr``. Default is
+  `true`.
+
+.. option:: AddConstexprToMethodOfClassWithoutConstexprConstructor
+
+  While a function of a class or struct could be declared ``constexpr``, when
+  the class itself can never be constructed at compile-time, then adding
+  ``constexpr`` to a member function is superfluous. This option controls if
+  ``constexpr`` should be added anyways. Default is ``false``.
+
+.. option:: ConstexprString
+
+  The string to use to specify a variable or function as ``constexpr``, for
+  example, a macro. Default is ``constexpr``.
+
+.. option:: ConstexprString
+
+  The string to use with C++23 to specify a function-local variable as 
+  ``static constexpr``, for example, a macro. Default is ``static constexpr``

EugeneZelenko wrote:

```suggestion
  ``static constexpr``, for example, a macro. Default is `static constexpr`
```

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


[clang] [libcxx] [Clang] Diagnose forming references to nullptr (PR #143667)

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

cor3ntin wrote:

> Per [CWG2823](https://cplusplus.github.io/CWG/issues/2823.html), would it be 
> more meaningful to diagnose dereferencing null pointers?

Yes, done!

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


[clang] a9ee179 - Remove helper function and use target agnostic needConversion function (#146680)

2025-07-02 Thread via cfe-commits

Author: Abhina Sree
Date: 2025-07-02T10:02:46-04:00
New Revision: a9ee1797b716fa61f495a2400f95da4594a8ae80

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

LOG: Remove helper function and use target agnostic needConversion function 
(#146680)

This patch adds back the needed AutoConvert.h header and removes the
unneeded include guard of MVS to prevent this header from being removed
in the future

Added: 


Modified: 
clang/lib/Basic/SourceManager.cpp

Removed: 




diff  --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 82096421f8579..1b4be1414b5d4 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -24,6 +24,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/Allocator.h"
+#include "llvm/Support/AutoConvert.h"
 #include "llvm/Support/Capacity.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Endian.h"
@@ -586,17 +587,6 @@ SourceManager::getOrCreateFileID(FileEntryRef SourceFile,
  FileCharacter);
 }
 
-/// Helper function to determine if an input file requires conversion
-bool needConversion(StringRef Filename) {
-#ifdef __MVS__
-  llvm::ErrorOr NeedConversion =
-  llvm::needzOSConversion(Filename.str().c_str());
-  return NeedConversion && *NeedConversion;
-#else
-  return false;
-#endif
-}
-
 /// createFileID - Create a new FileID for the specified ContentCache and
 /// include position.  This works regardless of whether the ContentCache
 /// corresponds to a file or some other input source.
@@ -616,8 +606,9 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, 
StringRef Filename,
 return FileID::get(LoadedID);
   }
   unsigned FileSize = File.getSize();
-  bool NeedConversion = needConversion(Filename);
-  if (NeedConversion) {
+  llvm::ErrorOr NeedConversion =
+  llvm::needConversion(Filename.str().c_str());
+  if (NeedConversion && *NeedConversion) {
 // Buffer size may increase due to potential z/OS EBCDIC to UTF-8
 // conversion.
 if (std::optional Buffer =



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


[clang] [libcxx] [Clang] Diagnose forming references to nullptr (PR #143667)

2025-07-02 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [libcxx] [Clang] Diagnose forming references to nullptr (PR #143667)

2025-07-02 Thread Vlad Serebrennikov via cfe-commits


@@ -107,6 +107,8 @@ void f() {
   constexpr int p = &*a;
   // since-cxx11-error@-1 {{cannot initialize a variable of type 'const int' 
with an rvalue of type 'A *'}}
   constexpr A *p2 = &*a;
+  // since-cxx11-error@-1 {{constexpr variable 'p2' must be initialized by a 
constant expression}} \
+  // since-cxx11-note@-1 {{read of dereferenced null pointer is not allowed in 
a constant expression}}

Endilll wrote:

```suggestion
  //   since-cxx11-note@-2 {{read of dereferenced null pointer is not allowed 
in a constant expression}}
```
As a consequence, you need to remove the backslash on the previous line.

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


[clang-tools-extra] [clang-tidy] add modernize-use-constexpr check (PR #146553)

2025-07-02 Thread via cfe-commits


@@ -0,0 +1,64 @@
+.. title:: clang-tidy - modernize-use-constexpr
+
+modernize-use-constexpr
+===
+
+Finds functions and variables that can be declared 'constexpr'.
+
+The check analyses any function and variable according to the rules defined
+for the language version that the code is compiled with.
+Changing to a newer language standard may therefore offer additional 
opportunity
+to declare a function or variable as ``constexpr``.
+Furthermore, this check can be incremental in terms of its diagnostics. For
+example, declaring a function ``constepxr`` might create new opportunities of
+marking additional variables or function ``constexpr``, which can only be found
+in subsequent runs of this check.
+
+For variables, the check will only detect variables that can be declared
+``constexpr`` if they are already ``const``.
+This is because this check would have to duplicate the expensive analysis of 
the
+:doc:`misc-const-correctness<../misc/const-correctness>` check.
+Therefore, it is recommended to have 
+:doc:`misc-const-correctness<../misc/const-correctness>` enabled
+in the Clang-Tidy config when this check is, so that all opportunities for
+``const`` and also ``constexpr`` are explored.
+
+Options
+---
+
+.. option:: ConservativeLiteralType
+
+  With this option enabled, only literal types that can be constructed at
+  compile-time are considered to supoprt ``constexpr``.
+
+  .. code-block:: c++
+
+struct NonLiteral{
+  NonLiteral();
+  ~NonLiteral();
+  int &ref;
+};
+
+  This type is a literal type, but can not be constructed at compile-time.
+  With `ConservativeLiteralType` equal to `true`, variables or funtions
+  with this type are not diagnosed to add ``constexpr``. Default is
+  `true`.
+
+.. option:: AddConstexprToMethodOfClassWithoutConstexprConstructor
+
+  While a function of a class or struct could be declared ``constexpr``, when
+  the class itself can never be constructed at compile-time, then adding
+  ``constexpr`` to a member function is superfluous. This option controls if
+  ``constexpr`` should be added anyways. Default is ``false``.
+
+.. option:: ConstexprString
+
+  The string to use to specify a variable or function as ``constexpr``, for
+  example, a macro. Default is ``constexpr``.

EugeneZelenko wrote:

```suggestion
  example, a macro. Default is `constexpr`.
```

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


[clang] [CIR] Add OptInfo attribute (PR #146261)

2025-07-02 Thread Sirui Mu via cfe-commits

https://github.com/Lancern updated 
https://github.com/llvm/llvm-project/pull/146261

>From 5b93633c4f9d4fb841c107fd146e89a2d086e497 Mon Sep 17 00:00:00 2001
From: Sirui Mu 
Date: Sun, 29 Jun 2025 15:25:10 +0800
Subject: [PATCH] [CIR] Add OptInfo attribute

---
 .../include/clang/CIR/Dialect/IR/CIRAttrs.td  | 48 +++
 .../clang/CIR/Dialect/IR/CIRDialect.td|  1 +
 clang/lib/CIR/CodeGen/CIRGenModule.cpp|  6 +++
 clang/lib/CIR/Dialect/IR/CIRAttrs.cpp | 15 ++
 clang/test/CIR/CodeGen/opt-info-attr.cpp  | 22 +
 clang/test/CIR/IR/invalid-opt-info.cir| 13 +
 6 files changed, 105 insertions(+)
 create mode 100644 clang/test/CIR/CodeGen/opt-info-attr.cpp
 create mode 100644 clang/test/CIR/IR/invalid-opt-info.cir

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 9a6560519eec4..c6dd753950859 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -65,6 +65,54 @@ class CIRUnitAttr traits = []>
   let isOptional = 1;
 }
 
+//===--===//
+// OptInfoAttr
+//===--===//
+
+def CIR_OptInfoAttr : CIR_Attr<"OptInfo", "opt_info"> {
+  let summary =
+"A module-level attribute that holds the optimization information";
+  let description = [{
+The `#cir.opt_info` attribute holds optimization related information. For
+now this attribute is a module-level attribute that gets attached to the
+module operation during CIRGen.
+
+The `level` parameter gives the optimization level. It must be an integer
+between 0 and 3, inclusive. It corresponds to the `OptimizationLevel` field
+within the `clang::CodeGenOptions` structure.
+
+The `size` parameter gives the code size optimization level. It must be an
+integer between 0 and 2, inclusive. It corresponds to the `OptimizeSize`
+field within the `clang::CodeGenOptions` structure.
+
+The `level` and `size` parameters correspond to the optimization level
+command line options passed to clang driver. The table below lists the
+current correspondance relationship:
+
+| Flag | `level` | `size` |
+|--|-||
+| `-O0` or nothing | 0   | 0  |
+| `-O1`| 1   | 0  |
+| `-O2`| 2   | 0  |
+| `-O3`| 3   | 0  |
+| `-Os`| 2   | 1  |
+| `-Oz`| 2   | 2  |
+
+Examples:
+
+```mlir
+#cir.opt_info  // -O2
+```
+  }];
+
+  let parameters = (ins "unsigned":$level, "unsigned":$size);
+
+  let assemblyFormat = [{
+`<` struct(params) `>`
+  }];
+  let genVerifyDecl = 1;
+}
+
 
//===--===//
 // BoolAttr
 
//===--===//
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRDialect.td 
b/clang/include/clang/CIR/Dialect/IR/CIRDialect.td
index 52e32eedf774d..d77ed53aa93a1 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRDialect.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRDialect.td
@@ -36,6 +36,7 @@ def CIR_Dialect : Dialect {
 
   let extraClassDeclaration = [{
 static llvm::StringRef getTripleAttrName() { return "cir.triple"; }
+static llvm::StringRef getOptInfoAttrName() { return "cir.opt_info"; }
 
 void registerAttributes();
 void registerTypes();
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp 
b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 7198b231d934b..c1434ee697f4c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -104,6 +104,12 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
 
   theModule->setAttr(cir::CIRDialect::getTripleAttrName(),
  builder.getStringAttr(getTriple().str()));
+
+  if (cgo.OptimizationLevel > 0 || cgo.OptimizeSize > 0)
+theModule->setAttr(cir::CIRDialect::getOptInfoAttrName(),
+   cir::OptInfoAttr::get(&mlirContext,
+ cgo.OptimizationLevel,
+ cgo.OptimizeSize));
 }
 
 CIRGenModule::~CIRGenModule() = default;
diff --git a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp 
b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp
index 29a9a815c31a1..0f84ffa4bf131 100644
--- a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp
@@ -55,6 +55,21 @@ void CIRDialect::printAttribute(Attribute attr, 
DialectAsmPrinter &os) const {
 llvm_unreachable("unexpected CIR type kind");
 }
 
+//===--===//
+// OptInfoAttr definitions
+//===--===//
+
+Logic

[clang] [Sema] Remove an unnecessary cast (NFC) (PR #146703)

2025-07-02 Thread Tim Gymnich via cfe-commits

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


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


[clang] [Sema] Remove an unnecessary cast (NFC) (PR #146703)

2025-07-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

The only use of Receiver is to initialize RecExpr.  This patch renames
Receiver to RecExpr while removing the cast statement.


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


1 Files Affected:

- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+1-3) 


``diff
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index b5d4a94da83df..cc361726c1cde 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -8499,13 +8499,11 @@ void SemaCodeCompletion::CodeCompleteObjCClassMessage(
 }
 
 void SemaCodeCompletion::CodeCompleteObjCInstanceMessage(
-Scope *S, Expr *Receiver, ArrayRef SelIdents,
+Scope *S, Expr *RecExpr, ArrayRef SelIdents,
 bool AtArgumentExpression, ObjCInterfaceDecl *Super) {
   typedef CodeCompletionResult Result;
   ASTContext &Context = getASTContext();
 
-  Expr *RecExpr = static_cast(Receiver);
-
   // If necessary, apply function/array conversion to the receiver.
   // C99 6.7.5.3p[7,8].
   if (RecExpr) {

``




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


[clang] [CIR] Clean up IntAttr (PR #146661)

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

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


[clang] [CIR] Introduce IntTypeInterface to allow uniform integer types handling (PR #146660)

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

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


[clang-tools-extra] [clang-tidy] add modernize-use-constexpr check (PR #146553)

2025-07-02 Thread Julian Schmidt via cfe-commits

5chmidti wrote:

> Another compiler error after transformation:
> 
> It made this constexpr:
> 
> ```c++
>   PUGI_IMPL_FN constexpr bool is_nan(double value)
>   {
>   #if defined(PUGI_IMPL_MSVC_CRT_VERSION) || defined(__BORLANDC__)
>   return !!_isnan(value);
>   #elif defined(fpclassify) && defined(FP_NAN)
>   return fpclassify(value) == FP_NAN;
>   #else
>   // fallback
>   const volatile double v = value;
>   return v != v;
>   #endif
>   }
> ```
> 
> But then:
> 
> ```
> /Users/sean/external/VTK/ThirdParty/pugixml/vtkpugixml/src/pugixml.cpp:8413:30:
>  error: constexpr function never produces a constant expression 
> [-Winvalid-constexpr]
>  8413 | PUGI_IMPL_FN constexpr bool is_nan(double value)
>   | ^~
> /Users/sean/external/VTK/ThirdParty/pugixml/vtkpugixml/src/pugixml.cpp:8422:15:
>  note: read of volatile-qualified type 'const volatile double' is not allowed 
> in a constant expression
>  8422 | return v != v;
>   | ^
> ```

I'll take a look

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


[clang] [CIR] Clean up IntAttr (PR #146661)

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

https://github.com/xlauko updated 
https://github.com/llvm/llvm-project/pull/146661

>From aa2ee38d1bd5ede51b4657d59b4530b39b3f377d Mon Sep 17 00:00:00 2001
From: xlauko 
Date: Wed, 2 Jul 2025 09:50:24 +0200
Subject: [PATCH] [CIR] Clean up IntAttr

- Add common CIR_ prefix
- Simplify printing/parsing
- Make it use IntTypeInterface

This mirrors incubator changes from https://github.com/llvm/clangir/pull/1725
---
 .../CIR/Dialect/Builder/CIRBaseBuilder.h  |   2 +-
 .../include/clang/CIR/Dialect/IR/CIRAttrs.td  |  53 --
 clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp  |   6 +-
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp|  15 ++-
 clang/lib/CIR/Dialect/IR/CIRAttrs.cpp | 100 +-
 5 files changed, 101 insertions(+), 75 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index 3e052c564112e..41ac8c1c875df 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -63,7 +63,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 
   mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ,
 const llvm::APInt &val) {
-return create(loc, getAttr(typ, val));
+return create(loc, cir::IntAttr::get(typ, val));
   }
 
   cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) {
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 9a6560519eec4..a042f5cd0c19e 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -117,36 +117,67 @@ def UndefAttr : CIR_TypedAttr<"Undef", "undef"> {
 // IntegerAttr
 
//===--===//
 
-def IntAttr : CIR_Attr<"Int", "int", [TypedAttrInterface]> {
+def CIR_IntAttr : CIR_Attr<"Int", "int", [TypedAttrInterface]> {
   let summary = "An attribute containing an integer value";
   let description = [{
 An integer attribute is a literal attribute that represents an integral
 value of the specified integer type.
   }];
-  let parameters = (ins AttributeSelfTypeParameter<"">:$type,
-APIntParameter<"">:$value);
+
+  let parameters = (ins
+AttributeSelfTypeParameter<"", "cir::IntTypeInterface">:$type,
+APIntParameter<"">:$value
+  );
+
   let builders = [
 AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
 "const llvm::APInt &":$value), [{
-  return $_get(type.getContext(), type, value);
+  auto intType = mlir::cast(type);
+  return $_get(type.getContext(), intType, value);
 }]>,
 AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
 "int64_t":$value), [{
-  IntType intType = mlir::cast(type);
+  auto intType = mlir::cast(type);
   mlir::APInt apValue(intType.getWidth(), value, intType.isSigned());
   return $_get(intType.getContext(), intType, apValue);
 }]>,
   ];
+
   let extraClassDeclaration = [{
-int64_t getSInt() const { return getValue().getSExtValue(); }
-uint64_t getUInt() const { return getValue().getZExtValue(); }
-bool isNullValue() const { return getValue() == 0; }
-uint64_t getBitWidth() const {
-  return mlir::cast(getType()).getWidth();
+int64_t getSInt() const;
+uint64_t getUInt() const;
+bool isNullValue() const;
+bool isSigned() const;
+bool isUnsigned() const;
+uint64_t getBitWidth() const;
+  }];
+
+ let extraClassDefinition = [{
+int64_t $cppClass::getSInt() const {
+  return getValue().getSExtValue();
+}
+uint64_t $cppClass::getUInt() const {
+  return getValue().getZExtValue();
+}
+bool $cppClass::isNullValue() const {
+  return getValue() == 0;
+}
+bool $cppClass::isSigned() const {
+  return mlir::cast(getType()).isSigned();
+}
+bool $cppClass::isUnsigned() const {
+  return mlir::cast(getType()).isUnsigned();
+}
+uint64_t $cppClass::getBitWidth() const {
+  return mlir::cast(getType()).getWidth();
 }
   }];
+
+  let assemblyFormat = [{
+`<` custom($value, ref($type)) `>`
+  }];
+
   let genVerifyDecl = 1;
-  let hasCustomAssemblyFormat = 1;
 }
 
 
//===--===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
index e25819cdb11bf..5fc7a92cd00f9 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
@@ -684,7 +684,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const 
APValue &value,
 if (mlir::isa(ty))
   return builder.getCIRBoolAttr(value.getInt().getZExtValue());
 assert(mlir::isa(ty) && "expected integral type");
-return cgm.getBuilder().getAttr(ty

[clang] [StaticAnalyzer] Remove unnecessary casts (NFC) (PR #146706)

2025-07-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Kazu Hirata (kazutakahirata)


Changes

N is already of ExplodedNode *.


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


1 Files Affected:

- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h (+3-2) 


``diff
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
index e995151927c96..bd11e0d40cfa9 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
@@ -448,14 +448,15 @@ class ExplodedNodeSet {
 
 public:
   ExplodedNodeSet(ExplodedNode *N) {
-assert(N && !static_cast(N)->isSink());
+assert(N && !N->isSink());
 Impl.insert(N);
   }
 
   ExplodedNodeSet() = default;
 
   void Add(ExplodedNode *N) {
-if (N && !static_cast(N)->isSink()) Impl.insert(N);
+if (N && !N->isSink())
+  Impl.insert(N);
   }
 
   using iterator = ImplTy::iterator;

``




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


[clang-tools-extra] [clangd] Drop const from a return type (NFC) (PR #146707)

2025-07-02 Thread Kazu Hirata via cfe-commits

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

We don't need const on the return type.


>From 4632ba6425e7cf1793e665169acdae85e5a9b7bd Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Tue, 1 Jul 2025 20:57:50 -0700
Subject: [PATCH] [clangd] Drop const from a return type (NFC)

We don't need const on the return type.
---
 .../clangd/refactor/tweaks/ExtractVariable.cpp  | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
index 90dac3b76c648..c74250ccbe9ea 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -359,9 +359,9 @@ struct ParsedBinaryOperator {
 //+   c <- End
 //   / \
 //  a   b <- Start
-const SourceRange getBinaryOperatorRange(const SelectionTree::Node &N,
- const SourceManager &SM,
- const LangOptions &LangOpts) {
+SourceRange getBinaryOperatorRange(const SelectionTree::Node &N,
+   const SourceManager &SM,
+   const LangOptions &LangOpts) {
   // If N is not a suitable binary operator, bail out.
   ParsedBinaryOperator Op;
   if (!Op.parse(N.ignoreImplicit()) || !Op.associative() ||

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


[clang] [StaticAnalyzer] Remove unnecessary casts (NFC) (PR #146706)

2025-07-02 Thread Kazu Hirata via cfe-commits

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

N is already of ExplodedNode *.


>From 698813a9dc8d286913f302c5fc498144d2406bc1 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Tue, 1 Jul 2025 20:55:55 -0700
Subject: [PATCH] [StaticAnalyzer] Remove unnecessary casts (NFC)

N is already of ExplodedNode *.
---
 .../clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h  | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
index e995151927c96..bd11e0d40cfa9 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
@@ -448,14 +448,15 @@ class ExplodedNodeSet {
 
 public:
   ExplodedNodeSet(ExplodedNode *N) {
-assert(N && !static_cast(N)->isSink());
+assert(N && !N->isSink());
 Impl.insert(N);
   }
 
   ExplodedNodeSet() = default;
 
   void Add(ExplodedNode *N) {
-if (N && !static_cast(N)->isSink()) Impl.insert(N);
+if (N && !N->isSink())
+  Impl.insert(N);
   }
 
   using iterator = ImplTy::iterator;

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


[clang] [StaticAnalyzer] Remove unnecessary casts (NFC) (PR #146706)

2025-07-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

N is already of ExplodedNode *.


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


1 Files Affected:

- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h (+3-2) 


``diff
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
index e995151927c96..bd11e0d40cfa9 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
@@ -448,14 +448,15 @@ class ExplodedNodeSet {
 
 public:
   ExplodedNodeSet(ExplodedNode *N) {
-assert(N && !static_cast(N)->isSink());
+assert(N && !N->isSink());
 Impl.insert(N);
   }
 
   ExplodedNodeSet() = default;
 
   void Add(ExplodedNode *N) {
-if (N && !static_cast(N)->isSink()) Impl.insert(N);
+if (N && !N->isSink())
+  Impl.insert(N);
   }
 
   using iterator = ImplTy::iterator;

``




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


[clang] [CIR] Clean up IntAttr (PR #146661)

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

https://github.com/xlauko updated 
https://github.com/llvm/llvm-project/pull/146661

>From 61e0a910f9bad6f8f735d13f427b8af78adc79da Mon Sep 17 00:00:00 2001
From: xlauko 
Date: Wed, 2 Jul 2025 09:50:24 +0200
Subject: [PATCH] [CIR] Clean up IntAttr

- Add common CIR_ prefix
- Simplify printing/parsing
- Make it use IntTypeInterface

This mirrors incubator changes from https://github.com/llvm/clangir/pull/1725
---
 .../CIR/Dialect/Builder/CIRBaseBuilder.h  |   2 +-
 .../include/clang/CIR/Dialect/IR/CIRAttrs.td  |  53 --
 clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp  |   6 +-
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp|  15 ++-
 clang/lib/CIR/Dialect/IR/CIRAttrs.cpp | 100 +-
 5 files changed, 101 insertions(+), 75 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index 3e052c564112e..41ac8c1c875df 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -63,7 +63,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 
   mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ,
 const llvm::APInt &val) {
-return create(loc, getAttr(typ, val));
+return create(loc, cir::IntAttr::get(typ, val));
   }
 
   cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) {
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 9a6560519eec4..a042f5cd0c19e 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -117,36 +117,67 @@ def UndefAttr : CIR_TypedAttr<"Undef", "undef"> {
 // IntegerAttr
 
//===--===//
 
-def IntAttr : CIR_Attr<"Int", "int", [TypedAttrInterface]> {
+def CIR_IntAttr : CIR_Attr<"Int", "int", [TypedAttrInterface]> {
   let summary = "An attribute containing an integer value";
   let description = [{
 An integer attribute is a literal attribute that represents an integral
 value of the specified integer type.
   }];
-  let parameters = (ins AttributeSelfTypeParameter<"">:$type,
-APIntParameter<"">:$value);
+
+  let parameters = (ins
+AttributeSelfTypeParameter<"", "cir::IntTypeInterface">:$type,
+APIntParameter<"">:$value
+  );
+
   let builders = [
 AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
 "const llvm::APInt &":$value), [{
-  return $_get(type.getContext(), type, value);
+  auto intType = mlir::cast(type);
+  return $_get(type.getContext(), intType, value);
 }]>,
 AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
 "int64_t":$value), [{
-  IntType intType = mlir::cast(type);
+  auto intType = mlir::cast(type);
   mlir::APInt apValue(intType.getWidth(), value, intType.isSigned());
   return $_get(intType.getContext(), intType, apValue);
 }]>,
   ];
+
   let extraClassDeclaration = [{
-int64_t getSInt() const { return getValue().getSExtValue(); }
-uint64_t getUInt() const { return getValue().getZExtValue(); }
-bool isNullValue() const { return getValue() == 0; }
-uint64_t getBitWidth() const {
-  return mlir::cast(getType()).getWidth();
+int64_t getSInt() const;
+uint64_t getUInt() const;
+bool isNullValue() const;
+bool isSigned() const;
+bool isUnsigned() const;
+uint64_t getBitWidth() const;
+  }];
+
+ let extraClassDefinition = [{
+int64_t $cppClass::getSInt() const {
+  return getValue().getSExtValue();
+}
+uint64_t $cppClass::getUInt() const {
+  return getValue().getZExtValue();
+}
+bool $cppClass::isNullValue() const {
+  return getValue() == 0;
+}
+bool $cppClass::isSigned() const {
+  return mlir::cast(getType()).isSigned();
+}
+bool $cppClass::isUnsigned() const {
+  return mlir::cast(getType()).isUnsigned();
+}
+uint64_t $cppClass::getBitWidth() const {
+  return mlir::cast(getType()).getWidth();
 }
   }];
+
+  let assemblyFormat = [{
+`<` custom($value, ref($type)) `>`
+  }];
+
   let genVerifyDecl = 1;
-  let hasCustomAssemblyFormat = 1;
 }
 
 
//===--===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
index e25819cdb11bf..5fc7a92cd00f9 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
@@ -684,7 +684,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const 
APValue &value,
 if (mlir::isa(ty))
   return builder.getCIRBoolAttr(value.getInt().getZExtValue());
 assert(mlir::isa(ty) && "expected integral type");
-return cgm.getBuilder().getAttr(ty

[clang] 5491576 - [CIR] Introduce IntTypeInterface to allow uniform integer types handling (#146660)

2025-07-02 Thread via cfe-commits

Author: Henrich Lauko
Date: 2025-07-02T16:29:03+02:00
New Revision: 5491576a16230a770a507115af2c90f600a5d447

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

LOG: [CIR] Introduce IntTypeInterface to allow uniform integer types handling 
(#146660)

This will in future allow to use builtin integer types within cir operations

This mirrors incubat changes from https://github.com/llvm/clangir/pull/1724

Added: 


Modified: 
clang/include/clang/CIR/Dialect/IR/CIRTypes.td
clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td

Removed: 




diff  --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index bfe42562abad7..898c26d22f6d1 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -35,7 +35,8 @@ class CIR_Type 
traits = [],
 
 def CIR_IntType : CIR_Type<"Int", "int", [
 DeclareTypeInterfaceMethods,
-DeclareTypeInterfaceMethods
+DeclareTypeInterfaceMethods,
+DeclareTypeInterfaceMethods,
 ]> {
   let summary = "Integer type with arbitrary precision up to a fixed limit";
   let description = [{

diff  --git a/clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td 
b/clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td
index 1b1acf749e773..cf6c8571ddcd9 100644
--- a/clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td
+++ b/clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td
@@ -15,6 +15,48 @@
 
 include "mlir/IR/OpBase.td"
 
+def CIR_IntTypeInterface : TypeInterface<"IntTypeInterface"> {
+  let description = [{
+Contains helper functions to query properties about an integer type.
+  }];
+  let cppNamespace = "::cir";
+  let methods = [
+InterfaceMethod<[{
+Returns true if this is a signed integer type.
+  }],
+  /*retTy=*/"bool",
+  /*methodName=*/"isSigned",
+  /*args=*/(ins),
+  /*methodBody=*/"",
+  /*defaultImplementation=*/[{
+return $_type.isSigned();
+  }]
+>,
+InterfaceMethod<[{
+Returns true if this is an unsigned integer type.
+  }],
+  /*retTy=*/"bool",
+  /*methodName=*/"isUnsigned",
+  /*args=*/(ins),
+  /*methodBody=*/"",
+  /*defaultImplementation=*/[{
+return $_type.isUnsigned();
+  }]
+>,
+InterfaceMethod<[{
+Returns the bit width of this integer type.
+  }],
+  /*retTy=*/"unsigned",
+  /*methodName=*/"getWidth",
+  /*args=*/(ins),
+  /*methodBody=*/"",
+  /*defaultImplementation=*/[{
+return $_type.getWidth();
+  }]
+>
+  ];
+}
+
 def CIR_FPTypeInterface : TypeInterface<"FPTypeInterface"> {
   let description = [{
 Contains helper functions to query properties about a floating-point type.



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


[clang] [CIR] Implement NotEqualOp for ComplexType (PR #146129)

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


@@ -1319,6 +1319,9 @@ def CmpOp : CIR_Op<"cmp", [Pure, SameTypeOperands]> {
 `cir.bool` result. The kinds of comparison available are:
 [lt,gt,ge,eq,ne]
 
+Note: The 'complex' dialect has separate complex.eq and complex.neq
+operations
+

AmrDeveloper wrote:

Yes, I will remove it, thanks

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


[clang-tools-extra] [clang-tidy] add modernize-use-constexpr check (PR #146553)

2025-07-02 Thread Sean McBride via cfe-commits

seanm wrote:

Another interesting case, it seems somehow multiple constexprs got added, ex:

```c++
template 
constexpr constexpr constexpr constexpr constexpr constexpr constexpr constexpr 
int numberOfSidesOfDimension(int dimension);
```

This actually compiles, though with a `-Wduplicate-decl-specifier` warning.

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


[clang-tools-extra] [clangd] Drop const from a return type (NFC) (PR #146707)

2025-07-02 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clangd

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

Author: Kazu Hirata (kazutakahirata)


Changes

We don't need const on the return type.


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


1 Files Affected:

- (modified) clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp 
(+3-3) 


``diff
diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
index 90dac3b76c648..c74250ccbe9ea 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -359,9 +359,9 @@ struct ParsedBinaryOperator {
 //+   c <- End
 //   / \
 //  a   b <- Start
-const SourceRange getBinaryOperatorRange(const SelectionTree::Node &N,
- const SourceManager &SM,
- const LangOptions &LangOpts) {
+SourceRange getBinaryOperatorRange(const SelectionTree::Node &N,
+   const SourceManager &SM,
+   const LangOptions &LangOpts) {
   // If N is not a suitable binary operator, bail out.
   ParsedBinaryOperator Op;
   if (!Op.parse(N.ignoreImplicit()) || !Op.associative() ||

``




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


[clang] 8dcdc0f - [CIR] Clean up IntAttr (#146661)

2025-07-02 Thread via cfe-commits

Author: Henrich Lauko
Date: 2025-07-02T16:36:09+02:00
New Revision: 8dcdc0ff1f410897bf7b59fa31d480319d1169e7

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

LOG: [CIR] Clean up IntAttr (#146661)

- Add common CIR_ prefix
- Simplify printing/parsing
- Make it use IntTypeInterface

This mirrors incubator changes from https://github.com/llvm/clangir/pull/1725

Added: 


Modified: 
clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
clang/lib/CIR/Dialect/IR/CIRAttrs.cpp

Removed: 




diff  --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index 3e052c564112e..41ac8c1c875df 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -63,7 +63,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 
   mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ,
 const llvm::APInt &val) {
-return create(loc, getAttr(typ, val));
+return create(loc, cir::IntAttr::get(typ, val));
   }
 
   cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) {

diff  --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 9a6560519eec4..a042f5cd0c19e 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -117,36 +117,67 @@ def UndefAttr : CIR_TypedAttr<"Undef", "undef"> {
 // IntegerAttr
 
//===--===//
 
-def IntAttr : CIR_Attr<"Int", "int", [TypedAttrInterface]> {
+def CIR_IntAttr : CIR_Attr<"Int", "int", [TypedAttrInterface]> {
   let summary = "An attribute containing an integer value";
   let description = [{
 An integer attribute is a literal attribute that represents an integral
 value of the specified integer type.
   }];
-  let parameters = (ins AttributeSelfTypeParameter<"">:$type,
-APIntParameter<"">:$value);
+
+  let parameters = (ins
+AttributeSelfTypeParameter<"", "cir::IntTypeInterface">:$type,
+APIntParameter<"">:$value
+  );
+
   let builders = [
 AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
 "const llvm::APInt &":$value), [{
-  return $_get(type.getContext(), type, value);
+  auto intType = mlir::cast(type);
+  return $_get(type.getContext(), intType, value);
 }]>,
 AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
 "int64_t":$value), [{
-  IntType intType = mlir::cast(type);
+  auto intType = mlir::cast(type);
   mlir::APInt apValue(intType.getWidth(), value, intType.isSigned());
   return $_get(intType.getContext(), intType, apValue);
 }]>,
   ];
+
   let extraClassDeclaration = [{
-int64_t getSInt() const { return getValue().getSExtValue(); }
-uint64_t getUInt() const { return getValue().getZExtValue(); }
-bool isNullValue() const { return getValue() == 0; }
-uint64_t getBitWidth() const {
-  return mlir::cast(getType()).getWidth();
+int64_t getSInt() const;
+uint64_t getUInt() const;
+bool isNullValue() const;
+bool isSigned() const;
+bool isUnsigned() const;
+uint64_t getBitWidth() const;
+  }];
+
+ let extraClassDefinition = [{
+int64_t $cppClass::getSInt() const {
+  return getValue().getSExtValue();
+}
+uint64_t $cppClass::getUInt() const {
+  return getValue().getZExtValue();
+}
+bool $cppClass::isNullValue() const {
+  return getValue() == 0;
+}
+bool $cppClass::isSigned() const {
+  return mlir::cast(getType()).isSigned();
+}
+bool $cppClass::isUnsigned() const {
+  return mlir::cast(getType()).isUnsigned();
+}
+uint64_t $cppClass::getBitWidth() const {
+  return mlir::cast(getType()).getWidth();
 }
   }];
+
+  let assemblyFormat = [{
+`<` custom($value, ref($type)) `>`
+  }];
+
   let genVerifyDecl = 1;
-  let hasCustomAssemblyFormat = 1;
 }
 
 
//===--===//

diff  --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
index e25819cdb11bf..5fc7a92cd00f9 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
@@ -684,7 +684,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const 
APValue &value,
 if (mlir::isa(ty))
   return builder.getCIRBoolAttr(value.getInt().getZEx

[clang] [CIR] Clean up FPAttr (PR #146662)

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

https://github.com/xlauko updated 
https://github.com/llvm/llvm-project/pull/146662

>From 675128592ac7dbc3665e2c9786f0ce8f0ee2bf84 Mon Sep 17 00:00:00 2001
From: xlauko 
Date: Wed, 2 Jul 2025 09:56:38 +0200
Subject: [PATCH] [CIR] Clean up FPAttr

- Adds CIR_ prefix to the definition
- Removes redundant builder and cleans up attribute creations

This mirrors incubator changes from https://github.com/llvm/clangir/pull/1726
---
 clang/include/clang/CIR/Dialect/IR/CIRAttrs.td | 14 +++---
 clang/lib/CIR/CodeGen/CIRGenBuilder.cpp|  2 +-
 clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp   |  6 +++---
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp |  3 +--
 4 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index a042f5cd0c19e..569e62ae11612 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -184,34 +184,34 @@ def CIR_IntAttr : CIR_Attr<"Int", "int", 
[TypedAttrInterface]> {
 // FPAttr
 
//===--===//
 
-def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
+def CIR_FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
   let summary = "An attribute containing a floating-point value";
   let description = [{
 An fp attribute is a literal attribute that represents a floating-point
 value of the specified floating-point type. Supporting only CIR FP types.
   }];
+
   let parameters = (ins
 AttributeSelfTypeParameter<"", "::cir::FPTypeInterface">:$type,
 APFloatParameter<"">:$value
   );
+
   let builders = [
 AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
 "const llvm::APFloat &":$value), [{
   return $_get(type.getContext(), mlir::cast(type), 
value);
-}]>,
-AttrBuilder<(ins "mlir::Type":$type,
- "const llvm::APFloat &":$value), [{
-  return $_get($_ctxt, mlir::cast(type), value);
-}]>,
+}]>
   ];
+
   let extraClassDeclaration = [{
 static FPAttr getZero(mlir::Type type);
   }];
-  let genVerifyDecl = 1;
 
   let assemblyFormat = [{
 `<` custom($value, ref($type)) `>`
   }];
+
+  let genVerifyDecl = 1;
 }
 
 
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
index b94963c71f9c1..4a5a1dd53a05a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
@@ -63,7 +63,7 @@ cir::ConstantOp
 clang::CIRGen::CIRGenBuilderTy::getConstFP(mlir::Location loc, mlir::Type t,
llvm::APFloat fpVal) {
   assert(mlir::isa(t) && "expected floating point type");
-  return create(loc, getAttr(t, fpVal));
+  return create(loc, cir::FPAttr::get(t, fpVal));
 }
 
 // This can't be defined in Address.h because that file is included by
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
index 5fc7a92cd00f9..5b3bf85cefbb0 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
@@ -698,7 +698,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const 
APValue &value,
 mlir::Type ty = cgm.convertType(destType);
 assert(mlir::isa(ty) &&
"expected floating-point type");
-return cgm.getBuilder().getAttr(ty, init);
+return cir::FPAttr::get(ty, init);
   }
   case APValue::Array: {
 const ArrayType *arrayTy = cgm.getASTContext().getAsArrayType(destType);
@@ -798,8 +798,8 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const 
APValue &value,
 llvm::APFloat real = value.getComplexFloatReal();
 llvm::APFloat imag = value.getComplexFloatImag();
 return builder.getAttr(
-complexType, builder.getAttr(complexElemTy, real),
-builder.getAttr(complexElemTy, imag));
+complexType, cir::FPAttr::get(complexElemTy, real),
+cir::FPAttr::get(complexElemTy, imag));
   }
   case APValue::FixedPoint:
   case APValue::AddrLabelDiff:
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 06827f84f34d4..6eeecca7e7c8f 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -165,8 +165,7 @@ class ScalarExprEmitter : public 
StmtVisitor {
 assert(mlir::isa(type) &&
"expect floating-point type");
 return builder.create(
-cgf.getLoc(e->getExprLoc()),
-builder.getAttr(type, e->getValue()));
+cgf.getLoc(e->getExprLoc()), cir::FPAttr::get(type, e->getValue()));
   }
 
   mlir::Value VisitCharacterLiteral(const CharacterLiteral *e) {

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


[clang] [CIR] Clean up IntAttr (PR #146661)

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

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


[clang] [CIR] Clean up FPAttr (PR #146662)

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

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


[clang] [CIR] Clean up FPAttr (PR #146662)

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

https://github.com/xlauko updated 
https://github.com/llvm/llvm-project/pull/146662

>From cfcd6f676025aa66c30a355ef7eaaeec6898e9af Mon Sep 17 00:00:00 2001
From: xlauko 
Date: Wed, 2 Jul 2025 09:56:38 +0200
Subject: [PATCH] [CIR] Clean up FPAttr

- Adds CIR_ prefix to the definition
- Removes redundant builder and cleans up attribute creations

This mirrors incubator changes from https://github.com/llvm/clangir/pull/1726
---
 clang/include/clang/CIR/Dialect/IR/CIRAttrs.td | 14 +++---
 clang/lib/CIR/CodeGen/CIRGenBuilder.cpp|  2 +-
 clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp   |  6 +++---
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp |  3 +--
 4 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index a042f5cd0c19e..569e62ae11612 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -184,34 +184,34 @@ def CIR_IntAttr : CIR_Attr<"Int", "int", 
[TypedAttrInterface]> {
 // FPAttr
 
//===--===//
 
-def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
+def CIR_FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
   let summary = "An attribute containing a floating-point value";
   let description = [{
 An fp attribute is a literal attribute that represents a floating-point
 value of the specified floating-point type. Supporting only CIR FP types.
   }];
+
   let parameters = (ins
 AttributeSelfTypeParameter<"", "::cir::FPTypeInterface">:$type,
 APFloatParameter<"">:$value
   );
+
   let builders = [
 AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
 "const llvm::APFloat &":$value), [{
   return $_get(type.getContext(), mlir::cast(type), 
value);
-}]>,
-AttrBuilder<(ins "mlir::Type":$type,
- "const llvm::APFloat &":$value), [{
-  return $_get($_ctxt, mlir::cast(type), value);
-}]>,
+}]>
   ];
+
   let extraClassDeclaration = [{
 static FPAttr getZero(mlir::Type type);
   }];
-  let genVerifyDecl = 1;
 
   let assemblyFormat = [{
 `<` custom($value, ref($type)) `>`
   }];
+
+  let genVerifyDecl = 1;
 }
 
 
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
index b94963c71f9c1..4a5a1dd53a05a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
@@ -63,7 +63,7 @@ cir::ConstantOp
 clang::CIRGen::CIRGenBuilderTy::getConstFP(mlir::Location loc, mlir::Type t,
llvm::APFloat fpVal) {
   assert(mlir::isa(t) && "expected floating point type");
-  return create(loc, getAttr(t, fpVal));
+  return create(loc, cir::FPAttr::get(t, fpVal));
 }
 
 // This can't be defined in Address.h because that file is included by
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
index 5fc7a92cd00f9..5b3bf85cefbb0 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
@@ -698,7 +698,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const 
APValue &value,
 mlir::Type ty = cgm.convertType(destType);
 assert(mlir::isa(ty) &&
"expected floating-point type");
-return cgm.getBuilder().getAttr(ty, init);
+return cir::FPAttr::get(ty, init);
   }
   case APValue::Array: {
 const ArrayType *arrayTy = cgm.getASTContext().getAsArrayType(destType);
@@ -798,8 +798,8 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const 
APValue &value,
 llvm::APFloat real = value.getComplexFloatReal();
 llvm::APFloat imag = value.getComplexFloatImag();
 return builder.getAttr(
-complexType, builder.getAttr(complexElemTy, real),
-builder.getAttr(complexElemTy, imag));
+complexType, cir::FPAttr::get(complexElemTy, real),
+cir::FPAttr::get(complexElemTy, imag));
   }
   case APValue::FixedPoint:
   case APValue::AddrLabelDiff:
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 06827f84f34d4..6eeecca7e7c8f 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -165,8 +165,7 @@ class ScalarExprEmitter : public 
StmtVisitor {
 assert(mlir::isa(type) &&
"expect floating-point type");
 return builder.create(
-cgf.getLoc(e->getExprLoc()),
-builder.getAttr(type, e->getValue()));
+cgf.getLoc(e->getExprLoc()), cir::FPAttr::get(type, e->getValue()));
   }
 
   mlir::Value VisitCharacterLiteral(const CharacterLiteral *e) {

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


[clang] [CIR] Clean up FPAttr (PR #146662)

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

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


[clang] [CIR] Untie Type and Attribute definitions (PR #146663)

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

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


[clang] [CIR] Untie Type and Attribute definitions (PR #146663)

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

https://github.com/xlauko updated 
https://github.com/llvm/llvm-project/pull/146663

>From aa3016db7986982d72aee5cb1a1e6b40ef9be68b Mon Sep 17 00:00:00 2001
From: xlauko 
Date: Wed, 2 Jul 2025 12:16:53 +0200
Subject: [PATCH] [CIR] Untie Type and Attribute definitions

This will allow to use Attributes and Types together in tablegen without 
inducing cyclic dependency.

This mirrors incubator changes from https://github.com/llvm/clangir/pull/1727
---
 clang/include/clang/CIR/Dialect/IR/CIRAttrs.h | 22 ---
 .../include/clang/CIR/Dialect/IR/CIRDialect.h |  1 +
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
index 64556bcb92baa..925a9a87e267f 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
@@ -10,16 +10,15 @@
 //
 
//===--===//
 
-#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRATTRS_H
-#define LLVM_CLANG_CIR_DIALECT_IR_CIRATTRS_H
-
-#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
-#include "clang/CIR/Dialect/IR/CIRTypes.h"
+#ifndef CLANG_CIR_DIALECT_IR_CIRATTRS_H
+#define CLANG_CIR_DIALECT_IR_CIRATTRS_H
 
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/BuiltinAttributeInterfaces.h"
 
-#include "llvm/ADT/SmallVector.h"
+#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
+
+#include "clang/CIR/Interfaces/CIRTypeInterfaces.h"
 
 
//===--===//
 // CIR Dialect Attrs
@@ -27,15 +26,22 @@
 
 namespace clang {
 class FunctionDecl;
-class VarDecl;
 class RecordDecl;
+class VarDecl;
 } // namespace clang
 
 namespace cir {
 class ArrayType;
+class BoolType;
+class ComplexType;
+class IntType;
+class MethodType;
+class PointerType;
+class RecordType;
+class VectorType;
 } // namespace cir
 
 #define GET_ATTRDEF_CLASSES
 #include "clang/CIR/Dialect/IR/CIROpsAttributes.h.inc"
 
-#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRATTRS_H
+#endif // CLANG_CIR_DIALECT_IR_CIRATTRS_H
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h 
b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
index 5de1722cf5bc2..fdd56ac1f218f 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
@@ -29,6 +29,7 @@
 #include "clang/CIR/Dialect/IR/CIRAttrs.h"
 #include "clang/CIR/Dialect/IR/CIROpsDialect.h.inc"
 #include "clang/CIR/Dialect/IR/CIROpsEnums.h"
+#include "clang/CIR/Dialect/IR/CIRTypes.h"
 #include "clang/CIR/Interfaces/CIRLoopOpInterface.h"
 #include "clang/CIR/Interfaces/CIROpInterfaces.h"
 #include "clang/CIR/MissingFeatures.h"

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


[clang] e288561 - [CIR] Clean up FPAttr (#146662)

2025-07-02 Thread via cfe-commits

Author: Henrich Lauko
Date: 2025-07-02T16:52:15+02:00
New Revision: e288561e6ba49855e89a324cd46c7967fce27cf5

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

LOG: [CIR] Clean up FPAttr (#146662)

- Adds CIR_ prefix to the definition
- Removes redundant builder and cleans up attribute creations

This mirrors incubator changes from https://github.com/llvm/clangir/pull/1726

Added: 


Modified: 
clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Removed: 




diff  --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index a042f5cd0c19e..569e62ae11612 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -184,34 +184,34 @@ def CIR_IntAttr : CIR_Attr<"Int", "int", 
[TypedAttrInterface]> {
 // FPAttr
 
//===--===//
 
-def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
+def CIR_FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
   let summary = "An attribute containing a floating-point value";
   let description = [{
 An fp attribute is a literal attribute that represents a floating-point
 value of the specified floating-point type. Supporting only CIR FP types.
   }];
+
   let parameters = (ins
 AttributeSelfTypeParameter<"", "::cir::FPTypeInterface">:$type,
 APFloatParameter<"">:$value
   );
+
   let builders = [
 AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
 "const llvm::APFloat &":$value), [{
   return $_get(type.getContext(), mlir::cast(type), 
value);
-}]>,
-AttrBuilder<(ins "mlir::Type":$type,
- "const llvm::APFloat &":$value), [{
-  return $_get($_ctxt, mlir::cast(type), value);
-}]>,
+}]>
   ];
+
   let extraClassDeclaration = [{
 static FPAttr getZero(mlir::Type type);
   }];
-  let genVerifyDecl = 1;
 
   let assemblyFormat = [{
 `<` custom($value, ref($type)) `>`
   }];
+
+  let genVerifyDecl = 1;
 }
 
 

diff  --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
index b94963c71f9c1..4a5a1dd53a05a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
@@ -63,7 +63,7 @@ cir::ConstantOp
 clang::CIRGen::CIRGenBuilderTy::getConstFP(mlir::Location loc, mlir::Type t,
llvm::APFloat fpVal) {
   assert(mlir::isa(t) && "expected floating point type");
-  return create(loc, getAttr(t, fpVal));
+  return create(loc, cir::FPAttr::get(t, fpVal));
 }
 
 // This can't be defined in Address.h because that file is included by

diff  --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
index 5fc7a92cd00f9..5b3bf85cefbb0 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
@@ -698,7 +698,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const 
APValue &value,
 mlir::Type ty = cgm.convertType(destType);
 assert(mlir::isa(ty) &&
"expected floating-point type");
-return cgm.getBuilder().getAttr(ty, init);
+return cir::FPAttr::get(ty, init);
   }
   case APValue::Array: {
 const ArrayType *arrayTy = cgm.getASTContext().getAsArrayType(destType);
@@ -798,8 +798,8 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const 
APValue &value,
 llvm::APFloat real = value.getComplexFloatReal();
 llvm::APFloat imag = value.getComplexFloatImag();
 return builder.getAttr(
-complexType, builder.getAttr(complexElemTy, real),
-builder.getAttr(complexElemTy, imag));
+complexType, cir::FPAttr::get(complexElemTy, real),
+cir::FPAttr::get(complexElemTy, imag));
   }
   case APValue::FixedPoint:
   case APValue::AddrLabelDiff:

diff  --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 06827f84f34d4..6eeecca7e7c8f 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -165,8 +165,7 @@ class ScalarExprEmitter : public 
StmtVisitor {
 assert(mlir::isa(type) &&
"expect floating-point type");
 return builder.create(
-cgf.getLoc(e->getExprLoc()),
-builder.getAttr(type, e->getValue()));
+cgf.getLoc(e->getExprLoc()), cir::FPAttr::get(type, e->getValue()));
   }
 
   mlir::Value VisitCharacterLiteral(const CharacterLiteral *e) {



___
cfe-commits mailing list
cfe-commits@lists.llvm

[clang] 4db8ce7 - [clang-fuzzer] Fix latent race condition in build (#146119)

2025-07-02 Thread via cfe-commits

Author: Paddy McDonald
Date: 2025-07-02T07:53:33-07:00
New Revision: 4db8ce7251384d27c5fcdf5b583eeb4048f22706

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

LOG: [clang-fuzzer] Fix latent race condition in build (#146119)

Add explicit dependency for gen_vt to the CMakeLists.txt for
clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp to prevent race
condition on generation of llvm/CodeGen/GenVT.inc This explicit
dependency was added in other CMakeLists.txt when the tablegen was added
for GenVT.inc file in https://reviews.llvm.org/D148770, but not for
handle-llvm

A similar fix was made in
https://github.com/llvm/llvm-project/pull/109306

rdar://151325382

Added: 


Modified: 
clang/tools/clang-fuzzer/handle-llvm/CMakeLists.txt

Removed: 




diff  --git a/clang/tools/clang-fuzzer/handle-llvm/CMakeLists.txt 
b/clang/tools/clang-fuzzer/handle-llvm/CMakeLists.txt
index 9962f9850f545..49a95a02d0447 100644
--- a/clang/tools/clang-fuzzer/handle-llvm/CMakeLists.txt
+++ b/clang/tools/clang-fuzzer/handle-llvm/CMakeLists.txt
@@ -24,4 +24,5 @@ add_clang_library(clangHandleLLVM
 
   DEPENDS
   intrinsics_gen
+  vt_gen
   )



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


[clang] [clang-fuzzer] Fix latent race condition in build (PR #146119)

2025-07-02 Thread via cfe-commits

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


[clang] [clang-tools-extra] [clang][modules] Serialize `CodeGenOptions` (PR #146422)

2025-07-02 Thread Jan Svoboda via cfe-commits

jansvoboda11 wrote:

> My concern is, there are many other CodeGenOpts. And if we model them as 
> incompatible default, it will be a breaking change for existing users. We 
> don't like breaking change. How do you feel about to emit a warning so that 
> the end users can have a chance to escape?

I'm not suggesting to treat `CodeGenOptions` as incompatible by default. For 
now I'm just trying to remove the duplication and improve the 
infrastructure.`CodeGenOptions` are still benign by default, and can only be 
marked as compatible, which doesn't have any impact on explicitly-built 
modules. This PR is intended to be an NFC.

I'm open to having a diagnostic that warns about mismatch in compatible 
`CodeGenOptions` for explicitly-built modules, but I don't think we should 
block this PR on that.

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


[clang] [llvm] [mlir] [debuginfo][coro] Emit debug info labels for coroutine resume points (PR #141937)

2025-07-02 Thread Paul T Robinson via cfe-commits


@@ -0,0 +1,148 @@
+; Tests that we add DILabels for the suspend points.
+;
+; We check both the generated LLVM:
+; RUN: opt < %s -passes='cgscc(coro-split)' -S | FileCheck %s
+;
+; And the debug info:
+; RUN: opt < %s -passes='cgscc(coro-split),coro-cleanup' \
+; RUN:   | llc -O0 -filetype=obj -o - \
+; RUN:   | llvm-dwarfdump - \
+; RUN:   | FileCheck %s -check-prefix=DWARF
+
+source_filename = "coro.c"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"

pogo59 wrote:

Yes, that should work.

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


[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-02 Thread Fangrui Song via cfe-commits

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


[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-02 Thread Fangrui Song via cfe-commits

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


[clang] [llvm] AMDGPU: Add MC layer support for load transpose instructions for gfx1250 (PR #146024)

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


@@ -1092,19 +1092,23 @@ let SubtargetPredicate = isGFX12Plus in {
   }
 
   let WaveSizePredicate = isWave32 in {
-let Mnemonic = "global_load_tr_b128" in
-defm GLOBAL_LOAD_TR_B128_w32  : FLAT_Global_Load_Pseudo 
<"global_load_tr_b128_w32", VReg_128>;
-let Mnemonic = "global_load_tr_b64" in
-defm GLOBAL_LOAD_TR_B64_w32   : FLAT_Global_Load_Pseudo 
<"global_load_tr_b64_w32", VReg_64>;
-  }
-  let WaveSizePredicate = isWave64 in {
-let Mnemonic = "global_load_tr_b128" in
-defm GLOBAL_LOAD_TR_B128_w64  : FLAT_Global_Load_Pseudo 
<"global_load_tr_b128_w64", VReg_64>;
-let Mnemonic = "global_load_tr_b64" in
-defm GLOBAL_LOAD_TR_B64_w64   : FLAT_Global_Load_Pseudo 
<"global_load_tr_b64_w64", VGPR_32>;
+defm GLOBAL_LOAD_TR_B128_w32  : FLAT_Global_Load_Pseudo 
<"global_load_tr_b128", VReg_128>;
+defm GLOBAL_LOAD_TR_B64_w32   : FLAT_Global_Load_Pseudo 
<"global_load_tr_b64", VReg_64>;
   }
 } // End SubtargetPredicate = isGFX12Plus
 
+let WaveSizePredicate = isWave64, SubtargetPredicate = isGFX12PlusNot12_50 in {
+  let Mnemonic = "global_load_tr_b128" in
+  defm GLOBAL_LOAD_TR_B128_w64  : FLAT_Global_Load_Pseudo 
<"global_load_tr_b128_w64", VReg_64>;
+  let Mnemonic = "global_load_tr_b64" in
+  defm GLOBAL_LOAD_TR_B64_w64   : FLAT_Global_Load_Pseudo 
<"global_load_tr_b64_w64", VGPR_32>;
+}
+
+let WaveSizePredicate = isWave32, SubtargetPredicate = isGFX1250Plus in {

changpeng wrote:

This was later changed to HasTransposeLoadF4F6Insts. When I made that change, I 
also submitted  the change to downsream. Unfortunately, you are merging an 
older point from upstream to ToT downstream branch. 

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


[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-02 Thread Fangrui Song via cfe-commits


@@ -263,11 +263,17 @@ bool AVRAsmPrinter::doFinalization(Module &M) {
 auto *Section = cast(TLOF.SectionForGlobal(&GO, TM));
 if (Section->getName().starts_with(".data"))
   NeedsCopyData = true;
-else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM())
+else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM()) {
   // AVRs that have a separate program memory (that's most AVRs) store
-  // .rodata sections in RAM.
-  NeedsCopyData = true;
-else if (Section->getName().starts_with(".bss"))
+  // .rodata sections in RAM,
+  // but XMEGA3 family maps all flash in the data space.
+  // Invoking __do_copy_data with 0 bytes to copy will crash,
+  // so we let the loader handle this for newer devices.
+  if (!(SubTM->hasFeatureSetFamilyXMEGA2() ||

MaskRay wrote:

Unless trivial (e.g. typo fix), "marked this conversation as resolved." should 
only be used by reviewers per suggestions on 
https://discourse.llvm.org/t/rfc-github-pr-resolve-conversation-button/73178

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


[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-02 Thread Fangrui Song via cfe-commits


@@ -263,11 +263,17 @@ bool AVRAsmPrinter::doFinalization(Module &M) {
 auto *Section = cast(TLOF.SectionForGlobal(&GO, TM));
 if (Section->getName().starts_with(".data"))
   NeedsCopyData = true;
-else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM())
+else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM()) {
   // AVRs that have a separate program memory (that's most AVRs) store
-  // .rodata sections in RAM.
-  NeedsCopyData = true;
-else if (Section->getName().starts_with(".bss"))
+  // .rodata sections in RAM,
+  // but XMEGA3 family maps all flash in the data space.
+  // Invoking __do_copy_data with 0 bytes to copy will crash,
+  // so we let the loader handle this for newer devices.
+  if (!(SubTM->hasFeatureSetFamilyXMEGA2() ||

MaskRay wrote:

(Sorry, didn't see that tomtor is the author :) )

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


[clang] [libcxx] [clang] [modules] Add err_main_in_named_module (PR #146635)

2025-07-02 Thread Ashwin Kishin Banwari via cfe-commits

https://github.com/kish1n updated 
https://github.com/llvm/llvm-project/pull/146635

>From 76bd9279c0410fa53c8a8ca34229f5ca3a4812e3 Mon Sep 17 00:00:00 2001
From: Ashwin Banwari 
Date: Mon, 30 Jun 2025 18:10:24 -0700
Subject: [PATCH 1/6] Reapply "[clang] [modules] Add err_main_in_named_module
 (#146247)"

This reverts commit 8a5b97a7205db189ca82f44dec7a399c2b5da546.
---
 clang/docs/ReleaseNotes.rst  | 3 +++
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 
 clang/lib/Sema/SemaDecl.cpp  | 8 
 clang/test/Driver/autocomplete.c | 1 +
 clang/test/SemaCXX/modules.cppm  | 2 ++
 5 files changed, 18 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e6c8f9df22170..db99cc9233377 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -659,6 +659,9 @@ Improvements to Clang's diagnostics
   diagnostics when floating-point numbers had both width field and plus or 
space
   prefix specified. (#GH143951)
 
+- A warning is now emitted when ``main`` is attached to a named module,
+  which can be turned off with ``-Wno-main-attached-to-named-module``. 
(#GH146247)
+
 - Clang now avoids issuing `-Wreturn-type` warnings in some cases where
   the final statement of a non-void function is a `throw` expression, or
   a call to a function that is trivially known to always throw (i.e., its
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5062505cf3c01..451619709c087 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1062,6 +1062,10 @@ def err_constexpr_main : Error<
   "'main' is not allowed to be declared %select{constexpr|consteval}0">;
 def err_deleted_main : Error<"'main' is not allowed to be deleted">;
 def err_mainlike_template_decl : Error<"%0 cannot be a template">;
+def warn_main_in_named_module
+: ExtWarn<"'main' should not be attached to a named module; consider "
+  "adding C++ language linkage">,
+  InGroup>;
 def err_main_returns_nonint : Error<"'main' must return 'int'">;
 def ext_main_returns_nonint : ExtWarn<"return type of 'main' is not 'int'">,
 InGroup;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a34e2c9cbb003..f4bc191d1dae6 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12489,6 +12489,14 @@ void Sema::CheckMain(FunctionDecl *FD, const DeclSpec 
&DS) {
 : FixItHint());
   FD->setInvalidDecl(true);
 }
+
+// In C++ [basic.start.main]p3, it is said a program attaching main to a
+// named module is ill-formed.
+if (FD->isInNamedModule()) {
+  const SourceLocation start = FD->getTypeSpecStartLoc();
+  Diag(start, diag::warn_main_in_named_module)
+  << FixItHint::CreateInsertion(start, "extern \"C++\" ", true);
+}
   }
 
   // Treat protoless main() as nullary.
diff --git a/clang/test/Driver/autocomplete.c b/clang/test/Driver/autocomplete.c
index 8cc604dbff875..4983b71496834 100644
--- a/clang/test/Driver/autocomplete.c
+++ b/clang/test/Driver/autocomplete.c
@@ -111,6 +111,7 @@
 // RUN: %clang --autocomplete=-Wma | FileCheck %s -check-prefix=WARNING
 // WARNING: -Wmacro-redefined
 // WARNING-NEXT: -Wmain
+// WARNING-NEXT: -Wmain-attached-to-named-module
 // WARNING-NEXT: -Wmain-return-type
 // WARNING-NEXT: -Wmalformed-warning-check
 // WARNING-NEXT: -Wmany-braces-around-scalar-init
diff --git a/clang/test/SemaCXX/modules.cppm b/clang/test/SemaCXX/modules.cppm
index 5d0d6da44a2ed..81bc749c58259 100644
--- a/clang/test/SemaCXX/modules.cppm
+++ b/clang/test/SemaCXX/modules.cppm
@@ -68,6 +68,8 @@ int n;
 //--- test3.cpp
 export module bar;
 
+int main() {} // expected-warning {{'main' should not be attached to a named 
module; consider adding C++ language linkage}}
+
 static int m;
 
 int n;

>From 195b81a312fed2b13bea14666feb45f3c1f599ed Mon Sep 17 00:00:00 2001
From: Ashwin Banwari 
Date: Tue, 1 Jul 2025 22:33:55 -0700
Subject: [PATCH 2/6] update test

---
 clang/test/SemaCXX/modules.cppm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/SemaCXX/modules.cppm b/clang/test/SemaCXX/modules.cppm
index 5d7ea6bacf7e0..5e0b3be9870c7 100644
--- a/clang/test/SemaCXX/modules.cppm
+++ b/clang/test/SemaCXX/modules.cppm
@@ -41,6 +41,8 @@ struct S {
   export static int n; // expected-error {{expected member name or ';'}}
 };
 
+int main() {} // expected-warning {{'main' should not be attached to a named 
module; consider adding C++ language linkage}}
+
 // FIXME: Exports of declarations without external linkage are disallowed.
 // Exports of declarations with non-external-linkage types are disallowed.
 
@@ -68,8 +70,6 @@ int n;
 //--- test3.cpp
 export module bar;
 
-int main() {} // expected-warning {{'main' should not be attached to a named 
module;

[clang] [libcxx] [clang] [modules] Add err_main_in_named_module (PR #146635)

2025-07-02 Thread Ashwin Kishin Banwari via cfe-commits

kish1n wrote:

The only fail is some unrelated test timeout, seems to be flaky. I will remove 
the added libcxx change now so its ready to merge

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


[clang] [llvm] [mlir] [debuginfo][coro] Emit debug info labels for coroutine resume points (PR #141937)

2025-07-02 Thread Paul T Robinson via cfe-commits

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


[clang] [llvm] [mlir] [debuginfo][coro] Emit debug info labels for coroutine resume points (PR #141937)

2025-07-02 Thread Paul T Robinson via cfe-commits

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


[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-02 Thread Fangrui Song via cfe-commits


@@ -651,8 +651,19 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   // This is almost always required because otherwise avr-ld
   // will assume 'avr2' and warn about the program being larger
   // than the bare minimum supports.
-  if (Linker.find("avr-ld") != std::string::npos && FamilyName)
-CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
+  if (Linker.find("avr-ld") != std::string::npos && FamilyName) {
+// Option to use mapped memory for modern devices with >32kB flash.
+// This is the only option for modern devices with <= 32kB flash,
+// but the larger default to a copy from flash to RAM (avr-ld version < 14)
+// or map the highest 32kB to RAM (avr-ld version >= 14).
+if (Args.hasFlag(options::OPT_mflmap, options::OPT_mrodata_in_ram, false)) 
{
+  CmdArgs.push_back(
+  Args.MakeArgString(std::string("-m") + *FamilyName + "_flmap"));

MaskRay wrote:

I am not familiar with these options. Are we sure this patch has listed all the 
effects?

gcc also seems to do something with the `__do_copy_data` symbol

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


[clang] [clang] [modules] Add err_main_in_named_module (PR #146635)

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


@@ -1062,6 +1062,10 @@ def err_constexpr_main : Error<
   "'main' is not allowed to be declared %select{constexpr|consteval}0">;
 def err_deleted_main : Error<"'main' is not allowed to be deleted">;
 def err_mainlike_template_decl : Error<"%0 cannot be a template">;
+def warn_main_in_named_module
+: ExtWarn<"'main' should not be attached to a named module; consider "
+  "adding C++ language linkage">,

cor3ntin wrote:

Maybe just `'main' never has module linkage;" the "Consider..." is somewhat 
redundant with the fixit

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


[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-02 Thread Ben Shi via cfe-commits

benshi001 wrote:

> > I do not think this PR is necessary, since there is no bug, I have 
> > explained in #146537.
> 
> You are right, so this PR is not a bug fix, but just adding features and a 
> minor optimization.

Currently I am focusing on bugfix and compatibility/substitutability with 
avr-gcc-7.3 (which is used by Arduino major version), and quite cautious about 
adding new features.

For the `mflmap` / `mrodata-in-ram"` / `__do_flmap_init` mentioned in your PR, 
I am not familiar with them. So I need more time to
1. Understand these features in newer AVR devices,
2. study how gcc and air-libc support them,
3. check if they affect stability of existing llvm-avr's functionalities.

What's more, I can only decide modifications to the AVR backend. If you want to 
add new clang options, you have to create a proposal at 
https://discourse.llvm.org, and let the clang reviewers to decide.

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


[clang] [llvm] [SPIRV] Add more id and range builtIns (PR #143909)

2025-07-02 Thread Victor Lomuller via cfe-commits

Naghasan wrote:

> makes it easier to support non clang based frontends. Say we wanted to do 
> something MLIR based.

Yes, that reminds me of the D compiler struggling to use the translator a few 
yers back.

@Keenuts so are you fine moving ahead as it is ? as @farzonl mentioned, it also 
has value if a non clang project also want to picks this up.

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


[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-02 Thread Tom Vijlbrief via cfe-commits

tomtor wrote:

@benshi There is an alternative to new driver options: 
https://github.com/llvm/llvm-project/pull/146244/files#r2179646110

That would be a minimal change, and a general improvement giving users more 
options to tune the linking.

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


  1   2   3   4   5   >