[clang] [llvm] [AArch64] Add initial support for -mcpu=olympus. (PR #132368)

2025-03-24 Thread David Green via cfe-commits

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

Thanks, LGTM

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


[clang] [clang] ``noconvergent`` does not affect calls to convergent functions (PR #132701)

2025-03-24 Thread Matt Arsenault via cfe-commits


@@ -1677,7 +1676,8 @@ being treated as convergent when it's safe.
 
   __device__ int example(void) {
 float x;
-[[clang::noconvergent]] x = bar(x);
+[[clang::noconvergent]] x = bar(x); // no effect on convergence
+[[clang::noconvergent]] { asm volatile ("nop"); } // the asm call is 
non-convergent
   }

arsenm wrote:

Maybe should have an example of an undefined usage 

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


[clang] [compiler-rt] [llvm] [FMV][AArch64] Add feature CSSC and detect on linux platform. (PR #132727)

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

jroelofs wrote:

> Hi @jroelofs @DanielKristofKiss. I am not sure how to detect on other 
> platforms. Suggestions for apple and windows welcome.

The place to look for feature tests on Apple platforms is here: 
https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/arm/cpu_capabilities_public.h.

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


[clang] [compiler-rt] [llvm] [FMV][AArch64] Add feature CSSC and detect on linux platform. (PR #132727)

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


@@ -33,7 +33,7 @@ enum CPUFeatures {
   FEAT_FP,
   FEAT_SIMD,
   FEAT_CRC,
-  RESERVED_FEAT_SHA1, // previously used and now ABI legacy
+  FEAT_CSSC,

jroelofs wrote:

Is re-using this index okay re: the ABI legacy thing?

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


[clang] [Driver] Search for compiler-rt libraries in sysroot/lib if not found in the resource directory (PR #132443)

2025-03-24 Thread Kostiantyn Lazukin via cfe-commits

https://github.com/Sunday111 updated 
https://github.com/llvm/llvm-project/pull/132443

>From 9a88ff05af21a5d5357780293f2d011ffe457041 Mon Sep 17 00:00:00 2001
From: Kostiantyn Lazukin
 
Date: Thu, 20 Mar 2025 16:54:06 +
Subject: [PATCH] [Driver] Search for compiler-rt libraries in sysroot/lib if
 not found in the resource directory

This patch improves support for embedded Linux toolchains with multiple
sysroots, each containing different built-in libraries. If compiler-rt
libraries are not found in the resource directory, the Clang driver will
fallback to searching in the sysroot/lib directory.

This change preserves the standard behavior for regular Linux toolchains
while allowing greater flexibility in toolchains with multiple sysroots.
---
 clang/lib/Driver/ToolChains/Linux.cpp |  2 ++
 .../Inputs/musl_sysroot_with_builtins/lib/Scrt1.o |  0
 .../lib/clang_rt.crtbegin.o   |  0
 .../musl_sysroot_with_builtins/lib/clang_rt.crtend.o  |  0
 .../Inputs/musl_sysroot_with_builtins/lib/crti.o  |  0
 .../Inputs/musl_sysroot_with_builtins/lib/crtn.o  |  0
 .../lib/libclang_rt.builtins.a|  0
 clang/test/Driver/Inputs/resource_dir_empty/keep  |  0
 clang/test/Driver/linux-musl-library-search.cpp   | 11 +++
 9 files changed, 13 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/Scrt1.o
 create mode 100644 
clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtend.o
 create mode 100644 
clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/crti.o
 create mode 100644 
clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/crtn.o
 create mode 100644 
clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/libclang_rt.builtins.a
 create mode 100644 clang/test/Driver/Inputs/resource_dir_empty/keep
 create mode 100644 clang/test/Driver/linux-musl-library-search.cpp

diff --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 1e9bd3de75f04..1bd8daafa8091 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -354,6 +354,8 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, 
const ArgList &Args)
 
   addPathIfExists(D, concat(SysRoot, "/lib"), Paths);
   addPathIfExists(D, concat(SysRoot, "/usr/lib"), Paths);
+
+  addPathIfExists(D, concat(SysRoot, "/lib"), getLibraryPaths());
 }
 
 ToolChain::RuntimeLibType Linux::GetDefaultRuntimeLibType() const {
diff --git a/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/Scrt1.o 
b/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/Scrt1.o
new file mode 100644
index 0..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtbegin.o 
b/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtbegin.o
new file mode 100644
index 0..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtend.o 
b/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtend.o
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/crti.o 
b/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/crti.o
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/crtn.o 
b/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/crtn.o
new file mode 100644
index 0..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/libclang_rt.builtins.a
 
b/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/libclang_rt.builtins.a
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/resource_dir_empty/keep 
b/clang/test/Driver/Inputs/resource_dir_empty/keep
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/test/Driver/linux-musl-library-search.cpp 
b/clang/test/Driver/linux-musl-library-search.cpp
new file mode 100644
index 0..7bfdc58af1dcd
--- /dev/null
+++ b/clang/test/Driver/linux-musl-library-search.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=aarch64-unknown-linux-musl \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir_empty \
+// RUN: --sysroot=%S/Inputs/musl_sysroot_with_builtins \
+// RUN: -static \
+// RUN: -rtlib=compiler-rt \
+// RUN:   | FileCheck %s
+
+// CHECK-DAG: "--sysroot={{[^"]+}}/Inputs/musl_sysroot_with_builtins"
+// CHECK-DAG: 
"{{[^"]+}}/Inputs/musl_sysroot_with_builtins/lib/libclang_rt.builtins.a"

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


[clang] d447c6e - [clang] NFC: remove stray newlines from clang/test/Misc/diag-template-diffing-cxx11.cpp

2025-03-24 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2025-03-24T13:18:07-03:00
New Revision: d447c6e9b73a43f865e4900a8374b242ce4c4bf6

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

LOG: [clang] NFC: remove stray newlines from 
clang/test/Misc/diag-template-diffing-cxx11.cpp

Added: 


Modified: 
clang/test/Misc/diag-template-diffing-cxx11.cpp

Removed: 




diff  --git a/clang/test/Misc/diag-template-
diff ing-cxx11.cpp b/clang/test/Misc/diag-template-
diff ing-cxx11.cpp
index c32a3fd56fc1b..ae4fa524e4e44 100644
--- a/clang/test/Misc/diag-template-
diff ing-cxx11.cpp
+++ b/clang/test/Misc/diag-template-
diff ing-cxx11.cpp
@@ -80,7 +80,7 @@ void test2() {
 // CHECK-ELIDE-TREE: candidate function not viable: no known conversion from 
argument type to parameter type for 1st argument
 // CHECK-ELIDE-TREE:   I2<
 // CHECK-ELIDE-TREE: [double != int],
-// CHECK-ELIDE-TREE: [...], 
+// CHECK-ELIDE-TREE: [...],
 // CHECK-ELIDE-TREE: [int != (default) void]>
 // CHECK-NOELIDE-TREE: no matching function for call to 'set2'
 // CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from 
argument type to parameter type for 1st argument
@@ -241,13 +241,13 @@ int k8 = f8(U8());
 // CHECK-ELIDE-TREE: no matching function for call to 'f8'
 // CHECK-ELIDE-TREE: candidate function not viable: no known conversion from 
argument type to parameter type for 1st argument
 // CHECK-ELIDE-TREE:   S8<
-// CHECK-ELIDE-TREE: [2 * ...], 
+// CHECK-ELIDE-TREE: [2 * ...],
 // CHECK-ELIDE-TREE: [char != double]>
 // CHECK-NOELIDE-TREE: no matching function for call to 'f8'
 // CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from 
argument type to parameter type for 1st argument
 // CHECK-NOELIDE-TREE:   S8<
-// CHECK-NOELIDE-TREE: int, 
-// CHECK-NOELIDE-TREE: char, 
+// CHECK-NOELIDE-TREE: int,
+// CHECK-NOELIDE-TREE: char,
 // CHECK-NOELIDE-TREE: [char != double]>
 
 template struct S9 {};
@@ -292,23 +292,23 @@ void test10() {
 // CHECK-ELIDE-TREE: no matching function for call to 'set10'
 // CHECK-ELIDE-TREE: candidate function not viable: no known conversion from 
argument type to parameter type for 1st argument
 // CHECK-ELIDE-TREE:   class_types<
-// CHECK-ELIDE-TREE: [...], 
+// CHECK-ELIDE-TREE: [...],
 // CHECK-ELIDE-TREE: [(no argument) != int]>
 // CHECK-ELIDE-TREE: no matching function for call to 'set10'
 // CHECK-ELIDE-TREE: candidate function not viable: no known conversion from 
argument type to parameter type for 1st argument
 // CHECK-ELIDE-TREE:   class_types<
-// CHECK-ELIDE-TREE: [2 * ...], 
+// CHECK-ELIDE-TREE: [2 * ...],
 // CHECK-ELIDE-TREE: [int != (no argument)]>
 // CHECK-NOELIDE-TREE: no matching function for call to 'set10'
 // CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from 
argument type to parameter type for 1st argument
 // CHECK-NOELIDE-TREE:   class_types<
-// CHECK-NOELIDE-TREE: int, 
+// CHECK-NOELIDE-TREE: int,
 // CHECK-NOELIDE-TREE: [(no argument) != int]>
 // CHECK-NOELIDE-TREE: no matching function for call to 'set10'
 // CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from 
argument type to parameter type for 1st argument
 // CHECK-NOELIDE-TREE:   class_types<
-// CHECK-NOELIDE-TREE: int, 
-// CHECK-NOELIDE-TREE: int, 
+// CHECK-NOELIDE-TREE: int,
+// CHECK-NOELIDE-TREE: int,
 // CHECK-NOELIDE-TREE: [int != (no argument)]>
 
 template class class_ints {};
@@ -328,24 +328,24 @@ void test11() {
 // CHECK-ELIDE-TREE: no matching function for call to 'set11'
 // CHECK-ELIDE-TREE: candidate function not viable: no known conversion from 
argument type to parameter type for 1st argument
 // CHECK-ELIDE-TREE:   class_ints<
-// CHECK-ELIDE-TREE: [1 != 2], 
+// CHECK-ELIDE-TREE: [1 != 2],
 // CHECK-ELIDE-TREE: [(no argument) != 3]>
 // CHECK-ELIDE-TREE: no matching function for call to 'set11'
 // CHECK-ELIDE-TREE: candidate function not viable: no known conversion from 
argument type to parameter type for 1st argument
 // CHECK-ELIDE-TREE:   class_ints<
-// CHECK-ELIDE-TREE: [0 != 2], 
-// CHECK-ELIDE-TREE: [...], 
+// CHECK-ELIDE-TREE: [0 != 2],
+// CHECK-ELIDE-TREE: [...],
 // CHECK-ELIDE-TREE: [6 != (no argument)]>
 // CHECK-NOELIDE-TREE: no matching function for call to 'set11'
 // CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from 
argument type to parameter type for 1st argument
 // CHECK-NOELIDE-TREE:   class_ints<
-// CHECK-NOELIDE-TREE: [1 != 2], 
+// CHECK-NOELIDE-TREE: [1 != 2],
 // CHECK-NOELIDE-TREE: [(no argument) != 3]>
 // CHECK-NOELIDE-TREE: no matching function for call to 'set11'
 // CHECK-NOELIDE-TREE: candidate func

[clang] [llvm] [AArch64] Add initial support for -mcpu=olympus. (PR #132368)

2025-03-24 Thread Ricardo Jesus via cfe-commits


@@ -872,6 +883,16 @@ def ProcessorFeatures {
   list Carmel   = [HasV8_2aOps, FeatureNEON, FeatureSHA2, 
FeatureAES,
  FeatureFullFP16, FeatureCRC, FeatureLSE, 
FeatureRAS, FeatureRDM,
  FeatureFPARMv8];
+  list Olympus = [HasV9_2aOps, FeatureBRBE, FeatureCCIDX,
+FeatureCHK, FeatureCrypto, FeatureETE,

rj-jesus wrote:

Thanks, done.

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


[clang] [clang-tools-extra] [clang] Concepts: support pack expansions for type constraints (PR #132626)

2025-03-24 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/132626

>From 6c1a554cfdb7028fccae5f99863c36118fa0226a Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sat, 22 Mar 2025 17:29:16 -0300
Subject: [PATCH 1/3] Revert "[Clang] Distinguish expanding-pack-in-place cases
 for SubstTemplateTypeParmTypes (#114220)"

This reverts commit adb0d8ddceb143749c519d14b8b31b481071da77.
---
 clang/include/clang/AST/ASTContext.h |  4 +--
 clang/include/clang/AST/PropertiesBase.td|  1 -
 clang/include/clang/AST/Type.h   | 29 ++--
 clang/include/clang/AST/TypeProperties.td|  5 +--
 clang/lib/AST/ASTContext.cpp |  7 ++--
 clang/lib/AST/ASTImporter.cpp|  4 +--
 clang/lib/AST/Type.cpp   |  6 +---
 clang/lib/Sema/SemaTemplateInstantiate.cpp   | 35 ++--
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp |  2 +-
 9 files changed, 23 insertions(+), 70 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index af8c49e99a7ce..1f7c75559e1e9 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1798,9 +1798,7 @@ class ASTContext : public RefCountedBase {
   QualType
   getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
unsigned Index,
-   std::optional PackIndex,
-   SubstTemplateTypeParmTypeFlag Flag =
-   SubstTemplateTypeParmTypeFlag::None) const;
+   std::optional PackIndex) const;
   QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl,
 unsigned Index, bool Final,
 const TemplateArgument &ArgPack);
diff --git a/clang/include/clang/AST/PropertiesBase.td 
b/clang/include/clang/AST/PropertiesBase.td
index 42883b6419261..5f3a885832e2e 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -137,7 +137,6 @@ def Selector : PropertyType;
 def SourceLocation : PropertyType;
 def StmtRef : RefPropertyType<"Stmt"> { let ConstWhenWriting = 1; }
   def ExprRef : SubclassPropertyType<"Expr", StmtRef>;
-def SubstTemplateTypeParmTypeFlag : EnumPropertyType;
 def TemplateArgument : PropertyType;
 def TemplateArgumentKind : EnumPropertyType<"TemplateArgument::ArgKind">;
 def TemplateName : DefaultValuePropertyType;
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 65756203f2073..3b80f962a3bc6 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1786,15 +1786,6 @@ enum class AutoTypeKeyword {
   GNUAutoType
 };
 
-enum class SubstTemplateTypeParmTypeFlag {
-  None,
-
-  /// Whether to expand the pack using the stored PackIndex in place. This is
-  /// useful for e.g. substituting into an atomic constraint expression, where
-  /// that expression is part of an unexpanded pack.
-  ExpandPacksInPlace,
-};
-
 enum class ArraySizeModifier;
 enum class ElaboratedTypeKeyword;
 enum class VectorKind;
@@ -2164,9 +2155,6 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 LLVM_PREFERRED_TYPE(bool)
 unsigned HasNonCanonicalUnderlyingType : 1;
 
-LLVM_PREFERRED_TYPE(SubstTemplateTypeParmTypeFlag)
-unsigned SubstitutionFlag : 1;
-
 // The index of the template parameter this substitution represents.
 unsigned Index : 15;
 
@@ -6396,8 +6384,7 @@ class SubstTemplateTypeParmType final
   Decl *AssociatedDecl;
 
   SubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
-unsigned Index, std::optional PackIndex,
-SubstTemplateTypeParmTypeFlag Flag);
+unsigned Index, std::optional PackIndex);
 
 public:
   /// Gets the type that was substituted for the template
@@ -6426,31 +6413,21 @@ class SubstTemplateTypeParmType final
 return SubstTemplateTypeParmTypeBits.PackIndex - 1;
   }
 
-  SubstTemplateTypeParmTypeFlag getSubstitutionFlag() const {
-return static_cast(
-SubstTemplateTypeParmTypeBits.SubstitutionFlag);
-  }
-
   bool isSugared() const { return true; }
   QualType desugar() const { return getReplacementType(); }
 
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, getReplacementType(), getAssociatedDecl(), getIndex(),
-getPackIndex(), getSubstitutionFlag());
+getPackIndex());
   }
 
   static void Profile(llvm::FoldingSetNodeID &ID, QualType Replacement,
   const Decl *AssociatedDecl, unsigned Index,
-  std::optional PackIndex,
-  SubstTemplateTypeParmTypeFlag Flag) {
+  std::optional PackIndex) {
 Replacement.Profile(ID);
 ID.AddPointer(AssociatedDecl);
 ID.AddInteger(Index)

[libclc] 7e22b09 - [libclc] Add missing license headers to source IR files (#132758)

2025-03-24 Thread via cfe-commits

Author: Fraser Cormack
Date: 2025-03-24T16:21:59Z
New Revision: 7e22b0903150c7f722b5290155d251b50d839c3a

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

LOG: [libclc] Add missing license headers to source IR files (#132758)

Added: 


Modified: 
libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll
libclc/amdgpu/lib/shared/vload_half_helpers.ll
libclc/amdgpu/lib/shared/vstore_half_helpers.ll
libclc/generic/lib/subnormal_disable.ll
libclc/generic/lib/subnormal_helper_func.ll
libclc/generic/lib/subnormal_use_default.ll
libclc/ptx/lib/shared/vload_half_helpers.ll
libclc/ptx/lib/shared/vstore_half_helpers.ll
libclc/r600/lib/image/get_image_attributes_impl.ll
libclc/r600/lib/image/read_image_impl.ll
libclc/r600/lib/image/write_image_impl.ll

Removed: 




diff  --git a/libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll 
b/libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll
index 7f12556c0abbc..3ed5e99be3149 100644
--- a/libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll
+++ b/libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll
@@ -1,3 +1,11 @@
+;;===--===;;
+;
+; 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
+;
+;;===--===;;
+
 define i64 @__clc__sync_fetch_and_min_global_8(i64 addrspace(1)* nocapture 
%ptr, i64 %value) nounwind alwaysinline {
 entry:
   %0 = atomicrmw volatile min i64 addrspace(1)* %ptr, i64 %value seq_cst

diff  --git a/libclc/amdgpu/lib/shared/vload_half_helpers.ll 
b/libclc/amdgpu/lib/shared/vload_half_helpers.ll
index b8c905af6fc82..bf7d544afbf55 100644
--- a/libclc/amdgpu/lib/shared/vload_half_helpers.ll
+++ b/libclc/amdgpu/lib/shared/vload_half_helpers.ll
@@ -1,3 +1,11 @@
+;;===--===;;
+;
+; 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
+;
+;;===--===;;
+
 define float @__clc_vload_half_float_helper__private(half addrspace(0)* 
nocapture %ptr) nounwind alwaysinline {
   %data = load half, half addrspace(0)* %ptr
   %res = fpext half %data to float

diff  --git a/libclc/amdgpu/lib/shared/vstore_half_helpers.ll 
b/libclc/amdgpu/lib/shared/vstore_half_helpers.ll
index e958664e56016..5ec193d6d40a0 100644
--- a/libclc/amdgpu/lib/shared/vstore_half_helpers.ll
+++ b/libclc/amdgpu/lib/shared/vstore_half_helpers.ll
@@ -1,3 +1,11 @@
+;;===--===;;
+;
+; 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
+;
+;;===--===;;
+
 define void @__clc_vstore_half_float_helper__private(float %data, half 
addrspace(0)* nocapture %ptr) nounwind alwaysinline {
   %res = fptrunc float %data to half
   store half %res, half addrspace(0)* %ptr

diff  --git a/libclc/generic/lib/subnormal_disable.ll 
b/libclc/generic/lib/subnormal_disable.ll
index b935583b5ade0..732d09ff09ab4 100644
--- a/libclc/generic/lib/subnormal_disable.ll
+++ b/libclc/generic/lib/subnormal_disable.ll
@@ -1 +1,9 @@
+;;===--===;;
+;
+; 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
+;
+;;===--===;;
+
 @__CLC_SUBNORMAL_DISABLE = unnamed_addr constant i1 true

diff  --git a/libclc/generic/lib/subnormal_helper_func.ll 
b/libclc/generic/lib/subnormal_helper_func.ll
index fb1b5d2b679fe..03beecf979260 100644
--- a/libclc/generic/lib/subnormal_helper_func.ll
+++ b/libclc/generic/lib/subnormal_helper_func.ll
@@ -1,3 +1,11 @@
+;;===--===;;
+;
+; 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
+;
+;;===--===;;
+
 

[clang] [compiler-rt] [llvm] [FMV][AArch64] Add feature CSSC and detect on linux platform. (PR #132727)

2025-03-24 Thread Alexandros Lamprineas via cfe-commits


@@ -33,7 +33,7 @@ enum CPUFeatures {
   FEAT_FP,
   FEAT_SIMD,
   FEAT_CRC,
-  RESERVED_FEAT_SHA1, // previously used and now ABI legacy
+  FEAT_CSSC,

labrinea wrote:

Yeap, we only need to make sure GNU is doing the same cc @Wilco1

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


[clang] [clang][bytecode] Implement __builtin_{wcscmp, wcsncmp} (PR #132723)

2025-03-24 Thread Rainer Orth via cfe-commits

rorth wrote:

Usually the SPARC-only `clang` will reject any non-`sparc*` triple as 
unsupported.  However, there are cases where they still work; I never 
understood when this works and when it doesn't.

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


[clang] [CIR] Emit allocas into the proper lexical scope (PR #132468)

2025-03-24 Thread Bruno Cardoso Lopes via cfe-commits

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

LGTM after nit

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


[clang] [clang][bytecode] Fix zero-init of atomic floating point objects (PR #132782)

2025-03-24 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/132782

We can't pass the AtomicType along to ASTContext::getFloatTypeSemantics.

>From 88ce8a55d9e8fea57ff71989f6a5cd2fe9b505ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 24 Mar 2025 18:13:03 +0100
Subject: [PATCH] [clang][bytecode] Fix zero-init of atomic floating point
 objects

We can't pass the AtomicType along to ASTContext::getFloatTypeSemantics.
---
 clang/lib/AST/ByteCode/Compiler.cpp | 3 +++
 clang/test/AST/ByteCode/floats.cpp  | 5 -
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 943e4302a0398..5242a524308a8 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4033,6 +4033,9 @@ template  bool 
Compiler::visitBool(const Expr *E) {
 template 
 bool Compiler::visitZeroInitializer(PrimType T, QualType QT,
  const Expr *E) {
+  if (const auto *AT = QT->getAs())
+QT = AT->getValueType();
+
   switch (T) {
   case PT_Bool:
 return this->emitZeroBool(E);
diff --git a/clang/test/AST/ByteCode/floats.cpp 
b/clang/test/AST/ByteCode/floats.cpp
index 45c31c759e47f..930921d0eee1f 100644
--- a/clang/test/AST/ByteCode/floats.cpp
+++ b/clang/test/AST/ByteCode/floats.cpp
@@ -175,7 +175,10 @@ namespace ZeroInit {
   static_assert(a.f == 0.0f, "");
 
   constexpr A b{12};
-  static_assert(a.f == 0.0, "");
+  static_assert(b.f == 0.0, "");
+
+  constexpr A<_Atomic(float)> c{12};
+  static_assert(c.f == 0.0, "");
 };
 
 namespace LongDouble {

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


[clang] [clang] Fix static_cast bypassing access control (PR #132285)

2025-03-24 Thread via cfe-commits


@@ -23,3 +22,67 @@ void test(A &a, B &b) {
   const A &&ar10 = static_cast(xvalue());
   const A &&ar11 = static_cast(xvalue());
 }
+
+struct C : private A { // expected-note 4 {{declared private here}}
+C&& that();
+
+void f() {
+(void)static_cast(*this);
+(void)static_cast(*this);
+
+(void)static_cast(that());
+(void)static_cast(that());
+}
+};
+C c;
+const C cc;
+
+void f() {
+static_cast(c);// expected-error {{cannot cast 'C' to its 
private base class 'A'}}
+static_cast(c.that()); // expected-error {{cannot cast 'C' to its 
private base class 'A'}}
+
+static_cast(c);// expected-error {{cannot cast 'C' to 
its private base class 'const A'}}
+static_cast(c.that()); // expected-error {{cannot cast 'C' to 
its private base class 'const A'}}
+}
+
+constexpr auto v = (
+(A&&)c,
+(A&&)(C&&)c,
+(A&&)cc,
+(A&&)(const C&&)c,
+(const A&&)c,
+(const A&&)(C&&)c,
+(const A&&)cc,
+(const A&&)(const C&&)c
+);
+
+struct D : A, B { // expected-warning {{direct base 'A' is inaccessible due to 
ambiguity}}
+D&& rv();
+};
+D d;
+
+void g(const D cd) {
+static_cast(d);  // expected-error {{ambiguous conversion from 
derived class 'D' to base class 'A'}}
+static_cast(d.rv()); // expected-error {{ambiguous conversion from 
derived class 'D' to base class 'A'}}
+
+static_cast(d);  // expected-error {{ambiguous conversion 
from derived class 'D' to base class 'const A'}}
+static_cast(d.rv()); // expected-error {{ambiguous conversion 
from derived class 'D' to base class 'const A'}}
+
+(A&&)d;  // expected-error {{ambiguous conversion from 
derived class 'D' to base class 'A'}}
+(A&&)(D&&)d; // expected-error {{ambiguous conversion from 
derived class 'D' to base class 'A'}}
+(A&&)cd; // expected-error {{ambiguous conversion from 
derived class 'D' to base class 'A'}}
+(A&&)(const D&&)d;   // expected-error {{ambiguous conversion from 
derived class 'D' to base class 'A'}}
+(const A&&)d;// expected-error {{ambiguous conversion from 
derived class 'D' to base class 'A'}}
+(const A&&)(D&&)d;   // expected-error {{ambiguous conversion from 
derived class 'D' to base class 'A'}}
+(const A&&)cd;   // expected-error {{ambiguous conversion from 
derived class 'D' to base class 'A'}}
+(const A&&)(const D&&)d; // expected-error {{ambiguous conversion from 
derived class 'D' to base class 'A'}}
+}
+
+template
+auto h(U u = {}) -> decltype(static_cast(u));
+
+template
+int h();
+
+int i = h();
+int j = h();

offsetof wrote:

Updated the test.

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


[clang] [CIR] Add binary operators (PR #132420)

2025-03-24 Thread Bruno Cardoso Lopes via cfe-commits


@@ -143,6 +147,114 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return createCast(loc, cir::CastKind::bitcast, src, newTy);
   }
 
+  mlir::Value createBinop(mlir::Value lhs, cir::BinOpKind kind,
+  const llvm::APInt &rhs) {
+return create(lhs.getLoc(), lhs.getType(), kind, lhs,
+  getConstAPInt(lhs.getLoc(), lhs.getType(), rhs));
+  }
+
+  mlir::Value createBinop(mlir::Value lhs, cir::BinOpKind kind,
+  mlir::Value rhs) {
+return create(lhs.getLoc(), lhs.getType(), kind, lhs, rhs);
+  }
+
+  mlir::Value createBinop(mlir::Location loc, mlir::Value lhs,
+  cir::BinOpKind kind, mlir::Value rhs) {
+return create(loc, lhs.getType(), kind, lhs, rhs);
+  }
+
+  mlir::Value createLowBitsSet(mlir::Location loc, unsigned size,
+   unsigned bits) {
+llvm::APInt val = llvm::APInt::getLowBitsSet(size, bits);
+auto type = cir::IntType::get(getContext(), size, false);
+return getConstAPInt(loc, type, val);
+  }
+
+  mlir::Value createAnd(mlir::Value lhs, const llvm::APInt &rhs) {
+mlir::Value val = getConstAPInt(lhs.getLoc(), lhs.getType(), rhs);
+return createBinop(lhs, cir::BinOpKind::And, val);
+  }
+
+  mlir::Value createAnd(mlir::Value lhs, mlir::Value rhs) {
+return createBinop(lhs, cir::BinOpKind::And, rhs);
+  }
+
+  mlir::Value createAnd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
+return createBinop(loc, lhs, cir::BinOpKind::And, rhs);
+  }
+
+  mlir::Value createOr(mlir::Value lhs, const llvm::APInt &rhs) {
+mlir::Value val = getConstAPInt(lhs.getLoc(), lhs.getType(), rhs);
+return createBinop(lhs, cir::BinOpKind::Or, val);
+  }
+
+  mlir::Value createOr(mlir::Value lhs, mlir::Value rhs) {
+return createBinop(lhs, cir::BinOpKind::Or, rhs);
+  }
+
+  mlir::Value createMul(mlir::Value lhs, mlir::Value rhs, bool hasNUW = false,
+bool hasNSW = false) {
+auto op = create(lhs.getLoc(), lhs.getType(),
+ cir::BinOpKind::Mul, lhs, rhs);
+if (hasNUW)
+  op.setNoUnsignedWrap(true);
+if (hasNSW)
+  op.setNoSignedWrap(true);
+return op;
+  }
+  mlir::Value createNSWMul(mlir::Value lhs, mlir::Value rhs) {
+return createMul(lhs, rhs, false, true);
+  }
+  mlir::Value createNUWAMul(mlir::Value lhs, mlir::Value rhs) {
+return createMul(lhs, rhs, true, false);
+  }
+
+  mlir::Value createMul(mlir::Value lhs, const llvm::APInt &rhs) {
+mlir::Value val = getConstAPInt(lhs.getLoc(), lhs.getType(), rhs);
+return createBinop(lhs, cir::BinOpKind::Mul, val);
+  }
+
+  mlir::Value createSub(mlir::Value lhs, mlir::Value rhs, bool hasNUW = false,

bcardosolopes wrote:

+1 on Erich's point. I'd suggest we just have our CIR specific enum 
CIRBaseBuilder.h (should be small and ) and not depend on LLVM for it, we can 
incrementally add more things (like saturated) when they make sense. 
Alternatively, you could add enum kinds in CIRAttr and just refer to those 
directly, but doing that will require you to redesign BinOp a bit to also use 
them.

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


[clang] [CIR] Add binary operators (PR #132420)

2025-03-24 Thread Bruno Cardoso Lopes via cfe-commits

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


[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-03-24 Thread Garvit Gupta via cfe-commits

https://github.com/quic-garvgupt updated 
https://github.com/llvm/llvm-project/pull/121829

>From e07a4cd4e0ff77f74b66695923bc998904c14746 Mon Sep 17 00:00:00 2001
From: Garvit Gupta 
Date: Fri, 13 Dec 2024 05:31:56 -0800
Subject: [PATCH] [Driver] Teach Barmetal toolchain about GCC installation

This patch introduces the baretmetal toolchain object about GCC Installation.
Currently, if `--gcc-installation` ot `--gcc-install-dir` options are passed on
commandline, then sysroot will be formed from there if paths will be valid.
Otherwise, it will be fallback to as it already existed in the Baremetal
toolchaibn object. Moreover, support for adding include paths for libstd
C++ library is added as well.

Additionally, the restriction to always use integrated assembler is removed
because with valid gcc installation, gnu assembler can be invoked as well.

This patch currently adds and modifies arm related test only. The riscv specific
test will be added in the last PR when driver code related to calling of
RISCVToolchain object will be removed. Currently in this PR, there is no way to
test riscv target.

RFC:
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524

Change-Id: Ibaeb569cf7e2cee03c022aa9ecd1abe29d5c30d4
---
 clang/lib/Driver/ToolChains/BareMetal.cpp | 130 ++
 clang/lib/Driver/ToolChains/BareMetal.h   |  14 +-
 .../aarch64-none-elf/include/c++/8.2.1/.keep  |   0
 .../aarch64-none-elf/lib/.keep|   0
 .../aarch64-none-elf/lib/crt0.o   |   0
 .../bin/aarch64-none-elf-ld   |   1 +
 .../lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o |   0
 .../lib/gcc/aarch64-none-elf/8.2.1/crtend.o   |   0
 .../aarch64-none-elf/lib/crt0.o   |   0
 .../aarch64-none-elf/lib/crtbegin.o   |   0
 .../aarch64-none-elf/lib/crtend.o |   0
 .../bin/aarch64-none-elf-ld   |   1 +
 .../armv6m-none-eabi/include/c++/8.2.1/.keep  |   0
 .../armv6m-none-eabi/lib/.keep|   0
 .../armv6m-none-eabi/lib/crt0.o   |   0
 .../bin/armv6m-none-eabi-ld   |   1 +
 .../lib/gcc/armv6m-none-eabi/8.2.1/crtbegin.o |   0
 .../lib/gcc/armv6m-none-eabi/8.2.1/crtend.o   |   0
 .../armv6m-none-eabi/lib/crt0.o   |   0
 .../armv6m-none-eabi/lib/crtbegin.o   |   0
 .../armv6m-none-eabi/lib/crtend.o |   0
 .../bin/armv6m-none-eabi-ld   |   1 +
 clang/test/Driver/aarch64-toolchain-extra.c   |  28 
 clang/test/Driver/aarch64-toolchain.c |  61 
 clang/test/Driver/arm-gnutools.c  |  12 ++
 clang/test/Driver/arm-toolchain-extra.c   |  29 
 clang/test/Driver/arm-toolchain.c |  62 +
 clang/test/Driver/baremetal.cpp   |  16 +++
 28 files changed, 324 insertions(+), 32 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/include/c++/8.2.1/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/crt0.o
 create mode 100755 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/bin/aarch64-none-elf-ld
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtend.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crt0.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crtend.o
 create mode 100755 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/bin/aarch64-none-elf-ld
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/include/c++/8.2.1/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/lib/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/lib/crt0.o
 create mode 100755 
clang/test/Driver/Inputs/basic_arm_gcc_tree/bin/armv6m-none-eabi-ld
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/lib/gcc/armv6m-none-eabi/8.2.1/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/lib/gcc/armv6m-none-eabi/8.2.1/crtend.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crt0.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crtend.o
 create mode 100755 
clang/test/Driver/Inputs/basic_arm_nogcc_tree/bin/armv6m-none-eabi-ld
 create mode 100644 clang/test/Driver/aarch64-toolchain-extra.c
 create mode 100644 clang/test/Driver/aarch64-toolchain.c
 create mode 100644 clan

[clang] [flang] [flang] Add -f[no-]slp-vectorize flags (PR #132801)

2025-03-24 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

> > If you are soliciting reviews, you could also use the "Reviewers" box on 
> > the top right of this page
> 
> I would, but I do not currently have the right permissions to use the box. 
> Hence the ccs - I need someone else to do it.

Huh. I didn't realize that one needed special permissions for that.

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


[clang] 0fb4ef4 - Revert "[clang-tidy] Avoid processing declarations in system headers … (#132743)

2025-03-24 Thread via cfe-commits

Author: Carlos Galvez
Date: 2025-03-24T20:47:57+01:00
New Revision: 0fb4ef40b12d08e4a4966eeac6a395b669d63237

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

LOG: Revert "[clang-tidy] Avoid processing declarations in system headers … 
(#132743)

…(#128150)"

This was too aggressive, and leads to problems for downstream users:
https://github.com/llvm/llvm-project/pull/128150#issuecomment-2739803409

Let's revert and reland it once we have addressed the problems.

This reverts commit e4a8969e56572371201863594b3a549de2e23f32.

Co-authored-by: Carlos Gálvez 

Added: 


Modified: 
clang-tools-extra/clang-query/Query.cpp
clang-tools-extra/clang-tidy/ClangTidy.cpp
clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-anon-record-fields.cpp
clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
clang-tools-extra/test/clang-tidy/infrastructure/system-headers.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/ASTMatchers/ASTMatchFinder.h
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-query/Query.cpp 
b/clang-tools-extra/clang-query/Query.cpp
index 091713600686e..382aa5d6fe25e 100644
--- a/clang-tools-extra/clang-query/Query.cpp
+++ b/clang-tools-extra/clang-query/Query.cpp
@@ -114,7 +114,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession 
&QS) const {
 Profiler.emplace();
 
   for (auto &AST : QS.ASTs) {
-ast_matchers::MatchFinderOptions FinderOptions;
+ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
 std::optional> Records;
 if (QS.EnableProfile) {
   Records.emplace();

diff  --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index d99847a82d168..733a53a0f5dcc 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -420,7 +420,7 @@ ClangTidyASTConsumerFactory::createASTConsumer(
   std::vector> Checks =
   CheckFactories->createChecksForLanguage(&Context);
 
-  ast_matchers::MatchFinderOptions FinderOptions;
+  ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
 
   std::unique_ptr Profiling;
   if (Context.getEnableProfiling()) {
@@ -429,10 +429,6 @@ ClangTidyASTConsumerFactory::createASTConsumer(
 FinderOptions.CheckProfiling.emplace(Profiling->Records);
   }
 
-  // Avoid processing system headers, unless the user explicitly requests it
-  if (!Context.getOptions().SystemHeaders.value_or(false))
-FinderOptions.SkipSystemHeaders = true;
-
   std::unique_ptr Finder(
   new ast_matchers::MatchFinder(std::move(FinderOptions)));
 

diff  --git a/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp 
b/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
index 2dff4c0e53b8c..bc4970825b4ca 100644
--- a/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
@@ -35,30 +35,6 @@ AST_POLYMORPHIC_MATCHER_P(
  Builder) != Args.end();
 }
 
-bool isStdOrPosixImpl(const DeclContext *Ctx) {
-  if (!Ctx->isNamespace())
-return false;
-
-  const auto *ND = cast(Ctx);
-  if (ND->isInline()) {
-return isStdOrPosixImpl(ND->getParent());
-  }
-
-  if (!ND->getParent()->getRedeclContext()->isTranslationUnit())
-return false;
-
-  const IdentifierInfo *II = ND->getIdentifier();
-  return II && (II->isStr("std") || II->isStr("posix"));
-}
-
-AST_MATCHER(Decl, isInStdOrPosixNS) {
-  for (const auto *Ctx = Node.getDeclContext(); Ctx; Ctx = Ctx->getParent()) {
-if (isStdOrPosixImpl(Ctx))
-  return true;
-  }
-  return false;
-}
-
 } // namespace
 
 namespace clang::tidy::cert {
@@ -66,10 +42,12 @@ namespace clang::tidy::cert {
 void DontModifyStdNamespaceCheck::registerMatchers(MatchFinder *Finder) {
   auto HasStdParent =
   hasDeclContext(namespaceDecl(hasAnyName("std", "posix"),
-   unless(hasDeclContext(namespaceDecl(
+   unless(hasParent(namespaceDecl(
  .bind("nmspc"));
-  auto UserDefinedType = qualType(hasUnqualifiedDesugaredType(
-  tagType(unless(hasDeclaration(tagDecl(isInStdOrPosixNS()));
+  auto UserDefinedType = qualType(
+  hasUnqualifiedDesugaredType(tagType(unless(hasDeclaration(tagDecl(
+  hasAncestor(namespaceDecl(hasAnyName("std", "posix"),
+unless(hasParent(namespaceDecl()));
   auto HasNoProgramDefinedTemplateArgument = unless(

[clang] [HLSL] Finish exposing half types and intrinsics always (PR #132804)

2025-03-24 Thread Sarah Spall via cfe-commits

spall wrote:

> > > For example, for `abs`, it still depends on the _HLSL_16BIT_AVAILABILITY 
> > > availability attribute. Does this PR intend to keep abs overloads using 
> > > half "unexposed"? Or should that overload for abs be exposed too?
> > 
> > 
> > Oh I see what you are referring to. That might be my mistake; let me double 
> > check if I used the wrong __HLSL_AVAILABILITY
> 
> Yeah, if the intention of this PR is to expose all half type overloads 
> always, then I would think there is no more utility in defining 
> `HLSL_16BIT_AVAILABILITY` anymore.

I think I was meant to use _HLSL_16BIT_AVAILABILITY and not _HLSL_AVAILABILITY; 
I'll fix that. Thanks for noticing the error!


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


[clang] [HLSL] Finish exposing half types and intrinsics always (PR #132804)

2025-03-24 Thread Chris B via cfe-commits

https://github.com/llvm-beanz commented:

this is not NFC, so we should verify that we can call these intrinsics with 
`half` values even if 16-bit types aren't enabled, and that they properly 
codegen to 32-bit variants.

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


[clang] [HLSL] Finish exposing half types and intrinsics always (PR #132804)

2025-03-24 Thread Joshua Batista via cfe-commits

bob80905 wrote:

> > For example, for `abs`, it still depends on the _HLSL_16BIT_AVAILABILITY 
> > availability attribute. Does this PR intend to keep abs overloads using 
> > half "unexposed"? Or should that overload for abs be exposed too?
> 
> Oh I see what you are referring to. That might be my mistake; let me double 
> check if I used the wrong __HLSL_AVAILABILITY

Yeah, if the intention of this PR is to expose all half type overloads always, 
then I would think there is no more utility in defining
`HLSL_16BIT_AVAILABILITY` anymore.

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


[clang] [flang] [flang] Add -f[no-]slp-vectorize flags (PR #132801)

2025-03-24 Thread Kajetan Puchalski via cfe-commits

mrkajetanp wrote:

> If you are soliciting reviews, you could also use the "Reviewers" box on the 
> top right of this page

I would, but I do not currently have the right permissions to use the box. 
Hence the ccs - I need someone else to do it. 

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


[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)

2025-03-24 Thread Garvit Gupta via cfe-commits

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


[clang] [clang-tools-extra] [clang][lex] Store non-owning options ref in `HeaderSearch` (PR #132780)

2025-03-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)


Changes

This makes it so that `CompilerInvocation` can be the only entity that manages 
ownership of `HeaderSearchOptions`, making it possible to implement 
copy-on-write semantics.

---

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


20 Files Affected:

- (modified) clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
(+4-7) 
- (modified) clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h 
(+2) 
- (modified) clang-tools-extra/clangd/ModulesBuilder.cpp (+5-5) 
- (modified) clang-tools-extra/clangd/unittests/StdLibTests.cpp (+2-1) 
- (modified) clang-tools-extra/modularize/ModularizeUtilities.cpp (+2-3) 
- (modified) clang-tools-extra/modularize/ModularizeUtilities.h (+2) 
- (modified) clang/include/clang/Frontend/ASTUnit.h (+3) 
- (modified) clang/include/clang/Lex/HeaderSearch.h (+5-5) 
- (modified) clang/lib/Frontend/ASTUnit.cpp (+2-2) 
- (modified) clang/lib/Frontend/CompilerInstance.cpp (+1-1) 
- (modified) clang/lib/Lex/HeaderSearch.cpp (+20-21) 
- (modified) clang/unittests/Analysis/MacroExpansionContextTest.cpp (+2-2) 
- (modified) clang/unittests/Basic/SourceManagerTest.cpp (+10-10) 
- (modified) clang/unittests/Lex/HeaderSearchTest.cpp (+2-2) 
- (modified) clang/unittests/Lex/LexerTest.cpp (+2-2) 
- (modified) clang/unittests/Lex/ModuleDeclStateTest.cpp (+2-2) 
- (modified) clang/unittests/Lex/PPCallbacksTest.cpp (+14-12) 
- (modified) clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp (+2-2) 
- (modified) clang/unittests/Lex/PPDependencyDirectivesTest.cpp (+2-2) 
- (modified) clang/unittests/Lex/PPMemoryAllocationsTest.cpp (+2-2) 


``diff
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index 4c34f9ea122d9..a15850cb63542 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -73,7 +73,7 @@ 
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
   // Forward the new diagnostics to the original DiagnosticConsumer.
   Diags(new DiagnosticIDs, new DiagnosticOptions,
 new ForwardingDiagnosticConsumer(Compiler.getDiagnosticClient())),
-  LangOpts(Compiler.getLangOpts()) {
+  LangOpts(Compiler.getLangOpts()), HSOpts(Compiler.getHeaderSearchOpts()) 
{
   // Add a FileSystem containing the extra files needed in place of modular
   // headers.
   OverlayFS->pushOverlay(InMemoryFs);
@@ -86,11 +86,8 @@ 
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
 
   LangOpts.Modules = false;
 
-  auto HSO = std::make_shared();
-  *HSO = Compiler.getHeaderSearchOpts();
-
-  HeaderInfo = std::make_unique(HSO, Sources, Diags, LangOpts,
-   &Compiler.getTarget());
+  HeaderInfo = std::make_unique(HSOpts, Sources, Diags, LangOpts,
+  &Compiler.getTarget());
 
   auto PO = std::make_shared();
   *PO = Compiler.getPreprocessorOpts();
@@ -102,7 +99,7 @@ 
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
   PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
   InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
  Compiler.getFrontendOpts(), 
Compiler.getCodeGenOpts());
-  ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts,
+  ApplyHeaderSearchOptions(*HeaderInfo, HSOpts, LangOpts,
Compiler.getTarget().getTriple());
 }
 
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
index 0742c21bc4372..a263681b3c633 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_TOOLING_EXPANDMODULARHEADERSPPCALLBACKS_H_
 #define LLVM_CLANG_TOOLING_EXPANDMODULARHEADERSPPCALLBACKS_H_
 
+#include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/DenseSet.h"
@@ -129,6 +130,7 @@ class ExpandModularHeadersPPCallbacks : public PPCallbacks {
   SourceManager &Sources;
   DiagnosticsEngine Diags;
   LangOptions LangOpts;
+  HeaderSearchOptions HSOpts;
   TrivialModuleLoader ModuleLoader;
 
   std::unique_ptr HeaderInfo;
diff --git a/clang-tools-extra/clangd/ModulesBuilder.cpp 
b/clang-tools-extra/clangd/ModulesBuilder.cpp
index 39cf57f5fe724..03c5f5e1b5993 100644
--- a/clang-tools-extra/clangd/ModulesBuilder.cpp
+++ b/clang-tools-extra/clangd/ModulesBuilder.cpp
@@ -181,10 +181,10 @@ class ReusablePrerequisiteModules : public 
PrerequisiteModules {
 bool IsModuleFileUpToDate(PathRef ModuleFilePath,
   const PrerequisiteM

[clang] [HLSL] Finish exposing half types and intrinsics always (PR #132804)

2025-03-24 Thread Sarah Spall via cfe-commits

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-24 Thread Oliver Hunt via cfe-commits


@@ -4749,6 +4753,15 @@ class Sema final : public SemaBase {
 
   CXXRecordDecl *getStdBadAlloc() const;
   EnumDecl *getStdAlignValT() const;
+  ClassTemplateDecl *getStdTypeIdentity() const;
+  std::optional InstantiateSpecializedTypeIdentity(QualType Subject);

ojhunt wrote:

Done.




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


[clang] Allow direct dispatch for the ObjFW runtime (PR #126382)

2025-03-24 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

https://llvm.org/docs/GitHub.html#backporting-fixes-to-the-release-branches 
https://llvm.org/docs/HowToReleaseLLVM.html#release-patch-rules .

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


[clang] Allow direct dispatch for the ObjFW runtime (PR #126382)

2025-03-24 Thread Jonathan Schleifer via cfe-commits

Midar wrote:

Thanks, that looks like it'll have to wait for 21.

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


[clang] [clang] Upstream Mach-O ptrauth driver defaults (PR #132834)

2025-03-24 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Nico Weber (nico)


Changes



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


3 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+41) 
- (modified) clang/lib/Driver/ToolChains/Darwin.h (+8) 
- (added) clang/test/Driver/arch-arm64e.c (+66) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index e67997314da36..5ac105d82ef6d 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1201,6 +1201,13 @@ void DarwinClang::addClangWarningOptions(ArgStringList 
&CC1Args) const {
   }
 }
 
+void DarwinClang::addClangTargetOptions(
+  const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
+  Action::OffloadKind DeviceOffloadKind) const {
+
+  Darwin::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
+}
+
 /// Take a path that speculatively points into Xcode and return the
 /// `XCODE/Contents/Developer` path if it is an Xcode path, or an empty path
 /// otherwise.
@@ -3060,9 +3067,43 @@ bool Darwin::isSizedDeallocationUnavailable() const {
   return TargetVersion < sizedDeallocMinVersion(OS);
 }
 
+void MachO::addClangTargetOptions(
+const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const {
+
+  ToolChain::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
+
+  // On arm64e, enable pointer authentication (for the return address and
+  // indirect calls), as well as usage of the intrinsics.
+  if (getArchName() == "arm64e") {
+if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
+   options::OPT_fno_ptrauth_returns))
+  CC1Args.push_back("-fptrauth-returns");
+
+if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
+   options::OPT_fno_ptrauth_intrinsics))
+  CC1Args.push_back("-fptrauth-intrinsics");
+
+if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
+   options::OPT_fno_ptrauth_calls))
+  CC1Args.push_back("-fptrauth-calls");
+
+if (!DriverArgs.hasArg(options::OPT_fptrauth_indirect_gotos,
+   options::OPT_fno_ptrauth_indirect_gotos))
+  CC1Args.push_back("-fptrauth-indirect-gotos");
+
+if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
+   options::OPT_fno_ptrauth_auth_traps))
+  CC1Args.push_back("-fptrauth-auth-traps");
+  }
+}
+
 void Darwin::addClangTargetOptions(
 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
 Action::OffloadKind DeviceOffloadKind) const {
+
+  MachO::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
+
   // Pass "-faligned-alloc-unavailable" only when the user hasn't manually
   // enabled or disabled aligned allocations.
   if (!DriverArgs.hasArgNoClaim(options::OPT_faligned_allocation,
diff --git a/clang/lib/Driver/ToolChains/Darwin.h 
b/clang/lib/Driver/ToolChains/Darwin.h
index c44780c577f4f..41aa07c188868 100644
--- a/clang/lib/Driver/ToolChains/Darwin.h
+++ b/clang/lib/Driver/ToolChains/Darwin.h
@@ -145,6 +145,10 @@ class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
   Tool *buildStaticLibTool() const override;
   Tool *getTool(Action::ActionClass AC) const override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ Action::OffloadKind DeviceOffloadKind) const 
override;
+
 private:
   mutable std::unique_ptr Lipo;
   mutable std::unique_ptr Dsymutil;
@@ -653,6 +657,10 @@ class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
 
   void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const 
override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ Action::OffloadKind DeviceOffloadKind) const 
override;
+
   void AddLinkARCArgs(const llvm::opt::ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) const override;
 
diff --git a/clang/test/Driver/arch-arm64e.c b/clang/test/Driver/arch-arm64e.c
new file mode 100644
index 0..0fb12d4dcc5e3
--- /dev/null
+++ b/clang/test/Driver/arch-arm64e.c
@@ -0,0 +1,66 @@
+// Check that we can manually enable specific ptrauth features.
+
+// RUN: %clang -target arm64-apple-darwin -c %s -### 2>&1 | FileCheck %s 
--check-prefix NONE
+// NONE: "-cc1"
+// NONE-NOT: "-fptrauth-intrinsics"
+// NONE-NOT: "-fptrauth-calls"
+// NONE-NOT: "-fptrauth-returns"
+// NONE-NOT: "-fptrauth-indirect-gotos"
+// NONE-NOT: "-fptrauth-auth-traps"
+
+// RUN: %clang -target arm64-apple-darwin -fptrauth-calls -c %s -### 2>&1 | 
FileCheck %s --check-prefix CALL
+// CALL: "-cc1"{{.*}} {{.*}} "-fptrauth-calls"
+
+// RUN: %clang -target arm64-

[clang] [Clang][Driver] Override complex number calculation method by -fno-fa… (PR #132680)

2025-03-24 Thread Andy Kaylor via cfe-commits


@@ -2997,6 +2997,7 @@ static void RenderFloatingPointOptions(const ToolChain 
&TC, const Driver &D,
   LangOptions::ComplexRangeKind Range = LangOptions::ComplexRangeKind::CX_None;
   std::string ComplexRangeStr = "";
   std::string GccRangeComplexOption = "";
+  std::string LastComplexRangeOption = "";

andykaylor wrote:

I don't think I remember during our Discourse discussion of this that there was 
already a `GccRangeComplexOption` variable here. Do we really need another 
variable? If you just set GccRangeComplexOption to empty for `-ffast-math` and 
`-fno-fast-math`, would that give us reasonable diagnostics?

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


[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-24 Thread Andrew Pinski via cfe-commits


@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -std=c99 -fsyntax-only -verify %s

pinskia wrote:

> This feels like a pretty bare bones set of tests, I think we can do better.
> 
> For example, it has been discussed that there should not be side effects, 
> let's verify that. Above in a comment `(int)var` was mentioned, we should 
> verify that. How about return values from functions which was also mentioned 
> above, we should verify it is usable in constant expressions etc

Agreed.  I have not written the testcases for GCC patch yet but I will make 
sure Kees's clang implementation matches up. Since GCC is in stage 4 and will 
be for one more month I am not going to submit the GCC patch until then so we 
have plenty of time to get agreement on the semantics of the builtin and such.

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


[clang] [clang][modules] Lazily load by name lookups in module maps (PR #132853)

2025-03-24 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-modules

Author: Michael Spencer (Bigcheese)


Changes

Instead of eagerly populating the `clang::ModuleMap` when looking up a module 
by name, this patch changes `HeaderSearch` to only load the modules that are 
actually used.

This introduces `ModuleMap::findOrLoadModule` which will load modules from 
parsed but not loaded module maps. This cannot be used anywhere that the module 
loading code calls into as it can create infinite recursion.

This currently just reparses module maps when looking up a module by header. 
This is fine as redeclarations are allowed from the same file, but future 
patches will also make looking up a module by header lazy.

This patch changes the shadow.m test to use explicitly built modules and 
`#import`. This test and the shadow feature are very brittle and do not work in 
general. The test relied on pcm files being left behind by prior failing clang 
invocations that were then reused by the last invocation. If you clean the 
cache then the last invocation will always fail. This is because the input 
module map and the `-fmodule-map-file=` module map are parsed in the same 
module scope, and `-fmodule-map-file=` is forwarded to implicit module builds. 
That means you are guaranteed to hit a module redeclaration error if the TU 
actually imports the module it is trying to shadow.

This patch changes when we load A2's module map to after the `A` module has 
been loaded, which sets the `IsFromModuleFile` bit on `A`. This means that A2's 
`A` is skipped entirely instead of creating a shadow module, and we get textual 
inclusion. It is possible to construct a case where this would happen before 
this patch too.

An upcoming patch in this series will rework shadowing to work in the general 
case, but that's only possible once header -> module lookup is lazy too.

---

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


17 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+1) 
- (modified) clang/include/clang/Basic/DiagnosticLexKinds.td (+6) 
- (modified) clang/include/clang/Lex/HeaderSearch.h (+39-2) 
- (modified) clang/include/clang/Lex/ModuleMap.h (+20) 
- (modified) clang/include/clang/Lex/ModuleMapFile.h (+9) 
- (modified) clang/lib/Frontend/CompilerInstance.cpp (+2-2) 
- (modified) clang/lib/Lex/HeaderSearch.cpp (+89-14) 
- (modified) clang/lib/Lex/ModuleMap.cpp (+139-12) 
- (modified) clang/lib/Lex/ModuleMapFile.cpp (+3) 
- (modified) clang/lib/Sema/SemaModule.cpp (+1-1) 
- (added) clang/test/Modules/Inputs/shadow/A1/A1.h () 
- (modified) clang/test/Modules/Inputs/shadow/A1/module.modulemap (+3-1) 
- (added) clang/test/Modules/Inputs/shadow/A2/A2.h () 
- (modified) clang/test/Modules/Inputs/shadow/A2/module.modulemap (+3-1) 
- (added) clang/test/Modules/lazy-by-name-lookup.c (+31) 
- (modified) clang/test/Modules/modulemap-locations.m (+2-1) 
- (modified) clang/test/Modules/shadow.m (+6-5) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index b9f08d96151c9..1abb63ba3aea6 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -576,6 +576,7 @@ def ModuleImport : DiagGroup<"module-import">;
 def ModuleConflict : DiagGroup<"module-conflict">;
 def ModuleFileExtension : DiagGroup<"module-file-extension">;
 def ModuleIncludeDirectiveTranslation : 
DiagGroup<"module-include-translation">;
+def ModuleMap : DiagGroup<"module-map">;
 def RoundTripCC1Args : DiagGroup<"round-trip-cc1-args">;
 def NewlineEOF : DiagGroup<"newline-eof">;
 def Nullability : DiagGroup<"nullability">;
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 912b8bd46e194..a6866ef868dcd 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -836,6 +836,12 @@ def warn_pp_date_time : Warning<
   ShowInSystemHeader, DefaultIgnore, InGroup>;
 
 // Module map parsing
+def remark_mmap_parse : Remark<
+  "parsing modulemap '%0'">, ShowInSystemHeader, InGroup;
+def remark_mmap_load : Remark<
+  "loading modulemap '%0'">, ShowInSystemHeader, InGroup;
+def remark_mmap_load_module : Remark<
+  "loading parsed module '%0'">, ShowInSystemHeader, InGroup;
 def err_mmap_unknown_token : Error<"skipping stray token">;
 def err_mmap_expected_module : Error<"expected module declaration">;
 def err_mmap_expected_module_name : Error<"expected module name">;
diff --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index f3dac905318c6..2c1e245fbfd37 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -332,13 +332,24 @@ class HeaderSearch {
   /// The mapping between modules and headers.
   mutable ModuleMap ModMap;
 
+  enum M

[clang] [clang][scan-build] Treat --use-cc and --use-c++ as shell commands (PR #131932)

2025-03-24 Thread Florian Ragwitz via cfe-commits


@@ -51,63 +51,40 @@ sub silent_system {
 # Compiler command setup.
 
##===--===##
 
-# Search in the PATH if the compiler exists
-sub SearchInPath {
-my $file = shift;
-foreach my $dir (split (':', $ENV{PATH})) {
-if (-x "$dir/$file") {
-return 1;
-}
-}
-return 0;
-}
-
-my $Compiler;
-my $Clang;
-my $DefaultCCompiler;
-my $DefaultCXXCompiler;
-my $IsCXX;
-my $AnalyzerTarget;
-
-# If on OSX, use xcrun to determine the SDK root.
-my $UseXCRUN = 0;
-
-if (`uname -s` =~ m/Darwin/) {
-  $DefaultCCompiler = 'clang';
-  $DefaultCXXCompiler = 'clang++';
-  # Older versions of OSX do not have xcrun to
-  # query the SDK location.
-  if (-x "/usr/bin/xcrun") {
-$UseXCRUN = 1;
-  }
-} elsif (`uname -s` =~ m/(FreeBSD|OpenBSD)/) {
-  $DefaultCCompiler = 'cc';
-  $DefaultCXXCompiler = 'c++';
-} else {
-  $DefaultCCompiler = 'gcc';
-  $DefaultCXXCompiler = 'g++';
-}
-
-if ($FindBin::Script =~ /c\+\+-analyzer/) {
-  $Compiler = $ENV{'CCC_CXX'};
-  if (!defined $Compiler || (! -x $Compiler && ! SearchInPath($Compiler))) { 
$Compiler = $DefaultCXXCompiler; }
-
-  $Clang = $ENV{'CLANG_CXX'};
-  if (!defined $Clang || ! -x $Clang) { $Clang = 'clang++'; }
-
-  $IsCXX = 1
+{
+  my ($DefaultCCompiler, $DefaultCXXCompiler);
+
+  my $os = `uname -s`;
+  if ($os =~ m/Darwin/) {
+$DefaultCCompiler = 'clang';
+$DefaultCXXCompiler = 'clang++';
+  } elsif ($os =~ m/(FreeBSD|OpenBSD)/) {
+$DefaultCCompiler = 'cc';
+$DefaultCXXCompiler = 'c++';
+  } else {
+$DefaultCCompiler = 'gcc';
+$DefaultCXXCompiler = 'g++';
+  }
+
+  sub DetermineCompiler {
+my ($is_cxx) = @_;
+my $default = $is_cxx ? $DefaultCXXCompiler : $DefaultCCompiler;
+my $opt = $ENV{$is_cxx ? 'CCC_CXX' : 'CCC_CC'};
+return defined $opt ? shellwords($opt) : $default;
+  }
 }
-else {
-  $Compiler = $ENV{'CCC_CC'};
-  if (!defined $Compiler || (! -x $Compiler && ! SearchInPath($Compiler))) { 
$Compiler = $DefaultCCompiler; }
-
-  $Clang = $ENV{'CLANG'};
-  if (!defined $Clang || ! -x $Clang) { $Clang = 'clang'; }
 
-  $IsCXX = 0
+sub DetermineClang {
+  my ($is_cxx) = @_;
+  my $default = $is_cxx ? 'clang++' : 'clang';
+  my $opt = $ENV{$is_cxx ? 'CLANG_CXX' : 'CLANG'};
+  return defined $opt ? $opt : $default;
 }
 
-$AnalyzerTarget = $ENV{'CLANG_ANALYZER_TARGET'};
+my $IsCXX = $FindBin::Script =~ /c\+\+-analyzer/;
+my ($Compiler, @CompilerArgs) = DetermineCompiler($IsCXX);

rafl wrote:

@ziqingluo-90 that's exactly right. `DetermineCompiler` returns a list of 
values (potentially a singleton list), and the call-site unpacks that return 
value into the first list element `$Compiler` and the rest of the list 
`@CompilerArgs` (which might be empty).

The actual parsing is done using shellwords from 
[Text::ParseWords](https://metacpan.org/pod/Text::ParseWords).

If you'd like to experiment how it parses certain inputs, you can do something 
like this, which prints out the parsed list, one item per line:

```
$ CCC_CC='foo "bar baz" \"quux' perl -MText::ParseWords -le'print for 
shellwords $ENV{CCC_CC}'
foo
bar baz
"quux
```

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


[clang] [clang][AMDGPU] Enable module splitting by default (PR #128509)

2025-03-24 Thread Pierre van Houtryve via cfe-commits

Pierre-vh wrote:

@shiltian PSDB passed, is it enough to land?

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


[clang] [CIR] Add binary operators (PR #132420)

2025-03-24 Thread Morris Hafner via cfe-commits


@@ -143,6 +147,114 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return createCast(loc, cir::CastKind::bitcast, src, newTy);
   }
 
+  mlir::Value createBinop(mlir::Value lhs, cir::BinOpKind kind,
+  const llvm::APInt &rhs) {
+return create(lhs.getLoc(), lhs.getType(), kind, lhs,
+  getConstAPInt(lhs.getLoc(), lhs.getType(), rhs));
+  }
+
+  mlir::Value createBinop(mlir::Value lhs, cir::BinOpKind kind,
+  mlir::Value rhs) {
+return create(lhs.getLoc(), lhs.getType(), kind, lhs, rhs);

mmha wrote:

Very nice catch. The source locations of all binops except for division were 
not passed through. I changed the signature of the builder functions to require 
an `mlir::Location`. If there's a future need for an overload without a 
location we can add those later.

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


[clang] [clang-format] Don't wrap before attributes in parameter lists (PR #132519)

2025-03-24 Thread via cfe-commits

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


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


[clang] [CIR] Add binary operators (PR #132420)

2025-03-24 Thread Morris Hafner via cfe-commits


@@ -826,6 +826,129 @@ def ForOp : CIR_Op<"for", [LoopOpInterface, 
NoRegionArguments]> {
   }];
 }
 
+//===--===//
+// BinOp
+//===--===//
+
+// FIXME: represent Commutative, Idempotent traits for appropriate binops
+def BinOpKind_Mul : I32EnumAttrCase<"Mul", 1, "mul">;
+def BinOpKind_Div : I32EnumAttrCase<"Div", 2, "div">;
+def BinOpKind_Rem : I32EnumAttrCase<"Rem", 3, "rem">;
+def BinOpKind_Add : I32EnumAttrCase<"Add", 4, "add">;
+def BinOpKind_Sub : I32EnumAttrCase<"Sub", 5, "sub">;
+def BinOpKind_And : I32EnumAttrCase<"And", 8, "and">;
+def BinOpKind_Xor : I32EnumAttrCase<"Xor", 9, "xor">;
+def BinOpKind_Or  : I32EnumAttrCase<"Or", 10, "or">;
+// TODO(cir): Do we need a min binop?
+def BinOpKind_Max : I32EnumAttrCase<"Max", 11, "max">;

mmha wrote:

This is to support `__builtin_elementwise_max` and at least one corresponding 
SIMD intrinsic function (see https://github.com/llvm/clangir/pull/1201).

I can't find that `TODO` in the git history of the incubator for some reason. 
But since there is a `__builtin_elementwise_min` I assume there needs to be a 
min as well.

Both builtins are still NYI though so I could remove them for the time being.

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


[clang] [clang][AMDGPU] Enable module splitting by default (PR #128509)

2025-03-24 Thread Shilei Tian via cfe-commits

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


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


[clang] [llvm] [IRBuilder] Add new overload for CreateIntrinsic (PR #131942)

2025-03-24 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul updated 
https://github.com/llvm/llvm-project/pull/131942

>From 321ac988a49489d910bf8ba90a28d05db853cc0d Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Tue, 18 Mar 2025 13:19:24 -0700
Subject: [PATCH] [IRBuilder] Add new overload for CreateIntrinsic

Add a new `CreateIntrinsic` overload with no `Types`, useful for
creating calls to non-overloaded intrinsics that don't need
additional mangling.
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  4 +-
 clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp   |  9 ++--
 llvm/include/llvm/IR/IRBuilder.h  |  8 +++
 llvm/lib/CodeGen/SafeStack.cpp|  2 +-
 llvm/lib/CodeGen/StackProtector.cpp   |  4 +-
 llvm/lib/IR/AutoUpgrade.cpp   | 52 +--
 .../Target/AArch64/AArch64ISelLowering.cpp|  4 +-
 .../AArch64/AArch64TargetTransformInfo.cpp|  2 +-
 .../AMDGPU/AMDGPUAsanInstrumentation.cpp  |  2 +-
 .../Target/AMDGPU/AMDGPUAtomicOptimizer.cpp   | 11 ++--
 .../Target/AMDGPU/AMDGPUCodeGenPrepare.cpp|  2 +-
 .../AMDGPU/AMDGPULowerKernelArguments.cpp |  2 +-
 .../AMDGPU/AMDGPULowerModuleLDSPass.cpp   |  3 +-
 .../lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp |  6 +--
 llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp   | 18 +++
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp |  8 +--
 llvm/lib/Target/ARM/ARMISelLowering.cpp   | 10 ++--
 llvm/lib/Target/ARM/MVETailPredication.cpp|  2 +-
 llvm/lib/Target/Hexagon/HexagonGenExtract.cpp |  2 +-
 .../Target/Hexagon/HexagonISelLowering.cpp|  4 +-
 .../Target/Hexagon/HexagonVectorCombine.cpp   |  2 +-
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   |  2 +-
 llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp |  6 +--
 llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp |  4 +-
 llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp   |  2 +-
 .../Target/X86/X86InstCombineIntrinsic.cpp|  4 +-
 llvm/lib/Target/X86/X86LowerAMXType.cpp   | 20 +++
 llvm/lib/Target/X86/X86WinEHState.cpp |  6 +--
 .../Target/XCore/XCoreLowerThreadLocal.cpp|  2 +-
 llvm/lib/Transforms/IPO/CrossDSOCFI.cpp   |  2 +-
 .../Instrumentation/BoundsChecking.cpp|  4 +-
 .../Instrumentation/HWAddressSanitizer.cpp|  3 +-
 llvm/lib/Transforms/Instrumentation/KCFI.cpp  |  2 +-
 .../Instrumentation/MemorySanitizer.cpp   |  4 +-
 .../Instrumentation/PGOInstrumentation.cpp|  7 ++-
 .../Instrumentation/ThreadSanitizer.cpp   |  2 +-
 llvm/lib/Transforms/Scalar/SROA.cpp   |  2 +-
 llvm/lib/Transforms/Utils/GuardUtils.cpp  |  2 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +-
 llvm/unittests/IR/IRBuilderTest.cpp   | 44 +---
 llvm/unittests/Transforms/Utils/LocalTest.cpp |  4 +-
 41 files changed, 146 insertions(+), 137 deletions(-)

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 0e859dd4a0b1d..3b1810b62a2cd 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -385,8 +385,8 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   SmallVector OB;
   if (CGM.shouldEmitConvergenceTokens()) {
 assert(EntryFn->isConvergent());
-llvm::Value *I = B.CreateIntrinsic(
-llvm::Intrinsic::experimental_convergence_entry, {}, {});
+llvm::Value *I =
+B.CreateIntrinsic(llvm::Intrinsic::experimental_convergence_entry, {});
 llvm::Value *bundleArgs[] = {I};
 OB.emplace_back("convergencectrl", bundleArgs);
   }
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp 
b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index f94917c905081..632181ff0c46e 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -241,13 +241,14 @@ static Value *handleHlslClip(const CallExpr *E, 
CodeGenFunction *CGF) {
 CMP = CGF->Builder.CreateIntrinsic(
 CGF->Builder.getInt1Ty(), CGF->CGM.getHLSLRuntime().getAnyIntrinsic(),
 {FCompInst});
-  } else
+  } else {
 CMP = CGF->Builder.CreateFCmpOLT(Op0, FZeroConst);
+  }
 
-  if (CGF->CGM.getTarget().getTriple().isDXIL())
+  if (CGF->CGM.getTarget().getTriple().isDXIL()) {
 LastInstr = CGF->Builder.CreateIntrinsic(
 CGF->VoidTy, Intrinsic::dx_discard, {CMP});
-  else if (CGF->CGM.getTarget().getTriple().isSPIRV()) {
+  } else if (CGF->CGM.getTarget().getTriple().isSPIRV()) {
 BasicBlock *LT0 = CGF->createBasicBlock("lt0", CGF->CurFn);
 BasicBlock *End = CGF->createBasicBlock("end", CGF->CurFn);
 
@@ -255,7 +256,7 @@ static Value *handleHlslClip(const CallExpr *E, 
CodeGenFunction *CGF) {
 
 CGF->Builder.SetInsertPoint(LT0);
 
-CGF->Builder.CreateIntrinsic(CGF->VoidTy, Intrinsic::spv_discard, {});
+CGF->Builder.CreateIntrinsic(Intrinsic::spv_discard, {});
 
 LastInstr = CGF->Builder.CreateBr(End);
 CGF->Builder.SetInsertPoint(End);
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 750a99cc50dd7..07660e93253d

[clang] [flang] [llvm] [clang][flang][Triple][llvm] Add isOffload function to LangOpts and isGPU function to Triple (PR #126956)

2025-03-24 Thread Nick Sarnie via cfe-commits

https://github.com/sarnex updated 
https://github.com/llvm/llvm-project/pull/126956

>From 044158c176316e6c9f44ce1487ff631c8a0d15c4 Mon Sep 17 00:00:00 2001
From: "Sarnie, Nick" 
Date: Tue, 4 Mar 2025 11:16:34 -0800
Subject: [PATCH 1/4] [clang] Add isOffloadingTarget function to LangOpts

Signed-off-by: Sarnie, Nick 
---
 clang/include/clang/Basic/LangOptions.h   |  4 
 clang/lib/CodeGen/CGOpenMPRuntime.cpp |  7 +++
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +-
 clang/lib/CodeGen/CodeGenModule.h |  3 +--
 clang/lib/Frontend/CompilerInvocation.cpp |  4 
 clang/lib/Sema/SemaType.cpp   | 16 
 6 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index e925e0f3b5d85..d722ca2d926b2 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -636,6 +636,8 @@ class LangOptions : public LangOptionsBase {
   bool AtomicFineGrainedMemory = false;
   bool AtomicIgnoreDenormalMode = false;
 
+  bool IsOffloadingTarget = false;
+
   LangOptions();
 
   /// Set language defaults for the given input language and
@@ -838,6 +840,8 @@ class LangOptions : public LangOptionsBase {
   return FPExceptionModeKind::FPE_Ignore;
 return EM;
   }
+
+  bool isOffloadingTarget() const { return IsOffloadingTarget; }
 };
 
 /// Floating point control options
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 06a652c146fb9..f61b46c4369a5 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2613,9 +2613,8 @@ void CGOpenMPRuntime::emitDistributeStaticInit(
   emitUpdateLocation(CGF, Loc, OMP_IDENT_WORK_DISTRIBUTE);
   llvm::Value *ThreadId = getThreadID(CGF, Loc);
   llvm::FunctionCallee StaticInitFunction;
-  bool isGPUDistribute =
-  CGM.getLangOpts().OpenMPIsTargetDevice &&
-  (CGM.getTriple().isAMDGCN() || CGM.getTriple().isNVPTX());
+  bool isGPUDistribute = CGM.getLangOpts().OpenMPIsTargetDevice &&
+ CGM.getLangOpts().isOffloadingTarget();
   StaticInitFunction = OMPBuilder.createForStaticInitFunction(
   Values.IVSize, Values.IVSigned, isGPUDistribute);
 
@@ -2645,7 +2644,7 @@ void CGOpenMPRuntime::emitForStaticFinish(CodeGenFunction 
&CGF,
   auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc);
   if (isOpenMPDistributeDirective(DKind) &&
   CGM.getLangOpts().OpenMPIsTargetDevice &&
-  (CGM.getTriple().isAMDGCN() || CGM.getTriple().isNVPTX()))
+  CGM.getLangOpts().isOffloadingTarget())
 CGF.EmitRuntimeCall(
 OMPBuilder.getOrCreateRuntimeFunction(
 CGM.getModule(), OMPRTL___kmpc_distribute_static_fini),
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index bca0a932b3495..9080b226a7b8b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -843,7 +843,7 @@ static void setVisibilityFromDLLStorageClass(const 
clang::LangOptions &LO,
 static bool isStackProtectorOn(const LangOptions &LangOpts,
const llvm::Triple &Triple,
clang::LangOptions::StackProtectorMode Mode) {
-  if (Triple.isAMDGPU() || Triple.isNVPTX())
+  if (LangOpts.isOffloadingTarget())
 return false;
   return LangOpts.getStackProtector() == Mode;
 }
diff --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index a72b4f7338767..3448c0ed06335 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1078,8 +1078,7 @@ class CodeGenModule : public CodeGenTypeCache {
   bool shouldEmitRTTI(bool ForEH = false) {
 return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
!(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
- (getTriple().isNVPTX() || getTriple().isAMDGPU() ||
-  getTriple().isSPIRV()));
+ getLangOpts().isOffloadingTarget());
   }
 
   /// Get the address of the RTTI descriptor for the given type.
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 4eb743acf327f..33d26ee7f9f7d 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4357,6 +4357,10 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   Opts.OpenACCMacroOverride = A->getValue();
   }
 
+  Opts.IsOffloadingTarget =
+  (Opts.OpenMPIsTargetDevice || Opts.SYCLIsDevice || Opts.CUDAIsDevice) &&
+  (T.isNVPTX() || T.isAMDGCN() || T.isSPIROrSPIRV());
+
   // FIXME: Eliminate this dependency.
   unsigned Opt = getOptimizationLevel(Args, IK, Diags),
OptSize = getOptimizationLevelSize(Args);
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 11943c0b53591..0f115a6f04509 100644
--- a/c

[libclc] [libclc] Add missing license headers to source IR files (PR #132758)

2025-03-24 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/132758

None

>From 8e2c04878b87a7da3929836df2d20c4c4c701312 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Mon, 24 Mar 2025 15:28:20 +
Subject: [PATCH] [libclc] Add missing license headers to source IR files

---
 .../lib/cl_khr_int64_extended_atomics/minmax_helpers.ll   | 8 
 libclc/amdgpu/lib/shared/vload_half_helpers.ll| 8 
 libclc/amdgpu/lib/shared/vstore_half_helpers.ll   | 8 
 libclc/generic/lib/subnormal_disable.ll   | 8 
 libclc/generic/lib/subnormal_helper_func.ll   | 8 
 libclc/generic/lib/subnormal_use_default.ll   | 8 
 libclc/ptx/lib/shared/vload_half_helpers.ll   | 8 
 libclc/ptx/lib/shared/vstore_half_helpers.ll  | 8 
 libclc/r600/lib/image/get_image_attributes_impl.ll| 8 
 libclc/r600/lib/image/read_image_impl.ll  | 8 
 libclc/r600/lib/image/write_image_impl.ll | 8 
 11 files changed, 88 insertions(+)

diff --git a/libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll 
b/libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll
index 7f12556c0abbc..3ed5e99be3149 100644
--- a/libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll
+++ b/libclc/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll
@@ -1,3 +1,11 @@
+;;===--===;;
+;
+; 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
+;
+;;===--===;;
+
 define i64 @__clc__sync_fetch_and_min_global_8(i64 addrspace(1)* nocapture 
%ptr, i64 %value) nounwind alwaysinline {
 entry:
   %0 = atomicrmw volatile min i64 addrspace(1)* %ptr, i64 %value seq_cst
diff --git a/libclc/amdgpu/lib/shared/vload_half_helpers.ll 
b/libclc/amdgpu/lib/shared/vload_half_helpers.ll
index b8c905af6fc82..bf7d544afbf55 100644
--- a/libclc/amdgpu/lib/shared/vload_half_helpers.ll
+++ b/libclc/amdgpu/lib/shared/vload_half_helpers.ll
@@ -1,3 +1,11 @@
+;;===--===;;
+;
+; 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
+;
+;;===--===;;
+
 define float @__clc_vload_half_float_helper__private(half addrspace(0)* 
nocapture %ptr) nounwind alwaysinline {
   %data = load half, half addrspace(0)* %ptr
   %res = fpext half %data to float
diff --git a/libclc/amdgpu/lib/shared/vstore_half_helpers.ll 
b/libclc/amdgpu/lib/shared/vstore_half_helpers.ll
index e958664e56016..5ec193d6d40a0 100644
--- a/libclc/amdgpu/lib/shared/vstore_half_helpers.ll
+++ b/libclc/amdgpu/lib/shared/vstore_half_helpers.ll
@@ -1,3 +1,11 @@
+;;===--===;;
+;
+; 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
+;
+;;===--===;;
+
 define void @__clc_vstore_half_float_helper__private(float %data, half 
addrspace(0)* nocapture %ptr) nounwind alwaysinline {
   %res = fptrunc float %data to half
   store half %res, half addrspace(0)* %ptr
diff --git a/libclc/generic/lib/subnormal_disable.ll 
b/libclc/generic/lib/subnormal_disable.ll
index b935583b5ade0..732d09ff09ab4 100644
--- a/libclc/generic/lib/subnormal_disable.ll
+++ b/libclc/generic/lib/subnormal_disable.ll
@@ -1 +1,9 @@
+;;===--===;;
+;
+; 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
+;
+;;===--===;;
+
 @__CLC_SUBNORMAL_DISABLE = unnamed_addr constant i1 true
diff --git a/libclc/generic/lib/subnormal_helper_func.ll 
b/libclc/generic/lib/subnormal_helper_func.ll
index fb1b5d2b679fe..03beecf979260 100644
--- a/libclc/generic/lib/subnormal_helper_func.ll
+++ b/libclc/generic/lib/subnormal_helper_func.ll
@@ -1,3 +1,11 @@
+;;===--===;;
+;
+; 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
+;
+;;===

[clang] [HLSL][NFC] Refactor HLSLExternalSemaSource (PR #131032)

2025-03-24 Thread Joshua Batista via cfe-commits

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


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


[clang] [HLSL][NFC] Refactor HLSLExternalSemaSource (PR #131032)

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

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


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


[clang] [PATCH] [clang][modules] Fix serialization and de-serialization of PCH module file refs (#105994) (PR #132802)

2025-03-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Paul Schwabauer (koplas)


Changes

The File ID is incorrectly calculated, resulting in an out-of-bounds access. 
The test code is more complex because the File fetching only happens in 
specific scenarios.

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


2 Files Affected:

- (modified) clang/lib/Serialization/ASTReader.cpp (+2-2) 
- (added) clang/test/Modules/MixedModulePrecompile.cpp (+49) 


``diff
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 2728e93c69516..7540ff5a3a95c 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -9615,7 +9615,7 @@ ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &M, 
unsigned ID) const {
 // It's a prefix (preamble, PCH, ...). Look it up by index.
 unsigned IndexFromEnd = ID >> 1;
 assert(IndexFromEnd && "got reference to unknown module file");
-return getModuleManager().pch_modules().end()[-IndexFromEnd];
+return 
getModuleManager().pch_modules().end()[-static_cast(IndexFromEnd)];
   }
 }
 
@@ -9633,7 +9633,7 @@ unsigned ASTReader::getModuleFileID(ModuleFile *M) {
   auto PCHModules = getModuleManager().pch_modules();
   auto I = llvm::find(PCHModules, M);
   assert(I != PCHModules.end() && "emitting reference to unknown file");
-  return (I - PCHModules.end()) << 1;
+  return std::distance(I, PCHModules.end()) << 1;
 }
 
 std::optional ASTReader::getSourceDescriptor(unsigned ID) 
{
diff --git a/clang/test/Modules/MixedModulePrecompile.cpp 
b/clang/test/Modules/MixedModulePrecompile.cpp
new file mode 100644
index 0..a800498cd2670
--- /dev/null
+++ b/clang/test/Modules/MixedModulePrecompile.cpp
@@ -0,0 +1,49 @@
+// Tests mixed usage of precompiled headers and modules.
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -x c++-header -emit-pch %t/a.hpp \
+// RUN: -o %t/a.pch
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part1.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Part1.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part2.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Part2.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part3.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Part3.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part4.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Part4.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -fprebuilt-module-path=%t 
-fprebuilt-implicit-modules %t/Mod.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Mod.pcm
+
+
+//--- a.hpp
+#pragma once
+
+class a {
+  virtual ~a();
+  a() {}
+};
+
+//--- Part1.cppm
+export module mod:part1;
+
+//--- Part2.cppm
+export module mod:part2;
+
+//--- Part3.cppm
+export module mod:part3;
+
+//--- Part4.cppm
+export module mod:part4;
+
+//--- Mod.cppm
+export module mod;
+export import :part1;
+export import :part2;
+export import :part3;
+export import :part4;
+

``




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


[clang] [flang] [flang] Add -f[no-]slp-vectorize flags (PR #132801)

2025-03-24 Thread Kajetan Puchalski via cfe-commits

mrkajetanp wrote:

cc @tblah @DavidTruby 

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


[clang] [flang] [flang] Add -f[no-]slp-vectorize flags (PR #132801)

2025-03-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Kajetan Puchalski (mrkajetanp)


Changes

Add -f[no-]slp-vectorize to the flang driver.
Add corresponding -fvectorize-slp to the flang frontend.

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


6 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+6-3) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+8) 
- (modified) flang/include/flang/Frontend/CodeGenOptions.def (+1) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+3) 
- (modified) flang/lib/Frontend/FrontendActions.cpp (+1) 
- (added) flang/test/Driver/slp-vectorize.f90 (+10) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 59a57c83c6b89..a2cdf9f26fcdf 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4032,11 +4032,14 @@ def : Flag<["-"], "ftree-vectorize">, Alias;
 def : Flag<["-"], "fno-tree-vectorize">, Alias;
 }
 
+let Visibility = [ClangOption, FlangOption] in {
 def fslp_vectorize : Flag<["-"], "fslp-vectorize">, Group,
   HelpText<"Enable the superword-level parallelism vectorization passes">;
 def fno_slp_vectorize : Flag<["-"], "fno-slp-vectorize">, Group;
 def : Flag<["-"], "ftree-slp-vectorize">, Alias;
 def : Flag<["-"], "fno-tree-slp-vectorize">, Alias;
+}
+
 def Wlarge_by_value_copy_def : Flag<["-"], "Wlarge-by-value-copy">,
   HelpText<"Warn if a function definition returns or accepts an object larger "
"in bytes than a given value">, Flags<[HelpHidden]>;
@@ -7384,6 +7387,9 @@ def mlink_bitcode_file
 def vectorize_loops : Flag<["-"], "vectorize-loops">,
   HelpText<"Run the Loop vectorization passes">,
   MarshallingInfoFlag>;
+def vectorize_slp : Flag<["-"], "vectorize-slp">,
+  HelpText<"Run the SLP vectorization passes">,
+  MarshallingInfoFlag>;
 } // let Visibility = [CC1Option, FC1Option]
 
 let Visibility = [CC1Option] in {
@@ -7499,9 +7505,6 @@ defm link_builtin_bitcode_postopt: 
BoolMOption<"link-builtin-bitcode-postopt",
   PosFlag,
   NegFlag>;
-def vectorize_slp : Flag<["-"], "vectorize-slp">,
-  HelpText<"Run the SLP vectorization passes">,
-  MarshallingInfoFlag>;
 def linker_option : Joined<["--"], "linker-option=">,
   HelpText<"Add linker option">,
   MarshallingInfoStringVector>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 5dbc5cbe77d0a..bb89432d3e58c 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -161,6 +161,14 @@ void Flang::addCodegenOptions(const ArgList &Args,
options::OPT_fno_vectorize, enableVec))
 CmdArgs.push_back("-vectorize-loops");
 
+  // -fslp-vectorize is enabled based on the optimization level selected.
+  bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true);
+  OptSpecifier SLPVectAliasOption =
+  EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize;
+  if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption,
+   options::OPT_fno_slp_vectorize, EnableSLPVec))
+CmdArgs.push_back("-vectorize-slp");
+
   if (shouldLoopVersion(Args))
 CmdArgs.push_back("-fversion-loops-for-stride");
 
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 44cb5a2cdd497..5d6af4271d4f6 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -32,6 +32,7 @@ CODEGENOPT(PrepareForThinLTO , 1, 0) ///< Set when -flto=thin 
is enabled on the
  ///< compile step.
 CODEGENOPT(StackArrays, 1, 0) ///< -fstack-arrays (enable the stack-arrays 
pass)
 CODEGENOPT(VectorizeLoop, 1, 0) ///< Enable loop vectorization.
+CODEGENOPT(VectorizeSLP, 1, 0) ///< Enable SLP vectorization.
 CODEGENOPT(LoopVersioning, 1, 0) ///< Enable loop versioning.
 CODEGENOPT(UnrollLoops, 1, 0) ///< Enable loop unrolling
 CODEGENOPT(AliasAnalysis, 1, 0) ///< Enable alias analysis pass
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index f433ec9966922..652b3d8795ab7 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -246,6 +246,9 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
   if (args.getLastArg(clang::driver::options::OPT_vectorize_loops))
 opts.VectorizeLoop = 1;
 
+  if (args.getLastArg(clang::driver::options::OPT_vectorize_slp))
+opts.VectorizeSLP = 1;
+
   if (args.hasFlag(clang::driver::options::OPT_floop_versioning,
clang::driver::options::OPT_fno_loop_versioning, false))
 opts.LoopVersioning = 1;
diff --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index 46ec7550e4140..3e6e98855fe7a 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendAc

[clang] [flang] [flang] Add -f[no-]slp-vectorize flags (PR #132801)

2025-03-24 Thread Kajetan Puchalski via cfe-commits

https://github.com/mrkajetanp created 
https://github.com/llvm/llvm-project/pull/132801

Add -f[no-]slp-vectorize to the flang driver.
Add corresponding -fvectorize-slp to the flang frontend.

>From d9b2a86d01688b69b8f116f6b52caeec8cd6e756 Mon Sep 17 00:00:00 2001
From: Kajetan Puchalski 
Date: Mon, 24 Mar 2025 17:28:03 +
Subject: [PATCH] [flang] Add -f[no-]slp-vectorize flags

Add -f[no-]slp-vectorize to the flang driver.
Add corresponding -fvectorize-slp to the flang frontend.

Signed-off-by: Kajetan Puchalski 
---
 clang/include/clang/Driver/Options.td   |  9 ++---
 clang/lib/Driver/ToolChains/Flang.cpp   |  8 
 flang/include/flang/Frontend/CodeGenOptions.def |  1 +
 flang/lib/Frontend/CompilerInvocation.cpp   |  3 +++
 flang/lib/Frontend/FrontendActions.cpp  |  1 +
 flang/test/Driver/slp-vectorize.f90 | 10 ++
 6 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 flang/test/Driver/slp-vectorize.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 59a57c83c6b89..a2cdf9f26fcdf 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4032,11 +4032,14 @@ def : Flag<["-"], "ftree-vectorize">, Alias;
 def : Flag<["-"], "fno-tree-vectorize">, Alias;
 }
 
+let Visibility = [ClangOption, FlangOption] in {
 def fslp_vectorize : Flag<["-"], "fslp-vectorize">, Group,
   HelpText<"Enable the superword-level parallelism vectorization passes">;
 def fno_slp_vectorize : Flag<["-"], "fno-slp-vectorize">, Group;
 def : Flag<["-"], "ftree-slp-vectorize">, Alias;
 def : Flag<["-"], "fno-tree-slp-vectorize">, Alias;
+}
+
 def Wlarge_by_value_copy_def : Flag<["-"], "Wlarge-by-value-copy">,
   HelpText<"Warn if a function definition returns or accepts an object larger "
"in bytes than a given value">, Flags<[HelpHidden]>;
@@ -7384,6 +7387,9 @@ def mlink_bitcode_file
 def vectorize_loops : Flag<["-"], "vectorize-loops">,
   HelpText<"Run the Loop vectorization passes">,
   MarshallingInfoFlag>;
+def vectorize_slp : Flag<["-"], "vectorize-slp">,
+  HelpText<"Run the SLP vectorization passes">,
+  MarshallingInfoFlag>;
 } // let Visibility = [CC1Option, FC1Option]
 
 let Visibility = [CC1Option] in {
@@ -7499,9 +7505,6 @@ defm link_builtin_bitcode_postopt: 
BoolMOption<"link-builtin-bitcode-postopt",
   PosFlag,
   NegFlag>;
-def vectorize_slp : Flag<["-"], "vectorize-slp">,
-  HelpText<"Run the SLP vectorization passes">,
-  MarshallingInfoFlag>;
 def linker_option : Joined<["--"], "linker-option=">,
   HelpText<"Add linker option">,
   MarshallingInfoStringVector>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 5dbc5cbe77d0a..bb89432d3e58c 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -161,6 +161,14 @@ void Flang::addCodegenOptions(const ArgList &Args,
options::OPT_fno_vectorize, enableVec))
 CmdArgs.push_back("-vectorize-loops");
 
+  // -fslp-vectorize is enabled based on the optimization level selected.
+  bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true);
+  OptSpecifier SLPVectAliasOption =
+  EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize;
+  if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption,
+   options::OPT_fno_slp_vectorize, EnableSLPVec))
+CmdArgs.push_back("-vectorize-slp");
+
   if (shouldLoopVersion(Args))
 CmdArgs.push_back("-fversion-loops-for-stride");
 
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 44cb5a2cdd497..5d6af4271d4f6 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -32,6 +32,7 @@ CODEGENOPT(PrepareForThinLTO , 1, 0) ///< Set when -flto=thin 
is enabled on the
  ///< compile step.
 CODEGENOPT(StackArrays, 1, 0) ///< -fstack-arrays (enable the stack-arrays 
pass)
 CODEGENOPT(VectorizeLoop, 1, 0) ///< Enable loop vectorization.
+CODEGENOPT(VectorizeSLP, 1, 0) ///< Enable SLP vectorization.
 CODEGENOPT(LoopVersioning, 1, 0) ///< Enable loop versioning.
 CODEGENOPT(UnrollLoops, 1, 0) ///< Enable loop unrolling
 CODEGENOPT(AliasAnalysis, 1, 0) ///< Enable alias analysis pass
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index f433ec9966922..652b3d8795ab7 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -246,6 +246,9 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
   if (args.getLastArg(clang::driver::options::OPT_vectorize_loops))
 opts.VectorizeLoop = 1;
 
+  if (args.getLastArg(clang::driver::options::OPT_vectorize_slp))
+opts.VectorizeSLP = 1;
+
   if (args.hasFlag(clang::driver::options::OPT_floop_versioni

[clang] [PATCH] [clang][modules] Fix serialization and de-serialization of PCH module file refs (#105994) (PR #132802)

2025-03-24 Thread Paul Schwabauer via cfe-commits

https://github.com/koplas created 
https://github.com/llvm/llvm-project/pull/132802

The File ID is incorrectly calculated, resulting in an out-of-bounds access. 
The test code is more complex because the File fetching only happens in 
specific scenarios.

>From cad802f9c91f12b8db26bc63eef13097474d9165 Mon Sep 17 00:00:00 2001
From: koplas 
Date: Mon, 24 Mar 2025 19:20:52 +0100
Subject: [PATCH] [PATCH] [clang][modules] Fix serialization and
 de-serialization of PCH module file refs  (#105994)

Co-authored-by: ShaderKeeper 
---
 clang/lib/Serialization/ASTReader.cpp|  4 +-
 clang/test/Modules/MixedModulePrecompile.cpp | 49 
 2 files changed, 51 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Modules/MixedModulePrecompile.cpp

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 2728e93c69516..7540ff5a3a95c 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -9615,7 +9615,7 @@ ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &M, 
unsigned ID) const {
 // It's a prefix (preamble, PCH, ...). Look it up by index.
 unsigned IndexFromEnd = ID >> 1;
 assert(IndexFromEnd && "got reference to unknown module file");
-return getModuleManager().pch_modules().end()[-IndexFromEnd];
+return 
getModuleManager().pch_modules().end()[-static_cast(IndexFromEnd)];
   }
 }
 
@@ -9633,7 +9633,7 @@ unsigned ASTReader::getModuleFileID(ModuleFile *M) {
   auto PCHModules = getModuleManager().pch_modules();
   auto I = llvm::find(PCHModules, M);
   assert(I != PCHModules.end() && "emitting reference to unknown file");
-  return (I - PCHModules.end()) << 1;
+  return std::distance(I, PCHModules.end()) << 1;
 }
 
 std::optional ASTReader::getSourceDescriptor(unsigned ID) 
{
diff --git a/clang/test/Modules/MixedModulePrecompile.cpp 
b/clang/test/Modules/MixedModulePrecompile.cpp
new file mode 100644
index 0..a800498cd2670
--- /dev/null
+++ b/clang/test/Modules/MixedModulePrecompile.cpp
@@ -0,0 +1,49 @@
+// Tests mixed usage of precompiled headers and modules.
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -x c++-header -emit-pch %t/a.hpp \
+// RUN: -o %t/a.pch
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part1.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Part1.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part2.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Part2.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part3.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Part3.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part4.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Part4.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -fprebuilt-module-path=%t 
-fprebuilt-implicit-modules %t/Mod.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Mod.pcm
+
+
+//--- a.hpp
+#pragma once
+
+class a {
+  virtual ~a();
+  a() {}
+};
+
+//--- Part1.cppm
+export module mod:part1;
+
+//--- Part2.cppm
+export module mod:part2;
+
+//--- Part3.cppm
+export module mod:part3;
+
+//--- Part4.cppm
+export module mod:part4;
+
+//--- Mod.cppm
+export module mod;
+export import :part1;
+export import :part2;
+export import :part3;
+export import :part4;
+

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


[clang] [PATCH] [clang][modules] Fix serialization and de-serialization of PCH module file refs (#105994) (PR #132802)

2025-03-24 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


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

2025-03-24 Thread Mészáros Gergely via cfe-commits


@@ -0,0 +1,534 @@
+#!/usr/bin/env python3
+
+"""generate_unsupported_in_drivermode.py
+
+This script generates Lit regression test files that validate that options are 
only exposed to intended driver modes.
+
+The options and driver modes are parsed from Options.td, whose path should be 
provided on the command line.
+See clang/include/clang/Driver/Options.td
+
+The LLVM TableGen executable can optionally be provided along with the path to 
the LLVM build tree bin directory.
+Otherwise, the script will search for it.
+
+The primary maintenance task for this script would be updating the expected 
return message for a driver mode if
+there are changes over time. See the instantiations of DriverData, 
specifically the check_str.
+
+Logic:
+1) For each option, (records of class "Option"), and for each driver, (records 
of class "OptionVisibility")
+a. if the option's "Visibility" field includes the driver flavour, skip 
processing this option for this driver
+b. if the option is part of an option group, (the record has the "Group" 
property),
+   and the group's "Visibility" field includes the driver flavour, skip 
processing this option for this driver
+c. otherwise this option is not supported by this driver flavour, and this 
pairing is saved for testing
+2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to 
parse for expected output. Ex: "error: unknown argument"
+"""
+
+import os
+import json
+import subprocess
+from bisect import bisect_left
+from dataclasses import dataclass
+import argparse
+import dataclasses
+import itertools
+
+# Strings defined in Options.td for the various driver flavours. See 
"OptionVisibility"
+VISIBILITY_CC1AS = "CC1AsOption"
+VISIBILITY_CC1 = "CC1Option"
+VISIBILITY_CL = "CLOption"
+VISIBILITY_DXC = "DXCOption"
+VISIBILITY_DEFAULT = "DefaultVis"
+VISIBILITY_FC1 = "FC1Option"
+VISIBILITY_FLANG = "FlangOption"
+
+# Lit test prefix strings
+SLASH_SLASH = "// "
+EXCLAMATION = "! "
+
+exceptions_sequence = [
+# Invalid usage of the driver options below causes unique output, so skip 
testing
+"cc1",
+"cc1as",
+# There is currently a bug with "_no_warnings", i.e. --no-warnings. 
Diagnostic related options
+# are parsed first, and always with CC1 visibility. They're used to set up 
the diagnostic
+# engine, which parses "_no_warnings" (and its alias "w", i.e. -w) and 
sets an internal flag
+# that suppresses all warnings.
+"_no_warnings",
+"w",
+]
+
+
+@dataclass
+class DriverOption:
+"""Defines an unsupported driver-option combination
+driver: The driver string as defined by OptionVisibility in Options.td
+option: The option object from Options.td
+option_name: Corresponding string for an option. See "Name" for a given 
option in Options.td
+prefix: String that precedes the option. Ex. "-"
+"""
+
+driver: str
+option: str
+option_name: str
+prefix: str
+
+
+@dataclass
+class DriverData:
+"""Dataclass for data specific to each driver
+lit_cmd_prefix: The beginning string of the Lit command
+lit_cmd_options: Strings containing additional options for this driver
+visibility_str: The corresponding visibility string from OptionVisibility 
in Options.td
+lit_cmd_end: String at the end of the Lit command
+check_str: The string or regex to be sent to FileCheck
+supported_joined_option_sequence: List of DriverOption objects for 
supported options
+  that are Kind *JOINED*, as defined in 
Options.td
+supported_non_joined_option_sequence: List of DriverOption objects for 
supported options
+  that are not Kind *JOINED*, as 
defined in Options.td
+test_option_sequence: A list of all the prefix-option pairs that will be 
tested for this driver
+"""
+
+lit_cmd_prefix: str
+lit_cmd_options: str
+visibility_str: str
+lit_cmd_end: str
+check_str: str
+supported_joined_option_sequence: list[DriverOption] = dataclasses.field(
+default_factory=list
+)
+supported_non_joined_option_sequence: list[DriverOption] = 
dataclasses.field(
+default_factory=list
+)
+test_option_sequence: list[str] = dataclasses.field(default_factory=list)
+
+
+def collect_transitive_groups(member, options_dictionary):
+"""Find the groups for a given member, where a member can be an option or 
a group.
+Note that groups can themselves be part of groups, hence the recursion
+
+For example, considering option 'C', it has the following 'Group' field as 
defined by Options.td:
+  "C": {
+"Group": {
+  "def": "Preprocessor_Group",
+  // ...
+},
+// ...
+  },
+'Preprocessor_Group' is itself part of 'CompileOnly_Group', so option 'C' 
would be part of both groups
+  "Preprocessor_Group": {
+// ...
+"Group": {
+  "def": "CompileOnly_Group",
+

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

2025-03-24 Thread Mészáros Gergely via cfe-commits


@@ -0,0 +1,534 @@
+#!/usr/bin/env python3
+
+"""generate_unsupported_in_drivermode.py
+
+This script generates Lit regression test files that validate that options are 
only exposed to intended driver modes.
+
+The options and driver modes are parsed from Options.td, whose path should be 
provided on the command line.
+See clang/include/clang/Driver/Options.td
+
+The LLVM TableGen executable can optionally be provided along with the path to 
the LLVM build tree bin directory.
+Otherwise, the script will search for it.
+
+The primary maintenance task for this script would be updating the expected 
return message for a driver mode if
+there are changes over time. See the instantiations of DriverData, 
specifically the check_str.
+
+Logic:
+1) For each option, (records of class "Option"), and for each driver, (records 
of class "OptionVisibility")
+a. if the option's "Visibility" field includes the driver flavour, skip 
processing this option for this driver
+b. if the option is part of an option group, (the record has the "Group" 
property),
+   and the group's "Visibility" field includes the driver flavour, skip 
processing this option for this driver
+c. otherwise this option is not supported by this driver flavour, and this 
pairing is saved for testing
+2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to 
parse for expected output. Ex: "error: unknown argument"
+"""
+
+import os
+import json
+import subprocess
+from bisect import bisect_left
+from dataclasses import dataclass
+import argparse
+import dataclasses
+import itertools
+
+# Strings defined in Options.td for the various driver flavours. See 
"OptionVisibility"
+VISIBILITY_CC1AS = "CC1AsOption"
+VISIBILITY_CC1 = "CC1Option"
+VISIBILITY_CL = "CLOption"
+VISIBILITY_DXC = "DXCOption"
+VISIBILITY_DEFAULT = "DefaultVis"
+VISIBILITY_FC1 = "FC1Option"
+VISIBILITY_FLANG = "FlangOption"
+
+# Lit test prefix strings
+SLASH_SLASH = "// "
+EXCLAMATION = "! "
+
+exceptions_sequence = [
+# Invalid usage of the driver options below causes unique output, so skip 
testing
+"cc1",
+"cc1as",
+# There is currently a bug with "_no_warnings", i.e. --no-warnings. 
Diagnostic related options
+# are parsed first, and always with CC1 visibility. They're used to set up 
the diagnostic
+# engine, which parses "_no_warnings" (and its alias "w", i.e. -w) and 
sets an internal flag
+# that suppresses all warnings.
+"_no_warnings",
+"w",
+]
+
+
+@dataclass
+class DriverOption:
+"""Defines an unsupported driver-option combination
+driver: The driver string as defined by OptionVisibility in Options.td
+option: The option object from Options.td
+option_name: Corresponding string for an option. See "Name" for a given 
option in Options.td
+prefix: String that precedes the option. Ex. "-"
+"""
+
+driver: str
+option: str
+option_name: str
+prefix: str
+
+
+@dataclass
+class DriverData:
+"""Dataclass for data specific to each driver
+lit_cmd_prefix: The beginning string of the Lit command
+lit_cmd_options: Strings containing additional options for this driver
+visibility_str: The corresponding visibility string from OptionVisibility 
in Options.td
+lit_cmd_end: String at the end of the Lit command
+check_str: The string or regex to be sent to FileCheck
+supported_joined_option_sequence: List of DriverOption objects for 
supported options
+  that are Kind *JOINED*, as defined in 
Options.td
+supported_non_joined_option_sequence: List of DriverOption objects for 
supported options
+  that are not Kind *JOINED*, as 
defined in Options.td
+test_option_sequence: A list of all the prefix-option pairs that will be 
tested for this driver
+"""
+
+lit_cmd_prefix: str
+lit_cmd_options: str
+visibility_str: str
+lit_cmd_end: str
+check_str: str
+supported_joined_option_sequence: list[DriverOption] = dataclasses.field(
+default_factory=list
+)
+supported_non_joined_option_sequence: list[DriverOption] = 
dataclasses.field(
+default_factory=list
+)
+test_option_sequence: list[str] = dataclasses.field(default_factory=list)
+
+
+def collect_transitive_groups(member, options_dictionary):
+"""Find the groups for a given member, where a member can be an option or 
a group.
+Note that groups can themselves be part of groups, hence the recursion
+
+For example, considering option 'C', it has the following 'Group' field as 
defined by Options.td:
+  "C": {
+"Group": {
+  "def": "Preprocessor_Group",
+  // ...
+},
+// ...
+  },
+'Preprocessor_Group' is itself part of 'CompileOnly_Group', so option 'C' 
would be part of both groups
+  "Preprocessor_Group": {
+// ...
+"Group": {
+  "def": "CompileOnly_Group",
+

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

2025-03-24 Thread Mészáros Gergely via cfe-commits


@@ -0,0 +1,534 @@
+#!/usr/bin/env python3
+
+"""generate_unsupported_in_drivermode.py
+
+This script generates Lit regression test files that validate that options are 
only exposed to intended driver modes.
+
+The options and driver modes are parsed from Options.td, whose path should be 
provided on the command line.
+See clang/include/clang/Driver/Options.td
+
+The LLVM TableGen executable can optionally be provided along with the path to 
the LLVM build tree bin directory.
+Otherwise, the script will search for it.
+
+The primary maintenance task for this script would be updating the expected 
return message for a driver mode if
+there are changes over time. See the instantiations of DriverData, 
specifically the check_str.
+
+Logic:
+1) For each option, (records of class "Option"), and for each driver, (records 
of class "OptionVisibility")
+a. if the option's "Visibility" field includes the driver flavour, skip 
processing this option for this driver
+b. if the option is part of an option group, (the record has the "Group" 
property),
+   and the group's "Visibility" field includes the driver flavour, skip 
processing this option for this driver
+c. otherwise this option is not supported by this driver flavour, and this 
pairing is saved for testing
+2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to 
parse for expected output. Ex: "error: unknown argument"
+"""
+
+import os
+import json
+import subprocess
+from bisect import bisect_left
+from dataclasses import dataclass
+import argparse
+import dataclasses
+import itertools
+
+# Strings defined in Options.td for the various driver flavours. See 
"OptionVisibility"
+VISIBILITY_CC1AS = "CC1AsOption"
+VISIBILITY_CC1 = "CC1Option"
+VISIBILITY_CL = "CLOption"
+VISIBILITY_DXC = "DXCOption"
+VISIBILITY_DEFAULT = "DefaultVis"
+VISIBILITY_FC1 = "FC1Option"
+VISIBILITY_FLANG = "FlangOption"
+
+# Lit test prefix strings
+SLASH_SLASH = "// "
+EXCLAMATION = "! "
+
+exceptions_sequence = [
+# Invalid usage of the driver options below causes unique output, so skip 
testing
+"cc1",
+"cc1as",
+# There is currently a bug with "_no_warnings", i.e. --no-warnings. 
Diagnostic related options
+# are parsed first, and always with CC1 visibility. They're used to set up 
the diagnostic
+# engine, which parses "_no_warnings" (and its alias "w", i.e. -w) and 
sets an internal flag
+# that suppresses all warnings.
+"_no_warnings",
+"w",
+]
+
+
+@dataclass
+class DriverOption:
+"""Defines an unsupported driver-option combination
+driver: The driver string as defined by OptionVisibility in Options.td
+option: The option object from Options.td
+option_name: Corresponding string for an option. See "Name" for a given 
option in Options.td
+prefix: String that precedes the option. Ex. "-"
+"""
+
+driver: str
+option: str
+option_name: str
+prefix: str
+
+
+@dataclass
+class DriverData:
+"""Dataclass for data specific to each driver
+lit_cmd_prefix: The beginning string of the Lit command
+lit_cmd_options: Strings containing additional options for this driver
+visibility_str: The corresponding visibility string from OptionVisibility 
in Options.td
+lit_cmd_end: String at the end of the Lit command
+check_str: The string or regex to be sent to FileCheck
+supported_joined_option_sequence: List of DriverOption objects for 
supported options
+  that are Kind *JOINED*, as defined in 
Options.td
+supported_non_joined_option_sequence: List of DriverOption objects for 
supported options
+  that are not Kind *JOINED*, as 
defined in Options.td
+test_option_sequence: A list of all the prefix-option pairs that will be 
tested for this driver
+"""
+
+lit_cmd_prefix: str
+lit_cmd_options: str
+visibility_str: str
+lit_cmd_end: str
+check_str: str
+supported_joined_option_sequence: list[DriverOption] = dataclasses.field(
+default_factory=list
+)
+supported_non_joined_option_sequence: list[DriverOption] = 
dataclasses.field(
+default_factory=list
+)
+test_option_sequence: list[str] = dataclasses.field(default_factory=list)
+
+
+def collect_transitive_groups(member, options_dictionary):
+"""Find the groups for a given member, where a member can be an option or 
a group.
+Note that groups can themselves be part of groups, hence the recursion
+
+For example, considering option 'C', it has the following 'Group' field as 
defined by Options.td:
+  "C": {
+"Group": {
+  "def": "Preprocessor_Group",
+  // ...
+},
+// ...
+  },
+'Preprocessor_Group' is itself part of 'CompileOnly_Group', so option 'C' 
would be part of both groups
+  "Preprocessor_Group": {
+// ...
+"Group": {
+  "def": "CompileOnly_Group",
+

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

2025-03-24 Thread Mészáros Gergely via cfe-commits


@@ -0,0 +1,534 @@
+#!/usr/bin/env python3
+
+"""generate_unsupported_in_drivermode.py
+
+This script generates Lit regression test files that validate that options are 
only exposed to intended driver modes.
+
+The options and driver modes are parsed from Options.td, whose path should be 
provided on the command line.
+See clang/include/clang/Driver/Options.td
+
+The LLVM TableGen executable can optionally be provided along with the path to 
the LLVM build tree bin directory.
+Otherwise, the script will search for it.
+
+The primary maintenance task for this script would be updating the expected 
return message for a driver mode if
+there are changes over time. See the instantiations of DriverData, 
specifically the check_str.
+
+Logic:
+1) For each option, (records of class "Option"), and for each driver, (records 
of class "OptionVisibility")
+a. if the option's "Visibility" field includes the driver flavour, skip 
processing this option for this driver
+b. if the option is part of an option group, (the record has the "Group" 
property),
+   and the group's "Visibility" field includes the driver flavour, skip 
processing this option for this driver
+c. otherwise this option is not supported by this driver flavour, and this 
pairing is saved for testing
+2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to 
parse for expected output. Ex: "error: unknown argument"
+"""
+
+import os
+import json
+import subprocess
+from bisect import bisect_left
+from dataclasses import dataclass
+import argparse
+import dataclasses
+import itertools
+
+# Strings defined in Options.td for the various driver flavours. See 
"OptionVisibility"
+VISIBILITY_CC1AS = "CC1AsOption"
+VISIBILITY_CC1 = "CC1Option"
+VISIBILITY_CL = "CLOption"
+VISIBILITY_DXC = "DXCOption"
+VISIBILITY_DEFAULT = "DefaultVis"
+VISIBILITY_FC1 = "FC1Option"
+VISIBILITY_FLANG = "FlangOption"
+
+# Lit test prefix strings
+SLASH_SLASH = "// "
+EXCLAMATION = "! "
+
+exceptions_sequence = [
+# Invalid usage of the driver options below causes unique output, so skip 
testing
+"cc1",
+"cc1as",
+# There is currently a bug with "_no_warnings", i.e. --no-warnings. 
Diagnostic related options
+# are parsed first, and always with CC1 visibility. They're used to set up 
the diagnostic
+# engine, which parses "_no_warnings" (and its alias "w", i.e. -w) and 
sets an internal flag
+# that suppresses all warnings.
+"_no_warnings",
+"w",
+]
+
+
+@dataclass
+class DriverOption:
+"""Defines an unsupported driver-option combination
+driver: The driver string as defined by OptionVisibility in Options.td
+option: The option object from Options.td
+option_name: Corresponding string for an option. See "Name" for a given 
option in Options.td
+prefix: String that precedes the option. Ex. "-"
+"""
+
+driver: str
+option: str
+option_name: str
+prefix: str
+
+
+@dataclass
+class DriverData:
+"""Dataclass for data specific to each driver
+lit_cmd_prefix: The beginning string of the Lit command
+lit_cmd_options: Strings containing additional options for this driver
+visibility_str: The corresponding visibility string from OptionVisibility 
in Options.td
+lit_cmd_end: String at the end of the Lit command
+check_str: The string or regex to be sent to FileCheck
+supported_joined_option_sequence: List of DriverOption objects for 
supported options
+  that are Kind *JOINED*, as defined in 
Options.td
+supported_non_joined_option_sequence: List of DriverOption objects for 
supported options
+  that are not Kind *JOINED*, as 
defined in Options.td
+test_option_sequence: A list of all the prefix-option pairs that will be 
tested for this driver
+"""
+
+lit_cmd_prefix: str
+lit_cmd_options: str
+visibility_str: str
+lit_cmd_end: str
+check_str: str
+supported_joined_option_sequence: list[DriverOption] = dataclasses.field(
+default_factory=list
+)
+supported_non_joined_option_sequence: list[DriverOption] = 
dataclasses.field(
+default_factory=list
+)
+test_option_sequence: list[str] = dataclasses.field(default_factory=list)
+
+
+def collect_transitive_groups(member, options_dictionary):
+"""Find the groups for a given member, where a member can be an option or 
a group.
+Note that groups can themselves be part of groups, hence the recursion
+
+For example, considering option 'C', it has the following 'Group' field as 
defined by Options.td:
+  "C": {
+"Group": {
+  "def": "Preprocessor_Group",
+  // ...
+},
+// ...
+  },
+'Preprocessor_Group' is itself part of 'CompileOnly_Group', so option 'C' 
would be part of both groups
+  "Preprocessor_Group": {
+// ...
+"Group": {
+  "def": "CompileOnly_Group",
+

[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-24 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt commented:



> *[Reviewable](https://reviewable.io/reviews/llvm/llvm-project/113510)* 
> status: 0 of 54 files reviewed, 119 unresolved discussions (waiting on 
> @AaronBallman, @Bigcheese, @ChuanqiXu9, @cor3ntin, @efriedma-quic, 
> @erichkeane, @mizvekov, @ogiroux, @Sirraide, @zmodem, and @zyn0217)






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


[clang] [clang] Upstream Mach-O ptrauth driver defaults (PR #132834)

2025-03-24 Thread Nico Weber via cfe-commits

https://github.com/nico updated https://github.com/llvm/llvm-project/pull/132834

>From ec8faf518af6384203c776fdd9928ef06e9b5be7 Mon Sep 17 00:00:00 2001
From: Nico Weber 
Date: Mon, 24 Mar 2025 15:56:49 -0400
Subject: [PATCH 1/2] [clang] Upstream Mach-O ptrauth driver defaults

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 41 
 clang/lib/Driver/ToolChains/Darwin.h   |  8 
 clang/test/Driver/arch-arm64e.c| 66 ++
 3 files changed, 115 insertions(+)
 create mode 100644 clang/test/Driver/arch-arm64e.c

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index e67997314da36..5ac105d82ef6d 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1201,6 +1201,13 @@ void DarwinClang::addClangWarningOptions(ArgStringList 
&CC1Args) const {
   }
 }
 
+void DarwinClang::addClangTargetOptions(
+  const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
+  Action::OffloadKind DeviceOffloadKind) const {
+
+  Darwin::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
+}
+
 /// Take a path that speculatively points into Xcode and return the
 /// `XCODE/Contents/Developer` path if it is an Xcode path, or an empty path
 /// otherwise.
@@ -3060,9 +3067,43 @@ bool Darwin::isSizedDeallocationUnavailable() const {
   return TargetVersion < sizedDeallocMinVersion(OS);
 }
 
+void MachO::addClangTargetOptions(
+const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const {
+
+  ToolChain::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
+
+  // On arm64e, enable pointer authentication (for the return address and
+  // indirect calls), as well as usage of the intrinsics.
+  if (getArchName() == "arm64e") {
+if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
+   options::OPT_fno_ptrauth_returns))
+  CC1Args.push_back("-fptrauth-returns");
+
+if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
+   options::OPT_fno_ptrauth_intrinsics))
+  CC1Args.push_back("-fptrauth-intrinsics");
+
+if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
+   options::OPT_fno_ptrauth_calls))
+  CC1Args.push_back("-fptrauth-calls");
+
+if (!DriverArgs.hasArg(options::OPT_fptrauth_indirect_gotos,
+   options::OPT_fno_ptrauth_indirect_gotos))
+  CC1Args.push_back("-fptrauth-indirect-gotos");
+
+if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
+   options::OPT_fno_ptrauth_auth_traps))
+  CC1Args.push_back("-fptrauth-auth-traps");
+  }
+}
+
 void Darwin::addClangTargetOptions(
 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
 Action::OffloadKind DeviceOffloadKind) const {
+
+  MachO::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
+
   // Pass "-faligned-alloc-unavailable" only when the user hasn't manually
   // enabled or disabled aligned allocations.
   if (!DriverArgs.hasArgNoClaim(options::OPT_faligned_allocation,
diff --git a/clang/lib/Driver/ToolChains/Darwin.h 
b/clang/lib/Driver/ToolChains/Darwin.h
index c44780c577f4f..41aa07c188868 100644
--- a/clang/lib/Driver/ToolChains/Darwin.h
+++ b/clang/lib/Driver/ToolChains/Darwin.h
@@ -145,6 +145,10 @@ class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
   Tool *buildStaticLibTool() const override;
   Tool *getTool(Action::ActionClass AC) const override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ Action::OffloadKind DeviceOffloadKind) const 
override;
+
 private:
   mutable std::unique_ptr Lipo;
   mutable std::unique_ptr Dsymutil;
@@ -653,6 +657,10 @@ class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
 
   void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const 
override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ Action::OffloadKind DeviceOffloadKind) const 
override;
+
   void AddLinkARCArgs(const llvm::opt::ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) const override;
 
diff --git a/clang/test/Driver/arch-arm64e.c b/clang/test/Driver/arch-arm64e.c
new file mode 100644
index 0..0fb12d4dcc5e3
--- /dev/null
+++ b/clang/test/Driver/arch-arm64e.c
@@ -0,0 +1,66 @@
+// Check that we can manually enable specific ptrauth features.
+
+// RUN: %clang -target arm64-apple-darwin -c %s -### 2>&1 | FileCheck %s 
--check-prefix NONE
+// NONE: "-cc1"
+// NONE-NOT: "-fptrauth-intrinsics"
+// NONE-NOT: "-fptrauth-calls"
+// NONE-NOT: "-fptrauth-returns"
+// NONE-NOT: "-fptrauth-indirect-gotos"
+// NONE-NOT: "-fptrauth-auth-traps"
+
+// RUN: %clang -target a

[clang] [clang] Decay types of function and constant template parameter packs (PR #132189)

2025-03-24 Thread Matheus Izvekov via cfe-commits


@@ -1277,19 +1278,27 @@ QualType 
Sema::CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI,
 TSI = SubstAutoTypeSourceInfoDependent(TSI);
   }
 
-  return CheckNonTypeTemplateParameterType(TSI->getType(), Loc);
+  return CheckNonTypeTemplateParameterType(TSI->getType(), Loc, Diagnose);
 }
 
-bool Sema::RequireStructuralType(QualType T, SourceLocation Loc) {
+bool Sema::RequireStructuralType(QualType T, SourceLocation Loc,
+ bool Diagnose) {
   if (T->isDependentType())
 return false;
 
-  if (RequireCompleteType(Loc, T, diag::err_template_nontype_parm_incomplete))
+  if (Diagnose ? RequireCompleteType(Loc, T,
+ 
diag::err_template_nontype_parm_incomplete)
+   : !isCompleteType(Loc, T))
 return true;
 
   if (T->isStructuralType())
 return false;
 
+  // If we're not emitting diagnostics, there's no need to figure out
+  // why exactly T is not a structural type.
+  if (!Diagnose)
+return true;

mizvekov wrote:

Oh yeah, you are right, that also calls out to the main implementation which 
has all those side effects.

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


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

2025-03-24 Thread Mészáros Gergely via cfe-commits


@@ -0,0 +1,534 @@
+#!/usr/bin/env python3
+
+"""generate_unsupported_in_drivermode.py
+
+This script generates Lit regression test files that validate that options are 
only exposed to intended driver modes.
+
+The options and driver modes are parsed from Options.td, whose path should be 
provided on the command line.
+See clang/include/clang/Driver/Options.td
+
+The LLVM TableGen executable can optionally be provided along with the path to 
the LLVM build tree bin directory.
+Otherwise, the script will search for it.
+
+The primary maintenance task for this script would be updating the expected 
return message for a driver mode if
+there are changes over time. See the instantiations of DriverData, 
specifically the check_str.
+
+Logic:
+1) For each option, (records of class "Option"), and for each driver, (records 
of class "OptionVisibility")
+a. if the option's "Visibility" field includes the driver flavour, skip 
processing this option for this driver
+b. if the option is part of an option group, (the record has the "Group" 
property),
+   and the group's "Visibility" field includes the driver flavour, skip 
processing this option for this driver
+c. otherwise this option is not supported by this driver flavour, and this 
pairing is saved for testing
+2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to 
parse for expected output. Ex: "error: unknown argument"
+"""
+
+import os
+import json
+import subprocess
+from bisect import bisect_left
+from dataclasses import dataclass
+import argparse
+import dataclasses
+import itertools
+
+# Strings defined in Options.td for the various driver flavours. See 
"OptionVisibility"
+VISIBILITY_CC1AS = "CC1AsOption"
+VISIBILITY_CC1 = "CC1Option"
+VISIBILITY_CL = "CLOption"
+VISIBILITY_DXC = "DXCOption"
+VISIBILITY_DEFAULT = "DefaultVis"
+VISIBILITY_FC1 = "FC1Option"
+VISIBILITY_FLANG = "FlangOption"
+
+# Lit test prefix strings
+SLASH_SLASH = "// "
+EXCLAMATION = "! "
+
+exceptions_sequence = [
+# Invalid usage of the driver options below causes unique output, so skip 
testing
+"cc1",
+"cc1as",
+# There is currently a bug with "_no_warnings", i.e. --no-warnings. 
Diagnostic related options
+# are parsed first, and always with CC1 visibility. They're used to set up 
the diagnostic
+# engine, which parses "_no_warnings" (and its alias "w", i.e. -w) and 
sets an internal flag
+# that suppresses all warnings.
+"_no_warnings",
+"w",
+]
+
+
+@dataclass
+class DriverOption:
+"""Defines an unsupported driver-option combination
+driver: The driver string as defined by OptionVisibility in Options.td
+option: The option object from Options.td
+option_name: Corresponding string for an option. See "Name" for a given 
option in Options.td
+prefix: String that precedes the option. Ex. "-"
+"""
+
+driver: str
+option: str
+option_name: str
+prefix: str
+
+
+@dataclass
+class DriverData:
+"""Dataclass for data specific to each driver
+lit_cmd_prefix: The beginning string of the Lit command
+lit_cmd_options: Strings containing additional options for this driver
+visibility_str: The corresponding visibility string from OptionVisibility 
in Options.td
+lit_cmd_end: String at the end of the Lit command
+check_str: The string or regex to be sent to FileCheck
+supported_joined_option_sequence: List of DriverOption objects for 
supported options
+  that are Kind *JOINED*, as defined in 
Options.td
+supported_non_joined_option_sequence: List of DriverOption objects for 
supported options
+  that are not Kind *JOINED*, as 
defined in Options.td
+test_option_sequence: A list of all the prefix-option pairs that will be 
tested for this driver
+"""
+
+lit_cmd_prefix: str
+lit_cmd_options: str
+visibility_str: str
+lit_cmd_end: str
+check_str: str
+supported_joined_option_sequence: list[DriverOption] = dataclasses.field(
+default_factory=list
+)
+supported_non_joined_option_sequence: list[DriverOption] = 
dataclasses.field(
+default_factory=list
+)
+test_option_sequence: list[str] = dataclasses.field(default_factory=list)
+
+
+def collect_transitive_groups(member, options_dictionary):
+"""Find the groups for a given member, where a member can be an option or 
a group.
+Note that groups can themselves be part of groups, hence the recursion
+
+For example, considering option 'C', it has the following 'Group' field as 
defined by Options.td:
+  "C": {
+"Group": {
+  "def": "Preprocessor_Group",
+  // ...
+},
+// ...
+  },
+'Preprocessor_Group' is itself part of 'CompileOnly_Group', so option 'C' 
would be part of both groups
+  "Preprocessor_Group": {
+// ...
+"Group": {
+  "def": "CompileOnly_Group",
+

[clang] 9a82f74 - [HLSL][NFC] Refactor HLSLExternalSemaSource (#131032)

2025-03-24 Thread via cfe-commits

Author: Helena Kotas
Date: 2025-03-24T14:56:05-07:00
New Revision: 9a82f742b4976650827674e58c3c2b0b412b56f0

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

LOG: [HLSL][NFC] Refactor HLSLExternalSemaSource (#131032)

Moving builder classes into separate files
`HLSLBuiltinTypeDeclBuilder.cpp`/`.h`, changing a some
`HLSLExternalSemaSource` methods to private and removing unused methods.

This is a prep work before we start adding more builtin types and
methods, like textures, resource constructors or matrices. For example
constructors could make use of the `BuiltinTypeMethodBuilder`, but this
helper class was defined in `HLSLExternalSemaSource.cpp` after the
method that creates a constructor. Rather than reshuffling the code one
big source file I am moving the builders into a separate cpp & header
file and placing the helper classes declarations up top.

Currently the new header only exposes `BuiltinTypeDeclBuilder` to
`HLSLExternalSemaSource`. In the future but we might decide to expose
more helper classes as needed.

Added: 
clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h

Modified: 
clang/include/clang/Sema/HLSLExternalSemaSource.h
clang/lib/Sema/CMakeLists.txt
clang/lib/Sema/HLSLExternalSemaSource.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h 
b/clang/include/clang/Sema/HLSLExternalSemaSource.h
index 3c7495e66055d..d93fb8c8eef6b 100644
--- a/clang/include/clang/Sema/HLSLExternalSemaSource.h
+++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -12,9 +12,8 @@
 #ifndef CLANG_SEMA_HLSLEXTERNALSEMASOURCE_H
 #define CLANG_SEMA_HLSLEXTERNALSEMASOURCE_H
 
-#include "llvm/ADT/DenseMap.h"
-
 #include "clang/Sema/ExternalSemaSource.h"
+#include "llvm/ADT/DenseMap.h"
 
 namespace clang {
 class NamespaceDecl;
@@ -27,14 +26,8 @@ class HLSLExternalSemaSource : public ExternalSemaSource {
   using CompletionFunction = std::function;
   llvm::DenseMap Completions;
 
-  void defineHLSLVectorAlias();
-  void defineTrivialHLSLTypes();
-  void defineHLSLTypesWithForwardDeclarations();
-
-  void onCompletion(CXXRecordDecl *Record, CompletionFunction Fn);
-
 public:
-  ~HLSLExternalSemaSource() override;
+  ~HLSLExternalSemaSource() override {}
 
   /// Initialize the semantic source with the Sema instance
   /// being used to perform semantic analysis on the abstract syntax
@@ -47,6 +40,12 @@ class HLSLExternalSemaSource : public ExternalSemaSource {
   using ExternalASTSource::CompleteType;
   /// Complete an incomplete HLSL builtin type
   void CompleteType(TagDecl *Tag) override;
+
+private:
+  void defineTrivialHLSLTypes();
+  void defineHLSLVectorAlias();
+  void defineHLSLTypesWithForwardDeclarations();
+  void onCompletion(CXXRecordDecl *Record, CompletionFunction Fn);
 };
 
 } // namespace clang

diff  --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 1a351684d133e..d3fe80f659f69 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangSema
   DeclSpec.cpp
   DelayedDiagnostic.cpp
   HeuristicResolver.cpp
+  HLSLBuiltinTypeDeclBuilder.cpp
   HLSLExternalSemaSource.cpp
   IdentifierResolver.cpp
   JumpDiagnostics.cpp

diff  --git a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp 
b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
new file mode 100644
index 0..6b7cc86fefa8f
--- /dev/null
+++ b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
@@ -0,0 +1,781 @@
+//===--- HLSLBuiltinTypeDeclBuilder.cpp - HLSL Builtin Type Decl Builder 
--===//
+//
+// 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
+//
+//===--===//
+//
+// Helper classes for creating HLSL builtin class types. Used by external HLSL
+// sema source.
+//
+//===--===//
+
+#include "HLSLBuiltinTypeDeclBuilder.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Type.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Sema/Sema.h"
+#include "clang/Sema/SemaHLSL.h"
+#include "llvm/ADT/SmallVector.h"
+
+using namespace llvm::hlsl;
+
+namespace clang {
+
+namespace hlsl {
+
+namespace {
+
+static FunctionDecl *lookupBuiltinFunction(Sema &S, StringRef Name) {
+  IdentifierInfo &II =
+  S.getASTContext().Idents.get(Name, tok::TokenKind::identifier);
+  DeclarationNameInfo NameInfo =
+  Declarati

[clang-tools-extra] [clang-doc] [feat] add --repository-line-prefix argument (PR #131280)

2025-03-24 Thread Mohamed Emad via cfe-commits

https://github.com/hulxv updated 
https://github.com/llvm/llvm-project/pull/131280

>From bf9bd4156cb7f652c9cf0477f537e5c58b470448 Mon Sep 17 00:00:00 2001
From: hulxv 
Date: Fri, 14 Mar 2025 07:39:15 +0200
Subject: [PATCH 01/12] [clang-doc] [feat] add `--repository-line-prefix`
 argument (fix #59814)

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 66 ---
 clang-tools-extra/clang-doc/MDGenerator.cpp   |  7 +-
 .../clang-doc/Representation.cpp  |  4 ++
 clang-tools-extra/clang-doc/Representation.h  |  5 +-
 .../clang-doc/tool/ClangDocMain.cpp   | 13 ++--
 5 files changed, 64 insertions(+), 31 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 18a0de826630c..967275f93193b 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -491,9 +491,9 @@ genReferencesBlock(const std::vector &References,
   return Out;
 }
 
-static std::unique_ptr
-writeFileDefinition(const Location &L,
-std::optional RepositoryUrl = std::nullopt) {
+static std::unique_ptr writeFileDefinition(
+const Location &L, std::optional RepositoryUrl = std::nullopt,
+std::optional RepositoryLinePrefix = std::nullopt) {
   if (!L.IsFileInRootDir && !RepositoryUrl)
 return std::make_unique(
 HTMLTag::TAG_P, "Defined at line " + std::to_string(L.LineNumber) +
@@ -514,17 +514,21 @@ writeFileDefinition(const Location &L,
   Node->Children.emplace_back(std::make_unique("Defined at line "));
   auto LocNumberNode =
   std::make_unique(HTMLTag::TAG_A, std::to_string(L.LineNumber));
-  // The links to a specific line in the source code use the github /
-  // googlesource notation so it won't work for all hosting pages.
-  // FIXME: we probably should have a configuration setting for line number
-  // rendering in the HTML. For example, GitHub uses #L22, while googlesource
-  // uses #22 for line numbers.
-  LocNumberNode->Attributes.emplace_back(
-  "href", (FileURL + "#" + std::to_string(L.LineNumber)).str());
+
+  std::string LineAnchor = "#";
+
+  if (RepositoryLinePrefix)
+LineAnchor += RepositoryLinePrefix.value().str();
+
+  LineAnchor += std::to_string(L.LineNumber);
+
+  LocNumberNode->Attributes.emplace_back("href", (FileURL + LineAnchor).str());
   Node->Children.emplace_back(std::move(LocNumberNode));
   Node->Children.emplace_back(std::make_unique(" of file "));
+
   auto LocFileNode = std::make_unique(
   HTMLTag::TAG_A, llvm::sys::path::filename(FileURL));
+
   LocFileNode->Attributes.emplace_back("href", std::string(FileURL));
   Node->Children.emplace_back(std::move(LocFileNode));
   return Node;
@@ -750,11 +754,15 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
   Out.emplace_back(std::move(Table));
 
   if (I.DefLoc) {
-if (!CDCtx.RepositoryUrl)
-  Out.emplace_back(writeFileDefinition(*I.DefLoc));
-else
-  Out.emplace_back(
-  writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+std::optional RepoUrl;
+std::optional RepoLinePrefix;
+
+if (CDCtx.RepositoryUrl)
+  RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+if (CDCtx.RepositoryLinePrefix)
+  RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
   }
 
   std::string Description;
@@ -799,11 +807,15 @@ genHTML(const FunctionInfo &I, const ClangDocContext 
&CDCtx,
   FunctionHeader->Children.emplace_back(std::make_unique(")"));
 
   if (I.DefLoc) {
-if (!CDCtx.RepositoryUrl)
-  Out.emplace_back(writeFileDefinition(*I.DefLoc));
-else
-  Out.emplace_back(writeFileDefinition(
-  *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+std::optional RepoUrl;
+std::optional RepoLinePrefix;
+
+if (CDCtx.RepositoryUrl)
+  RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+if (CDCtx.RepositoryLinePrefix)
+  RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
   }
 
   std::string Description;
@@ -866,11 +878,15 @@ genHTML(const RecordInfo &I, Index &InfoIndex, const 
ClangDocContext &CDCtx,
   Out.emplace_back(std::make_unique(HTMLTag::TAG_H1, InfoTitle));
 
   if (I.DefLoc) {
-if (!CDCtx.RepositoryUrl)
-  Out.emplace_back(writeFileDefinition(*I.DefLoc));
-else
-  Out.emplace_back(writeFileDefinition(
-  *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+std::optional RepoUrl;
+std::optional RepoLinePrefix;
+
+if (CDCtx.RepositoryUrl)
+  RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+if (CDCtx.RepositoryLinePrefix)
+  RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
   }
 
   std::string Description;
diff --git a/clang-tools-extra/clang-doc/MDGenerator.cpp 
b/clang-too

[clang] [Clang][Driver] Override complex number calculation method by -fno-fa… (PR #132680)

2025-03-24 Thread Andy Kaylor via cfe-commits


@@ -177,14 +177,45 @@
 // RUN: %clang -### -target x86_64 -ffast-math -fcomplex-arithmetic=basic -c 
%s 2>&1 \
 // RUN:   | FileCheck --check-prefix=BASIC %s
 
-// BASIC: -complex-range=basic
-// FULL: -complex-range=full
-// PRMTD: -complex-range=promoted
-// BASIC-NOT: -complex-range=improved
-// CHECK-NOT: -complex-range=basic
-// IMPRVD: -complex-range=improved
-// IMPRVD-NOT: -complex-range=basic
-// CHECK-NOT: -complex-range=improved
+// RUN: %clang -### -target x86_64 -fcx-limited-range -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN21 %s
+
+// RUN: %clang -### -Werror -target x86_64 -fno-cx-limited-range 
-fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL %s
+
+// RUN: %clang -### -target x86_64 -fcx-fortran-rules -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN22 %s
+
+// RUN: %clang -### -Werror -target x86_64 -fno-cx-fortran-rules 
-fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL %s
+
+// RUN: %clang -### -Werror -target x86_64 -ffast-math -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL %s
+
+// RUN: %clang -### -target x86_64 -fcomplex-arithmetic=basic -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN23 %s
+
+// RUN: %clang -### -target x86_64 -fcomplex-arithmetic=promoted 
-fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN24 %s
+
+// RUN: %clang -### -target x86_64 -fcomplex-arithmetic=improved 
-fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN25 %s
+
+// RUN: %clang -### -Werror -target x86_64 -fcomplex-arithmetic=full 
-fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL %s
+
+// RUN: %clang -### -target x86_64 -ffp-model=aggressive -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN23 %s
+
+// RUN: %clang -### -target x86_64 -ffp-model=fast -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN24 %s
+
+// RUN: %clang -### -Werror -target x86_64 -ffp-model=precise -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL %s
+
+// RUN: %clang -### -Werror -target x86_64 -ffp-model=strict -fno-fast-math \

andykaylor wrote:

Can you add test cases for when `-fno-fast-math` is followed by other options 
that change the complex mode?

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


[clang] [llvm] [clang][DebugInfo] Add symbol for debugger with VTable information. (PR #130255)

2025-03-24 Thread David Blaikie via cfe-commits

dwblaikie wrote:

> The link from the class to the specific vtable even seems mildly incorrect, 
> in that during object construction the vtable will go through several 
> different values, not just one.

Not sure I follow this - the object is only of the type, in some sense, when it 
is pointing to that particular vtable. When the base subobject is constructed - 
it's only that, the base subobject (Or on destruction - once the most derived 
destruction has run, and the vtable is set to the base type, all the object is, 
in some sense, at that point, is the base subobject)

Though I haven't thought seriously about the representation - truly off the 
cuff, take with a grain of salt, etc, the static member that is the vtable 
seems sort of reasonable to me. 

Not sure why it'd be necessary to make that vtable global variable "global" 
rather than static within the class? Is that for debug_names lookup? (I think 
static members are still in the index, right?) If it's a class member you can 
still do bidirectional lookup, right? IF you find the variable, you can find 
its parent to see which class it applies to, and if you have the class you can 
find the vtable variable inside it?

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


[clang] [HLSL] Finish exposing half types and intrinsics always (PR #132804)

2025-03-24 Thread Joshua Batista via cfe-commits

bob80905 wrote:

> > > > For example, for `abs`, it still depends on the 
> > > > _HLSL_16BIT_AVAILABILITY availability attribute. Does this PR intend to 
> > > > keep abs overloads using half "unexposed"? Or should that overload for 
> > > > abs be exposed too?
> > > 
> > > 
> > > Oh I see what you are referring to. That might be my mistake; let me 
> > > double check if I used the wrong __HLSL_AVAILABILITY
> > 
> > 
> > Yeah, if the intention of this PR is to expose all half type overloads 
> > always, then I would think there is no more utility in defining 
> > `HLSL_16BIT_AVAILABILITY` anymore.
> 
> I think I was meant to use _HLSL_16BIT_AVAILABILITY and not 
> _HLSL_AVAILABILITY; I'll fix that. Thanks for noticing the error!

What I'm trying to get at is, you're removing #ifdef __HLSL_ENABLE_16_BIT, and 
replacing it with an availability attribute making sure that the shader model 
is at least 6.2 for these functions.
If you look at the definition for HLSL_16bit_availability, you'll notice that 
it's also defined under an ifdef: #ifdef  __HLSL_ENABLE_16_BIT
The essence of this PR seems to me like it's assuming from now on that #ifdef 
__HLSL_ENABLE_16_BIT will always be true.
So, that means this availability attribute will always be defined. And it's 
identical to the HLSL_AVAILABILITY attribute. 
I might understand this incorrectly, but now it seems to me like there's no 
point or distinguishing use between HLSL_AVAILABILITY and 
HLSL_16bit_AVAILABILITY. Does that make sense?
Which would imply that functions like `abs` should just use HLSL_Availability 
instead and we can do away with HLSL_16bit_AVAILABILITY. Since you want all 
function overloads with a half parameter to always be exposed.



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


[clang] [CIR] Emit allocas into the proper lexical scope (PR #132468)

2025-03-24 Thread Andy Kaylor via cfe-commits


@@ -0,0 +1,81 @@
+//===--===//
+//
+// 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 "PassDetail.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/IR/PatternMatch.h"
+#include "mlir/Support/LogicalResult.h"
+#include "mlir/Transforms/DialectConversion.h"
+#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
+#include "clang/CIR/Dialect/IR/CIRDialect.h"
+#include "clang/CIR/Dialect/Passes.h"
+#include "clang/CIR/MissingFeatures.h"
+#include "llvm/Support/TimeProfiler.h"
+
+using namespace mlir;
+using namespace cir;
+
+namespace {
+
+struct HoistAllocasPass : public HoistAllocasBase {
+
+  HoistAllocasPass() = default;
+  void runOnOperation() override;
+};
+
+static void process(mlir::ModuleOp mod, cir::FuncOp func) {
+  if (func.getRegion().empty())
+return;
+
+  // Hoist all static allocas to the entry block.
+  mlir::Block &entryBlock = func.getRegion().front();
+  llvm::SmallVector allocas;
+  func.getBody().walk([&](cir::AllocaOp alloca) {

andykaylor wrote:

I'm not sure I can do that because the loop below is moving allocas. Hoisting 
them midwalk could disrupt the walking process.

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


[clang-tools-extra] [clang-doc] [feat] add --repository-line-prefix argument (PR #131280)

2025-03-24 Thread Mohamed Emad via cfe-commits

https://github.com/hulxv updated 
https://github.com/llvm/llvm-project/pull/131280

>From bf9bd4156cb7f652c9cf0477f537e5c58b470448 Mon Sep 17 00:00:00 2001
From: hulxv 
Date: Fri, 14 Mar 2025 07:39:15 +0200
Subject: [PATCH 01/11] [clang-doc] [feat] add `--repository-line-prefix`
 argument (fix #59814)

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 66 ---
 clang-tools-extra/clang-doc/MDGenerator.cpp   |  7 +-
 .../clang-doc/Representation.cpp  |  4 ++
 clang-tools-extra/clang-doc/Representation.h  |  5 +-
 .../clang-doc/tool/ClangDocMain.cpp   | 13 ++--
 5 files changed, 64 insertions(+), 31 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 18a0de826630c..967275f93193b 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -491,9 +491,9 @@ genReferencesBlock(const std::vector &References,
   return Out;
 }
 
-static std::unique_ptr
-writeFileDefinition(const Location &L,
-std::optional RepositoryUrl = std::nullopt) {
+static std::unique_ptr writeFileDefinition(
+const Location &L, std::optional RepositoryUrl = std::nullopt,
+std::optional RepositoryLinePrefix = std::nullopt) {
   if (!L.IsFileInRootDir && !RepositoryUrl)
 return std::make_unique(
 HTMLTag::TAG_P, "Defined at line " + std::to_string(L.LineNumber) +
@@ -514,17 +514,21 @@ writeFileDefinition(const Location &L,
   Node->Children.emplace_back(std::make_unique("Defined at line "));
   auto LocNumberNode =
   std::make_unique(HTMLTag::TAG_A, std::to_string(L.LineNumber));
-  // The links to a specific line in the source code use the github /
-  // googlesource notation so it won't work for all hosting pages.
-  // FIXME: we probably should have a configuration setting for line number
-  // rendering in the HTML. For example, GitHub uses #L22, while googlesource
-  // uses #22 for line numbers.
-  LocNumberNode->Attributes.emplace_back(
-  "href", (FileURL + "#" + std::to_string(L.LineNumber)).str());
+
+  std::string LineAnchor = "#";
+
+  if (RepositoryLinePrefix)
+LineAnchor += RepositoryLinePrefix.value().str();
+
+  LineAnchor += std::to_string(L.LineNumber);
+
+  LocNumberNode->Attributes.emplace_back("href", (FileURL + LineAnchor).str());
   Node->Children.emplace_back(std::move(LocNumberNode));
   Node->Children.emplace_back(std::make_unique(" of file "));
+
   auto LocFileNode = std::make_unique(
   HTMLTag::TAG_A, llvm::sys::path::filename(FileURL));
+
   LocFileNode->Attributes.emplace_back("href", std::string(FileURL));
   Node->Children.emplace_back(std::move(LocFileNode));
   return Node;
@@ -750,11 +754,15 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
   Out.emplace_back(std::move(Table));
 
   if (I.DefLoc) {
-if (!CDCtx.RepositoryUrl)
-  Out.emplace_back(writeFileDefinition(*I.DefLoc));
-else
-  Out.emplace_back(
-  writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+std::optional RepoUrl;
+std::optional RepoLinePrefix;
+
+if (CDCtx.RepositoryUrl)
+  RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+if (CDCtx.RepositoryLinePrefix)
+  RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
   }
 
   std::string Description;
@@ -799,11 +807,15 @@ genHTML(const FunctionInfo &I, const ClangDocContext 
&CDCtx,
   FunctionHeader->Children.emplace_back(std::make_unique(")"));
 
   if (I.DefLoc) {
-if (!CDCtx.RepositoryUrl)
-  Out.emplace_back(writeFileDefinition(*I.DefLoc));
-else
-  Out.emplace_back(writeFileDefinition(
-  *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+std::optional RepoUrl;
+std::optional RepoLinePrefix;
+
+if (CDCtx.RepositoryUrl)
+  RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+if (CDCtx.RepositoryLinePrefix)
+  RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
   }
 
   std::string Description;
@@ -866,11 +878,15 @@ genHTML(const RecordInfo &I, Index &InfoIndex, const 
ClangDocContext &CDCtx,
   Out.emplace_back(std::make_unique(HTMLTag::TAG_H1, InfoTitle));
 
   if (I.DefLoc) {
-if (!CDCtx.RepositoryUrl)
-  Out.emplace_back(writeFileDefinition(*I.DefLoc));
-else
-  Out.emplace_back(writeFileDefinition(
-  *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+std::optional RepoUrl;
+std::optional RepoLinePrefix;
+
+if (CDCtx.RepositoryUrl)
+  RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+if (CDCtx.RepositoryLinePrefix)
+  RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
   }
 
   std::string Description;
diff --git a/clang-tools-extra/clang-doc/MDGenerator.cpp 
b/clang-too

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

2025-03-24 Thread via cfe-commits

https://github.com/choikwa updated 
https://github.com/llvm/llvm-project/pull/129347

>From 1a6f7f27fb0017f45543ff8cc09c49bdfd4ebfd8 Mon Sep 17 00:00:00 2001
From: Kevin Choi 
Date: Fri, 28 Feb 2025 16:52:03 -0600
Subject: [PATCH] [AMDGPU][clang] provide device implementation for
 __builtin_logb and __builtin_scalbn

Clang generates library calls for __builtin_* functions which can be a problem 
for GPUs that cannot handle them.
This patch generates a device implementations for __builtin_logb and 
__builtin_scalbn.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 19 -
 clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp | 45 +
 clang/test/CodeGen/logb_scalbn.cpp  | 32 +++
 3 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/logb_scalbn.cpp

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f0ba52fa41ce8..b5c5b5e55efed 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -6011,10 +6011,27 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
   }
   }
 
+  // These will be emitted as Intrinsic later.
+  auto NeedsDeviceOverload = [&](unsigned BuiltinID) {
+if (getTarget().getTriple().isAMDGCN()) {
+  switch (BuiltinID) {
+  default:
+return false;
+  case Builtin::BIlogb:
+  case Builtin::BI__builtin_logb:
+  case Builtin::BIscalbn:
+  case Builtin::BI__builtin_scalbn:
+return true;
+  }
+}
+return false;
+  };
+
   // If this is an alias for a lib function (e.g. __builtin_sin), emit
   // the call using the normal call path, but using the unmangled
   // version of the function name.
-  if (getContext().BuiltinInfo.isLibFunction(BuiltinID))
+  if (!NeedsDeviceOverload(BuiltinID) &&
+  getContext().BuiltinInfo.isLibFunction(BuiltinID))
 return emitLibraryCall(*this, FD, E,
CGM.getBuiltinLibFunction(FD, BuiltinID));
 
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp 
b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index f94917c905081..b0e7679b69043 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -31,6 +31,27 @@ using namespace CodeGen;
 using namespace llvm;
 
 namespace {
+
+// Has second type mangled argument.
+static Value *
+emitBinaryExpMaybeConstrainedFPBuiltin(CodeGenFunction &CGF, const CallExpr *E,
+   Intrinsic::ID IntrinsicID,
+   Intrinsic::ID ConstrainedIntrinsicID) {
+  llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
+  llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
+
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
+  if (CGF.Builder.getIsFPConstrained()) {
+Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID,
+   {Src0->getType(), Src1->getType()});
+return CGF.Builder.CreateConstrainedFPCall(F, {Src0, Src1});
+  }
+
+  Function *F =
+  CGF.CGM.getIntrinsic(IntrinsicID, {Src0->getType(), Src1->getType()});
+  return CGF.Builder.CreateCall(F, {Src0, Src1});
+}
+
 // If \p E is not null pointer, insert address space cast to match return
 // type of \p E if necessary.
 Value *EmitAMDGPUDispatchPtr(CodeGenFunction &CGF,
@@ -1876,6 +1897,30 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_s_prefetch_data:
 return emitBuiltinWithOneOverloadedType<2>(
 *this, E, Intrinsic::amdgcn_s_prefetch_data);
+  case Builtin::BIlogb:
+  case Builtin::BI__builtin_logb: {
+auto *Src0 = EmitScalarExpr(E->getArg(0));
+auto *FrExpFunc = CGM.getIntrinsic(Intrinsic::amdgcn_frexp_exp,
+   {Builder.getInt32Ty(), 
Src0->getType()});
+auto *FrExp = Builder.CreateCall(FrExpFunc, Src0);
+auto *Add = Builder.CreateAdd(
+FrExp, ConstantInt::getSigned(FrExp->getType(), -1), "", false, true);
+auto *SIToFP = Builder.CreateSIToFP(Add, Builder.getDoubleTy());
+auto *Fabs = emitBuiltinWithOneOverloadedType<1>(*this, E, 
Intrinsic::fabs);
+auto *FCmpONE = Builder.CreateFCmpONE(
+Fabs, ConstantFP::getInfinity(Builder.getDoubleTy()));
+auto *Sel1 = Builder.CreateSelect(FCmpONE, SIToFP, Fabs);
+auto *FCmpOEQ =
+Builder.CreateFCmpOEQ(Src0, 
ConstantFP::getZero(Builder.getDoubleTy()));
+auto *Sel2 = Builder.CreateSelect(
+FCmpOEQ, ConstantFP::getInfinity(Builder.getDoubleTy(), /*Neg*/ true),
+Sel1);
+return Sel2;
+  }
+  case Builtin::BIscalbn:
+  case Builtin::BI__builtin_scalbn:
+return emitBinaryExpMaybeConstrainedFPBuiltin(
+*this, E, Intrinsic::ldexp, Intrinsic::experimental_constrained_ldexp);
   default:
 return nullptr;
   }
diff --git a/clang/test/CodeGen/logb_scalbn.cpp 
b/clang/test/CodeGen/logb_scalbn.cpp
new file mode 100644
index 0..ab8

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

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

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


[clang] [Clang][AMDGPU] Use size_t to compare with npos (PR #132868)

2025-03-24 Thread Matt Arsenault via cfe-commits

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


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


[clang] [HIP] use offload wrapper for non-device-only non-rdc (PR #132869)

2025-03-24 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu created 
https://github.com/llvm/llvm-project/pull/132869

Currently HIP still uses offload bundler for non-rdc mode for the new offload 
driver.

This patch switches to use offload wrapper for non-device-only non-rdc mode 
when new offload driver is enabled.

This makes the rdc and non-rdc compilation more consistent and speeds up 
compilation since the offload wrapper supports parallel compilation for 
different GPU arch's.

It is implemented by adding a linker wrapper action for each assemble action of 
input file. Linker wrapper action differentiates this special type of work vs 
normal linker wrapper work by the fle type. This type of work results in object 
instead of image. The linker wrapper adds "-r" for it and only includes the 
object file as input, not the host libraries.

For device-only non-RDC mode, the new driver keeps the original behavior.

>From 124633900a0067c81955a2d19d8a75f15a4d4c50 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Fri, 21 Mar 2025 14:16:44 -0400
Subject: [PATCH] [HIP] use offload wrapper for non-device-only non-rdc

Currently HIP still uses offload bundler for non-rdc mode for
the new offload driver.

This patch switches to use offload wrapper for non-device-only
non-rdc mode when new offload driver is enabled.

This makes the rdc and non-rdc compilation more consistent
and speeds up compilation since the offload wrapper supports
parallel compilation for different GPU arch's.

It is implemented by adding a linker wrapper action for
each assemble action of input file. Linker wrapper action
differentiates this special type of work vs normal
linker wrapper work by the fle type. This type of work
results in object instead of image. The linker wrapper
adds "-r" for it and only includes the object file
as input, not the host libraries.

For device-only non-RDC mode, the new driver keeps the
original behavior.
---
 clang/lib/CodeGen/CGCUDANV.cpp |  3 +-
 clang/lib/Driver/Driver.cpp| 41 ---
 clang/lib/Driver/ToolChains/Clang.cpp  | 19 +++--
 clang/test/Driver/hip-binding.hip  |  6 +-
 clang/test/Driver/hip-phases.hip   | 51 --
 clang/test/Driver/hip-toolchain-no-rdc.hip | 81 +-
 6 files changed, 132 insertions(+), 69 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 5445a9278596d..395263331d141 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1281,7 +1281,8 @@ llvm::Function *CGNVCUDARuntime::finalizeModule() {
 return nullptr;
   }
   if (CGM.getLangOpts().OffloadViaLLVM ||
-  (CGM.getLangOpts().OffloadingNewDriver && RelocatableDeviceCode))
+  (CGM.getLangOpts().OffloadingNewDriver &&
+   (CGM.getLangOpts().HIP || RelocatableDeviceCode)))
 createOffloadingEntries();
   else
 return makeModuleCtorFunction();
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 056bfcf1b739a..6d63a55918687 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4402,6 +4402,10 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
options::OPT_no_offload_new_driver,
C.isOffloadingHostKind(Action::OFK_Cuda));
 
+  bool HIPNoRDC =
+  C.isOffloadingHostKind(Action::OFK_HIP) &&
+  !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
+
   // Builder to be used to build offloading actions.
   std::unique_ptr OffloadBuilder =
   !UseNewOffloadingDriver
@@ -4502,6 +4506,16 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 InputArg))
 break;
 
+  // For HIP non-rdc non-device-only compilation, create a linker wrapper
+  // action for each host object to link, bundle and wrap device files in
+  // it.
+  if (Phase == phases::Assemble && UseNewOffloadingDriver && HIPNoRDC &&
+  !offloadDeviceOnly()) {
+ActionList AL{Current};
+Current = C.MakeAction(AL, types::TY_Object);
+Current->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
+  /*BoundArch=*/nullptr);
+  }
   if (Current->getType() == types::TY_Nothing)
 break;
 }
@@ -4535,7 +4549,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // Check if this Linker Job should emit a static library.
 if (ShouldEmitStaticLibrary(Args)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
-} else if (UseNewOffloadingDriver ||
+} else if ((UseNewOffloadingDriver && !HIPNoRDC) ||
Args.hasArg(options::OPT_offload_link)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
   LA->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
@@ -4945,12 +4959,15 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
   }
 }
 
-// Compiling HIP

[clang-tools-extra] [clang-doc] Format test files (PR #132428)

2025-03-24 Thread via cfe-commits

llvmbot wrote:




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

Author: Paul Kirth (ilovepi)


Changes

Many of the test files had an inconsistent formatting. This patch ran
clang-format over them using the project's .clang-format file, with
column limit = 0, to prevent test directives from being split over
multiple lines.

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


9 Files Affected:

- (modified) clang-tools-extra/test/clang-doc/DR-131697.cpp (+5-7) 
- (modified) 
clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp (+4-4) 
- (modified) 
clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp (+2-3) 
- (modified) 
clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Rectangle.cpp (+3-3) 
- (modified) clang-tools-extra/test/clang-doc/enum.cpp (+31-37) 
- (modified) clang-tools-extra/test/clang-doc/namespace.cpp (+21-28) 
- (modified) clang-tools-extra/test/clang-doc/single-file-public.cpp (+2-2) 
- (modified) clang-tools-extra/test/clang-doc/templates.cpp (+6-7) 
- (modified) clang-tools-extra/test/clang-doc/test-path-abs.cpp (-1) 


``diff
diff --git a/clang-tools-extra/test/clang-doc/DR-131697.cpp 
b/clang-tools-extra/test/clang-doc/DR-131697.cpp
index 67bd55b897973..9025bbf910813 100644
--- a/clang-tools-extra/test/clang-doc/DR-131697.cpp
+++ b/clang-tools-extra/test/clang-doc/DR-131697.cpp
@@ -13,10 +13,8 @@ int main() {
 }
 
 //--- compile_commands.json
-[
-{
-  "directory": "foo",
-  "file":"main.cpp",
-  "command":"clang main.cpp -c"
-}
-]
+[{
+  "directory" : "foo",
+  "file" : "main.cpp",
+  "command" : "clang main.cpp -c"
+}]
diff --git 
a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp 
b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
index 64f31dbf13d87..258ea22e46184 100644
--- a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
+++ b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
@@ -1,17 +1,17 @@
 #include "Calculator.h"
 
 int Calculator::add(int a, int b) {
-return a + b;
+  return a + b;
 }
 
 int Calculator::subtract(int a, int b) {
-return a - b;
+  return a - b;
 }
 
 int Calculator::multiply(int a, int b) {
-return a * b;
+  return a * b;
 }
 
 double Calculator::divide(int a, int b) {
-return static_cast(a) / b;
+  return static_cast(a) / b;
 }
diff --git 
a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp 
b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp
index 3ddb2fd9ff563..811aac4989bd0 100644
--- a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp
+++ b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp
@@ -3,10 +3,9 @@
 Circle::Circle(double radius) : radius_(radius) {}
 
 double Circle::area() const {
-return 3.141 * radius_ * radius_;
+  return 3.141 * radius_ * radius_;
 }
 
 double Circle::perimeter() const {
-return 3.141 * radius_;
+  return 3.141 * radius_;
 }
-
diff --git 
a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Rectangle.cpp 
b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Rectangle.cpp
index 7ffc769157ebc..a2b253b750aa8 100644
--- a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Rectangle.cpp
+++ b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Rectangle.cpp
@@ -1,12 +1,12 @@
 #include "Rectangle.h"
 
 Rectangle::Rectangle(double width, double height)
-: width_(width), height_(height) {}
+: width_(width), height_(height) {}
 
 double Rectangle::area() const {
-return width_ * height_;
+  return width_ * height_;
 }
 
 double Rectangle::perimeter() const {
-return 2 * (width_ + height_);
+  return 2 * (width_ + height_);
 }
\ No newline at end of file
diff --git a/clang-tools-extra/test/clang-doc/enum.cpp 
b/clang-tools-extra/test/clang-doc/enum.cpp
index ef768e33b4566..b05d8e2029070 100644
--- a/clang-tools-extra/test/clang-doc/enum.cpp
+++ b/clang-tools-extra/test/clang-doc/enum.cpp
@@ -14,16 +14,15 @@
 // RUN: FileCheck %s < %t/Vehicles/index.md --check-prefix=MD-VEHICLES-LINE
 // RUN: FileCheck %s < %t/Vehicles/index.md --check-prefix=MD-VEHICLES
 
-
 /**
  * @brief For specifying RGB colors
  */
 enum Color {
-// MD-INDEX-LINE: *Defined at 
{{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
-// HTML-INDEX-LINE: Defined at line [[@LINE-2]] of file 
{{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp
-  Red, ///< Comment 1
+  // MD-INDEX-LINE: *Defined at 
{{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
+  // HTML-INDEX-LINE: Defined at line [[@LINE-2]] of file 
{{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp
+  Red,   ///< Comment 1
   Green, ///< Comment 2
-  Blue ///< Comment 3
+  Blue   ///< Comment 3
 };
 
 // MD-INDEX: ## Enums
@@ -49,8 +48,8 @@ enum Color {
  * @brief Shape Types
  */
 enum class Shapes {
-// MD-INDEX-

[clang] [HLSL] Finish exposing half types and intrinsics always (PR #132804)

2025-03-24 Thread Sarah Spall via cfe-commits

spall wrote:

> For example, for `abs`, it still depends on the _HLSL_16BIT_AVAILABILITY 
> availability attribute. Does this PR intend to keep abs overloads using half 
> "unexposed"? Or should that overload for abs be exposed too?

I'm not sure I understand the question, I think abs is the same as the ones in 
this PR are modified to be. 

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


[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)

2025-03-24 Thread Garvit Gupta via cfe-commits


@@ -110,20 +110,76 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+std::string BareMetal::computeSysRoot() const {
+  if (!SysRoot.empty())
+return SysRoot;
+
+  std::string SysRoot = getDriver().SysRoot;
+  if (!SysRoot.empty())
+return SysRoot;
+
+  // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or
+  // alongside clang. If valid, form the sysroot. Otherwise, check
+  // lib/clang-runtimes above the driver.
+  SmallString<128> SysRootDir;
+  if (GCCInstallation.isValid()) {
+StringRef LibDir = GCCInstallation.getParentLibPath();
+StringRef TripleStr = GCCInstallation.getTriple().str();
+llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr);
+  } else {
+// Use the triple as provided to the driver. Unlike the parsed triple
+// this has not been normalized to always contain every field.
+llvm::sys::path::append(SysRootDir, getDriver().Dir, "..",
+getDriver().getTargetTriple());
+  }
+
+  if (llvm::sys::fs::exists(SysRootDir))
+return std::string(SysRootDir);
+  SysRoot = computeBaseSysRoot(getDriver(), /*IncludeTriple*/ true);
+
+  return SysRoot;

quic-garvgupt wrote:

Thanks for pointing this out!. I have fixed it in the next patchset

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


[clang] [CIR] Emit allocas into the proper lexical scope (PR #132468)

2025-03-24 Thread Andy Kaylor via cfe-commits


@@ -293,7 +294,8 @@ void CIRGenFunction::startFunction(GlobalDecl gd, QualType 
returnType,
 
 mlir::Value addrVal =
 emitAlloca(cast(paramVar)->getName(),
-   convertType(paramVar->getType()), paramLoc, alignment);
+   convertType(paramVar->getType()), paramLoc, alignment,
+   /*insertIntoFnEntryBlock=*/false);

andykaylor wrote:

This is an optional argument in the incubator, and it defaults to false there. 
However, in the incubator, this call happens inside of `declare` so we don't 
know there that it's going into the entry block and instead rely on the 
location having been set.

This should always insert into the entry block, because we set the insertion 
point above. If I set this to `true`, emitAlloca will go through the process of 
finding the correct insertion point, saving, setting, and restoring, for each 
parameter value.

It's probably better to get rid of the `insertIntoFnEntyBlock` argument 
altogether and add a separate `emitAllocaIntoFnEntryBlock` function for the 
cases where that is needed.

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


[clang] [clang][bytecode] Support composite arrays in memcpy op (PR #132775)

2025-03-24 Thread Timm Baeder via cfe-commits

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


[clang] [HLSL] Finish exposing half types and intrinsics always (PR #132804)

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

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


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


[clang] [flang] [flang] Add -f[no-]slp-vectorize flags (PR #132801)

2025-03-24 Thread Tom Eccles via cfe-commits


@@ -0,0 +1,10 @@
+! RUN: %flang -### -S -fslp-vectorize %s 2>&1 | FileCheck 
-check-prefix=CHECK-SLP-VECTORIZE %s
+! RUN: %flang -### -S -fno-slp-vectorize %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-SLP-VECTORIZE %s
+! RUN: %flang -### -S -O1 %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-SLP-VECTORIZE %s
+! RUN: %flang -### -S -O2 %s 2>&1 | FileCheck 
-check-prefix=CHECK-SLP-VECTORIZE %s
+! RUN: %flang -### -S -O3 %s 2>&1 | FileCheck 
-check-prefix=CHECK-SLP-VECTORIZE %s
+! CHECK-SLP-VECTORIZE: "-vectorize-slp"
+! CHECK-NO-SLP-VECTORIZE-NOT: "-no-vectorize-slp"
+
+program test
+end program

tblah wrote:

Please could you add a test to see if this is passed correctly to the middle 
end? 

E.g. you could test whether `flang -mllvm -print-pipeline-passes` contains 
"slp-vectorizer"

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


[clang] [AMDGPU] Remove outdated COV6 warning (PR #132814)

2025-03-24 Thread Shilei Tian via cfe-commits

https://github.com/shiltian created 
https://github.com/llvm/llvm-project/pull/132814

None

>From c1f916c5cb19c1a816737dbb5cf21e5ac1636de3 Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Mon, 24 Mar 2025 15:11:55 -0400
Subject: [PATCH] [AMDGPU] Remove outdated COV6 warning

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td | 4 
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 6 --
 clang/test/Driver/hip-code-object-version.hip  | 5 -
 clang/test/Misc/warning-flags.c| 1 -
 4 files changed, 16 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 058fecd4e91ef..df24cca49aaae 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -92,10 +92,6 @@ def err_drv_hipspv_no_hip_path : Error<
   "'--hip-path' must be specified when offloading to SPIR-V unless '-nogpuinc' 
"
   "is given">;
 
-// TODO: Remove when COV6 is fully supported by ROCm.
-def warn_drv_amdgpu_cov6: Warning<
-  "code object v6 is still in development and not ready for production use 
yet;"
-  " use at your own risk">;
 def err_drv_undetermined_gpu_arch : Error<
   "cannot determine %0 architecture: %1; consider passing it via '%2'; "
   "environment variable CLANG_TOOLCHAIN_PROGRAM_TIMEOUT specifies the tool "
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 157b9ff971add..7f04bcab9cd80 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2748,12 +2748,6 @@ void tools::checkAMDGPUCodeObjectVersion(const Driver &D,
   if (Remnant || CodeObjVer < MinCodeObjVer || CodeObjVer > MaxCodeObjVer)
 D.Diag(diag::err_drv_invalid_int_value)
 << CodeObjArg->getAsString(Args) << CodeObjArg->getValue();
-
-  // COV6 is only supported by LLVM at the time of writing this, and it's
-  // expected to take some time before all ROCm components fully
-  // support it. In the meantime, make sure users are aware of this.
-  if (CodeObjVer == 6)
-D.Diag(diag::warn_drv_amdgpu_cov6);
 }
   }
 }
diff --git a/clang/test/Driver/hip-code-object-version.hip 
b/clang/test/Driver/hip-code-object-version.hip
index 30d8644dff54c..e6f5cc16fd408 100644
--- a/clang/test/Driver/hip-code-object-version.hip
+++ b/clang/test/Driver/hip-code-object-version.hip
@@ -27,11 +27,6 @@
 // RUN:   --offload-arch=gfx906 --rocm-path=%S/Inputs/rocm \
 // RUN:   %s 2>&1 | FileCheck -check-prefix=V6 %s
 
-// V6: warning: code object v6 is still in development and not ready for 
production use yet; use at your own risk
-// V6: "-mcode-object-version=6"
-// V6: "-mllvm" "--amdhsa-code-object-version=6"
-// V6: "-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx906"
-
 
 // Check bundle ID for code object version default
 
diff --git a/clang/test/Misc/warning-flags.c b/clang/test/Misc/warning-flags.c
index a978835a41014..2c2ac0513ac3e 100644
--- a/clang/test/Misc/warning-flags.c
+++ b/clang/test/Misc/warning-flags.c
@@ -40,7 +40,6 @@ CHECK-NEXT:   warn_collection_expr_type
 CHECK-NEXT:   warn_conflicting_variadic
 CHECK-NEXT:   warn_delete_array_type
 CHECK-NEXT:   warn_double_const_requires_fp64
-CHECK-NEXT:   warn_drv_amdgpu_cov6
 CHECK-NEXT:   warn_drv_assuming_mfloat_abi_is
 CHECK-NEXT:   warn_drv_clang_unsupported
 CHECK-NEXT:   warn_drv_pch_not_first_include

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


[clang] [CIR] Emit allocas into the proper lexical scope (PR #132468)

2025-03-24 Thread Morris Hafner via cfe-commits


@@ -0,0 +1,81 @@
+//===--===//
+//
+// 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 "PassDetail.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/IR/PatternMatch.h"
+#include "mlir/Support/LogicalResult.h"
+#include "mlir/Transforms/DialectConversion.h"
+#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
+#include "clang/CIR/Dialect/IR/CIRDialect.h"
+#include "clang/CIR/Dialect/Passes.h"
+#include "clang/CIR/MissingFeatures.h"
+#include "llvm/Support/TimeProfiler.h"
+
+using namespace mlir;
+using namespace cir;
+
+namespace {
+
+struct HoistAllocasPass : public HoistAllocasBase {
+
+  HoistAllocasPass() = default;
+  void runOnOperation() override;
+};
+
+static void process(mlir::ModuleOp mod, cir::FuncOp func) {
+  if (func.getRegion().empty())
+return;
+
+  // Hoist all static allocas to the entry block.
+  mlir::Block &entryBlock = func.getRegion().front();
+  llvm::SmallVector allocas;
+  func.getBody().walk([&](cir::AllocaOp alloca) {

mmha wrote:

As far as I know `walk` traverses post order, so the entry block should come 
last. I don't know what happens within a block, but then again you're also 
modifying the list in the second loop.

But I don't know for sure if it works.

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


[clang] [HLSL] Finish exposing half types and intrinsics always (PR #132804)

2025-03-24 Thread Joshua Batista via cfe-commits

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

Talked offline, LGTM

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


[clang] [HLSL] Finish exposing half types and intrinsics always (PR #132804)

2025-03-24 Thread Joshua Batista via cfe-commits

bob80905 wrote:

> > > this is not NFC, so we should verify that we can call these intrinsics 
> > > with `half` values even if 16-bit types aren't enabled, and that they 
> > > properly codegen to 32-bit varia
> > 
> > 
> > > > > > > For example, for `abs`, it still depends on the 
> > > > > > > _HLSL_16BIT_AVAILABILITY availability attribute. Does this PR 
> > > > > > > intend to keep abs overloads using half "unexposed"? Or should 
> > > > > > > that overload for abs be exposed too?
> > > > > > 
> > > > > > 
> > > > > > Oh I see what you are referring to. That might be my mistake; let 
> > > > > > me double check if I used the wrong __HLSL_AVAILABILITY
> > > > > 
> > > > > 
> > > > > Yeah, if the intention of this PR is to expose all half type 
> > > > > overloads always, then I would think there is no more utility in 
> > > > > defining `HLSL_16BIT_AVAILABILITY` anymore.
> > > > 
> > > > 
> > > > I think I was meant to use _HLSL_16BIT_AVAILABILITY and not 
> > > > _HLSL_AVAILABILITY; I'll fix that. Thanks for noticing the error!
> > > 
> > > 
> > > What I'm trying to get at is, you're removing #ifdef 
> > > __HLSL_ENABLE_16_BIT, and replacing it with an availability attribute 
> > > making sure that the shader model is at least 6.2 for these functions. If 
> > > you look at the definition for HLSL_16bit_availability, you'll notice 
> > > that it's also defined under an ifdef: #ifdef __HLSL_ENABLE_16_BIT The 
> > > essence of this PR seems to me like it's assuming from now on that #ifdef 
> > > __HLSL_ENABLE_16_BIT will always be true. So, that means this 
> > > availability attribute will always be defined. And it's identical to the 
> > > HLSL_AVAILABILITY attribute. I might understand this incorrectly, but now 
> > > it seems to me like there's no point or distinguishing use between 
> > > HLSL_AVAILABILITY and HLSL_16bit_AVAILABILITY. Does that make sense? 
> > > Which would imply that functions like `abs` should just use 
> > > HLSL_Availability instead and we can do away with 
> > > HLSL_16bit_AVAILABILITY. Since you want all function overloads with a 
> > > half parameter to always be exposed.
> > 
> > 
> > @llvm-beanz Thoughts on this?
> 
> Looking at this again' _HLSL_16BIT_AVAILABILITY' is defined even if 
> _HLSL_ENABLE_16_BIT isn't defined; the important thing is the overloads are 
> defined even if there is no native half.

Nevermind I missed the #else :P
All resolved.

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


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

2025-03-24 Thread Mészáros Gergely via cfe-commits


@@ -0,0 +1,472 @@
+#!/usr/bin/env python3
+
+"""generate_unsupported_in_drivermode.py
+
+This script generates Lit regression test files that validate that options are 
only exposed to intended driver modes.
+
+The options and driver modes are parsed from Options.td, whose path should be 
provided on the command line.
+See clang/include/clang/Driver/Options.td
+
+The path to the TableGen executable can optionally be provided. Otherwise, the 
script will search for it.
+
+The primary maintenance task for this script would be updating the expected 
return message for a driver mode if
+there are changes over time. See the instantiations of DriverData, 
specifically the check_str.
+
+Logic:
+1) For each option, (records of class "Option"), and for each driver, (records 
of class "OptionVisibility")
+a. if the option's "Visibility" field includes the driver flavour, skip 
processing this option for this driver
+b. if the option is part of an option group, (the record has the "Group" 
property),
+   and the group's "Visibility" field includes the driver flavour, skip 
processing this option for this driver
+c. otherwise this option is not supported by this driver flavour, and this 
pairing is saved for testing
+2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to 
parse for expected output. Ex: "error: unknown argument"
+"""
+
+import shutil
+import os
+import json
+import subprocess
+from bisect import bisect_left
+from dataclasses import dataclass
+import argparse
+import dataclasses
+from itertools import batched
+
+# Strings defined in Options.td for the various driver flavours. See 
"OptionVisibility"
+VISIBILITY_CC1AS = "CC1AsOption"
+VISIBILITY_CC1 = "CC1Option"
+VISIBILITY_CL = "CLOption"
+VISIBILITY_DXC = "DXCOption"
+VISIBILITY_DEFAULT = "DefaultVis"
+VISIBILITY_FC1 = "FC1Option"
+VISIBILITY_FLANG = "FlangOption"
+
+# Lit test prefix strings
+SLASH_SLASH = "// "
+EXCLAMATION = "! "
+
+# Invalid usage of the driver options below causes unique output, so skip 
testing
+exceptions_sequence = [
+"cc1",
+"cc1as",
+]
+
+
+class UnsupportedDriverOption:
+"""Defines an unsupported driver-option combination
+driver: The driver string as defined by OptionVisibility in Options.td
+option: The option object from Options.td
+option_name: Corresponding string for an option. See "Name" for a given 
option in Options.td
+prefix: String that precedes the option. Ex. "-"
+"""
+
+def __init__(self, driver, option, option_name, prefix):
+self.driver = driver
+self.option = option
+self.option_name = option_name
+self.prefix = prefix
+
+# For sorting
+def __len__(self):
+return len(self.option_name)
+
+def __lt__(self, other):
+return len(self.option_name) > len(other.option_name)
+
+
+@dataclass
+class DriverData:
+"""Dataclass for data specific to each driver
+lit_cmd_prefix: The beginning string of the Lit command
+lit_cmd_options: Strings containing additional options for this driver
+visibility_str: The corresponding visibility string from OptionVisibility 
in Options.td
+lit_cmd_end: String at the end of the Lit command
+check_str: The string or regex to be sent to FileCheck
+supported_sequence: List of UnsupportedDriverOption objects for supported 
options
+that are Kind *JOINED*, as defined in Options.td
+test_option_sequence: A list of all the prefix-option pairs that will be 
tested for this driver
+"""
+
+lit_cmd_prefix: str
+lit_cmd_options: str
+visibility_str: str
+lit_cmd_end: str = " - < /dev/null 2>&1 | FileCheck 
-check-prefix=CHECK-COUNT-"
+check_str: str = "{{(unknown argument|n?N?o such file or directory)}}"
+supported_sequence: list[UnsupportedDriverOption] = dataclasses.field(
+default_factory=list
+)
+test_option_sequence: list[str] = dataclasses.field(default_factory=list)
+
+
+def find_groups(options_dictionary, option):
+"""Find the groups for a given option
+Note that groups can themselves be part of groups, hence the recursion
+
+For example, considering option "C", it has the following 'Group' list as 
defined by Options.td:
+  "Group": {
+"def": "Preprocessor_Group",
+"kind": "def",
+"printable": "Preprocessor_Group"
+  },
+Preprocessor_Group is itself part of CompileOnly_Group, so option C would 
be part of both groups
+  "Group": {
+"def": "CompileOnly_Group",
+"kind": "def",
+"printable": "CompileOnly_Group"
+  },
+
+options_dictionary: The converted Python dictionary from the Options.td 
json string
+option: The option object from Options.td
+
+Return: A set including the group found for the option
+"""
+group_list = options_dictionary[option]["Group"]
+
+if group_list is None:
+return None
+found_group = group_list["def"]
+

[clang] [NFC][Static Analyzer] Rename and discuss about `NotNullConstraint` & `NotNullBufferConstraint` (PR #131374)

2025-03-24 Thread Ziqing Luo via cfe-commits

https://github.com/ziqingluo-90 updated 
https://github.com/llvm/llvm-project/pull/131374

>From fdc265eeca36dc877f56389d8dba39b517e6 Mon Sep 17 00:00:00 2001
From: Ziqing Luo 
Date: Fri, 14 Mar 2025 11:13:46 -0700
Subject: [PATCH 1/3] [NFC][Static Analyzer] Rename `NotNullConstraint` &
 `NotNullBufferConstraint`

NotNullConstraint is used to check both null and non-null of a
pointer.  So the name, which was created originally for just checking
non-nullness, becomes less suitable.

The same reason applies to `NotNullBufferConstraint`.
---
 .../Checkers/StdLibraryFunctionsChecker.cpp   | 38 +--
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index fef19b4547555..3542b7c8aaf30 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -367,13 +367,13 @@ class StdLibraryFunctionsChecker
   };
 
   /// Check null or non-null-ness of an argument that is of pointer type.
-  class NotNullConstraint : public ValueConstraint {
+  class NullnessConstraint : public ValueConstraint {
 using ValueConstraint::ValueConstraint;
 // This variable has a role when we negate the constraint.
 bool CannotBeNull = true;
 
   public:
-NotNullConstraint(ArgNo ArgN, bool CannotBeNull = true)
+NullnessConstraint(ArgNo ArgN, bool CannotBeNull = true)
 : ValueConstraint(ArgN), CannotBeNull(CannotBeNull) {}
 
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
@@ -389,9 +389,9 @@ class StdLibraryFunctionsChecker
llvm::raw_ostream &Out) const override;
 
 ValueConstraintPtr negate() const override {
-  NotNullConstraint Tmp(*this);
+  NullnessConstraint Tmp(*this);
   Tmp.CannotBeNull = !this->CannotBeNull;
-  return std::make_shared(Tmp);
+  return std::make_shared(Tmp);
 }
 
   protected:
@@ -407,9 +407,9 @@ class StdLibraryFunctionsChecker
   /// The argument is meant to be a buffer that has a size constraint, and it
   /// is allowed to have a NULL value if the size is 0. The size can depend on
   /// 1 or 2 additional arguments, if one of these is 0 the buffer is allowed 
to
-  /// be NULL. This is useful for functions like `fread` which have this 
special
-  /// property.
-  class NotNullBufferConstraint : public ValueConstraint {
+  /// be NULL. Otherwise, the buffer pointer must be non-null. This is useful
+  /// for functions like `fread` which have this special property.
+  class BufferNullnessConstraint : public ValueConstraint {
 using ValueConstraint::ValueConstraint;
 ArgNo SizeArg1N;
 std::optional SizeArg2N;
@@ -417,7 +417,7 @@ class StdLibraryFunctionsChecker
 bool CannotBeNull = true;
 
   public:
-NotNullBufferConstraint(ArgNo ArgN, ArgNo SizeArg1N,
+BufferNullnessConstraint(ArgNo ArgN, ArgNo SizeArg1N,
 std::optional SizeArg2N,
 bool CannotBeNull = true)
 : ValueConstraint(ArgN), SizeArg1N(SizeArg1N), SizeArg2N(SizeArg2N),
@@ -436,9 +436,9 @@ class StdLibraryFunctionsChecker
llvm::raw_ostream &Out) const override;
 
 ValueConstraintPtr negate() const override {
-  NotNullBufferConstraint Tmp(*this);
+  BufferNullnessConstraint Tmp(*this);
   Tmp.CannotBeNull = !this->CannotBeNull;
-  return std::make_shared(Tmp);
+  return std::make_shared(Tmp);
 }
 
   protected:
@@ -1151,7 +1151,7 @@ ProgramStateRef 
StdLibraryFunctionsChecker::ComparisonConstraint::apply(
   return State;
 }
 
-ProgramStateRef StdLibraryFunctionsChecker::NotNullConstraint::apply(
+ProgramStateRef StdLibraryFunctionsChecker::NullnessConstraint::apply(
 ProgramStateRef State, const CallEvent &Call, const Summary &Summary,
 CheckerContext &C) const {
   SVal V = getArgSVal(Call, getArgNo());
@@ -1165,7 +1165,7 @@ ProgramStateRef 
StdLibraryFunctionsChecker::NotNullConstraint::apply(
   return State->assume(L, CannotBeNull);
 }
 
-void StdLibraryFunctionsChecker::NotNullConstraint::describe(
+void StdLibraryFunctionsChecker::NullnessConstraint::describe(
 DescriptionKind DK, const CallEvent &Call, ProgramStateRef State,
 const Summary &Summary, llvm::raw_ostream &Out) const {
   assert(CannotBeNull &&
@@ -1176,7 +1176,7 @@ void 
StdLibraryFunctionsChecker::NotNullConstraint::describe(
 Out << "is not NULL";
 }
 
-bool StdLibraryFunctionsChecker::NotNullConstraint::describeArgumentValue(
+bool StdLibraryFunctionsChecker::NullnessConstraint::describeArgumentValue(
 const CallEvent &Call, ProgramStateRef State, const Summary &Summary,
 llvm::raw_ostream &Out) const {
   assert(!CannotBeNull && "This function is used when the value is NULL");
@@ -1184,7 +1184,7 @@ bool 
StdLibraryFunctionsChecker::NotNullConstraint::

[clang] [NFC][Static Analyzer] Rename and discuss about `NotNullConstraint` & `NotNullBufferConstraint` (PR #131374)

2025-03-24 Thread Balázs Kéri via cfe-commits


@@ -1165,7 +1165,7 @@ ProgramStateRef 
StdLibraryFunctionsChecker::NotNullConstraint::apply(
   return State->assume(L, CannotBeNull);
 }
 
-void StdLibraryFunctionsChecker::NotNullConstraint::describe(
+void StdLibraryFunctionsChecker::NullnessConstraint::describe(
 DescriptionKind DK, const CallEvent &Call, ProgramStateRef State,
 const Summary &Summary, llvm::raw_ostream &Out) const {
   assert(CannotBeNull &&

balazske wrote:

Technically it is not an error to use the describe functions on any constraint, 
the assertion indicates only a not implemented (and not used) case. We can 
remove the assertion and print out a text like "" 
as description.

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


[clang] 449cdfa - Suppress pedantic diagnostic for a file not ending in EOL (#131794)

2025-03-24 Thread via cfe-commits

Author: Aaron Ballman
Date: 2025-03-19T07:49:16-04:00
New Revision: 449cdfacc07bd365d49a637196ce8f8067cf845c

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

LOG: Suppress pedantic diagnostic for a file not ending in EOL (#131794)

WG14 added N3411 to the list of papers which apply to older versions of
C in C2y, and WG21 adopted CWG787 as a Defect Report in C++11. So we no
longer should be issuing a pedantic diagnostic about a file which does
not end with a newline character.

We do, however, continue to support -Wnewline-eof as an opt-in
diagnostic.

Added: 
clang/test/CXX/drs/cwg787.cpp

Modified: 
clang-tools-extra/clangd/Preamble.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/test/C/C2y/n3411.c
clang/test/Lexer/newline-eof.c

Removed: 
clang/test/Lexer/newline-eof-c++98-compat.cpp



diff  --git a/clang-tools-extra/clangd/Preamble.cpp 
b/clang-tools-extra/clangd/Preamble.cpp
index b634981bb46bd..6fab3e2191426 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -627,10 +627,8 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
   return DiagnosticsEngine::Ignored;
 switch (Info.getID()) {
 case diag::warn_no_newline_eof:
-case diag::warn_cxx98_compat_no_newline_eof:
-case diag::ext_no_newline_eof:
   // If the preamble doesn't span the whole file, drop the no newline at
-  // eof warnings.
+  // eof warning.
   return Bounds.Size != ContentsBuffer->getBufferSize()
  ? DiagnosticsEngine::Level::Ignored
  : DiagLevel;

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 867ce60207b9d..075bcc64b1c59 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -130,8 +130,10 @@ C2y Feature Support
   that ``_Generic`` selection associations may now have ``void`` type, but it
   also removes UB with code like ``(void)(void)1;``.
 - Implemented `WG14 N3411 
`_
-  which allows a source file to not end with a newline character. This is still
-  reported as a conforming extension in earlier language modes.
+  which allows a source file to not end with a newline character. Note,
+  ``-pedantic`` will no longer diagnose this in either C or C++ modes. This
+  feature was adopted as applying to obsolete versions of C in WG14 and as a
+  defect report in WG21 (CWG787).
 - Implemented `WG14 N3353 
_`
   which adds the new ``0o`` and ``0O`` ocal literal prefixes and deprecates
   octal literals other than ``0`` which do not start with the new prefix. This

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index bdb7e9350b5f7..912b8bd46e194 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -52,15 +52,9 @@ def ext_multi_line_line_comment : Extension<"multi-line // 
comment">,
 def ext_line_comment : Extension<
   "// comments are not allowed in this language">,
   InGroup;
-def ext_no_newline_eof : Extension<"no newline at end of file">,
-  InGroup;
 def warn_no_newline_eof : Warning<"no newline at end of file">,
   InGroup, DefaultIgnore;
 
-def warn_cxx98_compat_no_newline_eof : Warning<
-  "C++98 requires newline at end of file">,
-  InGroup, DefaultIgnore;
-
 def ext_dollar_in_identifier : Extension<"'$' in identifier">,
   InGroup>;
 def ext_charize_microsoft : Extension<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 96d5d4f440768..3128627490e28 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -3187,28 +3187,12 @@ bool Lexer::LexEndOfFile(Token &Result, const char 
*CurPtr) {
 ConditionalStack.pop_back();
   }
 
-  // C99 5.1.1.2p2: If the file is non-empty and didn't end in a newline, issue
-  // a pedwarn.
-  if (CurPtr != BufferStart && (CurPtr[-1] != '\n' && CurPtr[-1] != '\r')) {
-DiagnosticsEngine &Diags = PP->getDiagnostics();
-SourceLocation EndLoc = getSourceLocation(BufferEnd);
-unsigned DiagID = diag::warn_no_newline_eof;
-
-if (LangOpts.CPlusPlus11) {
-  // C++11 [lex.phases] 2.2 p2
-  // Prefer the C++98 pedantic compatibility warning over the generic,
-  // non-extension, user-requested "missing newline at EOF" warning.
-  if (!Diags.isIgnored(diag::warn_cxx98_compat_no_newline_eof, EndLoc))
-DiagID = diag::warn_cxx98_compat_no_newline_eof;
-} else {
-  // This is conforming in C2y, but is an extension in earlier language
-  // modes.
-  if (!LangOpts.C2y)
-DiagID = diag::e

[clang-tools-extra] [clang-doc] Add regression test for test comments in macros (PR #132510)

2025-03-24 Thread Paul Kirth via cfe-commits

ilovepi wrote:

> @ilovepi I am not familiar with PR, so accidentally closed the previous PR. 
> This is a new one. Sorry for that.

It's fine. IIRC you can reopen one pretty easily, but 🤷 Its no problem.


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


[clang] da7f156 - [clang-format] Don't wrap before attributes in parameter lists (#132519)

2025-03-24 Thread via cfe-commits

Author: Owen Pan
Date: 2025-03-24T19:18:13-07:00
New Revision: da7f1564a82e431dfbbf5b8d0bd53c64c5ca6af9

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

LOG: [clang-format] Don't wrap before attributes in parameter lists (#132519)

Fix #132240

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 35577cd6db7a1..01bf8c3778928 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4078,6 +4078,7 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
   }
 
   bool InFunctionDecl = Line.MightBeFunctionDecl;
+  bool InParameterList = false;
   for (auto *Current = First->Next; Current; Current = Current->Next) {
 const FormatToken *Prev = Current->Previous;
 if (Current->is(TT_LineComment)) {
@@ -4132,6 +4133,19 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
 
 Current->CanBreakBefore =
 Current->MustBreakBefore || canBreakBefore(Line, *Current);
+
+if (Current->is(TT_FunctionDeclarationLParen)) {
+  InParameterList = true;
+} else if (Current->is(tok::r_paren)) {
+  const auto *LParen = Current->MatchingParen;
+  if (LParen && LParen->is(TT_FunctionDeclarationLParen))
+InParameterList = false;
+} else if (InParameterList &&
+   Current->endsSequence(TT_AttributeMacro,
+ TT_PointerOrReference)) {
+  Current->CanBreakBefore = false;
+}
+
 unsigned ChildSize = 0;
 if (Prev->Children.size() == 1) {
   FormatToken &LastOfChild = *Prev->Children[0]->Last;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 5df7865f5a629..0b90bd360b758 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12640,6 +12640,12 @@ TEST_F(FormatTest, UnderstandsAttributes) {
AfterType);
 
   FormatStyle CustomAttrs = getLLVMStyle();
+  CustomAttrs.AttributeMacros.push_back("my_attr_name");
+  verifyFormat("void MyGoodOldFunction(\n"
+   "void *const long_enough = nullptr,\n"
+   "void *my_attr_name even_longer = 
nullptr);",
+   CustomAttrs);
+
   CustomAttrs.AttributeMacros.push_back("__unused");
   CustomAttrs.AttributeMacros.push_back("__attr1");
   CustomAttrs.AttributeMacros.push_back("__attr2");



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


[clang-tools-extra] [clang-doc] Add regression test for test comments in macros (PR #132510)

2025-03-24 Thread Paul Kirth via cfe-commits

ilovepi wrote:

Ah, I see you deleted your repository, then yeah, that would make it hard to 
reopen.

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


[clang-tools-extra] [clang-doc] Add regression test for test comments in macros (PR #132510)

2025-03-24 Thread Paul Kirth via cfe-commits

ilovepi wrote:

>I am not familiar with PR, so accidentally closed the previous PR 
>https://github.com/llvm/llvm-project/pull/132360. This is a new one.

You can remove this part from the description. It isn't relevant to the rest of 
the project, and doesn't belong in the commit log.

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


[clang] [HIP] use offload wrapper for non-device-only non-rdc (PR #132869)

2025-03-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Yaxun (Sam) Liu (yxsamliu)


Changes

Currently HIP still uses offload bundler for non-rdc mode for the new offload 
driver.

This patch switches to use offload wrapper for non-device-only non-rdc mode 
when new offload driver is enabled.

This makes the rdc and non-rdc compilation more consistent and speeds up 
compilation since the offload wrapper supports parallel compilation for 
different GPU arch's.

It is implemented by adding a linker wrapper action for each assemble action of 
input file. Linker wrapper action differentiates this special type of work vs 
normal linker wrapper work by the fle type. This type of work results in object 
instead of image. The linker wrapper adds "-r" for it and only includes the 
object file as input, not the host libraries.

For device-only non-RDC mode, the new driver keeps the original behavior.

---

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


6 Files Affected:

- (modified) clang/lib/CodeGen/CGCUDANV.cpp (+2-1) 
- (modified) clang/lib/Driver/Driver.cpp (+31-10) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+15-4) 
- (modified) clang/test/Driver/hip-binding.hip (+3-3) 
- (modified) clang/test/Driver/hip-phases.hip (+31-20) 
- (modified) clang/test/Driver/hip-toolchain-no-rdc.hip (+50-31) 


``diff
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 5445a9278596d..395263331d141 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1281,7 +1281,8 @@ llvm::Function *CGNVCUDARuntime::finalizeModule() {
 return nullptr;
   }
   if (CGM.getLangOpts().OffloadViaLLVM ||
-  (CGM.getLangOpts().OffloadingNewDriver && RelocatableDeviceCode))
+  (CGM.getLangOpts().OffloadingNewDriver &&
+   (CGM.getLangOpts().HIP || RelocatableDeviceCode)))
 createOffloadingEntries();
   else
 return makeModuleCtorFunction();
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 056bfcf1b739a..6d63a55918687 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4402,6 +4402,10 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
options::OPT_no_offload_new_driver,
C.isOffloadingHostKind(Action::OFK_Cuda));
 
+  bool HIPNoRDC =
+  C.isOffloadingHostKind(Action::OFK_HIP) &&
+  !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
+
   // Builder to be used to build offloading actions.
   std::unique_ptr OffloadBuilder =
   !UseNewOffloadingDriver
@@ -4502,6 +4506,16 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 InputArg))
 break;
 
+  // For HIP non-rdc non-device-only compilation, create a linker wrapper
+  // action for each host object to link, bundle and wrap device files in
+  // it.
+  if (Phase == phases::Assemble && UseNewOffloadingDriver && HIPNoRDC &&
+  !offloadDeviceOnly()) {
+ActionList AL{Current};
+Current = C.MakeAction(AL, types::TY_Object);
+Current->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
+  /*BoundArch=*/nullptr);
+  }
   if (Current->getType() == types::TY_Nothing)
 break;
 }
@@ -4535,7 +4549,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // Check if this Linker Job should emit a static library.
 if (ShouldEmitStaticLibrary(Args)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
-} else if (UseNewOffloadingDriver ||
+} else if ((UseNewOffloadingDriver && !HIPNoRDC) ||
Args.hasArg(options::OPT_offload_link)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
   LA->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
@@ -4945,12 +4959,15 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
   }
 }
 
-// Compiling HIP in non-RDC mode requires linking each action individually.
+// Compiling HIP in device-only non-RDC mode requires linking each action
+// individually.
 for (Action *&A : DeviceActions) {
   if ((A->getType() != types::TY_Object &&
A->getType() != types::TY_LTO_BC) ||
   Kind != Action::OFK_HIP ||
-  Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false))
+  Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
+   false) ||
+  !offloadDeviceOnly())
 continue;
   ActionList LinkerInput = {A};
   A = C.MakeAction(LinkerInput, types::TY_Image);
@@ -4974,9 +4991,10 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
 }
   }
 
-  // HIP code in non-RDC mode will bundle the output if it invoked the linker.
+  // HIP code in device-only non-RDC mode will bundle the output if 

[clang] [HIP] use offload wrapper for non-device-only non-rdc (PR #132869)

2025-03-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yaxun (Sam) Liu (yxsamliu)


Changes

Currently HIP still uses offload bundler for non-rdc mode for the new offload 
driver.

This patch switches to use offload wrapper for non-device-only non-rdc mode 
when new offload driver is enabled.

This makes the rdc and non-rdc compilation more consistent and speeds up 
compilation since the offload wrapper supports parallel compilation for 
different GPU arch's.

It is implemented by adding a linker wrapper action for each assemble action of 
input file. Linker wrapper action differentiates this special type of work vs 
normal linker wrapper work by the fle type. This type of work results in object 
instead of image. The linker wrapper adds "-r" for it and only includes the 
object file as input, not the host libraries.

For device-only non-RDC mode, the new driver keeps the original behavior.

---

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


6 Files Affected:

- (modified) clang/lib/CodeGen/CGCUDANV.cpp (+2-1) 
- (modified) clang/lib/Driver/Driver.cpp (+31-10) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+15-4) 
- (modified) clang/test/Driver/hip-binding.hip (+3-3) 
- (modified) clang/test/Driver/hip-phases.hip (+31-20) 
- (modified) clang/test/Driver/hip-toolchain-no-rdc.hip (+50-31) 


``diff
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 5445a9278596d..395263331d141 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1281,7 +1281,8 @@ llvm::Function *CGNVCUDARuntime::finalizeModule() {
 return nullptr;
   }
   if (CGM.getLangOpts().OffloadViaLLVM ||
-  (CGM.getLangOpts().OffloadingNewDriver && RelocatableDeviceCode))
+  (CGM.getLangOpts().OffloadingNewDriver &&
+   (CGM.getLangOpts().HIP || RelocatableDeviceCode)))
 createOffloadingEntries();
   else
 return makeModuleCtorFunction();
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 056bfcf1b739a..6d63a55918687 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4402,6 +4402,10 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
options::OPT_no_offload_new_driver,
C.isOffloadingHostKind(Action::OFK_Cuda));
 
+  bool HIPNoRDC =
+  C.isOffloadingHostKind(Action::OFK_HIP) &&
+  !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
+
   // Builder to be used to build offloading actions.
   std::unique_ptr OffloadBuilder =
   !UseNewOffloadingDriver
@@ -4502,6 +4506,16 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 InputArg))
 break;
 
+  // For HIP non-rdc non-device-only compilation, create a linker wrapper
+  // action for each host object to link, bundle and wrap device files in
+  // it.
+  if (Phase == phases::Assemble && UseNewOffloadingDriver && HIPNoRDC &&
+  !offloadDeviceOnly()) {
+ActionList AL{Current};
+Current = C.MakeAction(AL, types::TY_Object);
+Current->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
+  /*BoundArch=*/nullptr);
+  }
   if (Current->getType() == types::TY_Nothing)
 break;
 }
@@ -4535,7 +4549,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // Check if this Linker Job should emit a static library.
 if (ShouldEmitStaticLibrary(Args)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
-} else if (UseNewOffloadingDriver ||
+} else if ((UseNewOffloadingDriver && !HIPNoRDC) ||
Args.hasArg(options::OPT_offload_link)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
   LA->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
@@ -4945,12 +4959,15 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
   }
 }
 
-// Compiling HIP in non-RDC mode requires linking each action individually.
+// Compiling HIP in device-only non-RDC mode requires linking each action
+// individually.
 for (Action *&A : DeviceActions) {
   if ((A->getType() != types::TY_Object &&
A->getType() != types::TY_LTO_BC) ||
   Kind != Action::OFK_HIP ||
-  Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false))
+  Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
+   false) ||
+  !offloadDeviceOnly())
 continue;
   ActionList LinkerInput = {A};
   A = C.MakeAction(LinkerInput, types::TY_Image);
@@ -4974,9 +4991,10 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
 }
   }
 
-  // HIP code in non-RDC mode will bundle the output if it invoked the linker.
+  // HIP code in device-only non-RDC mode will bundle the output if it invo

[clang] [Clang][AMDGPU] Use size_t to compare with npos (PR #132868)

2025-03-24 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-clang

Author: Jinsong Ji (jsji)


Changes

Fix error

llvm\clang\tools\amdgpu-arch\AMDGPUArchByHIP.cpp(102,29): error: result of 
comparison of constant 18446744073709551615 with expression of type 'unsigned 
int' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
102 | StringRef VerStr = (Pos == StringRef::npos) ? S : S.substr(Pos + 1);


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


1 Files Affected:

- (modified) clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp (+1-1) 


``diff
diff --git a/clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp 
b/clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp
index 4803f83f55ac7..02431bf909d6d 100644
--- a/clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp
+++ b/clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp
@@ -98,7 +98,7 @@ static std::vector getSearchPaths() {
 // Custom comparison function for dll name
 static bool compareVersions(StringRef A, StringRef B) {
   auto ParseVersion = [](StringRef S) -> VersionTuple {
-unsigned Pos = S.find_last_of('_');
+size_t Pos = S.find_last_of('_');
 StringRef VerStr = (Pos == StringRef::npos) ? S : S.substr(Pos + 1);
 VersionTuple Vt;
 (void)Vt.tryParse(VerStr);

``




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


[clang] [Clang][AMDGPU] Use size_t to compare with npos (PR #132868)

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

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


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


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-24 Thread Sean Perry via cfe-commits


@@ -4456,6 +4456,12 @@ void Parser::ParseDeclarationSpecifiers(
   isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID);
   break;
 
+case tok::kw__Export:
+  // If we find kw__Export, it is being applied to a var or function
+  // This will be handled in ParseDeclaratorInternal()

perry-ca wrote:

The _Export keyword is part of the declarator.  This code is to stop the 
declspec parsing.  For example, in `int _Export x,y;` only `x` is exported.  
The flag was added to the DeclSpec class to handle the case of `class _Export 
A`.  That is later passed on to the Decl for the class.  If there is a better 
way to do this, I'd be interested.  We do have to match the existing XL 
compiler for backwards compatibility.

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


[clang-tools-extra] [clang-doc] [feat] add --repository-line-prefix argument (PR #131280)

2025-03-24 Thread Mohamed Emad via cfe-commits

hulxv wrote:

@ilovepi 
About `writeFileDefiniation`, what's your opinion about making it similar to 
the markdown generator like this?
```cpp
static void writeFileDefinition(const ClangDocContext &CDCtx, const Location 
&L);
```
I think it's more better

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


[clang] [flang] [flang] Add -f[no-]slp-vectorize flags (PR #132801)

2025-03-24 Thread Tarun Prabhu via cfe-commits

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


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


[clang] [flang] [flang] Add -f[no-]slp-vectorize flags (PR #132801)

2025-03-24 Thread Tarun Prabhu via cfe-commits


@@ -4032,11 +4032,14 @@ def : Flag<["-"], "ftree-vectorize">, Alias;
 def : Flag<["-"], "fno-tree-vectorize">, Alias;
 }
 
+let Visibility = [ClangOption, FlangOption] in {

tarunprabhu wrote:

I think we should merge this with the visibility block for `fvectorize` above. 
The options are related anyway.

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


[clang] [flang] [flang] Add -f[no-]slp-vectorize flags (PR #132801)

2025-03-24 Thread Tarun Prabhu via cfe-commits


@@ -0,0 +1,10 @@
+! RUN: %flang -### -S -fslp-vectorize %s 2>&1 | FileCheck 
-check-prefix=CHECK-SLP-VECTORIZE %s
+! RUN: %flang -### -S -fno-slp-vectorize %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-SLP-VECTORIZE %s
+! RUN: %flang -### -S -O1 %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-SLP-VECTORIZE %s
+! RUN: %flang -### -S -O2 %s 2>&1 | FileCheck 
-check-prefix=CHECK-SLP-VECTORIZE %s
+! RUN: %flang -### -S -O3 %s 2>&1 | FileCheck 
-check-prefix=CHECK-SLP-VECTORIZE %s

tarunprabhu wrote:

Could you also add tests for `-Os` and `-Oz`? May also be worth adding `-O0`.

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


[clang] [flang] [flang] Add -f[no-]slp-vectorize flags (PR #132801)

2025-03-24 Thread Tarun Prabhu via cfe-commits


@@ -161,6 +161,14 @@ void Flang::addCodegenOptions(const ArgList &Args,
options::OPT_fno_vectorize, enableVec))
 CmdArgs.push_back("-vectorize-loops");
 
+  // -fslp-vectorize is enabled based on the optimization level selected.
+  bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true);
+  OptSpecifier SLPVectAliasOption =
+  EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize;
+  if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption,
+   options::OPT_fno_slp_vectorize, EnableSLPVec))
+CmdArgs.push_back("-vectorize-slp");
+

tarunprabhu wrote:

I think this block and the one above it that adds the `-vectorize-loops` `-fc1` 
option can be shared between `clang` and `flang`. The corresponding code in 
clang is 
[here](https://github.com/llvm/llvm-project/blob/8d3dc1ed5656a3e69e4195d58684a7f4bf0ff5cc/clang/lib/Driver/ToolChains/Clang.cpp#L7600).
 Such code is typically moved to `clang/lib/Driver/ToolChains/CommonArgs.cpp`. 
It's probably better to share it rather than duplicate it. See, for example, 
[this](https://github.com/llvm/llvm-project/pull/109210/files)

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


[clang] [HLSL] Finish exposing half types and intrinsics always (PR #132804)

2025-03-24 Thread Chris B via cfe-commits

llvm-beanz wrote:

> Finish the work of #81782

Maybe instead:

> Apply pattern of #81782 to intrinsics added in #95999.

Also probably worth having a description of the problem this solves in the 
description so that it ends up in the final commit message.

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


[clang] [HLSL] Finish exposing half types and intrinsics always (PR #132804)

2025-03-24 Thread Sarah Spall via cfe-commits

spall wrote:

> Are there any test changes we should consider here? If not could you prefix 
> `[NFC]` to the title?

It looked to me like the tests were all correct based on what was done in the 
reference PR

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


  1   2   3   4   5   >