[clang] [clang-tools-extra] [clangd] Support operators new and delete in textDocument/references (PR #135620)

2025-04-22 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-clang-x86_64-linux-debian` running on `gribozavr4` while building 
`clang-tools-extra,clang` at step 6 "test-openmp".

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


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

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

Exit Code: -11

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

--




```



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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread Tom Eccles via cfe-commits


@@ -24,6 +24,11 @@ CODEGENOPT(OptimizationLevel, 2, 0) ///< The -O[0-3] option 
specified.
 CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new
///< pass manager.
 
+ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 2, ProfileNone)
+ENUM_CODEGENOPT(ProfileUse, ProfileInstrKind, 2, ProfileNone)
+/// Whether emit extra debug info for sample pgo profile collection.
+CODEGENOPT(DebugInfoForProfiling, 1, 0)
+CODEGENOPT(AtomicProfileUpdate , 1, 0) ///< Set -fprofile-update=atomic

tblah wrote:

`-fprofile-update=atomic` is not currently supported so far as I can tell.

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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread Tom Eccles via cfe-commits


@@ -148,6 +148,55 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// OpenMP is enabled.
   using DoConcurrentMappingKind = flangomp::DoConcurrentMappingKind;
 
+  enum ProfileInstrKind {
+ProfileNone,   // Profile instrumentation is turned off.
+ProfileClangInstr, // Clang instrumentation to generate execution counts
+   // to use with PGO.
+ProfileIRInstr,// IR level PGO instrumentation in LLVM.
+ProfileCSIRInstr, // IR level PGO context sensitive instrumentation in 
LLVM.
+  };
+
+
+  /// Name of the profile file to use as output for -fprofile-instr-generate,
+  /// -fprofile-generate, and -fcs-profile-generate.
+  std::string InstrProfileOutput;
+
+  /// Name of the profile file to use as input for -fmemory-profile-use.
+  std::string MemoryProfileUsePath;
+
+  unsigned int DebugInfoForProfiling;
+
+  unsigned int AtomicProfileUpdate;
+
+  /// Name of the profile file to use as input for -fprofile-instr-use
+  std::string ProfileInstrumentUsePath;

tblah wrote:

What about filesystems using wide characters?

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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread Tom Eccles via cfe-commits


@@ -882,6 +882,14 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // TODO: Handle interactions between -w, -pedantic, -Wall, -WOption
   Args.AddLastArg(CmdArgs, options::OPT_w);
 
+
+  if (Args.hasArg(options::OPT_fprofile_generate)){ 
+CmdArgs.push_back("-fprofile-generate");
+  }
+  if (const Arg *A = Args.getLastArg(options::OPT_fprofile_use_EQ)) {
+CmdArgs.push_back(Args.MakeArgString(std::string("-fprofile-use=") + 
A->getValue()));
+  }

tblah wrote:

nit: I think it would be simpler to use
```suggestion
  Args.addAllArgs(CmdArgs, {OPT_fprofile_generate, OPT_fprofile_use_EQ});
```

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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread Tom Eccles via cfe-commits


@@ -148,6 +148,55 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// OpenMP is enabled.
   using DoConcurrentMappingKind = flangomp::DoConcurrentMappingKind;
 
+  enum ProfileInstrKind {
+ProfileNone,   // Profile instrumentation is turned off.
+ProfileClangInstr, // Clang instrumentation to generate execution counts
+   // to use with PGO.
+ProfileIRInstr,// IR level PGO instrumentation in LLVM.
+ProfileCSIRInstr, // IR level PGO context sensitive instrumentation in 
LLVM.
+  };
+
+
+  /// Name of the profile file to use as output for -fprofile-instr-generate,
+  /// -fprofile-generate, and -fcs-profile-generate.
+  std::string InstrProfileOutput;
+
+  /// Name of the profile file to use as input for -fmemory-profile-use.
+  std::string MemoryProfileUsePath;
+
+  unsigned int DebugInfoForProfiling;
+
+  unsigned int AtomicProfileUpdate;

tblah wrote:

Why are these added here and also in CodeGenOptions.def?

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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread Tom Eccles via cfe-commits


@@ -909,6 +940,29 @@ void 
CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
   llvm::PassInstrumentationCallbacks pic;
   llvm::PipelineTuningOptions pto;
   std::optional pgoOpt;
+ 
+  if (opts.hasProfileIRInstr()){
+// // -fprofile-generate.

tblah wrote:

```suggestion
// -fprofile-generate.
```

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


[clang] Control analysis-based diagnostics with #pragma (PR #136323)

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

AaronBallman wrote:

Any other changes needed, or are you happy @haoNoQ? @erichkeane @Sirraide want 
to re-review given the significant reworking?

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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread Tom Eccles via cfe-commits

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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread Tom Eccles via cfe-commits

https://github.com/tblah commented:

Thanks for contributing this

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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 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 h,cpp -- 
clang/lib/Driver/ToolChains/Flang.cpp 
flang/include/flang/Frontend/CodeGenOptions.h 
flang/lib/Frontend/CompilerInvocation.cpp flang/lib/Frontend/FrontendActions.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index fcdbe8a6a..563ab15a2 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -882,12 +882,12 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // TODO: Handle interactions between -w, -pedantic, -Wall, -WOption
   Args.AddLastArg(CmdArgs, options::OPT_w);
 
-
-  if (Args.hasArg(options::OPT_fprofile_generate)){ 
+  if (Args.hasArg(options::OPT_fprofile_generate)) {
 CmdArgs.push_back("-fprofile-generate");
   }
   if (const Arg *A = Args.getLastArg(options::OPT_fprofile_use_EQ)) {
-CmdArgs.push_back(Args.MakeArgString(std::string("-fprofile-use=") + 
A->getValue()));
+CmdArgs.push_back(
+Args.MakeArgString(std::string("-fprofile-use=") + A->getValue()));
   }
 
   // Forward flags for OpenMP. We don't do this if the current action is an
diff --git a/flang/include/flang/Frontend/CodeGenOptions.h 
b/flang/include/flang/Frontend/CodeGenOptions.h
index e052250f9..c9577862d 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.h
+++ b/flang/include/flang/Frontend/CodeGenOptions.h
@@ -156,7 +156,6 @@ public:
 ProfileCSIRInstr, // IR level PGO context sensitive instrumentation in 
LLVM.
   };
 
-
   /// Name of the profile file to use as output for -fprofile-instr-generate,
   /// -fprofile-generate, and -fcs-profile-generate.
   std::string InstrProfileOutput;
@@ -171,7 +170,7 @@ public:
   /// Name of the profile file to use as input for -fprofile-instr-use
   std::string ProfileInstrumentUsePath;
 
-/// Name of the profile remapping file to apply to the profile data 
supplied
+  /// Name of the profile remapping file to apply to the profile data supplied
   /// by -fprofile-sample-use or -fprofile-instr-use.
   std::string ProfileRemappingFile;
 
@@ -181,19 +180,17 @@ public:
   }
 
   /// Check if IR level profile instrumentation is on.
-  bool hasProfileIRInstr() const {
-return getProfileInstr() == ProfileIRInstr;
-  }
+  bool hasProfileIRInstr() const { return getProfileInstr() == ProfileIRInstr; 
}
 
   /// Check if CS IR level profile instrumentation is on.
   bool hasProfileCSIRInstr() const {
 return getProfileInstr() == ProfileCSIRInstr;
   }
-/// Check if IR level profile use is on.
-bool hasProfileIRUse() const {
-  return getProfileUse() == ProfileIRInstr ||
- getProfileUse() == ProfileCSIRInstr;
-}
+  /// Check if IR level profile use is on.
+  bool hasProfileIRUse() const {
+return getProfileUse() == ProfileIRInstr ||
+   getProfileUse() == ProfileCSIRInstr;
+  }
   /// Check if CSIR profile use is on.
   bool hasProfileCSIRUse() const { return getProfileUse() == ProfileCSIRInstr; 
}
 
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index f013fce2f..b28c2c004 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -27,7 +27,6 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/OptionUtils.h"
 #include "clang/Driver/Options.h"
-#include "clang/Driver/Driver.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Frontend/Debug/Options.h"
@@ -433,13 +432,17 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
   }
 
   if (args.hasArg(clang::driver::options::OPT_fprofile_generate)) {
-
opts.setProfileInstr(Fortran::frontend::CodeGenOptions::ProfileInstrKind::ProfileIRInstr);
-opts.DebugInfoForProfiling = 
args.hasArg(clang::driver::options::OPT_fdebug_info_for_profiling);
-opts.AtomicProfileUpdate = 
args.hasArg(clang::driver::options::OPT_fprofile_update_EQ);
+opts.setProfileInstr(
+Fortran::frontend::CodeGenOptions::ProfileInstrKind::ProfileIRInstr);
+opts.DebugInfoForProfiling =
+args.hasArg(clang::driver::options::OPT_fdebug_info_for_profiling);
+opts.AtomicProfileUpdate =
+args.hasArg(clang::driver::options::OPT_fprofile_update_EQ);
   }
- 
+
   if (auto A = args.getLastArg(clang::driver::options::OPT_fprofile_use_EQ)) {
-
opts.setProfileUse(Fortran::frontend::CodeGenOptions::ProfileInstrKind::ProfileIRInstr);
+opts.setProfileUse(
+Fortran::frontend::CodeGenOptions::ProfileInstrKind::ProfileIRInstr);
 opts.ProfileInstrumentUsePath = A->getValue();
   }
 
diff --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp

[clang] Reorganize -Winitializer-overrides and -Wreorder-init-list (PR #136586)

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

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

>From 49dcc67a3a448a3339c40ffb8b0fe58489e7554a Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Mon, 21 Apr 2025 13:40:19 -0400
Subject: [PATCH 1/2] Reorganize -Winitializer-overrides and
 -Wreorder-init-list

These are both now grouped under -Wc99-designator as they both relate
to the C99 feature as it was introduced into C++20.

Fixes #47037
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/include/clang/Basic/DiagnosticGroups.td | 17 ---
 clang/test/SemaCXX/cxx20-c99-designator.cpp   | 21 +++
 clang/test/SemaCXX/decltype.cpp   |  9 
 4 files changed, 34 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx20-c99-designator.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7417fdd71a392..510f16b1ad88c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -402,6 +402,9 @@ Improvements to Clang's diagnostics
   they're only triggered if the authors are already making the choice to use
   ``preferred_type`` attribute.
 
+- ``-Winitializer-overrides`` and ``-Wreorder-init-list`` are now grouped under
+  the ``-Wc99-designator`` diagnostic group, as they also are about the
+  behavior of the C99 feature as it was introduced into C++20. Fixes #GH47037
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index b29fe40b05c6f..59036b695da85 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -184,6 +184,13 @@ def AbstractFinalClass : DiagGroup<"abstract-final-class">;
 def FinalDtorNonFinalClass : DiagGroup<"final-dtor-non-final-class">;
 def GNUOffsetofExtensions : DiagGroup<"gnu-offsetof-extensions">;
 
+def InitializerOverrides : DiagGroup<"initializer-overrides">;
+// For compatibility with GCC; -Woverride-init = -Winitializer-overrides
+def : DiagGroup<"override-init", [InitializerOverrides]>;
+def ReorderCtor : DiagGroup<"reorder-ctor">;
+def ReorderInitList : DiagGroup<"reorder-init-list">;
+def Reorder : DiagGroup<"reorder", [ReorderCtor, ReorderInitList]>;
+
 def CXX11CompatDeprecatedWritableStr :
   DiagGroup<"c++11-compat-deprecated-writable-strings">;
 
@@ -250,7 +257,9 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
 def CXX20Designator : DiagGroup<"c++20-designator">;
 // Allow -Wno-c99-designator to be used to turn off all warnings on valid C99
 // designators (including the warning controlled by -Wc++20-designator).
-def C99Designator : DiagGroup<"c99-designator", [CXX20Designator]>;
+def C99Designator : DiagGroup<"c99-designator", [CXX20Designator,
+ InitializerOverrides,
+ ReorderInitList]>;
 def GNUDesignator : DiagGroup<"gnu-designator">;
 def DtorName : DiagGroup<"dtor-name">;
 
@@ -595,9 +604,6 @@ def NullabilityCompleteness : 
DiagGroup<"nullability-completeness",
 def NullArithmetic : DiagGroup<"null-arithmetic">;
 def NullCharacter : DiagGroup<"null-character">;
 def NullDereference : DiagGroup<"null-dereference">;
-def InitializerOverrides : DiagGroup<"initializer-overrides">;
-// For compatibility with GCC; -Woverride-init = -Winitializer-overrides
-def : DiagGroup<"override-init", [InitializerOverrides]>;
 def NonNull : DiagGroup<"nonnull">;
 def NonPODVarargs : DiagGroup<"non-pod-varargs">;
 def ClassVarargs : DiagGroup<"class-varargs", [NonPODVarargs]>;
@@ -919,9 +925,6 @@ def UsedButMarkedUnused : 
DiagGroup<"used-but-marked-unused">;
 def UsedSearchPath : DiagGroup<"search-path-usage">;
 def UserDefinedLiterals : DiagGroup<"user-defined-literals">;
 def UserDefinedWarnings : DiagGroup<"user-defined-warnings">;
-def ReorderCtor : DiagGroup<"reorder-ctor">;
-def ReorderInitList : DiagGroup<"reorder-init-list">;
-def Reorder : DiagGroup<"reorder", [ReorderCtor, ReorderInitList]>;
 def UndeclaredSelector : DiagGroup<"undeclared-selector">;
 def ImplicitAtomic : DiagGroup<"implicit-atomic-properties">;
 def AtomicAlignment : DiagGroup<"atomic-alignment">;
diff --git a/clang/test/SemaCXX/cxx20-c99-designator.cpp 
b/clang/test/SemaCXX/cxx20-c99-designator.cpp
new file mode 100644
index 0..b8c141a30a261
--- /dev/null
+++ b/clang/test/SemaCXX/cxx20-c99-designator.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=override,reorder 
-Werror=c99-designator %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=override 
-Wno-reorder-init-list -Werror=initializer-overrides %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=reorder 
-Wno-initializer-overrides -Werror=reorder-init-list %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=good -Wno-c99-designator %s
+// good-no-diagnostics
+
+// Ensure that -W

[clang] Control analysis-based diagnostics with #pragma (PR #136323)

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

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

>From 3beecb29772e13c6a1a41877e5e8cbbfb17a88f2 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Fri, 18 Apr 2025 12:26:36 -0400
Subject: [PATCH 1/5] Control analysis-based diagnostics with #pragma

Previously, analysis-based diagnostics (like -Wconsumed) had to be
enabled at file scope in order to be run at the end of each function
body. This meant that they did not respect #pragma clang diagnostic
enabling or disabling the diagnostic.

Now, these pragmas can control the diagnostic emission. However, the
behavior requires some explanation (which is why the documentation is
being updated). Analysis-based warnings run at the end of a function
body, so the diagnostic needs to be enabled after the closing } for the
function in order to run the analysis at all. However, if the analysis
emits a diagnostic for line in the function, the diagnostic still needs
to be enabled on that specific line in order to be shown to the user.

Fixes #42199
---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/docs/UsersManual.rst| 24 ++
 .../clang/Sema/AnalysisBasedWarnings.h|  4 +-
 clang/lib/Sema/AnalysisBasedWarnings.cpp  | 29 ---
 clang/lib/Sema/SemaDecl.cpp   |  8 +-
 clang/lib/Sema/SemaExpr.cpp   |  3 +-
 clang/test/Analysis/pragma-diag-control.cpp   | 77 +++
 7 files changed, 132 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/Analysis/pragma-diag-control.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f5cd1fbeabcfe..8d139123b47ce 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -395,6 +395,9 @@ Improvements to Clang's diagnostics
   constructors to initialize their non-modifiable members. The diagnostic is
   not new; being controlled via a warning group is what's new. Fixes #GH41104
 
+- Analysis-based diagnostics (like ``-Wconsumed`` or ``-Wunreachable-code``)
+  can now be correctly controlled by ``#pragma clang diagnostic``. #GH42199
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 69256527f40c9..0ba4e2dedd4eb 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1202,6 +1202,30 @@ Clang also allows you to push and pop the current 
warning state. This is
 particularly useful when writing a header file that will be compiled by
 other people, because you don't know what warning flags they build with.
 
+Note that the following diagnostic groups, which are ones based on analyzing
+the control flow graph for a function, require the diagnostic group to be
+enabled at the end of the function body (after the closing ``}``) in order to
+run the analysis, in addition to requiring the diagnostic group to be enabled
+at the line being diagnosed:
+
+  * ``-Wconsumed``
+  * ``-Wthread-safety-analysis``
+  * ``-Wunreachable-code``, ``-Wunreachable-code-aggressive``, or warnings
+controlled by either of those flags
+
+thus, it is generally better for a ``push`` and ``pop`` pair of pragmas
+controlling behavior for an entire function be placed outside of the function
+body rather than within it. e.g.,
+
+.. code-block:: c
+
+  #pragma clang diagnostic push
+  #pragma clang diagnostic warning "-Wwhatever"
+  int d() {
+// Better to put the pragmas outside of the function rather than within it.
+  }
+  #pragma clang diagnostic pop
+
 In the below example :option:`-Wextra-tokens` is ignored for only a single line
 of code, after which the diagnostics return to whatever state had previously
 existed.
diff --git a/clang/include/clang/Sema/AnalysisBasedWarnings.h 
b/clang/include/clang/Sema/AnalysisBasedWarnings.h
index aafe227b84084..49023863f4503 100644
--- a/clang/include/clang/Sema/AnalysisBasedWarnings.h
+++ b/clang/include/clang/Sema/AnalysisBasedWarnings.h
@@ -49,7 +49,6 @@ class AnalysisBasedWarnings {
 
 private:
   Sema &S;
-  Policy DefaultPolicy;
 
   class InterProceduralData;
   std::unique_ptr IPData;
@@ -103,7 +102,8 @@ class AnalysisBasedWarnings {
   // Issue warnings that require whole-translation-unit analysis.
   void IssueWarnings(TranslationUnitDecl *D);
 
-  Policy getDefaultPolicy() { return DefaultPolicy; }
+  // Gets the default policy which is in effect at the given source location.
+  Policy getPolicyInEffectAt(SourceLocation Loc);
 
   void PrintStats() const;
 };
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp 
b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 34045a7274021..72962acee66d3 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2493,8 +2493,9 @@ class sema::AnalysisBasedWarnings::InterProceduralData {
   CalledOnceInterProceduralData CalledOnceData;
 };
 
-static unsigned isEnabled(DiagnosticsEngine &D, unsigned diag) {
-  return (unsigned)!D.

[clang] Reorganize -Winitializer-overrides and -Wreorder-init-list (PR #136586)

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

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

>From 49dcc67a3a448a3339c40ffb8b0fe58489e7554a Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Mon, 21 Apr 2025 13:40:19 -0400
Subject: [PATCH 1/2] Reorganize -Winitializer-overrides and
 -Wreorder-init-list

These are both now grouped under -Wc99-designator as they both relate
to the C99 feature as it was introduced into C++20.

Fixes #47037
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/include/clang/Basic/DiagnosticGroups.td | 17 ---
 clang/test/SemaCXX/cxx20-c99-designator.cpp   | 21 +++
 clang/test/SemaCXX/decltype.cpp   |  9 
 4 files changed, 34 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx20-c99-designator.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7417fdd71a392..510f16b1ad88c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -402,6 +402,9 @@ Improvements to Clang's diagnostics
   they're only triggered if the authors are already making the choice to use
   ``preferred_type`` attribute.
 
+- ``-Winitializer-overrides`` and ``-Wreorder-init-list`` are now grouped under
+  the ``-Wc99-designator`` diagnostic group, as they also are about the
+  behavior of the C99 feature as it was introduced into C++20. Fixes #GH47037
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index b29fe40b05c6f..59036b695da85 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -184,6 +184,13 @@ def AbstractFinalClass : DiagGroup<"abstract-final-class">;
 def FinalDtorNonFinalClass : DiagGroup<"final-dtor-non-final-class">;
 def GNUOffsetofExtensions : DiagGroup<"gnu-offsetof-extensions">;
 
+def InitializerOverrides : DiagGroup<"initializer-overrides">;
+// For compatibility with GCC; -Woverride-init = -Winitializer-overrides
+def : DiagGroup<"override-init", [InitializerOverrides]>;
+def ReorderCtor : DiagGroup<"reorder-ctor">;
+def ReorderInitList : DiagGroup<"reorder-init-list">;
+def Reorder : DiagGroup<"reorder", [ReorderCtor, ReorderInitList]>;
+
 def CXX11CompatDeprecatedWritableStr :
   DiagGroup<"c++11-compat-deprecated-writable-strings">;
 
@@ -250,7 +257,9 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
 def CXX20Designator : DiagGroup<"c++20-designator">;
 // Allow -Wno-c99-designator to be used to turn off all warnings on valid C99
 // designators (including the warning controlled by -Wc++20-designator).
-def C99Designator : DiagGroup<"c99-designator", [CXX20Designator]>;
+def C99Designator : DiagGroup<"c99-designator", [CXX20Designator,
+ InitializerOverrides,
+ ReorderInitList]>;
 def GNUDesignator : DiagGroup<"gnu-designator">;
 def DtorName : DiagGroup<"dtor-name">;
 
@@ -595,9 +604,6 @@ def NullabilityCompleteness : 
DiagGroup<"nullability-completeness",
 def NullArithmetic : DiagGroup<"null-arithmetic">;
 def NullCharacter : DiagGroup<"null-character">;
 def NullDereference : DiagGroup<"null-dereference">;
-def InitializerOverrides : DiagGroup<"initializer-overrides">;
-// For compatibility with GCC; -Woverride-init = -Winitializer-overrides
-def : DiagGroup<"override-init", [InitializerOverrides]>;
 def NonNull : DiagGroup<"nonnull">;
 def NonPODVarargs : DiagGroup<"non-pod-varargs">;
 def ClassVarargs : DiagGroup<"class-varargs", [NonPODVarargs]>;
@@ -919,9 +925,6 @@ def UsedButMarkedUnused : 
DiagGroup<"used-but-marked-unused">;
 def UsedSearchPath : DiagGroup<"search-path-usage">;
 def UserDefinedLiterals : DiagGroup<"user-defined-literals">;
 def UserDefinedWarnings : DiagGroup<"user-defined-warnings">;
-def ReorderCtor : DiagGroup<"reorder-ctor">;
-def ReorderInitList : DiagGroup<"reorder-init-list">;
-def Reorder : DiagGroup<"reorder", [ReorderCtor, ReorderInitList]>;
 def UndeclaredSelector : DiagGroup<"undeclared-selector">;
 def ImplicitAtomic : DiagGroup<"implicit-atomic-properties">;
 def AtomicAlignment : DiagGroup<"atomic-alignment">;
diff --git a/clang/test/SemaCXX/cxx20-c99-designator.cpp 
b/clang/test/SemaCXX/cxx20-c99-designator.cpp
new file mode 100644
index 0..b8c141a30a261
--- /dev/null
+++ b/clang/test/SemaCXX/cxx20-c99-designator.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=override,reorder 
-Werror=c99-designator %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=override 
-Wno-reorder-init-list -Werror=initializer-overrides %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=reorder 
-Wno-initializer-overrides -Werror=reorder-init-list %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=good -Wno-c99-designator %s
+// good-no-diagnostics
+
+// Ensure that -W

[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t lit… (PR #136542)

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

AaronBallman wrote:

> Another possibility would be to add a new kind of type sugar for these cases 
> that has the same canonical type but knows that it should print as `size_t` / 
> `ptrdiff_t` etc. That'd allow you to produce an identical AST regardless of 
> whether the typedefs are included, which seems like it'd be better for 
> tooling than having the sugared type depend on which includes are present.

Yeah, this is more inline with what I was thinking. Given that both C and C++ 
now have `z`-based literals for `size_t`-based types, I think we want to treat 
`size_t` more like a builtin type than continue to leave it as a magic type.

> When formatting the type, you'd need to decide whether you want to always use 
> `size_t` as the formatted name, or perform some additional check such as 
> performing a name lookup into the global scope or into namespace `std` to see 
> if the type is present and correct, but that's just a type printing policy 
> decision, not something that affects correctness.

+1

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


[clang] [clang] Rework `hasBooleanRepresentation`. (PR #136038)

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

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

LGTM!

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


[clang] [llvm] [Clang] [OpenMP] Support NOWAIT with optional argument (PR #135030)

2025-04-22 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,h -- 
clang/test/OpenMP/nowait_ast_print.cpp clang/include/clang/AST/OpenMPClause.h 
clang/include/clang/AST/RecursiveASTVisitor.h 
clang/include/clang/Sema/SemaOpenMP.h clang/lib/AST/OpenMPClause.cpp 
clang/lib/AST/StmtProfile.cpp clang/lib/Parse/ParseOpenMP.cpp 
clang/lib/Sema/SemaOpenMP.cpp clang/lib/Sema/TreeTransform.h 
clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp 
clang/test/OpenMP/target_enter_data_nowait_messages.cpp 
clang/test/OpenMP/target_exit_data_nowait_messages.cpp 
clang/test/OpenMP/target_nowait_messages.cpp 
clang/test/OpenMP/target_parallel_for_nowait_messages.cpp 
clang/test/OpenMP/target_parallel_for_simd_nowait_messages.cpp 
clang/test/OpenMP/target_parallel_nowait_messages.cpp 
clang/test/OpenMP/target_simd_nowait_messages.cpp 
clang/test/OpenMP/target_teams_distribute_nowait_messages.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_nowait_messages.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_nowait_messages.cpp 
clang/test/OpenMP/target_teams_distribute_simd_nowait_messages.cpp 
clang/test/OpenMP/target_teams_nowait_messages.cpp 
clang/test/OpenMP/target_update_nowait_messages.cpp 
clang/tools/libclang/CIndex.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 76b9d1b50..e78229625 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -16975,7 +16975,8 @@ OMPClause 
*SemaOpenMP::ActOnOpenMPNowaitClause(SourceLocation StartLoc,
 
   QualType T = ValExpr->getType();
   if (T->isFloatingType()) {
-SemaRef.Diag(ValExpr->getExprLoc(), 
diag::err_omp_clause_floating_type_arg)
+SemaRef.Diag(ValExpr->getExprLoc(),
+ diag::err_omp_clause_floating_type_arg)
 << getOpenMPClauseName(OMPC_nowait);
   }
 

``




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


[clang] [llvm] [Clang] [OpenMP] Support NOWAIT with optional argument (PR #128742)

2025-04-22 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,h -- 
clang/test/OpenMP/nowait_ast_print.cpp clang/include/clang/AST/OpenMPClause.h 
clang/include/clang/AST/RecursiveASTVisitor.h 
clang/include/clang/Sema/SemaOpenMP.h clang/lib/AST/OpenMPClause.cpp 
clang/lib/AST/StmtProfile.cpp clang/lib/Parse/ParseOpenMP.cpp 
clang/lib/Sema/SemaOpenMP.cpp clang/lib/Sema/TreeTransform.h 
clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp 
clang/test/OpenMP/target_enter_data_nowait_messages.cpp 
clang/test/OpenMP/target_exit_data_nowait_messages.cpp 
clang/test/OpenMP/target_nowait_messages.cpp 
clang/test/OpenMP/target_parallel_for_nowait_messages.cpp 
clang/test/OpenMP/target_parallel_for_simd_nowait_messages.cpp 
clang/test/OpenMP/target_parallel_nowait_messages.cpp 
clang/test/OpenMP/target_simd_nowait_messages.cpp 
clang/test/OpenMP/target_teams_distribute_nowait_messages.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_nowait_messages.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_nowait_messages.cpp 
clang/test/OpenMP/target_teams_distribute_simd_nowait_messages.cpp 
clang/test/OpenMP/target_teams_nowait_messages.cpp 
clang/test/OpenMP/target_update_nowait_messages.cpp 
clang/tools/libclang/CIndex.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 76b9d1b50..e78229625 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -16975,7 +16975,8 @@ OMPClause 
*SemaOpenMP::ActOnOpenMPNowaitClause(SourceLocation StartLoc,
 
   QualType T = ValExpr->getType();
   if (T->isFloatingType()) {
-SemaRef.Diag(ValExpr->getExprLoc(), 
diag::err_omp_clause_floating_type_arg)
+SemaRef.Diag(ValExpr->getExprLoc(),
+ diag::err_omp_clause_floating_type_arg)
 << getOpenMPClauseName(OMPC_nowait);
   }
 

``




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


[clang] Reland [clang] Handle instantiated members to determine visibility (#136128) (PR #136689)

2025-04-22 Thread Andrew Savonichev via cfe-commits

asavonic wrote:

There are two commits in this review (the main patch and the fix). Let me know 
if you prefer to have separate pull-requests for them.

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


[clang] Reorganize -Winitializer-overrides and -Wreorder-init-list (PR #136586)

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

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


[clang] 3d91a71 - Reorganize -Winitializer-overrides and -Wreorder-init-list (#136586)

2025-04-22 Thread via cfe-commits

Author: Aaron Ballman
Date: 2025-04-22T07:58:03-04:00
New Revision: 3d91a71223801bb73ab3e4ff8ab3f883639ed79f

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

LOG: Reorganize -Winitializer-overrides and -Wreorder-init-list (#136586)

These are both now grouped under -Wc99-designator as they both relate to
the C99 feature as it was introduced into C++20.

Fixes #47037

Added: 
clang/test/SemaCXX/cxx20-c99-designator.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/test/SemaCXX/decltype.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 86d37f5616356..5ccd346a93b4f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -408,6 +408,10 @@ Improvements to Clang's diagnostics
   they're only triggered if the authors are already making the choice to use
   ``preferred_type`` attribute.
 
+- ``-Winitializer-overrides`` and ``-Wreorder-init-list`` are now grouped under
+  the ``-Wc99-designator`` diagnostic group, as they also are about the
+  behavior of the C99 feature as it was introduced into C++20. Fixes #GH47037
+
 Improvements to Clang's time-trace
 --
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index b29fe40b05c6f..59036b695da85 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -184,6 +184,13 @@ def AbstractFinalClass : DiagGroup<"abstract-final-class">;
 def FinalDtorNonFinalClass : DiagGroup<"final-dtor-non-final-class">;
 def GNUOffsetofExtensions : DiagGroup<"gnu-offsetof-extensions">;
 
+def InitializerOverrides : DiagGroup<"initializer-overrides">;
+// For compatibility with GCC; -Woverride-init = -Winitializer-overrides
+def : DiagGroup<"override-init", [InitializerOverrides]>;
+def ReorderCtor : DiagGroup<"reorder-ctor">;
+def ReorderInitList : DiagGroup<"reorder-init-list">;
+def Reorder : DiagGroup<"reorder", [ReorderCtor, ReorderInitList]>;
+
 def CXX11CompatDeprecatedWritableStr :
   DiagGroup<"c++11-compat-deprecated-writable-strings">;
 
@@ -250,7 +257,9 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
 def CXX20Designator : DiagGroup<"c++20-designator">;
 // Allow -Wno-c99-designator to be used to turn off all warnings on valid C99
 // designators (including the warning controlled by -Wc++20-designator).
-def C99Designator : DiagGroup<"c99-designator", [CXX20Designator]>;
+def C99Designator : DiagGroup<"c99-designator", [CXX20Designator,
+ InitializerOverrides,
+ ReorderInitList]>;
 def GNUDesignator : DiagGroup<"gnu-designator">;
 def DtorName : DiagGroup<"dtor-name">;
 
@@ -595,9 +604,6 @@ def NullabilityCompleteness : 
DiagGroup<"nullability-completeness",
 def NullArithmetic : DiagGroup<"null-arithmetic">;
 def NullCharacter : DiagGroup<"null-character">;
 def NullDereference : DiagGroup<"null-dereference">;
-def InitializerOverrides : DiagGroup<"initializer-overrides">;
-// For compatibility with GCC; -Woverride-init = -Winitializer-overrides
-def : DiagGroup<"override-init", [InitializerOverrides]>;
 def NonNull : DiagGroup<"nonnull">;
 def NonPODVarargs : DiagGroup<"non-pod-varargs">;
 def ClassVarargs : DiagGroup<"class-varargs", [NonPODVarargs]>;
@@ -919,9 +925,6 @@ def UsedButMarkedUnused : 
DiagGroup<"used-but-marked-unused">;
 def UsedSearchPath : DiagGroup<"search-path-usage">;
 def UserDefinedLiterals : DiagGroup<"user-defined-literals">;
 def UserDefinedWarnings : DiagGroup<"user-defined-warnings">;
-def ReorderCtor : DiagGroup<"reorder-ctor">;
-def ReorderInitList : DiagGroup<"reorder-init-list">;
-def Reorder : DiagGroup<"reorder", [ReorderCtor, ReorderInitList]>;
 def UndeclaredSelector : DiagGroup<"undeclared-selector">;
 def ImplicitAtomic : DiagGroup<"implicit-atomic-properties">;
 def AtomicAlignment : DiagGroup<"atomic-alignment">;

diff  --git a/clang/test/SemaCXX/cxx20-c99-designator.cpp 
b/clang/test/SemaCXX/cxx20-c99-designator.cpp
new file mode 100644
index 0..b8c141a30a261
--- /dev/null
+++ b/clang/test/SemaCXX/cxx20-c99-designator.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=override,reorder 
-Werror=c99-designator %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=override 
-Wno-reorder-init-list -Werror=initializer-overrides %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=reorder 
-Wno-initializer-overrides -Werror=reorder-init-list %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=good -Wno-c99-designator %s
+// good-no-diagnostics
+
+// Ensure that -Wc99-designator

[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t lit… (PR #136542)

2025-04-22 Thread via cfe-commits

https://github.com/YexuanXiao updated 
https://github.com/llvm/llvm-project/pull/136542

>From b9cc91971469dcf19bb926f6f53ae5a57d1109c3 Mon Sep 17 00:00:00 2001
From: YexuanXiao 
Date: Mon, 21 Apr 2025 14:28:33 +0800
Subject: [PATCH 01/11] [Clang] Make the result type of sizeof/pointer
 subtraction/size_t literals be typedefs instead of built-in types Includeing
 the results of `sizeof`, `sizeof...`, `__datasizeof`, `__alignof`,
 `_Alignof`, `alignof`, `_Countof`, `size_t` literals, and signed `size_t`
 literals, as well as the results of pointer-pointer subtraction. It does not
 affect any program output except for debugging information. The goal is to
 enable clang and downstream tools such as clangd and clang-tidy to provide
 more portable hints and diagnostics.

---
 clang/include/clang/AST/ASTContext.h   |  4 +++
 clang/lib/AST/ASTContext.cpp   | 29 ++
 clang/lib/AST/ComparisonCategories.cpp | 30 ---
 clang/lib/AST/ExprCXX.cpp  |  6 +++--
 clang/lib/Sema/SemaExpr.cpp| 34 --
 5 files changed, 68 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3c78833a3f069..0c133d45d3f5e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2442,6 +2442,10 @@ class ASTContext : public RefCountedBase {
   QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error,
   unsigned *IntegerConstantArgs = nullptr) const;
 
+  QualType getCGlobalCXXStdNSTypedef(const NamespaceDecl *StdNS,
+ StringRef DefName,
+ QualType FallBack = {}) const;
+
   /// Types and expressions required to build C++2a three-way comparisons
   /// using operator<=>, including the values return by builtin <=> operators.
   ComparisonCategories CompCategories;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 2836d68b05ff6..aa8ce0078d4d3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12556,6 +12556,35 @@ QualType ASTContext::GetBuiltinType(unsigned Id,
   return getFunctionType(ResType, ArgTypes, EPI);
 }
 
+QualType ASTContext::getCGlobalCXXStdNSTypedef(const NamespaceDecl *StdNS,
+   StringRef DefName,
+   QualType FallBack) const {
+  DeclContextLookupResult Lookup;
+  if (getLangOpts().C99) {
+Lookup = getTranslationUnitDecl()->lookup(&Idents.get(DefName));
+  } else if (getLangOpts().CPlusPlus) {
+if (StdNS == nullptr) {
+  auto LookupStdNS = getTranslationUnitDecl()->lookup(&Idents.get("std"));
+  if (!LookupStdNS.empty()) {
+StdNS = dyn_cast(LookupStdNS.front());
+  }
+}
+if (StdNS) {
+  Lookup = StdNS->lookup(&Idents.get(DefName));
+} else {
+  Lookup = getTranslationUnitDecl()->lookup(&Idents.get(DefName));
+}
+  }
+  if (!Lookup.empty()) {
+if (auto *TD = dyn_cast(Lookup.front())) {
+  if (auto Result = getTypeDeclType(TD); !Result.isNull()) {
+return Result;
+  }
+}
+  }
+  return FallBack;
+}
+
 static GVALinkage basicGVALinkageForFunction(const ASTContext &Context,
  const FunctionDecl *FD) {
   if (!FD->isExternallyVisible())
diff --git a/clang/lib/AST/ComparisonCategories.cpp 
b/clang/lib/AST/ComparisonCategories.cpp
index 28244104d6636..46dcd6ac4261d 100644
--- a/clang/lib/AST/ComparisonCategories.cpp
+++ b/clang/lib/AST/ComparisonCategories.cpp
@@ -87,37 +87,17 @@ ComparisonCategoryInfo::ValueInfo 
*ComparisonCategoryInfo::lookupValueInfo(
   return &Objects.back();
 }
 
-static const NamespaceDecl *lookupStdNamespace(const ASTContext &Ctx,
-   NamespaceDecl *&StdNS) {
-  if (!StdNS) {
-DeclContextLookupResult Lookup =
-Ctx.getTranslationUnitDecl()->lookup(&Ctx.Idents.get("std"));
-if (!Lookup.empty())
-  StdNS = dyn_cast(Lookup.front());
-  }
-  return StdNS;
-}
-
-static const CXXRecordDecl *lookupCXXRecordDecl(const ASTContext &Ctx,
-const NamespaceDecl *StdNS,
-ComparisonCategoryType Kind) {
-  StringRef Name = ComparisonCategories::getCategoryString(Kind);
-  DeclContextLookupResult Lookup = StdNS->lookup(&Ctx.Idents.get(Name));
-  if (!Lookup.empty())
-if (const CXXRecordDecl *RD = dyn_cast(Lookup.front()))
-  return RD;
-  return nullptr;
-}
-
 const ComparisonCategoryInfo *
 ComparisonCategories::lookupInfo(ComparisonCategoryType Kind) const {
   auto It = Data.find(static_cast(Kind));
   if (It != Data.end())
 return &It->second;
-
-  if (const NamespaceDecl *NS = lookupStdNamespace(Ctx, StdNS))
-if (const CXXRecordDecl *RD = lookupCXXRecordDecl(Ctx, NS, Kind))
+  if (auto Q

[clang] [clang-format] Don't test stability if JS format test fails (PR #136662)

2025-04-22 Thread via cfe-commits

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


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


[clang] [clang-format] Correctly annotate kw_operator in using decls (PR #136545)

2025-04-22 Thread via cfe-commits

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


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


[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t lit… (PR #136542)

2025-04-22 Thread via cfe-commits

https://github.com/YexuanXiao updated 
https://github.com/llvm/llvm-project/pull/136542

>From b9cc91971469dcf19bb926f6f53ae5a57d1109c3 Mon Sep 17 00:00:00 2001
From: YexuanXiao 
Date: Mon, 21 Apr 2025 14:28:33 +0800
Subject: [PATCH 1/9] [Clang] Make the result type of sizeof/pointer
 subtraction/size_t literals be typedefs instead of built-in types Includeing
 the results of `sizeof`, `sizeof...`, `__datasizeof`, `__alignof`,
 `_Alignof`, `alignof`, `_Countof`, `size_t` literals, and signed `size_t`
 literals, as well as the results of pointer-pointer subtraction. It does not
 affect any program output except for debugging information. The goal is to
 enable clang and downstream tools such as clangd and clang-tidy to provide
 more portable hints and diagnostics.

---
 clang/include/clang/AST/ASTContext.h   |  4 +++
 clang/lib/AST/ASTContext.cpp   | 29 ++
 clang/lib/AST/ComparisonCategories.cpp | 30 ---
 clang/lib/AST/ExprCXX.cpp  |  6 +++--
 clang/lib/Sema/SemaExpr.cpp| 34 --
 5 files changed, 68 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3c78833a3f069..0c133d45d3f5e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2442,6 +2442,10 @@ class ASTContext : public RefCountedBase {
   QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error,
   unsigned *IntegerConstantArgs = nullptr) const;
 
+  QualType getCGlobalCXXStdNSTypedef(const NamespaceDecl *StdNS,
+ StringRef DefName,
+ QualType FallBack = {}) const;
+
   /// Types and expressions required to build C++2a three-way comparisons
   /// using operator<=>, including the values return by builtin <=> operators.
   ComparisonCategories CompCategories;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 2836d68b05ff6..aa8ce0078d4d3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12556,6 +12556,35 @@ QualType ASTContext::GetBuiltinType(unsigned Id,
   return getFunctionType(ResType, ArgTypes, EPI);
 }
 
+QualType ASTContext::getCGlobalCXXStdNSTypedef(const NamespaceDecl *StdNS,
+   StringRef DefName,
+   QualType FallBack) const {
+  DeclContextLookupResult Lookup;
+  if (getLangOpts().C99) {
+Lookup = getTranslationUnitDecl()->lookup(&Idents.get(DefName));
+  } else if (getLangOpts().CPlusPlus) {
+if (StdNS == nullptr) {
+  auto LookupStdNS = getTranslationUnitDecl()->lookup(&Idents.get("std"));
+  if (!LookupStdNS.empty()) {
+StdNS = dyn_cast(LookupStdNS.front());
+  }
+}
+if (StdNS) {
+  Lookup = StdNS->lookup(&Idents.get(DefName));
+} else {
+  Lookup = getTranslationUnitDecl()->lookup(&Idents.get(DefName));
+}
+  }
+  if (!Lookup.empty()) {
+if (auto *TD = dyn_cast(Lookup.front())) {
+  if (auto Result = getTypeDeclType(TD); !Result.isNull()) {
+return Result;
+  }
+}
+  }
+  return FallBack;
+}
+
 static GVALinkage basicGVALinkageForFunction(const ASTContext &Context,
  const FunctionDecl *FD) {
   if (!FD->isExternallyVisible())
diff --git a/clang/lib/AST/ComparisonCategories.cpp 
b/clang/lib/AST/ComparisonCategories.cpp
index 28244104d6636..46dcd6ac4261d 100644
--- a/clang/lib/AST/ComparisonCategories.cpp
+++ b/clang/lib/AST/ComparisonCategories.cpp
@@ -87,37 +87,17 @@ ComparisonCategoryInfo::ValueInfo 
*ComparisonCategoryInfo::lookupValueInfo(
   return &Objects.back();
 }
 
-static const NamespaceDecl *lookupStdNamespace(const ASTContext &Ctx,
-   NamespaceDecl *&StdNS) {
-  if (!StdNS) {
-DeclContextLookupResult Lookup =
-Ctx.getTranslationUnitDecl()->lookup(&Ctx.Idents.get("std"));
-if (!Lookup.empty())
-  StdNS = dyn_cast(Lookup.front());
-  }
-  return StdNS;
-}
-
-static const CXXRecordDecl *lookupCXXRecordDecl(const ASTContext &Ctx,
-const NamespaceDecl *StdNS,
-ComparisonCategoryType Kind) {
-  StringRef Name = ComparisonCategories::getCategoryString(Kind);
-  DeclContextLookupResult Lookup = StdNS->lookup(&Ctx.Idents.get(Name));
-  if (!Lookup.empty())
-if (const CXXRecordDecl *RD = dyn_cast(Lookup.front()))
-  return RD;
-  return nullptr;
-}
-
 const ComparisonCategoryInfo *
 ComparisonCategories::lookupInfo(ComparisonCategoryType Kind) const {
   auto It = Data.find(static_cast(Kind));
   if (It != Data.end())
 return &It->second;
-
-  if (const NamespaceDecl *NS = lookupStdNamespace(Ctx, StdNS))
-if (const CXXRecordDecl *RD = lookupCXXRecordDecl(Ctx, NS, Kind))
+  if (auto QT 

[clang] [clang-format] Fix a bug in lexing C++ UDL ending in $ (PR #136476)

2025-04-22 Thread via cfe-commits

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


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


[clang] [clang-format] Fix a bug in parsing C-style cast of lambdas (PR #136099)

2025-04-22 Thread via cfe-commits

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


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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread via cfe-commits

fanju110 wrote:



The following is the Fortran benchmark test data from speccpu2006

|  | Runtime without PGO (Sec) | Runtime with PGO (Sec) | Speedup |
|  | - | -- | --- |
| 410.bwaves   | 101   | 97.6   | 1.03|
| 416.gamess   | 259   | 244| 1.06|
| 434.zeusmp   | 88.8  | 91 | 0.98|
| 437.leslie3d | 94.7  | 94.1   | 1.01|
| 454.calculix | 182   | 180| 1.01|
| 459.GemsFDTD | 176   | 187| 0.94|
| 465.tonto| 118   | 124| 0.95|
| 481.wrf  | 93.4  | 91.4   | 1.02|

* Complier: LLVM 20.1.0
* Options: 
  * without PGO: 
* -O3 -flto -ffast-math 
  * with PGO: 
* -O3 -flto -ffast-math -fprofile-generate
* -O3 -flto -ffast-math -fprofile-use=/file

* Hardware: 11th Gen Intel(R) Core(TM) i9-11900K @ 3.50GHz
* OS: Ubuntu20.04.6 LTS (Focal Fossa)



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


[clang] [lld] [llvm] [X86] Implement disabling APX relocations and EPGR/NDD instrs for relocations (PR #136660)

2025-04-22 Thread Shengchen Kan via cfe-commits

KanRobert wrote:

> Introduce an option (-mapx-relax-relocations) to control the emission of the 
> new APX relocations. It's off by default to keep backward compatibility with 
> old version of ld and other linkers without APX support. And EGPR and NDD are 
> also suppressed to avoid the instructions updated incorrectly by old version 
> of linkers.

Not understand this. IIUC, either we should not emit APX instructions at all, 
which  is controlled by `-m[no-]apxf`, or we should not relax the all the 
relocations, which is controlled by `-Wl,--no-relax`.

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


[clang] [clang][ARM][AArch64] Define intrinsics guarded by __has_builtin on all platforms (PR #128222)

2025-04-22 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

This breaks real-world code with MSVC headers.

Testcase:
```c
#include 
#include 
void func(void) { _InstructionSynchronizationBarrier(); }
```

```
$ bin/clang-cl --target=aarch64-windows-msvc -c isb.c
isb.c(3,19): error: call to undeclared library function '__isb' with type 'void 
(unsigned int)'; ISO C99 and later do not support implicit function 
declarations [-Wimplicit-function-declaration]
3 | void func(void) { _InstructionSynchronizationBarrier(); }
  |   ^
/home/martin/msvc2022-17.13/kits/10/include/10.0.22621.0/um/winnt.h(5717,46): 
note: expanded from macro '_InstructionSynchronizationBarrier'
 5717 | #define _InstructionSynchronizationBarrier() __isb(_ARM64_BARRIER_SY)
  |  ^
isb.c(3,19): note: include the header  or explicitly provide a 
declaration for '__isb'
/home/martin/msvc2022-17.13/kits/10/include/10.0.22621.0/um/winnt.h(5717,46): 
note: expanded from macro '_InstructionSynchronizationBarrier'
 5717 | #define _InstructionSynchronizationBarrier() __isb(_ARM64_BARRIER_SY)
  |  ^
1 error generated.
```


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


[clang] Reland [clang] Handle instantiated members to determine visibility (#136128) (PR #136689)

2025-04-22 Thread Andrew Savonichev via cfe-commits

https://github.com/asavonic created 
https://github.com/llvm/llvm-project/pull/136689

This patchset includes #136128, and adds a fix for regressions that were 
reported by @jplehr and @DKLoehr:

[clang] Fix computeTypeLinkageInfo for non-record member pointers

MemberPointerType can point to records, functions, or types from
template parameters. computeTypeLinkageInfo used to expect only
records, and crash for anything else. It seems that the compiler never
executed this code path before patch 
https://github.com/llvm/llvm-project/pull/136128 where the issue was
reported.

Function member (test74):

MemberPointerType 'type-parameter-0-0 (type-parameter-0-1::*)(void)' 
dependent
|-TemplateTypeParmType 'type-parameter-0-1' dependent depth 0 index 1
`-FunctionProtoType 'type-parameter-0-0 (void)' dependent cdecl
  `-TemplateTypeParmType 'type-parameter-0-0' dependent depth 0 index 0

Template parameter (test75):

MemberPointerType 'type-parameter-0-1 type-parameter-0-0::*' dependent
|-TemplateTypeParmType 'type-parameter-0-0' dependent depth 0 index 0
`-TemplateTypeParmType 'type-parameter-0-1' dependent depth 0 index 1

For non-record types, it should be enough to look at a pointee type to
determine linkage and visibility.

LIT tests 74 and 75 are reduced from Chromium and LLVM libc test
harness as reported in https://github.com/llvm/llvm-project/pull/136128.


>From 677653091bf4ca585c27b1ad30edfa94fe5d0b90 Mon Sep 17 00:00:00 2001
From: Andrew Savonichev 
Date: Mon, 21 Apr 2025 19:45:05 +0900
Subject: [PATCH 1/2] [clang] Fix computeTypeLinkageInfo for non-record member
 pointers

MemberPointerType can point to records, functions, or types from
template parameters. computeTypeLinkageInfo used to expect only
records, and crash for anything else. It seems that the compiler never
executed this code path before patch #136128 where the issue was
reported.

Function member (test74):

MemberPointerType 'type-parameter-0-0 (type-parameter-0-1::*)(void)' 
dependent
|-TemplateTypeParmType 'type-parameter-0-1' dependent depth 0 index 1
`-FunctionProtoType 'type-parameter-0-0 (void)' dependent cdecl
  `-TemplateTypeParmType 'type-parameter-0-0' dependent depth 0 index 0

Template parameter (test75):

MemberPointerType 'type-parameter-0-1 type-parameter-0-0::*' dependent
|-TemplateTypeParmType 'type-parameter-0-0' dependent depth 0 index 0
`-TemplateTypeParmType 'type-parameter-0-1' dependent depth 0 index 1

For non-record types, it should be enough to look at a pointee type to
determine linkage and visibility.

LIT tests 74 and 75 are reduced from Chromium and LLVM libc test
harness as reported in #136128.
---
 clang/lib/AST/Type.cpp   |  6 +++--
 clang/test/CodeGenCXX/visibility.cpp | 37 
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index fe1dc7e2fe786..5783f87012731 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -4787,8 +4787,10 @@ LinkageInfo 
LinkageComputer::computeTypeLinkageInfo(const Type *T) {
 return computeTypeLinkageInfo(cast(T)->getPointeeType());
   case Type::MemberPointer: {
 const auto *MPT = cast(T);
-LinkageInfo LV =
-getDeclLinkageAndVisibility(MPT->getMostRecentCXXRecordDecl());
+LinkageInfo LV;
+if (CXXRecordDecl *D = MPT->getMostRecentCXXRecordDecl()) {
+  LV.merge(getDeclLinkageAndVisibility(D));
+}
 LV.merge(computeTypeLinkageInfo(MPT->getPointeeType()));
 return LV;
   }
diff --git a/clang/test/CodeGenCXX/visibility.cpp 
b/clang/test/CodeGenCXX/visibility.cpp
index e1061f3dbd18f..b4c6fdcbcdf33 100644
--- a/clang/test/CodeGenCXX/visibility.cpp
+++ b/clang/test/CodeGenCXX/visibility.cpp
@@ -1463,3 +1463,40 @@ namespace test71 {
   // CHECK-HIDDEN-LABEL: define linkonce_odr hidden noundef i64 
@_ZN6test713fooIlE3zedEv(
   // CHECK-HIDDEN-LABEL: define linkonce_odr hidden noundef i32 
@_ZN6test713fooIlE3barIiEET_v(
 }
+
+namespace test74 {
+  template  struct T;
+  template 
+  struct T {
+template 
+static __attribute__((__visibility__("hidden"))) void Invoke(M) {
+}
+  };
+
+  struct C;
+  void (C::*MM)();
+
+  void Fun() {
+T::Invoke(0);
+  }
+  // CHECK-LABEL: define linkonce_odr void 
@_ZN6test741TIMNS_1CEFvvEE6InvokeIiEEvT_(
+  // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void 
@_ZN6test741TIMNS_1CEFvvEE6InvokeIiEEvT_(
+}
+
+namespace test75 {
+  template  struct T;
+  template 
+  struct T {
+template 
+static __attribute__((__visibility__("hidden")))
+void Invoke(M) {
+}
+  };
+
+  struct A;
+  void Fun() {
+T::Invoke(0);
+  }
+  // CHECK-LABEL: define linkonce_odr void 
@_ZN6test751TIMNS_1AEFvvEE6InvokeIiEEvT_(
+  // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void 
@_ZN6test751TIMNS_1AEFvvEE6InvokeIiEEvT_(
+}

>From e0118064d9935dad6b3232c1c9503be603d92f87 Mon Sep 17 00:00:00 2001
From: Andrew Savonichev 
Date: Thu, 1

[clang] Reland [clang] Handle instantiated members to determine visibility (#136128) (PR #136689)

2025-04-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Andrew Savonichev (asavonic)


Changes

This patchset includes #136128, and adds a fix for regressions that 
were reported by @jplehr and @DKLoehr:

[clang] Fix computeTypeLinkageInfo for non-record member pointers

MemberPointerType can point to records, functions, or types from
template parameters. computeTypeLinkageInfo used to expect only
records, and crash for anything else. It seems that the compiler never
executed this code path before patch 
https://github.com/llvm/llvm-project/pull/136128 where the issue was
reported.

Function member (test74):

MemberPointerType 'type-parameter-0-0 (type-parameter-0-1::*)(void)' 
dependent
|-TemplateTypeParmType 'type-parameter-0-1' dependent depth 0 index 1
`-FunctionProtoType 'type-parameter-0-0 (void)' dependent cdecl
  `-TemplateTypeParmType 'type-parameter-0-0' dependent depth 0 index 0

Template parameter (test75):

MemberPointerType 'type-parameter-0-1 type-parameter-0-0::*' dependent
|-TemplateTypeParmType 'type-parameter-0-0' dependent depth 0 index 0
`-TemplateTypeParmType 'type-parameter-0-1' dependent depth 0 index 1

For non-record types, it should be enough to look at a pointee type to
determine linkage and visibility.

LIT tests 74 and 75 are reduced from Chromium and LLVM libc test
harness as reported in https://github.com/llvm/llvm-project/pull/136128.


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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/AST/Decl.cpp (+10-3) 
- (modified) clang/lib/AST/Type.cpp (+4-2) 
- (modified) clang/test/CodeGenCXX/visibility.cpp (+74-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 86d37f5616356..9ecd78c13d4e5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -458,6 +458,7 @@ Bug Fixes in This Version
 - Fixed a crash when ``#embed`` appears as a part of a failed constant
   evaluation. The crashes were happening during diagnostics emission due to
   unimplemented statement printer. (#GH132641)
+- Fixed visibility calculation for template functions. (#GH103477)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 1d9208f0e1c72..61d497999b669 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -400,9 +400,9 @@ void LinkageComputer::mergeTemplateLV(
   FunctionTemplateDecl *temp = specInfo->getTemplate();
   // Merge information from the template declaration.
   LinkageInfo tempLV = getLVForDecl(temp, computation);
-  // The linkage of the specialization should be consistent with the
-  // template declaration.
-  LV.setLinkage(tempLV.getLinkage());
+  // The linkage and visibility of the specialization should be
+  // consistent with the template declaration.
+  LV.mergeMaybeWithVisibility(tempLV, considerVisibility);
 
   // Merge information from the template parameters.
   LinkageInfo paramsLV =
@@ -1051,6 +1051,13 @@ LinkageComputer::getLVForClassMember(const NamedDecl *D,
 if (const auto *redeclTemp = dyn_cast(temp)) {
   if (isExplicitMemberSpecialization(redeclTemp)) {
 explicitSpecSuppressor = temp->getTemplatedDecl();
+  } else if (const RedeclarableTemplateDecl *from =
+ redeclTemp->getInstantiatedFromMemberTemplate()) {
+// If no explicit visibility is specified yet, and this is an
+// instantiated member of a template, look up visibility there
+// as well.
+LinkageInfo fromLV = from->getLinkageAndVisibility();
+LV.mergeMaybeWithVisibility(fromLV, considerVisibility);
   }
 }
   }
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index fe1dc7e2fe786..5783f87012731 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -4787,8 +4787,10 @@ LinkageInfo 
LinkageComputer::computeTypeLinkageInfo(const Type *T) {
 return computeTypeLinkageInfo(cast(T)->getPointeeType());
   case Type::MemberPointer: {
 const auto *MPT = cast(T);
-LinkageInfo LV =
-getDeclLinkageAndVisibility(MPT->getMostRecentCXXRecordDecl());
+LinkageInfo LV;
+if (CXXRecordDecl *D = MPT->getMostRecentCXXRecordDecl()) {
+  LV.merge(getDeclLinkageAndVisibility(D));
+}
 LV.merge(computeTypeLinkageInfo(MPT->getPointeeType()));
 return LV;
   }
diff --git a/clang/test/CodeGenCXX/visibility.cpp 
b/clang/test/CodeGenCXX/visibility.cpp
index e1061f3dbd18f..442e2a5aaa2b3 100644
--- a/clang/test/CodeGenCXX/visibility.cpp
+++ b/clang/test/CodeGenCXX/visibility.cpp
@@ -1457,9 +1457,82 @@ namespace test71 {
   // CHECK-LABEL: declare hidden noundef i32 @_ZN6test713fooIiE3zedEv(
   // CHECK-LABEL: define linkonce_odr noundef i32 
@_ZN6test713fooIiE3barIiEET_v(
   // CHECK-LABEL: define linkonce_odr hidden noundef i64 
@_ZN6test713fooIlE3zedEv(
-  // CHECK-LABEL: define linkonce_odr nounde

[libclc] [libclc] Build for OpenCL 3.0 and enable all extensions and features (PR #135733)

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


@@ -429,7 +411,9 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 set( LIBCLC_ARCH_OBJFILE_DIR "${LIBCLC_OBJFILE_DIR}/${arch_suffix}" )
 file( MAKE_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR} )
 
-list( APPEND build_flags -cl-std=${opencl_lang_std} )
+# Build for OpenCL 3.0 and enable all extensions and features independently
+# of the target or device.
+list( APPEND build_flags -cl-std=CL3.0 -Xclang -cl-ext=+all )

frasercrmck wrote:

That makes sense. Then targets could choose not to build builtins for which 
they don't support the appropriate extension.

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


[clang] a35f940 - [clangd] Support operators new and delete in textDocument/references (#135620)

2025-04-22 Thread via cfe-commits

Author: Christian Kandeler
Date: 2025-04-22T10:42:56+02:00
New Revision: a35f940b876a09211f3e68dd25d00271b7195145

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

LOG: [clangd] Support operators new and delete in textDocument/references 
(#135620)

Added: 


Modified: 
clang-tools-extra/clangd/unittests/XRefsTests.cpp
clang/lib/Index/IndexBody.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index 693e965e78a96..1892f87c8e82a 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2303,7 +2303,15 @@ TEST(FindReferences, WithinAST) {
 bool $decl[[operator]]"" _u^dl(unsigned long long value);
 bool x = $(x)[[1_udl]];
   )cpp",
-  };
+  R"cpp(
+struct S {
+public:
+  static void $decl(S)[[operator]] delete(void *);
+  static void deleteObject(S *S) {
+$(S::deleteObject)[[de^lete]] S;
+  }
+};
+  )cpp"};
   for (const char *Test : Tests)
 checkFindRefs(Test);
 }

diff  --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index 5e69987820730..2ed20df22bda0 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -153,6 +153,20 @@ class BodyIndexer : public 
RecursiveASTVisitor {
 ParentDC);
   }
 
+  bool VisitCXXNewExpr(CXXNewExpr *E) {
+if (E->isGlobalNew() || !E->getOperatorNew())
+  return true;
+return IndexCtx.handleReference(E->getOperatorNew(), E->getBeginLoc(),
+Parent, ParentDC);
+  }
+
+  bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
+if (E->isGlobalDelete() || !E->getOperatorDelete())
+  return true;
+return IndexCtx.handleReference(E->getOperatorDelete(), E->getBeginLoc(),
+Parent, ParentDC);
+  }
+
   bool VisitLabelStmt(LabelStmt *S) {
 if (IndexCtx.shouldIndexFunctionLocalSymbols())
   return IndexCtx.handleDecl(S->getDecl());



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


[clang] [clang-tools-extra] [clangd] Support operators new and delete in textDocument/references (PR #135620)

2025-04-22 Thread Christian Kandeler via cfe-commits

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


[clang] [llvm] [RISCV] Add Andes N45/NX45 processor definition (PR #136670)

2025-04-22 Thread Jim Lin via cfe-commits

https://github.com/tclin914 created 
https://github.com/llvm/llvm-project/pull/136670

Andes N45/NX45 are 32/64bit in-order dual-issue 8-stage pipeline CPU 
architecture implementing the RV[32|64]IMAFDC_Zba_Zbb_Zbs ISA extensions.  They 
are developed by Andes Technology https://www.andestech.com, a RISC-V IP 
provider. 

The overviews for N45/NX45:
https://www.andestech.com/en/products-solutions/andescore-processors/riscv-n45/ 
https://www.andestech.com/en/products-solutions/andescore-processors/riscv-nx45/

Scheduling model will be implemented in a later PR.

>From df3a0b2bd9cb31fc8e252e250d3107dd1ac2cc0b Mon Sep 17 00:00:00 2001
From: Jim Lin 
Date: Tue, 22 Apr 2025 10:12:23 +0800
Subject: [PATCH] [RISCV] Add Andes N45/NX45 processor definition

Andes N45/NX45 are 32/64bit in-order dual-issue 8-stage pipeline CPU
architecture with rv[32|64]imafdc_zba_zbb_zbs march.

The overviews for N45/NX45:
https://www.andestech.com/en/products-solutions/andescore-processors/riscv-n45/
https://www.andestech.com/en/products-solutions/andescore-processors/riscv-nx45/

Scheduling model will be implemented in a later PR.
---
 clang/test/Driver/riscv-cpus.c| 34 +++
 .../test/Misc/target-invalid-cpu-note/riscv.c | 12 ---
 llvm/docs/ReleaseNotes.md |  1 +
 llvm/lib/Target/RISCV/RISCVProcessors.td  | 30 
 4 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index c2314efd34aa6..19da8ede26a40 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -692,3 +692,37 @@
 
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=syntacore-scr7 | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR7 %s
 // MTUNE-SYNTACORE-SCR7: "-tune-cpu" "syntacore-scr7"
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=andes-n45 | FileCheck 
-check-prefix=MCPU-ANDES-N45 %s
+// MCPU-ANDES-N45: "-target-cpu" "andes-n45"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+m"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+a"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+f"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+d"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+c"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zicsr"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zifencei"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zba"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zbb"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zbs"
+// MCPU-ANDES-N45-SAME: "-target-abi" "ilp32d"
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=andes-n45 | FileCheck 
-check-prefix=MTUNE-ANDES-N45 %s
+// MTUNE-ANDES-N45: "-tune-cpu" "andes-n45"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=andes-nx45 | FileCheck 
-check-prefix=MCPU-ANDES-NX45 %s
+// MCPU-ANDES-NX45: "-target-cpu" "andes-nx45"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+m"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+a"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+f"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+d"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+c"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zicsr"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zifencei"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zba"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zbb"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zbs"
+// MCPU-ANDES-NX45-SAME: "-target-abi" "lp64d"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=andes-nx45 | FileCheck 
-check-prefix=MTUNE-ANDES-NX45 %s
+// MTUNE-ANDES-NX45: "-tune-cpu" "andes-nx45"
diff --git a/clang/test/Misc/target-invalid-cpu-note/riscv.c 
b/clang/test/Misc/target-invalid-cpu-note/riscv.c
index 199916f70c14f..cd8a8bf95dd7a 100644
--- a/clang/test/Misc/target-invalid-cpu-note/riscv.c
+++ b/clang/test/Misc/target-invalid-cpu-note/riscv.c
@@ -5,7 +5,8 @@
 // RUN: not %clang_cc1 -triple riscv32 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV32
 // RISCV32: error: unknown target CPU 'not-a-cpu'
 // RISCV32-NEXT: note: valid target CPU values are:
-// RISCV32-SAME: {{^}} generic-rv32
+// RISCV32-SAME: {{^}} andes-n45
+// RISCV32-SAME: {{^}}, generic-rv32
 // RISCV32-SAME: {{^}}, rocket-rv32
 // RISCV32-SAME: {{^}}, rp2350-hazard3
 // RISCV32-SAME: {{^}}, sifive-e20
@@ -24,7 +25,8 @@
 // RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV64
 // RISCV64: error: unknown target CPU 'not-a-cpu'
 // RISCV64-NEXT: note: valid target CPU values are:
-// RISCV64-SAME: {{^}} generic-rv64
+// RISCV64-SAME: {{^}} andes-nx45
+// RISCV64-SAME: {{^}}, generic-rv64
 // RISCV64-SAME: {{^}}, mips-p8700
 // RISCV64-SAME: {{^}}, rocket-rv64
 // RISCV64-SAME: {{^}}, sifive-p450
@@ -52,7 +54,8 @@
 // RUN: not %clang_cc1 -triple riscv32 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV32
 // TUNE-RISCV32: error: unknown target CPU 'not-a-cpu'
 // TUNE-RISCV32-NEXT: note: valid t

[clang] [llvm] [RISCV] Add Andes N45/NX45 processor definition (PR #136670)

2025-04-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jim Lin (tclin914)


Changes

Andes N45/NX45 are 32/64bit in-order dual-issue 8-stage pipeline CPU 
architecture implementing the RV[32|64]IMAFDC_Zba_Zbb_Zbs ISA extensions.  They 
are developed by Andes Technology https://www.andestech.com, a RISC-V IP 
provider. 

The overviews for N45/NX45:
https://www.andestech.com/en/products-solutions/andescore-processors/riscv-n45/ 
https://www.andestech.com/en/products-solutions/andescore-processors/riscv-nx45/

Scheduling model will be implemented in a later PR.

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


4 Files Affected:

- (modified) clang/test/Driver/riscv-cpus.c (+34) 
- (modified) clang/test/Misc/target-invalid-cpu-note/riscv.c (+8-4) 
- (modified) llvm/docs/ReleaseNotes.md (+1) 
- (modified) llvm/lib/Target/RISCV/RISCVProcessors.td (+30) 


``diff
diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index c2314efd34aa6..19da8ede26a40 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -692,3 +692,37 @@
 
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=syntacore-scr7 | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR7 %s
 // MTUNE-SYNTACORE-SCR7: "-tune-cpu" "syntacore-scr7"
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=andes-n45 | FileCheck 
-check-prefix=MCPU-ANDES-N45 %s
+// MCPU-ANDES-N45: "-target-cpu" "andes-n45"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+m"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+a"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+f"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+d"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+c"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zicsr"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zifencei"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zba"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zbb"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zbs"
+// MCPU-ANDES-N45-SAME: "-target-abi" "ilp32d"
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=andes-n45 | FileCheck 
-check-prefix=MTUNE-ANDES-N45 %s
+// MTUNE-ANDES-N45: "-tune-cpu" "andes-n45"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=andes-nx45 | FileCheck 
-check-prefix=MCPU-ANDES-NX45 %s
+// MCPU-ANDES-NX45: "-target-cpu" "andes-nx45"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+m"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+a"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+f"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+d"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+c"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zicsr"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zifencei"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zba"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zbb"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zbs"
+// MCPU-ANDES-NX45-SAME: "-target-abi" "lp64d"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=andes-nx45 | FileCheck 
-check-prefix=MTUNE-ANDES-NX45 %s
+// MTUNE-ANDES-NX45: "-tune-cpu" "andes-nx45"
diff --git a/clang/test/Misc/target-invalid-cpu-note/riscv.c 
b/clang/test/Misc/target-invalid-cpu-note/riscv.c
index 199916f70c14f..cd8a8bf95dd7a 100644
--- a/clang/test/Misc/target-invalid-cpu-note/riscv.c
+++ b/clang/test/Misc/target-invalid-cpu-note/riscv.c
@@ -5,7 +5,8 @@
 // RUN: not %clang_cc1 -triple riscv32 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV32
 // RISCV32: error: unknown target CPU 'not-a-cpu'
 // RISCV32-NEXT: note: valid target CPU values are:
-// RISCV32-SAME: {{^}} generic-rv32
+// RISCV32-SAME: {{^}} andes-n45
+// RISCV32-SAME: {{^}}, generic-rv32
 // RISCV32-SAME: {{^}}, rocket-rv32
 // RISCV32-SAME: {{^}}, rp2350-hazard3
 // RISCV32-SAME: {{^}}, sifive-e20
@@ -24,7 +25,8 @@
 // RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV64
 // RISCV64: error: unknown target CPU 'not-a-cpu'
 // RISCV64-NEXT: note: valid target CPU values are:
-// RISCV64-SAME: {{^}} generic-rv64
+// RISCV64-SAME: {{^}} andes-nx45
+// RISCV64-SAME: {{^}}, generic-rv64
 // RISCV64-SAME: {{^}}, mips-p8700
 // RISCV64-SAME: {{^}}, rocket-rv64
 // RISCV64-SAME: {{^}}, sifive-p450
@@ -52,7 +54,8 @@
 // RUN: not %clang_cc1 -triple riscv32 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV32
 // TUNE-RISCV32: error: unknown target CPU 'not-a-cpu'
 // TUNE-RISCV32-NEXT: note: valid target CPU values are:
-// TUNE-RISCV32-SAME: {{^}} generic-rv32
+// TUNE-RISCV32-SAME: {{^}} andes-n45
+// TUNE-RISCV32-SAME: {{^}}, generic-rv32
 // TUNE-RISCV32-SAME: {{^}}, rocket-rv32
 // TUNE-RISCV32-SAME: {{^}}, rp2350-hazard3
 // TUNE-RISCV32-SAME: {{^}}, sifive-e20
@@ -75,7 +78,8 @@
 // RUN: not %clang_cc1 -triple riscv64 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV64
 // TUNE-RISCV64: error: unknown target CPU 'not-a-cpu'
 // TUNE-RISCV64-NEXT: note: valid target CPU values are:
-// 

[clang] [llvm] [RISCV] Add Andes N45/NX45 processor definition (PR #136670)

2025-04-22 Thread via cfe-commits

llvmbot wrote:




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

Author: Jim Lin (tclin914)


Changes

Andes N45/NX45 are 32/64bit in-order dual-issue 8-stage pipeline CPU 
architecture implementing the RV[32|64]IMAFDC_Zba_Zbb_Zbs ISA extensions.  They 
are developed by Andes Technology https://www.andestech.com, a RISC-V IP 
provider. 

The overviews for N45/NX45:
https://www.andestech.com/en/products-solutions/andescore-processors/riscv-n45/ 
https://www.andestech.com/en/products-solutions/andescore-processors/riscv-nx45/

Scheduling model will be implemented in a later PR.

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


4 Files Affected:

- (modified) clang/test/Driver/riscv-cpus.c (+34) 
- (modified) clang/test/Misc/target-invalid-cpu-note/riscv.c (+8-4) 
- (modified) llvm/docs/ReleaseNotes.md (+1) 
- (modified) llvm/lib/Target/RISCV/RISCVProcessors.td (+30) 


``diff
diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index c2314efd34aa6..19da8ede26a40 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -692,3 +692,37 @@
 
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=syntacore-scr7 | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR7 %s
 // MTUNE-SYNTACORE-SCR7: "-tune-cpu" "syntacore-scr7"
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=andes-n45 | FileCheck 
-check-prefix=MCPU-ANDES-N45 %s
+// MCPU-ANDES-N45: "-target-cpu" "andes-n45"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+m"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+a"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+f"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+d"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+c"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zicsr"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zifencei"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zba"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zbb"
+// MCPU-ANDES-N45-SAME: "-target-feature" "+zbs"
+// MCPU-ANDES-N45-SAME: "-target-abi" "ilp32d"
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=andes-n45 | FileCheck 
-check-prefix=MTUNE-ANDES-N45 %s
+// MTUNE-ANDES-N45: "-tune-cpu" "andes-n45"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=andes-nx45 | FileCheck 
-check-prefix=MCPU-ANDES-NX45 %s
+// MCPU-ANDES-NX45: "-target-cpu" "andes-nx45"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+m"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+a"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+f"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+d"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+c"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zicsr"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zifencei"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zba"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zbb"
+// MCPU-ANDES-NX45-SAME: "-target-feature" "+zbs"
+// MCPU-ANDES-NX45-SAME: "-target-abi" "lp64d"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=andes-nx45 | FileCheck 
-check-prefix=MTUNE-ANDES-NX45 %s
+// MTUNE-ANDES-NX45: "-tune-cpu" "andes-nx45"
diff --git a/clang/test/Misc/target-invalid-cpu-note/riscv.c 
b/clang/test/Misc/target-invalid-cpu-note/riscv.c
index 199916f70c14f..cd8a8bf95dd7a 100644
--- a/clang/test/Misc/target-invalid-cpu-note/riscv.c
+++ b/clang/test/Misc/target-invalid-cpu-note/riscv.c
@@ -5,7 +5,8 @@
 // RUN: not %clang_cc1 -triple riscv32 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV32
 // RISCV32: error: unknown target CPU 'not-a-cpu'
 // RISCV32-NEXT: note: valid target CPU values are:
-// RISCV32-SAME: {{^}} generic-rv32
+// RISCV32-SAME: {{^}} andes-n45
+// RISCV32-SAME: {{^}}, generic-rv32
 // RISCV32-SAME: {{^}}, rocket-rv32
 // RISCV32-SAME: {{^}}, rp2350-hazard3
 // RISCV32-SAME: {{^}}, sifive-e20
@@ -24,7 +25,8 @@
 // RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV64
 // RISCV64: error: unknown target CPU 'not-a-cpu'
 // RISCV64-NEXT: note: valid target CPU values are:
-// RISCV64-SAME: {{^}} generic-rv64
+// RISCV64-SAME: {{^}} andes-nx45
+// RISCV64-SAME: {{^}}, generic-rv64
 // RISCV64-SAME: {{^}}, mips-p8700
 // RISCV64-SAME: {{^}}, rocket-rv64
 // RISCV64-SAME: {{^}}, sifive-p450
@@ -52,7 +54,8 @@
 // RUN: not %clang_cc1 -triple riscv32 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV32
 // TUNE-RISCV32: error: unknown target CPU 'not-a-cpu'
 // TUNE-RISCV32-NEXT: note: valid target CPU values are:
-// TUNE-RISCV32-SAME: {{^}} generic-rv32
+// TUNE-RISCV32-SAME: {{^}} andes-n45
+// TUNE-RISCV32-SAME: {{^}}, generic-rv32
 // TUNE-RISCV32-SAME: {{^}}, rocket-rv32
 // TUNE-RISCV32-SAME: {{^}}, rp2350-hazard3
 // TUNE-RISCV32-SAME: {{^}}, sifive-e20
@@ -75,7 +78,8 @@
 // RUN: not %clang_cc1 -triple riscv64 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV64
 // TUNE-RISCV64: error: unknown target CPU 'not-a-cpu'
 // TUNE-RISCV64-NEXT: note: valid target CPU values 

[clang] [llvm] reduce over divergent mask (PR #133228)

2025-04-22 Thread Aniket Lal via cfe-commits

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


[clang] [llvm] [LLVM][SROA] Teach SROA how to "bitcast" between fixed and scalable vectors. (PR #130973)

2025-04-22 Thread Paul Walker via cfe-commits

paulwalker-arm wrote:

ping

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


[clang] 112ffe7 - Add support of the next Ubuntu (Ubuntu 25.10 - Questing Quokka)

2025-04-22 Thread Sylvestre Ledru via cfe-commits

Author: Sylvestre Ledru
Date: 2025-04-22T11:50:58+02:00
New Revision: 112ffe7c621e8bf145c5c5926e36f3af9e0fd045

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

LOG: Add support of the next Ubuntu (Ubuntu 25.10 - Questing Quokka)

Added: 


Modified: 
clang/include/clang/Driver/Distro.h
clang/lib/Driver/Distro.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Distro.h 
b/clang/include/clang/Driver/Distro.h
index b4d485dac8a26..9f27c2baaeb47 100644
--- a/clang/include/clang/Driver/Distro.h
+++ b/clang/include/clang/Driver/Distro.h
@@ -81,6 +81,7 @@ class Distro {
 UbuntuNoble,
 UbuntuOracular,
 UbuntuPlucky,
+UbuntuQuesting,
 UnknownDistro
   };
 
@@ -132,7 +133,7 @@ class Distro {
   }
 
   bool IsUbuntu() const {
-return DistroVal >= UbuntuHardy && DistroVal <= UbuntuPlucky;
+return DistroVal >= UbuntuHardy && DistroVal <= UbuntuQuesting;
   }
 
   bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }

diff  --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp
index 3cc79535de8da..82c627819d9fc 100644
--- a/clang/lib/Driver/Distro.cpp
+++ b/clang/lib/Driver/Distro.cpp
@@ -96,6 +96,7 @@ static Distro::DistroType 
DetectLsbRelease(llvm::vfs::FileSystem &VFS) {
 .Case("noble", Distro::UbuntuNoble)
 .Case("oracular", Distro::UbuntuOracular)
 .Case("plucky", Distro::UbuntuPlucky)
+.Case("questing", Distro::UbuntuQuesting)
 .Default(Distro::UnknownDistro);
   return Version;
 }



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


[clang] [CIR] Make UndefAttr use AttrBuilderWithInferredContext (PR #136605)

2025-04-22 Thread Henrich Lauko via cfe-commits

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


[clang] 53927ab - [CIR] Make ZeroAttr use AttrBuilderWithInferredContext (#136604)

2025-04-22 Thread via cfe-commits

Author: Henrich Lauko
Date: 2025-04-22T08:59:58+02:00
New Revision: 53927ab726e6d0dfb3255498b6d0b130adeafb8c

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

LOG: [CIR] Make ZeroAttr use AttrBuilderWithInferredContext (#136604)

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

Added: 


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

Removed: 




diff  --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index ee8af62ede0da..b303aa07838ee 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -83,21 +83,17 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return getConstPtrAttr(t, 0);
   }
 
-  mlir::TypedAttr getZeroAttr(mlir::Type t) {
-return cir::ZeroAttr::get(getContext(), t);
-  }
-
   mlir::TypedAttr getZeroInitAttr(mlir::Type ty) {
 if (mlir::isa(ty))
   return cir::IntAttr::get(ty, 0);
 if (cir::isAnyFloatingPointType(ty))
   return cir::FPAttr::getZero(ty);
 if (auto arrTy = mlir::dyn_cast(ty))
-  return getZeroAttr(arrTy);
+  return cir::ZeroAttr::get(arrTy);
 if (auto ptrTy = mlir::dyn_cast(ty))
   return getConstNullPtrAttr(ptrTy);
 if (auto recordTy = mlir::dyn_cast(ty))
-  return getZeroAttr(recordTy);
+  return cir::ZeroAttr::get(recordTy);
 if (mlir::isa(ty)) {
   return getFalseAttr();
 }

diff  --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 25ceded7e8a5b..214db1b1caeeb 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -71,6 +71,13 @@ def ZeroAttr : CIR_Attr<"Zero", "zero", 
[TypedAttrInterface]> {
   }];
 
   let parameters = (ins AttributeSelfTypeParameter<"">:$type);
+
+  let builders = [
+AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{
+  return $_get(type.getContext(), type);
+}]>
+  ];
+
   let assemblyFormat = [{}];
 }
 

diff  --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
index 0caa8961ed0a6..b9a74e90a5960 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
@@ -183,7 +183,7 @@ emitArrayConstant(CIRGenModule &cgm, mlir::Type desiredType,
   }
 
   if (nonzeroLength == 0)
-return cir::ZeroAttr::get(builder.getContext(), desiredType);
+return cir::ZeroAttr::get(desiredType);
 
   const unsigned trailingZeroes = arrayBound - nonzeroLength;
 



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


[clang] [CIR] Make ZeroAttr use AttrBuilderWithInferredContext (PR #136604)

2025-04-22 Thread Henrich Lauko via cfe-commits

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


[clang-tools-extra] [clang-tools-extra] Use llvm::unique (NFC) (PR #136514)

2025-04-22 Thread Kazu Hirata via cfe-commits

kazutakahirata wrote:

> May I ask what is the reason for this change? What problem does std::unique 
> have that llvm::unique solves?

- `llvm::unique(Foo)` is shorter than `std::unique(Foo.begin(), and Foo.end())`.
- `llvm::unique(Foo)` prevents us from mistakenly specifying two unrelated 
iterators like `std::unique(This.begin(), That.end())`.

https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ADT/STLExtras.h
 has a collection of similar functions.



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


[clang] [CIR] Make UndefAttr use AttrBuilderWithInferredContext (PR #136605)

2025-04-22 Thread Henrich Lauko via cfe-commits

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

>From ab355262c3a7da4d8089a49d531870bff14d5f8c Mon Sep 17 00:00:00 2001
From: xlauko 
Date: Mon, 21 Apr 2025 22:03:35 +0200
Subject: [PATCH] [CIR] Make UndefAttr use AttrBuilderWithInferredContext

---
 clang/include/clang/CIR/Dialect/IR/CIRAttrs.td | 7 +++
 clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 214db1b1caeeb..dfe15a10fa54e 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -93,6 +93,13 @@ def UndefAttr : CIR_Attr<"Undef", "undef", 
[TypedAttrInterface]> {
   }];
 
   let parameters = (ins AttributeSelfTypeParameter<"">:$type);
+
+  let builders = [
+AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{
+  return $_get(type.getContext(), type);
+}]>
+  ];
+
   let assemblyFormat = [{}];
 }
 
diff --git a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp 
b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
index 9cd5c54e6c19e..fe8a5e7428a81 100644
--- a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
@@ -34,8 +34,8 @@ llvm::SmallVector 
cir::AllocaOp::getPromotableSlots() {
 
 Value cir::AllocaOp::getDefaultValue(const MemorySlot &slot,
  OpBuilder &builder) {
-  return builder.create(
-  getLoc(), slot.elemType, builder.getAttr(slot.elemType));
+  return builder.create(getLoc(), slot.elemType,
+ cir::UndefAttr::get(slot.elemType));
 }
 
 void cir::AllocaOp::handleBlockArgument(const MemorySlot &slot,

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


[clang] [CIR] Make UndefAttr use AttrBuilderWithInferredContext (PR #136605)

2025-04-22 Thread Henrich Lauko via cfe-commits

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

>From e31c61b514c3541d594f67de02b1d495141b4ae3 Mon Sep 17 00:00:00 2001
From: xlauko 
Date: Mon, 21 Apr 2025 22:03:35 +0200
Subject: [PATCH] [CIR] Make UndefAttr use AttrBuilderWithInferredContext

---
 clang/include/clang/CIR/Dialect/IR/CIRAttrs.td | 7 +++
 clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 214db1b1caeeb..dfe15a10fa54e 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -93,6 +93,13 @@ def UndefAttr : CIR_Attr<"Undef", "undef", 
[TypedAttrInterface]> {
   }];
 
   let parameters = (ins AttributeSelfTypeParameter<"">:$type);
+
+  let builders = [
+AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{
+  return $_get(type.getContext(), type);
+}]>
+  ];
+
   let assemblyFormat = [{}];
 }
 
diff --git a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp 
b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
index 9cd5c54e6c19e..fe8a5e7428a81 100644
--- a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
@@ -34,8 +34,8 @@ llvm::SmallVector 
cir::AllocaOp::getPromotableSlots() {
 
 Value cir::AllocaOp::getDefaultValue(const MemorySlot &slot,
  OpBuilder &builder) {
-  return builder.create(
-  getLoc(), slot.elemType, builder.getAttr(slot.elemType));
+  return builder.create(getLoc(), slot.elemType,
+ cir::UndefAttr::get(slot.elemType));
 }
 
 void cir::AllocaOp::handleBlockArgument(const MemorySlot &slot,

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


[clang] [OpenACC][CIR] Implement 'async' lowering. (PR #136626)

2025-04-22 Thread Morris Hafner via cfe-commits


@@ -639,6 +639,9 @@ OpenACCClause 
*SemaOpenACCClauseVisitor::VisitVectorLengthClause(
 
 OpenACCClause *SemaOpenACCClauseVisitor::VisitAsyncClause(
 SemaOpenACC::OpenACCParsedClause &Clause) {
+  if (DisallowSinceLastDeviceType(Clause))

mmha wrote:

Can you update the comment on `DisallowSinceLastDeviceType()` to include 
`async`?

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


[clang] 8639b36 - [CIR] Make UndefAttr use AttrBuilderWithInferredContext (#136605)

2025-04-22 Thread via cfe-commits

Author: Henrich Lauko
Date: 2025-04-22T09:08:49+02:00
New Revision: 8639b365a5988932973a82ffe5e620a9c8ef9039

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

LOG: [CIR] Make UndefAttr use AttrBuilderWithInferredContext (#136605)

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

Added: 


Modified: 
clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp

Removed: 




diff  --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 214db1b1caeeb..dfe15a10fa54e 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -93,6 +93,13 @@ def UndefAttr : CIR_Attr<"Undef", "undef", 
[TypedAttrInterface]> {
   }];
 
   let parameters = (ins AttributeSelfTypeParameter<"">:$type);
+
+  let builders = [
+AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{
+  return $_get(type.getContext(), type);
+}]>
+  ];
+
   let assemblyFormat = [{}];
 }
 

diff  --git a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp 
b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
index 9cd5c54e6c19e..fe8a5e7428a81 100644
--- a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
@@ -34,8 +34,8 @@ llvm::SmallVector 
cir::AllocaOp::getPromotableSlots() {
 
 Value cir::AllocaOp::getDefaultValue(const MemorySlot &slot,
  OpBuilder &builder) {
-  return builder.create(
-  getLoc(), slot.elemType, builder.getAttr(slot.elemType));
+  return builder.create(getLoc(), slot.elemType,
+ cir::UndefAttr::get(slot.elemType));
 }
 
 void cir::AllocaOp::handleBlockArgument(const MemorySlot &slot,



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


[clang] [CIR] Make UndefAttr use AttrBuilderWithInferredContext (PR #136605)

2025-04-22 Thread Henrich Lauko via cfe-commits

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


[clang] [CIR] Let ConstantOp builder infer its type automatically (PR #136606)

2025-04-22 Thread Henrich Lauko via cfe-commits

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


[clang] [clang] add `-fimplicit-constexpr` flag (PR #136436)

2025-04-22 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/136436

From f37eb75b71d2aa6433bc528b7b4532138ae4e62a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sun, 20 Apr 2025 00:24:46 +0200
Subject: [PATCH 1/6] [clang] add -fimplicit-constexpr flag (with same
 behaviour as GCC)

---
 clang/include/clang/AST/Decl.h|   3 +
 .../include/clang/Basic/DiagnosticASTKinds.td |   2 +
 clang/include/clang/Basic/Features.def|   1 +
 clang/include/clang/Basic/LangOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   6 +
 clang/lib/AST/Decl.cpp|  21 
 clang/lib/AST/ExprConstant.cpp|  24 +++-
 clang/lib/Driver/ToolChains/Clang.cpp |   3 +
 clang/lib/Frontend/InitPreprocessor.cpp   |   3 +
 clang/lib/Sema/SemaExpr.cpp   |   6 +-
 clang/test/Sema/implicit-constexpr-basic.cpp  | 112 ++
 .../test/Sema/implicit-constexpr-features.cpp |  81 +
 .../test/Sema/implicit-constexpr-members.cpp  |  83 +
 13 files changed, 339 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/Sema/implicit-constexpr-basic.cpp
 create mode 100644 clang/test/Sema/implicit-constexpr-features.cpp
 create mode 100644 clang/test/Sema/implicit-constexpr-members.cpp

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 3faf63e395a08..be37cb115b24b 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2418,6 +2418,9 @@ class FunctionDecl : public DeclaratorDecl,
   bool isConstexpr() const {
 return getConstexprKind() != ConstexprSpecKind::Unspecified;
   }
+  /// Support for `-fimplicit-constexpr`
+  bool isConstexprOrImplicitlyCanBe(const LangOptions &LangOpts,
+bool MustBeInlined = true) const;
   void setConstexprKind(ConstexprSpecKind CSK) {
 FunctionDeclBits.ConstexprKind = static_cast(CSK);
   }
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index f73963752bb67..57d58a735db85 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -32,6 +32,8 @@ def note_constexpr_lshift_discards : Note<"signed left shift 
discards bits">;
 def note_constexpr_invalid_function : Note<
   "%select{non-constexpr|undefined}0 %select{function|constructor}1 %2 cannot "
   "be used in a constant expression">;
+def note_constexpr_implicit_constexpr_must_be_inlined
+: Note<"non-inline function %0 is not implicitly constexpr">;
 def note_constexpr_invalid_inhctor : Note<
   "constructor inherited from base class %0 cannot be used in a "
   "constant expression; derived class cannot be implicitly initialized">;
diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 14bff8a68846d..2fe9ed3419ee9 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -316,6 +316,7 @@ EXTENSION(matrix_types, LangOpts.MatrixTypes)
 EXTENSION(matrix_types_scalar_division, true)
 EXTENSION(cxx_attributes_on_using_declarations, LangOpts.CPlusPlus11)
 EXTENSION(datasizeof, LangOpts.CPlusPlus)
+EXTENSION(cxx_implicit_constexpr, LangOpts.ImplicitConstexpr)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 930c1c06d1a76..97a271b200976 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -413,6 +413,7 @@ BENIGN_LANGOPT(ArrowDepth, 32, 256,
"maximum number of operator->s to follow")
 BENIGN_LANGOPT(InstantiationDepth, 32, 1024,
"maximum template instantiation depth")
+COMPATIBLE_LANGOPT(ImplicitConstexpr, 1, 0, "make functions implicitly 
'constexpr'")
 BENIGN_LANGOPT(ConstexprCallDepth, 32, 512,
"maximum constexpr call depth")
 BENIGN_LANGOPT(ConstexprStepLimit, 32, 1048576,
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 919c1c643d080..877235147a044 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1991,6 +1991,12 @@ defm constant_cfstrings : 
BoolFOption<"constant-cfstrings",
   "Disable creation of CodeFoundation-type constant strings">,
   PosFlag>;
 def fconstant_string_class_EQ : Joined<["-"], "fconstant-string-class=">, 
Group;
+def fimplicit_constexpr
+: Joined<["-"], "fimplicit-constexpr">,
+  Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"All function declarations will be implicitly constexpr.">,
+  MarshallingInfoFlag>;
 def fconstexpr_depth_EQ : Joined<["-"], "fconstexpr-depth=">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Set the maximum depth of recursive

[clang] [CIR] Make ZeroAttr use AttrBuilderWithInferredContext (PR #136604)

2025-04-22 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-aarch64-ubuntu` 
running on `linaro-lldb-aarch64-ubuntu` while building `clang` at step 6 "test".

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


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

```
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: tools/lldb-dap/databreakpoint/TestDAP_setDataBreakpoints.py 
(1167 of 2125)
PASS: lldb-api :: 
tools/lldb-dap/instruction-breakpoint/TestDAP_instruction_breakpoint.py (1168 
of 2125)
PASS: lldb-api :: tools/lldb-dap/disconnect/TestDAP_disconnect.py (1169 of 2125)
PASS: lldb-api :: tools/lldb-dap/io/TestDAP_io.py (1170 of 2125)
PASS: lldb-api :: tools/lldb-dap/cancel/TestDAP_cancel.py (1171 of 2125)
PASS: lldb-api :: tools/lldb-dap/locations/TestDAP_locations.py (1172 of 2125)
PASS: lldb-api :: terminal/TestEditline.py (1173 of 2125)
PASS: lldb-api :: tools/lldb-dap/optimized/TestDAP_optimized.py (1174 of 2125)
PASS: lldb-api :: tools/lldb-dap/output/TestDAP_output.py (1175 of 2125)
UNRESOLVED: lldb-api :: tools/lldb-dap/memory/TestDAP_memory.py (1176 of 2125)
 TEST 'lldb-api :: tools/lldb-dap/memory/TestDAP_memory.py' 
FAILED 
Script:
--
/usr/bin/python3.10 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/dotest.py
 -u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --env 
LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include 
--env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin 
--arch aarch64 --build-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/lldb 
--compiler /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/clang 
--dsymutil /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/dsymutil 
--make /usr/bin/gmake --llvm-tools-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --lldb-obj-root 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb --lldb-libs-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/memory
 -p TestDAP_memory.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 
53927ab726e6d0dfb3255498b6d0b130adeafb8c)
  clang revision 53927ab726e6d0dfb3255498b6d0b130adeafb8c
  llvm revision 53927ab726e6d0dfb3255498b6d0b130adeafb8c
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 
'debugserver', 'objc']

--
Command Output (stderr):
--
= DEBUG ADAPTER PROTOCOL LOGS =
1745305805.509063721 --> (stdin/stdout) 
{"command":"initialize","type":"request","arguments":{"adapterID":"lldb-native","clientID":"vscode","columnsStartAt1":true,"linesStartAt1":true,"locale":"en-us","pathFormat":"path","supportsRunInTerminalRequest":true,"supportsVariablePaging":true,"supportsVariableType":true,"supportsStartDebuggingRequest":true,"supportsProgressReporting":true,"$__lldb_sourceInitFile":false},"seq":1}
1745305805.511143208 <-- (stdin/stdout) {"body":{"$__lldb_version":"lldb 
version 21.0.0git (https://github.com/llvm/llvm-project.git revision 
53927ab726e6d0dfb3255498b6d0b130adeafb8c)\n  clang revision 
53927ab726e6d0dfb3255498b6d0b130adeafb8c\n  llvm revision 
53927ab726e6d0dfb3255498b6d0b130adeafb8c","completionTriggerCharacters":["."," 
","\t"],"exceptionBreakpointFilters":[{"default":false,"filter":"cpp_catch","label":"C++
 Catch"},{"default":false,"filter":"cpp_throw","label":"C++ 
Throw"},{"default":false,"filter":"objc_catch","label":"Objective-C 
Catch"},{"default":false,"filter":"objc_throw","label":"Objective-C 
Throw"}],"supportTerminateDebuggee":true,"supportsBreakpointLocationsRequest":true,"supportsCancelRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":true,"supportsDelayedStackTraceLoading":true,"supportsDisassembleRequest":true,"supportsEvaluateForHovers":true,"supportsExceptionInfoRequest":true,"supportsExceptionOptions":true,"supportsFunctionBreakpoints":true,"supportsHitConditionalBreakpoints":true,"supportsInstructionBreakpoints":true,"supportsLogPoints":true,"supportsModulesRequest":true,"supportsReadMemoryRequest":true,"supportsRestartRequest":true,"supportsSetVariable":true,"supportsStepInTargetsRequest":true,"supportsSteppingGranularity":true,"supportsValueFormattingOptions":true},"command":"initialize","request_seq":1,"seq":0,"succe

[clang] [CIR] Let ConstantOp builder infer its type automatically (PR #136606)

2025-04-22 Thread Henrich Lauko via cfe-commits

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

>From ac40893c8429a57f11f1be3d60c326ac98de8282 Mon Sep 17 00:00:00 2001
From: xlauko 
Date: Mon, 21 Apr 2025 22:23:40 +0200
Subject: [PATCH] [CIR] Let ConstantOp builder infer its type automatically

---
 clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h | 4 ++--
 clang/include/clang/CIR/Dialect/IR/CIROps.td | 9 -
 clang/lib/CIR/CodeGen/CIRGenBuilder.h| 2 +-
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp   | 4 ++--
 clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp   | 2 +-
 5 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index b303aa07838ee..0385b4f476c3b 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -61,11 +61,11 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 
   mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ,
 const llvm::APInt &val) {
-return create(loc, typ, getAttr(typ, val));
+return create(loc, getAttr(typ, val));
   }
 
   cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) {
-return create(loc, attr.getType(), attr);
+return create(loc, attr);
   }
 
   cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty,
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index b526d077a910c..577cb8db41f57 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -288,18 +288,9 @@ def ConstantOp : CIR_Op<"const",
 ```
   }];
 
-  // The constant operation takes an attribute as the only input.
   let arguments = (ins TypedAttrInterface:$value);
-
-  // The constant operation returns a single value of CIR_AnyType.
   let results = (outs CIR_AnyType:$res);
 
-  let builders = [
-OpBuilder<(ins "cir::BoolAttr":$value), [{
-  build($_builder, $_state, value.getType(), value);
-}]>
-  ];
-
   let assemblyFormat = "attr-dict $value";
 
   let hasVerifier = 1;
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index 4f7ff5128d914..7d9988cc52c5a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -185,7 +185,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
   // Creates constant nullptr for pointer type ty.
   cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc) {
 assert(!cir::MissingFeatures::targetCodeGenInfoGetNullPointer());
-return create(loc, ty, getConstPtrAttr(ty, 0));
+return create(loc, getConstPtrAttr(ty, 0));
   }
 
   mlir::Value createNeg(mlir::Value value) {
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index f1561d1b26fc0..1e69ecae831e9 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -138,7 +138,7 @@ class ScalarExprEmitter : public 
StmtVisitor {
   mlir::Value VisitIntegerLiteral(const IntegerLiteral *e) {
 mlir::Type type = cgf.convertType(e->getType());
 return builder.create(
-cgf.getLoc(e->getExprLoc()), type,
+cgf.getLoc(e->getExprLoc()),
 builder.getAttr(type, e->getValue()));
   }
 
@@ -147,7 +147,7 @@ class ScalarExprEmitter : public 
StmtVisitor {
 assert(mlir::isa(type) &&
"expect floating-point type");
 return builder.create(
-cgf.getLoc(e->getExprLoc()), type,
+cgf.getLoc(e->getExprLoc()),
 builder.getAttr(type, e->getValue()));
   }
 
diff --git a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp 
b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
index fe8a5e7428a81..20b086ffdd850 100644
--- a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
@@ -34,7 +34,7 @@ llvm::SmallVector 
cir::AllocaOp::getPromotableSlots() {
 
 Value cir::AllocaOp::getDefaultValue(const MemorySlot &slot,
  OpBuilder &builder) {
-  return builder.create(getLoc(), slot.elemType,
+  return builder.create(getLoc(),
  cir::UndefAttr::get(slot.elemType));
 }
 

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


[clang] [CIR] Let ConstantOp builder infer its type automatically (PR #136606)

2025-04-22 Thread Henrich Lauko via cfe-commits

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

>From d5d928c7e90129f2a8029a06256689d9e81d831d Mon Sep 17 00:00:00 2001
From: xlauko 
Date: Mon, 21 Apr 2025 22:23:40 +0200
Subject: [PATCH] [CIR] Let ConstantOp builder infer its type automatically

---
 clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h | 4 ++--
 clang/include/clang/CIR/Dialect/IR/CIROps.td | 9 -
 clang/lib/CIR/CodeGen/CIRGenBuilder.h| 2 +-
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp   | 4 ++--
 clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp   | 2 +-
 5 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index b303aa07838ee..0385b4f476c3b 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -61,11 +61,11 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 
   mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ,
 const llvm::APInt &val) {
-return create(loc, typ, getAttr(typ, val));
+return create(loc, getAttr(typ, val));
   }
 
   cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) {
-return create(loc, attr.getType(), attr);
+return create(loc, attr);
   }
 
   cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty,
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index b526d077a910c..577cb8db41f57 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -288,18 +288,9 @@ def ConstantOp : CIR_Op<"const",
 ```
   }];
 
-  // The constant operation takes an attribute as the only input.
   let arguments = (ins TypedAttrInterface:$value);
-
-  // The constant operation returns a single value of CIR_AnyType.
   let results = (outs CIR_AnyType:$res);
 
-  let builders = [
-OpBuilder<(ins "cir::BoolAttr":$value), [{
-  build($_builder, $_state, value.getType(), value);
-}]>
-  ];
-
   let assemblyFormat = "attr-dict $value";
 
   let hasVerifier = 1;
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index 4f7ff5128d914..7d9988cc52c5a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -185,7 +185,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
   // Creates constant nullptr for pointer type ty.
   cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc) {
 assert(!cir::MissingFeatures::targetCodeGenInfoGetNullPointer());
-return create(loc, ty, getConstPtrAttr(ty, 0));
+return create(loc, getConstPtrAttr(ty, 0));
   }
 
   mlir::Value createNeg(mlir::Value value) {
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index f1561d1b26fc0..1e69ecae831e9 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -138,7 +138,7 @@ class ScalarExprEmitter : public 
StmtVisitor {
   mlir::Value VisitIntegerLiteral(const IntegerLiteral *e) {
 mlir::Type type = cgf.convertType(e->getType());
 return builder.create(
-cgf.getLoc(e->getExprLoc()), type,
+cgf.getLoc(e->getExprLoc()),
 builder.getAttr(type, e->getValue()));
   }
 
@@ -147,7 +147,7 @@ class ScalarExprEmitter : public 
StmtVisitor {
 assert(mlir::isa(type) &&
"expect floating-point type");
 return builder.create(
-cgf.getLoc(e->getExprLoc()), type,
+cgf.getLoc(e->getExprLoc()),
 builder.getAttr(type, e->getValue()));
   }
 
diff --git a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp 
b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
index fe8a5e7428a81..20b086ffdd850 100644
--- a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
@@ -34,7 +34,7 @@ llvm::SmallVector 
cir::AllocaOp::getPromotableSlots() {
 
 Value cir::AllocaOp::getDefaultValue(const MemorySlot &slot,
  OpBuilder &builder) {
-  return builder.create(getLoc(), slot.elemType,
+  return builder.create(getLoc(),
  cir::UndefAttr::get(slot.elemType));
 }
 

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


[clang] 56f5bcb - [CIR] Let ConstantOp builder infer its type automatically (#136606)

2025-04-22 Thread via cfe-commits

Author: Henrich Lauko
Date: 2025-04-22T09:15:59+02:00
New Revision: 56f5bcb0350b8af44aa5f65ccf865a464df2cc4a

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

LOG: [CIR] Let ConstantOp builder infer its type automatically (#136606)

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

Added: 


Modified: 
clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
clang/include/clang/CIR/Dialect/IR/CIROps.td
clang/lib/CIR/CodeGen/CIRGenBuilder.h
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp

Removed: 




diff  --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index b303aa07838ee..0385b4f476c3b 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -61,11 +61,11 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 
   mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ,
 const llvm::APInt &val) {
-return create(loc, typ, getAttr(typ, val));
+return create(loc, getAttr(typ, val));
   }
 
   cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) {
-return create(loc, attr.getType(), attr);
+return create(loc, attr);
   }
 
   cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty,

diff  --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index b526d077a910c..577cb8db41f57 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -288,18 +288,9 @@ def ConstantOp : CIR_Op<"const",
 ```
   }];
 
-  // The constant operation takes an attribute as the only input.
   let arguments = (ins TypedAttrInterface:$value);
-
-  // The constant operation returns a single value of CIR_AnyType.
   let results = (outs CIR_AnyType:$res);
 
-  let builders = [
-OpBuilder<(ins "cir::BoolAttr":$value), [{
-  build($_builder, $_state, value.getType(), value);
-}]>
-  ];
-
   let assemblyFormat = "attr-dict $value";
 
   let hasVerifier = 1;

diff  --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index 4f7ff5128d914..7d9988cc52c5a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -185,7 +185,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
   // Creates constant nullptr for pointer type ty.
   cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc) {
 assert(!cir::MissingFeatures::targetCodeGenInfoGetNullPointer());
-return create(loc, ty, getConstPtrAttr(ty, 0));
+return create(loc, getConstPtrAttr(ty, 0));
   }
 
   mlir::Value createNeg(mlir::Value value) {

diff  --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index f1561d1b26fc0..1e69ecae831e9 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -138,7 +138,7 @@ class ScalarExprEmitter : public 
StmtVisitor {
   mlir::Value VisitIntegerLiteral(const IntegerLiteral *e) {
 mlir::Type type = cgf.convertType(e->getType());
 return builder.create(
-cgf.getLoc(e->getExprLoc()), type,
+cgf.getLoc(e->getExprLoc()),
 builder.getAttr(type, e->getValue()));
   }
 
@@ -147,7 +147,7 @@ class ScalarExprEmitter : public 
StmtVisitor {
 assert(mlir::isa(type) &&
"expect floating-point type");
 return builder.create(
-cgf.getLoc(e->getExprLoc()), type,
+cgf.getLoc(e->getExprLoc()),
 builder.getAttr(type, e->getValue()));
   }
 

diff  --git a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp 
b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
index fe8a5e7428a81..20b086ffdd850 100644
--- a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
@@ -34,7 +34,7 @@ llvm::SmallVector 
cir::AllocaOp::getPromotableSlots() {
 
 Value cir::AllocaOp::getDefaultValue(const MemorySlot &slot,
  OpBuilder &builder) {
-  return builder.create(getLoc(), slot.elemType,
+  return builder.create(getLoc(),
  cir::UndefAttr::get(slot.elemType));
 }
 



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


[clang] [CIR] Let ConstantOp builder infer its type automatically (PR #136606)

2025-04-22 Thread Henrich Lauko via cfe-commits

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


[clang] [clang-format] Don't test stability if JS format test fails (PR #136662)

2025-04-22 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/136662

None

>From 6f974f65a1f7b52d00e75afaad8201b748f7357a Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 22 Apr 2025 00:12:51 -0700
Subject: [PATCH] [clang-format] Don't test stability if JS format test fails

---
 clang/unittests/Format/FormatTestJS.cpp | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index 1cfacc060d944..91577b9a49167 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -48,18 +48,22 @@ class FormatTestJS : public testing::Test {
   static void verifyFormat(
   StringRef Code,
   const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) {
-EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not 
stable";
-std::string Result = format(test::messUp(Code), Style);
-EXPECT_EQ(Code.str(), Result) << "Formatted:\n" << Result;
+auto Result = format(test::messUp(Code), Style);
+EXPECT_EQ(Code, Result) << "Formatted:\n" << Result;
+if (Code != Result)
+  return;
+EXPECT_EQ(Code, format(Code, Style)) << "Expected code is not stable";
   }
 
   static void verifyFormat(
   StringRef Expected, StringRef Code,
   const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) {
-EXPECT_EQ(Expected.str(), format(Expected, Style))
+auto Result = format(Code, Style);
+EXPECT_EQ(Expected, Result) << "Formatted:\n" << Result;
+if (Expected != Result)
+  return;
+EXPECT_EQ(Expected, format(Expected, Style))
 << "Expected code is not stable";
-std::string Result = format(Code, Style);
-EXPECT_EQ(Expected.str(), Result) << "Formatted:\n" << Result;
   }
 };
 

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


[clang] [clang-format] Don't test stability if JS format test fails (PR #136662)

2025-04-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes



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


1 Files Affected:

- (modified) clang/unittests/Format/FormatTestJS.cpp (+10-6) 


``diff
diff --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index 1cfacc060d944..91577b9a49167 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -48,18 +48,22 @@ class FormatTestJS : public testing::Test {
   static void verifyFormat(
   StringRef Code,
   const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) {
-EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not 
stable";
-std::string Result = format(test::messUp(Code), Style);
-EXPECT_EQ(Code.str(), Result) << "Formatted:\n" << Result;
+auto Result = format(test::messUp(Code), Style);
+EXPECT_EQ(Code, Result) << "Formatted:\n" << Result;
+if (Code != Result)
+  return;
+EXPECT_EQ(Code, format(Code, Style)) << "Expected code is not stable";
   }
 
   static void verifyFormat(
   StringRef Expected, StringRef Code,
   const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) {
-EXPECT_EQ(Expected.str(), format(Expected, Style))
+auto Result = format(Code, Style);
+EXPECT_EQ(Expected, Result) << "Formatted:\n" << Result;
+if (Expected != Result)
+  return;
+EXPECT_EQ(Expected, format(Expected, Style))
 << "Expected code is not stable";
-std::string Result = format(Code, Style);
-EXPECT_EQ(Expected.str(), Result) << "Formatted:\n" << Result;
   }
 };
 

``




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


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

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

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


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

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

djtodoro wrote:

I will postpone this PR until I prepare big endian support, thank you all for 
the comments!

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


[clang] [llvm] [clang][OpenMP][SPIR-V] Fix AS of globals and set the default AS to 4 (PR #135251)

2025-04-22 Thread Dmitry Sidorov via cfe-commits


@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown 
-fopenmp-targets=spirv64 -emit-llvm-bc %s -o %t-host.bc
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=spirv64 -fopenmp-is-target-device 
-triple spirv64 -fopenmp-host-ir-file-path %t-host.bc -emit-llvm %s -o - | 
FileCheck %s
+
+int main() {
+  int x = 0;
+
+#pragma omp target teams distribute parallel for simd
+  for(int i = 0; i < 1024; i++)
+x+=i;
+  return x;
+}
+
+// CHECK: @[[#STRLOC:]] = private unnamed_addr addrspace(1) constant [{{.*}} x 
i8] c{{.*}}, align 1
+// CHECK: @[[#IDENT:]] = private unnamed_addr addrspace(1) constant 
%struct.ident_t { i32 {{.*}}, i32 2050, i32 {{.*}}, i32 {{.*}}, ptr 
addrspacecast (ptr addrspace(1) @[[#STRLOC]] to ptr) }, align 8
+// CHECK: define internal spir_func void 
@__omp_offloading_{{.*}}_omp_outlined(ptr addrspace(4) noalias noundef {{.*}}., 
ptr addrspace(4) noalias noundef {{.*}}, i64 noundef {{.*}}) #{{.*}} {
+// CHECK: = load ptr addrspace(4), ptr addrspace(4) %{{.*}}, align 8
+// CHECK: = load i32, ptr addrspace(4) %{{.*}}, align 4
+// CHECK: = addrspacecast ptr addrspace(4) %{{.*}} to ptr
+// CHECK: = addrspacecast ptr addrspace(4) %{{.*}} to ptr
+// CHECK: = addrspacecast ptr addrspace(4) %{{.*}} to ptr
+// CHECK: = addrspacecast ptr addrspace(4) %{{.*}} to ptr
+// CHECK: call spir_func void @__kmpc_distribute_static_init{{.*}}(ptr 
addrspacecast (ptr addrspace(1) @[[#IDENT]] to ptr), i32 %{{.*}}, i32 {{.*}}, 
ptr %{{.*}}, ptr %{{.*}}, ptr %{{.*}}, ptr %{{.*}}, i32 {{.*}}, i32 %{{.*}})

MrSidims wrote:

This looks wrong. Casts from global to private are not allowed in SPIR and 
SPIR-V.

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


[clang] e12681a - [clang-cl] Parse the /dynamicdeopt option

2025-04-22 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2025-04-22T11:11:33+02:00
New Revision: e12681ae733e8341c161534d4d4de2611573b616

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

LOG: [clang-cl] Parse the /dynamicdeopt option

which was mentioned in
https://devblogs.microsoft.com/cppblog/cpp-dynamic-debugging-full-debuggability-for-optimized-builds/

(That post also mentions /d2DDTrimInlines, which we already parse via
a /d2 catch-all.)

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/cl-options.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8224e734a5a5c..a9f4083920663 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -9079,6 +9079,7 @@ def _SLASH_clr : CLJoined<"clr">;
 def _SLASH_d1 : CLJoined<"d1">;
 def _SLASH_d2 : CLJoined<"d2">;
 def _SLASH_doc : CLJoined<"doc">;
+def _SLASH_dynamicdeopt : CLJoined<"dynamicdeopt">;
 def _SLASH_experimental : CLJoined<"experimental:">;
 def _SLASH_exportHeader : CLFlag<"exportHeader">;
 def _SLASH_external : CLJoined<"external:">;

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index eb4c74378f9d7..beaef09c8a8d9 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -437,7 +437,9 @@
 // RUN: /d1import_no_registry \
 // RUN: /d1nodatetime \
 // RUN: /d2FH4 \
+// RUN: /d2TrimInlines \
 // RUN: /docname \
+// RUN: /dynamicdeopt \
 // RUN: /experimental:external \
 // RUN: /experimental:module \
 // RUN: /experimental:preprocessor \



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


[clang] [llvm] [ARM] Adding diagnostics for mcmodel=tiny when used in invalid targets (PR #125643)

2025-04-22 Thread via cfe-commits

https://github.com/ShashwathiNavada updated 
https://github.com/llvm/llvm-project/pull/125643

>From 0aebcd7119fbcd51154c5d9706752e8ff3f041bc Mon Sep 17 00:00:00 2001
From: ShashwathiNavada 
Date: Tue, 4 Feb 2025 00:16:09 -0600
Subject: [PATCH 1/9] Adding diagnostics for unsupported option

---
 clang/lib/Frontend/CompilerInvocation.cpp | 9 +
 1 file changed, 9 insertions(+)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 11fd6ab7f52a7..ac8d8be572012 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1897,6 +1897,15 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
&Opts, ArgList &Args,
 Opts.setInlining(CodeGenOptions::NormalInlining);
   }
 
+// -mcmodel option.
+if (const llvm::opt::Arg *A = 
Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) 
+{
+llvm::StringRef modelName = A->getValue();
+if(modelName=="tiny" && !T.isARM())
+  Diags.Report(diag::err_drv_unsupported_option_argument_for_target) 
+  << A->getSpelling() getValue();
 if(modelName=="tiny" && !T.isARM())
-  Diags.Report(diag::err_drv_unsupported_option_argument_for_target) 
-  << A->getSpelling() From 689dc3a3472ff8270ee9631b235e776f5fa1a27f Mon Sep 17 00:00:00 2001
From: ShashwathiNavada 
Date: Tue, 4 Feb 2025 00:49:37 -0600
Subject: [PATCH 3/9] minor changes

---
 clang/lib/Frontend/CompilerInvocation.cpp | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 1242073ea6746..15d382620d279 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1896,13 +1896,15 @@ bool 
CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
   } else {
 Opts.setInlining(CodeGenOptions::NormalInlining);
   }
-
- // -mcmodel option.
-  if (const llvm::opt::Arg *A = 
Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)){
+ 
+  // -mcmodel option.
+  if (const llvm::opt::Arg *A =
+  Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) {
 llvm::StringRef modelName = A->getValue();
-if(modelName=="tiny" && !T.isARM())
+if (modelName == "tiny" && !T.isARM()) {
   Diags.Report(diag::err_drv_unsupported_option_argument_for_target)
-  << A->getSpelling() << modelName << T.getTriple();  
+  << A->getSpelling() << modelName << T.getTriple();
+}
   }
 
   // PIC defaults to -fno-direct-access-external-data while non-PIC defaults to

>From 28fcb0ee20645cd1d30dd15bfd7f6eff402ba2b9 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada 
Date: Tue, 4 Feb 2025 01:01:00 -0600
Subject: [PATCH 4/9] minor changes

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

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 15d382620d279..f858ec2234cb5 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1896,7 +1896,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
&Opts, ArgList &Args,
   } else {
 Opts.setInlining(CodeGenOptions::NormalInlining);
   }
- 
+
   // -mcmodel option.
   if (const llvm::opt::Arg *A =
   Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) {

>From 843d4ccf4c41a78397e14eb5d9459a4921325741 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada 
Date: Tue, 4 Feb 2025 21:39:44 +0530
Subject: [PATCH 5/9] Addressed build fail

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

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index f858ec2234cb5..48f66931af06c 10064

[clang] [lld] [llvm] [X86] Implement disabling APX relocations and EPGR/NDD instrs for relocations (PR #136660)

2025-04-22 Thread Feng Zou via cfe-commits

fzou1 wrote:

> > Introduce an option (-mapx-relax-relocations) to control the emission of 
> > the new APX relocations. It's off by default to keep backward compatibility 
> > with old version of ld and other linkers without APX support. And EGPR and 
> > NDD are also suppressed to avoid the instructions updated incorrectly by 
> > old version of linkers.
> 
> Not understand this. IIUC, either we should not emit APX instructions at all, 
> which is controlled by `-m[no-]apxf`, or we should not relax the all the 
> relocations, which is controlled by `-Wl,--no-relax`.

If the APX relocation types are emitted in MC, they cannot be recognized by old 
version of linkers. It leads to APX features unavailable on existing Linux OSes 
with old version of linkers. `--no-relax` just disables the GOT optimization in 
linker, and it cannot resolve the link error of unsupported relocation type as 
mentioned above.

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


[clang-tools-extra] [clangd] Store documentation when indexing standard library (PR #133681)

2025-04-22 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

> 1.  we no longer use SymbolOrigin::StdLib for collected symbols

thanks for catching that, I think that's OK to pass in an extra `SymbolOrigin` 
flag here.

> 2. we run the symbol collector with CollectMainFileSymbols = true

I think this is WAI. Firstly we shouldn't have (m)any symbols in main-file when 
running stdlib indexing (as we just stitch together a file that `#include 
<...>` all stdlib headers we know of). but even if we run into some, these 
symbols are all part of the preamble section. hence even-if they're main-file 
only, they should get the same treatment as any other preamble symbol.

This also ensures we don't get different behavior if `` is indexed 
through preamble-index vs stdlib-index first.

> 3. we use the indexing option SystemSymbolFilterKind::DeclarationsOnly

agreed that this sounds like an improvement.

> 4. we no longer use 
> [this](https://searchfox.org/llvm/rev/bb21a6819b3fb9d689de776f7ee768030dfbacea/clang-tools-extra/clangd/index/IndexAction.cpp#143-148)
>  "deeply nested" optimization

I think this was just an oversight, we should probably have that in 
`indexSymbols` too. This can be a separate patch though.

> If that seems preferable to you over adding a parameter to 
> createStaticIndexingAction

Just to be clear, my concern is not about adding more knobs to 
`createStaticIndexingAction`, but rather it being the wrong fix. As your 
analysis revealed we actually had many more discrepancies between dynamic-index 
and stdlib-index. Amending `createStaticIndexingAction` to look more like 
dynamic-index will just blur the line between static and dynamic index, which 
sounds undesired overall.

> I'm happy to revise the patch along these lines.

That would be great, thanks a lot for taking care of this!

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


[clang] [llvm] reduce max wrt divergent mask (PR #135138)

2025-04-22 Thread Aniket Lal via cfe-commits

https://github.com/lalaniket8 updated 
https://github.com/llvm/llvm-project/pull/135138

>From a4b91e537441d9edba0d39d21eab7e150a066049 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Tue, 22 Apr 2025 13:52:27 +0530
Subject: [PATCH] reduce builtin compiler implementation

---
 clang/include/clang/Basic/BuiltinsAMDGPU.def |   2 +
 clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp  |  18 ++
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td |  14 ++
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp| 204 ++-
 llvm/lib/Target/AMDGPU/SIInstructions.td |  12 ++
 5 files changed, 244 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 39fef9e4601f8..11765a113a518 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -366,6 +366,8 @@ BUILTIN(__builtin_r600_read_tidig_z, "Ui", "nc")
 BUILTIN(__builtin_r600_recipsqrt_ieee, "dd", "nc")
 BUILTIN(__builtin_r600_recipsqrt_ieeef, "ff", "nc")
 
+BUILTIN(__builtin_amdgcn_wave_reduce_wrt_divergent_mask_max_i32, "", "nc")
+
 
//===--===//
 // MFMA builtins.
 
//===--===//
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp 
b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index ad012d98635ff..d6a20d61741d7 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -274,6 +274,15 @@ void 
CodeGenFunction::AddAMDGPUFenceAddressSpaceMMRA(llvm::Instruction *Inst,
   Inst->setMetadata(LLVMContext::MD_mmra, MMRAMetadata::getMD(Ctx, MMRAs));
 }
 
+static Intrinsic::ID getIntrinsicIDforWaveReduction(unsigned BuiltinID) {
+  switch (BuiltinID) {
+  case 
clang::AMDGPU::BI__builtin_amdgcn_wave_reduce_wrt_divergent_mask_max_i32:
+return Intrinsic::amdgcn_wave_reduce_wrt_divergent_mask_umax;
+  default:
+llvm_unreachable("Unknown BuiltinID for wave reduction");
+  }
+}
+
 Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
   const CallExpr *E) {
   llvm::AtomicOrdering AO = llvm::AtomicOrdering::SequentiallyConsistent;
@@ -1179,6 +1188,15 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_s_prefetch_data:
 return emitBuiltinWithOneOverloadedType<2>(
 *this, E, Intrinsic::amdgcn_s_prefetch_data);
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_wrt_divergent_mask_max_i32: {
+Intrinsic::ID IID = getIntrinsicIDforWaveReduction(BuiltinID);
+llvm::Value *Value = EmitScalarExpr(E->getArg(0));
+llvm::Value *Mask = EmitScalarExpr(E->getArg(1));
+llvm::Value *Strategy = EmitScalarExpr(E->getArg(2));
+// llvm::errs() << "Value->getType():" << Value->getType() << "\n";
+llvm::Function *F = CGM.getIntrinsic(IID, {Value->getType()});
+return Builder.CreateCall(F, {Value, Mask, Strategy});
+  }
   default:
 return nullptr;
   }
diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td 
b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index 75068717d9a5f..c155a75852473 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -2343,6 +2343,20 @@ class AMDGPUWaveReduce : Intrinsic<
 def int_amdgcn_wave_reduce_umin : AMDGPUWaveReduce;
 def int_amdgcn_wave_reduce_umax : AMDGPUWaveReduce;
 
+class AMDGPUWaveReduceWrtDivergentMask : 
Intrinsic<
+[data_ty],
+[
+  LLVMMatchType<0>,   // llvm value to reduce (SGPR/VGPR),
+  llvm_i32_ty,// Divergent mask
+  llvm_i32_ty // Reduction Strategy Switch for lowering ( 0: 
Default,
+  //  1: 
Iterative strategy, and
+  //  2. DPP)
+],
+[IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree, 
ImmArg>]>;
+
+def int_amdgcn_wave_reduce_wrt_divergent_mask_umin : 
AMDGPUWaveReduceWrtDivergentMask;
+def int_amdgcn_wave_reduce_wrt_divergent_mask_umax : 
AMDGPUWaveReduceWrtDivergentMask;
+
 def int_amdgcn_readfirstlane :
   Intrinsic<[llvm_any_ty], [LLVMMatchType<0>],
 [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, 
IntrNoFree]>;
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp 
b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 724a45062c1f4..f85bcccf6b142 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -5030,12 +5030,18 @@ static MachineBasicBlock *lowerWaveReduce(MachineInstr 
&MI,
   Register SrcReg = MI.getOperand(1).getReg();
   bool isSGPR = TRI->isSGPRClass(MRI.getRegClass(SrcReg));
   Register DstReg = MI.getOperand(0).getReg();
+  bool isDstSGPR = TRI->isSGPRClass(MRI.getRegClass(DstReg));
+
   MachineBasicBlock *RetBB = nullptr;
   if (isSGPR) {
 // Thes

[clang] [clang] add `-fimplicit-constexpr` flag (PR #136436)

2025-04-22 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/136436

From f37eb75b71d2aa6433bc528b7b4532138ae4e62a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sun, 20 Apr 2025 00:24:46 +0200
Subject: [PATCH 1/7] [clang] add -fimplicit-constexpr flag (with same
 behaviour as GCC)

---
 clang/include/clang/AST/Decl.h|   3 +
 .../include/clang/Basic/DiagnosticASTKinds.td |   2 +
 clang/include/clang/Basic/Features.def|   1 +
 clang/include/clang/Basic/LangOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   6 +
 clang/lib/AST/Decl.cpp|  21 
 clang/lib/AST/ExprConstant.cpp|  24 +++-
 clang/lib/Driver/ToolChains/Clang.cpp |   3 +
 clang/lib/Frontend/InitPreprocessor.cpp   |   3 +
 clang/lib/Sema/SemaExpr.cpp   |   6 +-
 clang/test/Sema/implicit-constexpr-basic.cpp  | 112 ++
 .../test/Sema/implicit-constexpr-features.cpp |  81 +
 .../test/Sema/implicit-constexpr-members.cpp  |  83 +
 13 files changed, 339 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/Sema/implicit-constexpr-basic.cpp
 create mode 100644 clang/test/Sema/implicit-constexpr-features.cpp
 create mode 100644 clang/test/Sema/implicit-constexpr-members.cpp

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 3faf63e395a08..be37cb115b24b 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2418,6 +2418,9 @@ class FunctionDecl : public DeclaratorDecl,
   bool isConstexpr() const {
 return getConstexprKind() != ConstexprSpecKind::Unspecified;
   }
+  /// Support for `-fimplicit-constexpr`
+  bool isConstexprOrImplicitlyCanBe(const LangOptions &LangOpts,
+bool MustBeInlined = true) const;
   void setConstexprKind(ConstexprSpecKind CSK) {
 FunctionDeclBits.ConstexprKind = static_cast(CSK);
   }
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index f73963752bb67..57d58a735db85 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -32,6 +32,8 @@ def note_constexpr_lshift_discards : Note<"signed left shift 
discards bits">;
 def note_constexpr_invalid_function : Note<
   "%select{non-constexpr|undefined}0 %select{function|constructor}1 %2 cannot "
   "be used in a constant expression">;
+def note_constexpr_implicit_constexpr_must_be_inlined
+: Note<"non-inline function %0 is not implicitly constexpr">;
 def note_constexpr_invalid_inhctor : Note<
   "constructor inherited from base class %0 cannot be used in a "
   "constant expression; derived class cannot be implicitly initialized">;
diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 14bff8a68846d..2fe9ed3419ee9 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -316,6 +316,7 @@ EXTENSION(matrix_types, LangOpts.MatrixTypes)
 EXTENSION(matrix_types_scalar_division, true)
 EXTENSION(cxx_attributes_on_using_declarations, LangOpts.CPlusPlus11)
 EXTENSION(datasizeof, LangOpts.CPlusPlus)
+EXTENSION(cxx_implicit_constexpr, LangOpts.ImplicitConstexpr)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 930c1c06d1a76..97a271b200976 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -413,6 +413,7 @@ BENIGN_LANGOPT(ArrowDepth, 32, 256,
"maximum number of operator->s to follow")
 BENIGN_LANGOPT(InstantiationDepth, 32, 1024,
"maximum template instantiation depth")
+COMPATIBLE_LANGOPT(ImplicitConstexpr, 1, 0, "make functions implicitly 
'constexpr'")
 BENIGN_LANGOPT(ConstexprCallDepth, 32, 512,
"maximum constexpr call depth")
 BENIGN_LANGOPT(ConstexprStepLimit, 32, 1048576,
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 919c1c643d080..877235147a044 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1991,6 +1991,12 @@ defm constant_cfstrings : 
BoolFOption<"constant-cfstrings",
   "Disable creation of CodeFoundation-type constant strings">,
   PosFlag>;
 def fconstant_string_class_EQ : Joined<["-"], "fconstant-string-class=">, 
Group;
+def fimplicit_constexpr
+: Joined<["-"], "fimplicit-constexpr">,
+  Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"All function declarations will be implicitly constexpr.">,
+  MarshallingInfoFlag>;
 def fconstexpr_depth_EQ : Joined<["-"], "fconstexpr-depth=">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Set the maximum depth of recursive

[clang] [AArch64] Change the coercion type of structs with pointer members. (PR #135064)

2025-04-22 Thread David Green via cfe-commits

https://github.com/davemgreen updated 
https://github.com/llvm/llvm-project/pull/135064

>From 8655b5aff2162bfc13d3f263d6b7830e0186c097 Mon Sep 17 00:00:00 2001
From: David Green 
Date: Wed, 9 Apr 2025 11:18:25 +0100
Subject: [PATCH 1/2] [AArch64] Add a test case for the coerced arguments. NFC

---
 .../AArch64/struct-coerce-using-ptr.cpp   | 548 ++
 1 file changed, 548 insertions(+)
 create mode 100644 clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp

diff --git a/clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp 
b/clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp
new file mode 100644
index 0..c31cbeca2970b
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp
@@ -0,0 +1,548 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -triple aarch64-none-elf -fcxx-exceptions -fexceptions 
-emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-A64
+// RUN: %clang_cc1 -triple arm64_32-apple-ios7.0 -fcxx-exceptions -fexceptions 
-emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-A64_32
+
+struct Sll {
+long long x, y;
+};
+// CHECK-A64-LABEL: define dso_local void @_Z3Tll3Sll(
+// CHECK-A64-SAME: [2 x i64] [[S_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-A64-NEXT:  [[ENTRY:.*:]]
+// CHECK-A64-NEXT:[[S:%.*]] = alloca [[STRUCT_SLL:%.*]], align 8
+// CHECK-A64-NEXT:store [2 x i64] [[S_COERCE]], ptr [[S]], align 8
+// CHECK-A64-NEXT:[[X:%.*]] = getelementptr inbounds nuw [[STRUCT_SLL]], 
ptr [[S]], i32 0, i32 0
+// CHECK-A64-NEXT:store i64 1, ptr [[X]], align 8
+// CHECK-A64-NEXT:ret void
+//
+// CHECK-A64_32-LABEL: define void @_Z3Tll3Sll(
+// CHECK-A64_32-SAME: [2 x i64] [[S_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-A64_32-NEXT:  [[ENTRY:.*:]]
+// CHECK-A64_32-NEXT:[[S:%.*]] = alloca [[STRUCT_SLL:%.*]], align 8
+// CHECK-A64_32-NEXT:store [2 x i64] [[S_COERCE]], ptr [[S]], align 8
+// CHECK-A64_32-NEXT:[[X:%.*]] = getelementptr inbounds nuw 
[[STRUCT_SLL]], ptr [[S]], i32 0, i32 0
+// CHECK-A64_32-NEXT:store i64 1, ptr [[X]], align 8
+// CHECK-A64_32-NEXT:ret void
+//
+void Tll(Sll s) { s.x = 1; }
+
+struct Sp {
+int *x;
+};
+// CHECK-A64-LABEL: define dso_local void @_Z2Tp2Sp(
+// CHECK-A64-SAME: i64 [[S_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK-A64-NEXT:  [[ENTRY:.*:]]
+// CHECK-A64-NEXT:[[S:%.*]] = alloca [[STRUCT_SP:%.*]], align 8
+// CHECK-A64-NEXT:[[COERCE_DIVE:%.*]] = getelementptr inbounds nuw 
[[STRUCT_SP]], ptr [[S]], i32 0, i32 0
+// CHECK-A64-NEXT:[[COERCE_VAL_IP:%.*]] = inttoptr i64 [[S_COERCE]] to ptr
+// CHECK-A64-NEXT:store ptr [[COERCE_VAL_IP]], ptr [[COERCE_DIVE]], align 8
+// CHECK-A64-NEXT:[[X:%.*]] = getelementptr inbounds nuw [[STRUCT_SP]], 
ptr [[S]], i32 0, i32 0
+// CHECK-A64-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X]], align 8
+// CHECK-A64-NEXT:store i32 1, ptr [[TMP0]], align 4
+// CHECK-A64-NEXT:ret void
+//
+// CHECK-A64_32-LABEL: define void @_Z2Tp2Sp(
+// CHECK-A64_32-SAME: i64 [[S_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK-A64_32-NEXT:  [[ENTRY:.*:]]
+// CHECK-A64_32-NEXT:[[S:%.*]] = alloca [[STRUCT_SP:%.*]], align 4
+// CHECK-A64_32-NEXT:[[COERCE_DIVE:%.*]] = getelementptr inbounds nuw 
[[STRUCT_SP]], ptr [[S]], i32 0, i32 0
+// CHECK-A64_32-NEXT:[[COERCE_VAL_II:%.*]] = trunc i64 [[S_COERCE]] to i32
+// CHECK-A64_32-NEXT:store i32 [[COERCE_VAL_II]], ptr [[COERCE_DIVE]], 
align 4
+// CHECK-A64_32-NEXT:[[X:%.*]] = getelementptr inbounds nuw [[STRUCT_SP]], 
ptr [[S]], i32 0, i32 0
+// CHECK-A64_32-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X]], align 4
+// CHECK-A64_32-NEXT:store i32 1, ptr [[TMP0]], align 4
+// CHECK-A64_32-NEXT:ret void
+//
+void Tp(Sp s) { *s.x = 1; }
+
+struct Spp {
+int *x, *y;
+};
+// CHECK-A64-LABEL: define dso_local void @_Z3Tpp3Spp(
+// CHECK-A64-SAME: [2 x i64] [[S_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK-A64-NEXT:  [[ENTRY:.*:]]
+// CHECK-A64-NEXT:[[S:%.*]] = alloca [[STRUCT_SPP:%.*]], align 8
+// CHECK-A64-NEXT:store [2 x i64] [[S_COERCE]], ptr [[S]], align 8
+// CHECK-A64-NEXT:[[X:%.*]] = getelementptr inbounds nuw [[STRUCT_SPP]], 
ptr [[S]], i32 0, i32 0
+// CHECK-A64-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X]], align 8
+// CHECK-A64-NEXT:store i32 1, ptr [[TMP0]], align 4
+// CHECK-A64-NEXT:ret void
+//
+// CHECK-A64_32-LABEL: define void @_Z3Tpp3Spp(
+// CHECK-A64_32-SAME: i64 [[S_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK-A64_32-NEXT:  [[ENTRY:.*:]]
+// CHECK-A64_32-NEXT:[[S:%.*]] = alloca [[STRUCT_SPP:%.*]], align 4
+// CHECK-A64_32-NEXT:store i64 [[S_COERCE]], ptr [[S]], align 4
+// CHECK-A64_32-NEXT:[[X:%.*]] = getelementptr inbounds nuw 
[[STRUCT_SPP]], ptr [[S]], i32 0, i32 0
+// CHECK-A64_32-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X]], align 4
+// CHECK-A64_32-NEXT:store i32 1, ptr [[TMP0]], align 4
+// CHECK-A64_32-NEXT:ret void
+//
+void Tpp(Spp s) { *s.x = 1; }

[clang] [AArch64] Change the coercion type of structs with pointer members. (PR #135064)

2025-04-22 Thread David Green via cfe-commits

https://github.com/davemgreen updated 
https://github.com/llvm/llvm-project/pull/135064

>From 8655b5aff2162bfc13d3f263d6b7830e0186c097 Mon Sep 17 00:00:00 2001
From: David Green 
Date: Wed, 9 Apr 2025 11:18:25 +0100
Subject: [PATCH 1/2] [AArch64] Add a test case for the coerced arguments. NFC

---
 .../AArch64/struct-coerce-using-ptr.cpp   | 548 ++
 1 file changed, 548 insertions(+)
 create mode 100644 clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp

diff --git a/clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp 
b/clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp
new file mode 100644
index 0..c31cbeca2970b
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp
@@ -0,0 +1,548 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -triple aarch64-none-elf -fcxx-exceptions -fexceptions 
-emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-A64
+// RUN: %clang_cc1 -triple arm64_32-apple-ios7.0 -fcxx-exceptions -fexceptions 
-emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-A64_32
+
+struct Sll {
+long long x, y;
+};
+// CHECK-A64-LABEL: define dso_local void @_Z3Tll3Sll(
+// CHECK-A64-SAME: [2 x i64] [[S_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-A64-NEXT:  [[ENTRY:.*:]]
+// CHECK-A64-NEXT:[[S:%.*]] = alloca [[STRUCT_SLL:%.*]], align 8
+// CHECK-A64-NEXT:store [2 x i64] [[S_COERCE]], ptr [[S]], align 8
+// CHECK-A64-NEXT:[[X:%.*]] = getelementptr inbounds nuw [[STRUCT_SLL]], 
ptr [[S]], i32 0, i32 0
+// CHECK-A64-NEXT:store i64 1, ptr [[X]], align 8
+// CHECK-A64-NEXT:ret void
+//
+// CHECK-A64_32-LABEL: define void @_Z3Tll3Sll(
+// CHECK-A64_32-SAME: [2 x i64] [[S_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-A64_32-NEXT:  [[ENTRY:.*:]]
+// CHECK-A64_32-NEXT:[[S:%.*]] = alloca [[STRUCT_SLL:%.*]], align 8
+// CHECK-A64_32-NEXT:store [2 x i64] [[S_COERCE]], ptr [[S]], align 8
+// CHECK-A64_32-NEXT:[[X:%.*]] = getelementptr inbounds nuw 
[[STRUCT_SLL]], ptr [[S]], i32 0, i32 0
+// CHECK-A64_32-NEXT:store i64 1, ptr [[X]], align 8
+// CHECK-A64_32-NEXT:ret void
+//
+void Tll(Sll s) { s.x = 1; }
+
+struct Sp {
+int *x;
+};
+// CHECK-A64-LABEL: define dso_local void @_Z2Tp2Sp(
+// CHECK-A64-SAME: i64 [[S_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK-A64-NEXT:  [[ENTRY:.*:]]
+// CHECK-A64-NEXT:[[S:%.*]] = alloca [[STRUCT_SP:%.*]], align 8
+// CHECK-A64-NEXT:[[COERCE_DIVE:%.*]] = getelementptr inbounds nuw 
[[STRUCT_SP]], ptr [[S]], i32 0, i32 0
+// CHECK-A64-NEXT:[[COERCE_VAL_IP:%.*]] = inttoptr i64 [[S_COERCE]] to ptr
+// CHECK-A64-NEXT:store ptr [[COERCE_VAL_IP]], ptr [[COERCE_DIVE]], align 8
+// CHECK-A64-NEXT:[[X:%.*]] = getelementptr inbounds nuw [[STRUCT_SP]], 
ptr [[S]], i32 0, i32 0
+// CHECK-A64-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X]], align 8
+// CHECK-A64-NEXT:store i32 1, ptr [[TMP0]], align 4
+// CHECK-A64-NEXT:ret void
+//
+// CHECK-A64_32-LABEL: define void @_Z2Tp2Sp(
+// CHECK-A64_32-SAME: i64 [[S_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK-A64_32-NEXT:  [[ENTRY:.*:]]
+// CHECK-A64_32-NEXT:[[S:%.*]] = alloca [[STRUCT_SP:%.*]], align 4
+// CHECK-A64_32-NEXT:[[COERCE_DIVE:%.*]] = getelementptr inbounds nuw 
[[STRUCT_SP]], ptr [[S]], i32 0, i32 0
+// CHECK-A64_32-NEXT:[[COERCE_VAL_II:%.*]] = trunc i64 [[S_COERCE]] to i32
+// CHECK-A64_32-NEXT:store i32 [[COERCE_VAL_II]], ptr [[COERCE_DIVE]], 
align 4
+// CHECK-A64_32-NEXT:[[X:%.*]] = getelementptr inbounds nuw [[STRUCT_SP]], 
ptr [[S]], i32 0, i32 0
+// CHECK-A64_32-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X]], align 4
+// CHECK-A64_32-NEXT:store i32 1, ptr [[TMP0]], align 4
+// CHECK-A64_32-NEXT:ret void
+//
+void Tp(Sp s) { *s.x = 1; }
+
+struct Spp {
+int *x, *y;
+};
+// CHECK-A64-LABEL: define dso_local void @_Z3Tpp3Spp(
+// CHECK-A64-SAME: [2 x i64] [[S_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK-A64-NEXT:  [[ENTRY:.*:]]
+// CHECK-A64-NEXT:[[S:%.*]] = alloca [[STRUCT_SPP:%.*]], align 8
+// CHECK-A64-NEXT:store [2 x i64] [[S_COERCE]], ptr [[S]], align 8
+// CHECK-A64-NEXT:[[X:%.*]] = getelementptr inbounds nuw [[STRUCT_SPP]], 
ptr [[S]], i32 0, i32 0
+// CHECK-A64-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X]], align 8
+// CHECK-A64-NEXT:store i32 1, ptr [[TMP0]], align 4
+// CHECK-A64-NEXT:ret void
+//
+// CHECK-A64_32-LABEL: define void @_Z3Tpp3Spp(
+// CHECK-A64_32-SAME: i64 [[S_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK-A64_32-NEXT:  [[ENTRY:.*:]]
+// CHECK-A64_32-NEXT:[[S:%.*]] = alloca [[STRUCT_SPP:%.*]], align 4
+// CHECK-A64_32-NEXT:store i64 [[S_COERCE]], ptr [[S]], align 4
+// CHECK-A64_32-NEXT:[[X:%.*]] = getelementptr inbounds nuw 
[[STRUCT_SPP]], ptr [[S]], i32 0, i32 0
+// CHECK-A64_32-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X]], align 4
+// CHECK-A64_32-NEXT:store i32 1, ptr [[TMP0]], align 4
+// CHECK-A64_32-NEXT:ret void
+//
+void Tpp(Spp s) { *s.x = 1; }

[clang] [AArch64] Change the coercion type of structs with pointer members. (PR #135064)

2025-04-22 Thread David Green via cfe-commits


@@ -485,6 +485,39 @@ ABIArgInfo AArch64ABIInfo::classifyArgumentType(QualType 
Ty, bool IsVariadicFn,
 }
 Size = llvm::alignTo(Size, Alignment);
 
+// If the Aggregate is made up of pointers, use an array of pointers for 
the
+// coerced type. This prevents having to convert ptr2int->int2ptr through
+// the call, allowing alias analysis to produce better code.
+std::function ContainsOnlyPointers = [&](QualType Ty) {
+  if (isEmptyRecord(getContext(), Ty, true))
+return false;
+  const RecordType *RT = Ty->getAs();
+  if (!RT)
+return false;
+  const RecordDecl *RD = RT->getDecl();
+  if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) {
+for (const auto &I : CXXRD->bases())
+  if (!ContainsOnlyPointers(I.getType()))
+return false;
+  }
+  return all_of(RD->fields(), [&](FieldDecl *FD) {
+QualType FDTy = FD->getType();
+if (FDTy->isArrayType())
+  FDTy = QualType(FDTy->getBaseElementTypeUnsafe(), 0);
+return (FDTy->isPointerOrReferenceType() &&
+getContext().getTypeSize(FDTy) == 64) ||
+   ContainsOnlyPointers(FDTy);
+  });
+};
+if (ContainsOnlyPointers(Ty)) {
+  assert((Size == 64 || Size == 128) &&
+ "Expected a 64 or 128bit struct containing pointers");
+  llvm::Type *PtrTy = llvm::PointerType::getUnqual(getVMContext());
+  if (Size == 128)
+PtrTy = llvm::ArrayType::get(PtrTy, 2);

davemgreen wrote:

Thanks - I had tested it with an align directive but not realized there was a 
difference between the "natural alignment" and after it was adjusted.

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


[clang] [llvm] Add Support for Ziccamoc (PR #136694)

2025-04-22 Thread Pengcheng Wang via cfe-commits

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


[clang] [llvm] [SYCL] Add SYCL property set registry class (PR #136697)

2025-04-22 Thread Justin Cai via cfe-commits

https://github.com/jzc created https://github.com/llvm/llvm-project/pull/136697

None

>From f5388e43a3ace6429ad911aebe2a3599858abf8f Mon Sep 17 00:00:00 2001
From: "Cai, Justin" 
Date: Tue, 22 Apr 2025 06:34:45 -0700
Subject: [PATCH] [SYCL] Add SYCL property set registry class

---
 .../clang-sycl-linker/ClangSYCLLinker.cpp |  14 ++-
 .../llvm/Frontend/Offloading/Utility.h| 102 ++
 llvm/lib/Frontend/Offloading/Utility.cpp  | 102 ++
 llvm/unittests/Frontend/CMakeLists.txt|   1 +
 .../Frontend/PropertySetRegistryTest.cpp  |  39 +++
 5 files changed, 253 insertions(+), 5 deletions(-)
 create mode 100644 llvm/unittests/Frontend/PropertySetRegistryTest.cpp

diff --git a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp 
b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
index 61ec4dbc1489d..e7f7654d377a1 100644
--- a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
+++ b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
@@ -20,6 +20,7 @@
 #include "llvm/BinaryFormat/Magic.h"
 #include "llvm/Bitcode/BitcodeWriter.h"
 #include "llvm/CodeGen/CommandFlags.h"
+#include "llvm/Frontend/Offloading/Utility.h"
 #include "llvm/IR/DiagnosticPrinter.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IRReader/IRReader.h"
@@ -54,6 +55,7 @@
 using namespace llvm;
 using namespace llvm::opt;
 using namespace llvm::object;
+using namespace llvm::offloading::sycl;
 
 /// Save intermediary results.
 static bool SaveTemps = false;
@@ -355,18 +357,18 @@ Error runSYCLLink(ArrayRef Files, const 
ArgList &Args) {
   // result in multiple bitcode codes.
   // The following lines are placeholders to represent multiple files and will
   // be refactored once SYCL post link support is available.
-  SmallVector SplitModules;
-  SplitModules.emplace_back(*LinkedFile);
+  SmallVector> SplitModules;
+  SplitModules.emplace_back(*LinkedFile, PropertySetRegistry{});
 
   // SPIR-V code generation step.
   for (size_t I = 0, E = SplitModules.size(); I != E; ++I) {
 auto Stem = OutputFile.rsplit('.').first;
 std::string SPVFile(Stem);
 SPVFile.append("_" + utostr(I) + ".spv");
-auto Err = runSPIRVCodeGen(SplitModules[I], Args, SPVFile, C);
+auto Err = runSPIRVCodeGen(SplitModules[I].first, Args, SPVFile, C);
 if (Err)
   return Err;
-SplitModules[I] = SPVFile;
+SplitModules[I].first = SPVFile;
   }
 
   // Write the final output into file.
@@ -376,7 +378,7 @@ Error runSYCLLink(ArrayRef Files, const 
ArgList &Args) {
   llvm::raw_fd_ostream FS(FD, /*shouldClose=*/true);
 
   for (size_t I = 0, E = SplitModules.size(); I != E; ++I) {
-auto File = SplitModules[I];
+const auto &[File, Properties] = SplitModules[I];
 llvm::ErrorOr> FileOrErr =
 llvm::MemoryBuffer::getFileOrSTDIN(File);
 if (std::error_code EC = FileOrErr.getError()) {
@@ -385,6 +387,7 @@ Error runSYCLLink(ArrayRef Files, const 
ArgList &Args) {
   else
 return createFileError(File, EC);
 }
+
 OffloadingImage TheImage{};
 TheImage.TheImageKind = IMG_Object;
 TheImage.TheOffloadKind = OFK_SYCL;
@@ -392,6 +395,7 @@ Error runSYCLLink(ArrayRef Files, const 
ArgList &Args) {
 Args.MakeArgString(Args.getLastArgValue(OPT_triple_EQ));
 TheImage.StringData["arch"] =
 Args.MakeArgString(Args.getLastArgValue(OPT_arch_EQ));
+TheImage.StringData["sycl_properties"] = Properties.writeJSON();
 TheImage.Image = std::move(*FileOrErr);
 
 llvm::SmallString<0> Buffer = OffloadBinary::write(TheImage);
diff --git a/llvm/include/llvm/Frontend/Offloading/Utility.h 
b/llvm/include/llvm/Frontend/Offloading/Utility.h
index 7b717a4733b79..c33a94a6cdf29 100644
--- a/llvm/include/llvm/Frontend/Offloading/Utility.h
+++ b/llvm/include/llvm/Frontend/Offloading/Utility.h
@@ -11,6 +11,7 @@
 
 #include 
 #include 
+#include 
 
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
@@ -159,6 +160,107 @@ namespace intel {
 /// the Intel runtime offload plugin.
 Error containerizeOpenMPSPIRVImage(std::unique_ptr &Binary);
 } // namespace intel
+
+namespace sycl {
+class PropertySetRegistry;
+
+// A property value. It can be either a 32-bit unsigned integer or a byte 
array.
+class PropertyValue {
+public:
+  using ByteArrayTy = SmallVector;
+
+  PropertyValue() = default;
+  PropertyValue(uint32_t Val) : Value(Val) {}
+  PropertyValue(StringRef Data)
+  : Value(ByteArrayTy(Data.begin(), Data.end())) {}
+
+  template 
+  PropertyValue(const C &Data)
+  : PropertyValue({reinterpret_cast(Data.data()),
+   Data.size() * sizeof(T)}) {}
+
+  uint32_t asUint32() const {
+assert(getType() == PV_UInt32 && "must be UINT32 value");
+return std::get(Value);
+  }
+
+  StringRef asByteArray() const {
+assert(getType() == PV_ByteArray && "must be BYTE_ARRAY value");
+const auto &ByteArrayRef = std::get(Value);
+return {ByteArrayRef.data(), ByteArrayRef.size()};
+  }
+
+  // Note: each enumeratio

[clang] [llvm] [SYCL] Add SYCL property set registry class (PR #136697)

2025-04-22 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [llvm] [clang][OpenMP][SPIR-V] Fix AS of globals and set the default AS to 4 (PR #135251)

2025-04-22 Thread Nick Sarnie via cfe-commits


@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown 
-fopenmp-targets=spirv64 -emit-llvm-bc %s -o %t-host.bc
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=spirv64 -fopenmp-is-target-device 
-triple spirv64 -fopenmp-host-ir-file-path %t-host.bc -emit-llvm %s -o - | 
FileCheck %s
+
+int main() {
+  int x = 0;
+
+#pragma omp target teams distribute parallel for simd
+  for(int i = 0; i < 1024; i++)
+x+=i;
+  return x;
+}
+
+// CHECK: @[[#STRLOC:]] = private unnamed_addr addrspace(1) constant [{{.*}} x 
i8] c{{.*}}, align 1
+// CHECK: @[[#IDENT:]] = private unnamed_addr addrspace(1) constant 
%struct.ident_t { i32 {{.*}}, i32 2050, i32 {{.*}}, i32 {{.*}}, ptr 
addrspacecast (ptr addrspace(1) @[[#STRLOC]] to ptr) }, align 8
+// CHECK: define internal spir_func void 
@__omp_offloading_{{.*}}_omp_outlined(ptr addrspace(4) noalias noundef {{.*}}., 
ptr addrspace(4) noalias noundef {{.*}}, i64 noundef {{.*}}) #{{.*}} {
+// CHECK: = load ptr addrspace(4), ptr addrspace(4) %{{.*}}, align 8
+// CHECK: = load i32, ptr addrspace(4) %{{.*}}, align 4
+// CHECK: = addrspacecast ptr addrspace(4) %{{.*}} to ptr
+// CHECK: = addrspacecast ptr addrspace(4) %{{.*}} to ptr
+// CHECK: = addrspacecast ptr addrspace(4) %{{.*}} to ptr
+// CHECK: = addrspacecast ptr addrspace(4) %{{.*}} to ptr
+// CHECK: call spir_func void @__kmpc_distribute_static_init{{.*}}(ptr 
addrspacecast (ptr addrspace(1) @[[#IDENT]] to ptr), i32 %{{.*}}, i32 {{.*}}, 
ptr %{{.*}}, ptr %{{.*}}, ptr %{{.*}}, ptr %{{.*}}, i32 {{.*}}, i32 %{{.*}})

sarnex wrote:

Discussing this offline

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


[clang] [llvm] [RISCV] Add support for Ziccamoc (PR #136694)

2025-04-22 Thread Pengcheng Wang via cfe-commits

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


[clang] [CIR] Let ConstantOp builder infer its type automatically (PR #136606)

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

erichkeane wrote:

> Best I can tell this breaks the CIR build:
> 
> ```
> FAILED: tools/clang/include/clang/CIR/Dialect/IR/CIROpsAttributes.h.inc 
> /local/home/ekeane/llvm-project/build/tools/clang/include/clang/CIR/Dialect/IR/CIROpsAttributes.h.inc
>  
> cd /local/home/ekeane/llvm-project/build && 
> /local/home/ekeane/llvm-project/build/NATIVE/bin/mlir-tblgen 
> -gen-attrdef-decls -I 
> /local/home/ekeane/llvm-project/clang/include/clang/CIR/Dialect/IR 
> -I/local/home/ekeane/llvm-project/clang/include 
> -I/local/home/ekeane/llvm-project/build/tools/clang/include 
> -I/local/home/ekeane/llvm-project/build/include 
> -I/local/home/ekeane/llvm-project/llvm/include -I/local/home/ekeane/llvm-p
> roject/llvm/../mlir/include 
> -I/local/home/ekeane/llvm-project/build/tools/mlir/include 
> /local/home/ekeane/llvm-project/clang/include/clang/CIR/Dialect/IR/CIROps.td 
> --write-if-changed -o 
> tools/clang/include/clang/CIR/Dialect/IR/CIROpsAttributes.h.inc -d 
> tools/clang/include/clang/CIR/Dialect/IR/CIROpsAttributes.h.inc.d
> Included from 
> /local/home/ekeane/llvm-project/clang/include/clang/CIR/Dialect/IR/CIROps.td:19:
> /local/home/ekeane/llvm-project/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td:110:5:
>  error: Using a raw APInt parameter without a custom comparator is not 
> supported because an assert in the equality operator is triggered when the 
> two APInts have different bit widths. This can lead to unexpected crashes. 
> Use an `APIntParameter` or provide a custom comparator.
> def IntAttr : CIR_Attr<"Int", "int", [TypedAttrInterface]> {
> ^
> ```
> 
> Do you have a fix for this?
> 
> @andykaylor @mmha @bcardosolopes

Hmm.. I get this issue, but I'm not convinced any longer that THIS patch caused 
it.  I'm going to have to do a more aggressive bisect :)  I'll let you know how 
it turns out.

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


[clang] [clang][ARM][AArch64] Define intrinsics guarded by __has_builtin on all platforms (PR #128222)

2025-04-22 Thread Nick Sarnie via cfe-commits

sarnex wrote:

Investigating, thanks

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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread Tarun Prabhu via cfe-commits

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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread Tarun Prabhu via cfe-commits


@@ -148,6 +148,55 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// OpenMP is enabled.
   using DoConcurrentMappingKind = flangomp::DoConcurrentMappingKind;
 
+  enum ProfileInstrKind {

tarunprabhu wrote:

Can this enum be shared between `clang` and `flang`? There is precedent for 
doing this, for example with the `VectorLibrary` enum. That was moved to 
`llvm/include/llvm/Frontend/Driver/CodeGenOptions.h`. We could consider doing 
the same for this.

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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread Tarun Prabhu via cfe-commits


@@ -0,0 +1,14 @@
+# IR level Instrumentation Flag
+:ir
+:entry_first
+_QQmain
+# Func Hash:
+146835646621254984
+# Num Counters:
+2
+# Counter Values:
+100
+1
+

tarunprabhu wrote:

Are the trailing newlines here necessary?

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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread Tarun Prabhu via cfe-commits


@@ -130,6 +133,20 @@ static bool saveMLIRTempFile(const CompilerInvocation &ci,
 // Custom BeginSourceFileAction
 
//===--===//
 
+
+static llvm::cl::opt ClPGOColdFuncAttr(

tarunprabhu wrote:

This was added in #89298 and is marked with a TODO in 
`clang/lib/CodeGen/BackendUtil.cpp` saying that it should be removed once a 
proper frontend driver option is added. @kiranchandramohan , Do we want to be 
replicating something experimental like this in flang as well?

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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu commented:

Thanks for working on this.

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


[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)

2025-04-22 Thread Tarun Prabhu via cfe-commits


@@ -892,6 +909,20 @@ static void 
generateMachineCodeOrAssemblyImpl(clang::DiagnosticsEngine &diags,
   delete tlii;
 }
 
+
+// Default filename used for profile generation.
+namespace llvm {
+  extern llvm::cl::opt DebugInfoCorrelate;
+  extern llvm::cl::opt 
ProfileCorrelate;
+
+
+std::string getDefaultProfileGenName() {

tarunprabhu wrote:

This looks like a duplicate of the code in I think this function definition 
could be moved to `llvm/lib/Frontend/Driver/CodeGenOptions.cpp` or somewhere 
within llvm/lib/Frontend. There is precedent for doing this with, for example, 
`createTLII`. In general, we would like to avoid duplicating code from `clang` 
as much as possible.

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


[clang] [clang][modules] Minor improvements to diagnosing `out of date` errors (PR #136612)

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

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

>From 046b60179ee5eddc6db2193406bfc2ef10fda3df Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Mon, 21 Apr 2025 13:20:12 -0700
Subject: [PATCH 1/4] [clang][Modules] Report when` lookupModuleFile` fails and
 theres an alternate module file to use

In an explicit build, the dependency scanner generates invocations with
dependencies to module files to use during compilation. The pcm's passed
in the invocations should match the ones that were imported by other
modules that share the same dependencies.

We have seen 'module out of date' bugs caused from incorrect invocations that 
mismatch which module file to load.
When this happens & we have information about which modules were
imported from the AST file, add a note to help with investigations, as
that should never occur in a well behaved build scheduled from the
dependency scanner.
---
 .../Basic/DiagnosticSerializationKinds.td |  2 +
 clang/lib/Serialization/ASTReader.cpp | 23 ---
 clang/test/Modules/invalid-module-dep.c   | 62 +++
 3 files changed, 79 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/Modules/invalid-module-dep.c

diff --git a/clang/include/clang/Basic/DiagnosticSerializationKinds.td 
b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
index 5fc5937b80d35..3babc5850c013 100644
--- a/clang/include/clang/Basic/DiagnosticSerializationKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -76,6 +76,8 @@ def err_module_file_missing_top_level_submodule : Error<
   "module file '%0' is missing its top-level submodule">, DefaultFatal;
 def note_module_file_conflict : Note<
   "compiled from '%0' and '%1'">;
+def note_alternate_module_file_imported
+: Note<"alternate module file '%0' was imported from '%1'">;
 
 def remark_module_import : Remark<
   "importing module '%0'%select{| into '%3'}2 from '%1'">,
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 70b54b7296882..cf875715aa132 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -3286,6 +3286,7 @@ ASTReader::ReadControlBlock(ModuleFile &F,
   time_t StoredModTime = 0;
   ASTFileSignature StoredSignature;
   std::string ImportedFile;
+  std::string StoredFile;
 
   // For prebuilt and explicit modules first consult the file map for
   // an override. Note that here we don't search prebuilt module
@@ -3293,7 +3294,9 @@ ASTReader::ReadControlBlock(ModuleFile &F,
   // explicit name to file mappings. Also, we will still verify the
   // size/signature making sure it is essentially the same file but
   // perhaps in a different location.
-  if (ImportedKind == MK_PrebuiltModule || ImportedKind == 
MK_ExplicitModule)
+  const bool UseFilemap = (ImportedKind == MK_PrebuiltModule ||
+   ImportedKind == MK_ExplicitModule);
+  if (UseFilemap)
 ImportedFile = PP.getHeaderSearchInfo().getPrebuiltModuleFileName(
 ImportedName, /*FileMapOnly*/ !IsImportingStdCXXModule);
 
@@ -3311,12 +3314,11 @@ ASTReader::ReadControlBlock(ModuleFile &F,
SignatureBytes.end());
 Blob = Blob.substr(ASTFileSignature::size);
 
-if (ImportedFile.empty()) {
-  // Use BaseDirectoryAsWritten to ensure we use the same path in the
-  // ModuleCache as when writing.
-  ImportedFile =
-  ReadPathBlob(BaseDirectoryAsWritten, Record, Idx, Blob);
-}
+// Use BaseDirectoryAsWritten to ensure we use the same path in the
+// ModuleCache as when writing.
+StoredFile = ReadPathBlob(BaseDirectoryAsWritten, Record, Idx, Blob);
+if (ImportedFile.empty())
+  ImportedFile = StoredFile;
   }
 
   // If our client can't cope with us being out of date, we can't cope with
@@ -3349,9 +3351,14 @@ ASTReader::ReadControlBlock(ModuleFile &F,
   .getModuleCache()
   .getInMemoryModuleCache()
   .isPCMFinal(F.FileName);
-  if (isDiagnosedResult(Result, Capabilities) || recompilingFinalized)
+  if (isDiagnosedResult(Result, Capabilities) || recompilingFinalized) {
 Diag(diag::note_module_file_imported_by)
 << F.FileName << !F.ModuleName.empty() << F.ModuleName;
+if (UseFilemap && !F.ModuleName.empty() && !StoredFile.empty() &&
+StoredFile != ImportedFile)
+  Diag(diag::note_alternate_module_file_imported)
+  << StoredFile << F.ModuleName;
+  }
 
   switch (Result) {
   case Failure: return Failure;
diff --git a/clang/test/Modules/invalid-module-dep.c 
b/clang/test/Modules/invalid-module-dep.c
new file mode 100644
index 0..b04a853558376
--- /dev/null
++

[clang] [CIR] Let ConstantOp builder infer its type automatically (PR #136606)

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

erichkeane wrote:

Looks like we now hit this: 
https://github.com/llvm/llvm-project/commit/4bcc414af3782c333f3d535c0e0a92e6120868f5

So the error was added since this patch.  I'll work with @andykaylor @mmha /etc 
separately to see what it takes to fix this.

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


[clang] [llvm] [mlir] [NVPTX] Add support for Shared Cluster Memory address space. (PR #135444)

2025-04-22 Thread Alex MacLean via cfe-commits

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


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


[clang] [llvm] [mlir] [NVPTX] Add support for Shared Cluster Memory address space. (PR #135444)

2025-04-22 Thread Alex MacLean via cfe-commits

https://github.com/AlexMaclean commented:

llvm changes LGTM, though I'm not too familiar with the MLIR portion of this 
change. 

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


[clang] [CIR] Let ConstantOp builder infer its type automatically (PR #136606)

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

erichkeane wrote:

Best I can tell this breaks the CIR build:

```
FAILED: tools/clang/include/clang/CIR/Dialect/IR/CIROpsAttributes.h.inc 
/local/home/ekeane/llvm-project/build/tools/clang/include/clang/CIR/Dialect/IR/CIROpsAttributes.h.inc
 
cd /local/home/ekeane/llvm-project/build && 
/local/home/ekeane/llvm-project/build/NATIVE/bin/mlir-tblgen -gen-attrdef-decls 
-I /local/home/ekeane/llvm-project/clang/include/clang/CIR/Dialect/IR 
-I/local/home/ekeane/llvm-project/clang/include 
-I/local/home/ekeane/llvm-project/build/tools/clang/include 
-I/local/home/ekeane/llvm-project/build/include 
-I/local/home/ekeane/llvm-project/llvm/include -I/local/home/ekeane/llvm-p
roject/llvm/../mlir/include 
-I/local/home/ekeane/llvm-project/build/tools/mlir/include 
/local/home/ekeane/llvm-project/clang/include/clang/CIR/Dialect/IR/CIROps.td 
--write-if-changed -o 
tools/clang/include/clang/CIR/Dialect/IR/CIROpsAttributes.h.inc -d 
tools/clang/include/clang/CIR/Dialect/IR/CIROpsAttributes.h.inc.d
Included from 
/local/home/ekeane/llvm-project/clang/include/clang/CIR/Dialect/IR/CIROps.td:19:
/local/home/ekeane/llvm-project/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td:110:5:
 error: Using a raw APInt parameter without a custom comparator is not 
supported because an assert in the equality operator is triggered when the two 
APInts have different bit widths. This can lead to unexpected crashes. Use an 
`APIntParameter` or provide a custom comparator.
def IntAttr : CIR_Attr<"Int", "int", [TypedAttrInterface]> {
^
```

Do you have a fix for this?

@andykaylor @mmha @bcardosolopes 

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


[clang] Reland [clang] Handle instantiated members to determine visibility (#136128) (PR #136689)

2025-04-22 Thread Andrew Savonichev via cfe-commits


@@ -4787,8 +4787,10 @@ LinkageInfo 
LinkageComputer::computeTypeLinkageInfo(const Type *T) {
 return computeTypeLinkageInfo(cast(T)->getPointeeType());
   case Type::MemberPointer: {
 const auto *MPT = cast(T);
-LinkageInfo LV =
-getDeclLinkageAndVisibility(MPT->getMostRecentCXXRecordDecl());
+LinkageInfo LV;
+if (CXXRecordDecl *D = MPT->getMostRecentCXXRecordDecl()) {

asavonic wrote:

> Is the issue here that now additional cases are called from 
> `mergeMaybeWithVisibility`.

Yes. Starting from `LinkageInfo fromLV = from->getLinkageAndVisibility();` we 
eventually reach

```
if (const auto *spec = dyn_cast(Tag)) {
  mergeTemplateLV(LV, spec, computation);
```
where spec is:
```
ClassTemplatePartialSpecializationDecl 0x5571ebf0  line:25:8 struct DecayedFunctorTraits definition 
explicit_specialization
[...]
|-TemplateArgument type 'type-parameter-0-0 (type-parameter-0-1::*)()'
| `-MemberPointerType 0x5571ea90 'type-parameter-0-0 
(type-parameter-0-1::*)()' dependent
|   |-TemplateTypeParmType 0x556f73b0 'type-parameter-0-1' dependent depth 
0 index 1
|   `-FunctionProtoType 0x5571e9e0 'type-parameter-0-0 ()' dependent cdecl
| `-TemplateTypeParmType 0x556f7630 'type-parameter-0-0' dependent 
depth 0 index 0
[...]
```

> How can we have a case where there is no record decl for a member pointer?

MemberPointerType seems to be both for data members or functions. Or I guess it 
can be neither if is a template parameter? (see test75)
https://github.com/llvm/llvm-project/blob/cfeaa395970b7a2a2f0389d06a20d0970d591807/clang/include/clang/AST/Type.h#L3567

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


[clang] [clang][Driver] Support passing arbitrary args to `-cc1as` with `-Xclangas`. (PR #100714)

2025-04-22 Thread Hubert Tong via cfe-commits

hubert-reinterpretcast wrote:

@alexrp, the test added fails on AIX: 
https://lab.llvm.org/buildbot/#/builders/64/builds/3074
Clang on AIX does not use the integrated assembler for assembly files.

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


[clang] [Clang][kcfi] Sign extend KCFI typeid rather than zero extend (PR #136734)

2025-04-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Bill Wendling (bwendling)


Changes

The KCFI typeid may be negative, but will result in this type of bitcode:

module asm ".weak __kcfi_typeid_func"
module asm ".set __kcfi_typeid_func, 2874394057"

// ...

define dso_local i32 @call_unsigned(ptr noundef %f) #0 
!kcfi_type !6 {
  // ...
  %call = call i32 %0(i32 noundef 37) [ "kcfi"(i32 -1420573239) ]
  ret i32 %call
}

declare !kcfi_type !7 noundef i32 @foo(i32 noundef)

// ...

!7 = !{i32 -1420573239}

The __kcfi_typeid_func value doesn't equal the metadata value. Therefore, we 
sign extend the typeid value rather than zero extend.

This also reorganizes the testcase to remove the "-DAG" checks, which are a bit 
confusing at first.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-1) 
- (modified) clang/test/CodeGen/kcfi.c (+56-26) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 83d8d4f758195..0422f4ab1cebb 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2931,7 +2931,7 @@ void CodeGenModule::finalizeKCFITypes() {
   continue;
 
 std::string Asm = (".weak __kcfi_typeid_" + Name + "\n.set __kcfi_typeid_" 
+
-   Name + ", " + Twine(Type->getZExtValue()) + "\n")
+   Name + ", " + Twine(Type->getSExtValue()) + "\n")
   .str();
 M.appendModuleInlineAsm(Asm);
   }
diff --git a/clang/test/CodeGen/kcfi.c b/clang/test/CodeGen/kcfi.c
index 622843cedba50..058f3277a8119 100644
--- a/clang/test/CodeGen/kcfi.c
+++ b/clang/test/CodeGen/kcfi.c
@@ -8,18 +8,25 @@
 /// Must emit __kcfi_typeid symbols for address-taken function declarations
 // CHECK: module asm ".weak __kcfi_typeid_[[F4:[a-zA-Z0-9_]+]]"
 // CHECK: module asm ".set __kcfi_typeid_[[F4]], [[#%d,HASH:]]"
+// CHECK: module asm ".weak __kcfi_typeid_[[F4_ARG:[a-zA-Z0-9_]+]]"
+// CHECK: module asm ".set __kcfi_typeid_[[F4_ARG]], [[#%d,ARG_HASH:]]"
+
 /// Must not __kcfi_typeid symbols for non-address-taken declarations
 // CHECK-NOT: module asm ".weak __kcfi_typeid_{{f6|_Z2f6v}}"
 
 // C: @ifunc1 = ifunc i32 (i32), ptr @resolver1
 // C: @ifunc2 = ifunc i64 (i64), ptr @resolver2
 typedef int (*fn_t)(void);
+typedef int (*fn_u_t)(unsigned int);
 
-// CHECK: define dso_local{{.*}} i32 @{{f1|_Z2f1v}}(){{.*}} !kcfi_type 
![[#TYPE:]]
-int f1(void) { return 0; }
+int f1(void);
 
-// CHECK: define dso_local{{.*}} i32 @{{f2|_Z2f2v}}(){{.*}} !kcfi_type 
![[#TYPE2:]]
-unsigned int f2(void) { return 2; }
+unsigned int f2(void);
+
+static int f3(void);
+
+extern int f4(void);
+extern int f4_arg(unsigned int);
 
 // CHECK-LABEL: define dso_local{{.*}} i32 
@{{__call|_Z6__callPFivE}}(ptr{{.*}} %f)
 int __call(fn_t f) __attribute__((__no_sanitize__("kcfi"))) {
@@ -27,17 +34,45 @@ int __call(fn_t f) __attribute__((__no_sanitize__("kcfi"))) 
{
   return f();
 }
 
-// CHECK: define dso_local{{.*}} i32 @{{call|_Z4callPFivE}}(ptr{{.*}} %f){{.*}}
+// CHECK-LABEL: define dso_local{{.*}} i32 @{{call|_Z4callPFivE}}(ptr{{.*}} %f)
 int call(fn_t f) {
   // CHECK: call{{.*}} i32 %{{.}}(){{.*}} [ "kcfi"(i32 [[#HASH]]) ]
   return f();
 }
 
-// CHECK-DAG: define internal{{.*}} i32 @{{f3|_ZL2f3v}}(){{.*}} !kcfi_type 
![[#TYPE]]
+// CHECK-LABEL: define dso_local{{.*}} i32 
@{{call_with_arg|_Z13call_with_argPFijE}}(ptr{{.*}} %f)
+int call_with_arg(fn_u_t f) {
+  // CHECK: call{{.*}} i32 %0(i32 {{.*}}) [ "kcfi"(i32 [[#ARG_HASH]]) ]
+  return f(42);
+}
+
+static int f5(void);
+
+extern int f6(void);
+
+int test(void) {
+  return call(f1) +
+ __call((fn_t)f2) +
+ call(f3) +
+ call(f4) +
+ call_with_arg(f4_arg) +
+ f5() +
+ f6();
+}
+
+// CHECK-LABEL: define dso_local{{.*}} i32 @{{f1|_Z2f1v}}(){{.*}} !kcfi_type 
![[#TYPE:]]
+int f1(void) { return 0; }
+
+// CHECK-LABEL: define dso_local{{.*}} i32 @{{f2|_Z2f2v}}(){{.*}} !kcfi_type 
![[#TYPE2:]]
+unsigned int f2(void) { return 2; }
+
+// CHECK: define internal{{.*}} i32 @{{f3|_ZL2f3v}}(){{.*}} !kcfi_type 
![[#TYPE]]
 static int f3(void) { return 1; }
 
-// CHECK-DAG: declare !kcfi_type ![[#TYPE]]{{.*}} i32 @[[F4]]()
-extern int f4(void);
+// CHECK-LABEL: declare !kcfi_type
+// CHECK-SAME:![[#TYPE]]{{.*}} i32 @[[F4]]
+// CHECK-LABEL: declare !kcfi_type
+// CHECK-SAME:![[#ARG_TYPE:]]{{.*}} i32 @[[F4_ARG]]
 
 /// Must not emit !kcfi_type for non-address-taken local functions
 // CHECK: define internal{{.*}} i32 @{{f5|_ZL2f5v}}()
@@ -45,8 +80,7 @@ extern int f4(void);
 // CHECK-SAME: {
 static int f5(void) { return 2; }
 
-// CHECK-DAG: declare !kcfi_type ![[#TYPE]]{{.*}} i32 @{{f6|_Z2f6v}}()
-extern int f6(void);
+// CHECK: declare !kcfi_type ![[#TYPE]]{{.*}} i32 @{{f6|_Z2f6v}}()
 
 #ifndef __cplusplus
 // C: define internal ptr @resolver1() #[[#]] !kcfi_type ![[#]] {

[clang] [Clang][kcfi] Sign extend KCFI typeid rather than zero extend (PR #136734)

2025-04-22 Thread Bill Wendling via cfe-commits

https://github.com/bwendling created 
https://github.com/llvm/llvm-project/pull/136734

The KCFI typeid may be negative, but will result in this type of bitcode:

module asm ".weak __kcfi_typeid_func"
module asm ".set __kcfi_typeid_func, 2874394057"

// ...

define dso_local i32 @call_unsigned(ptr noundef %f) #0 !kcfi_type !6 {
  // ...
  %call = call i32 %0(i32 noundef 37) [ "kcfi"(i32 -1420573239) ]
  ret i32 %call
}

declare !kcfi_type !7 noundef i32 @foo(i32 noundef)

// ...

!7 = !{i32 -1420573239}

The __kcfi_typeid_func value doesn't equal the metadata value. Therefore, we 
sign extend the typeid value rather than zero extend.

This also reorganizes the testcase to remove the "-DAG" checks, which are a bit 
confusing at first.

>From f858b157de257f6f135db38bc59f63152775 Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Tue, 22 Apr 2025 10:39:05 -0700
Subject: [PATCH] [Clang][kcfi] Sign extend KCFI typeid rather than zero extend

The KCFI typeid may be negative, but will result in this type of
bitcode:

module asm ".weak __kcfi_typeid_func"
module asm ".set __kcfi_typeid_func, 2874394057"

// ...

define dso_local i32 @call_unsigned(ptr noundef %f) #0 !kcfi_type !6 {
  // ...
  %call = call i32 %0(i32 noundef 37) [ "kcfi"(i32 -1420573239) ]
  ret i32 %call
}

declare !kcfi_type !7 noundef i32 @foo(i32 noundef)

// ...

!7 = !{i32 -1420573239}

The __kcfi_typeid_func value doesn't equal the metadata value.
Therefore, we sign extend the typeid value rather than zero extend.

This also reorganizes the testcase to remove the "-DAG" checks, which
are a bit confusing at first.

Signed-off-by: Bill Wendling 
---
 clang/lib/CodeGen/CodeGenModule.cpp |  2 +-
 clang/test/CodeGen/kcfi.c   | 82 -
 2 files changed, 57 insertions(+), 27 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 83d8d4f758195..0422f4ab1cebb 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2931,7 +2931,7 @@ void CodeGenModule::finalizeKCFITypes() {
   continue;
 
 std::string Asm = (".weak __kcfi_typeid_" + Name + "\n.set __kcfi_typeid_" 
+
-   Name + ", " + Twine(Type->getZExtValue()) + "\n")
+   Name + ", " + Twine(Type->getSExtValue()) + "\n")
   .str();
 M.appendModuleInlineAsm(Asm);
   }
diff --git a/clang/test/CodeGen/kcfi.c b/clang/test/CodeGen/kcfi.c
index 622843cedba50..058f3277a8119 100644
--- a/clang/test/CodeGen/kcfi.c
+++ b/clang/test/CodeGen/kcfi.c
@@ -8,18 +8,25 @@
 /// Must emit __kcfi_typeid symbols for address-taken function declarations
 // CHECK: module asm ".weak __kcfi_typeid_[[F4:[a-zA-Z0-9_]+]]"
 // CHECK: module asm ".set __kcfi_typeid_[[F4]], [[#%d,HASH:]]"
+// CHECK: module asm ".weak __kcfi_typeid_[[F4_ARG:[a-zA-Z0-9_]+]]"
+// CHECK: module asm ".set __kcfi_typeid_[[F4_ARG]], [[#%d,ARG_HASH:]]"
+
 /// Must not __kcfi_typeid symbols for non-address-taken declarations
 // CHECK-NOT: module asm ".weak __kcfi_typeid_{{f6|_Z2f6v}}"
 
 // C: @ifunc1 = ifunc i32 (i32), ptr @resolver1
 // C: @ifunc2 = ifunc i64 (i64), ptr @resolver2
 typedef int (*fn_t)(void);
+typedef int (*fn_u_t)(unsigned int);
 
-// CHECK: define dso_local{{.*}} i32 @{{f1|_Z2f1v}}(){{.*}} !kcfi_type 
![[#TYPE:]]
-int f1(void) { return 0; }
+int f1(void);
 
-// CHECK: define dso_local{{.*}} i32 @{{f2|_Z2f2v}}(){{.*}} !kcfi_type 
![[#TYPE2:]]
-unsigned int f2(void) { return 2; }
+unsigned int f2(void);
+
+static int f3(void);
+
+extern int f4(void);
+extern int f4_arg(unsigned int);
 
 // CHECK-LABEL: define dso_local{{.*}} i32 
@{{__call|_Z6__callPFivE}}(ptr{{.*}} %f)
 int __call(fn_t f) __attribute__((__no_sanitize__("kcfi"))) {
@@ -27,17 +34,45 @@ int __call(fn_t f) __attribute__((__no_sanitize__("kcfi"))) 
{
   return f();
 }
 
-// CHECK: define dso_local{{.*}} i32 @{{call|_Z4callPFivE}}(ptr{{.*}} %f){{.*}}
+// CHECK-LABEL: define dso_local{{.*}} i32 @{{call|_Z4callPFivE}}(ptr{{.*}} %f)
 int call(fn_t f) {
   // CHECK: call{{.*}} i32 %{{.}}(){{.*}} [ "kcfi"(i32 [[#HASH]]) ]
   return f();
 }
 
-// CHECK-DAG: define internal{{.*}} i32 @{{f3|_ZL2f3v}}(){{.*}} !kcfi_type 
![[#TYPE]]
+// CHECK-LABEL: define dso_local{{.*}} i32 
@{{call_with_arg|_Z13call_with_argPFijE}}(ptr{{.*}} %f)
+int call_with_arg(fn_u_t f) {
+  // CHECK: call{{.*}} i32 %0(i32 {{.*}}) [ "kcfi"(i32 [[#ARG_HASH]]) ]
+  return f(42);
+}
+
+static int f5(void);
+
+extern int f6(void);
+
+int test(void) {
+  return call(f1) +
+ __call((fn_t)f2) +
+ call(f3) +
+ call(f4) +
+ call_with_arg(f4_arg) +
+ f5() +
+ f6();
+}
+
+// CHECK-LABEL: define dso_local{{.*}} i32 @{{f1|_Z2f1v}}(){{.*}} !kcfi_type 
![[#TYPE:]]
+int f1(void) { return 0; }
+
+// CHECK-LABEL: define dso_local{{.*}} i32 @{{f2|_Z2f2v}}(){{.*}} !kcfi_type 
![[#TYPE2:]]
+unsign

[clang] [llvm] [RISCV] Add support for Ziccamoc (PR #136694)

2025-04-22 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp commented:

Release notes?

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


[clang] [llvm] [mlir] [NVPTX] Add support for Shared Cluster Memory address space. (PR #135444)

2025-04-22 Thread Mehdi Amini via cfe-commits

https://github.com/joker-eph approved this pull request.

MLIR side LGTM

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


[clang] Reland [clang] Handle instantiated members to determine visibility (#136128) (PR #136689)

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


@@ -4787,8 +4787,10 @@ LinkageInfo 
LinkageComputer::computeTypeLinkageInfo(const Type *T) {
 return computeTypeLinkageInfo(cast(T)->getPointeeType());
   case Type::MemberPointer: {
 const auto *MPT = cast(T);
-LinkageInfo LV =
-getDeclLinkageAndVisibility(MPT->getMostRecentCXXRecordDecl());
+LinkageInfo LV;
+if (CXXRecordDecl *D = MPT->getMostRecentCXXRecordDecl()) {

erichkeane wrote:

>MemberPointerType seems to be both for data members or functions.

I would expect both of those to have a `CXXRecordDecl`.

>Or I guess it can be neither if is a template parameter? (see test75)

Ok, so that looks like the record decl is null because the 'class' is dependent 
(see that `getMostRecentCXXDecl` does `getClass` as part of its implementation).

Should we be taking visibility from that `getClass` in this case?  It is a 
dependent expression in this case, but perhaps we should be?

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


[clang] c2ae572 - [clang][bytecode] Allow reinterpret casts from/to the same pointer type (#136692)

2025-04-22 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-04-22T16:50:42+02:00
New Revision: c2ae5723b5418fa0f5901f2c21c2c905fa48a498

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

LOG: [clang][bytecode] Allow reinterpret casts from/to the same pointer type 
(#136692)

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 3e53f2a2c8557..7cba0e8a4da19 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2990,6 +2990,8 @@ bool Compiler::VisitCXXReinterpretCastExpr(
 if (PointeeToT && PointeeFromT) {
   if (isIntegralType(*PointeeFromT) && isIntegralType(*PointeeToT))
 Fatal = false;
+} else {
+  Fatal = SubExpr->getType().getTypePtr() != E->getType().getTypePtr();
 }
 
 if (!this->emitInvalidCast(CastKind::Reinterpret, Fatal, E))

diff  --git a/clang/test/AST/ByteCode/cxx11.cpp 
b/clang/test/AST/ByteCode/cxx11.cpp
index 23582e9ab556a..4c69517304ea7 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -185,3 +185,11 @@ namespace InitLinkToRVO {
   constexpr A make() { return A {}; }
   static_assert(make().z == 4, "");
 }
+
+namespace DynamicCast {
+  struct S { int x, y; } s;
+  constexpr S* sptr = &s;
+  struct Str {
+int b : reinterpret_cast(sptr) == reinterpret_cast(sptr);
+  };
+}



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


[clang] [clang][bytecode] Allow reinterpret casts from/to the same pointer type (PR #136692)

2025-04-22 Thread Timm Baeder via cfe-commits

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


[clang] Reland [clang] Handle instantiated members to determine visibility (#136128) (PR #136689)

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


@@ -4787,8 +4787,10 @@ LinkageInfo 
LinkageComputer::computeTypeLinkageInfo(const Type *T) {
 return computeTypeLinkageInfo(cast(T)->getPointeeType());
   case Type::MemberPointer: {
 const auto *MPT = cast(T);
-LinkageInfo LV =
-getDeclLinkageAndVisibility(MPT->getMostRecentCXXRecordDecl());
+LinkageInfo LV;
+if (CXXRecordDecl *D = MPT->getMostRecentCXXRecordDecl()) {

mizvekov wrote:

Yes, the most recent decl will be null in most dependent cases, except when you 
have an injected class (ie referring to the class template itself inside its 
definition).

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


[clang] [HLSL] Use hlsl_device address space for getpointer. (PR #127675)

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

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

>From 2a288bc3528ae63f05551492518cbf500689108d Mon Sep 17 00:00:00 2001
From: Steven Perron 
Date: Wed, 12 Feb 2025 15:45:32 -0500
Subject: [PATCH 1/5] [HLSL] Use hlsl_device address space for getpointer.

We add the hlsl_device address space to represent the device memory
space as defined in section 1.7.1.3 of the [HLSL
spec](https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf).

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

# Conflicts:
#   clang/test/CodeGenHLSL/builtins/StructuredBuffers-subscripts.hlsl
---
 clang/include/clang/Basic/AddressSpaces.h |  1 +
 clang/lib/AST/Type.cpp|  8 ++--
 clang/lib/AST/TypePrinter.cpp |  2 +
 clang/lib/Basic/Targets/AArch64.h |  1 +
 clang/lib/Basic/Targets/AMDGPU.cpp|  2 +
 clang/lib/Basic/Targets/DirectX.h |  1 +
 clang/lib/Basic/Targets/NVPTX.h   |  1 +
 clang/lib/Basic/Targets/SPIR.h|  2 +
 clang/lib/Basic/Targets/SystemZ.h |  1 +
 clang/lib/Basic/Targets/TCE.h |  1 +
 clang/lib/Basic/Targets/WebAssembly.h |  1 +
 clang/lib/Basic/Targets/X86.h |  1 +
 clang/lib/CodeGen/CGHLSLBuiltins.cpp  |  4 +-
 clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp | 21 ++---
 clang/lib/Sema/SemaHLSL.cpp   |  6 ++-
 clang/test/AST/HLSL/OutArgExpr.hlsl   | 14 +++---
 .../test/AST/HLSL/StructuredBuffers-AST.hlsl  | 30 ++---
 clang/test/AST/HLSL/TypedBuffers-AST.hlsl | 16 +++
 .../builtins/RWBuffer-subscript.hlsl  | 16 +++
 .../StructuredBuffers-subscripts.hlsl | 45 +++
 20 files changed, 113 insertions(+), 61 deletions(-)

diff --git a/clang/include/clang/Basic/AddressSpaces.h 
b/clang/include/clang/Basic/AddressSpaces.h
index 5787e6dac0e36..519d959bb636c 100644
--- a/clang/include/clang/Basic/AddressSpaces.h
+++ b/clang/include/clang/Basic/AddressSpaces.h
@@ -60,6 +60,7 @@ enum class LangAS : unsigned {
   hlsl_groupshared,
   hlsl_constant,
   hlsl_private,
+  hlsl_device,
 
   // Wasm specific address spaces.
   wasm_funcref,
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index fe1dc7e2fe786..67cd690af7499 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -94,10 +94,12 @@ bool Qualifiers::isTargetAddressSpaceSupersetOf(LangAS A, 
LangAS B,
  (A == LangAS::Default &&
   (B == LangAS::cuda_constant || B == LangAS::cuda_device ||
B == LangAS::cuda_shared)) ||
- // `this` overloading depending on address space is not ready,
- // so this is a hack to allow generating addrspacecasts.
- // IR legalization will be required when this address space is used.
+ // In HLSL, the this pointer for member functions points to the 
default
+ // address space. This causes a problem if the structure is in
+ // a different address space. We want to allow casting from these
+ // address spaces to default to work around this problem.
  (A == LangAS::Default && B == LangAS::hlsl_private) ||
+ (A == LangAS::Default && B == LangAS::hlsl_device) ||
  // Conversions from target specific address spaces may be legal
  // depending on the target information.
  Ctx.getTargetInfo().isAddressSpaceSupersetOf(A, B);
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 7b1d1c7ae2131..cba1a2d98d660 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2617,6 +2617,8 @@ std::string Qualifiers::getAddrSpaceAsString(LangAS AS) {
 return "hlsl_constant";
   case LangAS::hlsl_private:
 return "hlsl_private";
+  case LangAS::hlsl_device:
+return "hlsl_device";
   case LangAS::wasm_funcref:
 return "__funcref";
   default:
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 58822e467ce39..2fab88cfca901 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -46,6 +46,7 @@ static const unsigned ARM64AddrSpaceMap[] = {
 0, // hlsl_groupshared
 0, // hlsl_constant
 0, // hlsl_private
+0, // hlsl_device
 // Wasm address space values for this target are dummy values,
 // as it is only enabled for Wasm targets.
 20, // wasm_funcref
diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index f81cdac3b7422..c368200f3f739 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -63,6 +63,7 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
 // FIXME(pr/122103): hlsl_private -> PRIVATE is wrong, but at least this
 // will break loudly.
 llvm::AMDGPUAS::PRIVATE_ADDRESS, // hlsl_private
+llvm::AMDGPUAS::GLOBAL_ADDRESS,  // hlsl_device
 };
 
 const LangASMap AMDGPUTargetInfo::AMDGPUDe

[clang] [HLSL] Use hlsl_device address space for getpointer. (PR #127675)

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


@@ -121,15 +121,15 @@ RESOURCE Buffer;
 // CHECK-SUBSCRIPT-NEXT: DeclRefExpr {{.*}} 'unsigned int' ParmVar {{.*}} 
'Index' 'unsigned int'
 // CHECK-SUBSCRIPT-NEXT: AlwaysInlineAttr {{.*}} Implicit always_inline
 
-// CHECK-NOSUBSCRIPT-NOT: CXXMethodDecl {{.*}} operator[] 'const element_type 
&(unsigned int) const'
-// CHECK-NOSUBSCRIPT-NOT: CXXMethodDecl {{.*}} operator[] 'element_type 
&(unsigned int)'
+// CHECK-NOSUBSCRIPT-NOT: CXXMethodDecl {{.*}} operator[] 'hlsl_device 
element_type &const (unsigned int) const'

s-perron wrote:

done

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


  1   2   3   4   >