[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-07 Thread Yanzuo Liu via cfe-commits


@@ -365,3 +365,9 @@ void test19(long long x)
   // FIXME: This case should be supported by codegen, but it fails now.
   asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: 
input with type 'st_size128' (aka 'struct _st_size128') matching output with 
type 'long long'}}
 }
+
+// PR119098
+void test20(char x) {
+  double value;
+  asm ("fabs" : "=t" (value): "0" (x)); // expected-error {{unsupported inline 
asm: input with type 'char' matching output with type 'double'}}
+}

zwuis wrote:

nit: add a new line character at EOF

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


[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-07 Thread Yanzuo Liu via cfe-commits


@@ -365,3 +365,9 @@ void test19(long long x)
   // FIXME: This case should be supported by codegen, but it fails now.
   asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: 
input with type 'st_size128' (aka 'struct _st_size128') matching output with 
type 'long long'}}
 }
+
+// PR119098

zwuis wrote:

```suggestion
// GH118892
```


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


[clang] [clang][perf-training] Fix profiling with -DCLANG_BOLT=perf (PR #119117)

2024-12-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Tom Stellard (tstellar)


Changes

This fixes the llvm-support build that generates the profile data. However, I'm 
wondering if maybe we should disable llvm-suppot and only run hello-world with 
-DCLANG_BOLT=perf.  The bolt optimizations with perf only give about a 3% 
performance increase (although maybe with hw counters this would be better) and 
it takes a very long time to convert all the perf profiles to the fdata format.

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


2 Files Affected:

- (modified) clang/utils/perf-training/bolt.lit.cfg (+18-4) 
- (modified) clang/utils/perf-training/llvm-support/build.test (+2-2) 


``diff
diff --git a/clang/utils/perf-training/bolt.lit.cfg 
b/clang/utils/perf-training/bolt.lit.cfg
index 1d0cf9a8a17a8e..7687a5a5cd2e68 100644
--- a/clang/utils/perf-training/bolt.lit.cfg
+++ b/clang/utils/perf-training/bolt.lit.cfg
@@ -8,21 +8,32 @@ import subprocess
 
 clang_bolt_mode = config.clang_bolt_mode.lower()
 clang_binary = "clang"
-perf_wrapper = f"{config.python_exe} {config.perf_helper_dir}/perf-helper.py 
perf "
+perf_wrapper = f"{config.python_exe} {config.perf_helper_dir}/perf-helper.py 
perf"
 
 if clang_bolt_mode == "instrument":
 perf_wrapper = ""
 clang_binary = config.clang_bolt_name
 elif clang_bolt_mode == "lbr":
-perf_wrapper += " --lbr -- "
+perf_wrapper += " --lbr --"
 elif clang_bolt_mode == "perf":
-perf_wrapper += " -- "
+perf_wrapper += " --"
 else:
 assert 0, "Unsupported CLANG_BOLT_MODE variable"
 
-config.clang = perf_wrapper + os.path.realpath(
+clang_nowrapper = os.path.realpath(
 lit.util.which(clang_binary, config.clang_tools_dir)
 ).replace("\\", "/")
+config.clang = f'{perf_wrapper} {clang_nowrapper}'
+
+# We need to limit the number of build jobs with perf in order to avoid this
+# error:
+# 
+# | Permission error mapping pages.
+# | Consider increasing /proc/sys/kernel/perf_event_mlock_kb,
+# | or try again with a smaller value of -m/--mmap_pages.
+ninja_args = ""
+if ninja_args != "instrument":
+ninja_args = "-j1"
 
 config.name = "Clang Perf Training"
 config.suffixes = [
@@ -52,3 +63,6 @@ config.substitutions.append(("%test_root", 
config.test_exec_root))
 config.substitutions.append(('%cmake_generator', config.cmake_generator))
 config.substitutions.append(('%cmake', config.cmake_exe))
 config.substitutions.append(('%llvm_src_dir', config.llvm_src_dir))
+config.substitutions.append(('%perf_cmake_compiler_launcher', 
perf_wrapper.replace(' ', ';')))
+config.substitutions.append(('%nowrapper_clang', clang_nowrapper))
+config.substitutions.append(('%ninja_args', ninja_args))
diff --git a/clang/utils/perf-training/llvm-support/build.test 
b/clang/utils/perf-training/llvm-support/build.test
index f29a594c846869..1f4d76502a3757 100644
--- a/clang/utils/perf-training/llvm-support/build.test
+++ b/clang/utils/perf-training/llvm-support/build.test
@@ -1,2 +1,2 @@
-RUN: %cmake -G %cmake_generator -B %t -S %llvm_src_dir 
-DCMAKE_C_COMPILER=%clang -DCMAKE_CXX_COMPILER=%clang 
-DCMAKE_CXX_FLAGS="--driver-mode=g++" -DCMAKE_BUILD_TYPE=Release
-RUN: %cmake --build %t -v --target LLVMSupport
+RUN: %cmake -G %cmake_generator -B %t -S %llvm_src_dir 
-DCMAKE_CXX_COMPILER_LAUNCHER="%perf_cmake_compiler_launcher" 
-DCMAKE_C_COMPILER="%nowrapper_clang" -DCMAKE_CXX_COMPILER="%nowrapper_clang" 
-DCMAKE_CXX_FLAGS="--driver-mode=g++" -DCMAKE_BUILD_TYPE=Release
+RUN: %cmake --build %t %ninja_args -v --target LLVMSupport

``




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


[clang] [clang][perf-training] Fix profiling with -DCLANG_BOLT=perf (PR #119117)

2024-12-07 Thread Tom Stellard via cfe-commits

https://github.com/tstellar created 
https://github.com/llvm/llvm-project/pull/119117

This fixes the llvm-support build that generates the profile data. However, I'm 
wondering if maybe we should disable llvm-suppot and only run hello-world with 
-DCLANG_BOLT=perf.  The bolt optimizations with perf only give about a 3% 
performance increase (although maybe with hw counters this would be better) and 
it takes a very long time to convert all the perf profiles to the fdata format.

>From 1760788d8decf90791044e199564e8336110b713 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Thu, 5 Dec 2024 15:01:27 +
Subject: [PATCH] [clang][perf-training] Fix profiling with -DCLANG_BOLT=perf

This fixes the llvm-support build that generates the profile data.
However, I'm wondering if maybe we should disable llvm-suppot and
only run hello-world with -DCLANG_BOLT=perf.  The bolt optimizations
with perf only give about a 3% performance increase (although maybe
with hw counters this would be better) and it takes a very long
time to convert all the perf profiles to the fdata format.
---
 clang/utils/perf-training/bolt.lit.cfg| 22 +++
 .../perf-training/llvm-support/build.test |  4 ++--
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/clang/utils/perf-training/bolt.lit.cfg 
b/clang/utils/perf-training/bolt.lit.cfg
index 1d0cf9a8a17a8e..7687a5a5cd2e68 100644
--- a/clang/utils/perf-training/bolt.lit.cfg
+++ b/clang/utils/perf-training/bolt.lit.cfg
@@ -8,21 +8,32 @@ import subprocess
 
 clang_bolt_mode = config.clang_bolt_mode.lower()
 clang_binary = "clang"
-perf_wrapper = f"{config.python_exe} {config.perf_helper_dir}/perf-helper.py 
perf "
+perf_wrapper = f"{config.python_exe} {config.perf_helper_dir}/perf-helper.py 
perf"
 
 if clang_bolt_mode == "instrument":
 perf_wrapper = ""
 clang_binary = config.clang_bolt_name
 elif clang_bolt_mode == "lbr":
-perf_wrapper += " --lbr -- "
+perf_wrapper += " --lbr --"
 elif clang_bolt_mode == "perf":
-perf_wrapper += " -- "
+perf_wrapper += " --"
 else:
 assert 0, "Unsupported CLANG_BOLT_MODE variable"
 
-config.clang = perf_wrapper + os.path.realpath(
+clang_nowrapper = os.path.realpath(
 lit.util.which(clang_binary, config.clang_tools_dir)
 ).replace("\\", "/")
+config.clang = f'{perf_wrapper} {clang_nowrapper}'
+
+# We need to limit the number of build jobs with perf in order to avoid this
+# error:
+# 
+# | Permission error mapping pages.
+# | Consider increasing /proc/sys/kernel/perf_event_mlock_kb,
+# | or try again with a smaller value of -m/--mmap_pages.
+ninja_args = ""
+if ninja_args != "instrument":
+ninja_args = "-j1"
 
 config.name = "Clang Perf Training"
 config.suffixes = [
@@ -52,3 +63,6 @@ config.substitutions.append(("%test_root", 
config.test_exec_root))
 config.substitutions.append(('%cmake_generator', config.cmake_generator))
 config.substitutions.append(('%cmake', config.cmake_exe))
 config.substitutions.append(('%llvm_src_dir', config.llvm_src_dir))
+config.substitutions.append(('%perf_cmake_compiler_launcher', 
perf_wrapper.replace(' ', ';')))
+config.substitutions.append(('%nowrapper_clang', clang_nowrapper))
+config.substitutions.append(('%ninja_args', ninja_args))
diff --git a/clang/utils/perf-training/llvm-support/build.test 
b/clang/utils/perf-training/llvm-support/build.test
index f29a594c846869..1f4d76502a3757 100644
--- a/clang/utils/perf-training/llvm-support/build.test
+++ b/clang/utils/perf-training/llvm-support/build.test
@@ -1,2 +1,2 @@
-RUN: %cmake -G %cmake_generator -B %t -S %llvm_src_dir 
-DCMAKE_C_COMPILER=%clang -DCMAKE_CXX_COMPILER=%clang 
-DCMAKE_CXX_FLAGS="--driver-mode=g++" -DCMAKE_BUILD_TYPE=Release
-RUN: %cmake --build %t -v --target LLVMSupport
+RUN: %cmake -G %cmake_generator -B %t -S %llvm_src_dir 
-DCMAKE_CXX_COMPILER_LAUNCHER="%perf_cmake_compiler_launcher" 
-DCMAKE_C_COMPILER="%nowrapper_clang" -DCMAKE_CXX_COMPILER="%nowrapper_clang" 
-DCMAKE_CXX_FLAGS="--driver-mode=g++" -DCMAKE_BUILD_TYPE=Release
+RUN: %cmake --build %t %ninja_args -v --target LLVMSupport

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


[clang] [clang][perf-training] Fix profiling with -DCLANG_BOLT=perf (PR #119117)

2024-12-07 Thread Tom Stellard via cfe-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/119117

>From 5d13b69039fab7c5960288cead18dc76f5d01f4f Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Thu, 5 Dec 2024 15:01:27 +
Subject: [PATCH] [clang][perf-training] Fix profiling with -DCLANG_BOLT=perf

This fixes the llvm-support build that generates the profile data.
However, I'm wondering if maybe we should disable llvm-suppot and
only run hello-world with -DCLANG_BOLT=perf.  The bolt optimizations
with perf only give about a 3% performance increase (although maybe
with hw counters this would be better) and it takes a very long
time to convert all the perf profiles to the fdata format.
---
 clang/utils/perf-training/bolt.lit.cfg| 22 +++
 .../perf-training/llvm-support/build.test |  4 ++--
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/clang/utils/perf-training/bolt.lit.cfg 
b/clang/utils/perf-training/bolt.lit.cfg
index 1d0cf9a8a17a8e..04b18975275495 100644
--- a/clang/utils/perf-training/bolt.lit.cfg
+++ b/clang/utils/perf-training/bolt.lit.cfg
@@ -8,21 +8,32 @@ import subprocess
 
 clang_bolt_mode = config.clang_bolt_mode.lower()
 clang_binary = "clang"
-perf_wrapper = f"{config.python_exe} {config.perf_helper_dir}/perf-helper.py 
perf "
+perf_wrapper = f"{config.python_exe} {config.perf_helper_dir}/perf-helper.py 
perf"
 
 if clang_bolt_mode == "instrument":
 perf_wrapper = ""
 clang_binary = config.clang_bolt_name
 elif clang_bolt_mode == "lbr":
-perf_wrapper += " --lbr -- "
+perf_wrapper += " --lbr --"
 elif clang_bolt_mode == "perf":
-perf_wrapper += " -- "
+perf_wrapper += " --"
 else:
 assert 0, "Unsupported CLANG_BOLT_MODE variable"
 
-config.clang = perf_wrapper + os.path.realpath(
+clang_nowrapper = os.path.realpath(
 lit.util.which(clang_binary, config.clang_tools_dir)
 ).replace("\\", "/")
+config.clang = f'{perf_wrapper} {clang_nowrapper}'
+
+# We need to limit the number of build jobs with perf in order to avoid this
+# error:
+# 
+# | Permission error mapping pages.
+# | Consider increasing /proc/sys/kernel/perf_event_mlock_kb,
+# | or try again with a smaller value of -m/--mmap_pages.
+ninja_args = ""
+if clang_bolt_mode != "instrument":
+ninja_args = "-j1"
 
 config.name = "Clang Perf Training"
 config.suffixes = [
@@ -52,3 +63,6 @@ config.substitutions.append(("%test_root", 
config.test_exec_root))
 config.substitutions.append(('%cmake_generator', config.cmake_generator))
 config.substitutions.append(('%cmake', config.cmake_exe))
 config.substitutions.append(('%llvm_src_dir', config.llvm_src_dir))
+config.substitutions.append(('%perf_cmake_compiler_launcher', 
perf_wrapper.replace(' ', ';')))
+config.substitutions.append(('%nowrapper_clang', clang_nowrapper))
+config.substitutions.append(('%ninja_args', ninja_args))
diff --git a/clang/utils/perf-training/llvm-support/build.test 
b/clang/utils/perf-training/llvm-support/build.test
index f29a594c846869..1f4d76502a3757 100644
--- a/clang/utils/perf-training/llvm-support/build.test
+++ b/clang/utils/perf-training/llvm-support/build.test
@@ -1,2 +1,2 @@
-RUN: %cmake -G %cmake_generator -B %t -S %llvm_src_dir 
-DCMAKE_C_COMPILER=%clang -DCMAKE_CXX_COMPILER=%clang 
-DCMAKE_CXX_FLAGS="--driver-mode=g++" -DCMAKE_BUILD_TYPE=Release
-RUN: %cmake --build %t -v --target LLVMSupport
+RUN: %cmake -G %cmake_generator -B %t -S %llvm_src_dir 
-DCMAKE_CXX_COMPILER_LAUNCHER="%perf_cmake_compiler_launcher" 
-DCMAKE_C_COMPILER="%nowrapper_clang" -DCMAKE_CXX_COMPILER="%nowrapper_clang" 
-DCMAKE_CXX_FLAGS="--driver-mode=g++" -DCMAKE_BUILD_TYPE=Release
+RUN: %cmake --build %t %ninja_args -v --target LLVMSupport

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


[clang] FunctionDecl::getFunctionTypeLoc: ignore function type attributes (PR #118420)

2024-12-07 Thread Robert Dazi via cfe-commits

https://github.com/v01dXYZ updated 
https://github.com/llvm/llvm-project/pull/118420

>From b6f013097c0003e37800ad13b420e50e3c84511b Mon Sep 17 00:00:00 2001
From: v01dxyz 
Date: Tue, 3 Dec 2024 04:52:33 +0100
Subject: [PATCH 1/4] FunctionDecl::getFunctionTypeLoc: ignore function type
 attributes

---
 clang/lib/AST/Decl.cpp | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 741e908cf9bc56..7df66b3bb7e14d 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3876,8 +3876,17 @@ bool 
FunctionDecl::doesDeclarationForceExternallyVisibleDefinition() const {
 
 FunctionTypeLoc FunctionDecl::getFunctionTypeLoc() const {
   const TypeSourceInfo *TSI = getTypeSourceInfo();
-  return TSI ? TSI->getTypeLoc().IgnoreParens().getAs()
- : FunctionTypeLoc();
+
+  if (!TSI)
+return FunctionTypeLoc();
+
+  TypeLoc TL = TSI->getTypeLoc().IgnoreParens();
+
+  // ignore function type attributes
+  while (auto ATL = TL.getAs())
+TL = ATL.getModifiedLoc();
+
+  return TL.getAs();
 }
 
 SourceRange FunctionDecl::getReturnTypeSourceRange() const {

>From d5faa43a7e9c27d9493b9a171fe4d283952a5103 Mon Sep 17 00:00:00 2001
From: v01dxyz 
Date: Sun, 8 Dec 2024 02:16:44 +0100
Subject: [PATCH 2/4] tmp: Add test and replace ignore parens by getAsAdjusted

---
 clang/lib/AST/Decl.cpp   |  8 +--
 clang/unittests/AST/AttrTest.cpp | 40 
 2 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 7df66b3bb7e14d..2ec5f5753427de 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3880,13 +3880,7 @@ FunctionTypeLoc FunctionDecl::getFunctionTypeLoc() const 
{
   if (!TSI)
 return FunctionTypeLoc();
 
-  TypeLoc TL = TSI->getTypeLoc().IgnoreParens();
-
-  // ignore function type attributes
-  while (auto ATL = TL.getAs())
-TL = ATL.getModifiedLoc();
-
-  return TL.getAs();
+  return TSI->getTypeLoc().getAsAdjusted();
 }
 
 SourceRange FunctionDecl::getReturnTypeSourceRange() const {
diff --git a/clang/unittests/AST/AttrTest.cpp b/clang/unittests/AST/AttrTest.cpp
index 46c3f5729021ec..6cf879c4012510 100644
--- a/clang/unittests/AST/AttrTest.cpp
+++ b/clang/unittests/AST/AttrTest.cpp
@@ -86,6 +86,9 @@ TEST(Attr, AnnotateType) {
 struct S { int mem; };
 int [[clang::annotate_type("int")]]
 S::* [[clang::annotate_type("ptr_to_mem")]] ptr_to_member = &S::mem;
+
+// Function Type Attributes
+__attribute__((noreturn)) int f_noreturn();
   )cpp");
 
   {
@@ -153,6 +156,42 @@ TEST(Attr, AnnotateType) {
 EXPECT_EQ(IntTL.getType(), AST->getASTContext().IntTy);
   }
 
+  {
+const FunctionDecl *Func = getFunctionNode(AST.get(), "f_noreturn");
+const FunctionTypeLoc FTL = Func->getFunctionTypeLoc();
+const FunctionType *FT = FTL.getTypePtr();
+
+EXPECT_TRUE(FT->getExtInfo().getNoReturn());
+  }
+
+  // The following test verifies getFunctionTypeLoc returns a type
+  // which takes into account the attribute (instead of only the nake
+  // type).
+  //
+  // This is hard to do with C/C++ because it seems using a function
+  // type attribute with a C/C++ -function declaration only results
+  // with either:
+  //
+  // 1. It does NOT produce any AttributedType (for example it only
+  //   sets one flag of the FunctionType's ExtInfo, ie NoReturn).
+  // 2. It produces an AttributedType with modified type and
+  //   equivalent type that are equal (for example, that's what
+  //   happens with Calling Convention attributes).
+  //
+  // Fortunately, ObjC has one specific function type attribute that
+  // creates an AttributedType with different modified type and
+  // equivalent type.
+  auto AST_ObjC = buildASTFromCodeWithArgs(R"objc(
+__attribute__((ns_returns_retained)) id f();
+  )objc", {"-fobjc-arc",}, "input.mm");
+  {
+const FunctionDecl *f = getFunctionNode(AST_ObjC.get(), "f");
+const FunctionTypeLoc FTL = f->getFunctionTypeLoc();
+
+const FunctionType *FT = FTL.getTypePtr();
+EXPECT_TRUE(FT->getExtInfo().getProducesResult());
+  }
+
   // Test type annotation on an `__auto_type` type in C mode.
   AST = buildASTFromCodeWithArgs(R"c(
 __auto_type [[clang::annotate_type("auto")]] auto_var = 1;
@@ -166,6 +205,7 @@ TEST(Attr, AnnotateType) {
 AutoTypeLoc AutoTL;
 AssertAnnotatedAs(Var->getTypeSourceInfo()->getTypeLoc(), "auto", AutoTL);
   }
+
 }
 
 TEST(Attr, RegularKeywordAttribute) {

>From 7e647b98756f64fbcaccba808dae2abaf9bdb2d1 Mon Sep 17 00:00:00 2001
From: v01dxyz 
Date: Sun, 8 Dec 2024 02:55:33 +0100
Subject: [PATCH 3/4] tmp: getAsAdjusted use getModifiedLoc, replace the loop
 by a custom one

---
 clang/lib/AST/Decl.cpp | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 2ec5f5753427de..110ef70562c72d 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clan

[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-07 Thread Peng Huang via cfe-commits

https://github.com/phuang updated 
https://github.com/llvm/llvm-project/pull/118192

>From 206f8f800df7e51648ec00b110f2437dca5a3ff6 Mon Sep 17 00:00:00 2001
From: Peng Huang 
Date: Tue, 15 Oct 2024 13:39:03 -0400
Subject: [PATCH 1/2] Fix build error for OHOS

For ohos targets, libclang_rt.builtins.a, clang_rt.crtbegin.o and
clang_rt.crtend.o are installed in
clang/20/lib/${arch}-unknown-linux-ohos. However OHOS toolchain
search them in clang/20/lib/${arch}-linux-ohos folder. It causes
link error. Fix the problem by seaching both folders.
---
 clang/lib/Driver/ToolChains/OHOS.cpp | 60 
 1 file changed, 26 insertions(+), 34 deletions(-)

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

[clang-tools-extra] [clangd] Handle DeducedTemplateSpecializationType in HeuristicResolver (PR #119107)

2024-12-07 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/119107

Fixes https://github.com/clangd/clangd/issues/2227

>From 85307a28e99c596afb47059ddea6f1e574ca55bf Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sat, 7 Dec 2024 22:03:02 -0500
Subject: [PATCH] [clangd] Handle DeducedTemplateSpecializationType in
 HeuristicResolver

Fixes https://github.com/clangd/clangd/issues/2227
---
 clang-tools-extra/clangd/HeuristicResolver.cpp | 18 ++
 .../clangd/unittests/FindTargetTests.cpp   | 17 +
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clangd/HeuristicResolver.cpp 
b/clang-tools-extra/clangd/HeuristicResolver.cpp
index 26d54200eeffd2..9eb892e8e4a8ea 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.cpp
+++ b/clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -118,6 +118,16 @@ const Type *resolveDeclsToType(const std::vector &Decls,
   return nullptr;
 }
 
+TemplateName getReferencedTemplateName(const Type *T) {
+  if (const auto *TST = T->getAs()) {
+return TST->getTemplateName();
+  }
+  if (const auto *DTST = T->getAs()) {
+return DTST->getTemplateName();
+  }
+  return TemplateName();
+}
+
 // Helper function for HeuristicResolver::resolveDependentMember()
 // which takes a possibly-dependent type `T` and heuristically
 // resolves it to a CXXRecordDecl in which we can try name lookup.
@@ -142,12 +152,12 @@ CXXRecordDecl 
*HeuristicResolverImpl::resolveTypeToRecordDecl(const Type *T) {
   if (!T)
 return nullptr;
 
-  const auto *TST = T->getAs();
-  if (!TST)
+  TemplateName TN = getReferencedTemplateName(T);
+  if (TN.isNull())
 return nullptr;
 
-  const ClassTemplateDecl *TD = dyn_cast_or_null(
-  TST->getTemplateName().getAsTemplateDecl());
+  const ClassTemplateDecl *TD =
+  dyn_cast_or_null(TN.getAsTemplateDecl());
   if (!TD)
 return nullptr;
 
diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 3220a5a6a98250..fc54f89f4941e1 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -842,6 +842,8 @@ TEST_F(TargetDeclTest, OverloadExpr) {
 }
 
 TEST_F(TargetDeclTest, DependentExprs) {
+  Flags.push_back("--std=c++20");
+
   // Heuristic resolution of method of dependent field
   Code = R"cpp(
 struct A { void foo() {} };
@@ -962,6 +964,21 @@ TEST_F(TargetDeclTest, DependentExprs) {
 };
   )cpp";
   EXPECT_DECLS("MemberExpr", "void find()");
+
+  // Base expression is the type of a non-type template parameter
+  // which is deduced using CTAD.
+  Code = R"cpp(
+template 
+struct Waldo {
+  const int found = N;
+};
+
+template 
+int test() {
+  return W.[[found]];
+}
+  )cpp";
+  EXPECT_DECLS("CXXDependentScopeMemberExpr", "const int found = N");
 }
 
 TEST_F(TargetDeclTest, DependentTypes) {

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


[clang-tools-extra] [clangd] Handle DeducedTemplateSpecializationType in HeuristicResolver (PR #119107)

2024-12-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Nathan Ridge (HighCommander4)


Changes

Fixes https://github.com/clangd/clangd/issues/2227

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


2 Files Affected:

- (modified) clang-tools-extra/clangd/HeuristicResolver.cpp (+14-4) 
- (modified) clang-tools-extra/clangd/unittests/FindTargetTests.cpp (+17) 


``diff
diff --git a/clang-tools-extra/clangd/HeuristicResolver.cpp 
b/clang-tools-extra/clangd/HeuristicResolver.cpp
index 26d54200eeffd2..9eb892e8e4a8ea 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.cpp
+++ b/clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -118,6 +118,16 @@ const Type *resolveDeclsToType(const std::vector &Decls,
   return nullptr;
 }
 
+TemplateName getReferencedTemplateName(const Type *T) {
+  if (const auto *TST = T->getAs()) {
+return TST->getTemplateName();
+  }
+  if (const auto *DTST = T->getAs()) {
+return DTST->getTemplateName();
+  }
+  return TemplateName();
+}
+
 // Helper function for HeuristicResolver::resolveDependentMember()
 // which takes a possibly-dependent type `T` and heuristically
 // resolves it to a CXXRecordDecl in which we can try name lookup.
@@ -142,12 +152,12 @@ CXXRecordDecl 
*HeuristicResolverImpl::resolveTypeToRecordDecl(const Type *T) {
   if (!T)
 return nullptr;
 
-  const auto *TST = T->getAs();
-  if (!TST)
+  TemplateName TN = getReferencedTemplateName(T);
+  if (TN.isNull())
 return nullptr;
 
-  const ClassTemplateDecl *TD = dyn_cast_or_null(
-  TST->getTemplateName().getAsTemplateDecl());
+  const ClassTemplateDecl *TD =
+  dyn_cast_or_null(TN.getAsTemplateDecl());
   if (!TD)
 return nullptr;
 
diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 3220a5a6a98250..fc54f89f4941e1 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -842,6 +842,8 @@ TEST_F(TargetDeclTest, OverloadExpr) {
 }
 
 TEST_F(TargetDeclTest, DependentExprs) {
+  Flags.push_back("--std=c++20");
+
   // Heuristic resolution of method of dependent field
   Code = R"cpp(
 struct A { void foo() {} };
@@ -962,6 +964,21 @@ TEST_F(TargetDeclTest, DependentExprs) {
 };
   )cpp";
   EXPECT_DECLS("MemberExpr", "void find()");
+
+  // Base expression is the type of a non-type template parameter
+  // which is deduced using CTAD.
+  Code = R"cpp(
+template 
+struct Waldo {
+  const int found = N;
+};
+
+template 
+int test() {
+  return W.[[found]];
+}
+  )cpp";
+  EXPECT_DECLS("CXXDependentScopeMemberExpr", "const int found = N");
 }
 
 TEST_F(TargetDeclTest, DependentTypes) {

``




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


[clang-tools-extra] fix parse windows driver and wsl path (PR #119085)

2024-12-07 Thread via cfe-commits

https://github.com/95833 updated 
https://github.com/llvm/llvm-project/pull/119085

>From 1a37796fbb624a54b00cfff42674fbfa79616f61 Mon Sep 17 00:00:00 2001
From: root <987004...@qq.com>
Date: Sun, 8 Dec 2024 01:19:59 +0800
Subject: [PATCH] fix parse windows driver and wsl path

---
 clang-tools-extra/clangd/PathMapping.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/clangd/PathMapping.cpp 
b/clang-tools-extra/clangd/PathMapping.cpp
index 4b93ff2c60c5c6..48a936867a738a 100644
--- a/clang-tools-extra/clangd/PathMapping.cpp
+++ b/clang-tools-extra/clangd/PathMapping.cpp
@@ -150,11 +150,11 @@ llvm::Expected parsePath(llvm::StringRef 
Path) {
   if (path::is_absolute(Path, path::Style::posix)) {
 return std::string(Path);
   }
-  if (path::is_absolute(Path, path::Style::windows)) {
-std::string Converted = path::convert_to_slash(Path, path::Style::windows);
-if (Converted.front() != '/')
-  Converted = "/" + Converted;
-return Converted;
+  llvm::StringRef Root = path::root_name(Path, path::Style::windows);
+  if (!Root.empty()) {
+std::string Converted = "/";
+return Converted.append(Root)
+  .append(path::convert_to_slash(Path.substr(Root.size()), 
path::Style::windows));
   }
   return error("Path not absolute: {0}", Path);
 }

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


[clang] 6b1c357 - [clang-format] Add cmake target clang-format-help to update ClangFormat.rst

2024-12-07 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-12-07T22:41:50-08:00
New Revision: 6b1c357acc312961743bef05f99120e7c68b2e25

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

LOG: [clang-format] Add cmake target clang-format-help to update ClangFormat.rst

Added: 


Modified: 
clang/lib/Format/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Format/CMakeLists.txt b/clang/lib/Format/CMakeLists.txt
index 7d2db087328e4a..9f4939824fdb8b 100644
--- a/clang/lib/Format/CMakeLists.txt
+++ b/clang/lib/Format/CMakeLists.txt
@@ -48,18 +48,17 @@ foreach(file IN LISTS files)
 COMMENT "Checking format of ${file}"
 )
   list(APPEND check_format_depends check_format_depend_${i})
-
   math(EXPR i ${i}+1)
 endforeach()
-
 add_custom_target(clang-format-check-format DEPENDS ${check_format_depends})
 
-set(style_options_depends ${CMAKE_CURRENT_BINARY_DIR}/dummy_output)
 set(docs_tools_dir ${CLANG_SOURCE_DIR}/docs/tools)
+
+set(format_style_depend ${CMAKE_CURRENT_BINARY_DIR}/format_style_depend)
+set(dump_style dump_format_style.py)
 set(style_options_rst ${CLANG_SOURCE_DIR}/docs/ClangFormatStyleOptions.rst)
-add_custom_command(OUTPUT ${style_options_depends}
-  COMMAND ${Python3_EXECUTABLE} dump_format_style.py &&
-  touch ${style_options_depends}
+add_custom_command(OUTPUT ${format_style_depend}
+  COMMAND ${Python3_EXECUTABLE} ${dump_style} && touch ${format_style_depend}
   WORKING_DIRECTORY ${docs_tools_dir}
   VERBATIM
   COMMENT "Updating ${style_options_rst}"
@@ -67,7 +66,21 @@ add_custom_command(OUTPUT ${style_options_depends}
   ${CLANG_SOURCE_DIR}/include/clang/Tooling/Inclusions/IncludeStyle.h
   ${style_options_rst}
   ${docs_tools_dir}/plurals.txt
-  ${docs_tools_dir}/dump_format_style.py
+  ${docs_tools_dir}/${dump_style}
   )
+add_custom_target(clang-format-style DEPENDS ${format_style_depend})
 
-add_custom_target(clang-format-style-options DEPENDS ${style_options_depends})
+set(format_help_depend ${CMAKE_CURRENT_BINARY_DIR}/format_help_depend)
+set(dump_help dump_format_help.py)
+set(clang_format_rst ${CLANG_SOURCE_DIR}/docs/ClangFormat.rst)
+add_custom_command(OUTPUT ${format_help_depend}
+  COMMAND ${Python3_EXECUTABLE} ${dump_help} -d ${CMAKE_BINARY_DIR}/bin &&
+  touch ${format_help_depend}
+  WORKING_DIRECTORY ${docs_tools_dir}
+  VERBATIM
+  COMMENT "Updating ${clang_format_rst}"
+  DEPENDS clang-format
+  ${clang_format_rst}
+  ${docs_tools_dir}/${dump_help}
+  )
+add_custom_target(clang-format-help DEPENDS ${format_help_depend})



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


[clang] [clang-format] Reorder TokenAnnotator::canBreakBefore (PR #119044)

2024-12-07 Thread Owen Pan via cfe-commits


@@ -6105,6 +6105,33 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine 
&Line,
   return false;
   }
 
+  // We only break before r_brace if there was a corresponding break before
+  // the l_brace, which is tracked by BreakBeforeClosingBrace.

owenca wrote:

```suggestion
  // We only break before an r_brace if there was a corresponding break after
  // the matching l_brace, which is tracked by BreakBeforeClosingBrace.
```

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


[clang] [clang-format] Reorder TokenAnnotator::canBreakBefore (PR #119044)

2024-12-07 Thread Owen Pan via cfe-commits


@@ -9383,6 +9383,13 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
   "(a, )) &&\n"
   ");",
   Style);
+  verifyFormat("void foo(\n"
+   "void (*foobarpntr)(\n"
+   "aa *,\n"
+   "bb *,\n"
+   " *,\n"
+   "dd *));",

owenca wrote:

We probably can do without this test, which would pass without this patch.

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


[clang] [clang-format] Reorder TokenAnnotator::canBreakBefore (PR #119044)

2024-12-07 Thread Owen Pan via cfe-commits


@@ -6105,6 +6105,33 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine 
&Line,
   return false;
   }
 
+  // We only break before r_brace if there was a corresponding break before
+  // the l_brace, which is tracked by BreakBeforeClosingBrace.
+  if (Right.is(tok::r_brace)) {
+return Right.MatchingParen && (Right.MatchingParen->is(BK_Block) ||
+   (Right.isBlockIndentedInitRBrace(Style)));
+  }
+
+  // We only break before r_paren if we're in a block indented context.
+  if (Right.is(tok::r_paren)) {
+if (Style.AlignAfterOpenBracket != FormatStyle::BAS_BlockIndent ||
+!Right.MatchingParen) {
+  return false;
+}
+auto Next = Right.Next;
+if (Next && Next->is(tok::r_paren))
+  Next = Next->Next;
+if (Next && Next->is(tok::l_paren))
+  return false;
+const FormatToken *Previous = Right.MatchingParen->Previous;
+return !(Previous && (Previous->is(tok::kw_for) || Previous->isIf()));
+  }
+
+  if (Left.isOneOf(tok::r_paren, TT_TrailingAnnotation) &&
+  Right.is(TT_TrailingAnnotation) &&
+  Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) {
+return false;
+  }
   if (Left.is(tok::at))

owenca wrote:

```suggestion

  if (Left.is(tok::at))
```

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


[clang] [clang-tools-extra] [clang] Compute accurate begin location for CallExpr with explicit object parameter (PR #117841)

2024-12-07 Thread Timm Baeder via cfe-commits

tbaederr wrote:

I didn't check if any tests fail but here's a version where `CallExpr` saves 
its `BeginLoc` explicitly: 
http://llvm-compile-time-tracker.com/compare.php?from=416e4cd332c7421b187844ac9aaf6fe28b575a7d&to=0b6e36fe460409aa59958b79766b4f64a31c97e6&stat=instructions:u

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


[clang] [clang][bytecode] Pass (float) BitWidth to DoBitCast (PR #119119)

2024-12-07 Thread Timm Baeder via cfe-commits

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

In certain cases (i.e. long double on x86), the bit with we get from the 
floating point semantics is different than the type size we compute for the 
BitCast instruction. Pass this along to DoBitCast, so in there we can check 
only the relevant bits for being initialized.

This also fixes a weirdness we still had in DoBitCast.

>From 2974b6d18fd67decca592b72e8426f9d018c7b15 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 8 Dec 2024 08:00:14 +0100
Subject: [PATCH] [clang][bytecode] Pass (float) BitWidth to DoBitCast

In certain cases (i.e. long double on x86), the bit with we get from
the floating point semantics is different than the type size we
compute for the BitCast instruction. Pass this along to DoBitCast,
so in there we can check only the relevant bits for being initialized.

This also fixes a weirdness we still had in DoBitCast.
---
 clang/lib/AST/ByteCode/BitcastBuffer.h|  1 +
 clang/lib/AST/ByteCode/Interp.h   | 23 ++-
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 19 +--
 clang/lib/AST/ByteCode/InterpBuiltinBitCast.h |  4 +++-
 .../ByteCode/builtin-bit-cast-long-double.cpp |  7 ++
 5 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
index 2a0d8a0cd9a81f..b1b6b9e5173a7c 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.h
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -45,6 +45,7 @@ struct Bits {
   bool operator>=(Bits Other) const { return N >= Other.N; }
   bool operator<=(Bits Other) const { return N <= Other.N; }
   bool operator==(Bits Other) const { return N == Other.N; }
+  bool operator!=(Bits Other) const { return N != Other.N; }
 };
 
 /// A quantity in bytes.
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index c5c2a5ef19cc4d..97e954112ae281 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_AST_INTERP_INTERP_H
 
 #include "../ExprConstShared.h"
+#include "BitcastBuffer.h"
 #include "Boolean.h"
 #include "DynamicAllocator.h"
 #include "FixedPoint.h"
@@ -3050,7 +3051,16 @@ inline bool BitCast(InterpState &S, CodePtr OpPC, bool 
TargetIsUCharOrByte,
   llvm::SmallVector Buff(BuffSize);
   bool HasIndeterminateBits = false;
 
-  if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), BuffSize, 
HasIndeterminateBits))
+  Bits FullBitWidth(ResultBitWidth);
+  Bits BitWidth = FullBitWidth;
+
+  if constexpr (std::is_same_v) {
+assert(Sem);
+BitWidth = Bits(llvm::APFloatBase::getSizeInBits(*Sem));
+  }
+
+  if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), FullBitWidth, BitWidth,
+ HasIndeterminateBits))
 return false;
 
   if (!CheckBitCast(S, OpPC, HasIndeterminateBits, TargetIsUCharOrByte))
@@ -3058,16 +3068,7 @@ inline bool BitCast(InterpState &S, CodePtr OpPC, bool 
TargetIsUCharOrByte,
 
   if constexpr (std::is_same_v) {
 assert(Sem);
-ptrdiff_t Offset = 0;
-
-if (llvm::sys::IsBigEndianHost) {
-  unsigned NumBits = llvm::APFloatBase::getSizeInBits(*Sem);
-  assert(NumBits % 8 == 0);
-  assert(NumBits <= ResultBitWidth);
-  Offset = (ResultBitWidth - NumBits) / 8;
-}
-
-S.Stk.push(T::bitcastFromMemory(Buff.data() + Offset, *Sem));
+S.Stk.push(T::bitcastFromMemory(Buff.data(), *Sem));
   } else {
 assert(!Sem);
 S.Stk.push(T::bitcastFromMemory(Buff.data(), ResultBitWidth));
diff --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index e12babc162ce3c..915d0723bf5363 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -278,44 +278,49 @@ static bool readPointerToBuffer(const Context &Ctx, const 
Pointer &FromPtr,
   if (llvm::sys::IsBigEndianHost)
 swapBytes(Buff.get(), NumBits.roundToBytes());
 
+  Buffer.markInitialized(BitOffset, NumBits);
 } else {
   BITCAST_TYPE_SWITCH(T, { P.deref().bitcastToMemory(Buff.get()); 
});
 
   if (llvm::sys::IsBigEndianHost)
 swapBytes(Buff.get(), FullBitWidth.roundToBytes());
+  Buffer.markInitialized(BitOffset, BitWidth);
 }
 
 Buffer.pushData(Buff.get(), BitOffset, BitWidth, TargetEndianness);
-Buffer.markInitialized(BitOffset, BitWidth);
 return true;
   });
 }
 
 bool clang::interp::DoBitCast(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
-  std::byte *Buff, size_t BuffSize,
+  std::byte *Buff, Bits FullBitWidth, Bits 
BitWidth,
   bool &HasIndeterminateBits) {
   assert(Ptr.isLive());
   assert(Ptr.isBlockPointer());
   assert(Buff);
+  assert(BitWidth <= FullBitWidth);
+  assert(FullBitWidth.isFullByte());
+  assert(Bit

[clang] [clang][bytecode] Pass (float) BitWidth to DoBitCast (PR #119119)

2024-12-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

In certain cases (i.e. long double on x86), the bit with we get from the 
floating point semantics is different than the type size we compute for the 
BitCast instruction. Pass this along to DoBitCast, so in there we can check 
only the relevant bits for being initialized.

This also fixes a weirdness we still had in DoBitCast.

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


5 Files Affected:

- (modified) clang/lib/AST/ByteCode/BitcastBuffer.h (+1) 
- (modified) clang/lib/AST/ByteCode/Interp.h (+12-11) 
- (modified) clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp (+12-7) 
- (modified) clang/lib/AST/ByteCode/InterpBuiltinBitCast.h (+3-1) 
- (modified) clang/test/AST/ByteCode/builtin-bit-cast-long-double.cpp (+7) 


``diff
diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
index 2a0d8a0cd9a81f..b1b6b9e5173a7c 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.h
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -45,6 +45,7 @@ struct Bits {
   bool operator>=(Bits Other) const { return N >= Other.N; }
   bool operator<=(Bits Other) const { return N <= Other.N; }
   bool operator==(Bits Other) const { return N == Other.N; }
+  bool operator!=(Bits Other) const { return N != Other.N; }
 };
 
 /// A quantity in bytes.
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index c5c2a5ef19cc4d..97e954112ae281 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_AST_INTERP_INTERP_H
 
 #include "../ExprConstShared.h"
+#include "BitcastBuffer.h"
 #include "Boolean.h"
 #include "DynamicAllocator.h"
 #include "FixedPoint.h"
@@ -3050,7 +3051,16 @@ inline bool BitCast(InterpState &S, CodePtr OpPC, bool 
TargetIsUCharOrByte,
   llvm::SmallVector Buff(BuffSize);
   bool HasIndeterminateBits = false;
 
-  if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), BuffSize, 
HasIndeterminateBits))
+  Bits FullBitWidth(ResultBitWidth);
+  Bits BitWidth = FullBitWidth;
+
+  if constexpr (std::is_same_v) {
+assert(Sem);
+BitWidth = Bits(llvm::APFloatBase::getSizeInBits(*Sem));
+  }
+
+  if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), FullBitWidth, BitWidth,
+ HasIndeterminateBits))
 return false;
 
   if (!CheckBitCast(S, OpPC, HasIndeterminateBits, TargetIsUCharOrByte))
@@ -3058,16 +3068,7 @@ inline bool BitCast(InterpState &S, CodePtr OpPC, bool 
TargetIsUCharOrByte,
 
   if constexpr (std::is_same_v) {
 assert(Sem);
-ptrdiff_t Offset = 0;
-
-if (llvm::sys::IsBigEndianHost) {
-  unsigned NumBits = llvm::APFloatBase::getSizeInBits(*Sem);
-  assert(NumBits % 8 == 0);
-  assert(NumBits <= ResultBitWidth);
-  Offset = (ResultBitWidth - NumBits) / 8;
-}
-
-S.Stk.push(T::bitcastFromMemory(Buff.data() + Offset, *Sem));
+S.Stk.push(T::bitcastFromMemory(Buff.data(), *Sem));
   } else {
 assert(!Sem);
 S.Stk.push(T::bitcastFromMemory(Buff.data(), ResultBitWidth));
diff --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index e12babc162ce3c..915d0723bf5363 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -278,44 +278,49 @@ static bool readPointerToBuffer(const Context &Ctx, const 
Pointer &FromPtr,
   if (llvm::sys::IsBigEndianHost)
 swapBytes(Buff.get(), NumBits.roundToBytes());
 
+  Buffer.markInitialized(BitOffset, NumBits);
 } else {
   BITCAST_TYPE_SWITCH(T, { P.deref().bitcastToMemory(Buff.get()); 
});
 
   if (llvm::sys::IsBigEndianHost)
 swapBytes(Buff.get(), FullBitWidth.roundToBytes());
+  Buffer.markInitialized(BitOffset, BitWidth);
 }
 
 Buffer.pushData(Buff.get(), BitOffset, BitWidth, TargetEndianness);
-Buffer.markInitialized(BitOffset, BitWidth);
 return true;
   });
 }
 
 bool clang::interp::DoBitCast(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
-  std::byte *Buff, size_t BuffSize,
+  std::byte *Buff, Bits FullBitWidth, Bits 
BitWidth,
   bool &HasIndeterminateBits) {
   assert(Ptr.isLive());
   assert(Ptr.isBlockPointer());
   assert(Buff);
+  assert(BitWidth <= FullBitWidth);
+  assert(FullBitWidth.isFullByte());
+  assert(BitWidth.isFullByte());
 
-  Bits BitSize = Bytes(BuffSize).toBits();
-  BitcastBuffer Buffer(BitSize);
+  BitcastBuffer Buffer(FullBitWidth);
+  size_t BuffSize = FullBitWidth.roundToBytes();
   if (!CheckBitcastType(S, OpPC, Ptr.getType(), /*IsToType=*/false))
 return false;
 
   bool Success = readPointerToBuffer(S.getContext(), Ptr, Buffer,
  /*ReturnOnUninit=*/false);
-  HasIndeterminateBits = !Buffer.allInitialized();
+  HasIndet

[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-07 Thread via cfe-commits

https://github.com/AdUhTkJm updated 
https://github.com/llvm/llvm-project/pull/119098

>From 367261c3b9d8bf80ba39ae296d30f53bff2a2d4b Mon Sep 17 00:00:00 2001
From: AdUhTkJm <2292398...@qq.com>
Date: Sun, 8 Dec 2024 07:04:11 +0800
Subject: [PATCH] [Clang] Fix crash for incompatible types in inline assembly

---
 clang/lib/Sema/SemaStmtAsm.cpp|  1 +
 .../test/Sema/inline-asm-incompatible-types.c | 19 +++
 2 files changed, 20 insertions(+)
 create mode 100644 clang/test/Sema/inline-asm-incompatible-types.c

diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 0b272b806391c4..5e236b59d14b7d 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -668,6 +668,7 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 // output was a register, just extend the shorter one to the size of the
 // larger one.
 if (!SmallerValueMentioned && InputDomain != AD_Other &&
+InputDomain == OutputDomain &&
 OutputConstraintInfos[TiedTo].allowsRegister()) {
   // FIXME: GCC supports the OutSize to be 128 at maximum. Currently 
codegen
   // crash when the size larger than the register size. So we limit it 
here.
diff --git a/clang/test/Sema/inline-asm-incompatible-types.c 
b/clang/test/Sema/inline-asm-incompatible-types.c
new file mode 100644
index 00..849543e8027c20
--- /dev/null
+++ b/clang/test/Sema/inline-asm-incompatible-types.c
@@ -0,0 +1,19 @@
+extern __inline  double
+fabs (char  __x)
+{
+  register double __value;
+  __asm __volatile__
+("fabs"
+ : "=t" (__value) : "0" (__x));
+  return __value;
+}
+int
+foo ()
+{
+  int i, j, k;
+  double x = 0, y = ((i == j) ? 1 : 0);
+  for (i = 0; i < 10; i++)
+;
+  fabs (x - y);
+  return 0;
+}
\ No newline at end of file

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


[clang] 7787328 - [ubsan] Improve lowering of @llvm.allow.ubsan.check (#119013)

2024-12-07 Thread via cfe-commits

Author: Vitaly Buka
Date: 2024-12-07T16:12:58-08:00
New Revision: 7787328dd64c750c7acf30b86b31f0d7166c8f27

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

LOG: [ubsan] Improve lowering of @llvm.allow.ubsan.check (#119013)

This fix the case, when single hot inlined callsite, prevent
checks for all other. This helps to reduce number of removed checks up
to 50% (deppedes on `cutoff-hot` value) .

`ScalarOptimizerLateEPCallback` was happening during
CGSCC walk, after each inlining, but this is effectively
after inlining.

Example, order in comments:

```
static void overflow() {
  // 1. Inline get/set if possible
  // 2. Simplify
  // 3. LowerAllowCheckPass
  set(get() + get());
}

void test() {
  // 4. Inline
  // 5. Nothing for LowerAllowCheckPass
  overflow();
}
```

With this patch it will look like:
```
static void overflow() {
  // 1. Inline get/set if possible
  // 2. Simplify
  set(get() + get());
}

void test() {
  // 3. Inline
  // 4. Simplify
  overflow();
}

// Later, after inliner CGSCC walk complete:
// 5. LowerAllowCheckPass for `overflow`
// 6. LowerAllowCheckPass for `test`
```

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/allow-ubsan-check-inline.c

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index fbb3fb6e5ea423..8cf44592a17475 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -789,13 +789,12 @@ static void addSanitizers(const Triple &TargetTriple,
   }
 
   if (LowerAllowCheckPass::IsRequested()) {
-// We can optimize after inliner, and PGO profile matching. The hook below
-// is called at the end `buildFunctionSimplificationPipeline`, which called
-// from `buildInlinerPipeline`, which called after profile matching.
-PB.registerScalarOptimizerLateEPCallback(
-[](FunctionPassManager &FPM, OptimizationLevel Level) {
-  FPM.addPass(LowerAllowCheckPass());
-});
+// We want to call it after inline, which is about 
OptimizerEarlyEPCallback.
+PB.registerOptimizerEarlyEPCallback([](ModulePassManager &MPM,
+   OptimizationLevel Level,
+   ThinOrFullLTOPhase Phase) {
+  MPM.addPass(createModuleToFunctionPassAdaptor(LowerAllowCheckPass()));
+});
   }
 }
 

diff  --git a/clang/test/CodeGen/allow-ubsan-check-inline.c 
b/clang/test/CodeGen/allow-ubsan-check-inline.c
index cabe76d8034d77..1de24ab90dac0e 100644
--- a/clang/test/CodeGen/allow-ubsan-check-inline.c
+++ b/clang/test/CodeGen/allow-ubsan-check-inline.c
@@ -7,8 +7,8 @@ void set(int x);
 // We will only make decision in the `overflow` function.
 // NOINL-COUNT-1: remark: Allowed check:
 
-// FIXME: We will make decision on every inline.
-// INLINE-COUNT-1: remark: Allowed check:
+// We will make decision on every inline.
+// INLINE-COUNT-5: remark: Allowed check:
 
 static void overflow() {
   set(get() + get());



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


[clang] [ubsan] Improve lowering of @llvm.allow.ubsan.check (PR #119013)

2024-12-07 Thread Vitaly Buka via cfe-commits

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


[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-07 Thread via cfe-commits

https://github.com/AdUhTkJm updated 
https://github.com/llvm/llvm-project/pull/119098

>From 84cd85c3c09482276cbe971f9e11b65673d55db4 Mon Sep 17 00:00:00 2001
From: AdUhTkJm <2292398...@qq.com>
Date: Sun, 8 Dec 2024 08:07:59 +0800
Subject: [PATCH] [Clang] Fix crash for incompatible types in inline assembly

---
 clang/lib/Sema/SemaStmtAsm.cpp | 10 +-
 clang/test/Sema/PR119098.c | 23 +++
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/PR119098.c

diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 0b272b806391c4..f3e4d08761ea07 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -664,11 +664,19 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
   SmallerValueMentioned |= OutSize < InSize;
 }
 
+// If the input is in an integer register while the output is floating 
point,
+// there is no way we can extend and we must reject it.
+bool FPExtendFromInt = false;
+if (InputDomain != AD_Float && OutputDomain == AD_Float) {
+  FPExtendFromInt = true;
+}
+
 // If the smaller value wasn't mentioned in the asm string, and if the
 // output was a register, just extend the shorter one to the size of the
 // larger one.
-if (!SmallerValueMentioned && InputDomain != AD_Other &&
+if (!SmallerValueMentioned && !FPExtendFromInt && InputDomain != AD_Other 
&&
 OutputConstraintInfos[TiedTo].allowsRegister()) {
+
   // FIXME: GCC supports the OutSize to be 128 at maximum. Currently 
codegen
   // crash when the size larger than the register size. So we limit it 
here.
   if (OutTy->isStructureType() &&
diff --git a/clang/test/Sema/PR119098.c b/clang/test/Sema/PR119098.c
new file mode 100644
index 00..48c41cb1bea042
--- /dev/null
+++ b/clang/test/Sema/PR119098.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64 -fsyntax-only -verify
+
+// expected-warning@+2 {{incompatible redeclaration of library function 
'fabs'}}
+// expected-note@+1 {{'fabs' is a builtin with type 'double (double)'}}
+extern __inline  double
+fabs (char  __x)
+{
+  register double __value;
+  __asm __volatile__
+("fabs"
+ : "=t" (__value) : "0" (__x));  // expected-error {{unsupported inline 
asm: input with type 'char' matching output with type 'double'}}
+  return __value;
+}
+int
+foo ()
+{
+  int i, j, k;
+  double x = 0, y = ((i == j) ? 1 : 0);
+  for (i = 0; i < 10; i++)
+;
+  fabs (x - y);
+  return 0;
+}
\ No newline at end of file

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


[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-07 Thread via cfe-commits

https://github.com/AdUhTkJm updated 
https://github.com/llvm/llvm-project/pull/119098

>From 26bb776fcd750df11a4940899869f59035f78a79 Mon Sep 17 00:00:00 2001
From: AdUhTkJm <2292398...@qq.com>
Date: Sun, 8 Dec 2024 08:07:59 +0800
Subject: [PATCH] [Clang] Fix crash for incompatible types in inline assembly

---
 clang/lib/Sema/SemaStmtAsm.cpp | 10 +-
 clang/test/Sema/PR119098.c | 23 +++
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/PR119098.c

diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 0b272b806391c4..f3e4d08761ea07 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -664,11 +664,19 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
   SmallerValueMentioned |= OutSize < InSize;
 }
 
+// If the input is in an integer register while the output is floating 
point,
+// there is no way we can extend and we must reject it.
+bool FPExtendFromInt = false;
+if (InputDomain != AD_Float && OutputDomain == AD_Float) {
+  FPExtendFromInt = true;
+}
+
 // If the smaller value wasn't mentioned in the asm string, and if the
 // output was a register, just extend the shorter one to the size of the
 // larger one.
-if (!SmallerValueMentioned && InputDomain != AD_Other &&
+if (!SmallerValueMentioned && !FPExtendFromInt && InputDomain != AD_Other 
&&
 OutputConstraintInfos[TiedTo].allowsRegister()) {
+
   // FIXME: GCC supports the OutSize to be 128 at maximum. Currently 
codegen
   // crash when the size larger than the register size. So we limit it 
here.
   if (OutTy->isStructureType() &&
diff --git a/clang/test/Sema/PR119098.c b/clang/test/Sema/PR119098.c
new file mode 100644
index 00..48c41cb1bea042
--- /dev/null
+++ b/clang/test/Sema/PR119098.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64 -fsyntax-only -verify
+
+// expected-warning@+2 {{incompatible redeclaration of library function 
'fabs'}}
+// expected-note@+1 {{'fabs' is a builtin with type 'double (double)'}}
+extern __inline  double
+fabs (char  __x)
+{
+  register double __value;
+  __asm __volatile__
+("fabs"
+ : "=t" (__value) : "0" (__x));  // expected-error {{unsupported inline 
asm: input with type 'char' matching output with type 'double'}}
+  return __value;
+}
+int
+foo ()
+{
+  int i, j, k;
+  double x = 0, y = ((i == j) ? 1 : 0);
+  for (i = 0; i < 10; i++)
+;
+  fabs (x - y);
+  return 0;
+}
\ No newline at end of file

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-07 Thread Chandler Carruth via cfe-commits

https://github.com/chandlerc updated 
https://github.com/llvm/llvm-project/pull/118734

>From 73a0b5c796881d1e52f8336eb69f678fd4c9f4c4 Mon Sep 17 00:00:00 2001
From: Chandler Carruth 
Date: Thu, 28 Nov 2024 09:56:40 +
Subject: [PATCH 1/5] Switch builtin strings to use string tables
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The Clang binary (and any binary linking Clang as a library), when built
using PIE, ends up with a pretty shocking number of dynamic relocations
to apply to the executable image: roughly 400k.

Each of these takes up binary space in the executable, and perhaps most
interestingly takes start-up time to apply the relocations.

The largest pattern I identified were the strings used to describe
target builtins. The addresses of these string literals were stored into
huge arrays, each one requiring a dynamic relocation. The way to avoid
this is to design the target builtins to use a single large table of
strings and offsets within the table for the individual strings. This
switches the builtin management to such a scheme.

This saves over 100k dynamic relocations by my measurement, an over 25%
reduction. Just looking at byte size improvements, using the `bloaty`
tool to compare a newly built `clang` binary to an old one:

```
FILE SIZEVM SIZE
 --  --
  +1.4%  +653Ki  +1.4%  +653Ki.rodata
  +0.0%+960  +0.0%+960.text
  +0.0%+197  +0.0%+197.dynstr
  +0.0%+184  +0.0%+184.eh_frame
  +0.0% +96  +0.0% +96.dynsym
  +0.0% +40  +0.0% +40.eh_frame_hdr
  +114% +32  [ = ]   0[Unmapped]
  +0.0% +20  +0.0% +20.gnu.hash
  +0.0%  +8  +0.0%  +8.gnu.version
  +0.9%  +7  +0.9%  +7[LOAD #2 [R]]
  [ = ]   0 -75.4% -3.00Ki.relro_padding
 -16.1%  -802Ki -16.1%  -802Ki.data.rel.ro
 -27.3% -2.52Mi -27.3% -2.52Mi.rela.dyn
  -1.6% -2.66Mi  -1.6% -2.66MiTOTAL
```

We get a 16% reduction in the `.data.rel.ro` section, and nearly 30%
reduction in `.rela.dyn` where those reloctaions are stored.

This is also visible in my benchmarking of binary start-up overhead at
least:

```
Benchmark 1: ./old_clang --version
  Time (mean ± σ):  17.6 ms ±   1.5 ms[User: 4.1 ms, System: 13.3 ms]
  Range (min … max):14.2 ms …  22.8 ms162 runs

Benchmark 2: ./new_clang --version
  Time (mean ± σ):  15.5 ms ±   1.4 ms[User: 3.6 ms, System: 11.8 ms]
  Range (min … max):12.4 ms …  20.3 ms216 runs

Summary
  './new_clang --version' ran
1.13 ± 0.14 times faster than './old_clang --version'
```

We get about 2ms faster `--version` runs. While there is a lot of noise
in binary execution time, this delta is pretty consistent, and
represents over 10% improvement. This is particularly interesting to me
because for very short source files, repeatedly starting the `clang`
binary is actually the dominant cost. For example, `configure` scripts
running against the `clang` compiler are slow in large part because of
binary start up time, not the time to process the actual inputs to the
compiler.



This PR implements the string tables using `constexpr` code and the
existing macro system. I understand that the builtins are moving towards
a TableGen model, and if complete that would provide more options for
modeling this. Unfortunately, that migration isn't complete, and even
the parts that are migrated still rely on the ability to break out of
the TableGen model and directly expand an X-macro style `BUILTIN(...)`
textually. I looked at trying to complete the move to TableGen, but it
would both require the difficult migration of the remaining targets, and
solving some tricky problems with how to move away from any macro-based
expansion.

I was also able to find a reasonably clean and effective way of doing
this with the existing macros and some `constexpr` code that I think is
clean enough to be a pretty good intermediate state, and maybe give
a good target for the eventual TableGen solution. I was also able to
factor the macros into set of consistent patterns that avoids
a significant regression in overall boilerplate.

There is one challenge with this approach: it requires the host compiler
to support (very) long string literals, a bit over half a meg. =/ The
current minimum MSVC version rejects these, but the very next patch
release (16.8) removed that restriction. I'm going to send out
a separate PR / RFC to raise the minimum version by one patch release,
which I hope is acceptable as the current version was set years ago.

FWIW, there are a few more low-hanging fruit sources of excessive
dynamic relocations, maybe as many as 50k to 100k more that I'll take
a look at to see if I can identify easy fixes. Beyond that, it seems to
get quite difficult. It might be worth adding some guidance to developer
documentation to try to avoid creating global data structures that
_repeatedly_ store pointers to oth

[clang] [docs] Add a more detailed description in CXString.h. (PR #119090)

2024-12-07 Thread Saleem Abdulrasool via cfe-commits


@@ -46,6 +46,9 @@ typedef struct {
 
 /**
  * Retrieve the character data associated with the given string.
+ *
+ * The caller shouldn't free the returned string data, and the returned string
+ * data shouldn't be accessed after the \c CXString disposed.

compnerd wrote:

I think that this is confusing. We could be more explicit about releasing the 
resources though as you point out.

```suggestion
 * The returned data is a reference and now owned by the user. This data
 * is only valid while the `CXString` is valid. This function is similar
 * to `std::string::c_str()`.
```

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


[clang] [docs] Add a more detailed description in CXString.h. (PR #119090)

2024-12-07 Thread via cfe-commits


@@ -46,6 +46,9 @@ typedef struct {
 
 /**
  * Retrieve the character data associated with the given string.
+ *
+ * The caller shouldn't free the returned string data, and the returned string
+ * data shouldn't be accessed after the \c CXString disposed.

iseki0 wrote:

The returned data is owned by the user? I interpret it as the user takes the 
ownership. So there will be the user's responsibility to free the pointer. I 
don't think that's true.


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


[clang] [compiler-rt] Move interceptors for libresolv functions to MSan (PR #119071)

2024-12-07 Thread Aaron Puchert via cfe-commits

https://github.com/aaronpuchert commented:

Regarding the removed test: there is still the MSan-specific test 
[compiler-rt/test/msan/Linux/b64.cpp](https://github.com/llvm/llvm-project/blob/main/compiler-rt/test/msan/Linux/b64.cpp).

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


[clang] [clang] Fix cast for injected types in case name lookup for dependent bases (PR #119024)

2024-12-07 Thread via cfe-commits

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


[clang] [clang] constexpr built-in elementwise add_sat function. (PR #119082)

2024-12-07 Thread via cfe-commits

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


[clang] [clang] constexpr built-in elementwise add_sat function. (PR #119082)

2024-12-07 Thread via cfe-commits

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


[clang] [clang] constexpr built-in elementwise add_sat function. (PR #119082)

2024-12-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (c8ef)


Changes

Part of #51787.

This patch adds constexpr support for the built-in elementwise add_sat function.

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


6 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+2-1) 
- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Basic/Builtins.td (+1-1) 
- (modified) clang/lib/AST/ExprConstant.cpp (+35) 
- (modified) clang/test/CodeGen/builtins-elementwise-math.c (+1-1) 
- (modified) clang/test/Sema/constant_builtins_vector.cpp (+8) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 6b950d05fb9bf9..40c0a0e5f1161c 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -648,7 +648,8 @@ elementwise to the input.
 Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = 
±infinity
 
 The integer elementwise intrinsics, including 
``__builtin_elementwise_popcount``,
-``__builtin_elementwise_bitreverse``, can be called in a ``constexpr`` context.
+``__builtin_elementwise_bitreverse``, ``__builtin_elementwise_add_sat``, can be
+called in a ``constexpr`` context.
 
 == 
== 
=
  Name   Operation  
   Supported element types
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 59e3a6609123d2..5aeda3ade7573a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -414,6 +414,7 @@ Non-comprehensive list of changes in this release
 - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
 - ``__builtin_elementwise_popcount`` function can now be used in constant 
expressions.
 - ``__builtin_elementwise_bitreverse`` function can now be used in constant 
expressions.
+- ``__builtin_elementwise_add_sat`` function can now be used in constant 
expressions.
 
 New Compiler Flags
 --
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index e2c3d3c535571c..1186ece419fdd2 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1450,7 +1450,7 @@ def ElementwiseFma : Builtin {
 
 def ElementwiseAddSat : Builtin {
   let Spellings = ["__builtin_elementwise_add_sat"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6b5b95aee35522..001773dc28dedc 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11339,6 +11339,31 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 
 return Success(APValue(ResultElements.data(), ResultElements.size()), E);
   }
+  case Builtin::BI__builtin_elementwise_add_sat: {
+APValue SourceLHS, SourceRHS;
+if (!EvaluateAsRValue(Info, E->getArg(0), SourceLHS) ||
+!EvaluateAsRValue(Info, E->getArg(1), SourceRHS))
+  return false;
+
+QualType DestEltTy = E->getType()->castAs()->getElementType();
+unsigned SourceLen = SourceLHS.getVectorLength();
+SmallVector ResultElements;
+ResultElements.reserve(SourceLen);
+
+for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
+  APSInt LHS = SourceLHS.getVectorElt(EltNum).getInt();
+  APSInt RHS = SourceRHS.getVectorElt(EltNum).getInt();
+  switch (E->getBuiltinCallee()) {
+  case Builtin::BI__builtin_elementwise_add_sat:
+ResultElements.push_back(APValue(
+APSInt(LHS.isSigned() ? LHS.sadd_sat(RHS) : RHS.uadd_sat(RHS),
+   DestEltTy->isUnsignedIntegerOrEnumerationType(;
+break;
+  }
+}
+
+return Success(APValue(ResultElements.data(), ResultElements.size()), E);
+  }
   }
 }
 
@@ -13204,6 +13229,16 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return Success(Val.rotr(Amt.urem(Val.getBitWidth())), E);
   }
 
+  case Builtin::BI__builtin_elementwise_add_sat: {
+APSInt LHS, RHS;
+if (!EvaluateInteger(E->getArg(0), LHS, Info) ||
+!EvaluateInteger(E->getArg(1), RHS, Info))
+  return false;
+
+APInt Result = LHS.isSigned() ? LHS.sadd_sat(RHS) : LHS.uadd_sat(RHS);
+return Success(APSInt(Result, !LHS.isSigned()), E);
+  }
+
   case Builtin::BIstrlen:
   case Builtin::BIwcslen:
 // A call to strlen is not a constant expression.
diff --git a/clang/test/CodeGen/builtins-elementwise-math.c 
b/clang/test/CodeGen/builtins-elementwise-math.c
index 82f82dd1ed7944..832691a55e52a1 100644
--- a/clang/test/CodeGen/builtins-elementwise-math.c
+++ b/clang/test/CodeGe

[clang] [clang] constexpr built-in elementwise add_sat function. (PR #119082)

2024-12-07 Thread via cfe-commits

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


[clang] 70c1764 - [clang] [Sema] Preserve nested name specifier prefix in MemberPointerType (#118236)

2024-12-07 Thread via cfe-commits

Author: Nathan Ridge
Date: 2024-12-07T20:17:07-05:00
New Revision: 70c1764d7a223b14b38bb394e5020e753be9c869

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

LOG: [clang] [Sema] Preserve nested name specifier prefix in MemberPointerType 
(#118236)

Fixes https://github.com/llvm/llvm-project/issues/118198
Fixes https://github.com/clangd/clangd/issues/2235

Added: 


Modified: 
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
clang/lib/Sema/SemaType.cpp
clang/test/AST/ast-dump-types-json.cpp
clang/test/CXX/conv/conv.mem/p4.cpp
clang/test/CXX/drs/cwg0xx.cpp
clang/test/CXX/drs/cwg13xx.cpp
clang/test/CXX/drs/cwg3xx.cpp
clang/test/CXX/drs/cwg4xx.cpp
clang/test/CXX/drs/cwg5xx.cpp
clang/test/CXX/expr/expr.unary/expr.unary.op/p4.cpp
clang/test/CXX/temp/temp.arg/temp.arg.nontype/p5.cpp
clang/test/Index/print-type.cpp
clang/test/Layout/ms-x86-member-pointers.cpp
clang/test/Parser/cxx1z-decomposition.cpp
clang/test/SemaCXX/addr-of-overloaded-function.cpp
clang/test/SemaCXX/calling-conv-compat.cpp
clang/test/SemaCXX/static-cast.cpp
clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 30b9b1902aa9c7..1ec51d862d0a6f 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1092,6 +1092,13 @@ sizeof...($TemplateParameter[[Elements]]);
 $Field_dependentName[[waldo]];
   }
 };
+)cpp",
+  // Pointer-to-member with nested-name-specifiers
+  R"cpp(
+  struct $Class_def[[Outer]] {
+struct $Class_def[[Inner]] {};
+  };
+  using $Typedef_decl[[Alias]] = void ($Class[[Outer]]::$Class[[Inner]]:: 
*)();
 )cpp"};
   for (const auto &TestCase : TestCases)
 // Mask off scope modifiers to keep the tests manageable.

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 5fb936297aa54a..4893bb0ec2d26f 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5347,15 +5347,23 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
 
 case NestedNameSpecifier::TypeSpec:
 case NestedNameSpecifier::TypeSpecWithTemplate:
-  ClsType = QualType(NNS->getAsType(), 0);
+  const Type *NNSType = NNS->getAsType();
+  ClsType = QualType(NNSType, 0);
   // Note: if the NNS has a prefix and ClsType is a nondependent
-  // TemplateSpecializationType, then the NNS prefix is NOT included
-  // in ClsType; hence we wrap ClsType into an ElaboratedType.
-  // NOTE: in particular, no wrap occurs if ClsType already is an
-  // Elaborated, DependentName, or DependentTemplateSpecialization.
-  if (isa(NNS->getAsType()))
+  // TemplateSpecializationType or a RecordType, then the NNS prefix is
+  // NOT included in ClsType; hence we wrap ClsType into an
+  // ElaboratedType. NOTE: in particular, no wrap occurs if ClsType
+  // already is an Elaborated, DependentName, or
+  // DependentTemplateSpecialization.
+  if (isa(NNSType)) {
+// FIXME: Rebuild DependentTemplateSpecializationType, adding the
+// Prefix.
+  } else if (isa(NNSType)) {
+// Either the dependent case (TemplateSpecializationType), or the
+// non-dependent one (RecordType).
 ClsType = Context.getElaboratedType(ElaboratedTypeKeyword::None,
 NNSPrefix, ClsType);
+  }
   break;
 }
   } else {

diff  --git a/clang/test/AST/ast-dump-types-json.cpp 
b/clang/test/AST/ast-dump-types-json.cpp
index c1bb9266fa8693..fa1fb53df0e851 100644
--- a/clang/test/AST/ast-dump-types-json.cpp
+++ b/clang/test/AST/ast-dump-types-json.cpp
@@ -248,15 +248,24 @@ using ::TestUsingShadowDeclType;
 // CHECK-NEXT:"inner": [
 // CHECK-NEXT: {
 // CHECK-NEXT:  "id": "0x{{.*}}",
-// CHECK-NEXT:  "kind": "RecordType",
+// CHECK-NEXT:  "kind": "ElaboratedType",
 // CHECK-NEXT:  "type": {
 // CHECK-NEXT:   "qualType": "T"
 // CHECK-NEXT:  },
-// CHECK-NEXT:  "decl": {
-// CHECK-NEXT:   "id": "0x{{.*}}",
-// CHECK-NEXT:   "kind": "CXXRecordDecl",
-// CHECK-NEXT:   "name": "T"
-// CHECK-NEXT:  }
+// CHECK-NEXT:  "inner": [
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "RecordType",
+// CHECK-NEXT:"type": {
+// CHECK-NEXT: "qualType": "T"
+// CHE

[clang-tools-extra] [clangd] Re-land "support outgoing calls in call hierarchy" (PR #117673)

2024-12-07 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> I would appreciate confirmation that this will indeed be possible with the 
> upcoming **clangd** changes.

Yes, the returned data is sufficient for clients to implement either of the 
above presentations.

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-07 Thread Chandler Carruth via cfe-commits

https://github.com/chandlerc commented:

> Fails to build with GCC:

Doh, I had hoped GCC would support this. Anyways, fixed back to just suppress 
the diagnostic with Clang. Did some builds with GCC and everything seems fine, 
and it doesn't seem like we're GCC warning clean these days anyways.

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-07 Thread Chandler Carruth via cfe-commits


@@ -68,23 +69,156 @@ enum ID {
   FirstTSBuiltin
 };
 
+// The info used to represent each builtin.
 struct Info {
-  llvm::StringLiteral Name;
-  const char *Type, *Attributes;
-  const char *Features;
+  // Rather than store pointers to the string literals describing these four
+  // aspects of builtins, we store offsets into a common string table.
+  struct StrOffsets {
+int Name;
+int Type;
+int Attributes;
+int Features;
+  } Offsets;
+
   HeaderDesc Header;
   LanguageID Langs;
 };
 
+// The storage for `N` builtins. This contains a single pointer to the string
+// table used for these builtins and an array of metadata for each builtin.
+template  struct Storage {
+  const char *StringTable;
+
+  std::array Infos;
+
+  // A constexpr function to construct the storage for a a given string table 
in
+  // the first argument and an array in the second argument. This is *only*
+  // expected to be used at compile time, we should mark it `consteval` when
+  // available.
+  //
+  // The `Infos` array is particularly special. This function expects an array
+  // of `Info` structs, where the string offsets of each entry refer to the
+  // *sizes* of those strings rather than their offsets, and for the target
+  // string to be in the provided string table at an offset the sum of all
+  // previous string sizes. This function walks the `Infos` array computing the
+  // running sum and replacing the sizes with the actual offsets in the string
+  // table that should be used. This arrangement is designed to make it easy to
+  // expand `.def` and `.inc` files with X-macros to construct both the string
+  // table and the `Info` structs in the arguments to this function.
+  static constexpr auto Make(const char *Strings,
+ std::array Infos) -> Storage {

chandlerc wrote:

Sorry, a new habit of mine and I hadn't gone through thoroughly enough to fix 
everywhere.

Should be fixed now throughout, I checked all the `auto` keywords in the diff.

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-07 Thread Chandler Carruth via cfe-commits

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


[clang] [clang-tools-extra] [clang] Compute accurate begin location for CallExpr with explicit object parameter (PR #117841)

2024-12-07 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> The branch is **not** taken most of the time (it's only taken for calls to 
> functions with an explicit object argument, which is a C++23 feature), so 
> perhaps annotating the branch as "unlikely" is sufficient to avoid the 
> performance regression?

Ah, no, that's not sufficient because it takes some work (a call to 
`getCalleeDecl()`) to compute the branch condition.

We could consider revising the implementation approach to optimize this better; 
for example, add a "uses explicit object argument" bit to `CallExprBits`?

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


[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-07 Thread via cfe-commits

https://github.com/AdUhTkJm updated 
https://github.com/llvm/llvm-project/pull/119098

>From 9f5c3334a580243f2812824dab4ab15aa80ddfec Mon Sep 17 00:00:00 2001
From: AdUhTkJm <2292398...@qq.com>
Date: Sun, 8 Dec 2024 08:07:59 +0800
Subject: [PATCH] [Clang] Fix crash for incompatible types in inline assembly

---
 clang/lib/Sema/SemaStmtAsm.cpp | 13 -
 clang/test/Sema/PR119098.c | 23 +++
 2 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/PR119098.c

diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 0b272b806391c4..770b59d0c3ebfa 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -664,11 +664,22 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
   SmallerValueMentioned |= OutSize < InSize;
 }
 
+// If the input is an integer register while the output is floating point,
+// there is no way they can work together.
+bool FPBoundToInt = false;
+if (InputDomain != AD_FP && OutputDomain == AD_FP) {
+  FPBoundToInt = true;
+}
+if (InputDomain == AD_FP && OutputDomain != AD_FP) {
+  FPBoundToInt = true;
+}
+
 // If the smaller value wasn't mentioned in the asm string, and if the
 // output was a register, just extend the shorter one to the size of the
 // larger one.
-if (!SmallerValueMentioned && InputDomain != AD_Other &&
+if (!SmallerValueMentioned && !FPBoundToInt && InputDomain != AD_Other &&
 OutputConstraintInfos[TiedTo].allowsRegister()) {
+
   // FIXME: GCC supports the OutSize to be 128 at maximum. Currently 
codegen
   // crash when the size larger than the register size. So we limit it 
here.
   if (OutTy->isStructureType() &&
diff --git a/clang/test/Sema/PR119098.c b/clang/test/Sema/PR119098.c
new file mode 100644
index 00..48c41cb1bea042
--- /dev/null
+++ b/clang/test/Sema/PR119098.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64 -fsyntax-only -verify
+
+// expected-warning@+2 {{incompatible redeclaration of library function 
'fabs'}}
+// expected-note@+1 {{'fabs' is a builtin with type 'double (double)'}}
+extern __inline  double
+fabs (char  __x)
+{
+  register double __value;
+  __asm __volatile__
+("fabs"
+ : "=t" (__value) : "0" (__x));  // expected-error {{unsupported inline 
asm: input with type 'char' matching output with type 'double'}}
+  return __value;
+}
+int
+foo ()
+{
+  int i, j, k;
+  double x = 0, y = ((i == j) ? 1 : 0);
+  for (i = 0; i < 10; i++)
+;
+  fabs (x - y);
+  return 0;
+}
\ No newline at end of file

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


[clang] [clang-tools-extra] [clang] Compute accurate begin location for CallExpr with explicit object parameter (PR #117841)

2024-12-07 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> It looks like this causes a significant compile-time regression: 
> https://llvm-compile-time-tracker.com/compare.php?from=2b855dd97092e2178ac5c470a804a17ec440d7e5&to=9ccde12f5eeb91152900082a2ae839e2a9702b31&stat=instructions:u
>  (Maybe most clearly seen during clang bootstrap, where this adds 0.5% to 
> many compilations: 
> https://llvm-compile-time-tracker.com/compare_clang.php?from=2b855dd97092e2178ac5c470a804a17ec440d7e5&to=9ccde12f5eeb91152900082a2ae839e2a9702b31&stat=instructions%3Au&sortBy=interestingness)
> 
> Is that expected?

I think it's at least conceivable, as the patch adds an extra branch to 
`CallExpr::getBeginLoc()`, which is likely to be called pretty frequently.

The branch is **not** taken most of the time (it's only taken for calls to 
functions with an explicit object argument, which is a C++23 feature), so 
perhaps annotating the branch as "unlikely" is sufficient to avoid the 
performance regression?

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


[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-07 Thread via cfe-commits

https://github.com/AdUhTkJm updated 
https://github.com/llvm/llvm-project/pull/119098

>From 8269073360f882daba9d9334ea8f2b6436fe9253 Mon Sep 17 00:00:00 2001
From: AdUhTkJm <2292398...@qq.com>
Date: Sun, 8 Dec 2024 08:07:59 +0800
Subject: [PATCH] [Clang] Fix crash for incompatible types in inline assembly

---
 clang/lib/Sema/SemaStmtAsm.cpp | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 0b272b806391c4..770b59d0c3ebfa 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -664,11 +664,22 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
   SmallerValueMentioned |= OutSize < InSize;
 }
 
+// If the input is an integer register while the output is floating point,
+// there is no way they can work together.
+bool FPBoundToInt = false;
+if (InputDomain != AD_FP && OutputDomain == AD_FP) {
+  FPBoundToInt = true;
+}
+if (InputDomain == AD_FP && OutputDomain != AD_FP) {
+  FPBoundToInt = true;
+}
+
 // If the smaller value wasn't mentioned in the asm string, and if the
 // output was a register, just extend the shorter one to the size of the
 // larger one.
-if (!SmallerValueMentioned && InputDomain != AD_Other &&
+if (!SmallerValueMentioned && !FPBoundToInt && InputDomain != AD_Other &&
 OutputConstraintInfos[TiedTo].allowsRegister()) {
+
   // FIXME: GCC supports the OutSize to be 128 at maximum. Currently 
codegen
   // crash when the size larger than the register size. So we limit it 
here.
   if (OutTy->isStructureType() &&

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


[clang] cb61a5e - [clang-format] Fix an assertion failure in RemoveSemicolon (#117472)

2024-12-07 Thread via cfe-commits

Author: Owen Pan
Date: 2024-12-07T16:47:35-08:00
New Revision: cb61a5e4209beef64b0a3b621c16010c53ed323a

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

LOG: [clang-format] Fix an assertion failure in RemoveSemicolon (#117472)

Fixes #117290.

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index bc5239209f3aab..49482973223c64 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3901,6 +3901,11 @@ bool TokenAnnotator::mustBreakForReturnType(const 
AnnotatedLine &Line) const {
 }
 
 void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const 
{
+  if (Line.Computed)
+return;
+
+  Line.Computed = true;
+
   for (AnnotatedLine *ChildLine : Line.Children)
 calculateFormattingInformation(*ChildLine);
 

diff  --git a/clang/lib/Format/TokenAnnotator.h 
b/clang/lib/Format/TokenAnnotator.h
index 5a02030e5ba7f9..9117ca3f9fb7b5 100644
--- a/clang/lib/Format/TokenAnnotator.h
+++ b/clang/lib/Format/TokenAnnotator.h
@@ -182,6 +182,9 @@ class AnnotatedLine {
   /// \c True if this line contains a macro call for which an expansion exists.
   bool ContainsMacroCall = false;
 
+  /// \c True if calculateFormattingInformation() has been called on this line.
+  bool Computed = false;
+
   /// \c True if this line should be formatted, i.e. intersects directly or
   /// indirectly with one of the input ranges.
   bool Affected;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 250e51b5421664..63d8dc2486e45f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -27386,6 +27386,13 @@ TEST_F(FormatTest, RemoveSemicolon) {
Style);
 #endif
 
+  verifyFormat("auto sgf = [] {\n"
+   "  ogl = {\n"
+   "  a, b, c, d, e,\n"
+   "  };\n"
+   "};",
+   Style);
+
   Style.TypenameMacros.push_back("STRUCT");
   verifyFormat("STRUCT(T, B) { int i; };", Style);
 }



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


[clang] [clang-format] Fix an assertion failure in RemoveSemicolon (PR #117472)

2024-12-07 Thread Owen Pan via cfe-commits

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


[clang] [clang] [Sema] Add assertion about expected type classes when building MemberPointerType (PR #119105)

2024-12-07 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/119105

None

>From 6c900d6cc82aab791504a0b96e1e72310d2ec24d Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sat, 7 Dec 2024 20:20:52 -0500
Subject: [PATCH] [clang] [Sema] Add assertion about expected type classes when
 building MemberPointerType

---
 clang/lib/Sema/SemaType.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 4893bb0ec2d26f..54c68d0c099490 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5363,6 +5363,9 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
 // non-dependent one (RecordType).
 ClsType = Context.getElaboratedType(ElaboratedTypeKeyword::None,
 NNSPrefix, ClsType);
+  } else {
+// The only other type we should get here is TemplateTypeParmType.
+assert(isa(NNSType));
   }
   break;
 }

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


[clang] [clang-tools-extra] [clang] [Sema] Preserve nested name specifier prefix in MemberPointerType (PR #118236)

2024-12-07 Thread Nathan Ridge via cfe-commits

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


[clang] [clang-tools-extra] [Clang] Warning as error Array Comparisons from C++26 (PR #118872)

2024-12-07 Thread Amr Hesham via cfe-commits

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


[clang-tools-extra] fix parse windows driver and wsl path (PR #119085)

2024-12-07 Thread via cfe-commits

https://github.com/95833 created 
https://github.com/llvm/llvm-project/pull/119085

path::is_absolute(Path, path::Style::windows) will return false leading to an 
error when the path appears in the root driver form, for example: 
path-mappings=E:=/mnt/e 

This modification also potentially provides support for WSL paths. for example: 
path-mappings=\\wsl.localhost/usr=/usr

>From 1a37796fbb624a54b00cfff42674fbfa79616f61 Mon Sep 17 00:00:00 2001
From: root <987004...@qq.com>
Date: Sun, 8 Dec 2024 01:19:59 +0800
Subject: [PATCH] fix parse windows driver and wsl path

---
 clang-tools-extra/clangd/PathMapping.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/clangd/PathMapping.cpp 
b/clang-tools-extra/clangd/PathMapping.cpp
index 4b93ff2c60c5c6..48a936867a738a 100644
--- a/clang-tools-extra/clangd/PathMapping.cpp
+++ b/clang-tools-extra/clangd/PathMapping.cpp
@@ -150,11 +150,11 @@ llvm::Expected parsePath(llvm::StringRef 
Path) {
   if (path::is_absolute(Path, path::Style::posix)) {
 return std::string(Path);
   }
-  if (path::is_absolute(Path, path::Style::windows)) {
-std::string Converted = path::convert_to_slash(Path, path::Style::windows);
-if (Converted.front() != '/')
-  Converted = "/" + Converted;
-return Converted;
+  llvm::StringRef Root = path::root_name(Path, path::Style::windows);
+  if (!Root.empty()) {
+std::string Converted = "/";
+return Converted.append(Root)
+  .append(path::convert_to_slash(Path.substr(Root.size()), 
path::Style::windows));
   }
   return error("Path not absolute: {0}", Path);
 }

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


[clang-tools-extra] fix parse windows driver and wsl path (PR #119085)

2024-12-07 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/119085
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] fix parse windows driver and wsl path (PR #119085)

2024-12-07 Thread via cfe-commits

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


[clang] [llvm] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Shilei Tian via cfe-commits

shiltian wrote:

Worth a bullet point in release note, both clang and openmp/offload.

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


[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

2024-12-07 Thread Björn Schäpers via cfe-commits


@@ -11077,6 +11077,157 @@ TEST_F(FormatTest, 
WrapsTemplateDeclarationsWithComments) {
   Style);
 }
 
+TEST_F(FormatTest, BreakBeforeTemplateClose) {

HazardyKnusperkeks wrote:

I want to see some lambdas and template usages (not declarations).

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


[clang] [llvm] [openmp] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Joseph Huber via cfe-commits

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

>From 4c710e49eea97e542b97e0b5e78b7915acd32383 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Sat, 7 Dec 2024 13:47:23 -0600
Subject: [PATCH 1/3] [OpenMP] Use generic IR for the OpenMP DeviceRTL

Summary:
We previously built this for every single architecture to deal with
incompatibility. This patch updates it to use the 'generic' IR that
`libc` and other projects use. Who knows if this will have any
side-effects, probably worth testing more but it passes the tests I
expect to pass on my side.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp |  3 +-
 clang/lib/Driver/ToolChains/Cuda.cpp   |  1 -
 offload/DeviceRTL/CMakeLists.txt   | 70 -
 offload/DeviceRTL/src/Reduction.cpp| 89 +++---
 4 files changed, 62 insertions(+), 101 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7d3d7f8f03c491..3dd90ecf8bca4c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2800,8 +2800,7 @@ void tools::addOpenMPDeviceRTL(const Driver &D,
 : options::OPT_libomptarget_nvptx_bc_path_EQ;
 
   StringRef ArchPrefix = Triple.isAMDGCN() ? "amdgpu" : "nvptx";
-  std::string LibOmpTargetName =
-  ("libomptarget-" + ArchPrefix + "-" + BitcodeSuffix + ".bc").str();
+  std::string LibOmpTargetName = ("libomptarget-" + ArchPrefix + ".bc").str();
 
   // First check whether user specifies bc library
   if (const Arg *A = DriverArgs.getLastArg(LibomptargetBCPathOpt)) {
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 102794829795da..214f1e5d83478f 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -851,7 +851,6 @@ void CudaToolChain::addClangTargetOptions(
   HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
 
   StringRef GpuArch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
-  assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
   assert((DeviceOffloadingKind == Action::OFK_OpenMP ||
   DeviceOffloadingKind == Action::OFK_Cuda) &&
  "Only OpenMP or CUDA offloading kinds are supported for NVIDIA 
GPUs.");
diff --git a/offload/DeviceRTL/CMakeLists.txt b/offload/DeviceRTL/CMakeLists.txt
index 1bf3eb9da38aa1..cda633c41062b6 100644
--- a/offload/DeviceRTL/CMakeLists.txt
+++ b/offload/DeviceRTL/CMakeLists.txt
@@ -42,38 +42,6 @@ set(devicertl_base_directory ${CMAKE_CURRENT_SOURCE_DIR})
 set(include_directory ${devicertl_base_directory}/include)
 set(source_directory ${devicertl_base_directory}/src)
 
-set(all_amdgpu_architectures "gfx700;gfx701;gfx801;gfx803;gfx900;gfx902;gfx906"
- 
"gfx908;gfx90a;gfx90c;gfx940;gfx941;gfx942;gfx950;gfx1010"
- 
"gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035"
- "gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150"
- "gfx1151;gfx1152;gfx1153")
-set(all_nvptx_architectures "sm_35;sm_37;sm_50;sm_52;sm_53;sm_60;sm_61;sm_62"
-"sm_70;sm_72;sm_75;sm_80;sm_86;sm_87;sm_89;sm_90")
-set(all_gpu_architectures
-"${all_amdgpu_architectures};${all_nvptx_architectures}")
-
-set(LIBOMPTARGET_DEVICE_ARCHITECTURES "all" CACHE STRING
-"List of device architectures to be used to compile the OpenMP DeviceRTL.")
-
-if(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "all")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_gpu_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "amdgpu")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_amdgpu_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "nvptx")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_nvptx_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "auto" OR
-   LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "native")
-  if(NOT LIBOMPTARGET_NVPTX_ARCH AND NOT LIBOMPTARGET_AMDGPU_ARCH)
-message(FATAL_ERROR
-  "Could not find 'amdgpu-arch' and 'nvptx-arch' tools required for 
'auto'")
-  elseif(NOT LIBOMPTARGET_FOUND_NVIDIA_GPU AND NOT 
LIBOMPTARGET_FOUND_AMDGPU_GPU)
-message(FATAL_ERROR "No AMD or NVIDIA GPU found on the system when using 
'auto'")
-  endif()
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES
-  
"${LIBOMPTARGET_NVPTX_DETECTED_ARCH_LIST};${LIBOMPTARGET_AMDGPU_DETECTED_ARCH_LIST}")
-endif()
-list(REMOVE_DUPLICATES LIBOMPTARGET_DEVICE_ARCHITECTURES)
-
 set(include_files
   ${include_directory}/Allocator.h
   ${include_directory}/Configuration.h
@@ -141,20 +109,21 @@ set(bc_flags -c -foffload-lto -std=c++17 
-fvisibility=hidden
 
 # first create an object target
 add_library(omptarget.devicertl.all_objs OBJECT IMPORTED)
-function(compileDeviceRTLLibrary target_cpu target_name target_triple)
+function(compileDeviceRTLLibrary target_name ta

[clang] [llvm] [openmp] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

@hidekisaito Might be relevant to your patch.

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


[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)

2024-12-07 Thread Björn Schäpers via cfe-commits


@@ -3398,6 +3401,21 @@ struct FormatStyle {
   /// \version 3.7
   unsigned MaxEmptyLinesToKeep;
 
+  /// If ``BinPackArguments`` is ``false`` this option can override it if
+  /// ``true`` when 20 or more items are in a braced initializer list.
+  /// \code
+  ///BinPackLongBracedLists: false  vs.   BinPackLongBracedLists: true
+  ///vector x{   vector x{1, 2, ...,
+  ///   20, 21};
+  ///1,
+  ///2,
+  ///...,
+  ///20,
+  ///21};
+  /// \endcode
+  /// \version 20
+  bool BinPackLongBracedLists;

HazardyKnusperkeks wrote:

Please resort.

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


[clang] [rtsan] Add `verify_interceptors` flag to docs (PR #119074)

2024-12-07 Thread via cfe-commits

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


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


[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)

2024-12-07 Thread via cfe-commits

https://github.com/AdUhTkJm updated 
https://github.com/llvm/llvm-project/pull/119098

>From 9780af34b63423344783ece5e8ec89de5b815c7f Mon Sep 17 00:00:00 2001
From: AdUhTkJm <2292398...@qq.com>
Date: Sun, 8 Dec 2024 08:07:59 +0800
Subject: [PATCH] [Clang] Fix crash for incompatible types in inline assembly

---
 clang/lib/Sema/SemaStmtAsm.cpp | 13 -
 clang/test/Sema/asm.c  |  6 ++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 0b272b806391c4..770b59d0c3ebfa 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -664,11 +664,22 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
   SmallerValueMentioned |= OutSize < InSize;
 }
 
+// If the input is an integer register while the output is floating point,
+// there is no way they can work together.
+bool FPBoundToInt = false;
+if (InputDomain != AD_FP && OutputDomain == AD_FP) {
+  FPBoundToInt = true;
+}
+if (InputDomain == AD_FP && OutputDomain != AD_FP) {
+  FPBoundToInt = true;
+}
+
 // If the smaller value wasn't mentioned in the asm string, and if the
 // output was a register, just extend the shorter one to the size of the
 // larger one.
-if (!SmallerValueMentioned && InputDomain != AD_Other &&
+if (!SmallerValueMentioned && !FPBoundToInt && InputDomain != AD_Other &&
 OutputConstraintInfos[TiedTo].allowsRegister()) {
+
   // FIXME: GCC supports the OutSize to be 128 at maximum. Currently 
codegen
   // crash when the size larger than the register size. So we limit it 
here.
   if (OutTy->isStructureType() &&
diff --git a/clang/test/Sema/asm.c b/clang/test/Sema/asm.c
index a9cff5947ef5d0..f925849b82b33b 100644
--- a/clang/test/Sema/asm.c
+++ b/clang/test/Sema/asm.c
@@ -365,3 +365,9 @@ void test19(long long x)
   // FIXME: This case should be supported by codegen, but it fails now.
   asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: 
input with type 'st_size128' (aka 'struct _st_size128') matching output with 
type 'long long'}}
 }
+
+// PR119098
+void test20(char x) {
+  double value;
+  asm ("fabs" : "=t" (value): "0" (x)); // expected-error {{unsupported inline 
asm: input with type 'char' matching output with type 'double'}}
+}
\ No newline at end of file

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


[clang] [rtsan] NFC: Adding links to Disabling, adding a few ` marks (PR #119075)

2024-12-07 Thread Chris Apple via cfe-commits

https://github.com/cjappl created 
https://github.com/llvm/llvm-project/pull/119075

None

>From 94225043e5e60424bc10fa0b8d33a21228420866 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Sat, 7 Dec 2024 07:51:45 -0800
Subject: [PATCH] [rtsan] NFC: Very small fixes of docs, adding `, adding link
 to Disabling

---
 clang/docs/RealtimeSanitizer.rst | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/docs/RealtimeSanitizer.rst b/clang/docs/RealtimeSanitizer.rst
index 233a91f6684162..2aec728cfed583 100644
--- a/clang/docs/RealtimeSanitizer.rst
+++ b/clang/docs/RealtimeSanitizer.rst
@@ -187,15 +187,15 @@ A **partial** list of flags RealtimeSanitizer respects:
* - ``abort_on_error``
  - OS dependent
  - boolean
- - If true, the tool calls abort() instead of _exit() after printing the 
error report. On some OSes (OSX, for exmple) this is beneficial because a 
better stack trace is emitted on crash.
+ - If true, the tool calls ``abort()`` instead of ``_exit()`` after 
printing the error report. On some OSes (MacOS, for exmple) this is beneficial 
because a better stack trace is emitted on crash.
* - ``symbolize``
  - ``true``
  - boolean
  - If set, use the symbolizer to turn virtual addresses to file/line 
locations. If false, can greatly speed up the error reporting.
* - ``suppressions``
- - ""
+ - ``""``
  - path
- - If set to a valid suppressions file, will suppress issue reporting. See 
details in "Disabling", below.
+ - If set to a valid suppressions file, will suppress issue reporting. See 
details in `Disabling and Suppressing`_.
 
 
 Some issues with flags can be debugged using the ``verbosity=$NUM`` flag:
@@ -244,6 +244,7 @@ To register a callback which will be invoked before a RTSan 
kills the process:
 ...
   }
 
+.. _disabling-and-suppressing:
 
 Disabling and suppressing
 -

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


[clang] [rtsan] NFC: Adding links to Disabling, adding a few ` marks (PR #119075)

2024-12-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Chris Apple (cjappl)


Changes



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


1 Files Affected:

- (modified) clang/docs/RealtimeSanitizer.rst (+4-3) 


``diff
diff --git a/clang/docs/RealtimeSanitizer.rst b/clang/docs/RealtimeSanitizer.rst
index 233a91f6684162..2aec728cfed583 100644
--- a/clang/docs/RealtimeSanitizer.rst
+++ b/clang/docs/RealtimeSanitizer.rst
@@ -187,15 +187,15 @@ A **partial** list of flags RealtimeSanitizer respects:
* - ``abort_on_error``
  - OS dependent
  - boolean
- - If true, the tool calls abort() instead of _exit() after printing the 
error report. On some OSes (OSX, for exmple) this is beneficial because a 
better stack trace is emitted on crash.
+ - If true, the tool calls ``abort()`` instead of ``_exit()`` after 
printing the error report. On some OSes (MacOS, for exmple) this is beneficial 
because a better stack trace is emitted on crash.
* - ``symbolize``
  - ``true``
  - boolean
  - If set, use the symbolizer to turn virtual addresses to file/line 
locations. If false, can greatly speed up the error reporting.
* - ``suppressions``
- - ""
+ - ``""``
  - path
- - If set to a valid suppressions file, will suppress issue reporting. See 
details in "Disabling", below.
+ - If set to a valid suppressions file, will suppress issue reporting. See 
details in `Disabling and Suppressing`_.
 
 
 Some issues with flags can be debugged using the ``verbosity=$NUM`` flag:
@@ -244,6 +244,7 @@ To register a callback which will be invoked before a RTSan 
kills the process:
 ...
   }
 
+.. _disabling-and-suppressing:
 
 Disabling and suppressing
 -

``




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


[clang] [compiler-rt] Move interceptors for libresolv functions to MSan (PR #119071)

2024-12-07 Thread Aaron Puchert via cfe-commits

https://github.com/aaronpuchert created 
https://github.com/llvm/llvm-project/pull/119071

The functions are not relevant for most sanitizers and only required for MSan 
to see which regions have been written to. This eliminates a link dependency 
for all other sanitizers and fixes #59007: while `-lresolv` had been added for 
the static runtime in 6dce56b2a308, it wasn't added to the shared runtimes.

Instead of just moving the interceptors, we adapt them to MSan conventions:
* We don't skip intercepting when `msan_init_is_running` is true, but directly 
call ENSURE_MSAN_INITED() like most other interceptors. It seems unlikely that 
these functions are called during initialization.
* We don't unpoison `errno`, because none of the functions is specified to use 
it.

>From d49569bb83cf2bd41b3e5efc92653c00a64c372e Mon Sep 17 00:00:00 2001
From: Aaron Puchert 
Date: Sat, 7 Dec 2024 14:58:04 +0100
Subject: [PATCH] Move interceptors for libresolv functions to MSan

The functions are not relevant for most sanitizers and only required for
MSan to see which regions have been written to. This eliminates a link
dependency for all other sanitizers and fixes #59007: while `-lresolv`
had been added for the static runtime in 6dce56b2a308, it wasn't added
to the shared runtimes.

Instead of just moving the interceptors, we adapt them to MSan
conventions:
* We don't skip intercepting when `msan_init_is_running` is true, but
  directly call ENSURE_MSAN_INITED() like most other interceptors. It
  seems unlikely that these functions are called during initialization.
* We don't unpoison `errno`, because none of the functions is specified
  to use it.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  2 +-
 compiler-rt/lib/msan/msan_interceptors.cpp| 76 ++
 .../sanitizer_common_interceptors.inc | 78 ---
 .../sanitizer_platform_interceptors.h |  2 -
 .../sanitizer_common/TestCases/Linux/b64.cpp  | 42 --
 5 files changed, 77 insertions(+), 123 deletions(-)
 delete mode 100644 compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7d3d7f8f03c491..03dbdc27975b42 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1410,7 +1410,7 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-  !TC.getTriple().isMusl())
+  !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())
 CmdArgs.push_back("-lresolv");
 }
 
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp 
b/compiler-rt/lib/msan/msan_interceptors.cpp
index f05c20618780b7..b2098d8a26d229 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -1358,6 +1358,79 @@ INTERCEPTOR(int, forkpty, int *aparent, char *name, 
const void *termp,
 #define MSAN_MAYBE_INTERCEPT_FORKPTY
 #endif
 
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+INTERCEPTOR(int, __b64_ntop, unsigned char const *src, SIZE_T srclength,
+char *target, SIZE_T targsize) {
+  ENSURE_MSAN_INITED();
+  CHECK_UNPOISONED(src, srclength);
+  InterceptorScope interceptor_scope;
+  int res = REAL(__b64_ntop)(src, srclength, target, targsize);
+  if (res >= 0)
+__msan_unpoison(target, res + 1);
+  return res;
+}
+INTERCEPTOR(int, __b64_pton, char const *src, char *target, SIZE_T targsize) {
+  ENSURE_MSAN_INITED();
+  CHECK_UNPOISONED(src, internal_strlen(src) + 1);
+  InterceptorScope interceptor_scope;
+  int res = REAL(__b64_pton)(src, target, targsize);
+  if (res >= 0)
+__msan_unpoison(target, res);
+  return res;
+}
+#  define MSAN_MAYBE_INTERCEPT___B64_TO \
+MSAN_INTERCEPT_FUNC(__b64_ntop);\
+COMMON_INTERCEPT_FUNCTION(__b64_pton);
+#else
+#  define MSAN_MAYBE_INTERCEPT___B64_TO
+#endif
+
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+#  if __GLIBC_PREREQ(2, 34)
+// Changed with https://sourceware.org/git/?p=glibc.git;h=640bbdf
+#define DN_COMP_INTERCEPTOR_NAME dn_comp
+#define DN_EXPAND_INTERCEPTOR_NAME dn_expand
+#  else
+#define DN_COMP_INTERCEPTOR_NAME __dn_comp
+#define DN_EXPAND_INTERCEPTOR_NAME __dn_expand
+#  endif
+INTERCEPTOR(int, DN_COMP_INTERCEPTOR_NAME, unsigned char *exp_dn,
+unsigned char *comp_dn, int length, unsigned char **dnptrs,
+unsigned char **lastdnptr) {
+  ENSURE_MSAN_INITED();
+  InterceptorScope interceptor_scope;
+  int res = REAL(DN_COMP_INTERCEPTOR_NAME)(exp_dn, comp_dn, length, dnptrs,
+   lastdnptr);
+  if (res >= 0) {
+__msan_unpoison(comp_dn, res);
+if (dnptrs && lastdnptr) {
+  unsigned char **p = dnptrs;
+  for (; p != lastdnptr && *p; ++p);
+  if (p != lastdnptr)
+++p;
+  __ms

[clang] [llvm] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/119091

Summary:
We previously built this for every single architecture to deal with
incompatibility. This patch updates it to use the 'generic' IR that
`libc` and other projects use. Who knows if this will have any
side-effects, probably worth testing more but it passes the tests I
expect to pass on my side.


>From 0df55740f2010c531ee4f96cc0f34aa1b8cea749 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Sat, 7 Dec 2024 13:47:23 -0600
Subject: [PATCH] [OpenMP] Use generic IR for the OpenMP DeviceRTL

Summary:
We previously built this for every single architecture to deal with
incompatibility. This patch updates it to use the 'generic' IR that
`libc` and other projects use. Who knows if this will have any
side-effects, probably worth testing more but it passes the tests I
expect to pass on my side.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp |  3 +-
 clang/lib/Driver/ToolChains/Cuda.cpp   |  1 -
 offload/DeviceRTL/CMakeLists.txt   | 70 
 offload/DeviceRTL/src/Reduction.cpp| 94 +++---
 4 files changed, 64 insertions(+), 104 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7d3d7f8f03c491..3dd90ecf8bca4c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2800,8 +2800,7 @@ void tools::addOpenMPDeviceRTL(const Driver &D,
 : options::OPT_libomptarget_nvptx_bc_path_EQ;
 
   StringRef ArchPrefix = Triple.isAMDGCN() ? "amdgpu" : "nvptx";
-  std::string LibOmpTargetName =
-  ("libomptarget-" + ArchPrefix + "-" + BitcodeSuffix + ".bc").str();
+  std::string LibOmpTargetName = ("libomptarget-" + ArchPrefix + ".bc").str();
 
   // First check whether user specifies bc library
   if (const Arg *A = DriverArgs.getLastArg(LibomptargetBCPathOpt)) {
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 102794829795da..214f1e5d83478f 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -851,7 +851,6 @@ void CudaToolChain::addClangTargetOptions(
   HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
 
   StringRef GpuArch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
-  assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
   assert((DeviceOffloadingKind == Action::OFK_OpenMP ||
   DeviceOffloadingKind == Action::OFK_Cuda) &&
  "Only OpenMP or CUDA offloading kinds are supported for NVIDIA 
GPUs.");
diff --git a/offload/DeviceRTL/CMakeLists.txt b/offload/DeviceRTL/CMakeLists.txt
index 1bf3eb9da38aa1..cda633c41062b6 100644
--- a/offload/DeviceRTL/CMakeLists.txt
+++ b/offload/DeviceRTL/CMakeLists.txt
@@ -42,38 +42,6 @@ set(devicertl_base_directory ${CMAKE_CURRENT_SOURCE_DIR})
 set(include_directory ${devicertl_base_directory}/include)
 set(source_directory ${devicertl_base_directory}/src)
 
-set(all_amdgpu_architectures "gfx700;gfx701;gfx801;gfx803;gfx900;gfx902;gfx906"
- 
"gfx908;gfx90a;gfx90c;gfx940;gfx941;gfx942;gfx950;gfx1010"
- 
"gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035"
- "gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150"
- "gfx1151;gfx1152;gfx1153")
-set(all_nvptx_architectures "sm_35;sm_37;sm_50;sm_52;sm_53;sm_60;sm_61;sm_62"
-"sm_70;sm_72;sm_75;sm_80;sm_86;sm_87;sm_89;sm_90")
-set(all_gpu_architectures
-"${all_amdgpu_architectures};${all_nvptx_architectures}")
-
-set(LIBOMPTARGET_DEVICE_ARCHITECTURES "all" CACHE STRING
-"List of device architectures to be used to compile the OpenMP DeviceRTL.")
-
-if(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "all")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_gpu_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "amdgpu")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_amdgpu_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "nvptx")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_nvptx_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "auto" OR
-   LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "native")
-  if(NOT LIBOMPTARGET_NVPTX_ARCH AND NOT LIBOMPTARGET_AMDGPU_ARCH)
-message(FATAL_ERROR
-  "Could not find 'amdgpu-arch' and 'nvptx-arch' tools required for 
'auto'")
-  elseif(NOT LIBOMPTARGET_FOUND_NVIDIA_GPU AND NOT 
LIBOMPTARGET_FOUND_AMDGPU_GPU)
-message(FATAL_ERROR "No AMD or NVIDIA GPU found on the system when using 
'auto'")
-  endif()
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES
-  
"${LIBOMPTARGET_NVPTX_DETECTED_ARCH_LIST};${LIBOMPTARGET_AMDGPU_DETECTED_ARCH_LIST}")
-endif()
-list(REMOVE_DUPLICATES LIBOMPTARGET_DEVICE_ARCHITECTURES)
-
 set(include_files
   ${include_directory}/Allocator.h
   ${include_directory}/Configuration.

[clang] [llvm] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Shilei Tian via cfe-commits


@@ -141,20 +109,21 @@ set(bc_flags -c -foffload-lto -std=c++17 
-fvisibility=hidden
 
 # first create an object target
 add_library(omptarget.devicertl.all_objs OBJECT IMPORTED)
-function(compileDeviceRTLLibrary target_cpu target_name target_triple)
+function(compileDeviceRTLLibrary target_name target_triple)
   set(target_bc_flags ${ARGN})
 
   set(bc_files "")
   foreach(src ${src_files})
 get_filename_component(infile ${src} ABSOLUTE)
 get_filename_component(outfile ${src} NAME)
-set(outfile "${outfile}-${target_cpu}.bc")
+set(outfile "${outfile}-${target_name}.bc")
 set(depfile "${outfile}.d")
 
 add_custom_command(OUTPUT ${outfile}
   COMMAND ${CLANG_TOOL}
   ${bc_flags}
-  --offload-arch=${target_cpu}
+  -fopenmp-targets=${target_triple}
+  -Xopenmp-target=${target_triple} -march=

shiltian wrote:

so which means there is no arch?

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


[clang] [llvm] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Joseph Huber via cfe-commits

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

>From 4c710e49eea97e542b97e0b5e78b7915acd32383 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Sat, 7 Dec 2024 13:47:23 -0600
Subject: [PATCH 1/2] [OpenMP] Use generic IR for the OpenMP DeviceRTL

Summary:
We previously built this for every single architecture to deal with
incompatibility. This patch updates it to use the 'generic' IR that
`libc` and other projects use. Who knows if this will have any
side-effects, probably worth testing more but it passes the tests I
expect to pass on my side.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp |  3 +-
 clang/lib/Driver/ToolChains/Cuda.cpp   |  1 -
 offload/DeviceRTL/CMakeLists.txt   | 70 -
 offload/DeviceRTL/src/Reduction.cpp| 89 +++---
 4 files changed, 62 insertions(+), 101 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7d3d7f8f03c491..3dd90ecf8bca4c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2800,8 +2800,7 @@ void tools::addOpenMPDeviceRTL(const Driver &D,
 : options::OPT_libomptarget_nvptx_bc_path_EQ;
 
   StringRef ArchPrefix = Triple.isAMDGCN() ? "amdgpu" : "nvptx";
-  std::string LibOmpTargetName =
-  ("libomptarget-" + ArchPrefix + "-" + BitcodeSuffix + ".bc").str();
+  std::string LibOmpTargetName = ("libomptarget-" + ArchPrefix + ".bc").str();
 
   // First check whether user specifies bc library
   if (const Arg *A = DriverArgs.getLastArg(LibomptargetBCPathOpt)) {
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 102794829795da..214f1e5d83478f 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -851,7 +851,6 @@ void CudaToolChain::addClangTargetOptions(
   HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
 
   StringRef GpuArch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
-  assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
   assert((DeviceOffloadingKind == Action::OFK_OpenMP ||
   DeviceOffloadingKind == Action::OFK_Cuda) &&
  "Only OpenMP or CUDA offloading kinds are supported for NVIDIA 
GPUs.");
diff --git a/offload/DeviceRTL/CMakeLists.txt b/offload/DeviceRTL/CMakeLists.txt
index 1bf3eb9da38aa1..cda633c41062b6 100644
--- a/offload/DeviceRTL/CMakeLists.txt
+++ b/offload/DeviceRTL/CMakeLists.txt
@@ -42,38 +42,6 @@ set(devicertl_base_directory ${CMAKE_CURRENT_SOURCE_DIR})
 set(include_directory ${devicertl_base_directory}/include)
 set(source_directory ${devicertl_base_directory}/src)
 
-set(all_amdgpu_architectures "gfx700;gfx701;gfx801;gfx803;gfx900;gfx902;gfx906"
- 
"gfx908;gfx90a;gfx90c;gfx940;gfx941;gfx942;gfx950;gfx1010"
- 
"gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035"
- "gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150"
- "gfx1151;gfx1152;gfx1153")
-set(all_nvptx_architectures "sm_35;sm_37;sm_50;sm_52;sm_53;sm_60;sm_61;sm_62"
-"sm_70;sm_72;sm_75;sm_80;sm_86;sm_87;sm_89;sm_90")
-set(all_gpu_architectures
-"${all_amdgpu_architectures};${all_nvptx_architectures}")
-
-set(LIBOMPTARGET_DEVICE_ARCHITECTURES "all" CACHE STRING
-"List of device architectures to be used to compile the OpenMP DeviceRTL.")
-
-if(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "all")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_gpu_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "amdgpu")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_amdgpu_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "nvptx")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_nvptx_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "auto" OR
-   LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "native")
-  if(NOT LIBOMPTARGET_NVPTX_ARCH AND NOT LIBOMPTARGET_AMDGPU_ARCH)
-message(FATAL_ERROR
-  "Could not find 'amdgpu-arch' and 'nvptx-arch' tools required for 
'auto'")
-  elseif(NOT LIBOMPTARGET_FOUND_NVIDIA_GPU AND NOT 
LIBOMPTARGET_FOUND_AMDGPU_GPU)
-message(FATAL_ERROR "No AMD or NVIDIA GPU found on the system when using 
'auto'")
-  endif()
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES
-  
"${LIBOMPTARGET_NVPTX_DETECTED_ARCH_LIST};${LIBOMPTARGET_AMDGPU_DETECTED_ARCH_LIST}")
-endif()
-list(REMOVE_DUPLICATES LIBOMPTARGET_DEVICE_ARCHITECTURES)
-
 set(include_files
   ${include_directory}/Allocator.h
   ${include_directory}/Configuration.h
@@ -141,20 +109,21 @@ set(bc_flags -c -foffload-lto -std=c++17 
-fvisibility=hidden
 
 # first create an object target
 add_library(omptarget.devicertl.all_objs OBJECT IMPORTED)
-function(compileDeviceRTLLibrary target_cpu target_name target_triple)
+function(compileDeviceRTLLibrary target_name ta

[clang] [llvm] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Joseph Huber via cfe-commits

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

>From 4c710e49eea97e542b97e0b5e78b7915acd32383 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Sat, 7 Dec 2024 13:47:23 -0600
Subject: [PATCH] [OpenMP] Use generic IR for the OpenMP DeviceRTL

Summary:
We previously built this for every single architecture to deal with
incompatibility. This patch updates it to use the 'generic' IR that
`libc` and other projects use. Who knows if this will have any
side-effects, probably worth testing more but it passes the tests I
expect to pass on my side.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp |  3 +-
 clang/lib/Driver/ToolChains/Cuda.cpp   |  1 -
 offload/DeviceRTL/CMakeLists.txt   | 70 -
 offload/DeviceRTL/src/Reduction.cpp| 89 +++---
 4 files changed, 62 insertions(+), 101 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7d3d7f8f03c491..3dd90ecf8bca4c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2800,8 +2800,7 @@ void tools::addOpenMPDeviceRTL(const Driver &D,
 : options::OPT_libomptarget_nvptx_bc_path_EQ;
 
   StringRef ArchPrefix = Triple.isAMDGCN() ? "amdgpu" : "nvptx";
-  std::string LibOmpTargetName =
-  ("libomptarget-" + ArchPrefix + "-" + BitcodeSuffix + ".bc").str();
+  std::string LibOmpTargetName = ("libomptarget-" + ArchPrefix + ".bc").str();
 
   // First check whether user specifies bc library
   if (const Arg *A = DriverArgs.getLastArg(LibomptargetBCPathOpt)) {
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 102794829795da..214f1e5d83478f 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -851,7 +851,6 @@ void CudaToolChain::addClangTargetOptions(
   HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
 
   StringRef GpuArch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
-  assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
   assert((DeviceOffloadingKind == Action::OFK_OpenMP ||
   DeviceOffloadingKind == Action::OFK_Cuda) &&
  "Only OpenMP or CUDA offloading kinds are supported for NVIDIA 
GPUs.");
diff --git a/offload/DeviceRTL/CMakeLists.txt b/offload/DeviceRTL/CMakeLists.txt
index 1bf3eb9da38aa1..cda633c41062b6 100644
--- a/offload/DeviceRTL/CMakeLists.txt
+++ b/offload/DeviceRTL/CMakeLists.txt
@@ -42,38 +42,6 @@ set(devicertl_base_directory ${CMAKE_CURRENT_SOURCE_DIR})
 set(include_directory ${devicertl_base_directory}/include)
 set(source_directory ${devicertl_base_directory}/src)
 
-set(all_amdgpu_architectures "gfx700;gfx701;gfx801;gfx803;gfx900;gfx902;gfx906"
- 
"gfx908;gfx90a;gfx90c;gfx940;gfx941;gfx942;gfx950;gfx1010"
- 
"gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035"
- "gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150"
- "gfx1151;gfx1152;gfx1153")
-set(all_nvptx_architectures "sm_35;sm_37;sm_50;sm_52;sm_53;sm_60;sm_61;sm_62"
-"sm_70;sm_72;sm_75;sm_80;sm_86;sm_87;sm_89;sm_90")
-set(all_gpu_architectures
-"${all_amdgpu_architectures};${all_nvptx_architectures}")
-
-set(LIBOMPTARGET_DEVICE_ARCHITECTURES "all" CACHE STRING
-"List of device architectures to be used to compile the OpenMP DeviceRTL.")
-
-if(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "all")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_gpu_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "amdgpu")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_amdgpu_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "nvptx")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_nvptx_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "auto" OR
-   LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "native")
-  if(NOT LIBOMPTARGET_NVPTX_ARCH AND NOT LIBOMPTARGET_AMDGPU_ARCH)
-message(FATAL_ERROR
-  "Could not find 'amdgpu-arch' and 'nvptx-arch' tools required for 
'auto'")
-  elseif(NOT LIBOMPTARGET_FOUND_NVIDIA_GPU AND NOT 
LIBOMPTARGET_FOUND_AMDGPU_GPU)
-message(FATAL_ERROR "No AMD or NVIDIA GPU found on the system when using 
'auto'")
-  endif()
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES
-  
"${LIBOMPTARGET_NVPTX_DETECTED_ARCH_LIST};${LIBOMPTARGET_AMDGPU_DETECTED_ARCH_LIST}")
-endif()
-list(REMOVE_DUPLICATES LIBOMPTARGET_DEVICE_ARCHITECTURES)
-
 set(include_files
   ${include_directory}/Allocator.h
   ${include_directory}/Configuration.h
@@ -141,20 +109,21 @@ set(bc_flags -c -foffload-lto -std=c++17 
-fvisibility=hidden
 
 # first create an object target
 add_library(omptarget.devicertl.all_objs OBJECT IMPORTED)
-function(compileDeviceRTLLibrary target_cpu target_name target_triple)
+function(compileDeviceRTLLibrary target_name target

[clang] [llvm] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Shilei Tian via cfe-commits


@@ -141,20 +109,21 @@ set(bc_flags -c -foffload-lto -std=c++17 
-fvisibility=hidden
 
 # first create an object target
 add_library(omptarget.devicertl.all_objs OBJECT IMPORTED)
-function(compileDeviceRTLLibrary target_cpu target_name target_triple)
+function(compileDeviceRTLLibrary target_name target_triple)
   set(target_bc_flags ${ARGN})
 
   set(bc_files "")
   foreach(src ${src_files})
 get_filename_component(infile ${src} ABSOLUTE)
 get_filename_component(outfile ${src} NAME)
-set(outfile "${outfile}-${target_cpu}.bc")
+set(outfile "${outfile}-${target_name}.bc")
 set(depfile "${outfile}.d")
 
 add_custom_command(OUTPUT ${outfile}
   COMMAND ${CLANG_TOOL}
   ${bc_flags}
-  --offload-arch=${target_cpu}
+  -fopenmp-targets=${target_triple}
+  -Xopenmp-target=${target_triple} -march=

shiltian wrote:

and nothing after `-march=`?

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


[clang] [llvm] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Joseph Huber via cfe-commits


@@ -141,20 +109,21 @@ set(bc_flags -c -foffload-lto -std=c++17 
-fvisibility=hidden
 
 # first create an object target
 add_library(omptarget.devicertl.all_objs OBJECT IMPORTED)
-function(compileDeviceRTLLibrary target_cpu target_name target_triple)
+function(compileDeviceRTLLibrary target_name target_triple)
   set(target_bc_flags ${ARGN})
 
   set(bc_files "")
   foreach(src ${src_files})
 get_filename_component(infile ${src} ABSOLUTE)
 get_filename_component(outfile ${src} NAME)
-set(outfile "${outfile}-${target_cpu}.bc")
+set(outfile "${outfile}-${target_name}.bc")
 set(depfile "${outfile}.d")
 
 add_custom_command(OUTPUT ${outfile}
   COMMAND ${CLANG_TOOL}
   ${bc_flags}
-  --offload-arch=${target_cpu}
+  -fopenmp-targets=${target_triple}
+  -Xopenmp-target=${target_triple} -march=

jhuber6 wrote:

Intentional

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


[clang] [llvm] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Shilei Tian via cfe-commits

https://github.com/shiltian commented:

I like this method, but just out of curiosity, did we use anything in AMDGPU 
implementation that has target dependent lowering in the front end? If not, 
this is totally fine I'd say.

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


[clang] [llvm] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Shilei Tian via cfe-commits


@@ -74,49 +72,53 @@ static int32_t nvptx_parallel_reduce_nowait(void 
*reduce_data,
   uint32_t NumThreads = omp_get_num_threads();
   if (NumThreads == 1)
 return 1;
-/*
- * This reduce function handles reduction within a team. It handles
- * parallel regions in both L1 and L2 parallelism levels. It also
- * supports Generic, SPMD, and NoOMP modes.
- *
- * 1. Reduce within a warp.
- * 2. Warp master copies value to warp 0 via shared memory.
- * 3. Warp 0 reduces to a single value.
- * 4. The reduced value is available in the thread that returns 1.
- */
-
-#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 700
-  uint32_t WarpsNeeded =
-  (NumThreads + mapping::getWarpSize() - 1) / mapping::getWarpSize();
-  uint32_t WarpId = mapping::getWarpIdInBlock();
-
-  // Volta execution model:
-  // For the Generic execution mode a parallel region either has 1 thread and
-  // beyond that, always a multiple of 32. For the SPMD execution mode we may
-  // have any number of threads.
-  if ((NumThreads % mapping::getWarpSize() == 0) || (WarpId < WarpsNeeded - 1))
-gpu_regular_warp_reduce(reduce_data, shflFct);
-  else if (NumThreads > 1) // Only SPMD execution mode comes thru this case.
-gpu_irregular_warp_reduce(reduce_data, shflFct,
-  /*LaneCount=*/NumThreads % 
mapping::getWarpSize(),
-  /*LaneId=*/mapping::getThreadIdInBlock() %
-  mapping::getWarpSize());
 
-  // When we have more than [mapping::getWarpSize()] number of threads
-  // a block reduction is performed here.
   //
-  // Only L1 parallel region can enter this if condition.
-  if (NumThreads > mapping::getWarpSize()) {
-// Gather all the reduced values from each warp
-// to the first warp.
-cpyFct(reduce_data, WarpsNeeded);
+  // This reduce function handles reduction within a team. It handles
+  // parallel regions in both L1 and L2 parallelism levels. It also
+  // supports Generic, SPMD, and NoOMP modes.
+  //
+  // 1. Reduce within a warp.
+  // 2. Warp master copies value to warp 0 via shared memory.
+  // 3. Warp 0 reduces to a single value.
+  // 4. The reduced value is available in the thread that returns 1.
+  //
 
-if (WarpId == 0)
-  gpu_irregular_warp_reduce(reduce_data, shflFct, WarpsNeeded,
-BlockThreadId);
+#if __has_builtin(__nvvm_reflect)
+  if (__nvvm_reflect("__CUDA_ARCH") >= 700) {

shiltian wrote:

I'll try to make an AMDGPU counterpart for this one, though it doesn't look 
like necessary for the purpose of OpenMP device runtime.

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


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-07 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 6568ceb9fa1c49383b2fa102a04fd8fd3af01491 
206f8f800df7e51648ec00b110f2437dca5a3ff6 --extensions cpp -- 
clang/lib/Driver/ToolChains/OHOS.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp 
b/clang/lib/Driver/ToolChains/OHOS.cpp
index 723c891d2a..c9a532771b 100644
--- a/clang/lib/Driver/ToolChains/OHOS.cpp
+++ b/clang/lib/Driver/ToolChains/OHOS.cpp
@@ -344,11 +344,11 @@ std::string OHOS::getCompilerRT(const ArgList &Args, 
StringRef Component,
   llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()),
   SelectedMultilib.gccSuffix(), CRTBasename);
   if (getVFS().exists(Path))
-  return std::string(Path);
+return std::string(Path);
 
   std::string NewPath = ToolChain::getCompilerRT(Args, Component, Type);
   if (getVFS().exists(NewPath))
-  return NewPath;
+return NewPath;
 
   return std::string(Path);
 }

``




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


[clang] [PAC][clang] Add new features to pauthtest ABI (PR #113150)

2024-12-07 Thread Daniil Kovalev via cfe-commits

https://github.com/kovdan01 updated 
https://github.com/llvm/llvm-project/pull/113150

>From 74814fd9424853399196b7d1e73f6171b0f1980b Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Mon, 21 Oct 2024 10:58:04 +0300
Subject: [PATCH] [PAC][clang] Add new features to pauthtest ABI

Enable init/fini address discrimination, type info vtable pointer
discrimination and AArch64 jump table hardening as part of pauthtest ABI.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 14 ++
 clang/test/Driver/aarch64-ptrauth.c   | 11 ---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 7ef55a33547c50..079048a20738e6 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1531,6 +1531,11 @@ static void handlePAuthABI(const ArgList &DriverArgs, 
ArgStringList &CC1Args) {
   options::OPT_fno_ptrauth_vtable_pointer_type_discrimination))
 CC1Args.push_back("-fptrauth-vtable-pointer-type-discrimination");
 
+  if (!DriverArgs.hasArg(
+  options::OPT_fptrauth_type_info_vtable_pointer_discrimination,
+  options::OPT_fno_ptrauth_type_info_vtable_pointer_discrimination))
+CC1Args.push_back("-fptrauth-type-info-vtable-pointer-discrimination");
+
   if (!DriverArgs.hasArg(options::OPT_fptrauth_indirect_gotos,
  options::OPT_fno_ptrauth_indirect_gotos))
 CC1Args.push_back("-fptrauth-indirect-gotos");
@@ -1538,6 +1543,15 @@ static void handlePAuthABI(const ArgList &DriverArgs, 
ArgStringList &CC1Args) {
   if (!DriverArgs.hasArg(options::OPT_fptrauth_init_fini,
  options::OPT_fno_ptrauth_init_fini))
 CC1Args.push_back("-fptrauth-init-fini");
+
+  if (!DriverArgs.hasArg(
+  options::OPT_fptrauth_init_fini_address_discrimination,
+  options::OPT_fno_ptrauth_init_fini_address_discrimination))
+CC1Args.push_back("-fptrauth-init-fini-address-discrimination");
+
+  if (!DriverArgs.hasArg(options::OPT_faarch64_jump_table_hardening,
+ options::OPT_fno_aarch64_jump_table_hardening))
+CC1Args.push_back("-faarch64-jump-table-hardening");
 }
 
 static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
diff --git a/clang/test/Driver/aarch64-ptrauth.c 
b/clang/test/Driver/aarch64-ptrauth.c
index d036189e614983..32acd83480849c 100644
--- a/clang/test/Driver/aarch64-ptrauth.c
+++ b/clang/test/Driver/aarch64-ptrauth.c
@@ -23,18 +23,23 @@
 // RUN: %clang -### -c --target=aarch64-linux-pauthtest %s 2>&1 | FileCheck %s 
--check-prefix=PAUTHABI1
 // PAUTHABI1:  "-cc1"{{.*}} "-triple" "aarch64-unknown-linux-pauthtest"
 // PAUTHABI1-SAME: "-target-abi" "pauthtest"
-// PAUTHABI1-SAME: "-fptrauth-intrinsics" "-fptrauth-calls" 
"-fptrauth-returns" "-fptrauth-auth-traps" 
"-fptrauth-vtable-pointer-address-discrimination" 
"-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-indirect-gotos" 
"-fptrauth-init-fini"
+// PAUTHABI1-SAME: "-fptrauth-intrinsics" "-fptrauth-calls" 
"-fptrauth-returns" "-fptrauth-auth-traps" 
"-fptrauth-vtable-pointer-address-discrimination" 
"-fptrauth-vtable-pointer-type-discrimination" 
"-fptrauth-type-info-vtable-pointer-discrimination" "-fptrauth-indirect-gotos" 
"-fptrauth-init-fini" "-fptrauth-init-fini-address-discrimination" 
"-faarch64-jump-table-hardening"
 
 // RUN: %clang -### -c --target=aarch64 -mabi=pauthtest 
-fno-ptrauth-intrinsics \
 // RUN:   -fno-ptrauth-calls -fno-ptrauth-returns -fno-ptrauth-auth-traps \
 // RUN:   -fno-ptrauth-vtable-pointer-address-discrimination 
-fno-ptrauth-vtable-pointer-type-discrimination \
-// RUN:   -fno-ptrauth-indirect-gotos -fno-ptrauth-init-fini %s 2>&1 | 
FileCheck %s --check-prefix=PAUTHABI2
+// RUN:   -fno-ptrauth-type-info-vtable-pointer-discrimination 
-fno-ptrauth-indirect-gotos \
+// RUN:   -fno-ptrauth-init-fini -fno-ptrauth-init-fini-address-discrimination 
\
+// RUN:   -fno-aarch64-jump-table-hardening %s 2>&1 | FileCheck %s 
--check-prefix=PAUTHABI2
 // RUN: %clang -### -c --target=aarch64-pauthtest -fno-ptrauth-intrinsics \
 // RUN:   -fno-ptrauth-calls -fno-ptrauth-returns -fno-ptrauth-auth-traps \
 // RUN:   -fno-ptrauth-vtable-pointer-address-discrimination 
-fno-ptrauth-vtable-pointer-type-discrimination \
-// RUN:   -fno-ptrauth-indirect-gotos -fno-ptrauth-init-fini %s 2>&1 | 
FileCheck %s --check-prefix=PAUTHABI2
+// RUN:   -fno-ptrauth-type-info-vtable-pointer-discrimination 
-fno-ptrauth-indirect-gotos \
+// RUN:   -fno-ptrauth-init-fini -fno-ptrauth-init-fini-address-discrimination 
\
+// RUN:   -fno-aarch64-jump-table-hardening %s 2>&1 | FileCheck %s 
--check-prefix=PAUTHABI2
 // PAUTHABI2: "-cc1"
 // PAUTHABI2-NOT: "-fptrauth-
+// PAUTHABI2-NOT: "-faarch64-jump-table-hardening"
 
 // RUN: not %clang -### -c --target=x86_64 -fptrauth-intrinsics 
-fptrauth-calls -fptrauth-returns -fptrauth-auth-traps \
 // RUN:   -fptrauth-vtable-pointer-addr

[clang] [compiler-rt] Move interceptors for libresolv functions to MSan (PR #119071)

2024-12-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Aaron Puchert (aaronpuchert)


Changes

The functions are not relevant for most sanitizers and only required for MSan 
to see which regions have been written to. This eliminates a link dependency 
for all other sanitizers and fixes #59007: while `-lresolv` had been 
added for the static runtime in 6dce56b2a308, it wasn't added to the shared 
runtimes.

Instead of just moving the interceptors, we adapt them to MSan conventions:
* We don't skip intercepting when `msan_init_is_running` is true, but directly 
call ENSURE_MSAN_INITED() like most other interceptors. It seems unlikely that 
these functions are called during initialization.
* We don't unpoison `errno`, because none of the functions is specified to use 
it.

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


5 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+1-1) 
- (modified) compiler-rt/lib/msan/msan_interceptors.cpp (+76) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc 
(-78) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h 
(-2) 
- (removed) compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp (-42) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7d3d7f8f03c491..03dbdc27975b42 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1410,7 +1410,7 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-  !TC.getTriple().isMusl())
+  !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())
 CmdArgs.push_back("-lresolv");
 }
 
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp 
b/compiler-rt/lib/msan/msan_interceptors.cpp
index f05c20618780b7..b2098d8a26d229 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -1358,6 +1358,79 @@ INTERCEPTOR(int, forkpty, int *aparent, char *name, 
const void *termp,
 #define MSAN_MAYBE_INTERCEPT_FORKPTY
 #endif
 
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+INTERCEPTOR(int, __b64_ntop, unsigned char const *src, SIZE_T srclength,
+char *target, SIZE_T targsize) {
+  ENSURE_MSAN_INITED();
+  CHECK_UNPOISONED(src, srclength);
+  InterceptorScope interceptor_scope;
+  int res = REAL(__b64_ntop)(src, srclength, target, targsize);
+  if (res >= 0)
+__msan_unpoison(target, res + 1);
+  return res;
+}
+INTERCEPTOR(int, __b64_pton, char const *src, char *target, SIZE_T targsize) {
+  ENSURE_MSAN_INITED();
+  CHECK_UNPOISONED(src, internal_strlen(src) + 1);
+  InterceptorScope interceptor_scope;
+  int res = REAL(__b64_pton)(src, target, targsize);
+  if (res >= 0)
+__msan_unpoison(target, res);
+  return res;
+}
+#  define MSAN_MAYBE_INTERCEPT___B64_TO \
+MSAN_INTERCEPT_FUNC(__b64_ntop);\
+COMMON_INTERCEPT_FUNCTION(__b64_pton);
+#else
+#  define MSAN_MAYBE_INTERCEPT___B64_TO
+#endif
+
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+#  if __GLIBC_PREREQ(2, 34)
+// Changed with https://sourceware.org/git/?p=glibc.git;h=640bbdf
+#define DN_COMP_INTERCEPTOR_NAME dn_comp
+#define DN_EXPAND_INTERCEPTOR_NAME dn_expand
+#  else
+#define DN_COMP_INTERCEPTOR_NAME __dn_comp
+#define DN_EXPAND_INTERCEPTOR_NAME __dn_expand
+#  endif
+INTERCEPTOR(int, DN_COMP_INTERCEPTOR_NAME, unsigned char *exp_dn,
+unsigned char *comp_dn, int length, unsigned char **dnptrs,
+unsigned char **lastdnptr) {
+  ENSURE_MSAN_INITED();
+  InterceptorScope interceptor_scope;
+  int res = REAL(DN_COMP_INTERCEPTOR_NAME)(exp_dn, comp_dn, length, dnptrs,
+   lastdnptr);
+  if (res >= 0) {
+__msan_unpoison(comp_dn, res);
+if (dnptrs && lastdnptr) {
+  unsigned char **p = dnptrs;
+  for (; p != lastdnptr && *p; ++p);
+  if (p != lastdnptr)
+++p;
+  __msan_unpoison(dnptrs, (p - dnptrs) * sizeof(*p));
+}
+  }
+  return res;
+}
+INTERCEPTOR(int, DN_EXPAND_INTERCEPTOR_NAME, unsigned char const *base,
+unsigned char const *end, unsigned char const *src, char *dest,
+int space) {
+  ENSURE_MSAN_INITED();
+  // TODO: add read check if __dn_comp intercept added
+  InterceptorScope interceptor_scope;
+  int res = REAL(DN_EXPAND_INTERCEPTOR_NAME)(base, end, src, dest, space);
+  if (res >= 0)
+__msan_unpoison(dest, internal_strlen(dest) + 1);
+  return res;
+}
+#  define MSAN_MAYBE_INTERCEPT_DN_COMP_EXPAND  \
+MSAN_INTERCEPT_FUNC(DN_COMP_INTERCEPTOR_NAME); \
+MSAN_INTERCEPT_FUNC(DN_EXPAND_INTERCEPTOR_NAME);
+#else
+#  define MSAN_MAYBE_INTERCEPT_DN_COMP_EXPAND
+#endif
+
 struct MSanInterceptorContext {
   bool in_interceptor_scop

[clang] [compiler-rt] Move interceptors for libresolv functions to MSan (PR #119071)

2024-12-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Aaron Puchert (aaronpuchert)


Changes

The functions are not relevant for most sanitizers and only required for MSan 
to see which regions have been written to. This eliminates a link dependency 
for all other sanitizers and fixes #59007: while `-lresolv` had been 
added for the static runtime in 6dce56b2a308, it wasn't added to the shared 
runtimes.

Instead of just moving the interceptors, we adapt them to MSan conventions:
* We don't skip intercepting when `msan_init_is_running` is true, but directly 
call ENSURE_MSAN_INITED() like most other interceptors. It seems unlikely that 
these functions are called during initialization.
* We don't unpoison `errno`, because none of the functions is specified to use 
it.

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


5 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+1-1) 
- (modified) compiler-rt/lib/msan/msan_interceptors.cpp (+76) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc 
(-78) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h 
(-2) 
- (removed) compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp (-42) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7d3d7f8f03c491..03dbdc27975b42 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1410,7 +1410,7 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-  !TC.getTriple().isMusl())
+  !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())
 CmdArgs.push_back("-lresolv");
 }
 
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp 
b/compiler-rt/lib/msan/msan_interceptors.cpp
index f05c20618780b7..b2098d8a26d229 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -1358,6 +1358,79 @@ INTERCEPTOR(int, forkpty, int *aparent, char *name, 
const void *termp,
 #define MSAN_MAYBE_INTERCEPT_FORKPTY
 #endif
 
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+INTERCEPTOR(int, __b64_ntop, unsigned char const *src, SIZE_T srclength,
+char *target, SIZE_T targsize) {
+  ENSURE_MSAN_INITED();
+  CHECK_UNPOISONED(src, srclength);
+  InterceptorScope interceptor_scope;
+  int res = REAL(__b64_ntop)(src, srclength, target, targsize);
+  if (res >= 0)
+__msan_unpoison(target, res + 1);
+  return res;
+}
+INTERCEPTOR(int, __b64_pton, char const *src, char *target, SIZE_T targsize) {
+  ENSURE_MSAN_INITED();
+  CHECK_UNPOISONED(src, internal_strlen(src) + 1);
+  InterceptorScope interceptor_scope;
+  int res = REAL(__b64_pton)(src, target, targsize);
+  if (res >= 0)
+__msan_unpoison(target, res);
+  return res;
+}
+#  define MSAN_MAYBE_INTERCEPT___B64_TO \
+MSAN_INTERCEPT_FUNC(__b64_ntop);\
+COMMON_INTERCEPT_FUNCTION(__b64_pton);
+#else
+#  define MSAN_MAYBE_INTERCEPT___B64_TO
+#endif
+
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+#  if __GLIBC_PREREQ(2, 34)
+// Changed with https://sourceware.org/git/?p=glibc.git;h=640bbdf
+#define DN_COMP_INTERCEPTOR_NAME dn_comp
+#define DN_EXPAND_INTERCEPTOR_NAME dn_expand
+#  else
+#define DN_COMP_INTERCEPTOR_NAME __dn_comp
+#define DN_EXPAND_INTERCEPTOR_NAME __dn_expand
+#  endif
+INTERCEPTOR(int, DN_COMP_INTERCEPTOR_NAME, unsigned char *exp_dn,
+unsigned char *comp_dn, int length, unsigned char **dnptrs,
+unsigned char **lastdnptr) {
+  ENSURE_MSAN_INITED();
+  InterceptorScope interceptor_scope;
+  int res = REAL(DN_COMP_INTERCEPTOR_NAME)(exp_dn, comp_dn, length, dnptrs,
+   lastdnptr);
+  if (res >= 0) {
+__msan_unpoison(comp_dn, res);
+if (dnptrs && lastdnptr) {
+  unsigned char **p = dnptrs;
+  for (; p != lastdnptr && *p; ++p);
+  if (p != lastdnptr)
+++p;
+  __msan_unpoison(dnptrs, (p - dnptrs) * sizeof(*p));
+}
+  }
+  return res;
+}
+INTERCEPTOR(int, DN_EXPAND_INTERCEPTOR_NAME, unsigned char const *base,
+unsigned char const *end, unsigned char const *src, char *dest,
+int space) {
+  ENSURE_MSAN_INITED();
+  // TODO: add read check if __dn_comp intercept added
+  InterceptorScope interceptor_scope;
+  int res = REAL(DN_EXPAND_INTERCEPTOR_NAME)(base, end, src, dest, space);
+  if (res >= 0)
+__msan_unpoison(dest, internal_strlen(dest) + 1);
+  return res;
+}
+#  define MSAN_MAYBE_INTERCEPT_DN_COMP_EXPAND  \
+MSAN_INTERCEPT_FUNC(DN_COMP_INTERCEPTOR_NAME); \
+MSAN_INTERCEPT_FUNC(DN_EXPAND_INTERCEPTOR_NAME);
+#else
+#  define MSAN_MAYBE_INTERCEPT_DN_COMP_EXPAND
+#endif
+
 struct MSanInterceptorContext {
   bool in_interceptor_scope;
 };
@@

[clang] [compiler-rt] Move interceptors for libresolv functions to MSan (PR #119071)

2024-12-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Aaron Puchert (aaronpuchert)


Changes

The functions are not relevant for most sanitizers and only required for MSan 
to see which regions have been written to. This eliminates a link dependency 
for all other sanitizers and fixes #59007: while `-lresolv` had been 
added for the static runtime in 6dce56b2a308, it wasn't added to the shared 
runtimes.

Instead of just moving the interceptors, we adapt them to MSan conventions:
* We don't skip intercepting when `msan_init_is_running` is true, but directly 
call ENSURE_MSAN_INITED() like most other interceptors. It seems unlikely that 
these functions are called during initialization.
* We don't unpoison `errno`, because none of the functions is specified to use 
it.

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


5 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+1-1) 
- (modified) compiler-rt/lib/msan/msan_interceptors.cpp (+76) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc 
(-78) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h 
(-2) 
- (removed) compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp (-42) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7d3d7f8f03c491..03dbdc27975b42 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1410,7 +1410,7 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-  !TC.getTriple().isMusl())
+  !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())
 CmdArgs.push_back("-lresolv");
 }
 
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp 
b/compiler-rt/lib/msan/msan_interceptors.cpp
index f05c20618780b7..b2098d8a26d229 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -1358,6 +1358,79 @@ INTERCEPTOR(int, forkpty, int *aparent, char *name, 
const void *termp,
 #define MSAN_MAYBE_INTERCEPT_FORKPTY
 #endif
 
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+INTERCEPTOR(int, __b64_ntop, unsigned char const *src, SIZE_T srclength,
+char *target, SIZE_T targsize) {
+  ENSURE_MSAN_INITED();
+  CHECK_UNPOISONED(src, srclength);
+  InterceptorScope interceptor_scope;
+  int res = REAL(__b64_ntop)(src, srclength, target, targsize);
+  if (res >= 0)
+__msan_unpoison(target, res + 1);
+  return res;
+}
+INTERCEPTOR(int, __b64_pton, char const *src, char *target, SIZE_T targsize) {
+  ENSURE_MSAN_INITED();
+  CHECK_UNPOISONED(src, internal_strlen(src) + 1);
+  InterceptorScope interceptor_scope;
+  int res = REAL(__b64_pton)(src, target, targsize);
+  if (res >= 0)
+__msan_unpoison(target, res);
+  return res;
+}
+#  define MSAN_MAYBE_INTERCEPT___B64_TO \
+MSAN_INTERCEPT_FUNC(__b64_ntop);\
+COMMON_INTERCEPT_FUNCTION(__b64_pton);
+#else
+#  define MSAN_MAYBE_INTERCEPT___B64_TO
+#endif
+
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+#  if __GLIBC_PREREQ(2, 34)
+// Changed with https://sourceware.org/git/?p=glibc.git;h=640bbdf
+#define DN_COMP_INTERCEPTOR_NAME dn_comp
+#define DN_EXPAND_INTERCEPTOR_NAME dn_expand
+#  else
+#define DN_COMP_INTERCEPTOR_NAME __dn_comp
+#define DN_EXPAND_INTERCEPTOR_NAME __dn_expand
+#  endif
+INTERCEPTOR(int, DN_COMP_INTERCEPTOR_NAME, unsigned char *exp_dn,
+unsigned char *comp_dn, int length, unsigned char **dnptrs,
+unsigned char **lastdnptr) {
+  ENSURE_MSAN_INITED();
+  InterceptorScope interceptor_scope;
+  int res = REAL(DN_COMP_INTERCEPTOR_NAME)(exp_dn, comp_dn, length, dnptrs,
+   lastdnptr);
+  if (res >= 0) {
+__msan_unpoison(comp_dn, res);
+if (dnptrs && lastdnptr) {
+  unsigned char **p = dnptrs;
+  for (; p != lastdnptr && *p; ++p);
+  if (p != lastdnptr)
+++p;
+  __msan_unpoison(dnptrs, (p - dnptrs) * sizeof(*p));
+}
+  }
+  return res;
+}
+INTERCEPTOR(int, DN_EXPAND_INTERCEPTOR_NAME, unsigned char const *base,
+unsigned char const *end, unsigned char const *src, char *dest,
+int space) {
+  ENSURE_MSAN_INITED();
+  // TODO: add read check if __dn_comp intercept added
+  InterceptorScope interceptor_scope;
+  int res = REAL(DN_EXPAND_INTERCEPTOR_NAME)(base, end, src, dest, space);
+  if (res >= 0)
+__msan_unpoison(dest, internal_strlen(dest) + 1);
+  return res;
+}
+#  define MSAN_MAYBE_INTERCEPT_DN_COMP_EXPAND  \
+MSAN_INTERCEPT_FUNC(DN_COMP_INTERCEPTOR_NAME); \
+MSAN_INTERCEPT_FUNC(DN_EXPAND_INTERCEPTOR_NAME);
+#else
+#  define MSAN_MAYBE_INTERCEPT_DN_COMP_EXPAND
+#endif
+
 struct MSanInterceptorContext {
   bool in_interceptor_scope;
 };
@@ -1916,

[clang] [compiler-rt] Move interceptors for libresolv functions to MSan (PR #119071)

2024-12-07 Thread Aaron Puchert via cfe-commits

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


[clang] [rtsan] NFC: Adding links to Disabling, adding a few ` marks (PR #119075)

2024-12-07 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-clang-aarch64-darwin` 
running on `doug-worker-4` while building `clang` at step 6 
"test-build-unified-tree-check-all".

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


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

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'LLVM :: 
ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll' FAILED 

Exit Code: 2

Command Output (stderr):
--
RUN: at line 1: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli 
-jit-kind=orc-lazy -compile-threads=2 -thread-entry hello 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll
 | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli -jit-kind=orc-lazy 
-compile-threads=2 -thread-entry hello 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace.
 #0 0x0001018c3280 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli+0x100e7b280)
 #1 0x0001018c1304 llvm::sys::RunSignalHandlers() 
(/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli+0x100e79304)
 #2 0x0001018c393c SignalHandler(int) 
(/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli+0x100e7b93c)
 #3 0x0001891c2584 (/usr/lib/system/libsystem_platform.dylib+0x18047a584)
 #4 0x00018919121c (/usr/lib/system/libsystem_pthread.dylib+0x18044921c)
 #5 0x0001890b7ad0 (/usr/lib/libc++.1.dylib+0x18036fad0)
 #6 0x00010147eb48 void llvm::detail::UniqueFunctionBase, llvm::detail::DenseMapPair>>>::CallImpl, 
llvm::detail::DenseMapPair> 
const&)::$_44>(void*, llvm::Expected, llvm::detail::DenseMapPair>>&) 
(/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli+0x100a36b48)
 #7 0x00010147a2fc 
llvm::orc::AsynchronousSymbolQuery::handleComplete(llvm::orc::ExecutionSession&)::RunQueryCompleteTask::run()
 (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli+0x100a322fc)
 #8 0x00010152eb30 void* 
std::__1::__thread_proxy[abi:un170006]>, 
llvm::orc::DynamicThreadPoolTaskDispatcher::dispatch(std::__1::unique_ptr>)::$_0>>(void*) 
(/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli+0x100ae6b30)
 #9 0x000189191f94 (/usr/lib/system/libsystem_pthread.dylib+0x180449f94)
#10 0x00018918cd34 (/usr/lib/system/libsystem_pthread.dylib+0x180444d34)
FileCheck error: '' is empty.
FileCheck command line:  
/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll

--




```



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


[clang] Draft (PR #119082)

2024-12-07 Thread via cfe-commits

https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/119082

None

>From 2af0eb663a106b712a3c9eb2028dc35014884708 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sun, 8 Dec 2024 01:11:51 +0800
Subject: [PATCH] constexpr elementwise add_sat

---
 clang/docs/LanguageExtensions.rst |  3 +-
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Builtins.td |  2 +-
 clang/lib/AST/ExprConstant.cpp| 35 +++
 .../test/CodeGen/builtins-elementwise-math.c  |  2 +-
 clang/test/Sema/constant_builtins_vector.cpp  |  8 +
 6 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 6b950d05fb9bf9..40c0a0e5f1161c 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -648,7 +648,8 @@ elementwise to the input.
 Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = 
±infinity
 
 The integer elementwise intrinsics, including 
``__builtin_elementwise_popcount``,
-``__builtin_elementwise_bitreverse``, can be called in a ``constexpr`` context.
+``__builtin_elementwise_bitreverse``, ``__builtin_elementwise_add_sat``, can be
+called in a ``constexpr`` context.
 
 == 
== 
=
  Name   Operation  
   Supported element types
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 59e3a6609123d2..5aeda3ade7573a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -414,6 +414,7 @@ Non-comprehensive list of changes in this release
 - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
 - ``__builtin_elementwise_popcount`` function can now be used in constant 
expressions.
 - ``__builtin_elementwise_bitreverse`` function can now be used in constant 
expressions.
+- ``__builtin_elementwise_add_sat`` function can now be used in constant 
expressions.
 
 New Compiler Flags
 --
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index e2c3d3c535571c..1186ece419fdd2 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1450,7 +1450,7 @@ def ElementwiseFma : Builtin {
 
 def ElementwiseAddSat : Builtin {
   let Spellings = ["__builtin_elementwise_add_sat"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6b5b95aee35522..001773dc28dedc 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11339,6 +11339,31 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 
 return Success(APValue(ResultElements.data(), ResultElements.size()), E);
   }
+  case Builtin::BI__builtin_elementwise_add_sat: {
+APValue SourceLHS, SourceRHS;
+if (!EvaluateAsRValue(Info, E->getArg(0), SourceLHS) ||
+!EvaluateAsRValue(Info, E->getArg(1), SourceRHS))
+  return false;
+
+QualType DestEltTy = E->getType()->castAs()->getElementType();
+unsigned SourceLen = SourceLHS.getVectorLength();
+SmallVector ResultElements;
+ResultElements.reserve(SourceLen);
+
+for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
+  APSInt LHS = SourceLHS.getVectorElt(EltNum).getInt();
+  APSInt RHS = SourceRHS.getVectorElt(EltNum).getInt();
+  switch (E->getBuiltinCallee()) {
+  case Builtin::BI__builtin_elementwise_add_sat:
+ResultElements.push_back(APValue(
+APSInt(LHS.isSigned() ? LHS.sadd_sat(RHS) : RHS.uadd_sat(RHS),
+   DestEltTy->isUnsignedIntegerOrEnumerationType(;
+break;
+  }
+}
+
+return Success(APValue(ResultElements.data(), ResultElements.size()), E);
+  }
   }
 }
 
@@ -13204,6 +13229,16 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return Success(Val.rotr(Amt.urem(Val.getBitWidth())), E);
   }
 
+  case Builtin::BI__builtin_elementwise_add_sat: {
+APSInt LHS, RHS;
+if (!EvaluateInteger(E->getArg(0), LHS, Info) ||
+!EvaluateInteger(E->getArg(1), RHS, Info))
+  return false;
+
+APInt Result = LHS.isSigned() ? LHS.sadd_sat(RHS) : LHS.uadd_sat(RHS);
+return Success(APSInt(Result, !LHS.isSigned()), E);
+  }
+
   case Builtin::BIstrlen:
   case Builtin::BIwcslen:
 // A call to strlen is not a constant expression.
diff --git a/clang/test/CodeGen/builtins-elementwise-math.c 
b/clang/test/CodeGen/builtins-elementwise-math.c
index 82f82dd1ed7944..832691a55e52a1 100644
--- a/clang/test/CodeGen/builtins-elementw

[clang-tools-extra] fix parse windows driver and wsl path (PR #119085)

2024-12-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: None (95833)


Changes

path::is_absolute(Path, path::Style::windows) will return false leading to an 
error when the path appears in the root driver form, for example: 
path-mappings=E:=/mnt/e 

This modification also potentially provides support for WSL paths. for example: 
path-mappings=wsl.localhost/usr=/usr

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


1 Files Affected:

- (modified) clang-tools-extra/clangd/PathMapping.cpp (+5-5) 


``diff
diff --git a/clang-tools-extra/clangd/PathMapping.cpp 
b/clang-tools-extra/clangd/PathMapping.cpp
index 4b93ff2c60c5c6..48a936867a738a 100644
--- a/clang-tools-extra/clangd/PathMapping.cpp
+++ b/clang-tools-extra/clangd/PathMapping.cpp
@@ -150,11 +150,11 @@ llvm::Expected parsePath(llvm::StringRef 
Path) {
   if (path::is_absolute(Path, path::Style::posix)) {
 return std::string(Path);
   }
-  if (path::is_absolute(Path, path::Style::windows)) {
-std::string Converted = path::convert_to_slash(Path, path::Style::windows);
-if (Converted.front() != '/')
-  Converted = "/" + Converted;
-return Converted;
+  llvm::StringRef Root = path::root_name(Path, path::Style::windows);
+  if (!Root.empty()) {
+std::string Converted = "/";
+return Converted.append(Root)
+  .append(path::convert_to_slash(Path.substr(Root.size()), 
path::Style::windows));
   }
   return error("Path not absolute: {0}", Path);
 }

``




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


[clang] [clang][transformer] Allow usage of applyFirst with rewriteDescendants (PR #117658)

2024-12-07 Thread via cfe-commits

SherAndrei wrote:

@5chmidti, @carlosgalvezp, @PiotrZSL, can anyone please review suggested 
changes or maybe help find who can additionally review them? The author of the 
code under question -- @ymand, is absent for over a week

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


[clang] 66f9448 - [NFC][ubsan] Pre-commit test with missed optimization (#119012)

2024-12-07 Thread via cfe-commits

Author: Vitaly Buka
Date: 2024-12-07T14:50:19-08:00
New Revision: 66f9448b4b14a117141a3efd014e1240b30b741f

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

LOG: [NFC][ubsan] Pre-commit test with missed optimization (#119012)

Added: 
clang/test/CodeGen/allow-ubsan-check-inline.c

Modified: 


Removed: 




diff  --git a/clang/test/CodeGen/allow-ubsan-check-inline.c 
b/clang/test/CodeGen/allow-ubsan-check-inline.c
new file mode 100644
index 00..cabe76d8034d77
--- /dev/null
+++ b/clang/test/CodeGen/allow-ubsan-check-inline.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s 
-fsanitize=signed-integer-overflow -mllvm -ubsan-guard-checks -O3 -mllvm 
-lower-allow-check-random-rate=1 -Rpass=lower-allow-check 
-Rpass-missed=lower-allow-check -fno-inline 2>&1 | FileCheck %s 
--check-prefixes=NOINL --implicit-check-not="remark:"
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s 
-fsanitize=signed-integer-overflow -mllvm -ubsan-guard-checks -O3 -mllvm 
-lower-allow-check-random-rate=1 -Rpass=lower-allow-check 
-Rpass-missed=lower-allow-check 2>&1 | FileCheck %s --check-prefixes=INLINE 
--implicit-check-not="remark:"
+
+int get();
+void set(int x);
+
+// We will only make decision in the `overflow` function.
+// NOINL-COUNT-1: remark: Allowed check:
+
+// FIXME: We will make decision on every inline.
+// INLINE-COUNT-1: remark: Allowed check:
+
+static void overflow() {
+  set(get() + get());
+}
+
+void test() {
+  overflow();
+  overflow();
+  overflow();
+  overflow();
+  overflow();
+}



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


[clang] [ubsan] Improve lowering of @llvm.allow.ubsan.check (PR #119013)

2024-12-07 Thread Vitaly Buka via cfe-commits

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


[clang] [clang][modules] Fix std::initializer_list recognition if it's exported out of a module (PR #118537)

2024-12-07 Thread via cfe-commits

https://github.com/jijjijj updated 
https://github.com/llvm/llvm-project/pull/118537

>From d0a3059a10b7ceeb7e9c27068266f8c41e794203 Mon Sep 17 00:00:00 2001
From: jijjijj 
Date: Tue, 3 Dec 2024 22:57:34 +0300
Subject: [PATCH] Fix std::initializer_list recognition if it's exported out of
 a module

If the std::initializer_list is exported out of module, its DeclContext is not 
a namespace as `Sema::isStdInitializerList` expects, but an 
`Decl::Kind::Export` and only its parent is a namespace. So this commit makes 
`Sema::isStdInitializerList` account for that.
---
 clang/lib/Sema/SemaDeclCXX.cpp | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 7e8e321c4b90e6..4572229562ed3b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11919,8 +11919,12 @@ bool Sema::isStdInitializerList(QualType Ty, QualType 
*Element) {
 CXXRecordDecl *TemplateClass = Template->getTemplatedDecl();
 if (TemplateClass->getIdentifier() !=
 &PP.getIdentifierTable().get("initializer_list") ||
-!getStdNamespace()->InEnclosingNamespaceSetOf(
-TemplateClass->getDeclContext()))
+!(getStdNamespace()->InEnclosingNamespaceSetOf(
+TemplateClass->getDeclContext()) ||
+// if decl context is an export from module we need to check the parent
+(TemplateClass->getDeclContext()->getDeclKind() == Decl::Kind::Export 
&&
+getStdNamespace()->InEnclosingNamespaceSetOf(
+TemplateClass->getDeclContext()->getParent()
   return false;
 // This is a template called std::initializer_list, but is it the right
 // template?

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


[clang] [clang][modules] Fix std::initializer_list recognition if it's exported out of a module (PR #118537)

2024-12-07 Thread via cfe-commits

https://github.com/jijjijj updated 
https://github.com/llvm/llvm-project/pull/118537

>From d0a3059a10b7ceeb7e9c27068266f8c41e794203 Mon Sep 17 00:00:00 2001
From: jijjijj 
Date: Tue, 3 Dec 2024 22:57:34 +0300
Subject: [PATCH 1/2] Fix std::initializer_list recognition if it's exported
 out of a module

If the std::initializer_list is exported out of module, its DeclContext is not 
a namespace as `Sema::isStdInitializerList` expects, but an 
`Decl::Kind::Export` and only its parent is a namespace. So this commit makes 
`Sema::isStdInitializerList` account for that.
---
 clang/lib/Sema/SemaDeclCXX.cpp | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 7e8e321c4b90e6..4572229562ed3b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11919,8 +11919,12 @@ bool Sema::isStdInitializerList(QualType Ty, QualType 
*Element) {
 CXXRecordDecl *TemplateClass = Template->getTemplatedDecl();
 if (TemplateClass->getIdentifier() !=
 &PP.getIdentifierTable().get("initializer_list") ||
-!getStdNamespace()->InEnclosingNamespaceSetOf(
-TemplateClass->getDeclContext()))
+!(getStdNamespace()->InEnclosingNamespaceSetOf(
+TemplateClass->getDeclContext()) ||
+// if decl context is an export from module we need to check the parent
+(TemplateClass->getDeclContext()->getDeclKind() == Decl::Kind::Export 
&&
+getStdNamespace()->InEnclosingNamespaceSetOf(
+TemplateClass->getDeclContext()->getParent()
   return false;
 // This is a template called std::initializer_list, but is it the right
 // template?

>From 932764c8eb1b87364ffbcf8311a38cd0b8ff0b9d Mon Sep 17 00:00:00 2001
From: jijjijj 
Date: Sat, 7 Dec 2024 19:24:29 +0300
Subject: [PATCH 2/2] Fix std::initializer_list recognition if it's exported
 out of a module

- Improve implementation
- Add a regression test
- Add release notes
---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/lib/Sema/SemaDeclCXX.cpp|  8 +---
 ...hrough-export-and-linkage-issue-118218.cpp | 39 +++
 3 files changed, 43 insertions(+), 6 deletions(-)
 create mode 100644 
clang/test/Modules/initializer-list-recognition-through-export-and-linkage-issue-118218.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 59e3a6609123d2..2e25f487bfb528 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -796,6 +796,8 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure caused by mangled names with invalid identifiers. 
(#GH112205)
 - Fixed an incorrect lambda scope of generic lambdas that caused Clang to 
crash when computing potential lambda
   captures at the end of a full expression. (#GH115931)
+- Fixed recognition of ``std::initializer_list`` when it's surrounded with 
``extern "C++"`` and exported
+  out of a module. (#GH118218)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 4436b521d21928..d5229143709c03 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11926,12 +11926,8 @@ bool Sema::isStdInitializerList(QualType Ty, QualType 
*Element) {
 CXXRecordDecl *TemplateClass = Template->getTemplatedDecl();
 if (TemplateClass->getIdentifier() !=
 &PP.getIdentifierTable().get("initializer_list") ||
-!(getStdNamespace()->InEnclosingNamespaceSetOf(
-TemplateClass->getDeclContext()) ||
-// if decl context is an export from module we need to check the parent
-(TemplateClass->getDeclContext()->getDeclKind() == Decl::Kind::Export 
&&
-getStdNamespace()->InEnclosingNamespaceSetOf(
-TemplateClass->getDeclContext()->getParent()
+!getStdNamespace()->InEnclosingNamespaceSetOf(
+TemplateClass->getNonTransparentDeclContext()))
   return false;
 // This is a template called std::initializer_list, but is it the right
 // template?
diff --git 
a/clang/test/Modules/initializer-list-recognition-through-export-and-linkage-issue-118218.cpp
 
b/clang/test/Modules/initializer-list-recognition-through-export-and-linkage-issue-118218.cpp
new file mode 100644
index 00..70ad8951e63356
--- /dev/null
+++ 
b/clang/test/Modules/initializer-list-recognition-through-export-and-linkage-issue-118218.cpp
@@ -0,0 +1,39 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/std.cppm -emit-module-interface -o %t/std.pcm
+// RUN: %clang_cc1 -std=c++20 %t/mod.cppm -fprebuilt-module-path=%t 
-emit-module-interface -o %t/mod.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -verify %t/main.cpp
+
+//--- std.cppm
+export module std;
+
+extern "C++" {
+  namespace std {
+  export template 
+  class initializ

[clang] 342c8db - [rtsan] NFC: Docs update adding links to Disabling, adding a few ` marks (#119075)

2024-12-07 Thread via cfe-commits

Author: Chris Apple
Date: 2024-12-07T08:25:08-08:00
New Revision: 342c8db381129e908116f1059e97d235b62bcaf2

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

LOG: [rtsan] NFC: Docs update adding links to Disabling, adding a few ` marks 
(#119075)

Added: 


Modified: 
clang/docs/RealtimeSanitizer.rst

Removed: 




diff  --git a/clang/docs/RealtimeSanitizer.rst 
b/clang/docs/RealtimeSanitizer.rst
index 233a91f6684162..2aec728cfed583 100644
--- a/clang/docs/RealtimeSanitizer.rst
+++ b/clang/docs/RealtimeSanitizer.rst
@@ -187,15 +187,15 @@ A **partial** list of flags RealtimeSanitizer respects:
* - ``abort_on_error``
  - OS dependent
  - boolean
- - If true, the tool calls abort() instead of _exit() after printing the 
error report. On some OSes (OSX, for exmple) this is beneficial because a 
better stack trace is emitted on crash.
+ - If true, the tool calls ``abort()`` instead of ``_exit()`` after 
printing the error report. On some OSes (MacOS, for exmple) this is beneficial 
because a better stack trace is emitted on crash.
* - ``symbolize``
  - ``true``
  - boolean
  - If set, use the symbolizer to turn virtual addresses to file/line 
locations. If false, can greatly speed up the error reporting.
* - ``suppressions``
- - ""
+ - ``""``
  - path
- - If set to a valid suppressions file, will suppress issue reporting. See 
details in "Disabling", below.
+ - If set to a valid suppressions file, will suppress issue reporting. See 
details in `Disabling and Suppressing`_.
 
 
 Some issues with flags can be debugged using the ``verbosity=$NUM`` flag:
@@ -244,6 +244,7 @@ To register a callback which will be invoked before a RTSan 
kills the process:
 ...
   }
 
+.. _disabling-and-suppressing:
 
 Disabling and suppressing
 -



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


[clang] [rtsan] NFC: Adding links to Disabling, adding a few ` marks (PR #119075)

2024-12-07 Thread Chris Apple via cfe-commits

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


[clang] [rtsan] Add `verify_interceptors` flag to docs (PR #119074)

2024-12-07 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/119074

>From 2c882a78ce82801590a6bfd217c8e8b8e4b4c6f5 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Sat, 7 Dec 2024 07:45:34 -0800
Subject: [PATCH] [rtsan] Add `verify_interceptors` to docs

---
 clang/docs/RealtimeSanitizer.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/RealtimeSanitizer.rst b/clang/docs/RealtimeSanitizer.rst
index 2aec728cfed583..f5d29af2bef3c5 100644
--- a/clang/docs/RealtimeSanitizer.rst
+++ b/clang/docs/RealtimeSanitizer.rst
@@ -196,7 +196,10 @@ A **partial** list of flags RealtimeSanitizer respects:
  - ``""``
  - path
  - If set to a valid suppressions file, will suppress issue reporting. See 
details in `Disabling and Suppressing`_.
-
+   * - ``verify_interceptors``
+ - ``true``
+ - boolean
+ - If true, verifies interceptors are working at initialization. The 
program will abort with error ``==ERROR: Interceptors are not working. This may 
be because RealtimeSanitizer is loaded too late (e.g. via dlopen)`` if an issue 
is detected.
 
 Some issues with flags can be debugged using the ``verbosity=$NUM`` flag:
 

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


[clang] [compiler-rt] Move interceptors for libresolv functions to MSan (PR #119071)

2024-12-07 Thread Aaron Puchert via cfe-commits

https://github.com/aaronpuchert updated 
https://github.com/llvm/llvm-project/pull/119071

>From cf38afeed8ede6b77adf836ecb51a9bb0ae6 Mon Sep 17 00:00:00 2001
From: Aaron Puchert 
Date: Sat, 7 Dec 2024 14:58:04 +0100
Subject: [PATCH] Move interceptors for libresolv functions to MSan

The functions are not relevant for most sanitizers and only required for
MSan to see which regions have been written to. This eliminates a link
dependency for all other sanitizers and fixes #59007: while `-lresolv`
had been added for the static runtime in 6dce56b2a308, it wasn't added
to the shared runtimes.

Instead of just moving the interceptors, we adapt them to MSan
conventions:
* We don't skip intercepting when `msan_init_is_running` is true, but
  directly call ENSURE_MSAN_INITED() like most other interceptors. It
  seems unlikely that these functions are called during initialization.
* We don't unpoison `errno`, because none of the functions is specified
  to use it.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  2 +-
 compiler-rt/lib/msan/msan_interceptors.cpp| 76 ++
 .../sanitizer_common_interceptors.inc | 78 ---
 .../sanitizer_platform_interceptors.h |  2 -
 .../TestCases => msan}/Linux/dn_expand.cpp| 18 ++---
 .../sanitizer_common/TestCases/Linux/b64.cpp  | 42 --
 6 files changed, 86 insertions(+), 132 deletions(-)
 rename compiler-rt/test/{sanitizer_common/TestCases => 
msan}/Linux/dn_expand.cpp (81%)
 delete mode 100644 compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7d3d7f8f03c491..03dbdc27975b42 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1410,7 +1410,7 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-  !TC.getTriple().isMusl())
+  !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())
 CmdArgs.push_back("-lresolv");
 }
 
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp 
b/compiler-rt/lib/msan/msan_interceptors.cpp
index f05c20618780b7..b2098d8a26d229 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -1358,6 +1358,79 @@ INTERCEPTOR(int, forkpty, int *aparent, char *name, 
const void *termp,
 #define MSAN_MAYBE_INTERCEPT_FORKPTY
 #endif
 
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+INTERCEPTOR(int, __b64_ntop, unsigned char const *src, SIZE_T srclength,
+char *target, SIZE_T targsize) {
+  ENSURE_MSAN_INITED();
+  CHECK_UNPOISONED(src, srclength);
+  InterceptorScope interceptor_scope;
+  int res = REAL(__b64_ntop)(src, srclength, target, targsize);
+  if (res >= 0)
+__msan_unpoison(target, res + 1);
+  return res;
+}
+INTERCEPTOR(int, __b64_pton, char const *src, char *target, SIZE_T targsize) {
+  ENSURE_MSAN_INITED();
+  CHECK_UNPOISONED(src, internal_strlen(src) + 1);
+  InterceptorScope interceptor_scope;
+  int res = REAL(__b64_pton)(src, target, targsize);
+  if (res >= 0)
+__msan_unpoison(target, res);
+  return res;
+}
+#  define MSAN_MAYBE_INTERCEPT___B64_TO \
+MSAN_INTERCEPT_FUNC(__b64_ntop);\
+COMMON_INTERCEPT_FUNCTION(__b64_pton);
+#else
+#  define MSAN_MAYBE_INTERCEPT___B64_TO
+#endif
+
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+#  if __GLIBC_PREREQ(2, 34)
+// Changed with https://sourceware.org/git/?p=glibc.git;h=640bbdf
+#define DN_COMP_INTERCEPTOR_NAME dn_comp
+#define DN_EXPAND_INTERCEPTOR_NAME dn_expand
+#  else
+#define DN_COMP_INTERCEPTOR_NAME __dn_comp
+#define DN_EXPAND_INTERCEPTOR_NAME __dn_expand
+#  endif
+INTERCEPTOR(int, DN_COMP_INTERCEPTOR_NAME, unsigned char *exp_dn,
+unsigned char *comp_dn, int length, unsigned char **dnptrs,
+unsigned char **lastdnptr) {
+  ENSURE_MSAN_INITED();
+  InterceptorScope interceptor_scope;
+  int res = REAL(DN_COMP_INTERCEPTOR_NAME)(exp_dn, comp_dn, length, dnptrs,
+   lastdnptr);
+  if (res >= 0) {
+__msan_unpoison(comp_dn, res);
+if (dnptrs && lastdnptr) {
+  unsigned char **p = dnptrs;
+  for (; p != lastdnptr && *p; ++p);
+  if (p != lastdnptr)
+++p;
+  __msan_unpoison(dnptrs, (p - dnptrs) * sizeof(*p));
+}
+  }
+  return res;
+}
+INTERCEPTOR(int, DN_EXPAND_INTERCEPTOR_NAME, unsigned char const *base,
+unsigned char const *end, unsigned char const *src, char *dest,
+int space) {
+  ENSURE_MSAN_INITED();
+  // TODO: add read check if __dn_comp intercept added
+  InterceptorScope interceptor_scope;
+  int res = REAL(DN_EXPAND_INTERCEPTOR_NAME)(base, end, src, dest, space);
+  if (res >= 0)
+__msan_unpoison(dest, internal_strlen(dest) + 1);
+  return res;
+

[clang] [compiler-rt] Move interceptors for libresolv functions to MSan (PR #119071)

2024-12-07 Thread Aaron Puchert via cfe-commits


@@ -1410,7 +1410,7 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-  !TC.getTriple().isMusl())
+  !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())

aaronpuchert wrote:

This is not very efficient, because `getSanitizerArgs` actually extracts them 
from `Args` every time it is called. I've started working on a change to fix 
that.

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


[clang] [compiler-rt] Move interceptors for libresolv functions to MSan (PR #119071)

2024-12-07 Thread Aaron Puchert via cfe-commits

https://github.com/aaronpuchert updated 
https://github.com/llvm/llvm-project/pull/119071

>From 2b0071ca68164abdf2e9e174c1ecd2c166aa8815 Mon Sep 17 00:00:00 2001
From: Aaron Puchert 
Date: Sat, 7 Dec 2024 14:58:04 +0100
Subject: [PATCH] Move interceptors for libresolv functions to MSan

The functions are not relevant for most sanitizers and only required for
MSan to see which regions have been written to. This eliminates a link
dependency for all other sanitizers and fixes #59007: while `-lresolv`
had been added for the static runtime in 6dce56b2a308, it wasn't added
to the shared runtimes.

Instead of just moving the interceptors, we adapt them to MSan
conventions:
* We don't skip intercepting when `msan_init_is_running` is true, but
  directly call ENSURE_MSAN_INITED() like most other interceptors. It
  seems unlikely that these functions are called during initialization.
* We don't unpoison `errno`, because none of the functions is specified
  to use it.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  2 +-
 clang/test/Driver/sanitizer-ld.c  | 39 +-
 compiler-rt/lib/msan/msan_interceptors.cpp| 76 ++
 .../sanitizer_common_interceptors.inc | 78 ---
 .../sanitizer_platform_interceptors.h |  2 -
 .../TestCases => msan}/Linux/dn_expand.cpp| 20 ++---
 .../sanitizer_common/TestCases/Linux/b64.cpp  | 42 --
 7 files changed, 107 insertions(+), 152 deletions(-)
 rename compiler-rt/test/{sanitizer_common/TestCases => 
msan}/Linux/dn_expand.cpp (79%)
 delete mode 100644 compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7d3d7f8f03c491..03dbdc27975b42 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1410,7 +1410,7 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-  !TC.getTriple().isMusl())
+  !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())
 CmdArgs.push_back("-lresolv");
 }
 
diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c
index c83066a334001a..877a01c3de3047 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -15,7 +15,7 @@
 // CHECK-ASAN-LINUX: "-lpthread"
 // CHECK-ASAN-LINUX: "-lrt"
 // CHECK-ASAN-LINUX: "-ldl"
-// CHECK-ASAN-LINUX: "-lresolv"
+// CHECK-ASAN-LINUX-NOT: "-lresolv"
 
 // RUN: %clang -fsanitize=address -fno-sanitize-link-runtime -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -143,7 +143,7 @@
 // CHECK-ASAN-LINUX-CXX: "-lpthread"
 // CHECK-ASAN-LINUX-CXX: "-lrt"
 // CHECK-ASAN-LINUX-CXX: "-ldl"
-// CHECK-ASAN-LINUX-CXX: "-lresolv"
+// CHECK-ASAN-LINUX-CXX-NOT: "-lresolv"
 
 // RUN: %clang -### %s -o /dev/null -fsanitize=address \
 // RUN: --target=i386-unknown-linux -fuse-ld=ld -stdlib=platform \
@@ -292,7 +292,7 @@
 // CHECK-TSAN-LINUX-CXX: "-lpthread"
 // CHECK-TSAN-LINUX-CXX: "-lrt"
 // CHECK-TSAN-LINUX-CXX: "-ldl"
-// CHECK-TSAN-LINUX-CXX: "-lresolv"
+// CHECK-TSAN-LINUX-CXX-NOT: "-lresolv"
 
 // RUN: %clang -fsanitize=thread -fno-sanitize-link-runtime -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -365,7 +365,7 @@
 // CHECK-UBSAN-LINUX-NOT: libclang_rt.ubsan_standalone_cxx
 // CHECK-UBSAN-LINUX-NOT: "-lstdc++"
 // CHECK-UBSAN-LINUX: "-lpthread"
-// CHECK-UBSAN-LINUX: "-lresolv"
+// CHECK-UBSAN-LINUX-NOT: "-lresolv"
 
 // RUN: %clang -fsanitize=undefined -fno-sanitize-link-runtime -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \
@@ -438,7 +438,7 @@
 // CHECK-UBSAN-LINUX-CXX: "-lstdc++"
 // CHECK-UBSAN-LINUX-CXX-NOT: libclang_rt.asan
 // CHECK-UBSAN-LINUX-CXX: "-lpthread"
-// CHECK-UBSAN-LINUX-CXX: "-lresolv"
+// CHECK-UBSAN-LINUX-CXX-NOT: "-lresolv"
 
 // RUN: %clang -fsanitize=undefined -fsanitize-minimal-runtime -### %s 2>&1 \
 // RUN: --target=i386-unknown-linux -fuse-ld=ld \
@@ -448,7 +448,7 @@
 // CHECK-UBSAN-MINIMAL-LINUX: "{{.*}}ld{{(.exe)?}}"
 // CHECK-UBSAN-MINIMAL-LINUX: "--whole-archive" 
"{{.*}}libclang_rt.ubsan_minimal.a" "--no-whole-archive"
 // CHECK-UBSAN-MINIMAL-LINUX: "-lpthread"
-// CHECK-UBSAN-MINIMAL-LINUX: "-lresolv"
+// CHECK-UBSAN-MINIMAL-LINUX-NOT: "-lresolv"
 
 // RUN: %clang -fsanitize=undefined -fsanitize-minimal-runtime -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin -fuse-ld=ld \
@@ -485,7 +485,7 @@
 // CHECK-ASAN-UBSAN-LINUX-NOT: libclang_rt.ubsan
 // CHECK-ASAN-UBSAN-LINUX-NOT: "-lstdc++"
 // CHECK-ASAN-UBSAN-LINUX: "-lpthread"
-// CHECK-ASAN-UBSAN-LINUX: "-lresolv"
+// CHECK-ASAN-UBSAN-LINUX-NOT: "-lresolv"
 
 // RUN: %clangxx -fsanitize=address,undefined -### %s 2>&1 \
 // RUN: --target=i386-unknown-linux -fuse-ld=ld -stdlib

[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)

2024-12-07 Thread Gedare Bloom via cfe-commits

https://github.com/gedare updated 
https://github.com/llvm/llvm-project/pull/112482

>From 9fb82b16dfea2115431219bd9915d18eff081805 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/3] [clang-format] add BinPackLongBracedLists style option

The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
 clang/include/clang/Format/Format.h| 19 
 clang/lib/Format/Format.cpp|  2 ++
 clang/lib/Format/FormatToken.cpp   |  2 +-
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  | 26 ++
 5 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..52eedce8e9d397 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1208,6 +1208,21 @@ struct FormatStyle {
   /// \version 3.7
   bool BinPackArguments;
 
+  /// If ``BinPackArguments`` is ``false`` this option can override it if
+  /// ``true`` when 20 or more items are in a braced initializer list.
+  /// \code
+  ///BinPackLongBracedLists: false  vs.   BinPackLongBracedLists: true
+  ///vector x{   vector x{1, 2, ...,
+  ///   20, 21};
+  ///1,
+  ///2,
+  ///...,
+  ///20,
+  ///21};
+  /// \endcode
+  /// \version 20
+  bool BinPackLongBracedLists;
+
   /// Different way to try to fit all parameters on a line.
   enum BinPackParametersStyle : int8_t {
 /// Bin-pack parameters.
@@ -2515,6 +2530,9 @@ struct FormatStyle {
   /// (e.g. a type or variable name), clang-format formats as if the ``{}`` 
were
   /// the parentheses of a function call with that name. If there is no name,
   /// a zero-length name is assumed.
+  ///
+  /// ``BinPackArguments`` may be forced to true for initializer lists with
+  /// more than 20 items if ``BinPackLongBracedLists`` is true.
   /// \code
   ///true:  false:
   ///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -5172,6 +5190,7 @@ struct FormatStyle {
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
+   BinPackLongBracedLists == R.BinPackLongBracedLists &&
BinPackParameters == R.BinPackParameters &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ee52972ce66f4a..72106945214207 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -981,6 +981,7 @@ template <> struct MappingTraits {
Style.AlwaysBreakBeforeMultilineStrings);
 IO.mapOptional("AttributeMacros", Style.AttributeMacros);
 IO.mapOptional("BinPackArguments", Style.BinPackArguments);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
 IO.mapOptional("BinPackParameters", Style.BinPackParameters);
 IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
 IO.mapOptional("BracedInitializerIndentWidth",
@@ -1484,6 +1485,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
   LLVMStyle.AttributeMacros.push_back("__capability");
   LLVMStyle.BinPackArguments = true;
+  LLVMStyle.BinPackLongBracedLists = true;
   LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
   LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
   LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 963e8f87793fa0..a56a13bd58a519 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -174,7 +174,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const 
FormatToken *Token) {
   // have many items (20 or more) or we allow bin-packing of function call
   // arguments.
   if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
-  Commas.size() < 19) {
+  (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
 return;
   }
 
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 7fc7492271668b..9c29cd3f57273f 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -160,6 +160,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLi

[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)

2024-12-07 Thread Gedare Bloom via cfe-commits


@@ -3398,6 +3401,21 @@ struct FormatStyle {
   /// \version 3.7
   unsigned MaxEmptyLinesToKeep;
 
+  /// If ``BinPackArguments`` is ``false`` this option can override it if
+  /// ``true`` when 20 or more items are in a braced initializer list.
+  /// \code
+  ///BinPackLongBracedLists: false  vs.   BinPackLongBracedLists: true
+  ///vector x{   vector x{1, 2, ...,
+  ///   20, 21};
+  ///1,
+  ///2,
+  ///...,
+  ///20,
+  ///21};
+  /// \endcode
+  /// \version 20
+  bool BinPackLongBracedLists;

gedare wrote:

done.

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


[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)

2024-12-07 Thread Gedare Bloom via cfe-commits

https://github.com/gedare updated 
https://github.com/llvm/llvm-project/pull/112482

>From 59770d0e915b2cb50b89c2c98ed20f7d9170d744 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/3] [clang-format] add BinPackLongBracedLists style option

The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
 clang/include/clang/Format/Format.h| 19 
 clang/lib/Format/Format.cpp|  2 ++
 clang/lib/Format/FormatToken.cpp   |  2 +-
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  | 26 ++
 5 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..52eedce8e9d397 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1208,6 +1208,21 @@ struct FormatStyle {
   /// \version 3.7
   bool BinPackArguments;
 
+  /// If ``BinPackArguments`` is ``false`` this option can override it if
+  /// ``true`` when 20 or more items are in a braced initializer list.
+  /// \code
+  ///BinPackLongBracedLists: false  vs.   BinPackLongBracedLists: true
+  ///vector x{   vector x{1, 2, ...,
+  ///   20, 21};
+  ///1,
+  ///2,
+  ///...,
+  ///20,
+  ///21};
+  /// \endcode
+  /// \version 20
+  bool BinPackLongBracedLists;
+
   /// Different way to try to fit all parameters on a line.
   enum BinPackParametersStyle : int8_t {
 /// Bin-pack parameters.
@@ -2515,6 +2530,9 @@ struct FormatStyle {
   /// (e.g. a type or variable name), clang-format formats as if the ``{}`` 
were
   /// the parentheses of a function call with that name. If there is no name,
   /// a zero-length name is assumed.
+  ///
+  /// ``BinPackArguments`` may be forced to true for initializer lists with
+  /// more than 20 items if ``BinPackLongBracedLists`` is true.
   /// \code
   ///true:  false:
   ///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -5172,6 +5190,7 @@ struct FormatStyle {
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
+   BinPackLongBracedLists == R.BinPackLongBracedLists &&
BinPackParameters == R.BinPackParameters &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index dcaac4b0d42cc5..559ffe56a30afe 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -981,6 +981,7 @@ template <> struct MappingTraits {
Style.AlwaysBreakBeforeMultilineStrings);
 IO.mapOptional("AttributeMacros", Style.AttributeMacros);
 IO.mapOptional("BinPackArguments", Style.BinPackArguments);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
 IO.mapOptional("BinPackParameters", Style.BinPackParameters);
 IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
 IO.mapOptional("BracedInitializerIndentWidth",
@@ -1484,6 +1485,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
   LLVMStyle.AttributeMacros.push_back("__capability");
   LLVMStyle.BinPackArguments = true;
+  LLVMStyle.BinPackLongBracedLists = true;
   LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
   LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
   LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 963e8f87793fa0..a56a13bd58a519 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -174,7 +174,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const 
FormatToken *Token) {
   // have many items (20 or more) or we allow bin-packing of function call
   // arguments.
   if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
-  Commas.size() < 19) {
+  (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
 return;
   }
 
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 7fc7492271668b..9c29cd3f57273f 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -160,6 +160,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLi

[clang] [llvm] [openmp] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Shilei Tian via cfe-commits

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

it seems like there are some test failures but I think the PR looks good

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


[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)

2024-12-07 Thread Gedare Bloom via cfe-commits

https://github.com/gedare updated 
https://github.com/llvm/llvm-project/pull/112482

>From b61cb81d93e6fb137af282a4f2f0ebf151c2543c Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Tue, 15 Oct 2024 23:55:49 -0600
Subject: [PATCH 1/3] [clang-format] add BinPackLongBracedLists style option

The use of Cpp11BracedListStyle with BinPackParameters=False
avoids bin packing until reaching a hard-coded limit of 20 items.
This is an arbitrary choice. Introduce a new style option to
allow disabling this limit.
---
 clang/include/clang/Format/Format.h| 19 
 clang/lib/Format/Format.cpp|  2 ++
 clang/lib/Format/FormatToken.cpp   |  2 +-
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  | 26 ++
 5 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..00af4ca7c94bed 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1208,6 +1208,21 @@ struct FormatStyle {
   /// \version 3.7
   bool BinPackArguments;
 
+  /// If ``BinPackArguments`` is ``false`` this option can override it if
+  /// ``true`` when 20 or more items are in a braced initializer list.
+  /// \code
+  ///BinPackLongBracedLists: false  vs.   BinPackLongBracedLists: true
+  ///vector x{   vector x{1, 2, ...,
+  ///   20, 21};
+  ///1,
+  ///2,
+  ///...,
+  ///20,
+  ///21};
+  /// \endcode
+  /// \version 20
+  bool BinPackLongBracedLists;
+
   /// Different way to try to fit all parameters on a line.
   enum BinPackParametersStyle : int8_t {
 /// Bin-pack parameters.
@@ -2515,6 +2530,9 @@ struct FormatStyle {
   /// (e.g. a type or variable name), clang-format formats as if the ``{}`` 
were
   /// the parentheses of a function call with that name. If there is no name,
   /// a zero-length name is assumed.
+  ///
+  /// ``BinPackArguments`` may be forced to true for initializer lists with
+  /// more than 20 items if ``BinPackLongBracedLists`` is true.
   /// \code
   ///true:  false:
   ///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 };
@@ -5234,6 +5252,7 @@ struct FormatStyle {
LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin 
&&
MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros &&
MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
+   BinPackLongBracedLists == R.BinPackLongBracedLists &&
NamespaceIndentation == R.NamespaceIndentation &&
NamespaceMacros == R.NamespaceMacros &&
ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ee52972ce66f4a..39082da13c3051 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1060,6 +1060,7 @@ template <> struct MappingTraits {
 IO.mapOptional("Macros", Style.Macros);
 IO.mapOptional("MainIncludeChar", Style.IncludeStyle.MainIncludeChar);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
+IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists);
 IO.mapOptional("NamespaceIndentation", Style.NamespaceIndentation);
 IO.mapOptional("NamespaceMacros", Style.NamespaceMacros);
 IO.mapOptional("ObjCBinPackProtocolList", Style.ObjCBinPackProtocolList);
@@ -1573,6 +1574,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.Language = Language;
   LLVMStyle.LineEnding = FormatStyle::LE_DeriveLF;
   LLVMStyle.MaxEmptyLinesToKeep = 1;
+  LLVMStyle.BinPackLongBracedLists = true;
   LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
   LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
   LLVMStyle.ObjCBlockIndentWidth = 2;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 963e8f87793fa0..a56a13bd58a519 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -174,7 +174,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const 
FormatToken *Token) {
   // have many items (20 or more) or we allow bin-packing of function call
   // arguments.
   if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
-  Commas.size() < 19) {
+  (Commas.size() < 19 || !Style.BinPackLongBracedLists)) {
 return;
   }
 
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 7fc7492271668b..9c29cd3f57273f 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -160,6 +160,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
   CHECK_PARSE_BOOL(AllowS

[clang] [llvm] [openmp] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Joseph Huber via cfe-commits

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

>From 4c710e49eea97e542b97e0b5e78b7915acd32383 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Sat, 7 Dec 2024 13:47:23 -0600
Subject: [PATCH 1/4] [OpenMP] Use generic IR for the OpenMP DeviceRTL

Summary:
We previously built this for every single architecture to deal with
incompatibility. This patch updates it to use the 'generic' IR that
`libc` and other projects use. Who knows if this will have any
side-effects, probably worth testing more but it passes the tests I
expect to pass on my side.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp |  3 +-
 clang/lib/Driver/ToolChains/Cuda.cpp   |  1 -
 offload/DeviceRTL/CMakeLists.txt   | 70 -
 offload/DeviceRTL/src/Reduction.cpp| 89 +++---
 4 files changed, 62 insertions(+), 101 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7d3d7f8f03c491..3dd90ecf8bca4c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2800,8 +2800,7 @@ void tools::addOpenMPDeviceRTL(const Driver &D,
 : options::OPT_libomptarget_nvptx_bc_path_EQ;
 
   StringRef ArchPrefix = Triple.isAMDGCN() ? "amdgpu" : "nvptx";
-  std::string LibOmpTargetName =
-  ("libomptarget-" + ArchPrefix + "-" + BitcodeSuffix + ".bc").str();
+  std::string LibOmpTargetName = ("libomptarget-" + ArchPrefix + ".bc").str();
 
   // First check whether user specifies bc library
   if (const Arg *A = DriverArgs.getLastArg(LibomptargetBCPathOpt)) {
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 102794829795da..214f1e5d83478f 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -851,7 +851,6 @@ void CudaToolChain::addClangTargetOptions(
   HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
 
   StringRef GpuArch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
-  assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
   assert((DeviceOffloadingKind == Action::OFK_OpenMP ||
   DeviceOffloadingKind == Action::OFK_Cuda) &&
  "Only OpenMP or CUDA offloading kinds are supported for NVIDIA 
GPUs.");
diff --git a/offload/DeviceRTL/CMakeLists.txt b/offload/DeviceRTL/CMakeLists.txt
index 1bf3eb9da38aa1..cda633c41062b6 100644
--- a/offload/DeviceRTL/CMakeLists.txt
+++ b/offload/DeviceRTL/CMakeLists.txt
@@ -42,38 +42,6 @@ set(devicertl_base_directory ${CMAKE_CURRENT_SOURCE_DIR})
 set(include_directory ${devicertl_base_directory}/include)
 set(source_directory ${devicertl_base_directory}/src)
 
-set(all_amdgpu_architectures "gfx700;gfx701;gfx801;gfx803;gfx900;gfx902;gfx906"
- 
"gfx908;gfx90a;gfx90c;gfx940;gfx941;gfx942;gfx950;gfx1010"
- 
"gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035"
- "gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150"
- "gfx1151;gfx1152;gfx1153")
-set(all_nvptx_architectures "sm_35;sm_37;sm_50;sm_52;sm_53;sm_60;sm_61;sm_62"
-"sm_70;sm_72;sm_75;sm_80;sm_86;sm_87;sm_89;sm_90")
-set(all_gpu_architectures
-"${all_amdgpu_architectures};${all_nvptx_architectures}")
-
-set(LIBOMPTARGET_DEVICE_ARCHITECTURES "all" CACHE STRING
-"List of device architectures to be used to compile the OpenMP DeviceRTL.")
-
-if(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "all")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_gpu_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "amdgpu")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_amdgpu_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "nvptx")
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES ${all_nvptx_architectures})
-elseif(LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "auto" OR
-   LIBOMPTARGET_DEVICE_ARCHITECTURES STREQUAL "native")
-  if(NOT LIBOMPTARGET_NVPTX_ARCH AND NOT LIBOMPTARGET_AMDGPU_ARCH)
-message(FATAL_ERROR
-  "Could not find 'amdgpu-arch' and 'nvptx-arch' tools required for 
'auto'")
-  elseif(NOT LIBOMPTARGET_FOUND_NVIDIA_GPU AND NOT 
LIBOMPTARGET_FOUND_AMDGPU_GPU)
-message(FATAL_ERROR "No AMD or NVIDIA GPU found on the system when using 
'auto'")
-  endif()
-  set(LIBOMPTARGET_DEVICE_ARCHITECTURES
-  
"${LIBOMPTARGET_NVPTX_DETECTED_ARCH_LIST};${LIBOMPTARGET_AMDGPU_DETECTED_ARCH_LIST}")
-endif()
-list(REMOVE_DUPLICATES LIBOMPTARGET_DEVICE_ARCHITECTURES)
-
 set(include_files
   ${include_directory}/Allocator.h
   ${include_directory}/Configuration.h
@@ -141,20 +109,21 @@ set(bc_flags -c -foffload-lto -std=c++17 
-fvisibility=hidden
 
 # first create an object target
 add_library(omptarget.devicertl.all_objs OBJECT IMPORTED)
-function(compileDeviceRTLLibrary target_cpu target_name target_triple)
+function(compileDeviceRTLLibrary target_name ta

[clang] [llvm] [openmp] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

@ronlieb This will probably conflict a lot with downstream, should probably 
wait until I've talked it over with others before trying to merge it in AOMP.

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


[clang] [llvm] [openmp] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-07 Thread via cfe-commits

ronlieb wrote:

> @ronlieb This will probably conflict a lot with downstream, should probably 
> wait until I've talked it over with others before trying to merge it in AOMP.

yes please , lets wait until internal monday mtg to discuss. also i would like 
to help with some precommit performance testing   using a downstream build.

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


[clang] [compiler-rt] Move interceptors for libresolv functions to MSan (PR #119071)

2024-12-07 Thread Aaron Puchert via cfe-commits

https://github.com/aaronpuchert updated 
https://github.com/llvm/llvm-project/pull/119071

>From fdc60e8335dd68f08d6afbe4b281a7a278120f7a Mon Sep 17 00:00:00 2001
From: Aaron Puchert 
Date: Sat, 7 Dec 2024 14:58:04 +0100
Subject: [PATCH] Move interceptors for libresolv functions to MSan

The functions are not relevant for most sanitizers and only required for
MSan to see which regions have been written to. This eliminates a link
dependency for all other sanitizers and fixes #59007: while `-lresolv`
had been added for the static runtime in 6dce56b2a308, it wasn't added
to the shared runtimes.

Instead of just moving the interceptors, we adapt them to MSan
conventions:
* We don't skip intercepting when `msan_init_is_running` is true, but
  directly call ENSURE_MSAN_INITED() like most other interceptors. It
  seems unlikely that these functions are called during initialization.
* We don't unpoison `errno`, because none of the functions is specified
  to use it.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  2 +-
 compiler-rt/lib/msan/msan_interceptors.cpp| 76 ++
 .../sanitizer_common_interceptors.inc | 78 ---
 .../sanitizer_platform_interceptors.h |  2 -
 .../TestCases => msan}/Linux/dn_expand.cpp| 20 ++---
 .../sanitizer_common/TestCases/Linux/b64.cpp  | 42 --
 6 files changed, 87 insertions(+), 133 deletions(-)
 rename compiler-rt/test/{sanitizer_common/TestCases => 
msan}/Linux/dn_expand.cpp (79%)
 delete mode 100644 compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7d3d7f8f03c491..03dbdc27975b42 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1410,7 +1410,7 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-  !TC.getTriple().isMusl())
+  !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())
 CmdArgs.push_back("-lresolv");
 }
 
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp 
b/compiler-rt/lib/msan/msan_interceptors.cpp
index f05c20618780b7..b2098d8a26d229 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -1358,6 +1358,79 @@ INTERCEPTOR(int, forkpty, int *aparent, char *name, 
const void *termp,
 #define MSAN_MAYBE_INTERCEPT_FORKPTY
 #endif
 
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+INTERCEPTOR(int, __b64_ntop, unsigned char const *src, SIZE_T srclength,
+char *target, SIZE_T targsize) {
+  ENSURE_MSAN_INITED();
+  CHECK_UNPOISONED(src, srclength);
+  InterceptorScope interceptor_scope;
+  int res = REAL(__b64_ntop)(src, srclength, target, targsize);
+  if (res >= 0)
+__msan_unpoison(target, res + 1);
+  return res;
+}
+INTERCEPTOR(int, __b64_pton, char const *src, char *target, SIZE_T targsize) {
+  ENSURE_MSAN_INITED();
+  CHECK_UNPOISONED(src, internal_strlen(src) + 1);
+  InterceptorScope interceptor_scope;
+  int res = REAL(__b64_pton)(src, target, targsize);
+  if (res >= 0)
+__msan_unpoison(target, res);
+  return res;
+}
+#  define MSAN_MAYBE_INTERCEPT___B64_TO \
+MSAN_INTERCEPT_FUNC(__b64_ntop);\
+COMMON_INTERCEPT_FUNCTION(__b64_pton);
+#else
+#  define MSAN_MAYBE_INTERCEPT___B64_TO
+#endif
+
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+#  if __GLIBC_PREREQ(2, 34)
+// Changed with https://sourceware.org/git/?p=glibc.git;h=640bbdf
+#define DN_COMP_INTERCEPTOR_NAME dn_comp
+#define DN_EXPAND_INTERCEPTOR_NAME dn_expand
+#  else
+#define DN_COMP_INTERCEPTOR_NAME __dn_comp
+#define DN_EXPAND_INTERCEPTOR_NAME __dn_expand
+#  endif
+INTERCEPTOR(int, DN_COMP_INTERCEPTOR_NAME, unsigned char *exp_dn,
+unsigned char *comp_dn, int length, unsigned char **dnptrs,
+unsigned char **lastdnptr) {
+  ENSURE_MSAN_INITED();
+  InterceptorScope interceptor_scope;
+  int res = REAL(DN_COMP_INTERCEPTOR_NAME)(exp_dn, comp_dn, length, dnptrs,
+   lastdnptr);
+  if (res >= 0) {
+__msan_unpoison(comp_dn, res);
+if (dnptrs && lastdnptr) {
+  unsigned char **p = dnptrs;
+  for (; p != lastdnptr && *p; ++p);
+  if (p != lastdnptr)
+++p;
+  __msan_unpoison(dnptrs, (p - dnptrs) * sizeof(*p));
+}
+  }
+  return res;
+}
+INTERCEPTOR(int, DN_EXPAND_INTERCEPTOR_NAME, unsigned char const *base,
+unsigned char const *end, unsigned char const *src, char *dest,
+int space) {
+  ENSURE_MSAN_INITED();
+  // TODO: add read check if __dn_comp intercept added
+  InterceptorScope interceptor_scope;
+  int res = REAL(DN_EXPAND_INTERCEPTOR_NAME)(base, end, src, dest, space);
+  if (res >= 0)
+__msan_unpoison(dest, internal_strlen(dest) + 1);
+  return res;
+

[clang] [Clang] Deleting an incomplete enum type is not an error (PR #119077)

2024-12-07 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/119077

The changes introduced in #97733 accidentally prevented to delete an incomplete 
enum
(the validity of which has been confirmed by CWG2925

Fixes #99278


>From 8b89f6a56e0921b13c8638c9768ec99945825840 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Tue, 3 Dec 2024 10:29:23 +0100
Subject: [PATCH 1/3] [Clang] Deleting an incomplete enum type is not an error

The changes introduced in #97733 accidentally prevented
to delete an incomplete enum (the validity of which
has been confirmed by CWG2925

Fixes #99278
---
 clang/docs/ReleaseNotes.rst   | 1 +
 clang/lib/Sema/SemaExprCXX.cpp| 3 ++-
 clang/test/SemaCXX/new-delete.cpp | 8 
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 01c7899e36c932..e442516c225f74 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -766,6 +766,7 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure caused by mangled names with invalid identifiers. 
(#GH112205)
 - Fixed an incorrect lambda scope of generic lambdas that caused Clang to 
crash when computing potential lambda
   captures at the end of a full expression. (#GH115931)
+- Clang no longer rejects deleting a pointer of incomplete enumeration type. 
(#GH99278)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d85819b21c8265..20947ca4e35b17 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -3748,7 +3748,8 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool 
UseGlobal,
   // FIXME: This can result in errors if the definition was imported from a
   // module but is hidden.
   if (!RequireCompleteType(StartLoc, Pointee,
-   LangOpts.CPlusPlus26
+   Pointee->isStructureOrClassType() &&
+   LangOpts.CPlusPlus26
? diag::err_delete_incomplete
: diag::warn_delete_incomplete,
Ex.get())) {
diff --git a/clang/test/SemaCXX/new-delete.cpp 
b/clang/test/SemaCXX/new-delete.cpp
index 595bdc689d694b..18b26e7f0f08a1 100644
--- a/clang/test/SemaCXX/new-delete.cpp
+++ b/clang/test/SemaCXX/new-delete.cpp
@@ -540,6 +540,14 @@ namespace PR10504 {
   void f(A *x) { delete x; } // expected-warning {{delete called on 
'PR10504::A' that is abstract but has non-virtual destructor}}
 }
 
+#if __cplusplus >= 201103L
+enum GH99278_1 { // expected-note {{definition of 'GH99278_1' is not complete 
until the closing '}'}}
+zero = decltype(delete static_cast(nullptr), 0){}
+// expected-warning@-1 {{deleting pointer to incomplete type}}
+// expected-warning@-2 {{expression with side effects has no effect in an 
unevaluated context}}
+};
+#endif
+
 struct PlacementArg {};
 inline void *operator new[](size_t, const PlacementArg &) throw () {
   return 0;

>From eeaa30618c73febdf413dbec6deb8792c576a30d Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 4 Dec 2024 06:08:38 +0100
Subject: [PATCH 2/3] remove warning

---
 clang/lib/Sema/SemaExprCXX.cpp| 6 +++---
 clang/test/SemaCXX/new-delete.cpp | 5 ++---
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 20947ca4e35b17..d524337f7f79b5 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -3747,9 +3747,9 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool 
UseGlobal,
 } else if (!Pointee->isDependentType()) {
   // FIXME: This can result in errors if the definition was imported from a
   // module but is hidden.
-  if (!RequireCompleteType(StartLoc, Pointee,
-   Pointee->isStructureOrClassType() &&
-   LangOpts.CPlusPlus26
+  if (!Pointee->isStructureOrClassType() ||
+  !RequireCompleteType(StartLoc, Pointee,
+   LangOpts.CPlusPlus26
? diag::err_delete_incomplete
: diag::warn_delete_incomplete,
Ex.get())) {
diff --git a/clang/test/SemaCXX/new-delete.cpp 
b/clang/test/SemaCXX/new-delete.cpp
index 18b26e7f0f08a1..98b168d9df1f37 100644
--- a/clang/test/SemaCXX/new-delete.cpp
+++ b/clang/test/SemaCXX/new-delete.cpp
@@ -541,10 +541,9 @@ namespace PR10504 {
 }
 
 #if __cplusplus >= 201103L
-enum GH99278_1 { // expected-note {{definition of 'GH99278_1' is not complete 
until the closing '}'}}
+enum GH99278_1 {
 zero = decltype(delete static_cast(nullptr), 0){}
-// expected-warning@-1 {{deleting pointer to incomplete type}}
-// expected-warning@-2 {{expression with side effects has no effect in an 
unevaluated contex

[clang] [Clang] Deleting an incomplete enum type is not an error (PR #119077)

2024-12-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

The changes introduced in #97733 accidentally prevented to delete an 
incomplete enum
(the validity of which has been confirmed by CWG2925

Fixes #99278


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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+2-1) 
- (modified) clang/test/SemaCXX/new-delete.cpp (+16) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 01c7899e36c932..e442516c225f74 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -766,6 +766,7 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure caused by mangled names with invalid identifiers. 
(#GH112205)
 - Fixed an incorrect lambda scope of generic lambdas that caused Clang to 
crash when computing potential lambda
   captures at the end of a full expression. (#GH115931)
+- Clang no longer rejects deleting a pointer of incomplete enumeration type. 
(#GH99278)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d85819b21c8265..d0baedbf782d42 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -3747,7 +3747,8 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool 
UseGlobal,
 } else if (!Pointee->isDependentType()) {
   // FIXME: This can result in errors if the definition was imported from a
   // module but is hidden.
-  if (!RequireCompleteType(StartLoc, Pointee,
+  if (Pointee->isEnumeralType() ||
+  !RequireCompleteType(StartLoc, Pointee,
LangOpts.CPlusPlus26
? diag::err_delete_incomplete
: diag::warn_delete_incomplete,
diff --git a/clang/test/SemaCXX/new-delete.cpp 
b/clang/test/SemaCXX/new-delete.cpp
index 595bdc689d694b..fb4810ad673ad2 100644
--- a/clang/test/SemaCXX/new-delete.cpp
+++ b/clang/test/SemaCXX/new-delete.cpp
@@ -540,6 +540,22 @@ namespace PR10504 {
   void f(A *x) { delete x; } // expected-warning {{delete called on 
'PR10504::A' that is abstract but has non-virtual destructor}}
 }
 
+#if __cplusplus >= 201103L
+enum GH99278_1 {
+zero = decltype(delete static_cast(nullptr), 0){}
+// expected-warning@-1 {{expression with side effects has no effect in an 
unevaluated context}}
+};
+template 
+struct GH99278_2 {
+  union b {};
+  struct c {
+c() { delete d; }
+b *d;
+  } f;
+};
+GH99278_2 e;
+#endif
+
 struct PlacementArg {};
 inline void *operator new[](size_t, const PlacementArg &) throw () {
   return 0;

``




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


[clang] [Clang] Deleting an incomplete enum type is not an error (PR #119077)

2024-12-07 Thread via cfe-commits

cor3ntin wrote:

This is a reland of #118455 with the regression introduced therein fixed

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


[clang] [clang] Fix cast for injected types in case name lookup for dependent bases (PR #119024)

2024-12-07 Thread via cfe-commits

https://github.com/cor3ntin commented:

Can you confirm this is a fix for 
https://github.com/llvm/llvm-project/pull/118003 ?
In which case we do not need changelog entry

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


[clang] [clang] Fix cast for injected types in case name lookup for dependent bases (PR #119024)

2024-12-07 Thread via cfe-commits

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


  1   2   >