[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-03 Thread Erich Keane via cfe-commits


@@ -166,7 +166,8 @@ getScopeFromNormalizedScopeName(StringRef ScopeName) {
   .Case("hlsl", AttributeCommonInfo::Scope::HLSL)
   .Case("msvc", AttributeCommonInfo::Scope::MSVC)
   .Case("omp", AttributeCommonInfo::Scope::OMP)
-  .Case("riscv", AttributeCommonInfo::Scope::RISCV);
+  .Case("riscv", AttributeCommonInfo::Scope::RISCV)

erichkeane wrote:

Ah, that appears to be the correct list, yes, thank you!

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


[libclc] [llvm] [libclc] Add Maintainers.md for libclc (PR #118309)

2025-01-03 Thread David Spickett via cfe-commits

https://github.com/DavidSpickett updated 
https://github.com/llvm/llvm-project/pull/118309

>From 409dd1184f1c4ff9f11e2d715b6e4a496c70c7e4 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Mon, 2 Dec 2024 15:22:50 +
Subject: [PATCH 1/2] [libclc] Add Maintainers.md for libclc

---
 libclc/Maintainers.md | 10 ++
 llvm/Maintainers.md   |  8 ++--
 2 files changed, 12 insertions(+), 6 deletions(-)
 create mode 100644 libclc/Maintainers.md

diff --git a/libclc/Maintainers.md b/libclc/Maintainers.md
new file mode 100644
index 00..314b139b81aaff
--- /dev/null
+++ b/libclc/Maintainers.md
@@ -0,0 +1,10 @@
+# libclc Maintainers
+
+This file is a list of the
+[maintainers](https://llvm.org/docs/DeveloperPolicy.html#maintainers) for
+libclc.
+
+# Lead maintainer
+
+Tom Stellard \
+tstel...@redhat.com (email), [tstellar](https://github.com/tstellar) (GitHub)
\ No newline at end of file
diff --git a/llvm/Maintainers.md b/llvm/Maintainers.md
index 313afa21180fd4..27b69ef98da1f6 100644
--- a/llvm/Maintainers.md
+++ b/llvm/Maintainers.md
@@ -422,7 +422,6 @@ gkistan...@gmail.com (email), 
[gkistanova](https://github.com/gkistanova) (GitHu
 ### Other subprojects
 
 Some subprojects maintain their own list of per-component maintainers.
-Others only have a lead maintainer listed here.
 
 [Bolt 
maintainers](https://github.com/llvm/llvm-project/blob/main/bolt/Maintainers.txt)
 
@@ -436,6 +435,8 @@ Others only have a lead maintainer listed here.
 
 [libc++ 
maintainers](https://github.com/llvm/llvm-project/blob/main/libcxx/Maintainers.md)
 
+[libclc 
maintainers](https://github.com/llvm/llvm-project/blob/main/libclc/Maintainers.md)
+
 [LLD 
maintainers](https://github.com/llvm/llvm-project/blob/main/lld/Maintainers.md)
 
 [LLDB 
maintainers](https://github.com/llvm/llvm-project/blob/main/lldb/Maintainers.rst)
@@ -444,11 +445,6 @@ Others only have a lead maintainer listed here.
 
 [Polly 
maintainers](https://github.com/llvm/llvm-project/blob/main/polly/Maintainers.md)
 
- libclc
-
-Tom Stellard \
-tstel...@redhat.com (email), [tstellar](https://github.com/tstellar) (GitHub)
-
 ## Inactive Maintainers
 
 The following people have graciously spent time performing maintainer

>From 4056e1814024174719c44d160dcd153e948ee2d6 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Fri, 3 Jan 2025 14:16:24 +
Subject: [PATCH 2/2] list both for libclc

---
 libclc/Maintainers.md | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libclc/Maintainers.md b/libclc/Maintainers.md
index 314b139b81aaff..ac869b6945db55 100644
--- a/libclc/Maintainers.md
+++ b/libclc/Maintainers.md
@@ -4,7 +4,14 @@ This file is a list of the
 [maintainers](https://llvm.org/docs/DeveloperPolicy.html#maintainers) for
 libclc.
 
-# Lead maintainer
+## Current Maintainers
+
+The following people are the active maintainers for the project. Please reach
+out to them for code reviews, questions about their area of expertise, or other
+assistance.
+
+Fraser Cormack \
+fra...@codeplay.com (email), [frasercrmck](https://github.com/frasercrmck) 
(GitHub)
 
 Tom Stellard \
-tstel...@redhat.com (email), [tstellar](https://github.com/tstellar) (GitHub)
\ No newline at end of file
+tstel...@redhat.com (email), [tstellar](https://github.com/tstellar) (GitHub)

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


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-03 Thread Erich Keane via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

erichkeane wrote:

I would expect this to be a normal warning.  The difference between 
`clang::Unknown` and `Unknown::UnknownAttr` are the same severity/warning 
type/etc.  A different MESSAGE is sensible, and a different warning GROUP is 
equally as sensible, but one being a warning and the other an extension seems 
odd.

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


[libclc] [llvm] [libclc] Add Maintainers.md for libclc (PR #118309)

2025-01-03 Thread David Spickett via cfe-commits

DavidSpickett wrote:

Updated to list @frasercrmck and @tstellar for libclc. Tell me if that works 
for now, perhaps you can sort out any additions later.

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


[clang] [Clang] emit -Wignored-qualifiers diagnostic for cv-qualified base classes (PR #121419)

2025-01-03 Thread Erich Keane via cfe-commits

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

I have a bit of a concern that the template cases are going to be REALLY noisy, 
but we can deal with restricting individual use cases to a separate 
warning-group in the future if need-be.

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


[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

2025-01-03 Thread via cfe-commits


@@ -,12 +,57 @@ bool Sema::EnsureTemplateArgumentListConstraints(
   return false;
 }
 
-bool Sema::CheckInstantiatedFunctionTemplateConstraints(
+static bool CheckFunctionConstraintsWithoutInstantiation(
+Sema &SemaRef, SourceLocation PointOfInstantiation,
+FunctionTemplateDecl *Template, ArrayRef TemplateArgs,
+ConstraintSatisfaction &Satisfaction) {
+  SmallVector TemplateAC;
+  Template->getAssociatedConstraints(TemplateAC);
+  if (TemplateAC.empty()) {
+Satisfaction.IsSatisfied = true;
+return false;
+  }
+
+  LocalInstantiationScope Scope(SemaRef);
+
+  FunctionDecl *FD = Template->getTemplatedDecl();
+  // Collect the list of template arguments relative to the 'primary'
+  // template. We need the entire list, since the constraint is completely
+  // uninstantiated at this point.
+
+  // FIXME: Add TemplateArgs through the 'Innermost' parameter once
+  // the refactoring of getTemplateInstantiationArgs() relands.
+  MultiLevelTemplateArgumentList MLTAL;
+  MLTAL.addOuterTemplateArguments(Template, /*Args=*/TemplateArgs,

cor3ntin wrote:

Ok, so we need to set `Template` as the innermost associated decl - and use 
FD's decl context elsewhere
Does it work if we pass an empty array to getTemplateInstantiationArgs()
and subsequently call replaceInnermostTemplateArguments with the correct 
arguments/decl?

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


[clang] [llvm] [Driver][SYCL] Add initial SYCL offload compilation support (PR #117268)

2025-01-03 Thread Michael Toguchi via cfe-commits


@@ -630,6 +630,11 @@ void toolchains::MinGW::AddHIPIncludeArgs(const ArgList 
&DriverArgs,
   RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
 }
 
+void toolchains::MinGW::addSYCLIncludeArgs(const ArgList &DriverArgs,
+   ArgStringList &CC1Args) const {
+  SYCLInstallation->addSYCLIncludeArgs(DriverArgs, CC1Args);

mdtoguchi wrote:

Initial testing found the need for this due to the general check for the 
updated header search locations.  As reviews progressed with @tahonermann, it 
was suggested to not add the explicit header search locations as it was not 
determined yet (SYCL specific headers and libraries not yet part of the build) 
so now there is nothing being tested here for this target.  This can be cleaned 
up and added again later when the headers are actually searched.

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


[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

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


@@ -,12 +,57 @@ bool Sema::EnsureTemplateArgumentListConstraints(
   return false;
 }
 
-bool Sema::CheckInstantiatedFunctionTemplateConstraints(
+static bool CheckFunctionConstraintsWithoutInstantiation(
+Sema &SemaRef, SourceLocation PointOfInstantiation,
+FunctionTemplateDecl *Template, ArrayRef TemplateArgs,
+ConstraintSatisfaction &Satisfaction) {
+  SmallVector TemplateAC;
+  Template->getAssociatedConstraints(TemplateAC);
+  if (TemplateAC.empty()) {
+Satisfaction.IsSatisfied = true;
+return false;
+  }
+
+  LocalInstantiationScope Scope(SemaRef);
+
+  FunctionDecl *FD = Template->getTemplatedDecl();
+  // Collect the list of template arguments relative to the 'primary'
+  // template. We need the entire list, since the constraint is completely
+  // uninstantiated at this point.
+
+  // FIXME: Add TemplateArgs through the 'Innermost' parameter once
+  // the refactoring of getTemplateInstantiationArgs() relands.
+  MultiLevelTemplateArgumentList MLTAL;
+  MLTAL.addOuterTemplateArguments(Template, /*Args=*/TemplateArgs,

zyn0217 wrote:

This sounds hacky but I like it! I'll run the test locally and see if it works

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


[clang] [compiler-rt] ohos: make configure fail if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is OFF (PR #121575)

2025-01-03 Thread Peng Huang via cfe-commits

https://github.com/phuang created 
https://github.com/llvm/llvm-project/pull/121575

OHOS driver doesn't support old runtime libraries layout, so make cmake 
configure report error if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is OFF.

[Driver][OHOS] Fix lld link issue

The link error is becasue clang rt libraries are installed in 
lib/${arch}-linux-unknown-ohos/ folder, however OHOS driver searches libraries 
in lib/${arch}-linux-ohos/ folder. Fix the problem by searching libraries in 
both lib/${arch}-linux-ohos/ and lib/${arch}-linux-unknown-ohos/

Also make cmake report error if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is not used 
for building OHOS runtime, since OHOS driver doesn't support the old layout

>From 9e9a457fc1f57f1fb233e48a694336c2985f7414 Mon Sep 17 00:00:00 2001
From: Peng Huang 
Date: Thu, 2 Jan 2025 13:07:24 -0500
Subject: [PATCH] ohos: make configure fail if
 LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is OFF

OHOS driver doesn't support old runtime libraries layout, so make
cmake configure report error if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR
is OFF.

[Driver][OHOS] Fix lld link issue

The link error is becasue clang rt libraries are installed in
lib/${arch}-linux-unknown-ohos/ folder, however OHOS driver
searches libraries in lib/${arch}-linux-ohos/ folder. Fix the
problem by searching libraries in both lib/${arch}-linux-ohos/ and
lib/${arch}-linux-unknown-ohos/

Also make cmake report error if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR
is not used for building OHOS runtime, since OHOS driver doesn't
support the old layout
---
 clang/lib/Driver/ToolChains/OHOS.cpp  | 64 +--
 .../cmake/Modules/CompilerRTUtils.cmake   |  5 ++
 2 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp 
b/clang/lib/Driver/ToolChains/OHOS.cpp
index 6e1a09ae908b2f..a4137ba0416a7a 100644
--- a/clang/lib/Driver/ToolChains/OHOS.cpp
+++ b/clang/lib/Driver/ToolChains/OHOS.cpp
@@ -19,8 +19,8 @@
 #include "llvm/ProfileData/InstrProf.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/VirtualFileSystem.h"
 
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
@@ -58,11 +58,9 @@ static bool findOHOSMuslMultilibs(const Driver &D,
   return false;
 }
 
-static bool findOHOSMultilibs(const Driver &D,
-  const ToolChain &TC,
-  const llvm::Triple &TargetTriple,
-  StringRef Path, const ArgList &Args,
-  DetectedMultilibs &Result) {
+static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC,
+  const llvm::Triple &TargetTriple, StringRef Path,
+  const ArgList &Args, DetectedMultilibs &Result) {
   Multilib::flags_list Flags;
   bool IsA7 = false;
   if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
@@ -172,8 +170,7 @@ OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, 
const ArgList &Args)
   Paths);
 }
 
-ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(
-const ArgList &Args) const {
+ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const {
   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) {
 StringRef Value = A->getValue();
 if (Value != "compiler-rt")
@@ -184,20 +181,19 @@ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(
   return ToolChain::RLT_CompilerRT;
 }
 
-ToolChain::CXXStdlibType
-OHOS::GetCXXStdlibType(const ArgList &Args) const {
+ToolChain::CXXStdlibType OHOS::GetCXXStdlibType(const ArgList &Args) const {
   if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
 StringRef Value = A->getValue();
 if (Value != "libc++")
   getDriver().Diag(diag::err_drv_invalid_stdlib_name)
-<< A->getAsString(Args);
+  << A->getAsString(Args);
   }
 
   return ToolChain::CST_Libcxx;
 }
 
 void OHOS::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
-ArgStringList &CC1Args) const {
+ ArgStringList &CC1Args) const {
   const Driver &D = getDriver();
   const llvm::Triple &Triple = getTriple();
   std::string SysRoot = computeSysRoot();
@@ -258,7 +254,7 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList 
&DriverArgs,
 }
 
 void OHOS::AddCXXStdlibLibArgs(const ArgList &Args,
-  ArgStringList &CmdArgs) const {
+   ArgStringList &CmdArgs) const {
   switch (GetCXXStdlibType(Args)) {
   case ToolChain::CST_Libcxx:
 CmdArgs.push_back("-lc++");
@@ -291,7 +287,8 @@ ToolChain::path_list OHOS::getRuntimePaths() const {
 
   // First try the triple passed to driver as --target=.
   P.assign(D.ResourceDir);
-  llvm::sys::path::append(P, "lib", D.getTargetTriple(), 
SelectedMultilib.gccSuffix(

[clang] [compiler-rt] ohos: make configure fail if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is OFF (PR #121575)

2025-01-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Peng Huang (phuang)


Changes

OHOS driver doesn't support old runtime libraries layout, so make cmake 
configure report error if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is OFF.

[Driver][OHOS] Fix lld link issue

The link error is becasue clang rt libraries are installed in 
lib/${arch}-linux-unknown-ohos/ folder, however OHOS driver searches libraries 
in lib/${arch}-linux-ohos/ folder. Fix the problem by searching libraries in 
both lib/${arch}-linux-ohos/ and lib/${arch}-linux-unknown-ohos/

Also make cmake report error if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is not used 
for building OHOS runtime, since OHOS driver doesn't support the old layout

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/OHOS.cpp (+31-33) 
- (modified) compiler-rt/cmake/Modules/CompilerRTUtils.cmake (+5) 


``diff
diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp 
b/clang/lib/Driver/ToolChains/OHOS.cpp
index 6e1a09ae908b2f..a4137ba0416a7a 100644
--- a/clang/lib/Driver/ToolChains/OHOS.cpp
+++ b/clang/lib/Driver/ToolChains/OHOS.cpp
@@ -19,8 +19,8 @@
 #include "llvm/ProfileData/InstrProf.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/VirtualFileSystem.h"
 
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
@@ -58,11 +58,9 @@ static bool findOHOSMuslMultilibs(const Driver &D,
   return false;
 }
 
-static bool findOHOSMultilibs(const Driver &D,
-  const ToolChain &TC,
-  const llvm::Triple &TargetTriple,
-  StringRef Path, const ArgList &Args,
-  DetectedMultilibs &Result) {
+static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC,
+  const llvm::Triple &TargetTriple, StringRef Path,
+  const ArgList &Args, DetectedMultilibs &Result) {
   Multilib::flags_list Flags;
   bool IsA7 = false;
   if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
@@ -172,8 +170,7 @@ OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, 
const ArgList &Args)
   Paths);
 }
 
-ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(
-const ArgList &Args) const {
+ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const {
   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) {
 StringRef Value = A->getValue();
 if (Value != "compiler-rt")
@@ -184,20 +181,19 @@ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(
   return ToolChain::RLT_CompilerRT;
 }
 
-ToolChain::CXXStdlibType
-OHOS::GetCXXStdlibType(const ArgList &Args) const {
+ToolChain::CXXStdlibType OHOS::GetCXXStdlibType(const ArgList &Args) const {
   if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
 StringRef Value = A->getValue();
 if (Value != "libc++")
   getDriver().Diag(diag::err_drv_invalid_stdlib_name)
-<< A->getAsString(Args);
+  << A->getAsString(Args);
   }
 
   return ToolChain::CST_Libcxx;
 }
 
 void OHOS::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
-ArgStringList &CC1Args) const {
+ ArgStringList &CC1Args) const {
   const Driver &D = getDriver();
   const llvm::Triple &Triple = getTriple();
   std::string SysRoot = computeSysRoot();
@@ -258,7 +254,7 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList 
&DriverArgs,
 }
 
 void OHOS::AddCXXStdlibLibArgs(const ArgList &Args,
-  ArgStringList &CmdArgs) const {
+   ArgStringList &CmdArgs) const {
   switch (GetCXXStdlibType(Args)) {
   case ToolChain::CST_Libcxx:
 CmdArgs.push_back("-lc++");
@@ -291,7 +287,8 @@ ToolChain::path_list OHOS::getRuntimePaths() const {
 
   // First try the triple passed to driver as --target=.
   P.assign(D.ResourceDir);
-  llvm::sys::path::append(P, "lib", D.getTargetTriple(), 
SelectedMultilib.gccSuffix());
+  llvm::sys::path::append(P, "lib", D.getTargetTriple(),
+  SelectedMultilib.gccSuffix());
   Paths.push_back(P.c_str());
 
   // Second try the normalized triple.
@@ -340,26 +337,26 @@ std::string OHOS::getDynamicLinker(const ArgList &Args) 
const {
 
 std::string OHOS::getCompilerRT(const ArgList &Args, StringRef Component,
 FileType Type) const {
+  std::string CRTBasename =
+  buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
+
+  // Search libraries in ${arch}-linux-ohos directory first.
   SmallString<128> Path(getDriver().ResourceDir);
   llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()),
-  SelectedMultilib.gccSuffix());
-  const char

[clang] [clang][NFC][docs] Fix typo in LanguageExtensions (PR #121576)

2025-01-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Fabian Ritter (ritter-x2a)


Changes



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


1 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+1-1) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index cc5f1d4ddf4477..e020710c7aa4f5 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3641,7 +3641,7 @@ program location should be executed. It is expected to be 
used to implement
 `_
 intrinsic.
 
-The ``__builtin_allow_runtime_check()`` can be used within constrol structures
+The ``__builtin_allow_runtime_check()`` can be used within control structures
 like ``if`` to guard expensive runtime checks. The return value is determined
 by the following compiler options and may differ per call site:
 

``




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


[clang] [clang][NFC][docs] Fix typo in LanguageExtensions (PR #121576)

2025-01-03 Thread Fabian Ritter via cfe-commits

https://github.com/ritter-x2a created 
https://github.com/llvm/llvm-project/pull/121576

None

>From 67b8039fcd54adc2a599fcf6aa3f62ed8b348f3c Mon Sep 17 00:00:00 2001
From: Fabian Ritter 
Date: Fri, 3 Jan 2025 09:43:35 -0500
Subject: [PATCH] [clang][NFC][docs] Fix typo in LanguageExtensions

---
 clang/docs/LanguageExtensions.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index cc5f1d4ddf4477..e020710c7aa4f5 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3641,7 +3641,7 @@ program location should be executed. It is expected to be 
used to implement
 `_
 intrinsic.
 
-The ``__builtin_allow_runtime_check()`` can be used within constrol structures
+The ``__builtin_allow_runtime_check()`` can be used within control structures
 like ``if`` to guard expensive runtime checks. The return value is determined
 by the following compiler options and may differ per call site:
 

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


[clang] Reapply "[Driver][OHOS] Fix lld link issue for OHOS (#118192)" (PR #120159)

2025-01-03 Thread Peng Huang via cfe-commits

phuang wrote:

I created a new [PR](!https://github.com/llvm/llvm-project/pull/121575) , PTAL. 
Thanks

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


[clang] [compiler-rt] [Driver][OHOS] Fix lld link issue (PR #121575)

2025-01-03 Thread Peng Huang via cfe-commits

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


[clang] [compiler-rt] [Driver][OHOS] Fix lld link issue (PR #121575)

2025-01-03 Thread Peng Huang via cfe-commits

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


[clang] [Clang] Fix unexpanded packs in NTTP type constraints (PR #121296)

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

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

>From 102e031cae56c130f48f08bcb316b6f451facf49 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 29 Dec 2024 23:13:52 +0800
Subject: [PATCH 1/5] [Clang] Diagnose unexpanded packs for NTTP type
 constraints

---
 clang/docs/ReleaseNotes.rst |  1 +
 clang/lib/Sema/SemaTemplate.cpp | 12 +--
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp | 43 +
 3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8b984ecaefecaf..78ae4c8cab3a9e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -885,6 +885,7 @@ Bug Fixes to C++ Support
 - Fixed recognition of ``std::initializer_list`` when it's surrounded with 
``extern "C++"`` and exported
   out of a module (which is the case e.g. in MSVC's implementation of ``std`` 
module). (#GH118218)
 - Fixed a pack expansion issue in checking unexpanded parameter sizes. 
(#GH17042)
+- Clang now identifies unexpanded parameter packs within the type constraint 
on a non-type template parameter. (#GH88866)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 5e7a3c8484c88f..eac184d468ce9a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1530,9 +1530,17 @@ NamedDecl *Sema::ActOnNonTypeTemplateParameter(Scope *S, 
Declarator &D,
   Param->setAccess(AS_public);
 
   if (AutoTypeLoc TL = TInfo->getTypeLoc().getContainedAutoTypeLoc())
-if (TL.isConstrained())
-  if (AttachTypeConstraint(TL, Param, Param, D.getEllipsisLoc()))
+if (TL.isConstrained()) {
+  if (const ASTTemplateArgumentListInfo *ArgumentList =
+  TL.getConceptReference()->getTemplateArgsAsWritten())
+for (const TemplateArgumentLoc &Loc : ArgumentList->arguments()) {
+  Invalid |= DiagnoseUnexpandedParameterPack(
+  Loc, UnexpandedParameterPackContext::UPPC_TypeConstraint);
+}
+  if (!Invalid &&
+  AttachTypeConstraint(TL, Param, Param, D.getEllipsisLoc()))
 Invalid = true;
+}
 
   if (Invalid)
 Param->setInvalidDecl();
diff --git a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp 
b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
index 0674135aac483f..00236a8a839135 100644
--- a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
+++ b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
@@ -305,3 +305,46 @@ 
static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like,
 0>::type, long));
 
 }
+
+namespace GH88866 {
+
+template  struct index_by;
+
+template 
+concept InitFunc = true;
+
+namespace Invalid {
+
+template  auto... init>
+struct LazyLitMatrix;
+
+template <
+typename...Indices,
+InitFunc> auto... init
+// expected-error@-1 {{type constraint contains unexpanded parameter pack 
'Indices'}}
+>
+struct LazyLitMatrix, init...> {
+};
+
+static_assert(
+!__is_same(LazyLitMatrix, 42, 43>, 
LazyLitMatrix, 42, 43>));
+// expected-error@-1 {{static assertion failed}}
+}
+
+namespace Valid {
+
+template  auto... init>
+struct LazyLitMatrix;
+
+template <
+typename...Indices,
+InitFunc> auto... init
+>
+struct LazyLitMatrix, init...> {
+};
+
+static_assert(__is_same(LazyLitMatrix, 42, 43>, 
+LazyLitMatrix, 42, 43>));
+}
+
+}

>From 111d1002e081322fdb5f3fa8e94b15b99817b3b9 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 29 Dec 2024 23:30:57 +0800
Subject: [PATCH 2/5] Simplify the test

---
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp 
b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
index 00236a8a839135..509922c0a8f4fe 100644
--- a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
+++ b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
@@ -326,9 +326,8 @@ template <
 struct LazyLitMatrix, init...> {
 };
 
-static_assert(
-!__is_same(LazyLitMatrix, 42, 43>, 
LazyLitMatrix, 42, 43>));
-// expected-error@-1 {{static assertion failed}}
+using T = LazyLitMatrix, 42, 43>;
+
 }
 
 namespace Valid {
@@ -343,8 +342,8 @@ template <
 struct LazyLitMatrix, init...> {
 };
 
-static_assert(__is_same(LazyLitMatrix, 42, 43>, 
-LazyLitMatrix, 42, 43>));
+using T = LazyLitMatrix, 42, 43>;
+
 }
 
 }

>From 144f3c997def0a4d746edb111f2e7f90797b153e Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 31 Dec 2024 16:13:46 +0800
Subject: [PATCH 3/5] Let ... expand NTTP constraints

---
 clang/lib/AST/ASTContext.cpp |  2 +-
 clang/lib/Sema/SemaTemplate.cpp  | 14 +++---
 clang/lib/Sema/SemaTemplateDeduction.cpp |  3 ++-
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 8b4ae58e8427a9..a9ecb4ee9c76b2 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTC

[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

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


@@ -6089,16 +6090,16 @@ bool 
TreeTransform::TransformFunctionTypeParams(
 const FunctionProtoType::ExtParameterInfo *ParamInfos,
 SmallVectorImpl &OutParamTypes,
 SmallVectorImpl *PVars,
-Sema::ExtParameterInfoBuilder &PInfos,
-unsigned *LastParamTransformed) {
+Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed,
+bool IgnoreParameterIndex) {

zyn0217 wrote:

... Or let me see if I can refactor some common logics from 
TransformFunctionTypeParams

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


[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)

2025-01-03 Thread via cfe-commits

https://github.com/higher-performance updated 
https://github.com/llvm/llvm-project/pull/102040

>From 88208fd5fa392e9f5701d7548d0dcd24f8274709 Mon Sep 17 00:00:00 2001
From: higher-performance 
Date: Mon, 5 Aug 2024 15:04:19 -0400
Subject: [PATCH 01/13] Add Clang attribute to ensure that fields are
 initialized explicitly

---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |  9 
 clang/include/clang/AST/DeclCXX.h |  5 ++
 clang/include/clang/Basic/Attr.td |  8 
 clang/include/clang/Basic/AttrDocs.td | 29 
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/lib/AST/DeclCXX.cpp | 24 ++
 clang/lib/Sema/SemaDeclAttr.cpp   |  7 +++
 clang/lib/Sema/SemaInit.cpp   | 15 ++
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/SemaCXX/uninitialized.cpp  | 46 +++
 11 files changed, 152 insertions(+)

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index 6620840df0ced2..54f28046c63ebb 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -119,6 +119,15 @@ FIELD(HasInitMethod, 1, NO_MERGE)
 /// within anonymous unions or structs.
 FIELD(HasInClassInitializer, 1, NO_MERGE)
 
+/// Custom attribute that is True if any field is marked as requiring explicit
+/// initialization with [[clang::requires_explicit_initialization]] in a type
+/// without a user-provided default constructor, or if this is the case for any
+/// base classes and/or member variables whose types are aggregates.
+///
+/// In this case, default-construction is diagnosed, as it would not explicitly
+/// initialize the field.
+FIELD(HasUninitializedExplicitInitFields, 1, NO_MERGE)
+
 /// True if any field is of reference type, and does not have an
 /// in-class initializer.
 ///
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index c232556edeff70..66b88b337cf783 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1159,6 +1159,11 @@ class CXXRecordDecl : public RecordDecl {
   /// structs).
   bool hasInClassInitializer() const { return data().HasInClassInitializer; }
 
+  bool hasUninitializedExplicitInitFields() const {
+return !isUnion() && !hasUserProvidedDefaultConstructor() &&
+   data().HasUninitializedExplicitInitFields;
+  }
+
   /// Whether this class or any of its subobjects has any members of
   /// reference type which would make value-initialization ill-formed.
   ///
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52ad72eb608c31..5fa91f11f197b4 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1891,6 +1891,14 @@ def Leaf : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def ExplicitInit : InheritableAttr {
+  let Spellings = [Clang<"requires_explicit_initialization", 0>];
+  let Subjects = SubjectList<[Field], ErrorDiag>;
+  let Documentation = [ExplicitInitDocs];
+  let LangOpts = [CPlusPlus];
+  let SimpleHandler = 1;
+}
+
 def LifetimeBound : DeclOrTypeAttr {
   let Spellings = [Clang<"lifetimebound", 0>];
   let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fdad4c9a3ea191..0972424abc7159 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1608,6 +1608,35 @@ is not specified.
   }];
 }
 
+def ExplicitInitDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+The ``clang::requires_explicit_initialization`` attribute indicates that the
+field of an aggregate must be initialized explicitly by users when the class
+is constructed. Its usage is invalid on non-aggregates.
+
+Example usage:
+
+.. code-block:: c++
+
+  struct some_aggregate {
+int x;
+int y [[clang::requires_explicit_initialization]];
+  };
+
+  some_aggregate create() {
+return {.x = 1};  // error: y is not initialized explicitly
+  }
+
+This attribute is *not* a memory safety feature, and is *not* intended to guard
+against use of uninitialized memory.
+Rather, its intended use is in structs that represent "parameter objects", to
+allow extending them while ensuring that callers do not forget to specify
+values for newly added fields ("parameters").
+
+  }];
+}
+
 def NoUniqueAddressDocs : Documentation {
   let Category = DocCatField;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 3ac490d30371b1..aebc573fe72386 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -795,6 +795,7 @@ def Trigraphs

[clang] 119fc72 - NFC, explicitly specify the -fopenmp lib in spirv-openmp-toolchain.c test

2025-01-03 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2025-01-03T14:16:47+01:00
New Revision: 119fc720a19e047fee59d7f7446c911b158563e0

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

LOG: NFC, explicitly specify the -fopenmp lib in spirv-openmp-toolchain.c test

Don't rely on the default `CLANG_DEFAULT_OPENMP_RUNTIME` env variable
which is `libomp` by default.

Added: 


Modified: 
clang/test/Driver/spirv-openmp-toolchain.c

Removed: 




diff  --git a/clang/test/Driver/spirv-openmp-toolchain.c 
b/clang/test/Driver/spirv-openmp-toolchain.c
index 3eb1f22a03ed0a..377b2d9be0b09b 100644
--- a/clang/test/Driver/spirv-openmp-toolchain.c
+++ b/clang/test/Driver/spirv-openmp-toolchain.c
@@ -9,7 +9,7 @@
 // CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-emit-obj"
 // CHECK: clang-linker-wrapper{{.*}} "-o" "a.out"
 
-// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fopenmp 
-fopenmp-targets=spirv64-intel %s 2>&1 \
+// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu 
-fopenmp=libomp -fopenmp-targets=spirv64-intel %s 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-PHASES %s
 
 // CHECK-PHASES: 0: input, "[[INPUT:.+]]", c, (host-openmp)
@@ -28,8 +28,8 @@
 // CHECK-PHASES: 13: assembler, {12}, object, (host-openmp)
 // CHECK-PHASES: 14: clang-linker-wrapper, {13}, image, (host-openmp)
 
-// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-fopenmp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-BINDINGS
-// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-fopenmp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-BINDINGS
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-fopenmp=libomp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-BINDINGS
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-fopenmp=libomp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-BINDINGS
 
 // CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[INPUT:.+]]"], output: "[[HOST_BC:.+]]"
 // CHECK-BINDINGS: "spirv64-intel" - "clang", inputs: ["[[INPUT]]", 
"[[HOST_BC]]"], output: "[[DEVICE_TEMP_BC:.+]]"
@@ -38,8 +38,8 @@
 // CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[HOST_BC]]", "[[DEVICE_IMAGE]]"], output: "[[HOST_OBJ:.+]]"
 // CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: 
["[[HOST_OBJ]]"], output: "a.out"
 
-// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-save-temps -fopenmp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | 
FileCheck %s --check-prefix=CHECK-BINDINGS-TEMPS
-// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-save-temps -fopenmp -fopenmp-targets=spirv64-intel %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-BINDINGS-TEMPS
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-save-temps -fopenmp=libomp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | 
FileCheck %s --check-prefix=CHECK-BINDINGS-TEMPS
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-save-temps -fopenmp=libomp -fopenmp-targets=spirv64-intel %s 2>&1 | FileCheck 
%s --check-prefix=CHECK-BINDINGS-TEMPS
 // CHECK-BINDINGS-TEMPS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[INPUT:.+]]"], output: "[[HOST_PP:.+]]"
 // CHECK-BINDINGS-TEMPS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[HOST_PP]]"], output: "[[HOST_BC:.+]]"
 // CHECK-BINDINGS-TEMPS: "spirv64-intel" - "clang", inputs: ["[[INPUT]]"], 
output: "[[DEVICE_PP:.+]]"
@@ -51,14 +51,14 @@
 // CHECK-BINDINGS-TEMPS: "x86_64-unknown-linux-gnu" - "clang::as", inputs: 
["[[HOST_ASM]]"], output: "[[HOST_OBJ:.+]]"
 // CHECK-BINDINGS-TEMPS: "x86_64-unknown-linux-gnu" - "Offload::Linker", 
inputs: ["[[HOST_OBJ]]"], output: "a.out"
 
-// RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp 
-fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-EMIT-LLVM-IR
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S 
-fopenmp=libomp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-EMIT-LLVM-IR
 // CHECK-EMIT-LLVM-IR: "-cc1" "-triple" "spirv64-intel"{{.*}}"-emit-llvm-bc"
 
-// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp 
-fopenmp-targets=spirv64-intel \
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp 
-fopenmp-targets=spirv64-intel \
 // RUN: --sysroot=%S/Inputs/spirv-openmp/ %s 2>&1 | FileCheck 
--check-prefix=CHECK-GPULIB %s
 // CHECK-GPULIB: "-cc1" "-triple" 
"spirv64-intel"{{.*}}"-mlink-builtin-bitcode" "{{.*}}libomptarget-spi

[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-03 Thread Djordje Todorovic via cfe-commits


@@ -4963,6 +4963,10 @@ def msave_restore : Flag<["-"], "msave-restore">, 
Group,
 def mno_save_restore : Flag<["-"], "mno-save-restore">, 
Group,
   HelpText<"Disable using library calls for save and restore">;
 } // let Flags = [TargetSpecific]
+def mload_store_pairs : Flag<["-"], "mload-store-pairs">, 
Group;
+def mno_load_store_pairs : Flag<["-"], "mno-load-store-pairs">, 
Group;
+def mccmov : Flag<["-"], "mccmov">, Group;
+def mno_ccmov : Flag<["-"], "mno-ccmov">, Group;

djtodoro wrote:

Well, you are right. We have used those for testing purposes, and I will remove 
it. Thank you for the point.

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


[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)

2025-01-03 Thread via cfe-commits

higher-performance wrote:

Looks like the tests finally all pass with my last fix. Could we merge? :) 
Happy new year!

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


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-03 Thread Erich Keane via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

erichkeane wrote:

Curiously, and after I sent that, I realized why _WE_ of all compilers SHOULD 
warn here, even if others don't.  Clang supports/recognizes the prefixes of all 
of the major compilers, which drastically increases the chance that an 
unrecognized one is a typo rather than an intentional difference.  

It would be justifiable to have a 'list' of ones that we don't recognize, but 
acknowledge that is hidden under that extension warning, but we SHOULD be doing 
`gcc` and `gmu` and `clagn` the same severity/applicability as if you 
misspelled it as `caries_dependency`.

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


[clang] [clang][analyzer] Stable order for SymbolRef-keyed containers (PR #121551)

2025-01-03 Thread Arseniy Zaostrovnykh via cfe-commits


@@ -687,4 +711,35 @@ class SymbolVisitor {
 
 } // namespace clang
 
+// Override the default definition that would use pointer values of SymbolRefs
+// to order them, which is unstable due to ASLR.
+// Use the SymbolID instead which reflect the order in which the symbols were
+// allocated. This is usually stable across runs leading to the stability of
+// ConstraintMap and other containers using SymbolRef as keys.
+template <>
+struct ::llvm::ImutContainerInfo
+: public ImutProfileInfo {
+  using value_type =
+  typename ImutProfileInfo::value_type;
+  using value_type_ref =
+  typename ImutProfileInfo::value_type_ref;

necto wrote:

inlined
d32f6abb0404 [NFC] Explain why isDataEqual is necessary; inline type aliases.


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


[clang] [clang][analyzer] Stable order for SymbolRef-keyed containers (PR #121551)

2025-01-03 Thread Arseniy Zaostrovnykh via cfe-commits


@@ -687,4 +711,35 @@ class SymbolVisitor {
 
 } // namespace clang
 
+// Override the default definition that would use pointer values of SymbolRefs
+// to order them, which is unstable due to ASLR.
+// Use the SymbolID instead which reflect the order in which the symbols were
+// allocated. This is usually stable across runs leading to the stability of
+// ConstraintMap and other containers using SymbolRef as keys.
+template <>
+struct ::llvm::ImutContainerInfo
+: public ImutProfileInfo {
+  using value_type =
+  typename ImutProfileInfo::value_type;
+  using value_type_ref =
+  typename ImutProfileInfo::value_type_ref;
+  using key_type = value_type;
+  using key_type_ref = value_type_ref;
+  using data_type = bool;
+  using data_type_ref = bool;
+
+  static key_type_ref KeyOfValue(value_type_ref D) { return D; }
+  static data_type_ref DataOfValue(value_type_ref) { return true; }
+
+  static bool isEqual(key_type_ref LHS, key_type_ref RHS) {
+return LHS->getSymbolID() == RHS->getSymbolID();
+  }

necto wrote:

Inlined
d32f6abb0404 [NFC] Explain why isDataEqual is necessary; inline type aliases.


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


[clang] [clang][analyzer] Stable order for SymbolRef-keyed containers (PR #121551)

2025-01-03 Thread Arseniy Zaostrovnykh via cfe-commits


@@ -687,4 +711,35 @@ class SymbolVisitor {
 
 } // namespace clang
 
+// Override the default definition that would use pointer values of SymbolRefs
+// to order them, which is unstable due to ASLR.
+// Use the SymbolID instead which reflect the order in which the symbols were
+// allocated. This is usually stable across runs leading to the stability of
+// ConstraintMap and other containers using SymbolRef as keys.
+template <>
+struct ::llvm::ImutContainerInfo
+: public ImutProfileInfo {
+  using value_type =
+  typename ImutProfileInfo::value_type;
+  using value_type_ref =
+  typename ImutProfileInfo::value_type_ref;
+  using key_type = value_type;
+  using key_type_ref = value_type_ref;
+  using data_type = bool;
+  using data_type_ref = bool;

necto wrote:

This is due to the way ImmutableMap and ImmutableSet are implemented via a 
common interface of AVLTree
d32f6abb0404 [NFC] Explain why isDataEqual is necessary; inline type aliases.



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


[clang] [clang][analyzer] Stable order for SymbolRef-keyed containers (PR #121551)

2025-01-03 Thread Arseniy Zaostrovnykh via cfe-commits

https://github.com/necto updated 
https://github.com/llvm/llvm-project/pull/121551

>From 115814c2776b6acc8f4a08ec696a3cb27a7c0ebd Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Thu, 2 Jan 2025 09:58:53 +0100
Subject: [PATCH 1/5] Add SymbolID to every SymExpr, not just SymbolData

---
 .../Core/PathSensitive/SymExpr.h  | 25 ---
 .../Core/PathSensitive/SymbolManager.h| 19 +++---
 .../lib/StaticAnalyzer/Core/SymbolManager.cpp | 15 +++
 clang/test/Analysis/dump_egraph.cpp   |  2 +-
 .../expr-inspection-printState-diseq-info.c   | 12 -
 .../expr-inspection-printState-eq-classes.c   |  4 +--
 clang/test/Analysis/ptr-arith.cpp |  4 +--
 ...symbol-simplification-disequality-info.cpp | 20 +++
 ...-simplification-fixpoint-one-iteration.cpp | 12 -
 ...simplification-fixpoint-two-iterations.cpp | 18 ++---
 clang/test/Analysis/unary-sym-expr.c  |  6 ++---
 11 files changed, 75 insertions(+), 62 deletions(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
index 862a30c0e73633..2b6401eb05b72b 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
@@ -25,6 +25,8 @@ namespace ento {
 
 class MemRegion;
 
+using SymbolID = unsigned;
+
 /// Symbolic value. These values used to capture symbolic execution of
 /// the program.
 class SymExpr : public llvm::FoldingSetNode {
@@ -39,9 +41,19 @@ class SymExpr : public llvm::FoldingSetNode {
 
 private:
   Kind K;
+  /// A unique identifier for this symbol.
+  ///
+  /// It is useful for SymbolData to easily differentiate multiple symbols, but
+  /// also for "ephemeral" symbols, such as binary operations, because this id
+  /// can be used for arranging constraints or equivalence classes instead of
+  /// unstable pointer values.
+  ///
+  /// Note, however, that it can't be used in Profile because SymbolManager
+  /// needs to compute Profile before allocating SymExpr.
+  const SymbolID Sym;
 
 protected:
-  SymExpr(Kind k) : K(k) {}
+  SymExpr(Kind k, SymbolID Sym) : K(k), Sym(Sym) {}
 
   static bool isValidTypeForSymbol(QualType T) {
 // FIXME: Depending on whether we choose to deprecate structural symbols,
@@ -56,6 +68,8 @@ class SymExpr : public llvm::FoldingSetNode {
 
   Kind getKind() const { return K; }
 
+  SymbolID getSymbolID() const { return Sym; }
+
   virtual void dump() const;
 
   virtual void dumpToStream(raw_ostream &os) const {}
@@ -112,19 +126,14 @@ inline raw_ostream &operator<<(raw_ostream &os,
 
 using SymbolRef = const SymExpr *;
 using SymbolRefSmallVectorTy = SmallVector;
-using SymbolID = unsigned;
 
 /// A symbol representing data which can be stored in a memory location
 /// (region).
 class SymbolData : public SymExpr {
-  const SymbolID Sym;
-
   void anchor() override;
 
 protected:
-  SymbolData(Kind k, SymbolID sym) : SymExpr(k), Sym(sym) {
-assert(classof(this));
-  }
+  SymbolData(Kind k, SymbolID sym) : SymExpr(k, sym) { assert(classof(this)); }
 
 public:
   ~SymbolData() override = default;
@@ -132,8 +141,6 @@ class SymbolData : public SymExpr {
   /// Get a string representation of the kind of the region.
   virtual StringRef getKindStr() const = 0;
 
-  SymbolID getSymbolID() const { return Sym; }
-
   unsigned computeComplexity() const override {
 return 1;
   };
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
index 73732d532f630f..e6d7f5a37130d1 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -287,8 +287,8 @@ class SymbolCast : public SymExpr {
   QualType ToTy;
 
 public:
-  SymbolCast(const SymExpr *In, QualType From, QualType To)
-  : SymExpr(SymbolCastKind), Operand(In), FromTy(From), ToTy(To) {
+  SymbolCast(SymbolID Sym, const SymExpr *In, QualType From, QualType To)
+  : SymExpr(SymbolCastKind, Sym), Operand(In), FromTy(From), ToTy(To) {
 assert(In);
 assert(isValidTypeForSymbol(From));
 // FIXME: GenericTaintChecker creates symbols of void type.
@@ -333,8 +333,9 @@ class UnarySymExpr : public SymExpr {
   QualType T;
 
 public:
-  UnarySymExpr(const SymExpr *In, UnaryOperator::Opcode Op, QualType T)
-  : SymExpr(UnarySymExprKind), Operand(In), Op(Op), T(T) {
+  UnarySymExpr(SymbolID Sym, const SymExpr *In, UnaryOperator::Opcode Op,
+   QualType T)
+  : SymExpr(UnarySymExprKind, Sym), Operand(In), Op(Op), T(T) {
 // Note, some unary operators are modeled as a binary operator. E.g. ++x is
 // modeled as x + 1.
 assert((Op == UO_Minus || Op == UO_Not) && "non-supported unary 
expression");
@@ -381,8 +382,8 @@ class BinarySymExpr : public 

[clang] [clang][analyzer] Stable order for SymbolRef-keyed containers (PR #121551)

2025-01-03 Thread Arseniy Zaostrovnykh via cfe-commits

necto wrote:

> By the way, what fraction of the results is perturbed (replaced with other 
> random results) when this commit is activated? Did you run any "without this 
> commit vs with this commit" comparisons?

The difference is around 5-10 appearing/disappearing issues, and 50-100 issues 
with changed execution path (out of 83 K issues, with no Z3 refutation).

> As a tangential remark, I noticed that there seems to be heavy code 
> duplication between the `getXSymbol` methods of `SymbolManager` -- it would 
> be nice to unify them into a single template method that takes the symbol 
> class and the argument list types as template parameters (analogously to 
> `SymExprAllocator::make` which does similar forwarding). However, this 
> probably belongs to a separate NFC refactoring commit (and I can also 
> implement it if you don't have time for it). What do you think? Do you see 
> any obstacle (or perhaps conflict with changes that you're planning).

It makes sense and I have no future developments that would be incompatible 
with this refactoring. I did not do it in this PR to avoid scope creep. I will 
see on Monday, if I have some spare time to do this refactoring.

@steakhal, I believe I addressed all your feedback. If you are happy with the 
PR, feel free to merge it.

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


[clang] [clang][analyzer] Stable order for SymbolRef-keyed containers (PR #121551)

2025-01-03 Thread Arseniy Zaostrovnykh via cfe-commits


@@ -56,6 +68,8 @@ class SymExpr : public llvm::FoldingSetNode {
 
   Kind getKind() const { return K; }
 
+  SymbolID getSymbolID() const { return Sym; }

necto wrote:

Documented in
355c588f4469 az/order-by-symref-id [NFC] A doc comment explaining the 
SymExpr::getSymbolID()


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


[clang] [clang][analyzer] Stable order for SymbolRef-keyed containers (PR #121551)

2025-01-03 Thread Arseniy Zaostrovnykh via cfe-commits

https://github.com/necto updated 
https://github.com/llvm/llvm-project/pull/121551

>From 115814c2776b6acc8f4a08ec696a3cb27a7c0ebd Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Thu, 2 Jan 2025 09:58:53 +0100
Subject: [PATCH 1/4] Add SymbolID to every SymExpr, not just SymbolData

---
 .../Core/PathSensitive/SymExpr.h  | 25 ---
 .../Core/PathSensitive/SymbolManager.h| 19 +++---
 .../lib/StaticAnalyzer/Core/SymbolManager.cpp | 15 +++
 clang/test/Analysis/dump_egraph.cpp   |  2 +-
 .../expr-inspection-printState-diseq-info.c   | 12 -
 .../expr-inspection-printState-eq-classes.c   |  4 +--
 clang/test/Analysis/ptr-arith.cpp |  4 +--
 ...symbol-simplification-disequality-info.cpp | 20 +++
 ...-simplification-fixpoint-one-iteration.cpp | 12 -
 ...simplification-fixpoint-two-iterations.cpp | 18 ++---
 clang/test/Analysis/unary-sym-expr.c  |  6 ++---
 11 files changed, 75 insertions(+), 62 deletions(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
index 862a30c0e73633..2b6401eb05b72b 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
@@ -25,6 +25,8 @@ namespace ento {
 
 class MemRegion;
 
+using SymbolID = unsigned;
+
 /// Symbolic value. These values used to capture symbolic execution of
 /// the program.
 class SymExpr : public llvm::FoldingSetNode {
@@ -39,9 +41,19 @@ class SymExpr : public llvm::FoldingSetNode {
 
 private:
   Kind K;
+  /// A unique identifier for this symbol.
+  ///
+  /// It is useful for SymbolData to easily differentiate multiple symbols, but
+  /// also for "ephemeral" symbols, such as binary operations, because this id
+  /// can be used for arranging constraints or equivalence classes instead of
+  /// unstable pointer values.
+  ///
+  /// Note, however, that it can't be used in Profile because SymbolManager
+  /// needs to compute Profile before allocating SymExpr.
+  const SymbolID Sym;
 
 protected:
-  SymExpr(Kind k) : K(k) {}
+  SymExpr(Kind k, SymbolID Sym) : K(k), Sym(Sym) {}
 
   static bool isValidTypeForSymbol(QualType T) {
 // FIXME: Depending on whether we choose to deprecate structural symbols,
@@ -56,6 +68,8 @@ class SymExpr : public llvm::FoldingSetNode {
 
   Kind getKind() const { return K; }
 
+  SymbolID getSymbolID() const { return Sym; }
+
   virtual void dump() const;
 
   virtual void dumpToStream(raw_ostream &os) const {}
@@ -112,19 +126,14 @@ inline raw_ostream &operator<<(raw_ostream &os,
 
 using SymbolRef = const SymExpr *;
 using SymbolRefSmallVectorTy = SmallVector;
-using SymbolID = unsigned;
 
 /// A symbol representing data which can be stored in a memory location
 /// (region).
 class SymbolData : public SymExpr {
-  const SymbolID Sym;
-
   void anchor() override;
 
 protected:
-  SymbolData(Kind k, SymbolID sym) : SymExpr(k), Sym(sym) {
-assert(classof(this));
-  }
+  SymbolData(Kind k, SymbolID sym) : SymExpr(k, sym) { assert(classof(this)); }
 
 public:
   ~SymbolData() override = default;
@@ -132,8 +141,6 @@ class SymbolData : public SymExpr {
   /// Get a string representation of the kind of the region.
   virtual StringRef getKindStr() const = 0;
 
-  SymbolID getSymbolID() const { return Sym; }
-
   unsigned computeComplexity() const override {
 return 1;
   };
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
index 73732d532f630f..e6d7f5a37130d1 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -287,8 +287,8 @@ class SymbolCast : public SymExpr {
   QualType ToTy;
 
 public:
-  SymbolCast(const SymExpr *In, QualType From, QualType To)
-  : SymExpr(SymbolCastKind), Operand(In), FromTy(From), ToTy(To) {
+  SymbolCast(SymbolID Sym, const SymExpr *In, QualType From, QualType To)
+  : SymExpr(SymbolCastKind, Sym), Operand(In), FromTy(From), ToTy(To) {
 assert(In);
 assert(isValidTypeForSymbol(From));
 // FIXME: GenericTaintChecker creates symbols of void type.
@@ -333,8 +333,9 @@ class UnarySymExpr : public SymExpr {
   QualType T;
 
 public:
-  UnarySymExpr(const SymExpr *In, UnaryOperator::Opcode Op, QualType T)
-  : SymExpr(UnarySymExprKind), Operand(In), Op(Op), T(T) {
+  UnarySymExpr(SymbolID Sym, const SymExpr *In, UnaryOperator::Opcode Op,
+   QualType T)
+  : SymExpr(UnarySymExprKind, Sym), Operand(In), Op(Op), T(T) {
 // Note, some unary operators are modeled as a binary operator. E.g. ++x is
 // modeled as x + 1.
 assert((Op == UO_Minus || Op == UO_Not) && "non-supported unary 
expression");
@@ -381,8 +382,8 @@ class BinarySymExpr : public 

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

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


@@ -805,7 +805,6 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(
   SemaRef, CodeSynthesisContext::BuildingDeductionGuides,
   PointOfInstantiation, InstantiationRange, Entity) {}
 
-

ricejasonf wrote:

Sorry, `git clang-format` keeps modifying this.

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


[clang] [llvm] [Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (PR #120507)

2025-01-03 Thread Jon Roelofs via cfe-commits

jroelofs wrote:

IIUC `__MACH__` means "the kernel is Mach, and we're going to be loaded by 
dyld", and `apple-none-macho` targets is _not_ that.

> as Swift expects all MachO targets to have that defined.

can you elaborate on that expectation?

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


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

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


@@ -15991,6 +15991,13 @@ 
TreeTransform::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
   return E;
 }
 
+template 
+ExprResult TreeTransform::TransformResolvedUnexpandedPackExpr(
+ResolvedUnexpandedPackExpr *E) {
+  // Default behavior is to do nothing with this transformation.

ricejasonf wrote:

I was about to do this, but I see I followed the convention of the other 
ParmPackExpr kinds above it. Are you sure you want me to move template 
instantiation stuff into TreeTransform?

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


[clang] [Clang][ASTMatcher] Add `dependentTemplateSpecializationType` AST mat… (PR #121435)

2025-01-03 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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


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


[clang] [Clang][ASTMatcher] Add `dependentTemplateSpecializationType` AST mat… (PR #121435)

2025-01-03 Thread Nathan Ridge via cfe-commits

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


[clang] d85b22e - [Clang][ASTMatcher] Add `dependentTemplateSpecializationType` matcher (#121435)

2025-01-03 Thread via cfe-commits

Author: kefan cao
Date: 2025-01-03T16:32:02-05:00
New Revision: d85b22ed5dbb794835fd4b5166d5bb79ad9e09f2

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

LOG: [Clang][ASTMatcher] Add `dependentTemplateSpecializationType` matcher 
(#121435)

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

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/docs/ReleaseNotes.rst
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/AST/ASTImporterTest.cpp
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 8564f2650d205f..fc557888013254 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -2546,6 +2546,17 @@ Node Matchers
   };
 
 
+MatcherType>dependentTemplateSpecializationTypeMatcherDependentTemplateSpecializationType>...
+Matches a dependent template 
specialization type.
+
+Example matches A::template B
+
+  template struct A;
+  template struct declToImport {
+typename A::template B a;
+  };
+
+
 MatcherType>deducedTemplateSpecializationTypeMatcherDeducedTemplateSpecializationType>...
 Matches C++17 deduced template 
specialization types, e.g. deduced class
 template types.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 61d6aa2216cd06..5e75fc447636e0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1114,6 +1114,8 @@ AST Matchers
 
 - Add ``dependentNameType`` matcher to match a dependent name type.
 
+- Add ``dependentTemplateSpecializationType`` matcher to match a dependent 
template specialization type.
+
 clang-format
 
 

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 9a046714068a51..dd0fedb2cda2d4 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7721,6 +7721,18 @@ AST_MATCHER_P(DecayedType, hasDecayedType, 
internal::Matcher,
 /// \endcode
 extern const AstTypeMatcher dependentNameType;
 
+/// Matches a dependent template specialization type
+///
+/// Example matches A::template B
+/// \code
+///   template struct A;
+///   template struct declToImport {
+/// typename A::template B a;
+///   };
+/// \endcode
+extern const AstTypeMatcher
+dependentTemplateSpecializationType;
+
 /// Matches declarations whose declaration context, interpreted as a
 /// Decl, matches \c InnerMatcher.
 ///

diff  --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index a47633bf4bae24..9c7943a98d6523 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -1109,6 +1109,8 @@ const AstTypeMatcher 
templateTypeParmType;
 const AstTypeMatcher injectedClassNameType;
 const AstTypeMatcher decayedType;
 const AstTypeMatcher dependentNameType;
+const AstTypeMatcher
+dependentTemplateSpecializationType;
 AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasElementType,
  AST_POLYMORPHIC_SUPPORTED_TYPES(ArrayType,
  ComplexType));

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index bfdee412c53281..97e6bbc093fe46 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -224,6 +224,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(declRefExpr);
   REGISTER_MATCHER(dependentNameType);
   REGISTER_MATCHER(dependentScopeDeclRefExpr);
+  REGISTER_MATCHER(dependentTemplateSpecializationType);
   REGISTER_MATCHER(declStmt);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(decltypeType);

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index ee1d896f1ca6dc..d197d30df3adf5 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -763,10 +763,6 @@ TEST_P(ImportType, ImportPackExpansion) {
implicitCastExpr(has(declRefExpr();
 }
 
-const internal::VariadicDynCastAllOfMatcher
-dependentTemplateSpecializationType;
-
 TEST_P(ImportType, ImportDependentTemplateSpecialization)

[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2025-01-03 Thread Tony Tye via cfe-commits


@@ -537,7 +537,11 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(const 
LangOptions &LangOpts,
 break;
   }
 
-  if (Ordering != llvm::AtomicOrdering::SequentiallyConsistent) {
+  // OpenCL assumes by default that atomic scopes are per-address space for
+  // non-sequentially consistent operations.
+  if (Scope >= SyncScope::OpenCLWorkGroup &&

t-tye wrote:

It looks like the code is using the argument to specify what memory model 
semantics are being requested. This function is not itself OpenCL specific. It 
would be the caller of this function that has to decide if it wants to use the 
OpenCL specific enumerators or not. The caller may decide based on the language 
being compiler, or may be due to a piece of code being in another language with 
some pragma that can be used to specify a request for OpenCL memory model 
semantics. This function itself is just specting the meaning of the argument it 
is given.

Or am I missing something?

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


[clang] Deprecate order file instrumentation (PR #121514)

2025-01-03 Thread Ellis Hoag via cfe-commits

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


[clang] 432a871 - Deprecate order file instrumentation (#121514)

2025-01-03 Thread via cfe-commits

Author: Ellis Hoag
Date: 2025-01-03T11:23:35-08:00
New Revision: 432a871ba8f6a62272a7ef1162305328b0de7802

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

LOG: Deprecate order file instrumentation (#121514)

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/clang_f_opts.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 523761f5e0d801..12edfbb171d34c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1890,7 +1890,7 @@ defm pseudo_probe_for_profiling : 
BoolFOption<"pseudo-probe-for-profiling",
   " pseudo probes for sample profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Visibility<[ClangOption, CC1Option, CLOption]>,
-HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;
+HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var). Deprecated, please use temporal profiling.">;
 def fprofile_list_EQ : Joined<["-"], "fprofile-list=">,
 Group, Visibility<[ClangOption, CC1Option, CLOption]>,
 HelpText<"Filename defining the list of functions/files to instrument. "

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index a020e00cd17392..daf863c78d303f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8010,15 +8010,19 @@ void Clang::ConstructJob(Compilation &C, const 
JobAction &JA,
 }
   }
 
-  if (Args.hasArg(options::OPT_forder_file_instrumentation)) {
- CmdArgs.push_back("-forder-file-instrumentation");
- // Enable order file instrumentation when ThinLTO is not on. When ThinLTO 
is
- // on, we need to pass these flags as linker flags and that will be 
handled
- // outside of the compiler.
- if (!IsUsingLTO) {
-   CmdArgs.push_back("-mllvm");
-   CmdArgs.push_back("-enable-order-file-instrumentation");
- }
+  if (const Arg *A =
+  Args.getLastArg(options::OPT_forder_file_instrumentation)) {
+D.Diag(diag::warn_drv_deprecated_arg)
+<< A->getAsString(Args) << /*hasReplacement=*/true
+<< "-mllvm -pgo-temporal-instrumentation";
+CmdArgs.push_back("-forder-file-instrumentation");
+// Enable order file instrumentation when ThinLTO is not on. When ThinLTO 
is
+// on, we need to pass these flags as linker flags and that will be handled
+// outside of the compiler.
+if (!IsUsingLTO) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-enable-order-file-instrumentation");
+}
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_fforce_enable_int128,

diff  --git a/clang/test/Driver/clang_f_opts.c 
b/clang/test/Driver/clang_f_opts.c
index ddbf1fd951c84e..2b72068eae1eeb 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -364,6 +364,7 @@
 // RUN: -fno-devirtualize-speculatively   \
 // RUN: -fslp-vectorize-aggressive\
 // RUN: -fno-slp-vectorize-aggressive \
+// RUN: -forder-file-instrumentation  \
 // RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-WARNING %s
 // CHECK-WARNING-DAG: optimization flag '-finline-limit=1000' is not supported
 // CHECK-WARNING-DAG: optimization flag '-finline-limit' is not supported
@@ -423,6 +424,7 @@
 // CHECK-WARNING-DAG: optimization flag '-fno-devirtualize-speculatively' is 
not supported
 // CHECK-WARNING-DAG: the flag '-fslp-vectorize-aggressive' has been 
deprecated and will be ignored
 // CHECK-WARNING-DAG: the flag '-fno-slp-vectorize-aggressive' has been 
deprecated and will be ignored
+// CHECK-WARNING-DAG: argument '-forder-file-instrumentation' is deprecated, 
use '-mllvm -pgo-temporal-instrumentation' instead
 
 // Test that we mute the warning on these
 // RUN: %clang -### -finline-limit=1000 -Wno-invalid-command-line-argument 
 \



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


[clang-tools-extra] [clang-tidy] New option `CompilationArgsToRemoveRegex` to remove arguments from the command line (PR #111453)

2025-01-03 Thread Félix-Antoine Constantin via cfe-commits

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


[clang] [llvm] [SPIRV] Add Target Builtins using Distance ext as an example (PR #121598)

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

https://github.com/farzonl created 
https://github.com/llvm/llvm-project/pull/121598

- Update pr labeler so new SPIRV files get properly labeled.
- Add distance target builtin to BuiltinsSPIRV.td.
- Update TargetBuiltins.h to account for spirv builtins.
- Update clang basic CMakeLists.txt to build spirv builtin tablegen.
- Hook up sema for SPIRV in Sema.h|cpp, SemaSPIRV.h|cpp, and SemaChecking.cpp.
- Hookup sprv target builtins to SPIR.h|SPIR.cpp target.
- Update GBuiltin.cpp to emit spirv intrinsics when we get the expected spirv 
target builtin.

Consensus was reach in this RFC to add both target builtins and pattern 
matching: 
https://discourse.llvm.org/t/rfc-add-targetbuiltins-for-spirv-to-support-hlsl/83329.

pattern matching will come in a separate pr this one just sets up the 
groundwork to do target builtins for spirv.

>From 74f86806bbdf1397973f70043ce0856bc6a4a4a7 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Fri, 3 Jan 2025 14:52:31 -0500
Subject: [PATCH] [SPIRV] Add Target Builtins using Distance ext as an example

- Update pr labeler so new SPIRV files get properly labeled.
- Add distance target builtin to BuiltinsSPIRV.td.
- Update TargetBuiltins.h to account for spirv builtins.
- Update clang basic CMakeLists.txt to build spirv builtin tablegen.
- Hook up sema for SPIRV in Sema.h|cpp, SemaSPIRV.h|cpp, and SemaChecking.cpp.
- Hookup sprv target builtins to SPIR.h|SPIR.cpp target.
- Update GBuiltin.cpp to emit spirv intrinsics when we get the expected
  spirv target builtin.
-
---
 .github/new-prs-labeler.yml   |  5 ++
 clang/include/clang/Basic/BuiltinsSPIRV.td| 15 +
 clang/include/clang/Basic/CMakeLists.txt  |  4 ++
 clang/include/clang/Basic/TargetBuiltins.h| 10 
 clang/include/clang/Sema/Sema.h   |  7 +++
 clang/include/clang/Sema/SemaSPIRV.h  | 29 +
 clang/lib/Basic/Targets/SPIR.cpp  | 13 
 clang/lib/Basic/Targets/SPIR.h|  2 +-
 clang/lib/CodeGen/CGBuiltin.cpp   | 22 +++
 clang/lib/CodeGen/CodeGenFunction.h   |  1 +
 clang/lib/Sema/CMakeLists.txt |  1 +
 clang/lib/Sema/Sema.cpp   |  2 +
 clang/lib/Sema/SemaChecking.cpp   |  3 +
 clang/lib/Sema/SemaSPIRV.cpp  | 59 +++
 clang/test/CodeGenSPIRV/Builtins/distance.c   | 31 ++
 .../test/SemaSPIRV/BuiltIns/distance-errors.c | 23 
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  1 +
 .../Target/SPIRV/SPIRVInstructionSelector.cpp |  2 +
 .../CodeGen/SPIRV/hlsl-intrinsics/distance.ll | 33 +++
 llvm/test/CodeGen/SPIRV/opencl/distance.ll| 34 +++
 .../gn/secondary/clang/lib/Sema/BUILD.gn  |  1 +
 21 files changed, 297 insertions(+), 1 deletion(-)
 create mode 100644 clang/include/clang/Basic/BuiltinsSPIRV.td
 create mode 100644 clang/include/clang/Sema/SemaSPIRV.h
 create mode 100644 clang/lib/Sema/SemaSPIRV.cpp
 create mode 100644 clang/test/CodeGenSPIRV/Builtins/distance.c
 create mode 100644 clang/test/SemaSPIRV/BuiltIns/distance-errors.c
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/distance.ll
 create mode 100644 llvm/test/CodeGen/SPIRV/opencl/distance.ll

diff --git a/.github/new-prs-labeler.yml b/.github/new-prs-labeler.yml
index 0aa05cd027a47f..566308bb3df8d6 100644
--- a/.github/new-prs-labeler.yml
+++ b/.github/new-prs-labeler.yml
@@ -661,6 +661,11 @@ backend:DirectX:
 
 backend:SPIR-V:
   - clang/lib/Driver/ToolChains/SPIRV.*
+  - clang/lib/Sema/SemaSPIRV.cpp
+  - clang/include/clang/Sema/SemaSPIRV.h
+  - clang/include/clang/Basic/BuiltinsSPIRV.td
+  - clang/test/CodeGenSPIRV/**
+  - clang/test/SemaSPIRV/**
   - llvm/lib/Target/SPIRV/**
   - llvm/test/CodeGen/SPIRV/**
   - llvm/test/Frontend/HLSL/**
diff --git a/clang/include/clang/Basic/BuiltinsSPIRV.td 
b/clang/include/clang/Basic/BuiltinsSPIRV.td
new file mode 100644
index 00..195c13573d047f
--- /dev/null
+++ b/clang/include/clang/Basic/BuiltinsSPIRV.td
@@ -0,0 +1,15 @@
+//===--- BuiltinsSPIRV.td - SPIRV Builtin function database -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+include "clang/Basic/BuiltinsBase.td"
+
+def HLSLDistance : Builtin {
+  let Spellings = ["__builtin_spirv_distance"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 76ac3367e23a66..a53f537fc171a9 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -60,6 +60,10 @@ clang_tablegen(BuiltinsRISCV.inc -gen-clang-builtins
   SOURCE BuiltinsRISCV.td
   TARGET ClangBuiltinsRISCV)
 
+clang_tablegen(Builti

[clang] [llvm] [SPIRV] Add Target Builtins using Distance ext as an example (PR #121598)

2025-01-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Farzon Lotfi (farzonl)


Changes

- Update pr labeler so new SPIRV files get properly labeled.
- Add distance target builtin to BuiltinsSPIRV.td.
- Update TargetBuiltins.h to account for spirv builtins.
- Update clang basic CMakeLists.txt to build spirv builtin tablegen.
- Hook up sema for SPIRV in Sema.h|cpp, SemaSPIRV.h|cpp, and SemaChecking.cpp.
- Hookup sprv target builtins to SPIR.h|SPIR.cpp target.
- Update GBuiltin.cpp to emit spirv intrinsics when we get the expected spirv 
target builtin.

Consensus was reach in this RFC to add both target builtins and pattern 
matching: 
https://discourse.llvm.org/t/rfc-add-targetbuiltins-for-spirv-to-support-hlsl/83329.

pattern matching will come in a separate pr this one just sets up the 
groundwork to do target builtins for spirv.

---

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


21 Files Affected:

- (modified) .github/new-prs-labeler.yml (+5) 
- (added) clang/include/clang/Basic/BuiltinsSPIRV.td (+15) 
- (modified) clang/include/clang/Basic/CMakeLists.txt (+4) 
- (modified) clang/include/clang/Basic/TargetBuiltins.h (+10) 
- (modified) clang/include/clang/Sema/Sema.h (+7) 
- (added) clang/include/clang/Sema/SemaSPIRV.h (+29) 
- (modified) clang/lib/Basic/Targets/SPIR.cpp (+13) 
- (modified) clang/lib/Basic/Targets/SPIR.h (+1-1) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+22) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+1) 
- (modified) clang/lib/Sema/CMakeLists.txt (+1) 
- (modified) clang/lib/Sema/Sema.cpp (+2) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+3) 
- (added) clang/lib/Sema/SemaSPIRV.cpp (+59) 
- (added) clang/test/CodeGenSPIRV/Builtins/distance.c (+31) 
- (added) clang/test/SemaSPIRV/BuiltIns/distance-errors.c (+23) 
- (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (+1) 
- (modified) llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp (+2) 
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/distance.ll (+33) 
- (added) llvm/test/CodeGen/SPIRV/opencl/distance.ll (+34) 
- (modified) llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn (+1) 


``diff
diff --git a/.github/new-prs-labeler.yml b/.github/new-prs-labeler.yml
index 0aa05cd027a47f..566308bb3df8d6 100644
--- a/.github/new-prs-labeler.yml
+++ b/.github/new-prs-labeler.yml
@@ -661,6 +661,11 @@ backend:DirectX:
 
 backend:SPIR-V:
   - clang/lib/Driver/ToolChains/SPIRV.*
+  - clang/lib/Sema/SemaSPIRV.cpp
+  - clang/include/clang/Sema/SemaSPIRV.h
+  - clang/include/clang/Basic/BuiltinsSPIRV.td
+  - clang/test/CodeGenSPIRV/**
+  - clang/test/SemaSPIRV/**
   - llvm/lib/Target/SPIRV/**
   - llvm/test/CodeGen/SPIRV/**
   - llvm/test/Frontend/HLSL/**
diff --git a/clang/include/clang/Basic/BuiltinsSPIRV.td 
b/clang/include/clang/Basic/BuiltinsSPIRV.td
new file mode 100644
index 00..195c13573d047f
--- /dev/null
+++ b/clang/include/clang/Basic/BuiltinsSPIRV.td
@@ -0,0 +1,15 @@
+//===--- BuiltinsSPIRV.td - SPIRV Builtin function database -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+include "clang/Basic/BuiltinsBase.td"
+
+def HLSLDistance : Builtin {
+  let Spellings = ["__builtin_spirv_distance"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 76ac3367e23a66..a53f537fc171a9 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -60,6 +60,10 @@ clang_tablegen(BuiltinsRISCV.inc -gen-clang-builtins
   SOURCE BuiltinsRISCV.td
   TARGET ClangBuiltinsRISCV)
 
+clang_tablegen(BuiltinsSPIRV.inc -gen-clang-builtins
+  SOURCE BuiltinsSPIRV.td
+  TARGET ClangBuiltinsSPIRV)
+
 clang_tablegen(BuiltinsX86.inc -gen-clang-builtins
   SOURCE BuiltinsX86.td
   TARGET ClangBuiltinsX86)
diff --git a/clang/include/clang/Basic/TargetBuiltins.h 
b/clang/include/clang/Basic/TargetBuiltins.h
index a14fd2c4b224d8..81b8895622a4b1 100644
--- a/clang/include/clang/Basic/TargetBuiltins.h
+++ b/clang/include/clang/Basic/TargetBuiltins.h
@@ -119,6 +119,16 @@ namespace clang {
   };
   }
 
+  /// SPIRV builtins
+  namespace SPIRV {
+  enum {
+LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
+#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
+#include "clang/Basic/BuiltinsSPIRV.inc"
+LastTSBuiltin
+  };
+  } // namespace SPIRV
+
   /// X86 builtins
   namespace X86 {
   enum {
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5ee7ea48cc983c..a41f16f6dc8c9b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -173,6 +173,7 @@ class SemaOpenMP;
 class SemaPPC

[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2025-01-03 Thread Tony Tye via cfe-commits

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


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

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


@@ -951,28 +959,130 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator 
&D,
   return New;
 }
 
+namespace {
+// CheckBindingsCount
+//  - Checks the arity of the structured bindings
+//  - Creates the resolved pack expr if there is
+//one
+bool CheckBindingsCount(Sema &S, DecompositionDecl *DD, QualType DecompType,
+ArrayRef Bindings,
+unsigned MemberCount) {
+  auto BindingWithPackItr =
+  std::find_if(Bindings.begin(), Bindings.end(),
+   [](BindingDecl *D) -> bool { return D->isParameterPack(); 
});
+  bool HasPack = BindingWithPackItr != Bindings.end();
+  bool IsValid;
+  if (!HasPack) {
+IsValid = Bindings.size() == MemberCount;
+  } else {
+// there may not be more members than non-pack bindings
+IsValid = MemberCount >= Bindings.size() - 1;
+  }
+
+  if (IsValid && HasPack) {
+TemplateTypeParmDecl *DummyTemplateParam = TemplateTypeParmDecl::Create(
+S.Context, S.Context.getTranslationUnitDecl(),
+/*KeyLoc*/ SourceLocation(), /*NameLoc*/ SourceLocation(),
+/*TemplateDepth*/ 0, /*AutoParameterPosition*/ 0,
+/*Identifier*/ nullptr, false, /*IsParameterPack*/ true);
+
+// create the pack expr and assign it to the binding
+unsigned PackSize = MemberCount - Bindings.size() + 1;
+QualType PackType = S.Context.getPackExpansionType(
+QualType(DummyTemplateParam->getTypeForDecl(), 0), PackSize);
+(*BindingWithPackItr)
+->setBinding(PackType,
+ ResolvedUnexpandedPackExpr::Create(
+ S.Context, DD->getBeginLoc(), DecompType, PackSize));
+  }
+
+  if (IsValid)
+return false;
+
+  S.Diag(DD->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
+  << DecompType << (unsigned)Bindings.size() << MemberCount << MemberCount
+  << (MemberCount < Bindings.size());
+  return true;
+}
+
+// BindingInitWalker
+//  - This implements a forward iterating flattened view
+//of structured bindings that may have a nested pack.
+//It allows the user to set the init expr for either the
+//BindingDecl or its ResolvedUnexpandedPackExpr

ricejasonf wrote:

Do you mean that we should not have BindingDecls as TrailingObjects for the 
DecompositionDecl? I started doing something like this and it did mean that we 
would have a contiguous array of bindings. We would have to store a pointer to 
the BindingDecl that represents a pack to transform it. (I kind of started to 
do this and then abandoned it.)

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


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

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

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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

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

https://github.com/farzonl created 
https://github.com/llvm/llvm-project/pull/121611

None

>From 2de0c4911dfbc67b9492eb4f13bcd162e79c3d37 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Tue, 17 Dec 2024 18:30:23 -0500
Subject: [PATCH 1/2] [HLSL] Move length intrinsic to the header

---
 clang/include/clang/Basic/Builtins.td |   6 -
 clang/lib/CodeGen/CGBuiltin.cpp   |  25 --
 clang/lib/CodeGen/CGHLSLRuntime.h |   1 -
 clang/lib/Headers/hlsl/hlsl_detail.h  |  22 ++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  31 +--
 clang/lib/Sema/SemaHLSL.cpp   |  18 --
 clang/test/CodeGenHLSL/builtins/length.hlsl   | 232 +++-
 .../test/SemaHLSL/BuiltIns/length-errors.hlsl |  51 +++-
 llvm/include/llvm/IR/IntrinsicsDirectX.td |   1 -
 .../Target/DirectX/DXILIntrinsicExpansion.cpp |  30 --
 llvm/test/CodeGen/DirectX/length.ll   | 261 --
 llvm/test/CodeGen/DirectX/length_error.ll |  10 -
 .../DirectX/length_invalid_intrinsic_error.ll |  10 -
 .../length_invalid_intrinsic_error_scalar.ll  |  10 -
 14 files changed, 406 insertions(+), 302 deletions(-)
 delete mode 100644 llvm/test/CodeGen/DirectX/length_error.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error.ll
 delete mode 100644 
llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error_scalar.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index b5b47ae2746011..ab6e92e35dda5d 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4852,12 +4852,6 @@ def HLSLIsinf : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
-def HLSLLength : LangBuiltin<"HLSL_LANG"> {
-  let Spellings = ["__builtin_hlsl_length"];
-  let Attributes = [NoThrow, Const];
-  let Prototype = "void(...)";
-}
-
 def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_lerp"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 4d4b7428abd505..c4097f8df13de9 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19290,31 +19290,6 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType=*/X->getType(), CGM.getHLSLRuntime().getLerpIntrinsic(),
 ArrayRef{X, Y, S}, nullptr, "hlsl.lerp");
   }
-  case Builtin::BI__builtin_hlsl_length: {
-Value *X = EmitScalarExpr(E->getArg(0));
-
-assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
-   "length operand must have a float representation");
-// if the operand is a scalar, we can use the fabs llvm intrinsic directly
-if (!E->getArg(0)->getType()->isVectorType())
-  return EmitFAbs(*this, X);
-
-return Builder.CreateIntrinsic(
-/*ReturnType=*/X->getType()->getScalarType(),
-CGM.getHLSLRuntime().getLengthIntrinsic(), ArrayRef{X},
-nullptr, "hlsl.length");
-  }
-  case Builtin::BI__builtin_hlsl_normalize: {
-Value *X = EmitScalarExpr(E->getArg(0));
-
-assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
-   "normalize operand must have a float representation");
-
-return Builder.CreateIntrinsic(
-/*ReturnType=*/X->getType(),
-CGM.getHLSLRuntime().getNormalizeIntrinsic(), ArrayRef{X},
-nullptr, "hlsl.normalize");
-  }
   case Builtin::BI__builtin_hlsl_elementwise_degrees: {
 Value *X = EmitScalarExpr(E->getArg(0));
 
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index edb87f9d5efdf9..7f0af941b198b1 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -77,7 +77,6 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(Cross, cross)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Degrees, degrees)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
-  GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Normalize, normalize)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Rsqrt, rsqrt)
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 8d5fd941331531..c31f1745daae96 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -13,6 +13,14 @@ namespace hlsl {
 
 namespace __detail {
 
+template  struct is_same {
+  static const bool value = false;
+};
+
+template  struct is_same {
+  static const bool value = true;
+};
+
 template  struct enable_if {};
 
 template  struct enable_if {
@@ -33,6 +41,20 @@ constexpr enable_if_t bit_cast(T 
F) {
   return __builtin_bit_cast(U, F);
 }
 
+template 
+constexpr enable_if_t::value || is_same::value, T>
+length_impl(T X) {
+  return __builtin_elementwise_abs(X);
+}
+
+template 
+constexpr enable_if_t::value || is_same::value, T>
+length_vec_impl(vector X) {
+  vector XSquared = X * X;
+  T XSquaredSum = 

[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

2025-01-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Farzon Lotfi (farzonl)


Changes



---

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


14 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (-6) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (-25) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.h (-1) 
- (modified) clang/lib/Headers/hlsl/hlsl_detail.h (+25) 
- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+11-20) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (-18) 
- (modified) clang/test/CodeGenHLSL/builtins/length.hlsl (+151-73) 
- (modified) clang/test/SemaHLSL/BuiltIns/length-errors.hlsl (+36-15) 
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (-1) 
- (modified) llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp (-30) 
- (removed) llvm/test/CodeGen/DirectX/length.ll (-116) 
- (removed) llvm/test/CodeGen/DirectX/length_error.ll (-10) 
- (removed) llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error.ll (-10) 
- (removed) llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error_scalar.ll 
(-10) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index b5b47ae2746011..ab6e92e35dda5d 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4852,12 +4852,6 @@ def HLSLIsinf : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
-def HLSLLength : LangBuiltin<"HLSL_LANG"> {
-  let Spellings = ["__builtin_hlsl_length"];
-  let Attributes = [NoThrow, Const];
-  let Prototype = "void(...)";
-}
-
 def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_lerp"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 4d4b7428abd505..c4097f8df13de9 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19290,31 +19290,6 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType=*/X->getType(), CGM.getHLSLRuntime().getLerpIntrinsic(),
 ArrayRef{X, Y, S}, nullptr, "hlsl.lerp");
   }
-  case Builtin::BI__builtin_hlsl_length: {
-Value *X = EmitScalarExpr(E->getArg(0));
-
-assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
-   "length operand must have a float representation");
-// if the operand is a scalar, we can use the fabs llvm intrinsic directly
-if (!E->getArg(0)->getType()->isVectorType())
-  return EmitFAbs(*this, X);
-
-return Builder.CreateIntrinsic(
-/*ReturnType=*/X->getType()->getScalarType(),
-CGM.getHLSLRuntime().getLengthIntrinsic(), ArrayRef{X},
-nullptr, "hlsl.length");
-  }
-  case Builtin::BI__builtin_hlsl_normalize: {
-Value *X = EmitScalarExpr(E->getArg(0));
-
-assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
-   "normalize operand must have a float representation");
-
-return Builder.CreateIntrinsic(
-/*ReturnType=*/X->getType(),
-CGM.getHLSLRuntime().getNormalizeIntrinsic(), ArrayRef{X},
-nullptr, "hlsl.normalize");
-  }
   case Builtin::BI__builtin_hlsl_elementwise_degrees: {
 Value *X = EmitScalarExpr(E->getArg(0));
 
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index edb87f9d5efdf9..7f0af941b198b1 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -77,7 +77,6 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(Cross, cross)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Degrees, degrees)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
-  GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Normalize, normalize)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Rsqrt, rsqrt)
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 8d5fd941331531..ac4710e9f821bd 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -13,6 +13,14 @@ namespace hlsl {
 
 namespace __detail {
 
+template  struct is_same {
+  static const bool value = false;
+};
+
+template  struct is_same {
+  static const bool value = true;
+};
+
 template  struct enable_if {};
 
 template  struct enable_if {
@@ -33,6 +41,23 @@ constexpr enable_if_t bit_cast(T 
F) {
   return __builtin_bit_cast(U, F);
 }
 
+template 
+constexpr enable_if_t::value || is_same::value, T>
+length_impl(T X) {
+  return __builtin_elementwise_abs(X);
+}
+
+template 
+enable_if_t::value || is_same::value, T>
+length_vec_impl(vector X) {
+  vector XSquared = X * X;
+  T XSquaredSum = XSquared[0];
+  [unroll]
+  for (int i = 1; i < N; ++i)
+XSquaredSum += XSquared[i];
+  return __builtin_elementwise_sqrt(XSquaredSum);
+}
+
 } // namespace __detail
 } // namespace hlsl
 #endif //_HLSL_HLSL_DETAILS_H_
diff --git a/clang/lib/Headers/hlsl/

[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

2025-01-03 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 a106ad0f1d0f74fde3591149c63f3e94ec780fef 
74ad2ec542078c61064a103e1ea3154057489ccb --extensions cpp,h -- 
clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGHLSLRuntime.h 
clang/lib/Headers/hlsl/hlsl_detail.h clang/lib/Headers/hlsl/hlsl_intrinsics.h 
clang/lib/Sema/SemaHLSL.cpp llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index ac4710e9f8..392075d276 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -52,9 +52,7 @@ enable_if_t::value || is_same::value, T>
 length_vec_impl(vector X) {
   vector XSquared = X * X;
   T XSquaredSum = XSquared[0];
-  [unroll]
-  for (int i = 1; i < N; ++i)
-XSquaredSum += XSquared[i];
+  [unroll] for (int i = 1; i < N; ++i) XSquaredSum += XSquared[i];
   return __builtin_elementwise_sqrt(XSquaredSum);
 }
 
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index f51cd28bb4..cf287e598f 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1300,13 +1300,11 @@ float4 lerp(float4, float4, float4);
 const inline half length(half X) { return __detail::length_impl(X); }
 const inline float length(float X) { return __detail::length_impl(X); }
 
-template 
-const inline half length(vector X) {
+template  const inline half length(vector X) {
   return __detail::length_vec_impl(X);
 }
 
-template  
-const inline float length(vector X) {
+template  const inline float length(vector X) {
   return __detail::length_vec_impl(X);
 }
 

``




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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

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


@@ -33,6 +41,23 @@ constexpr enable_if_t bit_cast(T 
F) {
   return __builtin_bit_cast(U, F);
 }
 
+template 
+constexpr enable_if_t::value || is_same::value, T>
+length_impl(T X) {
+  return __builtin_elementwise_abs(X);
+}
+
+template 
+enable_if_t::value || is_same::value, T>
+length_vec_impl(vector X) {
+  vector XSquared = X * X;
+  T XSquaredSum = XSquared[0];
+  [unroll]
+  for (int i = 1; i < N; ++i)

farzonl wrote:

Because of the loop this can't be a constexpr. Made this change because its 
unlikely we will be able to use the vec reduce add builtin.

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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

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


@@ -1,73 +1,151 @@
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
-// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ 
-// RUN:   --check-prefixes=CHECK,NATIVE_HALF
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
-// RUN:   -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
-
-// NATIVE_HALF: define noundef half @
-// NATIVE_HALF: call half @llvm.fabs.f16(half
-// NO_HALF: call float @llvm.fabs.f32(float
-// NATIVE_HALF: ret half
-// NO_HALF: ret float
-half test_length_half(half p0)
-{
-  return length(p0);
-}
-// NATIVE_HALF: define noundef half @
-// NATIVE_HALF: %hlsl.length = call half @llvm.dx.length.v2f16
-// NO_HALF: %hlsl.length = call float @llvm.dx.length.v2f32(
-// NATIVE_HALF: ret half %hlsl.length
-// NO_HALF: ret float %hlsl.length
-half test_length_half2(half2 p0)
-{
-  return length(p0);
-}
-// NATIVE_HALF: define noundef half @
-// NATIVE_HALF: %hlsl.length = call half @llvm.dx.length.v3f16
-// NO_HALF: %hlsl.length = call float @llvm.dx.length.v3f32(
-// NATIVE_HALF: ret half %hlsl.length
-// NO_HALF: ret float %hlsl.length
-half test_length_half3(half3 p0)
-{
-  return length(p0);
-}
-// NATIVE_HALF: define noundef half @
-// NATIVE_HALF: %hlsl.length = call half @llvm.dx.length.v4f16
-// NO_HALF: %hlsl.length = call float @llvm.dx.length.v4f32(
-// NATIVE_HALF: ret half %hlsl.length
-// NO_HALF: ret float %hlsl.length
-half test_length_half4(half4 p0)
-{
-  return length(p0);
-}
-
-// CHECK: define noundef float @
-// CHECK: call float @llvm.fabs.f32(float
-// CHECK: ret float
-float test_length_float(float p0)
-{
-  return length(p0);
-}
-// CHECK: define noundef float @
-// CHECK: %hlsl.length = call float @llvm.dx.length.v2f32(
-// CHECK: ret float %hlsl.length
-float test_length_float2(float2 p0)
-{
-  return length(p0);
-}
-// CHECK: define noundef float @
-// CHECK: %hlsl.length = call float @llvm.dx.length.v3f32(
-// CHECK: ret float %hlsl.length
-float test_length_float3(float3 p0)
-{
-  return length(p0);
-}
-// CHECK: define noundef float @
-// CHECK: %hlsl.length = call float @llvm.dx.length.v4f32(
-// CHECK: ret float %hlsl.length
-float test_length_float4(float4 p0)
-{
-  return length(p0);
-}
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN: -emit-llvm -O2 -o - | FileCheck %s
+
+// CHECK-LABEL: define noundef half @_Z16test_length_halfDh(
+// CHECK-SAME: half noundef [[P0:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[ELT_ABS_I:%.*]] = tail call noundef half 
@llvm.fabs.f16(half [[P0]])
+// CHECK-NEXT:ret half [[ELT_ABS_I]]
+//
+half test_length_half(half p0)
+{
+  return length(p0);
+}
+
+// CHECK-LABEL: define noundef half @_Z17test_length_half2Dv2_Dh(
+// CHECK-SAME: <2 x half> noundef [[P0:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul <2 x half> [[P0]], [[P0]]
+// CHECK-NEXT:[[VECEXT_I:%.*]] = extractelement <2 x half> [[MUL_I]], i64 0
+// CHECK-NEXT:[[VECEXT1_I:%.*]] = extractelement <2 x half> [[MUL_I]], i64 
1
+// CHECK-NEXT:[[ADD_I:%.*]] = fadd half [[VECEXT1_I]], [[VECEXT_I]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call noundef half @llvm.sqrt.f16(half 
[[ADD_I]])
+// CHECK-NEXT:ret half [[TMP0]]
+//
+half test_length_half2(half2 p0)
+{
+  return length(p0);
+}
+
+// CHECK-LABEL: define noundef half @_Z17test_length_half3Dv3_Dh(
+// CHECK-SAME: <3 x half> noundef [[P0:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul <3 x half> [[P0]], [[P0]]
+// CHECK-NEXT:[[VECEXT_I:%.*]] = extractelement <3 x half> [[MUL_I]], i64 0
+// CHECK-NEXT:[[VECEXT1_I:%.*]] = extractelement <3 x half> [[MUL_I]], i64 
1
+// CHECK-NEXT:[[ADD_I:%.*]] = fadd half [[VECEXT_I]], [[VECEXT1_I]]
+// CHECK-NEXT:[[VECEXT1_I_1:%.*]] = extractelement <3 x half> [[MUL_I]], 
i64 2
+// CHECK-NEXT:[[ADD_I_1:%.*]] = fadd half [[ADD_I]], [[VECEXT1_I_1]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call noundef half @llvm.sqrt.f16(half 
[[ADD_I_1]])
+// CHECK-NEXT:ret half [[TMP0]]
+//
+half test_length_half3(half3 p0)
+{
+  return length(p0);
+}
+
+// CHECK-LABEL: define noundef half @_Z17test_length_half4Dv4_Dh(
+// CHECK-SAME: <4 x half> noundef [[P0:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul <4 x half> [[P0]], [[P0]]
+// CHECK-NEXT:[[VECEXT_I:%.*]] = extractelement <4 x half> [[MUL_I]], i64 0
+// CHECK-NEXT:[[VECEXT1_I:%.*]] = extractelement <4 x half> [[MUL_I]], i64 
1
+// CHECK-NEXT:[[ADD_I:%.*]] = fadd half [[VECEXT_I]], [[VECEXT1_I]]

[clang] [clang] Fix `gnu::init_priority` attribute handling for reserved values (PR #121577)

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


@@ -33,23 +33,22 @@ Two goo __attribute__((init_priority(2,3))) ( 5, 6 ); // 
expected-error {{'init_
 
 Two coo[2]  __attribute__((init_priority(100)));
 #if !defined(SYSTEM)
-  // expected-error@-2 {{'init_priority' attribute requires integer constant 
between 101 and 65535 inclusive}}
+  // expected-error@-2 {{requested 'init_priority' 100 is reserved for 
internal use}}
   // unknown-warning@-3 {{unknown attribute 'init_priority' ignored}}
 #endif
 
-Two boo[2]  __attribute__((init_priority(65536)));
-#if !defined(SYSTEM)
- // expected-error@-2 {{'init_priority' attribute requires integer constant 
between 101 and 65535 inclusive}}
- // unknown-warning@-3 {{unknown attribute 'init_priority' ignored}}
-#endif
+Two zoo[2]  __attribute__((init_priority(-1))); // expected-error 
{{'init_priority' attribute requires integer constant between 0 and 65535 
inclusive}}
+// unknown-warning@-1 {{unknown attribute 'init_priority' ignored}}
+
+Two boo[2]  __attribute__((init_priority(65536))); // expected-error 
{{'init_priority' attribute requires integer constant between 0 and 65535 
inclusive}}

shafik wrote:

Can we also test `65535` which should be valid, just for completeness sake.

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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

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

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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

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

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/121611

>From 2de0c4911dfbc67b9492eb4f13bcd162e79c3d37 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Tue, 17 Dec 2024 18:30:23 -0500
Subject: [PATCH 1/2] [HLSL] Move length intrinsic to the header

---
 clang/include/clang/Basic/Builtins.td |   6 -
 clang/lib/CodeGen/CGBuiltin.cpp   |  25 --
 clang/lib/CodeGen/CGHLSLRuntime.h |   1 -
 clang/lib/Headers/hlsl/hlsl_detail.h  |  22 ++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  31 +--
 clang/lib/Sema/SemaHLSL.cpp   |  18 --
 clang/test/CodeGenHLSL/builtins/length.hlsl   | 232 +++-
 .../test/SemaHLSL/BuiltIns/length-errors.hlsl |  51 +++-
 llvm/include/llvm/IR/IntrinsicsDirectX.td |   1 -
 .../Target/DirectX/DXILIntrinsicExpansion.cpp |  30 --
 llvm/test/CodeGen/DirectX/length.ll   | 261 --
 llvm/test/CodeGen/DirectX/length_error.ll |  10 -
 .../DirectX/length_invalid_intrinsic_error.ll |  10 -
 .../length_invalid_intrinsic_error_scalar.ll  |  10 -
 14 files changed, 406 insertions(+), 302 deletions(-)
 delete mode 100644 llvm/test/CodeGen/DirectX/length_error.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error.ll
 delete mode 100644 
llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error_scalar.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index b5b47ae2746011..ab6e92e35dda5d 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4852,12 +4852,6 @@ def HLSLIsinf : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
-def HLSLLength : LangBuiltin<"HLSL_LANG"> {
-  let Spellings = ["__builtin_hlsl_length"];
-  let Attributes = [NoThrow, Const];
-  let Prototype = "void(...)";
-}
-
 def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_lerp"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 4d4b7428abd505..c4097f8df13de9 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19290,31 +19290,6 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType=*/X->getType(), CGM.getHLSLRuntime().getLerpIntrinsic(),
 ArrayRef{X, Y, S}, nullptr, "hlsl.lerp");
   }
-  case Builtin::BI__builtin_hlsl_length: {
-Value *X = EmitScalarExpr(E->getArg(0));
-
-assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
-   "length operand must have a float representation");
-// if the operand is a scalar, we can use the fabs llvm intrinsic directly
-if (!E->getArg(0)->getType()->isVectorType())
-  return EmitFAbs(*this, X);
-
-return Builder.CreateIntrinsic(
-/*ReturnType=*/X->getType()->getScalarType(),
-CGM.getHLSLRuntime().getLengthIntrinsic(), ArrayRef{X},
-nullptr, "hlsl.length");
-  }
-  case Builtin::BI__builtin_hlsl_normalize: {
-Value *X = EmitScalarExpr(E->getArg(0));
-
-assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
-   "normalize operand must have a float representation");
-
-return Builder.CreateIntrinsic(
-/*ReturnType=*/X->getType(),
-CGM.getHLSLRuntime().getNormalizeIntrinsic(), ArrayRef{X},
-nullptr, "hlsl.normalize");
-  }
   case Builtin::BI__builtin_hlsl_elementwise_degrees: {
 Value *X = EmitScalarExpr(E->getArg(0));
 
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index edb87f9d5efdf9..7f0af941b198b1 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -77,7 +77,6 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(Cross, cross)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Degrees, degrees)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
-  GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Normalize, normalize)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Rsqrt, rsqrt)
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 8d5fd941331531..c31f1745daae96 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -13,6 +13,14 @@ namespace hlsl {
 
 namespace __detail {
 
+template  struct is_same {
+  static const bool value = false;
+};
+
+template  struct is_same {
+  static const bool value = true;
+};
+
 template  struct enable_if {};
 
 template  struct enable_if {
@@ -33,6 +41,20 @@ constexpr enable_if_t bit_cast(T 
F) {
   return __builtin_bit_cast(U, F);
 }
 
+template 
+constexpr enable_if_t::value || is_same::value, T>
+length_impl(T X) {
+  return __builtin_elementwise_abs(X);
+}
+
+template 
+constexpr enable_if_t::value || is_same::value, T>
+length_vec_impl(vector X) {
+  vector XSquared = X * X;
+  T XSquaredSum = __buil

[clang] [clang] Do not serialize function definitions without a body (PR #121550)

2025-01-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Alejandro Álvarez Ayllón (alejandro-alvarez-sonarsource)


Changes

An instantiated templated function definition may not have a body due to 
parsing errors inside the templated function. When serializing, an assert is 
triggered inside `ASTRecordWriter::AddFunctionDefinition`.

The instantiation may happen on an intermediate module.

The test case was reduced from `mp-units`.

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


2 Files Affected:

- (modified) clang/lib/Serialization/ASTWriter.cpp (+4-2) 
- (added) clang/test/Modules/missing-body-in-import.cpp (+42) 


``diff
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 4a6027943072c0..36b9e3e2ba1720 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -6227,8 +6227,10 @@ void ASTWriter::WriteDeclUpdatesBlocks(ASTContext 
&Context,
 // Add a trailing update record, if any. These must go last because we
 // lazily load their attached statement.
 if (!GeneratingReducedBMI || !CanElideDeclDef(D)) {
-  if (HasUpdatedBody) {
-const auto *Def = cast(D);
+  assert(!(HasUpdatedBody && HasAddedVarDefinition) &&
+ "Declaration can not be both a FunctionDecl and a VarDecl");
+  if (const auto *Def = dyn_cast(D);
+  HasUpdatedBody && Def->doesThisDeclarationHaveABody()) {
 Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION);
 Record.push_back(Def->isInlined());
 Record.AddSourceLocation(Def->getInnerLocStart());
diff --git a/clang/test/Modules/missing-body-in-import.cpp 
b/clang/test/Modules/missing-body-in-import.cpp
new file mode 100644
index 00..b52ebba15087a3
--- /dev/null
+++ b/clang/test/Modules/missing-body-in-import.cpp
@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++23 mod1.cppm -emit-module-interface -o mod1.pcm 
-fallow-pcm-with-compiler-errors -verify
+// RUN: %clang_cc1 -std=c++23 mod2.cppm -emit-module-interface -o mod2.pcm 
-fmodule-file=mod1=mod1.pcm -verify -fallow-pcm-with-compiler-errors
+// RUN: %clang_cc1 -std=c++23 mod3.cppm -emit-module-interface -o mod3.pcm 
-fmodule-file=mod1=mod1.pcm -fmodule-file=mod2=mod2.pcm -verify 
-fallow-pcm-with-compiler-errors
+// RUN: %clang_cc1 -std=c++23 main.cpp -fmodule-file=mod1=mod1.pcm 
-fmodule-file=mod2=mod2.pcm -fmodule-file=mod3=mod3.pcm -verify 
-fallow-pcm-with-compiler-errors -ast-dump-all
+
+//--- mod1.cppm
+export module mod1;
+
+export template 
+class A {
+public:
+  constexpr A(const char[], const char[]) {
+auto x = BrokenExpr; // expected-error {{use of undeclared identifier 
'BrokenExpr'}}
+  }
+};
+
+export template NTTP>
+struct B {};
+
+template < unsigned N, unsigned M >
+A(const char (&)[N], const char (&)[M]) -> A< 1, 1 >;
+
+//--- mod2.cppm
+export module mod2;
+import mod1;
+
+struct C: B  { // expected-error {{non-type template argument is 
not a constant expression}}
+  constexpr C(int a) { }
+};
+
+//--- mod3.cppm
+// expected-no-diagnostics
+export module mod3;
+export import mod2;
+
+//--- main.cpp
+// expected-no-diagnostics
+import mod3; // no crash

``




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


[clang] [clang] Do not serialize function definitions without a body (PR #121550)

2025-01-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alejandro Álvarez Ayllón (alejandro-alvarez-sonarsource)


Changes

An instantiated templated function definition may not have a body due to 
parsing errors inside the templated function. When serializing, an assert is 
triggered inside `ASTRecordWriter::AddFunctionDefinition`.

The instantiation may happen on an intermediate module.

The test case was reduced from `mp-units`.

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


2 Files Affected:

- (modified) clang/lib/Serialization/ASTWriter.cpp (+4-2) 
- (added) clang/test/Modules/missing-body-in-import.cpp (+42) 


``diff
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 4a6027943072c0..36b9e3e2ba1720 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -6227,8 +6227,10 @@ void ASTWriter::WriteDeclUpdatesBlocks(ASTContext 
&Context,
 // Add a trailing update record, if any. These must go last because we
 // lazily load their attached statement.
 if (!GeneratingReducedBMI || !CanElideDeclDef(D)) {
-  if (HasUpdatedBody) {
-const auto *Def = cast(D);
+  assert(!(HasUpdatedBody && HasAddedVarDefinition) &&
+ "Declaration can not be both a FunctionDecl and a VarDecl");
+  if (const auto *Def = dyn_cast(D);
+  HasUpdatedBody && Def->doesThisDeclarationHaveABody()) {
 Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION);
 Record.push_back(Def->isInlined());
 Record.AddSourceLocation(Def->getInnerLocStart());
diff --git a/clang/test/Modules/missing-body-in-import.cpp 
b/clang/test/Modules/missing-body-in-import.cpp
new file mode 100644
index 00..b52ebba15087a3
--- /dev/null
+++ b/clang/test/Modules/missing-body-in-import.cpp
@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++23 mod1.cppm -emit-module-interface -o mod1.pcm 
-fallow-pcm-with-compiler-errors -verify
+// RUN: %clang_cc1 -std=c++23 mod2.cppm -emit-module-interface -o mod2.pcm 
-fmodule-file=mod1=mod1.pcm -verify -fallow-pcm-with-compiler-errors
+// RUN: %clang_cc1 -std=c++23 mod3.cppm -emit-module-interface -o mod3.pcm 
-fmodule-file=mod1=mod1.pcm -fmodule-file=mod2=mod2.pcm -verify 
-fallow-pcm-with-compiler-errors
+// RUN: %clang_cc1 -std=c++23 main.cpp -fmodule-file=mod1=mod1.pcm 
-fmodule-file=mod2=mod2.pcm -fmodule-file=mod3=mod3.pcm -verify 
-fallow-pcm-with-compiler-errors -ast-dump-all
+
+//--- mod1.cppm
+export module mod1;
+
+export template 
+class A {
+public:
+  constexpr A(const char[], const char[]) {
+auto x = BrokenExpr; // expected-error {{use of undeclared identifier 
'BrokenExpr'}}
+  }
+};
+
+export template NTTP>
+struct B {};
+
+template < unsigned N, unsigned M >
+A(const char (&)[N], const char (&)[M]) -> A< 1, 1 >;
+
+//--- mod2.cppm
+export module mod2;
+import mod1;
+
+struct C: B  { // expected-error {{non-type template argument is 
not a constant expression}}
+  constexpr C(int a) { }
+};
+
+//--- mod3.cppm
+// expected-no-diagnostics
+export module mod3;
+export import mod2;
+
+//--- main.cpp
+// expected-no-diagnostics
+import mod3; // no crash

``




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


[clang] [llvm] [RISCV] Add support of Sdext, Sdtrig extentions (PR #120936)

2025-01-03 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp approved this pull request.

LGTM.

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


[clang] [clang] Do not serialize function definitions without a body (PR #121550)

2025-01-03 Thread Alejandro Álvarez Ayllón via cfe-commits

https://github.com/alejandro-alvarez-sonarsource created 
https://github.com/llvm/llvm-project/pull/121550

An instantiated templated function definition may not have a body due to 
parsing errors inside the templated function. When serializing, an assert is 
triggered inside `ASTRecordWriter::AddFunctionDefinition`.

The instantiation may happen on an intermediate module.

The test case was reduced from `mp-units`.

From fe4adf2f95aeb72436eead3567767c8c539811c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 
Date: Fri, 3 Jan 2025 08:58:23 +0100
Subject: [PATCH] [clang] Do not serialize function definitions without a body

An instantiated templated function definition may not have a body due
to parsing errors inside the templated function. When serializing, an
assert is tripped inside `ASTRecordWriter::AddFunctionDefinition` when
building with assertions enabled.

The instantiation may happen on an intermediate module.

The test case was reduced from `mp-units`.
---
 clang/lib/Serialization/ASTWriter.cpp |  6 ++-
 clang/test/Modules/missing-body-in-import.cpp | 42 +++
 2 files changed, 46 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Modules/missing-body-in-import.cpp

diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 4a6027943072c0..36b9e3e2ba1720 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -6227,8 +6227,10 @@ void ASTWriter::WriteDeclUpdatesBlocks(ASTContext 
&Context,
 // Add a trailing update record, if any. These must go last because we
 // lazily load their attached statement.
 if (!GeneratingReducedBMI || !CanElideDeclDef(D)) {
-  if (HasUpdatedBody) {
-const auto *Def = cast(D);
+  assert(!(HasUpdatedBody && HasAddedVarDefinition) &&
+ "Declaration can not be both a FunctionDecl and a VarDecl");
+  if (const auto *Def = dyn_cast(D);
+  HasUpdatedBody && Def->doesThisDeclarationHaveABody()) {
 Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION);
 Record.push_back(Def->isInlined());
 Record.AddSourceLocation(Def->getInnerLocStart());
diff --git a/clang/test/Modules/missing-body-in-import.cpp 
b/clang/test/Modules/missing-body-in-import.cpp
new file mode 100644
index 00..b52ebba15087a3
--- /dev/null
+++ b/clang/test/Modules/missing-body-in-import.cpp
@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++23 mod1.cppm -emit-module-interface -o mod1.pcm 
-fallow-pcm-with-compiler-errors -verify
+// RUN: %clang_cc1 -std=c++23 mod2.cppm -emit-module-interface -o mod2.pcm 
-fmodule-file=mod1=mod1.pcm -verify -fallow-pcm-with-compiler-errors
+// RUN: %clang_cc1 -std=c++23 mod3.cppm -emit-module-interface -o mod3.pcm 
-fmodule-file=mod1=mod1.pcm -fmodule-file=mod2=mod2.pcm -verify 
-fallow-pcm-with-compiler-errors
+// RUN: %clang_cc1 -std=c++23 main.cpp -fmodule-file=mod1=mod1.pcm 
-fmodule-file=mod2=mod2.pcm -fmodule-file=mod3=mod3.pcm -verify 
-fallow-pcm-with-compiler-errors -ast-dump-all
+
+//--- mod1.cppm
+export module mod1;
+
+export template 
+class A {
+public:
+  constexpr A(const char[], const char[]) {
+auto x = BrokenExpr; // expected-error {{use of undeclared identifier 
'BrokenExpr'}}
+  }
+};
+
+export template NTTP>
+struct B {};
+
+template < unsigned N, unsigned M >
+A(const char (&)[N], const char (&)[M]) -> A< 1, 1 >;
+
+//--- mod2.cppm
+export module mod2;
+import mod1;
+
+struct C: B  { // expected-error {{non-type template argument is 
not a constant expression}}
+  constexpr C(int a) { }
+};
+
+//--- mod3.cppm
+// expected-no-diagnostics
+export module mod3;
+export import mod2;
+
+//--- main.cpp
+// expected-no-diagnostics
+import mod3; // no crash

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


[clang] [clang] Implement __attribute__((format_matches)) (PR #116708)

2025-01-03 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier 
Message-ID:
In-Reply-To: 



@@ -595,6 +595,97 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
   llvm_unreachable("Invalid ArgType Kind!");
 }
 
+static analyze_format_string::ArgType::MatchKind
+integerTypeMatch(ASTContext &C, QualType A, QualType B, bool CheckSign) {
+  using MK = analyze_format_string::ArgType::MatchKind;
+
+  uint64_t IntSize = C.getTypeSize(C.IntTy);
+  uint64_t ASize = C.getTypeSize(A);
+  uint64_t BSize = C.getTypeSize(B);
+  if (std::max(ASize, IntSize) != std::max(BSize, IntSize))
+return MK::NoMatch;
+  if (CheckSign && A->isSignedIntegerType() != B->isSignedIntegerType())
+return MK::NoMatchSignedness;
+  if (ASize != BSize)
+return MK::MatchPromotion;
+  return MK::Match;
+}
+
+analyze_format_string::ArgType::MatchKind
+ArgType::matchesArgType(ASTContext &C, const ArgType &Other) const {
+  using AK = analyze_format_string::ArgType::Kind;
+
+  // Per matchesType.
+  if (K == AK::InvalidTy || Other.K == AK::InvalidTy)
+return NoMatch;
+  if (K == AK::UnknownTy || Other.K == AK::UnknownTy)

apple-fcloutier wrote:

The AK enumeration declares neither. The format checker bails out from 
unspecialized template functions; not sure how to get an AutoTy value in this 
context, but I'm happy to check what happens if you can help me with that.

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


[clang] [clang] Implement __attribute__((format_matches)) (PR #116708)

2025-01-03 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier 
Message-ID:
In-Reply-To: 


apple-fcloutier wrote:

I lost commit access during the purge, so either you or @ahatanak will need to 
press the button for me once we feel good about the change. As a result, there 
should be no concern that I might merge too early.

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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

2025-01-03 Thread Justin Bogner via cfe-commits


@@ -13,6 +13,14 @@ namespace hlsl {
 
 namespace __detail {
 
+template  struct is_same {
+  static const bool value = false;
+};
+
+template  struct is_same {
+  static const bool value = true;
+};

bogner wrote:

These seem fine, but we should make sure we're being aware of how much of 
standard C++ we're reimplementing in this header as we do more of this stuff.

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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

2025-01-03 Thread Justin Bogner via cfe-commits


@@ -33,6 +41,21 @@ constexpr enable_if_t bit_cast(T 
F) {
   return __builtin_bit_cast(U, F);
 }
 
+template 
+constexpr enable_if_t::value || is_same::value, T>
+length_impl(T X) {
+  return __builtin_elementwise_abs(X);
+}
+
+template 
+enable_if_t::value || is_same::value, T>
+length_vec_impl(vector X) {
+  vector XSquared = X * X;
+  T XSquaredSum = XSquared[0];
+  [unroll] for (int i = 1; i < N; ++i) XSquaredSum += XSquared[i];

bogner wrote:

clang-format doesn't seem to handle `[unroll]`, but this should probably be one 
of:
```c++
  [unroll]
  for (int i = 1; i < N; ++i)
XSquaredSum += XSquared[i];
```
or
```c++
  [unroll] for (int i = 1; i < N; ++i)
XSquaredSum += XSquared[i];
```

The latter is closer to what clang-format does with `[[unroll]]` instead of 
`[unroll]` to trick it into seeing that as an attribute.

(aside: I'm not sure if we have a bug for clang-format for this yet, we should 
check)

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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

2025-01-03 Thread Justin Bogner via cfe-commits

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


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


[clang] [Clang] disallow attributes after namespace identifier (PR #121614)

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

https://github.com/a-tarasyuk created 
https://github.com/llvm/llvm-project/pull/121614

Fixes #121407

>From b8f6ffc0a98a0d3ac55fba4e6ee680f1edea4571 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 4 Jan 2025 02:24:26 +0200
Subject: [PATCH] [Clang] disallow attributes after namespace identifier

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/Basic/DiagnosticParseKinds.td |  2 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |  9 ++---
 clang/test/Parser/namespace-attributes.cpp| 10 +-
 4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e0aef1af2135cd..43a95fd022c070 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -553,6 +553,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now disallows the use of attributes after the namespace name. 
(#GH121407)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 86fcae209c40db..9d76376cd6b015 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -283,6 +283,8 @@ def err_unexpected_qualified_namespace_alias : Error<
   "namespace alias must be a single identifier">;
 def err_unexpected_nested_namespace_attribute : Error<
   "attributes cannot be specified on a nested namespace definition">;
+def err_attribute_after_namespace : Error<
+  "standard attributes cannot appear after the namespace name">;
 def err_inline_namespace_alias : Error<"namespace alias cannot be inline">;
 def err_namespace_nonnamespace_scope : Error<
   "namespaces can only be defined in global or namespace scope">;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index f30603feb65c5d..ec87163ffb7cee 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -81,7 +81,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 
   ParsedAttributes attrs(AttrFactory);
 
-  auto ReadAttributes = [&] {
+  auto ReadAttributes = [&](bool TrailingAttrs) {
 bool MoreToParse;
 do {
   MoreToParse = false;
@@ -90,6 +90,9 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 MoreToParse = true;
   }
   if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {
+if (TrailingAttrs)
+  Diag(Tok.getLocation(), diag::err_attribute_after_namespace);
+
 Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
 ? diag::warn_cxx14_compat_ns_enum_attribute
 : diag::ext_ns_enum_attribute)
@@ -100,7 +103,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 } while (MoreToParse);
   };
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ false);
 
   if (Tok.is(tok::identifier)) {
 Ident = Tok.getIdentifierInfo();
@@ -126,7 +129,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 }
   }
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ true);
 
   SourceLocation attrLoc = attrs.Range.getBegin();
 
diff --git a/clang/test/Parser/namespace-attributes.cpp 
b/clang/test/Parser/namespace-attributes.cpp
index 9f925b742dfebd..8a873c55c5d633 100644
--- a/clang/test/Parser/namespace-attributes.cpp
+++ b/clang/test/Parser/namespace-attributes.cpp
@@ -16,11 +16,11 @@ namespace [[]] __attribute__(()) A
 {
 }
 
-namespace A __attribute__(()) [[]]
+namespace A __attribute__(()) [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A [[]] __attribute__(())
+namespace A [[]] __attribute__(()) // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
@@ -28,14 +28,14 @@ namespace [[]] A __attribute__(())
 {
 }
 
-namespace __attribute__(()) A [[]]
+namespace __attribute__(()) A [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A::B __attribute__(()) // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace A::B __attribute__(()) // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }
 
-namespace __attribute__(()) A::B // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace __attribute__(()) A::B // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }

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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

2025-01-03 Thread Justin Bogner via cfe-commits


@@ -33,6 +41,23 @@ constexpr enable_if_t bit_cast(T 
F) {
   return __builtin_bit_cast(U, F);
 }
 
+template 
+constexpr enable_if_t::value || is_same::value, T>
+length_impl(T X) {
+  return __builtin_elementwise_abs(X);
+}
+
+template 
+enable_if_t::value || is_same::value, T>
+length_vec_impl(vector X) {
+  vector XSquared = X * X;
+  T XSquaredSum = XSquared[0];
+  [unroll]
+  for (int i = 1; i < N; ++i)

bogner wrote:

This is because HLSL is only C++11 and not C++14, right? We could always 
implement this with template recursion if we really want it to be constexpr, 
but in all likelihood waiting until we bring HLSL up to C++14 eventually before 
we make this constexpr is fine.

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


[clang] [Clang] disallow attributes after namespace identifier (PR #121614)

2025-01-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #121407

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+2) 
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+6-3) 
- (modified) clang/test/Parser/namespace-attributes.cpp (+5-5) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e0aef1af2135cd..43a95fd022c070 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -553,6 +553,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now disallows the use of attributes after the namespace name. 
(#GH121407)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 86fcae209c40db..9d76376cd6b015 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -283,6 +283,8 @@ def err_unexpected_qualified_namespace_alias : Error<
   "namespace alias must be a single identifier">;
 def err_unexpected_nested_namespace_attribute : Error<
   "attributes cannot be specified on a nested namespace definition">;
+def err_attribute_after_namespace : Error<
+  "standard attributes cannot appear after the namespace name">;
 def err_inline_namespace_alias : Error<"namespace alias cannot be inline">;
 def err_namespace_nonnamespace_scope : Error<
   "namespaces can only be defined in global or namespace scope">;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index f30603feb65c5d..ec87163ffb7cee 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -81,7 +81,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 
   ParsedAttributes attrs(AttrFactory);
 
-  auto ReadAttributes = [&] {
+  auto ReadAttributes = [&](bool TrailingAttrs) {
 bool MoreToParse;
 do {
   MoreToParse = false;
@@ -90,6 +90,9 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 MoreToParse = true;
   }
   if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {
+if (TrailingAttrs)
+  Diag(Tok.getLocation(), diag::err_attribute_after_namespace);
+
 Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
 ? diag::warn_cxx14_compat_ns_enum_attribute
 : diag::ext_ns_enum_attribute)
@@ -100,7 +103,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 } while (MoreToParse);
   };
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ false);
 
   if (Tok.is(tok::identifier)) {
 Ident = Tok.getIdentifierInfo();
@@ -126,7 +129,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 }
   }
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ true);
 
   SourceLocation attrLoc = attrs.Range.getBegin();
 
diff --git a/clang/test/Parser/namespace-attributes.cpp 
b/clang/test/Parser/namespace-attributes.cpp
index 9f925b742dfebd..8a873c55c5d633 100644
--- a/clang/test/Parser/namespace-attributes.cpp
+++ b/clang/test/Parser/namespace-attributes.cpp
@@ -16,11 +16,11 @@ namespace [[]] __attribute__(()) A
 {
 }
 
-namespace A __attribute__(()) [[]]
+namespace A __attribute__(()) [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A [[]] __attribute__(())
+namespace A [[]] __attribute__(()) // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
@@ -28,14 +28,14 @@ namespace [[]] A __attribute__(())
 {
 }
 
-namespace __attribute__(()) A [[]]
+namespace __attribute__(()) A [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A::B __attribute__(()) // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace A::B __attribute__(()) // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }
 
-namespace __attribute__(()) A::B // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace __attribute__(()) A::B // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }

``




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


[clang] [llvm] [SPIRV] Add Target Builtins using Distance ext as an example (PR #121598)

2025-01-03 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,59 @@
+//===- SemaSPIRV.cpp - Semantic Analysis for SPIRV constructs
+//---===//

bogner wrote:

same here

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


[clang] [llvm] [SPIRV] Add Target Builtins using Distance ext as an example (PR #121598)

2025-01-03 Thread Justin Bogner via cfe-commits

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

The boilerplate all looks correct to me.

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


[clang] [llvm] [SPIRV] Add Target Builtins using Distance ext as an example (PR #121598)

2025-01-03 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,29 @@
+//===- SemaSPIRV.h - Semantic Analysis for SPIRV constructs
+//-===//

bogner wrote:

clang-format went wrong here

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


[clang] [llvm] [SPIRV] Add Target Builtins using Distance ext as an example (PR #121598)

2025-01-03 Thread Justin Bogner via cfe-commits

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


[clang] [llvm] [HLSL][SPIR-V] implement SV_GroupID semantic lowering (PR #121521)

2025-01-03 Thread Justin Bogner via cfe-commits

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


[clang] [llvm] [HLSL][SPIR-V] implement SV_GroupID semantic lowering (PR #121521)

2025-01-03 Thread Justin Bogner via cfe-commits

https://github.com/bogner commented:

This basically LGTM but th SV_GroupID.ll test could use a fair amount of cleanup

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


[clang] [llvm] [HLSL][SPIR-V] implement SV_GroupID semantic lowering (PR #121521)

2025-01-03 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,82 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-vulkan-unknown %s -o - | 
FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-vulkan-unknown %s -o - 
-filetype=obj | spirv-val %}
+
+; This file generated from the following command:
+; clang -cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm 
-disable-llvm-passes -finclude-default-header - -o - 

[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2025-01-03 Thread Tony Tye via cfe-commits


@@ -537,7 +537,11 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(const 
LangOptions &LangOpts,
 break;
   }
 
-  if (Ordering != llvm::AtomicOrdering::SequentiallyConsistent) {
+  // OpenCL assumes by default that atomic scopes are per-address space for
+  // non-sequentially consistent operations.
+  if (Scope >= SyncScope::OpenCLWorkGroup &&

t-tye wrote:

The OpenCL language defines atomics to have this "strange" behavior. So this 
function appears to be part of Clang which is responsible for generating the 
correct LLVM IR for a given target. The AMD GPU supports multiple sync-scope 
values so that the different language semantics can be represented efficiently. 
The on-as allows unnecessary waitcnts to be eliminated which has been an issue 
for performance of some of our library code.

Does this change preserve the optimizations that are possible for OpenCL source 
code?

@Pierre-vh should review these changes as I believe he is the compute code 
maintainer for the AMD GPU memory model.

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


[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

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


@@ -537,7 +537,11 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(const 
LangOptions &LangOpts,
 break;
   }
 
-  if (Ordering != llvm::AtomicOrdering::SequentiallyConsistent) {
+  // OpenCL assumes by default that atomic scopes are per-address space for
+  // non-sequentially consistent operations.
+  if (Scope >= SyncScope::OpenCLWorkGroup &&

jhuber6 wrote:

Currently each implementation of this "atomic scope" thing uses a different set 
of enums. The code is simply checking if it's inside the range of enums that 
the OpenCL implementation uses so that it will have the modified behavior if 
the user wants the OpenCL flavor. This makes sense to me because currently all 
targets are emitting these weaker atomics which are not correct in all cases 
the user would expect atomics to work outside of what the OpenCL standard 
specifies. So if users want the OpenCL rules they should use the OpenCL flavor 
builtins. I.e. `__opencl_atomic` vs. `__atomic` or `__scoped_atomic` or 
`__hip_atomic`.

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


[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2025-01-03 Thread Tony Tye via cfe-commits


@@ -537,7 +537,11 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(const 
LangOptions &LangOpts,
 break;
   }
 
-  if (Ordering != llvm::AtomicOrdering::SequentiallyConsistent) {
+  // OpenCL assumes by default that atomic scopes are per-address space for
+  // non-sequentially consistent operations.
+  if (Scope >= SyncScope::OpenCLWorkGroup &&

t-tye wrote:

I am not sure what you mean by "each implementation of this "atomic scope" 
thing". It looks like there is a single function involved here called 
AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID . It takes an argument called 
scope. Its job is to correctly generate the sync-scope that should be used for 
the AMD GPU target for the given value of the scope argument. It is up to the 
callers of this function to pass the correct value for "scope". Are all the 
callers doing that correctly?

This is not about an OpenCL implementation, it is about the compiler 
implementing the correct semantics for the source code that clang is compiling. 
Clang is responsible for honoring the semantics of the source language and any 
directives it may have. Non-OpenCL source languages may want certain code to 
use the OpenCL semantics and so "invent" directives to do that, and hence may 
cause this function to be called with one of the OpenCL enumerator values.

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


[clang] [llvm] [Driver][SYCL] Add initial SYCL offload compilation support (PR #117268)

2025-01-03 Thread Michael Toguchi via cfe-commits

https://github.com/mdtoguchi updated 
https://github.com/llvm/llvm-project/pull/117268

>From 3fdc74687dbf6da831a1c27995d9d7fef3a2a51f Mon Sep 17 00:00:00 2001
From: Michael Toguchi 
Date: Fri, 15 Nov 2024 05:14:21 -0700
Subject: [PATCH 01/10] Reland - [Driver][SYCL] Add initial SYCL offload
 compilation support (#107493)

Introduces the SYCL based toolchain and initial toolchain construction
when using the '-fsycl' option. This option will enable SYCL based
offloading, creating a SPIR-V based IR file packaged into the compiled
host object.

This includes early support for creating the host/device object using
the new offloading model. The device object is created using the
spir64-unknown-unknown target triple.

New/Updated Options:
 -fsycl  Enables SYCL offloading for host and device
 -fsycl-device-only
 Enables device only compilation for SYCL
 -fsycl-host-only
 Enables host only compilation for SYCL

RFC Reference:
https://discourse.llvm.org/t/rfc-sycl-driver-enhancements/74092

Was reverted due to buildbot issues.  Contains additional fixes to pull
in the SYCL header dependencies to other toolchains.
---
 clang/include/clang/Driver/Action.h |   1 +
 clang/include/clang/Driver/Options.td   |  20 ++-
 clang/include/clang/Driver/ToolChain.h  |   4 +
 clang/lib/Driver/Action.cpp |   8 +-
 clang/lib/Driver/CMakeLists.txt |   1 +
 clang/lib/Driver/Compilation.cpp|   9 +-
 clang/lib/Driver/Driver.cpp | 104 +-
 clang/lib/Driver/ToolChain.cpp  |   3 +
 clang/lib/Driver/ToolChains/Clang.cpp   |  58 ++--
 clang/lib/Driver/ToolChains/Darwin.cpp  |   8 +-
 clang/lib/Driver/ToolChains/Darwin.h|   4 +
 clang/lib/Driver/ToolChains/Gnu.cpp |   8 +-
 clang/lib/Driver/ToolChains/Gnu.h   |   5 +
 clang/lib/Driver/ToolChains/Linux.cpp   |   5 +
 clang/lib/Driver/ToolChains/Linux.h |   2 +
 clang/lib/Driver/ToolChains/MSVC.cpp|   7 +-
 clang/lib/Driver/ToolChains/MSVC.h  |   5 +
 clang/lib/Driver/ToolChains/MinGW.cpp   |   7 +-
 clang/lib/Driver/ToolChains/MinGW.h |   4 +
 clang/lib/Driver/ToolChains/SYCL.cpp| 179 
 clang/lib/Driver/ToolChains/SYCL.h  |  82 +++
 clang/test/Driver/sycl-offload-jit.cpp  |  80 +++
 llvm/include/llvm/TargetParser/Triple.h |   3 +
 23 files changed, 579 insertions(+), 28 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/SYCL.cpp
 create mode 100644 clang/lib/Driver/ToolChains/SYCL.h
 create mode 100644 clang/test/Driver/sycl-offload-jit.cpp

diff --git a/clang/include/clang/Driver/Action.h 
b/clang/include/clang/Driver/Action.h
index 04fa8b01b418f8..feeabae89d6b1c 100644
--- a/clang/include/clang/Driver/Action.h
+++ b/clang/include/clang/Driver/Action.h
@@ -94,6 +94,7 @@ class Action {
 OFK_Cuda = 0x02,
 OFK_OpenMP = 0x04,
 OFK_HIP = 0x08,
+OFK_SYCL = 0x10,
   };
 
   static const char *getClassName(ActionClass AC);
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5167c3c39e315a..1da3c9a1118ca8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -182,7 +182,8 @@ def opencl_Group : OptionGroup<"">, 
Group,
DocName<"OpenCL options">;
 
 def sycl_Group : OptionGroup<"">, Group,
- DocName<"SYCL options">;
+ DocName<"SYCL options">,
+ Visibility<[ClangOption, CLOption]>;
 
 def cuda_Group : OptionGroup<"">, Group,
DocName<"CUDA options">,
@@ -6782,16 +6783,21 @@ defm : FlangIgnoredDiagOpt<"frontend-loop-interchange">;
 defm : FlangIgnoredDiagOpt<"target-lifetime">;
 
 // C++ SYCL options
+let Group = sycl_Group in {
 def fsycl : Flag<["-"], "fsycl">,
-  Visibility<[ClangOption, CLOption]>,
-  Group, HelpText<"Enables SYCL kernels compilation for device">;
+  HelpText<"Enable SYCL C++ extensions">;
 def fno_sycl : Flag<["-"], "fno-sycl">,
-  Visibility<[ClangOption, CLOption]>,
-  Group, HelpText<"Disables SYCL kernels compilation for device">;
+  HelpText<"Disable SYCL C++ extensions">;
+def fsycl_device_only : Flag<["-"], "fsycl-device-only">,
+  Alias, HelpText<"Compile SYCL code for device only">;
+def fsycl_host_only : Flag<["-"], "fsycl-host-only">,
+  Alias, HelpText<"Compile SYCL code for host only. Has no "
+  "effect on non-SYCL compilations">;
 def sycl_link : Flag<["--"], "sycl-link">, Flags<[HelpHidden]>,
-  Visibility<[ClangOption, CLOption]>,
-  Group, HelpText<"Perform link through clang-sycl-linker via the 
target "
+  HelpText<"Perform link through clang-sycl-linker via the target "
   "offloading toolchain.">;
+} // let Group = sycl_Group
+
 // OS-specific options
 let Flags = [TargetSpecific] in {
 defm android_pad_segment : BooleanFFlag<"android-pad-segment">, Group;
diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 5347e29be91439..4efef49346fa4d 100644
--- a/clang/in

[clang] [clang] Fix `gnu::init_priority` attribute handling for reserved values (PR #121577)

2025-01-03 Thread via cfe-commits

https://github.com/el-ev updated 
https://github.com/llvm/llvm-project/pull/121577

>From 5551c179d4b1ed0f41885fc96fa4844c9b0435b5 Mon Sep 17 00:00:00 2001
From: Iris Shi <0...@owo.li>
Date: Fri, 3 Jan 2025 23:00:14 +0800
Subject: [PATCH 1/4] fix gnu::init_priority behavior

---
 clang/include/clang/Basic/DiagnosticGroups.td|  1 +
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  3 +++
 clang/lib/Sema/SemaDeclAttr.cpp  | 15 ++-
 clang/test/SemaCXX/init-priority-attr.cpp| 13 ++---
 4 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 3ac490d30371b1..046bd0c5c8f2b9 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -510,6 +510,7 @@ def PrivateModule : DiagGroup<"private-module">;
 def CXX11InlineNamespace : DiagGroup<"c++11-inline-namespace">;
 def InlineNamespaceReopenedNoninline
 : DiagGroup<"inline-namespace-reopened-noninline">;
+def InitPriorityReserved : DiagGroup<"init-priority-reserved">;
 def InvalidNoreturn : DiagGroup<"invalid-noreturn">;
 def InvalidSourceEncoding : DiagGroup<"invalid-source-encoding">;
 def KNRPromotedParameter : DiagGroup<"knr-promoted-parameter">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 330ae045616aba..acc8868829df64 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3324,6 +3324,9 @@ def err_attribute_argument_out_of_range : Error<
 def err_init_priority_object_attr : Error<
   "can only use 'init_priority' attribute on file-scope definitions "
   "of objects of class type">;
+def warn_init_priority_reserved : Warning<
+  "requested 'init_priority' %0 is reserved for internal use">,
+  InGroup;
 def err_attribute_argument_out_of_bounds : Error<
   "%0 attribute parameter %1 is out of bounds">;
 def err_attribute_only_once_per_parameter : Error<
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..de3b867eaa7c52 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3591,15 +3591,20 @@ static void handleInitPriorityAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 return;
   }
 
+  if (prioritynum < 0 || prioritynum > 65535) {
+S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_range)
+<< E->getSourceRange() << AL << 0 << 65535;
+AL.setInvalid();
+return;
+  }
+
   // Only perform the priority check if the attribute is outside of a system
   // header. Values <= 100 are reserved for the implementation, and libc++
   // benefits from being able to specify values in that range.
-  if ((prioritynum < 101 || prioritynum > 65535) &&
+  if (prioritynum < 101 &&
   !S.getSourceManager().isInSystemHeader(AL.getLoc())) {
-S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_range)
-<< E->getSourceRange() << AL << 101 << 65535;
-AL.setInvalid();
-return;
+S.Diag(AL.getLoc(), diag::warn_init_priority_reserved)
+<< E->getSourceRange() << prioritynum;
   }
   D->addAttr(::new (S.Context) InitPriorityAttr(S.Context, AL, prioritynum));
 }
diff --git a/clang/test/SemaCXX/init-priority-attr.cpp 
b/clang/test/SemaCXX/init-priority-attr.cpp
index 8c0a17682bb02a..0d41f4ddc62179 100644
--- a/clang/test/SemaCXX/init-priority-attr.cpp
+++ b/clang/test/SemaCXX/init-priority-attr.cpp
@@ -33,15 +33,15 @@ Two goo __attribute__((init_priority(2,3))) ( 5, 6 ); // 
expected-error {{'init_
 
 Two coo[2]  __attribute__((init_priority(100)));
 #if !defined(SYSTEM)
-  // expected-error@-2 {{'init_priority' attribute requires integer constant 
between 101 and 65535 inclusive}}
+  // expected-warning@-2 {{requested 'init_priority' 100 is reserved for 
internal use}}
   // unknown-warning@-3 {{unknown attribute 'init_priority' ignored}}
 #endif
 
-Two boo[2]  __attribute__((init_priority(65536)));
-#if !defined(SYSTEM)
- // expected-error@-2 {{'init_priority' attribute requires integer constant 
between 101 and 65535 inclusive}}
- // unknown-warning@-3 {{unknown attribute 'init_priority' ignored}}
-#endif
+Two zoo[2]  __attribute__((init_priority(-1))); // expected-error 
{{'init_priority' attribute requires integer constant between 0 and 65535 
inclusive}}
+// unknown-warning@-1 {{unknown attribute 'init_priority' ignored}}
+
+Two boo[2]  __attribute__((init_priority(65536))); // expected-error 
{{'init_priority' attribute requires integer constant between 0 and 65535 
inclusive}}
+// unknown-warning@-1 {{unknown attribute 'init_priority' ignored}}
 
 Two koo[4]  __attribute__((init_priority(1.13))); // expected-error 
{{'init_priority' attribute requires an integer constant}}
 // unknown-warning@-1 {{unknown attribute 'init_priority' ignored}}
@@ -49,7 +49,6 @@ Two koo[4]  __attribute__((init

[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

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


@@ -537,7 +537,11 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(const 
LangOptions &LangOpts,
 break;
   }
 
-  if (Ordering != llvm::AtomicOrdering::SequentiallyConsistent) {
+  // OpenCL assumes by default that atomic scopes are per-address space for
+  // non-sequentially consistent operations.
+  if (Scope >= SyncScope::OpenCLWorkGroup &&

jhuber6 wrote:

The change here causes the `one-as` to only be emitted if the atomic was used 
via the `opencl` language builtins.

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


[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

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


@@ -537,7 +537,11 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(const 
LangOptions &LangOpts,
 break;
   }
 
-  if (Ordering != llvm::AtomicOrdering::SequentiallyConsistent) {
+  // OpenCL assumes by default that atomic scopes are per-address space for
+  // non-sequentially consistent operations.
+  if (Scope >= SyncScope::OpenCLWorkGroup &&

jhuber6 wrote:

You can use the OpenCL builtins outisde of OpenCL 
https://godbolt.org/z/Ex4aPMx3v. This function is called by all the various 
reimplementations of this, but with different enum values for the scope. So, if 
we want the `__opencl_` versions to maintain this behavior, we can do that.

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


[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2025-01-03 Thread Tony Tye via cfe-commits

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


[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2025-01-03 Thread Tony Tye via cfe-commits


@@ -537,7 +537,11 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(const 
LangOptions &LangOpts,
 break;
   }
 
-  if (Ordering != llvm::AtomicOrdering::SequentiallyConsistent) {
+  // OpenCL assumes by default that atomic scopes are per-address space for
+  // non-sequentially consistent operations.
+  if (Scope >= SyncScope::OpenCLWorkGroup &&

t-tye wrote:

What does seem questionable is that this function is checking the memory 
ordering. It feels like that should be done by the caller of this function. It 
is the caller that should be selecting the right value for the scope argument. 
For OpenCL the *one-as" sync-scopes should only be used for non-sequentially 
consistent memory orders. That is is rule of the OpenCL language.

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


[clang] [llvm] [Clang][C++23] Core language changes from P1467R9 extended floating-point types and standard names. (PR #78503)

2025-01-03 Thread M. Zeeshan Siddiqui via cfe-commits


@@ -5565,6 +5565,15 @@ float APFloat::convertToFloat() const {
   return Temp.getIEEE().convertToFloat();
 }
 
+/// Returns true if the semantics can represent all of the values that the 
other
+/// semantics can represent.
+///
+/// \param Sem - type float semantics

codemzs wrote:

Update comment to include the second parameter.

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


[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2025-01-03 Thread Tony Tye via cfe-commits


@@ -537,7 +537,11 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(const 
LangOptions &LangOpts,
 break;
   }
 
-  if (Ordering != llvm::AtomicOrdering::SequentiallyConsistent) {
+  // OpenCL assumes by default that atomic scopes are per-address space for
+  // non-sequentially consistent operations.
+  if (Scope >= SyncScope::OpenCLWorkGroup &&

t-tye wrote:

I guess I am still feeling I am missing something. This PR is making a change 
to this function. Nothing else. So it seems the question is if the change is 
correct. This function should only act on the arguments it is given and 
faithfully do the right thing. It seems that is what it is doing, except for 
the check of the memory ordering. That check should be in the callers of the 
function.

Sounds like the callers of this function are the builtins that you describe. 
The builtins that are intended to implement OpenCL semantics should be sure to 
pass the O{PENCL* scope values, and should check the memory ordering for being 
sequentially consistent. The non-OpenCL builtins should pass in the appropriate 
non-OPENCL values for scope. Is that what is happening?

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


[clang] [llvm] [Clang][C++23] Core language changes from P1467R9 extended floating-point types and standard names. (PR #78503)

2025-01-03 Thread M. Zeeshan Siddiqui via cfe-commits

codemzs wrote:

Hi @shafik , it looks like you’re the designated reviewer for C++ standards. 
Would you mind taking a look at this PR? It has already been through several 
iterations with @tahonermann, and we’d really appreciate your feedback. Thanks!

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


[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

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


@@ -537,7 +537,11 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(const 
LangOptions &LangOpts,
 break;
   }
 
-  if (Ordering != llvm::AtomicOrdering::SequentiallyConsistent) {
+  // OpenCL assumes by default that atomic scopes are per-address space for
+  // non-sequentially consistent operations.
+  if (Scope >= SyncScope::OpenCLWorkGroup &&

jhuber6 wrote:

Yes, each non-OpenCL function goes through this common interface. The issue is 
that for non-OpenCL users they all get the `one-as` feature added, which is not 
correct in the general case. This patch is an attempt to maintain the OpenCL 
behavior while the other users of this function will not longer have `one-as` 
on them.

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


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

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

https://github.com/ricejasonf updated 
https://github.com/llvm/llvm-project/pull/121417

>From 3c81c5bd989f26331917f1401becc1cfa7f4a454 Mon Sep 17 00:00:00 2001
From: Jason Rice 
Date: Thu, 22 Jul 2021 16:46:33 -0700
Subject: [PATCH 1/4] [Clang][P1061] stuctured binding packs

---
 clang/include/clang/AST/Decl.h|   8 +-
 clang/include/clang/AST/DeclCXX.h |  22 +-
 clang/include/clang/AST/ExprCXX.h |  48 
 clang/include/clang/AST/RecursiveASTVisitor.h |   1 +
 .../clang/Basic/DiagnosticParseKinds.td   |   5 +
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Basic/StmtNodes.td|   1 +
 clang/include/clang/Sema/DeclSpec.h   |   1 +
 clang/include/clang/Sema/Sema.h   |   4 +-
 .../include/clang/Serialization/ASTBitCodes.h |   1 +
 clang/lib/AST/ASTContext.cpp  |  14 +-
 clang/lib/AST/ASTImporter.cpp |   2 +-
 clang/lib/AST/Decl.cpp|  11 +-
 clang/lib/AST/DeclBase.cpp|   6 +-
 clang/lib/AST/DeclCXX.cpp |  60 -
 clang/lib/AST/Expr.cpp|   5 +
 clang/lib/AST/ExprCXX.cpp |  48 
 clang/lib/AST/ExprClassification.cpp  |   7 +
 clang/lib/AST/ExprConstant.cpp|   5 +-
 clang/lib/AST/ItaniumMangle.cpp   |   2 +-
 clang/lib/AST/StmtPrinter.cpp |  11 +
 clang/lib/AST/StmtProfile.cpp |   4 +
 clang/lib/CodeGen/CGDebugInfo.cpp |   4 +-
 clang/lib/CodeGen/CGDecl.cpp  |   5 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |   4 +-
 clang/lib/Parse/ParseDecl.cpp |  28 ++-
 clang/lib/Sema/SemaDecl.cpp   |  10 +
 clang/lib/Sema/SemaDeclCXX.cpp| 209 ++
 clang/lib/Sema/SemaExceptionSpec.cpp  |   7 +-
 clang/lib/Sema/SemaLambda.cpp |   1 +
 clang/lib/Sema/SemaStmt.cpp   |  14 +-
 clang/lib/Sema/SemaTemplate.cpp   |   7 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  40 +++-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  32 ++-
 clang/lib/Sema/SemaTemplateVariadic.cpp   |  73 +-
 clang/lib/Sema/TreeTransform.h|   7 +
 clang/lib/Serialization/ASTReaderStmt.cpp |  11 +
 clang/lib/Serialization/ASTWriter.cpp |   1 +
 clang/lib/Serialization/ASTWriterStmt.cpp |  11 +
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |   1 +
 clang/test/Parser/cxx2c-binding-pack.cpp  |   7 +
 .../cxx2c-binding-pack-nontemplate.cpp|  12 +
 clang/test/SemaCXX/cxx2c-binding-pack.cpp |  82 +++
 clang/test/SemaCXX/typo-correction-crash.cpp  |   3 +-
 clang/tools/libclang/CXCursor.cpp |   1 +
 45 files changed, 728 insertions(+), 111 deletions(-)
 create mode 100644 clang/test/Parser/cxx2c-binding-pack.cpp
 create mode 100644 clang/test/SemaCXX/cxx2c-binding-pack-nontemplate.cpp
 create mode 100644 clang/test/SemaCXX/cxx2c-binding-pack.cpp

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 67ee0bb412692a..bdf6c81732d0bc 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -698,6 +698,10 @@ class ValueDecl : public NamedDecl {
 return const_cast(this)->getPotentiallyDecomposedVarDecl();
   }
 
+  /// Determine whether this value is actually a function parameter pack,
+  /// init-capture pack, or structured binding pack
+  bool isParameterPack() const;
+
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }
@@ -1527,10 +1531,6 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
 NonParmVarDeclBits.IsInitCapture = IC;
   }
 
-  /// Determine whether this variable is actually a function parameter pack or
-  /// init-capture pack.
-  bool isParameterPack() const;
-
   /// Whether this local extern variable declaration's previous declaration
   /// was declared in the same block scope. Only correct in C++.
   bool isPreviousDeclInSameBlockScope() const {
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index c232556edeff70..12002db17fb3ad 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -4131,8 +4131,9 @@ class BindingDecl : public ValueDecl {
   /// binding).
   Expr *Binding = nullptr;
 
-  BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
-  : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {}
+  BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id,
+  QualType T)
+  : ValueDecl(Decl::Binding, DC, IdLoc, Id, T) {}
 
   void anchor() override;
 
@@ -4140,7 +4141,8 @@ class BindingDecl : public ValueDecl {
   friend class ASTDeclReader;
 
   static BindingDecl *Create(ASTContext

[clang-tools-extra] [clang-tidy] Improved readability redundant casting with enums (PR #111424)

2025-01-03 Thread Félix-Antoine Constantin via cfe-commits

felix642 wrote:

Closing this PR since I no longer think this is an option that we need.

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


[clang-tools-extra] [clang-tidy] Improved readability redundant casting with enums (PR #111424)

2025-01-03 Thread Félix-Antoine Constantin via cfe-commits

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


[clang] [llvm] [Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (PR #120507)

2025-01-03 Thread Ian Anderson via cfe-commits

ian-twilightcoder wrote:

> > > as Swift expects all MachO targets to have that defined.
> > 
> > 
> > can you elaborate on that expectation?
> 
> [shims/Visibility.h](https://github.com/swiftlang/swift/blob/main/stdlib/public/SwiftShims/swift/shims/Visibility.h#L137)
>  uses `__MACH__` to figure out how to configure the visibility attributes. 
> It's taking `__MACH__` to mean Mach-O and not dyld. Without that, 
> apple-none-macho falls down to Windows declspec which is an error. libc++'s 
> [__configuration/platform.h](https://github.com/llvm/llvm-project/blob/main/libcxx/include/__configuration/platform.h#L21)
>  takes the same meaning. usr/include/TargetConditionals.h also equates 
> `__MACH__` to Mach-O.

Actually the TargetConditionals.h use seems to be more like "running Mac OS X 
native" as opposed to "running in Mac OS 9 or the Classic environment on Mac OS 
X". gssapi/gssapi.h and krb5/krb5.h is using it for the same purpose. There's 
similar use in unicode/platform.h and dispatch/dispatch.h, though it's a little 
less clear if they're trying to figure out (it almost looks like they just 
don't know about `__has_include` or don't want to use it because it's not 
supported by every compiler?).

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


[clang] [llvm] [Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (PR #120507)

2025-01-03 Thread Ian Anderson via cfe-commits

ian-twilightcoder wrote:

> > as Swift expects all MachO targets to have that defined.
> 
> can you elaborate on that expectation?

[shims/Visibility.h](https://github.com/swiftlang/swift/blob/main/stdlib/public/SwiftShims/swift/shims/Visibility.h#L137)
 uses `__MACH__` to figure out how to configure the visibility attributes. It's 
taking `__MACH__` to mean Mach-O and not dyld. Without that, apple-none-macho 
falls down to Windows declspec which is an error. libc++'s 
[__configuration/platform.h](https://github.com/llvm/llvm-project/blob/main/libcxx/include/__configuration/platform.h#L21)
 takes the same meaning. usr/include/TargetConditionals.h also equates 
`__MACH__` to Mach-O.

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


[clang] [llvm] [HLSL][SPIR-V] implement SV_GroupID semantic lowering (PR #121521)

2025-01-03 Thread Zhengxing li via cfe-commits


@@ -0,0 +1,82 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-vulkan-unknown %s -o - | 
FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-vulkan-unknown %s -o - 
-filetype=obj | spirv-val %}
+
+; This file generated from the following command:
+; clang -cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm 
-disable-llvm-passes -finclude-default-header - -o - 

[clang] [Clang][AMDGPU] Stop defaulting to `one-as` for all atomic scopes (PR #120095)

2025-01-03 Thread Tony Tye via cfe-commits


@@ -537,7 +537,11 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(const 
LangOptions &LangOpts,
 break;
   }
 
-  if (Ordering != llvm::AtomicOrdering::SequentiallyConsistent) {
+  // OpenCL assumes by default that atomic scopes are per-address space for
+  // non-sequentially consistent operations.
+  if (Scope >= SyncScope::OpenCLWorkGroup &&

t-tye wrote:

But with this change that is no longer the case. So is there any push back on 
this fix?

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


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

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

https://github.com/ricejasonf updated 
https://github.com/llvm/llvm-project/pull/121417

>From 3c81c5bd989f26331917f1401becc1cfa7f4a454 Mon Sep 17 00:00:00 2001
From: Jason Rice 
Date: Thu, 22 Jul 2021 16:46:33 -0700
Subject: [PATCH 1/5] [Clang][P1061] stuctured binding packs

---
 clang/include/clang/AST/Decl.h|   8 +-
 clang/include/clang/AST/DeclCXX.h |  22 +-
 clang/include/clang/AST/ExprCXX.h |  48 
 clang/include/clang/AST/RecursiveASTVisitor.h |   1 +
 .../clang/Basic/DiagnosticParseKinds.td   |   5 +
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Basic/StmtNodes.td|   1 +
 clang/include/clang/Sema/DeclSpec.h   |   1 +
 clang/include/clang/Sema/Sema.h   |   4 +-
 .../include/clang/Serialization/ASTBitCodes.h |   1 +
 clang/lib/AST/ASTContext.cpp  |  14 +-
 clang/lib/AST/ASTImporter.cpp |   2 +-
 clang/lib/AST/Decl.cpp|  11 +-
 clang/lib/AST/DeclBase.cpp|   6 +-
 clang/lib/AST/DeclCXX.cpp |  60 -
 clang/lib/AST/Expr.cpp|   5 +
 clang/lib/AST/ExprCXX.cpp |  48 
 clang/lib/AST/ExprClassification.cpp  |   7 +
 clang/lib/AST/ExprConstant.cpp|   5 +-
 clang/lib/AST/ItaniumMangle.cpp   |   2 +-
 clang/lib/AST/StmtPrinter.cpp |  11 +
 clang/lib/AST/StmtProfile.cpp |   4 +
 clang/lib/CodeGen/CGDebugInfo.cpp |   4 +-
 clang/lib/CodeGen/CGDecl.cpp  |   5 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |   4 +-
 clang/lib/Parse/ParseDecl.cpp |  28 ++-
 clang/lib/Sema/SemaDecl.cpp   |  10 +
 clang/lib/Sema/SemaDeclCXX.cpp| 209 ++
 clang/lib/Sema/SemaExceptionSpec.cpp  |   7 +-
 clang/lib/Sema/SemaLambda.cpp |   1 +
 clang/lib/Sema/SemaStmt.cpp   |  14 +-
 clang/lib/Sema/SemaTemplate.cpp   |   7 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  40 +++-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  32 ++-
 clang/lib/Sema/SemaTemplateVariadic.cpp   |  73 +-
 clang/lib/Sema/TreeTransform.h|   7 +
 clang/lib/Serialization/ASTReaderStmt.cpp |  11 +
 clang/lib/Serialization/ASTWriter.cpp |   1 +
 clang/lib/Serialization/ASTWriterStmt.cpp |  11 +
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |   1 +
 clang/test/Parser/cxx2c-binding-pack.cpp  |   7 +
 .../cxx2c-binding-pack-nontemplate.cpp|  12 +
 clang/test/SemaCXX/cxx2c-binding-pack.cpp |  82 +++
 clang/test/SemaCXX/typo-correction-crash.cpp  |   3 +-
 clang/tools/libclang/CXCursor.cpp |   1 +
 45 files changed, 728 insertions(+), 111 deletions(-)
 create mode 100644 clang/test/Parser/cxx2c-binding-pack.cpp
 create mode 100644 clang/test/SemaCXX/cxx2c-binding-pack-nontemplate.cpp
 create mode 100644 clang/test/SemaCXX/cxx2c-binding-pack.cpp

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 67ee0bb412692a..bdf6c81732d0bc 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -698,6 +698,10 @@ class ValueDecl : public NamedDecl {
 return const_cast(this)->getPotentiallyDecomposedVarDecl();
   }
 
+  /// Determine whether this value is actually a function parameter pack,
+  /// init-capture pack, or structured binding pack
+  bool isParameterPack() const;
+
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }
@@ -1527,10 +1531,6 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
 NonParmVarDeclBits.IsInitCapture = IC;
   }
 
-  /// Determine whether this variable is actually a function parameter pack or
-  /// init-capture pack.
-  bool isParameterPack() const;
-
   /// Whether this local extern variable declaration's previous declaration
   /// was declared in the same block scope. Only correct in C++.
   bool isPreviousDeclInSameBlockScope() const {
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index c232556edeff70..12002db17fb3ad 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -4131,8 +4131,9 @@ class BindingDecl : public ValueDecl {
   /// binding).
   Expr *Binding = nullptr;
 
-  BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
-  : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {}
+  BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id,
+  QualType T)
+  : ValueDecl(Decl::Binding, DC, IdLoc, Id, T) {}
 
   void anchor() override;
 
@@ -4140,7 +4141,8 @@ class BindingDecl : public ValueDecl {
   friend class ASTDeclReader;
 
   static BindingDecl *Create(ASTContext

[clang] [llvm] [HLSL][SPIR-V] implement SV_GroupID semantic lowering (PR #121521)

2025-01-03 Thread Zhengxing li via cfe-commits

https://github.com/lizhengxing updated 
https://github.com/llvm/llvm-project/pull/121521

>From 21114c408baaa9309e3370d46a4ee196cc4f714a Mon Sep 17 00:00:00 2001
From: Zhengxing Li 
Date: Thu, 2 Jan 2025 12:30:18 -0800
Subject: [PATCH 1/2] [HLSL][SPIR-V] implement SV_GroupID semantic lowering

The HLSL SV_GroupID semantic attribute is lowered into @llvm.spv.group.id 
intrinsic in LLVM IR for SPIR-V target.

In the SPIR-V backend, this is now translated to a `WorkgroupId` builtin 
variable.

Fixes #118700 which's a follow-up work to #70120
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  2 +-
 clang/lib/CodeGen/CGHLSLRuntime.h |  1 +
 .../CodeGenHLSL/semantics/SV_GroupID.hlsl | 34 
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  1 +
 .../Target/SPIRV/SPIRVInstructionSelector.cpp |  8 ++
 .../SPIRV/hlsl-intrinsics/SV_GroupID.ll   | 82 +++
 6 files changed, 112 insertions(+), 16 deletions(-)
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/SV_GroupID.ll

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index c354e58e15f4bb..5679bd71581795 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -395,7 +395,7 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> 
&B,
 return buildVectorInput(B, GroupThreadIDIntrinsic, Ty);
   }
   if (D.hasAttr()) {
-llvm::Function *GroupIDIntrinsic = 
CGM.getIntrinsic(Intrinsic::dx_group_id);
+llvm::Function *GroupIDIntrinsic = CGM.getIntrinsic(getGroupIdIntrinsic());
 return buildVectorInput(B, GroupIDIntrinsic, Ty);
   }
   assert(false && "Unhandled parameter attribute");
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index edb87f9d5efdf9..3d5724118611cb 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -87,6 +87,7 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(Radians, radians)
   GENERATE_HLSL_INTRINSIC_FUNCTION(ThreadId, thread_id)
   GENERATE_HLSL_INTRINSIC_FUNCTION(GroupThreadId, thread_id_in_group)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(GroupId, group_id)
   GENERATE_HLSL_INTRINSIC_FUNCTION(FDot, fdot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(UDot, udot)
diff --git a/clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl 
b/clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl
index 5e09f0fe06d4e6..3aa054afc90451 100644
--- a/clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl
+++ b/clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl
@@ -1,32 +1,36 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-DXIL -DTARGET=dx
+// RUN: %clang_cc1 -triple spirv-linux-vulkan-library -x hlsl -emit-llvm 
-finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-SPIRV -DTARGET=spv
 
-// Make sure SV_GroupID translated into dx.group.id.
+// Make sure SV_GroupID translated into dx.group.id for directx target and 
spv.group.id for spirv target.
 
-// CHECK:  define void @foo()
-// CHECK:  %[[#ID:]] = call i32 @llvm.dx.group.id(i32 0)
-// CHECK:  call void @{{.*}}foo{{.*}}(i32 %[[#ID]])
+// CHECK:   define void @foo()
+// CHECK:   %[[#ID:]] = call i32 @llvm.[[TARGET]].group.id(i32 0)
+// CHECK-DXIL:   call void @{{.*}}foo{{.*}}(i32 %[[#ID]])
+// CHECK-SPIRV:  call spir_func void @{{.*}}foo{{.*}}(i32 %[[#ID]])
 [shader("compute")]
 [numthreads(8,8,1)]
 void foo(uint Idx : SV_GroupID) {}
 
-// CHECK:  define void @bar()
-// CHECK:  %[[#ID_X:]] = call i32 @llvm.dx.group.id(i32 0)
-// CHECK:  %[[#ID_X_:]] = insertelement <2 x i32> poison, i32 %[[#ID_X]], i64 0
-// CHECK:  %[[#ID_Y:]] = call i32 @llvm.dx.group.id(i32 1)
-// CHECK:  %[[#ID_XY:]] = insertelement <2 x i32> %[[#ID_X_]], i32 %[[#ID_Y]], 
i64 1
-// CHECK:  call void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]])
+// CHECK:   define void @bar()
+// CHECK:   %[[#ID_X:]] = call i32 @llvm.[[TARGET]].group.id(i32 0)
+// CHECK:   %[[#ID_X_:]] = insertelement <2 x i32> poison, i32 %[[#ID_X]], 
i64 0
+// CHECK:   %[[#ID_Y:]] = call i32 @llvm.[[TARGET]].group.id(i32 1)
+// CHECK:   %[[#ID_XY:]] = insertelement <2 x i32> %[[#ID_X_]], i32 
%[[#ID_Y]], i64 1
+// CHECK-DXIL:  call void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]])
+// CHECK-SPIRV:  call spir_func void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]])
 [shader("compute")]
 [numthreads(8,8,1)]
 void bar(uint2 Idx : SV_GroupID) {}
 
 // CHECK:  define void @test()
-// CHECK:  %[[#ID_X:]] = call i32 @llvm.dx.group.id(i32 0)
+// CHECK:  %[[#ID_X:]] = call i32 @llvm.[[TARGET]].group.id(i32 0)
 // CHECK:  %[[#ID_X_:]] = insertelement <3 x i32> poison, i32 %[[#ID_X]], i64 0
-// CHECK:  %[[

[clang] [llvm] [HLSL][SPIR-V] implement SV_GroupID semantic lowering (PR #121521)

2025-01-03 Thread Zhengxing li via cfe-commits


@@ -0,0 +1,82 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-vulkan-unknown %s -o - | 
FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-vulkan-unknown %s -o - 
-filetype=obj | spirv-val %}
+
+; This file generated from the following command:
+; clang -cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm 
-disable-llvm-passes -finclude-default-header - -o - 

[clang-tools-extra] [clang-tidy] Add readability-string-view-substr check (PR #120055)

2025-01-03 Thread Helmut Januschka via cfe-commits

https://github.com/hjanuschka updated 
https://github.com/llvm/llvm-project/pull/120055

>From 8b2dc9adf4fae2065823e5beb3a1cd851686913c Mon Sep 17 00:00:00 2001
From: Helmut Januschka 
Date: Mon, 16 Dec 2024 08:24:14 +0100
Subject: [PATCH 1/8] [clang-tidy] Add readability-string-view-substr check

Add a new check that suggests using string_view::remove_prefix() and
remove_suffix() instead of substr() when the intent is to remove
characters from either end of a string_view.
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../readability/ReadabilityTidyModule.cpp |   3 +
 .../readability/StringViewSubstrCheck.cpp | 132 ++
 .../readability/StringViewSubstrCheck.h   |  39 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   7 +
 .../checks/readability/string-view-substr.rst |  16 +++
 .../readability/stringview_substr.cpp |  55 
 7 files changed, 253 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/string-view-substr.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/stringview_substr.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 8f303c51e1b0da..8b44fc339441ac 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -53,6 +53,7 @@ add_clang_library(clangTidyReadabilityModule STATIC
   StaticAccessedThroughInstanceCheck.cpp
   StaticDefinitionInAnonymousNamespaceCheck.cpp
   StringCompareCheck.cpp
+  StringViewSubstrCheck.cpp
   SuspiciousCallArgumentCheck.cpp
   UniqueptrDeleteReleaseCheck.cpp
   UppercaseLiteralSuffixCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index d61c0ba39658e5..f36ec8f95ede60 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -56,6 +56,7 @@
 #include "StaticAccessedThroughInstanceCheck.h"
 #include "StaticDefinitionInAnonymousNamespaceCheck.h"
 #include "StringCompareCheck.h"
+#include "StringViewSubstrCheck.h"
 #include "SuspiciousCallArgumentCheck.h"
 #include "UniqueptrDeleteReleaseCheck.h"
 #include "UppercaseLiteralSuffixCheck.h"
@@ -146,6 +147,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-static-definition-in-anonymous-namespace");
 CheckFactories.registerCheck(
 "readability-string-compare");
+CheckFactories.registerCheck(
+"readability-stringview-substr");
 CheckFactories.registerCheck(
 "readability-named-parameter");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp
new file mode 100644
index 00..e86a971695a835
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/StringViewSubstrCheck.cpp
@@ -0,0 +1,132 @@
+//===--- StringViewSubstrCheck.cpp - clang-tidy--*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "StringViewSubstrCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void StringViewSubstrCheck::registerMatchers(MatchFinder *Finder) {
+  const auto HasStringViewType = 
hasType(hasUnqualifiedDesugaredType(recordType(
+  hasDeclaration(recordDecl(hasName("::std::basic_string_view"));
+
+  // Match assignment to string_view's substr
+  Finder->addMatcher(
+  cxxOperatorCallExpr(
+  hasOverloadedOperatorName("="),
+  hasArgument(0, expr(HasStringViewType).bind("target")),
+  hasArgument(
+  1, cxxMemberCallExpr(callee(memberExpr(hasDeclaration(
+   cxxMethodDecl(hasName("substr"),
+   on(expr(HasStringViewType).bind("source")))
+ .bind("substr_call")))
+  .bind("assignment"),
+  this);
+}
+
+void StringViewSubstrCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Assignment =
+  Result.Nodes.getNodeAs("assignment");
+  const auto *Target = Result.Nodes.getNodeAs("target");
+  const auto *Source = Result.Nodes.getNodeAs("source");
+  const auto *SubstrCall =
+  Result.Nod

[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2025-01-03 Thread Denis Mikhailov via cfe-commits

denzor200 wrote:

> Wouldn't that be a runtime check, and thus not something clang-tidy can do 
> without significant data flow analysis effort?

I'm not experienced enough in clang-tidy internals, but I believe it will not 
be a serious challenge to check for having `assert(sp.use_count() == 1)` one 
line before `*sp` being moved.

I suppose everybody agree that this snippet
```
assert(sp.use_count() == 1);
auto y = std::move(*sp);
```
..is better than that one:
```
// NOLINTNEXTLINE(clang-tidy-bugprone-move-shared-pointer-contents)
auto y = std::move(*sp);
```



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


[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

2025-01-03 Thread Max Winkler via cfe-commits

https://github.com/MaxEW707 updated 
https://github.com/llvm/llvm-project/pull/99833

>From 0a705b1a8e9673cd5e803ffe392dacfa0f06c40f Mon Sep 17 00:00:00 2001
From: MaxEW707 
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/26] Support MSVC lvalue to temporary reference binding

---
 clang/docs/ReleaseNotes.rst |   4 +
 clang/include/clang/Basic/LangOptions.def   |   1 +
 clang/include/clang/Driver/Options.td   |  12 +++
 clang/include/clang/Sema/Sema.h |   2 +
 clang/lib/Driver/ToolChains/Clang.cpp   |   5 +
 clang/lib/Driver/ToolChains/MSVC.cpp|   1 +
 clang/lib/Sema/SemaInit.cpp |  22 +++--
 clang/lib/Sema/SemaOverload.cpp |  16 ++-
 clang/test/Driver/cl-permissive.c   |   7 ++
 clang/test/Driver/cl-zc.cpp |   2 +
 clang/test/SemaCXX/ms-reference-binding.cpp | 102 
 11 files changed, 165 insertions(+), 9 deletions(-)
 create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02284225fb4fa1..3e8f7a8f7d889e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -419,6 +419,10 @@ New Compiler Flags
   existing ``-fno-c++-static-destructors`` flag) skips all static
   destructors registration.
 
+- ``-fms-reference-binding`` and its clang-cl counterpart 
``/Zc:referenceBinding``.
+  Implements the MSVC extension where expressions that bind a user-defined 
type temporary
+  to a non-const lvalue reference are allowed.
+
 Deprecated Compiler Flags
 -
 
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 39e4851dd3814c..c0451eaae344de 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -311,6 +311,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations 
/ deallocations with
 LANGOPT(OpenACC   , 1, 0, "OpenACC Enabled")
 
 LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with 
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const 
lvalue reference to a temporary")
 LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
 LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
 LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are 
unavailable")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4bc0b97ea68f2f..4f963a18297ee7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3096,6 +3096,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">, 
Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Accept some non-standard constructs supported by the Microsoft 
compiler">,
   MarshallingInfoFlag>, 
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">, 
Group,
+  Visibility<[ClangOption, CC1Option, CLOption]>,
+  HelpText<"Accept expressions that bind a non-const lvalue reference to a 
user-defined type temporary as supported by the Microsoft Compiler">,
+  MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">, 
Group,
+  Visibility<[ClangOption, CLOption]>;
 defm asm_blocks : BoolFOption<"asm-blocks",
   LangOpts<"AsmBlocks">, Default,
   PosFlag,
@@ -8683,6 +8689,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
   HelpText<"Enable C++ builtin type wchar_t (default)">;
 def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
   HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+  HelpText<"Do not accept expressions that bind a non-const lvalue reference 
to a user-defined type temporary">,
+  Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+  HelpText<"Accept expressions that bind a non-const lvalue reference to a 
user-defined type temporary">,
+  Alias;
 def _SLASH_Z7 : CLFlag<"Z7">, Alias,
   HelpText<"Enable CodeView debug information in object files">;
 def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b8684d11460eda..ada5184eb71b05 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10144,6 +10144,8 @@ class Sema final : public SemaBase {
   CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
 
+  bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
   /// AddOverloadCandidate - Adds the given function to the set of
   /// candidate functions, using the given function call arguments.  If
   /// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 99a092d83d

[clang] [clang][analyzer] Stable order for SymbolRef-keyed containers (PR #121551)

2025-01-03 Thread Arseniy Zaostrovnykh via cfe-commits

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


[clang] [clang][analyzer] Stabilize path-constraint order by using alloc IDs (PR #121347)

2025-01-03 Thread Arseniy Zaostrovnykh via cfe-commits


@@ -427,8 +434,8 @@ class BinarySymExprImpl : public BinarySymExpr {
 
 public:
   BinarySymExprImpl(LHSTYPE lhs, BinaryOperator::Opcode op, RHSTYPE rhs,
-QualType t)
-  : BinarySymExpr(ClassKind, op, t), LHS(lhs), RHS(rhs) {
+QualType t, AllocIDType AllocID)
+  : BinarySymExpr(ClassKind, op, t, AllocID), LHS(lhs), RHS(rhs) {

necto wrote:

Done: 
https://github.com/llvm/llvm-project/pull/121551/commits/115814c2776b6acc8f4a08ec696a3cb27a7c0ebd#diff-b857e7d32a22c18619e58b7971b4acc7823f5603c89f011bb3c7180c755641cdR51-R52

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


[clang] [clang][analyzer] Stabilize path-constraint order by using alloc IDs (PR #121347)

2025-01-03 Thread Arseniy Zaostrovnykh via cfe-commits


@@ -401,7 +401,22 @@ class RangeSet {
   friend class Factory;
 };
 
-using ConstraintMap = llvm::ImmutableMap;
+struct ConstraintKVInfo : llvm::ImutKeyValueInfo {
+  static inline bool isEqual(key_type_ref L, key_type_ref R) {
+return L->getAllocID() == R->getAllocID();
+  }
+
+  static inline bool isLess(key_type_ref L, key_type_ref R) {
+return L->getAllocID() < R->getAllocID();
+  }
+
+  static inline void Profile(llvm::FoldingSetNodeID &ID, value_type_ref V) {
+ID.AddInteger(V.first->getAllocID());
+ID.Add(V.second);
+  }
+};
+
+using ConstraintMap = llvm::ImmutableMap;

necto wrote:

Done in https://github.com/llvm/llvm-project/pull/121551

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


  1   2   3   >