[clang] [Driver] Corrections for linker flags passed with relocatable linking on OpenBSD (PR #67254)

2023-09-24 Thread Brad Smith via cfe-commits

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


[clang] [Driver] Some adjustments for relocatable linking on OpenBSD (PR #67254)

2023-09-24 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/67254

>From c638c2fe9d022f6e25f4ec5e6d2a4db49ac5d0f8 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 24 Sep 2023 00:20:53 -0400
Subject: [PATCH] [Driver] Corrections for linker flags passed with relocatable
 linking on OpenBSD

The entry point symbol handling matches our GCC link spec..
%{!shared:%{!nostdlib:%{!r:%{!e*:-e __start
---
 clang/lib/Driver/ToolChains/OpenBSD.cpp | 8 +---
 clang/test/Driver/openbsd.c | 4 +++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index 91fe3837b81..8d88379ef4c10e7 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -121,6 +121,7 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   bool Profiling = Args.hasArg(options::OPT_pg);
   bool Pie = Args.hasArg(options::OPT_pie);
   bool Nopie = Args.hasArg(options::OPT_nopie);
+  bool Relocatable = Args.hasArg(options::OPT_r);
 
   // Silence warning for "clang -g foo.o -o foo"
   Args.ClaimAllArgs(options::OPT_g_Group);
@@ -138,7 +139,7 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   else if (Arch == llvm::Triple::mips64el)
 CmdArgs.push_back("-EL");
 
-  if (!Args.hasArg(options::OPT_nostdlib) && !Shared) {
+  if (!Args.hasArg(options::OPT_nostdlib) && !Shared && !Relocatable) {
 CmdArgs.push_back("-e");
 CmdArgs.push_back("__start");
   }
@@ -149,10 +150,11 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   } else {
 if (Args.hasArg(options::OPT_rdynamic))
   CmdArgs.push_back("-export-dynamic");
-CmdArgs.push_back("-Bdynamic");
+if (!Relocatable)
+  CmdArgs.push_back("-Bdynamic");
 if (Shared) {
   CmdArgs.push_back("-shared");
-} else if (!Args.hasArg(options::OPT_r)) {
+} else if (!Relocatable) {
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/usr/libexec/ld.so");
 }
diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index 05d290a309c40c0..a8db20200cd473d 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -36,10 +36,12 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64-LD %s
 // RUN: %clang --target=mips64el-unknown-openbsd -### %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s
-// CHECK-LD-R: "-r"
+// CHECK-LD-R-NOT: "-e" "__start"
+// CHECK-LD-R-NOT: "-Bdynamic"
 // CHECK-LD-R-NOT: "-dynamic-linker"
 // CHECK-LD-R-NOT: "-l
 // CHECK-LD-R-NOT: crt{{[^./\\]+}}.o
+// CHECK-LD-R: "-r"
 // CHECK-LD-S: "-cc1" "-triple" "i686-pc-openbsd"
 // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" 
"-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" 
"-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" 
"{{.*}}crtend.o"
 // CHECK-LD-T: "-cc1" "-triple" "i686-pc-openbsd"

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


[clang] [clang-format] Fix a bug in aligning trailing comments (PR #67221)

2023-09-24 Thread Owen Pan via cfe-commits

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


[clang] d3f8c88 - [clang-format] Fix a bug in aligning trailing comments (#67221)

2023-09-24 Thread via cfe-commits

Author: Owen Pan
Date: 2023-09-24T20:07:23-07:00
New Revision: d3f8c88abe2ecc455165f0a32c389fec61730ace

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

LOG: [clang-format] Fix a bug in aligning trailing comments (#67221)

Fixes #67116.

Added: 


Modified: 
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTestComments.cpp

Removed: 




diff  --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 27ad90c6879abec..1790a9df42b5d14 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1062,7 +1062,7 @@ void WhitespaceManager::alignTrailingComments() {
   const int OriginalSpaces =
   C.OriginalWhitespaceRange.getEnd().getRawEncoding() -
   C.OriginalWhitespaceRange.getBegin().getRawEncoding() -
-  C.Tok->NewlinesBefore;
+  C.Tok->LastNewlineOffset;
   assert(OriginalSpaces >= 0);
   const auto RestoredLineLength =
   C.StartOfTokenColumn + C.TokenLength + OriginalSpaces;

diff  --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 001c5bf5fcda14e..1198329b7b5a8f0 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -3053,6 +3053,12 @@ TEST_F(FormatTestComments, AlignTrailingCommentsLeave) {
"}",
Style);
 
+  Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
+  verifyNoChange("#define FOO\\\n"
+ "  /* foo(); */ \\\n"
+ "  bar();",
+ Style);
+
   // Allow to keep 2 empty lines
   Style.MaxEmptyLinesToKeep = 2;
   EXPECT_EQ("// do not touch\n"



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


[clang] [clang-format] Fix a bug in aligning trailing comments (PR #67221)

2023-09-24 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/67221

>From 8f9df29e1fdfdf49d4a420cc7ec7a28d6bba807f Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 22 Sep 2023 23:47:23 -0700
Subject: [PATCH] [clang-format] Fix a bug in aligning trailing comments

Fixes #67116.
---
 clang/lib/Format/WhitespaceManager.cpp| 2 +-
 clang/unittests/Format/FormatTestComments.cpp | 6 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 27ad90c6879abec..1790a9df42b5d14 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1062,7 +1062,7 @@ void WhitespaceManager::alignTrailingComments() {
   const int OriginalSpaces =
   C.OriginalWhitespaceRange.getEnd().getRawEncoding() -
   C.OriginalWhitespaceRange.getBegin().getRawEncoding() -
-  C.Tok->NewlinesBefore;
+  C.Tok->LastNewlineOffset;
   assert(OriginalSpaces >= 0);
   const auto RestoredLineLength =
   C.StartOfTokenColumn + C.TokenLength + OriginalSpaces;
diff --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 001c5bf5fcda14e..1198329b7b5a8f0 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -3053,6 +3053,12 @@ TEST_F(FormatTestComments, AlignTrailingCommentsLeave) {
"}",
Style);
 
+  Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
+  verifyNoChange("#define FOO\\\n"
+ "  /* foo(); */ \\\n"
+ "  bar();",
+ Style);
+
   // Allow to keep 2 empty lines
   Style.MaxEmptyLinesToKeep = 2;
   EXPECT_EQ("// do not touch\n"

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


[clang] [clang-format] Fix a bug in aligning trailing comments (PR #67221)

2023-09-24 Thread Owen Pan via cfe-commits

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Kai Luo via cfe-commits


@@ -3412,13 +3416,23 @@ SDValue 
PPCTargetLowering::LowerGlobalTLSAddressAIX(SDValue Op,
 return DAG.getNode(PPCISD::ADD_TLS, dl, PtrVT, TLSReg, VariableOffset);
   }
 
-  // Only Local-Exec, Initial-Exec and General-Dynamic TLS models are currently
-  // supported models. If Local- or Initial-exec are not possible or specified,
-  // all GlobalTLSAddress nodes are lowered using the general-dynamic model.
-  // We need to generate two TOC entries, one for the variable offset, one for
-  // the region handle. The global address for the TOC entry of the region
-  // handle is created with the MO_TLSGDM_FLAG flag and the global address
-  // for the TOC entry of the variable offset is created with MO_TLSGD_FLAG.
+  if (Model == TLSModel::LocalDynamic) {
+// For local-dynamic on AIX, we need to generate two TOC entries, one for
+// the variable offset, the other for the module handle. The module handle
+// is encapsulated inside the TLSLD_AIX pseudo node, and will be expanded 
by
+// PPCTLSDynamicCall.
+SDValue VariableOffsetTGA =
+DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, PPCII::MO_TLSLD_FLAG);
+SDValue VariableOffset = getTOCEntry(DAG, dl, VariableOffsetTGA);

bzEq wrote:

I don't think the module handle has external linkage, `_$TLSML` is renamed from 
the module handle defined in the module. If we need a `GlobalValue` to create a 
TOC entry for the module handle, `PreISelIntrinsicLowering` would be a 
candidate pass to realize it.

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


[clang] [X86][RFC] Support AVX10 options (PR #67278)

2023-09-24 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang updated 
https://github.com/llvm/llvm-project/pull/67278

>From eaf36c8cac3fe6d9bb3dcb1387b0b4f1febf5ef7 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Mon, 25 Sep 2023 10:31:37 +0800
Subject: [PATCH 1/2] [X86][RFC] Support AVX10 options

AVX10 Architecture Specification: 
https://cdrdv2.intel.com/v1/dl/getContent/784267
AVX10 Technical Paper: https://cdrdv2.intel.com/v1/dl/getContent/784343
RFC: https://discourse.llvm.org/t/rfc-design-for-avx10-options-support/73672
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Driver/Options.td |  9 +
 clang/lib/Basic/Targets/X86.cpp   | 37 +--
 clang/lib/Basic/Targets/X86.h |  2 +
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 30 +++
 clang/test/CodeGen/X86/avx512-error.c | 20 +++---
 clang/test/CodeGen/attr-target-x86.c  | 14 +--
 clang/test/CodeGen/target-avx-abi-diag.c  |  4 ++
 clang/test/Driver/x86-target-features.c   | 20 ++
 clang/test/Preprocessor/x86_target_features.c | 14 +++
 llvm/docs/ReleaseNotes.rst|  2 +
 .../llvm/TargetParser/X86TargetParser.def |  2 +
 llvm/lib/Target/X86/X86.td|  8 
 llvm/lib/Target/X86/X86InstrInfo.td   |  2 +
 llvm/lib/TargetParser/Host.cpp|  6 +++
 llvm/lib/TargetParser/X86TargetParser.cpp |  9 +
 16 files changed, 168 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7abcb8d799e09dc..419bab7577cfad4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -387,6 +387,7 @@ X86 Support
 
 - Added option ``-m[no-]evex512`` to disable ZMM and 64-bit mask instructions
   for AVX512 features.
+- Support ISA of ``AVX10.1``.
 
 Arm and AArch64 Support
 ^^^
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0f93479170d73bc..dd44333e6cb30a7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -197,6 +197,9 @@ def m_wasm_Features_Driver_Group : OptionGroup<"">,
 def m_x86_Features_Group : OptionGroup<"">,
Group, Visibility<[ClangOption, CLOption]>,
DocName<"X86">;
+def m_x86_AVX10_Features_Group : OptionGroup<"">,
+ Group, Visibility<[ClangOption, 
CLOption]>,
+ DocName<"X86 AVX10">;
 def m_riscv_Features_Group : OptionGroup<"">,
  Group, DocName<"RISC-V">;
 def m_ve_Features_Group : OptionGroup<"">,
@@ -5693,6 +5696,12 @@ def msse4a : Flag<["-"], "msse4a">, 
Group;
 def mno_sse4a : Flag<["-"], "mno-sse4a">, Group;
 def mavx : Flag<["-"], "mavx">, Group;
 def mno_avx : Flag<["-"], "mno-avx">, Group;
+def mavx10_1_256 : Flag<["-"], "mavx10.1-256">, 
Group;
+def mno_avx10_1_256 : Flag<["-"], "mno-avx10.1-256">, 
Group;
+def mavx10_1_512 : Flag<["-"], "mavx10.1-512">, 
Group;
+def mno_avx10_1_512 : Flag<["-"], "mno-avx10.1-512">, 
Group;
+def mavx10_1 : Flag<["-"], "mavx10.1">, Alias;
+def mno_avx10_1 : Flag<["-"], "mno-avx10.1">, Alias;
 def mavx2 : Flag<["-"], "mavx2">, Group;
 def mno_avx2 : Flag<["-"], "mno-avx2">, Group;
 def mavx512f : Flag<["-"], "mavx512f">, Group;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 022d5753135e160..746414181926f7d 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -121,6 +121,7 @@ bool X86TargetInfo::initFeatureMap(
   std::vector UpdatedFeaturesVec;
   bool HasEVEX512 = true;
   bool HasAVX512F = false;
+  bool HasAVX10 = false;
   for (const auto  : FeaturesVec) {
 // Expand general-regs-only to -x86, -mmx and -sse
 if (Feature == "+general-regs-only") {
@@ -130,17 +131,35 @@ bool X86TargetInfo::initFeatureMap(
   continue;
 }
 
-if (!HasAVX512F && Feature.substr(0, 7) == "+avx512")
+if (Feature.substr(0, 7) == "+avx10.") {
+  HasAVX10 = true;
   HasAVX512F = true;
-if (HasAVX512F && Feature == "-avx512f")
+  if (Feature.substr(Feature.size() - 3, 3) == "512") {
+HasEVEX512 = true;
+  } else if (Feature.substr(7, 2) == "1-") {
+HasEVEX512 = false;
+  }
+} else if (!HasAVX512F && Feature.substr(0, 7) == "+avx512") {
+  HasAVX512F = true;
+} else if (HasAVX512F && Feature == "-avx512f") {
+  HasAVX512F = false;
+} else if (HasAVX10 && Feature == "-avx10.1-256") {
+  HasAVX10 = false;
   HasAVX512F = false;
-if (HasEVEX512 && Feature == "-evex512")
+} else if (!HasEVEX512 && Feature == "+evex512") {
+  HasEVEX512 = true;
+} else if (HasEVEX512 && Feature == "-avx10.1-512") {
   HasEVEX512 = false;
+} else if (HasEVEX512 && Feature == "-evex512") {
+  HasEVEX512 = false;
+}
 
 UpdatedFeaturesVec.push_back(Feature);
   }
   

[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-24 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 c60ccfbb898148449946f82cbac6140f1e01cb12 
f97313eadac98e753155b5e05ac0eef16f7fb82d -- 
libcxx/include/__algorithm/ranges_clamp.h 
libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp 
b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
index 771169071d77..69d2af0fdf62 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
@@ -34,25 +34,15 @@ struct CreateNoComp {
 };
 
 struct Comparator {
-bool operator()(const int&& x, const int&& y) const {
-return x < y;
-}
-bool operator()(const int&& x, int& y) const {
-return x < y;
-}
-bool operator()(int& x, const int&& y) const {
-return x < y;
-}
-bool operator()(int& x, int& y) const {
-return x < y;
-}
-bool operator()(std::same_as auto && x, std::same_as auto && y) const {
-return x < y;
-}
+  bool operator()(const int&& x, const int&& y) const { return x < y; }
+  bool operator()(const int&& x, int& y) const { return x < y; }
+  bool operator()(int& x, const int&& y) const { return x < y; }
+  bool operator()(int& x, int& y) const { return x < y; }
+  bool operator()(std::same_as auto&& x, std::same_as 
auto&& y) const { return x < y; }
 };
 
 struct MoveProj {
-const int&& operator()(const int& x) const { return std::move(x); }
+  const int&& operator()(const int& x) const { return std::move(x); }
 };
 
 static_assert(std::indirect_strict_weak_order>);
@@ -110,7 +100,7 @@ constexpr bool test() {
   }
 
   { // Make sure we don't call the projection more than three times per 
[alg.clamp], see #64717
-int counter = 0;
+int counter  = 0;
 auto projection_function = [](const int value) -> int {
   counter++;
   return value;
@@ -124,22 +114,16 @@ constexpr bool test() {
 };
 
 // taking by value is important here
-auto comparator = [](std::string a, std::string b) {
-  return std::atoi(a.c_str()) < std::atoi(b.c_str());
-};
+auto comparator = [](std::string a, std::string b) { return 
std::atoi(a.c_str()) < std::atoi(b.c_str()); };
 
-auto projection = [](Foo const& foo) {
-  return foo.s;
-};
+auto projection = [](Foo const& foo) { return foo.s; };
 
 Foo foo{"12"};
 Foo high{"10"};
 Foo low{"1"};
 assert(std::ranges::clamp(foo, low, high, comparator, projection).s == 
"10");
   }
-  {
-assert(std::ranges::clamp(0, 1, 2, Comparator{}, MoveProj{}) == 1);
-  }
+  { assert(std::ranges::clamp(0, 1, 2, Comparator{}, MoveProj{}) == 1); }
   return true;
 }
 

``




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


[clang-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-24 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 c60ccfbb898148449946f82cbac6140f1e01cb12 
f97313eadac98e753155b5e05ac0eef16f7fb82d -- 
libcxx/include/__algorithm/ranges_clamp.h 
libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp 
b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
index 771169071d77..69d2af0fdf62 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
@@ -34,25 +34,15 @@ struct CreateNoComp {
 };
 
 struct Comparator {
-bool operator()(const int&& x, const int&& y) const {
-return x < y;
-}
-bool operator()(const int&& x, int& y) const {
-return x < y;
-}
-bool operator()(int& x, const int&& y) const {
-return x < y;
-}
-bool operator()(int& x, int& y) const {
-return x < y;
-}
-bool operator()(std::same_as auto && x, std::same_as auto && y) const {
-return x < y;
-}
+  bool operator()(const int&& x, const int&& y) const { return x < y; }
+  bool operator()(const int&& x, int& y) const { return x < y; }
+  bool operator()(int& x, const int&& y) const { return x < y; }
+  bool operator()(int& x, int& y) const { return x < y; }
+  bool operator()(std::same_as auto&& x, std::same_as 
auto&& y) const { return x < y; }
 };
 
 struct MoveProj {
-const int&& operator()(const int& x) const { return std::move(x); }
+  const int&& operator()(const int& x) const { return std::move(x); }
 };
 
 static_assert(std::indirect_strict_weak_order>);
@@ -110,7 +100,7 @@ constexpr bool test() {
   }
 
   { // Make sure we don't call the projection more than three times per 
[alg.clamp], see #64717
-int counter = 0;
+int counter  = 0;
 auto projection_function = [](const int value) -> int {
   counter++;
   return value;
@@ -124,22 +114,16 @@ constexpr bool test() {
 };
 
 // taking by value is important here
-auto comparator = [](std::string a, std::string b) {
-  return std::atoi(a.c_str()) < std::atoi(b.c_str());
-};
+auto comparator = [](std::string a, std::string b) { return 
std::atoi(a.c_str()) < std::atoi(b.c_str()); };
 
-auto projection = [](Foo const& foo) {
-  return foo.s;
-};
+auto projection = [](Foo const& foo) { return foo.s; };
 
 Foo foo{"12"};
 Foo high{"10"};
 Foo low{"1"};
 assert(std::ranges::clamp(foo, low, high, comparator, projection).s == 
"10");
   }
-  {
-assert(std::ranges::clamp(0, 1, 2, Comparator{}, MoveProj{}) == 1);
-  }
+  { assert(std::ranges::clamp(0, 1, 2, Comparator{}, MoveProj{}) == 1); }
   return true;
 }
 

``




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


[clang] [X86][RFC] Support AVX10 options (PR #67278)

2023-09-24 Thread Phoebe Wang via cfe-commits

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


[clang] [X86][RFC] Support AVX10 options (PR #67278)

2023-09-24 Thread Phoebe Wang via cfe-commits

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


[clang] [X86][RFC] Support AVX10 options (PR #67278)

2023-09-24 Thread Phoebe Wang via cfe-commits

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


[clang] main (PR #67278)

2023-09-24 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 81a3828dbd992aaf03cb6080abace8114ba40f8e 
eaf36c8cac3fe6d9bb3dcb1387b0b4f1febf5ef7 -- clang/lib/Basic/Targets/X86.cpp 
clang/lib/Basic/Targets/X86.h clang/lib/Driver/ToolChains/Arch/X86.cpp 
clang/test/CodeGen/X86/avx512-error.c clang/test/CodeGen/attr-target-x86.c 
clang/test/CodeGen/target-avx-abi-diag.c 
clang/test/Driver/x86-target-features.c 
clang/test/Preprocessor/x86_target_features.c llvm/lib/TargetParser/Host.cpp 
llvm/lib/TargetParser/X86TargetParser.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/TargetParser/X86TargetParser.cpp 
b/llvm/lib/TargetParser/X86TargetParser.cpp
index f0115b801..995b5eebd 100644
--- a/llvm/lib/TargetParser/X86TargetParser.cpp
+++ b/llvm/lib/TargetParser/X86TargetParser.cpp
@@ -614,8 +614,8 @@ constexpr FeatureBitset ImpliedFeaturesAVXVNNI = 
FeatureAVX2;
 constexpr FeatureBitset ImpliedFeaturesAVX10_1 =
 FeatureAVX512CD | FeatureAVX512VBMI | FeatureAVX512IFMA |
 FeatureAVX512VNNI | FeatureAVX512BF16 | FeatureAVX512VPOPCNTDQ |
-FeatureAVX512VBMI2 | FeatureAVX512BITALG | FeatureVAES |
-FeatureVPCLMULQDQ | FeatureAVX512FP16;
+FeatureAVX512VBMI2 | FeatureAVX512BITALG | FeatureVAES | FeatureVPCLMULQDQ 
|
+FeatureAVX512FP16;
 constexpr FeatureBitset ImpliedFeaturesAVX10_1_512 =
 FeatureAVX10_1 | FeatureEVEX512;
 

``




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


[clang] main (PR #67278)

2023-09-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

- Reapply "[AArch64] Merge LDRSWpre-LD[U]RSW pair into LDPSWpre"
- Revert "[ORC][LLJIT] Move enable-debugger-support utility out of 
LLJITBuilder."
- [gn build] Port e5f169f91a86
- [ConstraintElimination] Introduce tests for PR66173
- [ConstraintElimination] Extend unsigned-to-signed fact transfer
- [clang][Interp][NFC] Refactor ByteCodeEmitter a bit
- Fix: Distinguish CFI Metadata Checks in MergeFunctions Pass (#65963)
- [clang][Interp][NFC] Enable constexpr-single-element-array test
- [Workflow] Try to fix code-formatter failing to find changes in some cases.
- [Workflow] Use a higher max depth
- [libc] Fix cyclical dependency on errno matcher for NVPTX architectures
- Propagate the volatile qualifier of exp  to  store /load operations .
- [clang][Interp][NFC] Enable more existing SemaCXX tests
- [DAGCombiner][AArch64] Fix incorrect cast VT in `takeInexpensiveLog2`
- [Workflow] Roll back some settings since they caused more issues
- [BPF] Check jump and memory offsets to avoid truncation
- [NVPTX] Test crash introduced by #67073
- [ProfileData] Use llvm::byteswap instead of sys::getSwappedBytes (NFC)
- [Support] Use llvm::byteswap instead of sys::getSwappedBytes (NFC)
- [Lex] Use llvm::byteswap instead of sys::getSwappedBytes (NFC)
- Reapply "[AMDGPU] Introduce real and keep fake True16 instructions."
- [Support] Use llvm::bit_cast in getSwappedBytes (NFC)
- Use llvm::find (NFC)
- [LLVM][OpenMP] Allow OpenMPOpt to handle non-OpenMP target regions (#67075)
- [libunwind][nfc] avoid prototype warning (#67250)
- [clangd] Remove unused using decls (NFC)
- [llvm-exegesis] Remove unused using decls (NFC)
- [clang][Interp][NFC] Use GetPtrThisField intead of two ops
- [clang][Interp][NFC] Make a local variable const
- [clang][Interp][NFC] Clean up EvalEmitter includes
- [clang][Interp][NFC] Clean up Context includes
- [TableGen] Fix ordering of register classes. (#67245)
- [InstCombine] Add test cases from PR63321. NFC.
- [InstCombine] Fold `(-1 + A)  B` into `A ? 0 : B` where A is effectively 
a bool
- [AMDGPU] Add ISD::FSHR Handling to AMDGPUISD::PERM matching
- [DAG] getNode() - fold (zext (trunc x)) - x iff the upper bits are known 
zero - add SRL support
- [libcxx] Don't deallocate non-pointer data in string assignment. (#67200)
- [EarlyCSE] Support CSE for commutative intrinsics with over 2 args (#67255)
- [GlobalISel][NFC] Remove unused method CombinerHelper::tryCombine()
- [Clang][CodeGen] Add __builtin_bcopy (#67130)
- [InstCombine] Add pre-commit tests for PR57328. NFC.
- [InstSimplify] Generalize fold for icmp ugt/ule (pow2  X), signmask
- [InstCombine] Add more pre-commit tests for PR57328. NFC.
- [InstCombine] Add conjugate part of pre-commit tests for PR57328. NFC.
- Fix assertion failure mangling an unresolved template argument that 
corresponds to a parameter pack.
- [llvm-cov] Properly fix -Wcovered-switch-default in CoverageMapping.cpp
- [InstCombine] Fold `icmp eq/ne min|max(X, Y), Z` (#67087)
- [Driver] Hook up NetBSD/riscv support (#67256)
- [InstCombine] Add pre-commit tests for PR65968. NFC.
- [VPlan] Simplify HCFG construction of region blocks (NFC).
- [OMPIRBuilder] Added `createTeams` (#66807)
- [clang-format][NFC] Clean up alignTrailingComments() (#67218)
- Remove unused clang::TargetInfo::adjustTargetOptions
- [clang-format] Fix an assertion failure in Whitespace Manager
- [clang][Sema] Make format size estimator aware of %p's existence in format 
string (#65969)
- Revert "[InstCombine] Fold `icmp eq/ne min|max(X, Y), Z` (#67087)"
- [SimplifyCFG] Transform for redirecting phis between unmergeable BB and 
SuccBB (#67275)
- [clang-format][NFC] Remove the unused separateDefinitionBlocks()
- [libcxx] experimental/simd excluded long double for 32-bits x86 
temporarily
- [X86][RFC] Support AVX10 options


---

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


16 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Driver/Options.td (+9) 
- (modified) clang/lib/Basic/Targets/X86.cpp (+34-3) 
- (modified) clang/lib/Basic/Targets/X86.h (+2) 
- (modified) clang/lib/Driver/ToolChains/Arch/X86.cpp (+30) 
- (modified) clang/test/CodeGen/X86/avx512-error.c (+14-6) 
- (modified) clang/test/CodeGen/attr-target-x86.c (+11-3) 
- (modified) clang/test/CodeGen/target-avx-abi-diag.c (+4) 
- (modified) clang/test/Driver/x86-target-features.c (+20) 
- (modified) clang/test/Preprocessor/x86_target_features.c (+14) 
- (modified) llvm/docs/ReleaseNotes.rst (+2) 
- (modified) llvm/include/llvm/TargetParser/X86TargetParser.def (+2) 
- (modified) llvm/lib/Target/X86/X86.td (+8) 
- (modified) llvm/lib/Target/X86/X86InstrInfo.td (+2) 
- (modified) llvm/lib/TargetParser/Host.cpp (+6) 
- (modified) llvm/lib/TargetParser/X86TargetParser.cpp (+9) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 

[clang] main (PR #67278)

2023-09-24 Thread Phoebe Wang via cfe-commits

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


[clang] main (PR #67278)

2023-09-24 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang created 
https://github.com/llvm/llvm-project/pull/67278

- Reapply "[AArch64] Merge LDRSWpre-LD[U]RSW pair into LDPSWpre"
- Revert "[ORC][LLJIT] Move enable-debugger-support utility out of 
LLJITBuilder."
- [gn build] Port e5f169f91a86
- [ConstraintElimination] Introduce tests for PR66173
- [ConstraintElimination] Extend unsigned-to-signed fact transfer
- [clang][Interp][NFC] Refactor ByteCodeEmitter a bit
- Fix: Distinguish CFI Metadata Checks in MergeFunctions Pass (#65963)
- [clang][Interp][NFC] Enable constexpr-single-element-array test
- [Workflow] Try to fix code-formatter failing to find changes in some cases.
- [Workflow] Use a higher max depth
- [libc] Fix cyclical dependency on errno matcher for NVPTX architectures
- Propagate the volatile qualifier of exp  to  store /load operations .
- [clang][Interp][NFC] Enable more existing SemaCXX tests
- [DAGCombiner][AArch64] Fix incorrect cast VT in `takeInexpensiveLog2`
- [Workflow] Roll back some settings since they caused more issues
- [BPF] Check jump and memory offsets to avoid truncation
- [NVPTX] Test crash introduced by #67073
- [ProfileData] Use llvm::byteswap instead of sys::getSwappedBytes (NFC)
- [Support] Use llvm::byteswap instead of sys::getSwappedBytes (NFC)
- [Lex] Use llvm::byteswap instead of sys::getSwappedBytes (NFC)
- Reapply "[AMDGPU] Introduce real and keep fake True16 instructions."
- [Support] Use llvm::bit_cast in getSwappedBytes (NFC)
- Use llvm::find (NFC)
- [LLVM][OpenMP] Allow OpenMPOpt to handle non-OpenMP target regions (#67075)
- [libunwind][nfc] avoid prototype warning (#67250)
- [clangd] Remove unused using decls (NFC)
- [llvm-exegesis] Remove unused using decls (NFC)
- [clang][Interp][NFC] Use GetPtrThisField intead of two ops
- [clang][Interp][NFC] Make a local variable const
- [clang][Interp][NFC] Clean up EvalEmitter includes
- [clang][Interp][NFC] Clean up Context includes
- [TableGen] Fix ordering of register classes. (#67245)
- [InstCombine] Add test cases from PR63321. NFC.
- [InstCombine] Fold `(-1 + A) & B` into `A ? 0 : B` where A is effectively a 
bool
- [AMDGPU] Add ISD::FSHR Handling to AMDGPUISD::PERM matching
- [DAG] getNode() - fold (zext (trunc x)) -> x iff the upper bits are known 
zero - add SRL support
- [libcxx] Don't deallocate non-pointer data in string assignment. (#67200)
- [EarlyCSE] Support CSE for commutative intrinsics with over 2 args (#67255)
- [GlobalISel][NFC] Remove unused method CombinerHelper::tryCombine()
- [Clang][CodeGen] Add __builtin_bcopy (#67130)
- [InstCombine] Add pre-commit tests for PR57328. NFC.
- [InstSimplify] Generalize fold for icmp ugt/ule (pow2 << X), signmask
- [InstCombine] Add more pre-commit tests for PR57328. NFC.
- [InstCombine] Add conjugate part of pre-commit tests for PR57328. NFC.
- Fix assertion failure mangling an unresolved template argument that 
corresponds to a parameter pack.
- [llvm-cov] Properly fix -Wcovered-switch-default in CoverageMapping.cpp
- [InstCombine] Fold `icmp eq/ne min|max(X, Y), Z` (#67087)
- [Driver] Hook up NetBSD/riscv support (#67256)
- [InstCombine] Add pre-commit tests for PR65968. NFC.
- [VPlan] Simplify HCFG construction of region blocks (NFC).
- [OMPIRBuilder] Added `createTeams` (#66807)
- [clang-format][NFC] Clean up alignTrailingComments() (#67218)
- Remove unused clang::TargetInfo::adjustTargetOptions
- [clang-format] Fix an assertion failure in Whitespace Manager
- [clang][Sema] Make format size estimator aware of %p's existence in format 
string (#65969)
- Revert "[InstCombine] Fold `icmp eq/ne min|max(X, Y), Z` (#67087)"
- [SimplifyCFG] Transform for redirecting phis between unmergeable BB and 
SuccBB (#67275)
- [clang-format][NFC] Remove the unused separateDefinitionBlocks()
- [libcxx]  excluded long double for 32-bits x86 temporarily
- [X86][RFC] Support AVX10 options


>From eaf36c8cac3fe6d9bb3dcb1387b0b4f1febf5ef7 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Mon, 25 Sep 2023 10:31:37 +0800
Subject: [PATCH] [X86][RFC] Support AVX10 options

AVX10 Architecture Specification: 
https://cdrdv2.intel.com/v1/dl/getContent/784267
AVX10 Technical Paper: https://cdrdv2.intel.com/v1/dl/getContent/784343
RFC: https://discourse.llvm.org/t/rfc-design-for-avx10-options-support/73672
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Driver/Options.td |  9 +
 clang/lib/Basic/Targets/X86.cpp   | 37 +--
 clang/lib/Basic/Targets/X86.h |  2 +
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 30 +++
 clang/test/CodeGen/X86/avx512-error.c | 20 +++---
 clang/test/CodeGen/attr-target-x86.c  | 14 +--
 clang/test/CodeGen/target-avx-abi-diag.c  |  4 ++
 clang/test/Driver/x86-target-features.c   | 20 ++
 clang/test/Preprocessor/x86_target_features.c | 14 +++
 llvm/docs/ReleaseNotes.rst|  2 +
 .../llvm/TargetParser/X86TargetParser.def |  2 +
 

[clang] [Driver] Remove FreeBSD/riscv32 support (PR #67277)

2023-09-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

FreeBSD does not support riscv32 and has no intention of doing so.

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


4 Files Affected:

- (modified) clang/lib/Basic/Targets.cpp (-3) 
- (modified) clang/lib/Driver/ToolChains/FreeBSD.cpp (-5) 
- (modified) clang/test/Driver/freebsd.c (-3) 
- (modified) clang/test/Preprocessor/predefined-macros-no-warnings.c (-1) 


``diff
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 35d1d0d2c45c530..80822f65662850d 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -430,9 +430,6 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
 
   case llvm::Triple::riscv32:
 switch (os) {
-case llvm::Triple::FreeBSD:
-  return std::make_unique>(Triple,
-Opts);
 case llvm::Triple::NetBSD:
   return std::make_unique>(Triple,
Opts);
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 4c46861bbbd74ef..67a8bb863b3b6b0 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -210,11 +210,6 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 else
   CmdArgs.push_back("elf64ltsmip_fbsd");
 break;
-  case llvm::Triple::riscv32:
-CmdArgs.push_back("-m");
-CmdArgs.push_back("elf32lriscv");
-CmdArgs.push_back("-X");
-break;
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
diff --git a/clang/test/Driver/freebsd.c b/clang/test/Driver/freebsd.c
index 8ac0cb011638a8a..afa0a17249851b3 100644
--- a/clang/test/Driver/freebsd.c
+++ b/clang/test/Driver/freebsd.c
@@ -73,9 +73,6 @@
 //
 // Check that RISC-V passes the correct linker emulation.
 //
-// RUN: %clang --target=riscv32-freebsd -### %s %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-RV32I-LD %s
-// CHECK-RV32I-LD: ld{{.*}}" {{.*}} "-m" "elf32lriscv"
 // RUN: %clang --target=riscv64-freebsd -### %s %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-RV64I-LD %s
 // CHECK-RV64I-LD: ld{{.*}}" {{.*}} "-m" "elf64lriscv"
diff --git a/clang/test/Preprocessor/predefined-macros-no-warnings.c 
b/clang/test/Preprocessor/predefined-macros-no-warnings.c
index 56573af6fc7ba82..e0617f8de4da385 100644
--- a/clang/test/Preprocessor/predefined-macros-no-warnings.c
+++ b/clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -103,7 +103,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple amdgcn
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple r600
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv32
-// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv32-freebsd
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv32-linux
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv64
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv64-freebsd

``




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


[clang] [Driver] Remove FreeBSD/riscv32 support (PR #67277)

2023-09-24 Thread Brad Smith via cfe-commits

https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/67277

FreeBSD does not support riscv32 and has no intention of doing so.

>From f72b48795ea5ceb6e0301460defe361041767013 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 24 Sep 2023 22:24:20 -0400
Subject: [PATCH] [Driver] Remove FreeBSD/riscv32 support

FreeBSD does not support riscv32 and has no intention of doing so.
---
 clang/lib/Basic/Targets.cpp | 3 ---
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 5 -
 clang/test/Driver/freebsd.c | 3 ---
 clang/test/Preprocessor/predefined-macros-no-warnings.c | 1 -
 4 files changed, 12 deletions(-)

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 35d1d0d2c45c530..80822f65662850d 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -430,9 +430,6 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
 
   case llvm::Triple::riscv32:
 switch (os) {
-case llvm::Triple::FreeBSD:
-  return std::make_unique>(Triple,
-Opts);
 case llvm::Triple::NetBSD:
   return std::make_unique>(Triple,
Opts);
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 4c46861bbbd74ef..67a8bb863b3b6b0 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -210,11 +210,6 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 else
   CmdArgs.push_back("elf64ltsmip_fbsd");
 break;
-  case llvm::Triple::riscv32:
-CmdArgs.push_back("-m");
-CmdArgs.push_back("elf32lriscv");
-CmdArgs.push_back("-X");
-break;
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
diff --git a/clang/test/Driver/freebsd.c b/clang/test/Driver/freebsd.c
index 8ac0cb011638a8a..afa0a17249851b3 100644
--- a/clang/test/Driver/freebsd.c
+++ b/clang/test/Driver/freebsd.c
@@ -73,9 +73,6 @@
 //
 // Check that RISC-V passes the correct linker emulation.
 //
-// RUN: %clang --target=riscv32-freebsd -### %s %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-RV32I-LD %s
-// CHECK-RV32I-LD: ld{{.*}}" {{.*}} "-m" "elf32lriscv"
 // RUN: %clang --target=riscv64-freebsd -### %s %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-RV64I-LD %s
 // CHECK-RV64I-LD: ld{{.*}}" {{.*}} "-m" "elf64lriscv"
diff --git a/clang/test/Preprocessor/predefined-macros-no-warnings.c 
b/clang/test/Preprocessor/predefined-macros-no-warnings.c
index 56573af6fc7ba82..e0617f8de4da385 100644
--- a/clang/test/Preprocessor/predefined-macros-no-warnings.c
+++ b/clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -103,7 +103,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple amdgcn
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple r600
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv32
-// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv32-freebsd
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv32-linux
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv64
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv64-freebsd

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-24 Thread Jocelyn Castellano via cfe-commits

https://github.com/pandaninjas updated 
https://github.com/llvm/llvm-project/pull/66315

>From ead65bfcb70be46788bc9e88c891e7ae7f91b8d7 Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 17:38:17 -0700
Subject: [PATCH 01/21] [libc++] Prevent calling the projection more than three
 times

---
 libcxx/include/__algorithm/ranges_clamp.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 9613f7f37720a6c..ca46675eb4b3041 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto  = std::invoke(__proj, __value);
+if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), 
std::invoke(__proj, __value)))
+else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
   return __high;
 else
   return __value;

>From c18d60870ac342a95a5528396a8e0c7b91717cbb Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 18:56:44 -0700
Subject: [PATCH 02/21] [libc++] Run clang-format on file

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index ca46675eb4b3041..3469a6419b2270f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto  = std::invoke(__proj, __value);
+auto& projection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From b40e791f0e9fedbb19936851e1e71decf00331fa Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:20 -0700
Subject: [PATCH 03/21] [libcxx] CamelCase projection and make variable name
 more descriptive

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3469a6419b2270f..3adb5fa828e1ee5 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto& projection = std::invoke(__proj, __value);
+auto& ValueProjection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From a8907624defa4cc4f47520a2d93a8bd042816aa2 Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:47 -0700
Subject: [PATCH 04/21] [libcxx] properly change variable name

---
 libcxx/include/__algorithm/ranges_clamp.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3adb5fa828e1ee5..3d7a224b3649a3f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -38,9 +38,9 @@ struct __fn {
  "Bad bounds passed to std::ranges::clamp");
 
 auto& ValueProjection = std::invoke(__proj, __value);
-if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
+if (std::invoke(__comp, ValueProjection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
+else if (std::invoke(__comp, std::invoke(__proj, __high), ValueProjection))
   return __high;
 else
   return __value;

>From 15d3b2b79fbd61f97b0312e0913cede36b5b202d Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Thu, 14 Sep 2023 10:37:34 -0700
Subject: [PATCH 05/21] Apply suggestions from code review

---
 libcxx/include/__algorithm/ranges_clamp.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3d7a224b3649a3f..a97538e4c0e3f65 

[clang] 7db211b - [clang-format][NFC] Remove the unused separateDefinitionBlocks()

2023-09-24 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-09-24T19:25:23-07:00
New Revision: 7db211bda791e4326e380a57a882af20a273

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

LOG: [clang-format][NFC] Remove the unused separateDefinitionBlocks()

Also, fixed a formatting error introduced in 84e3fdfc6523.

Added: 


Modified: 
clang/lib/Format/Format.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 8e9be6752ce5870..8a34b4d9431b62a 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -61,8 +61,8 @@ namespace llvm {
 namespace yaml {
 template <>
 struct ScalarEnumerationTraits 
{
-  static void enumeration(IO ,
-  FormatStyle::BreakBeforeNoexceptSpecifierStyle 
) {
+  static void
+  enumeration(IO , FormatStyle::BreakBeforeNoexceptSpecifierStyle ) {
 IO.enumCase(Value, "Never", FormatStyle::BBNSS_Never);
 IO.enumCase(Value, "OnlyWithParen", FormatStyle::BBNSS_OnlyWithParen);
 IO.enumCase(Value, "Always", FormatStyle::BBNSS_Always);
@@ -3779,16 +3779,6 @@ tooling::Replacements fixNamespaceEndComments(const 
FormatStyle ,
   return NamespaceEndCommentsFixer(*Env, Style).process().first;
 }
 
-tooling::Replacements separateDefinitionBlocks(const FormatStyle ,
-   StringRef Code,
-   ArrayRef Ranges,
-   StringRef FileName) {
-  auto Env = Environment::make(Code, FileName, Ranges);
-  if (!Env)
-return {};
-  return DefinitionBlockSeparator(*Env, Style).process().first;
-}
-
 tooling::Replacements sortUsingDeclarations(const FormatStyle ,
 StringRef Code,
 ArrayRef Ranges,



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


[clang-tools-extra] [clangd] fix compilation errors with newer versions of gRPC (PR #67258)

2023-09-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd


Changes

in recent versions of gRPC, header files with prefix `grpc++` are deprecated.

gRPC headers in include/grpc++ are deprecated since gRPC 1.10.0 
https://github.com/grpc/grpc/releases/tag/v1.10.0 , this PR should close 
https://github.com/clangd/clangd/issues/1603

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


3 Files Affected:

- (modified) clang-tools-extra/clangd/index/remote/Client.cpp (+1-1) 
- (modified) clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp (+1-1) 
- (modified) clang-tools-extra/clangd/index/remote/server/Server.cpp (+3-3) 


``diff
diff --git a/clang-tools-extra/clangd/index/remote/Client.cpp 
b/clang-tools-extra/clangd/index/remote/Client.cpp
index 391da3916259c67..bc95d0787fdb74e 100644
--- a/clang-tools-extra/clangd/index/remote/Client.cpp
+++ b/clang-tools-extra/clangd/index/remote/Client.cpp
@@ -6,7 +6,7 @@
 //
 
//===--===//
 
-#include 
+#include 
 
 #include "Client.h"
 #include "Feature.h"
diff --git a/clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp 
b/clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
index 9a58b5871bfce1a..ad391573804f4da 100644
--- a/clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
+++ b/clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
@@ -16,7 +16,7 @@
 
 #include 
 #include 
-#include 
+#include 
 
 namespace clang {
 namespace clangd {
diff --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp 
b/clang-tools-extra/clangd/index/remote/server/Server.cpp
index e108d4d0b057ba2..ad075c4446cad18 100644
--- a/clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -33,8 +33,8 @@
 #include "llvm/Support/VirtualFileSystem.h"
 
 #include 
-#include 
-#include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -42,7 +42,7 @@
 #include 
 
 #if ENABLE_GRPC_REFLECTION
-#include 
+#include 
 #endif
 
 #ifdef __GLIBC__

``




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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits

orcguru wrote:

> For below case:
> 
> ```
> __thread extern  int x = 42;
> __thread extern int y = 42;
> int main(void) {
>return x + y;
> }
> ```
> 
> For now, we get:
> 
> ```
> .main:
> # %bb.0:# %entry
> mflr 0
> stwu 1, -32(1)
> stw 0, 40(1)
> lwz 6, L..C0(2) # target-flags(ppc-tlsld) @x
> lwz 7, L..C1(2) # target-flags(ppc-tlsld) @y
> lwz 3, L..C2(2) # target-flags(ppc-tlsld) 
> &"_$TLSML[TC]"
> bla .__tls_get_mod[PR]
> add 3, 3, 6
> lwz 6, 0(3)
> lwz 3, L..C2(2) # target-flags(ppc-tlsld) 
> &"_$TLSML[TC]"
> bla .__tls_get_mod[PR]
> add 3, 3, 7
> lwz 3, 0(3)
> add 3, 3, 6
> addi 1, 1, 32
> lwz 0, 8(1)
> mtlr 0
> blr
> ```
> 
> I think we should be able to save one `__tls_get_mod()`?
> 
> If this is not easy to optimize now, I'm OK we do this optimization later.

I think this has been addressed in 
[c5779c1](https://github.com/llvm/llvm-project/pull/66316/commits/c5779c1142936db45c1d0e2046ee5015a7d02fe9).
 TLSLDAIX nodes no longer have any parameter, they look the same to 
machine-cse, and so should be able to be eliminated now.

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


[clang-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-24 Thread A. Jiang via cfe-commits

frederick-vs-ja wrote:

It seems that we should remove this block because it turns out that 
`ranges::clamp` needs double moves under some circumstances.
https://github.com/llvm/llvm-project/blob/4c1c96e6fc0f704e9e032f87b2cd1e04bb4240dd/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp#L89-L110

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits

orcguru wrote:

I'm working on environment issue, and will update remaining two LIT cases and 
do testing etc.

I'm requesting another round of review in the mean time. Thank you all for your 
inputs!

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits


@@ -3412,13 +3416,23 @@ SDValue 
PPCTargetLowering::LowerGlobalTLSAddressAIX(SDValue Op,
 return DAG.getNode(PPCISD::ADD_TLS, dl, PtrVT, TLSReg, VariableOffset);
   }
 
-  // Only Local-Exec, Initial-Exec and General-Dynamic TLS models are currently
-  // supported models. If Local- or Initial-exec are not possible or specified,
-  // all GlobalTLSAddress nodes are lowered using the general-dynamic model.
-  // We need to generate two TOC entries, one for the variable offset, one for
-  // the region handle. The global address for the TOC entry of the region
-  // handle is created with the MO_TLSGDM_FLAG flag and the global address
-  // for the TOC entry of the variable offset is created with MO_TLSGD_FLAG.
+  if (Model == TLSModel::LocalDynamic) {
+// For local-dynamic on AIX, we need to generate two TOC entries, one for
+// the variable offset, the other for the module handle. The module handle
+// is encapsulated inside the TLSLD_AIX pseudo node, and will be expanded 
by
+// PPCTLSDynamicCall.
+SDValue VariableOffsetTGA =
+DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, PPCII::MO_TLSLD_FLAG);
+SDValue VariableOffset = getTOCEntry(DAG, dl, VariableOffsetTGA);

orcguru wrote:

I still didn't figure out how to remove the strange function.

The way I tried was getOrCreate ExternalLinkage GV named "_$TLSML", and call 
getTOCEntry on that GV. However there will be a symbol table entry for the 
symbol, but we don't want that.

For asm mode, I can add hack in 
MCAsmStreamer::emitXCOFFSymbolLinkageWithVisibility to do not emit the ".extern 
_Renamed..5f24__TLSML; rename _Renamed..5f24__TLSML ..".

For obj mode, things are more complex, and I'm not able to cleanly remove the 
symbol table entry without by using hack approach.

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


[clang-tools-extra] [X86] Add detection for more Tremont models (PR #67150)

2023-09-24 Thread via cfe-commits

https://github.com/libenc updated 
https://github.com/llvm/llvm-project/pull/67150

>From 6f0e5d947d05105b3480221b0d9759216596268a Mon Sep 17 00:00:00 2001
From: libenc <75132456+lib...@users.noreply.github.com>
Date: Fri, 22 Sep 2023 22:43:46 +0800
Subject: [PATCH] [X86] Add detection for more Tremont models

Fix the issue that only the server series Tremont processors
(Snow Ridge & Elkhart Lake) can be detected as Tremont, while
the client series (Jasper Lake & Lakefield) will be guessed
as Goldmont.
---
 compiler-rt/lib/builtins/cpu_model.c | 2 ++
 llvm/lib/TargetParser/Host.cpp   | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/compiler-rt/lib/builtins/cpu_model.c 
b/compiler-rt/lib/builtins/cpu_model.c
index 6a0cc8f7a402dad..32f38b5c08f096b 100644
--- a/compiler-rt/lib/builtins/cpu_model.c
+++ b/compiler-rt/lib/builtins/cpu_model.c
@@ -553,6 +553,8 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned 
Model,
   *Type = INTEL_GOLDMONT_PLUS;
   break;
 case 0x86:
+case 0x8a: // Lakefield
+case 0x9c: // Jasper Lake
   CPU = "tremont";
   *Type = INTEL_TREMONT;
   break;
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index c79595295d1bd81..c743de893447844 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -913,6 +913,8 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned 
Model,
   *Type = X86::INTEL_GOLDMONT_PLUS;
   break;
 case 0x86:
+case 0x8a: // Lakefield
+case 0x9c: // Jasper Lake
   CPU = "tremont";
   *Type = X86::INTEL_TREMONT;
   break;

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits

orcguru wrote:

> > The primary advantage of the local-dynamic access method is that you only 
> > make a single function call to __tls_get_mod() and use the returned pointer 
> > to get at all TLS variables. This implementation makes a function call for 
> > every variable. The only thing you've gained is a reduction in the number 
> > of TOC symbols.
> 
> The issue with duplicated calls to .__tls_get_mod is due to those pseudo 
> TLSLDAIX nodes depending on different GVs, and CSE is not able to do dedup. I 
> probably have to create a pseudo GV named like "_$TLSML", and use that GV for 
> all TLSLDAIX pseudo nodes.

I tired TLSLDAIX without parameter (load module-handle is well known so the 
parameter is redundant), and now looks like those redundant .__tls_get_mod 
calls can be eliminated by optimization pass machine-cse.

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits


@@ -156,10 +156,11 @@ define void @storesTIInit(double %Val) #0 {
 ; SMALL32:   # %bb.0: # %entry
 ; SMALL32-NEXT:mflr 0
 ; SMALL32-NEXT:stwu 1, -32(1)
-; SMALL32-NEXT:lwz 3, L..C4(2) # target-flags(ppc-lo) @TIInit
-; SMALL32-NEXT:lwz 4, L..C5(2) # target-flags(ppc-tlsgd) @TIInit
 ; SMALL32-NEXT:stw 0, 40(1)
-; SMALL32-NEXT:bla .__tls_get_addr[PR]
+; SMALL32-NEXT:lwz 6, L..C4(2) # target-flags(ppc-tlsld) @TIInit

orcguru wrote:

Now for the small-model, we did reuse r4. However for the large-model, since 
machine-scheduler will decide to move the ADDIS before the .__tls_get_mod call, 
I did not try to move ADDIS in PPCTLSDynamicCall.cpp

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


[clang] 56c3b8e - [clang][Sema] Make format size estimator aware of %p's existence in format string (#65969)

2023-09-24 Thread via cfe-commits

Author: Takuya Shimizu
Date: 2023-09-25T10:03:46+09:00
New Revision: 56c3b8e997d065b568964f71715ecbbd28c2e4a4

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

LOG: [clang][Sema] Make format size estimator aware of %p's existence in format 
string (#65969)

This change introduces `-Wformat-overflow` and `-Wformat-truncation` warning 
flags that were formerly diagnosed from `-Wfortify-source` warning group.
This also introduces `-Wformat-overflow-non-kprintf` and 
`-Wformat-truncation-non-kprintf`, both of which will be used when the format 
string contains `%p` format string.

The rationale for this is that Linux kernel has its own extension for `%p` 
format specifier, and we need some way to suppress false positives in kernel 
codebase.
The approach of this patch aims NOT to affect non-kernel codebases.
Note that GCC stops format size estimation upon `%p` format specifier.

As requested in https://github.com/llvm/llvm-project/issues/64871

Added: 
clang/test/Sema/warn-format-overflow-truncation.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/test/Misc/warning-wall.c
clang/test/Sema/warn-fortify-source.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8b5e48d1758d96d..7abcb8d799e09dc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -185,9 +185,19 @@ Improvements to Clang's diagnostics
 - Clang constexpr evaluator now diagnoses compound assignment operators against
   uninitialized variables as a read of uninitialized object.
   (`#51536 `_)
-- Clang's ``-Wfortify-source`` now diagnoses ``snprintf`` call that is known to
+- Clang's ``-Wformat-truncation`` now diagnoses ``snprintf`` call that is 
known to
   result in string truncation.
   (`#64871: `_).
+  Existing warnings that similarly warn about the overflow in ``sprintf``
+  now falls under its own warning group ```-Wformat-overflow`` so that it can
+  be disabled separately from ``Wfortify-source``.
+  These two new warning groups have subgroups 
``-Wformat-truncation-non-kprintf``
+  and ``-Wformat-overflow-non-kprintf``, respectively. These subgroups are 
used when
+  the format string contains ``%p`` format specifier.
+  Because Linux kernel's codebase has format extensions for ``%p``, kernel 
developers
+  are encouraged to disable these two subgroups by setting 
``-Wno-format-truncation-non-kprintf``
+  and ``-Wno-format-overflow-non-kprintf`` in order to avoid false positives on
+  the kernel codebase.
   Also clang no longer emits false positive warnings about the output length of
   ``%g`` format specifier and about ``%o, %x, %X`` with ``#`` flag.
 - Clang now emits ``-Wcast-qual`` for functional-style cast expressions.

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 00c458fb23e73e2..afbf0f0ed22e57f 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -961,10 +961,16 @@ def FormatNonStandard : DiagGroup<"format-non-iso">;
 def FormatY2K : DiagGroup<"format-y2k">;
 def FormatPedantic : DiagGroup<"format-pedantic">;
 def FormatTypeConfusion : DiagGroup<"format-type-confusion">;
+
+def FormatOverflowNonKprintf: DiagGroup<"format-overflow-non-kprintf">;
+def FormatOverflow: DiagGroup<"format-overflow", [FormatOverflowNonKprintf]>;
+def FormatTruncationNonKprintf: DiagGroup<"format-truncation-non-kprintf">;
+def FormatTruncation: DiagGroup<"format-truncation", 
[FormatTruncationNonKprintf]>;
+
 def Format : DiagGroup<"format",
[FormatExtraArgs, FormatZeroLength, NonNull,
 FormatSecurity, FormatY2K, FormatInvalidSpecifier,
-FormatInsufficientArgs]>,
+FormatInsufficientArgs, FormatOverflow, 
FormatTruncation]>,
  DiagCategory<"Format String Issue">;
 def FormatNonLiteral : DiagGroup<"format-nonliteral">;
 def Format2 : DiagGroup<"format=2",
@@ -1400,7 +1406,7 @@ def CrossTU : DiagGroup<"ctu">;
 
 def CTADMaybeUnsupported : DiagGroup<"ctad-maybe-unsupported">;
 
-def FortifySource : DiagGroup<"fortify-source">;
+def FortifySource : DiagGroup<"fortify-source", [FormatOverflow, 
FormatTruncation]>;
 
 def MaxTokens : DiagGroup<"max-tokens"> {
   code Documentation = [{

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9613cca63193ffd..f4eb02fd9570c2f 100644
--- 

[clang] [clang][Sema] Make format size estimator aware of %p's existence in format string (PR #65969)

2023-09-24 Thread Takuya Shimizu via cfe-commits

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits


@@ -3412,13 +3416,23 @@ SDValue 
PPCTargetLowering::LowerGlobalTLSAddressAIX(SDValue Op,
 return DAG.getNode(PPCISD::ADD_TLS, dl, PtrVT, TLSReg, VariableOffset);
   }
 
-  // Only Local-Exec, Initial-Exec and General-Dynamic TLS models are currently
-  // supported models. If Local- or Initial-exec are not possible or specified,
-  // all GlobalTLSAddress nodes are lowered using the general-dynamic model.
-  // We need to generate two TOC entries, one for the variable offset, one for
-  // the region handle. The global address for the TOC entry of the region
-  // handle is created with the MO_TLSGDM_FLAG flag and the global address
-  // for the TOC entry of the variable offset is created with MO_TLSGD_FLAG.
+  if (Model == TLSModel::LocalDynamic) {
+// For local-dynamic on AIX, we need to generate two TOC entries, one for
+// the variable offset, the other for the module handle. The module handle
+// is encapsulated inside the TLSLD_AIX pseudo node, and will be expanded 
by
+// PPCTLSDynamicCall.
+SDValue VariableOffsetTGA =
+DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, PPCII::MO_TLSLD_FLAG);
+SDValue VariableOffset = getTOCEntry(DAG, dl, VariableOffsetTGA);

orcguru wrote:

There is a blocker which limits FLAG bit size to be 12:

```
llvm/include/llvm/CodeGen/MachineOperand.h
...
  unsigned SubReg_TargetFlags : 12;
...
  void setTargetFlags(unsigned F) {
assert(!isReg() && "Register operands can't have target flags");
SubReg_TargetFlags = F;
assert(SubReg_TargetFlags == F && "Target flags out of range");
  } 
```

Currently PPCII::TOF is already full. I'm afraid this will be a FIXME...

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


[clang] [clang][Sema] Make format size estimator aware of %p's existence in format string (PR #65969)

2023-09-24 Thread Takuya Shimizu via cfe-commits

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


[clang] [clang][Sema] Stop format size estimator upon %p to adapt to linux kernel's extension (PR #65969)

2023-09-24 Thread Takuya Shimizu via cfe-commits

hazohelet wrote:

> ping @hazohelet . This should be good to land and should help clear some red 
> in our CI for Linux kernel builds.

Thanks for the ping. I was away for a while. I'm merging this after updating 
the PR descriptions.

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


[clang] [clang-format][NFC] Clean up alignTrailingComments() (PR #67218)

2023-09-24 Thread Owen Pan via cfe-commits

owenca wrote:

Fixed in ff7e85402280.

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits


@@ -3412,13 +3416,23 @@ SDValue 
PPCTargetLowering::LowerGlobalTLSAddressAIX(SDValue Op,
 return DAG.getNode(PPCISD::ADD_TLS, dl, PtrVT, TLSReg, VariableOffset);
   }
 
-  // Only Local-Exec, Initial-Exec and General-Dynamic TLS models are currently
-  // supported models. If Local- or Initial-exec are not possible or specified,
-  // all GlobalTLSAddress nodes are lowered using the general-dynamic model.
-  // We need to generate two TOC entries, one for the variable offset, one for
-  // the region handle. The global address for the TOC entry of the region
-  // handle is created with the MO_TLSGDM_FLAG flag and the global address
-  // for the TOC entry of the variable offset is created with MO_TLSGD_FLAG.
+  if (Model == TLSModel::LocalDynamic) {
+// For local-dynamic on AIX, we need to generate two TOC entries, one for

orcguru wrote:

Updated comment to:
// For local-dynamic on AIX, we need to generate one TOC entry for each
// variable offset, and single module-handle TOC entry for the entire file.


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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits


@@ -1771,9 +1771,13 @@ const char 
*PPCTargetLowering::getTargetNodeName(unsigned Opcode) const {
   case PPCISD::ADDIS_TLSGD_HA:  return "PPCISD::ADDIS_TLSGD_HA";
   case PPCISD::ADDI_TLSGD_L:return "PPCISD::ADDI_TLSGD_L";
   case PPCISD::GET_TLS_ADDR:return "PPCISD::GET_TLS_ADDR";
+  case PPCISD::GET_TLS_MOD_AIX:

orcguru wrote:

Sure. I followed your advice. Thank you!

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits


@@ -2826,6 +2877,8 @@ void PPCAIXAsmPrinter::emitInstruction(const MachineInstr 
*MI) {
 MMI->hasDebugInfo());
 break;
   }
+  case PPC::GETtlsMOD32AIX:
+  case PPC::GETtlsMOD64AIX:
   case PPC::GETtlsTpointer32AIX:
   case PPC::GETtlsADDR64AIX:
   case PPC::GETtlsADDR32AIX: {

orcguru wrote:

Added comments:
// A reference to .__tls_get_mod is unknown to the assembler so we need to
// emit an external symbol reference.


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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits


@@ -1362,6 +1402,8 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr 
*MI) {
   case PPC::GETtlsADDRPCREL:
   case PPC::GETtlsADDR32AIX:
   case PPC::GETtlsADDR64AIX:
+  case PPC::GETtlsMOD32AIX:

orcguru wrote:

Added following description:
// Transform: %r3 = GETtlsMODNNAIX %r3 (for NN == 32/64).
// Into: BLA .__tls_get_mod()
// Input parameter is a module handle (__TLSML[TC]@ml) for all variables.


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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits


@@ -231,12 +231,15 @@ class PPCTargetAsmStreamer : public PPCTargetStreamer {
   MCSymbolXCOFF *TCSym =
   cast(Streamer.getCurrentSectionOnly())
   ->getQualNameSymbol();
-  // On AIX, we have a region handle (symbol@m) and the variable offset
-  // (symbol@{gd|ie|le}) for TLS variables, depending on the TLS model.
+  // On AIX, we have a region handle (symbol@m), module handle

orcguru wrote:

Thank you! I put this description into the comment.

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits


@@ -1622,6 +1629,10 @@ def TLSGDAIX8 :
  "#TLSGDAIX8",
  [(set i64:$rD,
(PPCTlsgdAIX i64:$offset, i64:$handle))]>;
+// This pseudo is expanded to one copy to put the module handle in R3, then 
call
+// GETtlsMOD64AIX, and then add variable offset to the output from the call.
+def TLSLDAIX8 : PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc:$handle),

orcguru wrote:

Thank you. I have changed the implementation of the pseudo node: it loads 
module-handle into R/X3 and then calls .__tls_get_mod. (ADD is implemented by 
standalone ISD::ADD, so not in the scope of this pseudo node)

Now I changed the comment to:
// This pseudo is expanded to load module-handle in X3, and the call to 
GETtlsMOD64AIX.

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits

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


[clang] [clang-format][NFC] Clean up alignTrailingComments() (PR #67218)

2023-09-24 Thread Nico Weber via cfe-commits

nico wrote:

This seems to break tests: http://45.33.8.238/linux/119090/step_8.txt

Please take a look and revert for now if it takes a while to fix.

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-24 Thread Felix via cfe-commits

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


[clang] 2c3cae3 - Remove unused clang::TargetInfo::adjustTargetOptions

2023-09-24 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-09-24T16:37:24-07:00
New Revision: 2c3cae3f01b10a2ba3745761e11b63a2b129eee9

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

LOG: Remove unused clang::TargetInfo::adjustTargetOptions

The hook introduced by https://reviews.llvm.org/D22815 for AMDGPU was
removed by commit ce2258c1cd5dc9cf20040d1b1e540d80250c1435 in 2020.

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/Frontend/CompilerInstance.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 61be52149341f01..9d56e97a3d4bb88 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1260,10 +1260,6 @@ class TargetInfo : public TransferrableTargetInfo,
   /// the language based on the target options where applicable.
   virtual void adjust(DiagnosticsEngine , LangOptions );
 
-  /// Adjust target options based on codegen options.
-  virtual void adjustTargetOptions(const CodeGenOptions ,
-   TargetOptions ) const {}
-
   /// Initialize the map with the default set of target features for the
   /// CPU this should include all legal feature strings on the target.
   ///

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 49c1d8e553a1df6..aacbb2050334411 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -151,9 +151,6 @@ bool CompilerInstance::createTarget() {
   // created. This complexity should be lifted elsewhere.
   getTarget().adjust(getDiagnostics(), getLangOpts());
 
-  // Adjust target options based on codegen options.
-  getTarget().adjustTargetOptions(getCodeGenOpts(), getTargetOpts());
-
   if (auto *Aux = getAuxTarget())
 getTarget().setAuxTarget(Aux);
 



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


[clang] [Clang][RISCV] Handle RVV tuple types correctly as OutputOperands for inline asm (PR #67018)

2023-09-24 Thread Kito Cheng via cfe-commits


@@ -2524,11 +2551,32 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt ) {
   ResultRegIsFlagReg.push_back(IsFlagReg);
 
   llvm::Type *Ty = ConvertTypeForMem(QTy);
+  ResultTruncRegTypes.push_back(Ty);
+
+  // Expressing the type as a structure in inline asm calls will complicate
+  // the current code case, so instead, the return type is set to be a
+  // single scalable vector, then reconstructed with `vector.extract` and
+  // `insertvalue`. The type is derived here, and the reconstruction is 
done
+  // under EmitAsmStores.
+  if (QTy->isRVVType() && isa(Ty)) {
+// Flatten the structure into a single ScalableVectorType
+auto *STy = cast(Ty);
+assert(STy->containsHomogeneousScalableVectorTypes() &&
+   isa(STy->getElementType(0)) &&
+   "Dealing with RVV tuple (aggregate with homogeneous scalable "
+   "vectors");
+
+auto *VecTy = cast(STy->getElementType(0));
+
+Ty = llvm::ScalableVectorType::get(VecTy->getScalarType(),
+   STy->getNumElements() *
+   VecTy->getMinNumElements());

kito-cheng wrote:

Does it also work well for some types like `vint32m1x3_t`?

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


[clang] [clang-format][NFC] Clean up alignTrailingComments() (PR #67218)

2023-09-24 Thread Owen Pan via cfe-commits

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


[clang] d1c643a - [clang-format][NFC] Clean up alignTrailingComments() (#67218)

2023-09-24 Thread via cfe-commits

Author: Owen Pan
Date: 2023-09-24T15:00:57-07:00
New Revision: d1c643a0168268445dab29d96b96d5fcb9c97f92

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

LOG: [clang-format][NFC] Clean up alignTrailingComments() (#67218)

Added: 


Modified: 
clang/lib/Format/WhitespaceManager.cpp

Removed: 




diff  --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index b7bd8d27dc976b1..d7e5612928ef764 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1042,68 +1042,67 @@ void WhitespaceManager::alignChainedConditionals() {
 }
 
 void WhitespaceManager::alignTrailingComments() {
-  unsigned MinColumn = 0;
-  unsigned MaxColumn = UINT_MAX;
-  unsigned StartOfSequence = 0;
+  const int Size = Changes.size();
+  int MinColumn = 0;
+  int StartOfSequence = 0;
   bool BreakBeforeNext = false;
-  unsigned Newlines = 0;
-  unsigned int NewLineThreshold = 1;
+  int NewLineThreshold = 1;
   if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Always)
 NewLineThreshold = Style.AlignTrailingComments.OverEmptyLines + 1;
 
-  for (unsigned i = 0, e = Changes.size(); i != e; ++i) {
-if (Changes[i].StartOfBlockComment)
+  for (int I = 0, MaxColumn = INT_MAX, Newlines = 0; I < Size; ++I) {
+auto  = Changes[I];
+if (C.StartOfBlockComment)
   continue;
-Newlines += Changes[i].NewlinesBefore;
-if (!Changes[i].IsTrailingComment)
+Newlines += C.NewlinesBefore;
+if (!C.IsTrailingComment)
   continue;
 
 if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Leave) {
-  auto OriginalSpaces =
-  Changes[i].OriginalWhitespaceRange.getEnd().getRawEncoding() -
-  Changes[i].OriginalWhitespaceRange.getBegin().getRawEncoding() -
-  Changes[i].Tok->NewlinesBefore;
-  unsigned RestoredLineLength = Changes[i].StartOfTokenColumn +
-Changes[i].TokenLength + OriginalSpaces;
+  const int OriginalSpaces =
+  C.OriginalWhitespaceRange.getEnd().getRawEncoding() -
+  C.OriginalWhitespaceRange.getBegin().getRawEncoding() -
+  C.Tok->NewlinesBefore;
+  assert(OriginalSpaces >= 0);
+  const auto RestoredLineLength =
+  C.StartOfTokenColumn + C.TokenLength + OriginalSpaces;
   // If leaving comments makes the line exceed the column limit, give up to
   // leave the comments.
-  if (RestoredLineLength >= Style.ColumnLimit && Style.ColumnLimit != 0)
+  if (RestoredLineLength >= Style.ColumnLimit && Style.ColumnLimit > 0)
 break;
-  Changes[i].Spaces = OriginalSpaces;
+  C.Spaces = OriginalSpaces;
   continue;
 }
 
-unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
-unsigned ChangeMaxColumn;
-
-if (Style.ColumnLimit == 0)
-  ChangeMaxColumn = UINT_MAX;
-else if (Style.ColumnLimit >= Changes[i].TokenLength)
-  ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength;
-else
-  ChangeMaxColumn = ChangeMinColumn;
+const int ChangeMinColumn = C.StartOfTokenColumn;
+int ChangeMaxColumn;
 
 // If we don't create a replacement for this change, we have to consider
 // it to be immovable.
-if (!Changes[i].CreateReplacement)
+if (!C.CreateReplacement)
+  ChangeMaxColumn = ChangeMinColumn;
+else if (Style.ColumnLimit == 0)
+  ChangeMaxColumn = INT_MAX;
+else if (Style.ColumnLimit >= C.TokenLength)
+  ChangeMaxColumn = Style.ColumnLimit - C.TokenLength;
+else
   ChangeMaxColumn = ChangeMinColumn;
 
-if (i + 1 != e && Changes[i + 1].ContinuesPPDirective)
+if (I + 1 < Size && Changes[I + 1].ContinuesPPDirective) {
   ChangeMaxColumn -= 2;
+  assert(ChangeMaxColumn >= 0);
+}
 
-// We don't want to align namespace end comments.
-bool DontAlignThisComment = i > 0 && Changes[i].NewlinesBefore == 0 &&
-Changes[i - 1].Tok->is(TT_NamespaceRBrace);
 bool WasAlignedWithStartOfNextLine = false;
-if (Changes[i].NewlinesBefore >= 1) { // A comment on its own line.
-  unsigned CommentColumn = SourceMgr.getSpellingColumnNumber(
-  Changes[i].OriginalWhitespaceRange.getEnd());
-  for (unsigned j = i + 1; j != e; ++j) {
-if (Changes[j].Tok->is(tok::comment))
+if (C.NewlinesBefore >= 1) { // A comment on its own line.
+  const auto CommentColumn =
+  
SourceMgr.getSpellingColumnNumber(C.OriginalWhitespaceRange.getEnd());
+  for (int J = I + 1; J < Size; ++J) {
+if (Changes[J].Tok->is(tok::comment))
   continue;
 
-unsigned NextColumn = SourceMgr.getSpellingColumnNumber(
-Changes[j].OriginalWhitespaceRange.getEnd());
+const auto 

[clang] [Driver] Move assertion check before checking Output.isFilename (PR #67210)

2023-09-24 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/67210

>From 6747bc42be015d39509af516f34ba96e07e4045c Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Fri, 22 Sep 2023 19:35:21 -0400
Subject: [PATCH] [Driver] Move assertion check before checking
 Output.isFilename

---
 clang/lib/Driver/ToolChains/Cuda.cpp  | 6 +++---
 clang/lib/Driver/ToolChains/DragonFly.cpp | 3 +--
 clang/lib/Driver/ToolChains/Flang.cpp | 3 +--
 clang/lib/Driver/ToolChains/FreeBSD.cpp   | 3 +--
 clang/lib/Driver/ToolChains/Gnu.cpp   | 2 +-
 clang/lib/Driver/ToolChains/Hexagon.cpp   | 2 +-
 clang/lib/Driver/ToolChains/NetBSD.cpp| 3 +--
 clang/lib/Driver/ToolChains/OpenBSD.cpp   | 3 +--
 clang/lib/Driver/ToolChains/PS4CPU.cpp| 3 +--
 clang/lib/Driver/ToolChains/Solaris.cpp   | 3 +--
 clang/lib/Driver/ToolChains/XCore.cpp | 3 +--
 11 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 97472a302715bb9..e95ff98e6c940f1 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -572,14 +572,14 @@ void NVPTX::Linker::ConstructJob(Compilation , const 
JobAction ,
  const char *LinkingOutput) const {
   const auto  =
   static_cast(getToolChain());
+  ArgStringList CmdArgs;
+
   assert(TC.getTriple().isNVPTX() && "Wrong platform");
 
-  ArgStringList CmdArgs;
+  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
-  } else {
-assert(Output.isNothing() && "Invalid output.");
   }
 
   if (mustEmitDebugInfo(Args) == EmitSameDebugInfoAsHost)
diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index 82c975990a32511..a1e4937231572b7 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -85,11 +85,10 @@ void dragonfly::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("elf_i386");
   }
 
+  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
-  } else {
-assert(Output.isNothing() && "Invalid output.");
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 11c9d90c701f0ce..10f785ce7ab9075 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -565,11 +565,10 @@ void Flang::ConstructJob(Compilation , const JobAction 
,
 }
   }
 
+  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
-  } else {
-assert(Output.isNothing() && "Invalid output.");
   }
 
   assert(Input.isFilename() && "Invalid input.");
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 4c46861bbbd74ef..636828b0171fe41 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -232,11 +232,10 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 }
   }
 
+  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
-  } else {
-assert(Output.isNothing() && "Invalid output.");
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 1b4a94d72cc0a66..5949d9872c54f72 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -117,11 +117,11 @@ void tools::gcc::Common::ConstructJob(Compilation , 
const JobAction ,
 break;
   }
 
+  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
   } else {
-assert(Output.isNothing() && "Unexpected output");
 CmdArgs.push_back("-fsyntax-only");
   }
 
diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 0d6980c003a72b5..e7dca1053dc8d8a 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -218,11 +218,11 @@ void hexagon::Assembler::ConstructJob(Compilation , 
const JobAction ,
 
   addSanitizerRuntimes(HTC, Args, CmdArgs);
 
+  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
   } else {
-assert(Output.isNothing() 

[clang] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-09-24 Thread Yingwei Zheng via cfe-commits

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


[clang-tools-extra] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-09-24 Thread Yingwei Zheng via cfe-commits

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


[clang] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-09-24 Thread Yingwei Zheng via cfe-commits

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


[clang-tools-extra] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-09-24 Thread Yingwei Zheng via cfe-commits

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


[clang] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-09-24 Thread Yingwei Zheng via cfe-commits


@@ -757,7 +757,8 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
   bool computeVLVTYPEChanges(const MachineBasicBlock ,
  VSETVLIInfo ) const;
   void computeIncomingVLVTYPE(const MachineBasicBlock );
-  void emitVSETVLIs(MachineBasicBlock );
+  void emitVSETVLIs(MachineBasicBlock ,
+SmallVectorImpl );

dtcxzyw wrote:

I don't think it is a typo.


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


[clang] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-09-24 Thread Yingwei Zheng via cfe-commits

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


[clang-tools-extra] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-09-24 Thread Yingwei Zheng via cfe-commits


@@ -757,7 +757,8 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
   bool computeVLVTYPEChanges(const MachineBasicBlock ,
  VSETVLIInfo ) const;
   void computeIncomingVLVTYPE(const MachineBasicBlock );
-  void emitVSETVLIs(MachineBasicBlock );
+  void emitVSETVLIs(MachineBasicBlock ,
+SmallVectorImpl );

dtcxzyw wrote:

I don't think it is a typo.


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


[clang] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-09-24 Thread Yingwei Zheng via cfe-commits

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


[clang-tools-extra] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-09-24 Thread Yingwei Zheng via cfe-commits

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


[clang] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-09-24 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/65934

>From 2fe5756dd4d49580d3a23b0ff1b72535f725915e Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Mon, 11 Sep 2023 15:51:46 +0800
Subject: [PATCH 1/4] [RISCV] Eliminate dead li after emitting VSETVLIs

---
 llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp  | 22 ++---
 .../RISCV/rvv/fixed-vectors-masked-gather.ll  | 24 ---
 2 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp 
b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
index b42ad269c18de6f..918c96beb29afca 100644
--- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -757,7 +757,8 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
   bool computeVLVTYPEChanges(const MachineBasicBlock ,
  VSETVLIInfo ) const;
   void computeIncomingVLVTYPE(const MachineBasicBlock );
-  void emitVSETVLIs(MachineBasicBlock );
+  void emitVSETVLIs(MachineBasicBlock ,
+SmallVectorImpl );
   void doLocalPostpass(MachineBasicBlock );
   void doPRE(MachineBasicBlock );
   void insertReadVL(MachineBasicBlock );
@@ -1216,7 +1217,8 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo 
,
   return false;
 }
 
-void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock ) {
+void RISCVInsertVSETVLI::emitVSETVLIs(
+MachineBasicBlock , SmallVectorImpl ) {
   VSETVLIInfo CurInfo = BlockInfo[MBB.getNumber()].Pred;
   // Track whether the prefix of the block we've scanned is transparent
   // (meaning has not yet changed the abstract state).
@@ -1255,6 +1257,13 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock 
) {
 MachineOperand  = MI.getOperand(getVLOpNum(MI));
 if (VLOp.isReg()) {
   // Erase the AVL operand from the instruction.
+  if (MachineInstr *MI = MRI->getVRegDef(VLOp.getReg());
+  MI && MI->getOpcode() == RISCV::ADDI &&
+  MI->getOperand(1).isReg() && MI->getOperand(2).isImm() &&
+  MI->getOperand(1).getReg() == RISCV::X0 &&
+  MI->getOperand(2).getImm() != 0)
+DeadVLInstrs.push_back(MI);
+
   VLOp.setReg(RISCV::NoRegister);
   VLOp.setIsKill(false);
 }
@@ -1580,8 +1589,9 @@ bool 
RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction ) {
   // Phase 2 information to avoid adding vsetvlis before the first vector
   // instruction in the block if the VL/VTYPE is satisfied by its
   // predecessors.
+  SmallVector DeadVLInstrs;
   for (MachineBasicBlock  : MF)
-emitVSETVLIs(MBB);
+emitVSETVLIs(MBB, DeadVLInstrs);
 
   // Now that all vsetvlis are explicit, go through and do block local
   // DSE and peephole based demanded fields based transforms.  Note that
@@ -1592,6 +1602,12 @@ bool 
RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction ) {
   for (MachineBasicBlock  : MF)
 doLocalPostpass(MBB);
 
+  // Remove dead LI instructions that set VL.
+  for (MachineInstr *MI : DeadVLInstrs) {
+if (MRI->use_nodbg_empty(MI->getOperand(0).getReg()))
+  MI->eraseFromParent();
+  }
+
   // Once we're fully done rewriting all the instructions, do a final pass
   // through to check for VSETVLIs which write to an unused destination.
   // For the non X0, X0 variant, we can replace the destination register
diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll 
b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll
index f7352b4659e5a9b..0d306775528ed86 100644
--- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll
@@ -12393,7 +12393,6 @@ define <32 x i8> @mgather_baseidx_v32i8(ptr %base, <32 
x i8> %idxs, <32 x i1> %m
 ; RV64ZVE32F-NEXT:vmv.x.s a2, v12
 ; RV64ZVE32F-NEXT:add a2, a0, a2
 ; RV64ZVE32F-NEXT:lbu a2, 0(a2)
-; RV64ZVE32F-NEXT:li a3, 32
 ; RV64ZVE32F-NEXT:vmv.s.x v12, a2
 ; RV64ZVE32F-NEXT:vsetivli zero, 2, e8, m2, tu, ma
 ; RV64ZVE32F-NEXT:vslideup.vi v10, v12, 1
@@ -12431,7 +12430,6 @@ define <32 x i8> @mgather_baseidx_v32i8(ptr %base, <32 
x i8> %idxs, <32 x i1> %m
 ; RV64ZVE32F-NEXT:vmv.x.s a2, v14
 ; RV64ZVE32F-NEXT:add a2, a0, a2
 ; RV64ZVE32F-NEXT:lbu a2, 0(a2)
-; RV64ZVE32F-NEXT:li a3, 32
 ; RV64ZVE32F-NEXT:vmv.s.x v14, a2
 ; RV64ZVE32F-NEXT:vsetivli zero, 6, e8, m2, tu, ma
 ; RV64ZVE32F-NEXT:vslideup.vi v10, v14, 5
@@ -12455,7 +12453,6 @@ define <32 x i8> @mgather_baseidx_v32i8(ptr %base, <32 
x i8> %idxs, <32 x i1> %m
 ; RV64ZVE32F-NEXT:vmv.x.s a2, v13
 ; RV64ZVE32F-NEXT:add a2, a0, a2
 ; RV64ZVE32F-NEXT:lbu a2, 0(a2)
-; RV64ZVE32F-NEXT:li a3, 32
 ; RV64ZVE32F-NEXT:vmv.s.x v14, a2
 ; RV64ZVE32F-NEXT:vsetivli zero, 10, e8, m2, tu, ma
 ; RV64ZVE32F-NEXT:vslideup.vi v10, v14, 9
@@ -12470,7 +12467,6 @@ define <32 x i8> @mgather_baseidx_v32i8(ptr %base, <32 
x i8> 

[clang-tools-extra] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-09-24 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/65934

>From 2fe5756dd4d49580d3a23b0ff1b72535f725915e Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Mon, 11 Sep 2023 15:51:46 +0800
Subject: [PATCH 1/4] [RISCV] Eliminate dead li after emitting VSETVLIs

---
 llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp  | 22 ++---
 .../RISCV/rvv/fixed-vectors-masked-gather.ll  | 24 ---
 2 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp 
b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
index b42ad269c18de6f..918c96beb29afca 100644
--- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -757,7 +757,8 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
   bool computeVLVTYPEChanges(const MachineBasicBlock ,
  VSETVLIInfo ) const;
   void computeIncomingVLVTYPE(const MachineBasicBlock );
-  void emitVSETVLIs(MachineBasicBlock );
+  void emitVSETVLIs(MachineBasicBlock ,
+SmallVectorImpl );
   void doLocalPostpass(MachineBasicBlock );
   void doPRE(MachineBasicBlock );
   void insertReadVL(MachineBasicBlock );
@@ -1216,7 +1217,8 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo 
,
   return false;
 }
 
-void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock ) {
+void RISCVInsertVSETVLI::emitVSETVLIs(
+MachineBasicBlock , SmallVectorImpl ) {
   VSETVLIInfo CurInfo = BlockInfo[MBB.getNumber()].Pred;
   // Track whether the prefix of the block we've scanned is transparent
   // (meaning has not yet changed the abstract state).
@@ -1255,6 +1257,13 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock 
) {
 MachineOperand  = MI.getOperand(getVLOpNum(MI));
 if (VLOp.isReg()) {
   // Erase the AVL operand from the instruction.
+  if (MachineInstr *MI = MRI->getVRegDef(VLOp.getReg());
+  MI && MI->getOpcode() == RISCV::ADDI &&
+  MI->getOperand(1).isReg() && MI->getOperand(2).isImm() &&
+  MI->getOperand(1).getReg() == RISCV::X0 &&
+  MI->getOperand(2).getImm() != 0)
+DeadVLInstrs.push_back(MI);
+
   VLOp.setReg(RISCV::NoRegister);
   VLOp.setIsKill(false);
 }
@@ -1580,8 +1589,9 @@ bool 
RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction ) {
   // Phase 2 information to avoid adding vsetvlis before the first vector
   // instruction in the block if the VL/VTYPE is satisfied by its
   // predecessors.
+  SmallVector DeadVLInstrs;
   for (MachineBasicBlock  : MF)
-emitVSETVLIs(MBB);
+emitVSETVLIs(MBB, DeadVLInstrs);
 
   // Now that all vsetvlis are explicit, go through and do block local
   // DSE and peephole based demanded fields based transforms.  Note that
@@ -1592,6 +1602,12 @@ bool 
RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction ) {
   for (MachineBasicBlock  : MF)
 doLocalPostpass(MBB);
 
+  // Remove dead LI instructions that set VL.
+  for (MachineInstr *MI : DeadVLInstrs) {
+if (MRI->use_nodbg_empty(MI->getOperand(0).getReg()))
+  MI->eraseFromParent();
+  }
+
   // Once we're fully done rewriting all the instructions, do a final pass
   // through to check for VSETVLIs which write to an unused destination.
   // For the non X0, X0 variant, we can replace the destination register
diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll 
b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll
index f7352b4659e5a9b..0d306775528ed86 100644
--- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll
@@ -12393,7 +12393,6 @@ define <32 x i8> @mgather_baseidx_v32i8(ptr %base, <32 
x i8> %idxs, <32 x i1> %m
 ; RV64ZVE32F-NEXT:vmv.x.s a2, v12
 ; RV64ZVE32F-NEXT:add a2, a0, a2
 ; RV64ZVE32F-NEXT:lbu a2, 0(a2)
-; RV64ZVE32F-NEXT:li a3, 32
 ; RV64ZVE32F-NEXT:vmv.s.x v12, a2
 ; RV64ZVE32F-NEXT:vsetivli zero, 2, e8, m2, tu, ma
 ; RV64ZVE32F-NEXT:vslideup.vi v10, v12, 1
@@ -12431,7 +12430,6 @@ define <32 x i8> @mgather_baseidx_v32i8(ptr %base, <32 
x i8> %idxs, <32 x i1> %m
 ; RV64ZVE32F-NEXT:vmv.x.s a2, v14
 ; RV64ZVE32F-NEXT:add a2, a0, a2
 ; RV64ZVE32F-NEXT:lbu a2, 0(a2)
-; RV64ZVE32F-NEXT:li a3, 32
 ; RV64ZVE32F-NEXT:vmv.s.x v14, a2
 ; RV64ZVE32F-NEXT:vsetivli zero, 6, e8, m2, tu, ma
 ; RV64ZVE32F-NEXT:vslideup.vi v10, v14, 5
@@ -12455,7 +12453,6 @@ define <32 x i8> @mgather_baseidx_v32i8(ptr %base, <32 
x i8> %idxs, <32 x i1> %m
 ; RV64ZVE32F-NEXT:vmv.x.s a2, v13
 ; RV64ZVE32F-NEXT:add a2, a0, a2
 ; RV64ZVE32F-NEXT:lbu a2, 0(a2)
-; RV64ZVE32F-NEXT:li a3, 32
 ; RV64ZVE32F-NEXT:vmv.s.x v14, a2
 ; RV64ZVE32F-NEXT:vsetivli zero, 10, e8, m2, tu, ma
 ; RV64ZVE32F-NEXT:vslideup.vi v10, v14, 9
@@ -12470,7 +12467,6 @@ define <32 x i8> @mgather_baseidx_v32i8(ptr %base, <32 
x i8> 

[clang] [NFC][Clang][CodeGen] Improve performance for vtable metadata generation (PR #67066)

2023-09-24 Thread Fangrui Song via cfe-commits

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


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


[clang] [Driver] Hook up Haiku ARM support (PR #67222)

2023-09-24 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/67222

>From b9ad72d918c663f7b5ee782979ce5704b23aa370 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sat, 23 Sep 2023 03:22:18 -0400
Subject: [PATCH] [Driver] Hook up Haiku ARM support

---
 clang/lib/Basic/Targets.cpp   | 2 ++
 clang/lib/Basic/Targets/ARM.cpp   | 3 ++-
 clang/lib/Driver/ToolChains/Arch/ARM.cpp  | 1 +
 clang/test/Driver/arm-abi.c   | 2 ++
 clang/test/Driver/haiku.c | 5 +
 llvm/lib/TargetParser/ARMTargetParser.cpp | 6 +-
 6 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 35d1d0d2c45c530..9e3543c6d5ff81c 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -219,6 +219,8 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
   return std::make_unique>(Triple, 
Opts);
 case llvm::Triple::RTEMS:
   return std::make_unique>(Triple, Opts);
+case llvm::Triple::Haiku:
+  return std::make_unique>(Triple, Opts);
 case llvm::Triple::NaCl:
   return std::make_unique>(Triple, Opts);
 case llvm::Triple::Win32:
diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 06e99e67c875584..1e809283748b66c 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -257,6 +257,7 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple ,
   bool IsFreeBSD = Triple.isOSFreeBSD();
   bool IsOpenBSD = Triple.isOSOpenBSD();
   bool IsNetBSD = Triple.isOSNetBSD();
+  bool IsHaiku = Triple.isOSHaiku();
 
   // FIXME: the isOSBinFormatMachO is a workaround for identifying a 
Darwin-like
   // environment where size_t is `unsigned long` rather than `unsigned int`
@@ -323,7 +324,7 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple ,
 default:
   if (IsNetBSD)
 setABI("apcs-gnu");
-  else if (IsFreeBSD || IsOpenBSD)
+  else if (IsFreeBSD || IsOpenBSD || IsHaiku)
 setABI("aapcs-linux");
   else
 setABI("aapcs");
diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index bb66db5feae8c3b..8e1cff0b443eeeb 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -404,6 +404,7 @@ arm::FloatABI arm::getDefaultFloatABI(const llvm::Triple 
) {
 }
 break;
 
+  case llvm::Triple::Haiku:
   case llvm::Triple::OpenBSD:
 return FloatABI::SoftFP;
 
diff --git a/clang/test/Driver/arm-abi.c b/clang/test/Driver/arm-abi.c
index 7bf5977992f65a2..139456cf98e1478 100644
--- a/clang/test/Driver/arm-abi.c
+++ b/clang/test/Driver/arm-abi.c
@@ -33,6 +33,8 @@
 // RUN:   | FileCheck -check-prefix=CHECK-AAPCS-LINUX %s
 // RUN: %clang -target arm--openbsd- %s -### -o %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-AAPCS-LINUX %s
+// RUN: %clang -target arm--haiku- %s -### -o %t.o 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-AAPCS-LINUX %s
 
 // Otherwise, ABI is selected based on environment
 // RUN: %clang -target arm---android %s -### -o %t.o 2>&1 \
diff --git a/clang/test/Driver/haiku.c b/clang/test/Driver/haiku.c
index 021ab522be06e5c..3888c6732923228 100644
--- a/clang/test/Driver/haiku.c
+++ b/clang/test/Driver/haiku.c
@@ -65,3 +65,8 @@
 // CHECK-X86_64-SHARED-SAME: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK-X86_64-SHARED: "{{.*}}ld{{(.exe)?}}"
 // CHECK-X86_64-SHARED-NOT: "[[SYSROOT]]/boot/system/develop/lib/start_dyn.o"
+
+// Check default ARM CPU, ARMv6
+// RUN: %clang -### %s 2>&1 --target=arm-unknown-haiku \
+// RUN:   | FileCheck --check-prefix=CHECK-ARM-CPU %s
+// CHECK-ARM-CPU: "-target-cpu" "arm1176jzf-s"
diff --git a/llvm/lib/TargetParser/ARMTargetParser.cpp 
b/llvm/lib/TargetParser/ARMTargetParser.cpp
index c84928eeb07b140..20225232b3cccb7 100644
--- a/llvm/lib/TargetParser/ARMTargetParser.cpp
+++ b/llvm/lib/TargetParser/ARMTargetParser.cpp
@@ -526,7 +526,8 @@ StringRef ARM::computeDefaultTargetABI(const Triple , 
StringRef CPU) {
   default:
 if (TT.isOSNetBSD())
   return "apcs-gnu";
-if (TT.isOSFreeBSD() || TT.isOSOpenBSD() || TT.isOHOSFamily())
+if (TT.isOSFreeBSD() || TT.isOSOpenBSD() || TT.isOSHaiku() ||
+TT.isOHOSFamily())
   return "aapcs-linux";
 return "aapcs";
   }
@@ -542,6 +543,7 @@ StringRef ARM::getARMCPUForArch(const llvm::Triple , 
StringRef MArch) {
   case llvm::Triple::FreeBSD:
   case llvm::Triple::NetBSD:
   case llvm::Triple::OpenBSD:
+  case llvm::Triple::Haiku:
 if (!MArch.empty() && MArch == "v6")
   return "arm1176jzf-s";
 if (!MArch.empty() && MArch == "v7")
@@ -574,6 +576,8 @@ StringRef ARM::getARMCPUForArch(const llvm::Triple , 
StringRef MArch) {
   // If no specific architecture version is requested, return the minimum CPU
   // required by the OS and environment.
   switch (Triple.getOS()) {
+  case llvm::Triple::Haiku:
+return "arm1176jzf-s";
   case llvm::Triple::NetBSD:
 switch 

[clang] 62ffbe0 - [Driver] Hook up NetBSD/riscv support (#67256)

2023-09-24 Thread via cfe-commits

Author: Brad Smith
Date: 2023-09-24T16:29:46-04:00
New Revision: 62ffbe0dcca9f394f9dbfda160e0f0a1e96948ae

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

LOG: [Driver] Hook up NetBSD/riscv support (#67256)

Added: 


Modified: 
clang/lib/Basic/Targets.cpp
clang/lib/Driver/ToolChains/NetBSD.cpp
clang/test/Driver/netbsd.c
clang/test/Driver/netbsd.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 69576dbc458d9a1..35d1d0d2c45c530 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -429,11 +429,13 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
 return std::make_unique(Triple, Opts);
 
   case llvm::Triple::riscv32:
-// TODO: add cases for NetBSD, RTEMS once tested.
 switch (os) {
 case llvm::Triple::FreeBSD:
   return std::make_unique>(Triple,
 Opts);
+case llvm::Triple::NetBSD:
+  return std::make_unique>(Triple,
+   Opts);
 case llvm::Triple::Linux:
   return std::make_unique>(Triple, 
Opts);
 default:
@@ -441,11 +443,13 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
 }
 
   case llvm::Triple::riscv64:
-// TODO: add cases for NetBSD, RTEMS once tested.
 switch (os) {
 case llvm::Triple::FreeBSD:
   return std::make_unique>(Triple,
 Opts);
+case llvm::Triple::NetBSD:
+  return std::make_unique>(Triple,
+   Opts);
 case llvm::Triple::OpenBSD:
   return std::make_unique>(Triple,
 Opts);

diff  --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 88be6ea0d5e7883..0bd15434898828a 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -216,6 +216,16 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("elf64ppc");
 break;
 
+  case llvm::Triple::riscv32:
+CmdArgs.push_back("-m");
+CmdArgs.push_back("elf32lriscv");
+break;
+
+  case llvm::Triple::riscv64:
+CmdArgs.push_back("-m");
+CmdArgs.push_back("elf64lriscv");
+break;
+
   case llvm::Triple::sparc:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf32_sparc");
@@ -230,6 +240,9 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 break;
   }
 
+  if (Triple.isRISCV())
+CmdArgs.push_back("-X");
+
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
@@ -282,6 +295,8 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   case llvm::Triple::ppc:
   case llvm::Triple::ppc64:
   case llvm::Triple::ppc64le:
+  case llvm::Triple::riscv32:
+  case llvm::Triple::riscv64:
   case llvm::Triple::sparc:
   case llvm::Triple::sparcv9:
   case llvm::Triple::x86:
@@ -418,6 +433,8 @@ ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() 
const {
   case llvm::Triple::ppc:
   case llvm::Triple::ppc64:
   case llvm::Triple::ppc64le:
+  case llvm::Triple::riscv32:
+  case llvm::Triple::riscv64:
   case llvm::Triple::sparc:
   case llvm::Triple::sparcv9:
   case llvm::Triple::x86:
@@ -539,7 +556,9 @@ void NetBSD::addClangTargetOptions(const ArgList 
,
   getTriple().getArch() == llvm::Triple::aarch64 ||
   getTriple().getArch() == llvm::Triple::aarch64_be ||
   getTriple().getArch() == llvm::Triple::arm ||
-  getTriple().getArch() == llvm::Triple::armeb;
+  getTriple().getArch() == llvm::Triple::armeb ||
+  getTriple().getArch() == llvm::Triple::riscv32 ||
+  getTriple().getArch() == llvm::Triple::riscv64;
 
   if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
   options::OPT_fno_use_init_array, 
UseInitArrayDefault))

diff  --git a/clang/test/Driver/netbsd.c b/clang/test/Driver/netbsd.c
index 67c048c6e91515f..760cba4ac4e0c9f 100644
--- a/clang/test/Driver/netbsd.c
+++ b/clang/test/Driver/netbsd.c
@@ -59,6 +59,12 @@
 // RUN: %clang --target=arm-unknown-netbsd7.0.0-eabi \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=ARM-7 %s
+// RUN: %clang --target=riscv32-unknown-netbsd \
+// RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=RISCV32 %s
+// RUN: %clang --target=riscv64-unknown-netbsd \
+// RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=RISCV64 %s
 // RUN: %clang 

[clang] [Driver] Hook up NetBSD/riscv support (PR #67256)

2023-09-24 Thread Brad Smith via cfe-commits

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


[clang] [Driver] Hook up NetBSD/riscv support (PR #67256)

2023-09-24 Thread Brad Smith via cfe-commits

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


[clang] [Driver] Hook up NetBSD/riscv64 support (PR #67256)

2023-09-24 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/67256

>From 2c5311b844f9ad08b0357ea2b79d0d8bee922296 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 24 Sep 2023 02:29:27 -0400
Subject: [PATCH] [Driver] Hook up NetBSD/riscv support

---
 clang/lib/Basic/Targets.cpp|  8 +++--
 clang/lib/Driver/ToolChains/NetBSD.cpp | 21 +++-
 clang/test/Driver/netbsd.c | 42 
 clang/test/Driver/netbsd.cpp   | 44 ++
 4 files changed, 112 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 69576dbc458d9a1..35d1d0d2c45c530 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -429,11 +429,13 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
 return std::make_unique(Triple, Opts);
 
   case llvm::Triple::riscv32:
-// TODO: add cases for NetBSD, RTEMS once tested.
 switch (os) {
 case llvm::Triple::FreeBSD:
   return std::make_unique>(Triple,
 Opts);
+case llvm::Triple::NetBSD:
+  return std::make_unique>(Triple,
+   Opts);
 case llvm::Triple::Linux:
   return std::make_unique>(Triple, 
Opts);
 default:
@@ -441,11 +443,13 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
 }
 
   case llvm::Triple::riscv64:
-// TODO: add cases for NetBSD, RTEMS once tested.
 switch (os) {
 case llvm::Triple::FreeBSD:
   return std::make_unique>(Triple,
 Opts);
+case llvm::Triple::NetBSD:
+  return std::make_unique>(Triple,
+   Opts);
 case llvm::Triple::OpenBSD:
   return std::make_unique>(Triple,
 Opts);
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 88be6ea0d5e7883..0bd15434898828a 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -216,6 +216,16 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("elf64ppc");
 break;
 
+  case llvm::Triple::riscv32:
+CmdArgs.push_back("-m");
+CmdArgs.push_back("elf32lriscv");
+break;
+
+  case llvm::Triple::riscv64:
+CmdArgs.push_back("-m");
+CmdArgs.push_back("elf64lriscv");
+break;
+
   case llvm::Triple::sparc:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf32_sparc");
@@ -230,6 +240,9 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 break;
   }
 
+  if (Triple.isRISCV())
+CmdArgs.push_back("-X");
+
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
@@ -282,6 +295,8 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   case llvm::Triple::ppc:
   case llvm::Triple::ppc64:
   case llvm::Triple::ppc64le:
+  case llvm::Triple::riscv32:
+  case llvm::Triple::riscv64:
   case llvm::Triple::sparc:
   case llvm::Triple::sparcv9:
   case llvm::Triple::x86:
@@ -418,6 +433,8 @@ ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() 
const {
   case llvm::Triple::ppc:
   case llvm::Triple::ppc64:
   case llvm::Triple::ppc64le:
+  case llvm::Triple::riscv32:
+  case llvm::Triple::riscv64:
   case llvm::Triple::sparc:
   case llvm::Triple::sparcv9:
   case llvm::Triple::x86:
@@ -539,7 +556,9 @@ void NetBSD::addClangTargetOptions(const ArgList 
,
   getTriple().getArch() == llvm::Triple::aarch64 ||
   getTriple().getArch() == llvm::Triple::aarch64_be ||
   getTriple().getArch() == llvm::Triple::arm ||
-  getTriple().getArch() == llvm::Triple::armeb;
+  getTriple().getArch() == llvm::Triple::armeb ||
+  getTriple().getArch() == llvm::Triple::riscv32 ||
+  getTriple().getArch() == llvm::Triple::riscv64;
 
   if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
   options::OPT_fno_use_init_array, 
UseInitArrayDefault))
diff --git a/clang/test/Driver/netbsd.c b/clang/test/Driver/netbsd.c
index 67c048c6e91515f..760cba4ac4e0c9f 100644
--- a/clang/test/Driver/netbsd.c
+++ b/clang/test/Driver/netbsd.c
@@ -59,6 +59,12 @@
 // RUN: %clang --target=arm-unknown-netbsd7.0.0-eabi \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=ARM-7 %s
+// RUN: %clang --target=riscv32-unknown-netbsd \
+// RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=RISCV32 %s
+// RUN: %clang --target=riscv64-unknown-netbsd \
+// RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=RISCV64 %s
 // RUN: %clang --target=sparc-unknown-netbsd \
 // RUN: 

[clang] [clang-format][NFC] Clean up alignTrailingComments() (PR #67218)

2023-09-24 Thread Björn Schäpers via cfe-commits

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


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


[clang] [clang-format] Fix a bug in aligning trailing comments (PR #67221)

2023-09-24 Thread Björn Schäpers via cfe-commits

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


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


[clang] [clang-format] Disable OuterScope lambda indentation behaviour for constructor initializers (PR #66755)

2023-09-24 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

You should adapt the documentation.

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


[clang] Ensure NoTrapAfterNoreturn is false for the wasm backend (PR #65876)

2023-09-24 Thread Heejin Ahn via cfe-commits

aheejin wrote:

> > Can you point out what are the unsupported options here?
> 
> All of them, they are all options that translate to TargetOptions, and they 
> do nothing for a wasm target triple: ` --trap-unreachable=false 
> --xcoff-traceback-table=true --relax-elf-relocations=false --vec-extabi=true`

I don't think these options are the same case as this PR. These are just 
non-wasm options, so they mean nothing to wasm. Wasm simply doesn't do anything 
with respect to these options and wasm is not _overriding_ them. But with this 
PR, even if a user gives `--no-trap-after-noreturn` in the command line, they 
wouldn't know that their request was silently rejected/overridden.

To say it another way, the difference is, Wasm doesn't understand 
`--xcoff-traceback-table=true` and will do nothing with respect to it. But Wasm 
understands `--no-trap-after-noreturn` and will silently reject it after this 
PR.

> > I'm suggesting a warning only when an incompatible option is explicitly 
> > given in the command line.
> 
> I'm just trying to fix a bug and match how it currently works. If you want to 
> change the behaviour to give more warnings, and especially only when an 
> option is given on the command line, that's a more involved change that 
> belongs in a separate issue.

I have been kind of confused by your characterization of this as "bugfix", 
given that this does not change anything functionality-wise. I agree this PR 
can be an improvement being a failsafe mechanism if someone chooses to override 
the default option or explicitly chooses to override it in the command line. 
But I think, at least in the latter case, the user should be informed that even 
though they requested `--no-trap-after-noreturn`, we will do 
`--no-trap-after-noreturn=0` regardless.

So I'm not sure if I agree that this PR is a bugfix. I consider this as an 
improvement adding a failsafe mechanism.

> > If you grep with report_fatal_error in all target's ***TargetMachine.cpp, 
> > there are many instances of reporting that some options are not supported. 
> > (I'm not necessarily suggesting erroring out though)
> 
> Most of these are hard errors, where there's a real contradiction between two 
> requested features. Not so with TrapUnreachable and NoTrapAfterNoreturn, they 
> are more like hints or suggestions, and can be ignored without breaking 
> anything.

Didn't you provide a counterexample that `--no-trap-after-noreturn` produces 
invalid code? Then don't we have "a real contradiction"? What's your 
distinction criteria for "real contradiction" and "hints or suggestions"?


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


[clang-tools-extra] Ensure NoTrapAfterNoreturn is false for the wasm backend (PR #65876)

2023-09-24 Thread Heejin Ahn via cfe-commits

aheejin wrote:

> > Can you point out what are the unsupported options here?
> 
> All of them, they are all options that translate to TargetOptions, and they 
> do nothing for a wasm target triple: ` --trap-unreachable=false 
> --xcoff-traceback-table=true --relax-elf-relocations=false --vec-extabi=true`

I don't think these options are the same case as this PR. These are just 
non-wasm options, so they mean nothing to wasm. Wasm simply doesn't do anything 
with respect to these options and wasm is not _overriding_ them. But with this 
PR, even if a user gives `--no-trap-after-noreturn` in the command line, they 
wouldn't know that their request was silently rejected/overridden.

To say it another way, the difference is, Wasm doesn't understand 
`--xcoff-traceback-table=true` and will do nothing with respect to it. But Wasm 
understands `--no-trap-after-noreturn` and will silently reject it after this 
PR.

> > I'm suggesting a warning only when an incompatible option is explicitly 
> > given in the command line.
> 
> I'm just trying to fix a bug and match how it currently works. If you want to 
> change the behaviour to give more warnings, and especially only when an 
> option is given on the command line, that's a more involved change that 
> belongs in a separate issue.

I have been kind of confused by your characterization of this as "bugfix", 
given that this does not change anything functionality-wise. I agree this PR 
can be an improvement being a failsafe mechanism if someone chooses to override 
the default option or explicitly chooses to override it in the command line. 
But I think, at least in the latter case, the user should be informed that even 
though they requested `--no-trap-after-noreturn`, we will do 
`--no-trap-after-noreturn=0` regardless.

So I'm not sure if I agree that this PR is a bugfix. I consider this as an 
improvement adding a failsafe mechanism.

> > If you grep with report_fatal_error in all target's ***TargetMachine.cpp, 
> > there are many instances of reporting that some options are not supported. 
> > (I'm not necessarily suggesting erroring out though)
> 
> Most of these are hard errors, where there's a real contradiction between two 
> requested features. Not so with TrapUnreachable and NoTrapAfterNoreturn, they 
> are more like hints or suggestions, and can be ignored without breaking 
> anything.

Didn't you provide a counterexample that `--no-trap-after-noreturn` produces 
invalid code? Then don't we have "a real contradiction"? What's your 
distinction criteria for "real contradiction" and "hints or suggestions"?


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


[clang] [Driver] Hook up NetBSD/riscv64 support (PR #67256)

2023-09-24 Thread Brad Smith via cfe-commits

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


[clang] [Driver] Hook up NetBSD/riscv64 support (PR #67256)

2023-09-24 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/67256

>From 949ffebe8d74fd5ca27551934bd7a565022ebaa7 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 24 Sep 2023 02:29:27 -0400
Subject: [PATCH] [Driver] Hook up NetBSD/riscv64 support

---
 clang/lib/Basic/Targets.cpp|  5 +++--
 clang/lib/Driver/ToolChains/NetBSD.cpp | 13 -
 clang/test/Driver/netbsd.c | 21 +
 clang/test/Driver/netbsd.cpp   | 22 ++
 4 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 69576dbc458d9a1..bd37caf8edd4131 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -429,7 +429,6 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
 return std::make_unique(Triple, Opts);
 
   case llvm::Triple::riscv32:
-// TODO: add cases for NetBSD, RTEMS once tested.
 switch (os) {
 case llvm::Triple::FreeBSD:
   return std::make_unique>(Triple,
@@ -441,11 +440,13 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple ,
 }
 
   case llvm::Triple::riscv64:
-// TODO: add cases for NetBSD, RTEMS once tested.
 switch (os) {
 case llvm::Triple::FreeBSD:
   return std::make_unique>(Triple,
 Opts);
+case llvm::Triple::NetBSD:
+  return std::make_unique>(Triple,
+   Opts);
 case llvm::Triple::OpenBSD:
   return std::make_unique>(Triple,
 Opts);
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 88be6ea0d5e7883..50aa73d1e503365 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -216,6 +216,11 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back("elf64ppc");
 break;
 
+  case llvm::Triple::riscv64:
+CmdArgs.push_back("-m");
+CmdArgs.push_back("elf64lriscv");
+break;
+
   case llvm::Triple::sparc:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf32_sparc");
@@ -230,6 +235,9 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 break;
   }
 
+  if (ToolChain.getArch() == llvm::Triple::riscv64)
+CmdArgs.push_back("-X");
+
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
@@ -282,6 +290,7 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   case llvm::Triple::ppc:
   case llvm::Triple::ppc64:
   case llvm::Triple::ppc64le:
+  case llvm::Triple::riscv64:
   case llvm::Triple::sparc:
   case llvm::Triple::sparcv9:
   case llvm::Triple::x86:
@@ -418,6 +427,7 @@ ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() 
const {
   case llvm::Triple::ppc:
   case llvm::Triple::ppc64:
   case llvm::Triple::ppc64le:
+  case llvm::Triple::riscv64:
   case llvm::Triple::sparc:
   case llvm::Triple::sparcv9:
   case llvm::Triple::x86:
@@ -539,7 +549,8 @@ void NetBSD::addClangTargetOptions(const ArgList 
,
   getTriple().getArch() == llvm::Triple::aarch64 ||
   getTriple().getArch() == llvm::Triple::aarch64_be ||
   getTriple().getArch() == llvm::Triple::arm ||
-  getTriple().getArch() == llvm::Triple::armeb;
+  getTriple().getArch() == llvm::Triple::armeb ||
+  getTriple().getArch() == llvm::Triple::riscv64;
 
   if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
   options::OPT_fno_use_init_array, 
UseInitArrayDefault))
diff --git a/clang/test/Driver/netbsd.c b/clang/test/Driver/netbsd.c
index 67c048c6e91515f..ca895a55ef7e8cb 100644
--- a/clang/test/Driver/netbsd.c
+++ b/clang/test/Driver/netbsd.c
@@ -59,6 +59,9 @@
 // RUN: %clang --target=arm-unknown-netbsd7.0.0-eabi \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=ARM-7 %s
+// RUN: %clang --target=riscv64-unknown-netbsd \
+// RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=RISCV64 %s
 // RUN: %clang --target=sparc-unknown-netbsd \
 // RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=SPARC %s
@@ -99,6 +102,9 @@
 // RUN: %clang --target=arm-unknown-netbsd7.0.0-eabi -static \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-ARM-7 %s
+// RUN: %clang --target=riscv64-unknown-netbsd7.0.0 -static \
+// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=S-RISCV64-7 %s
 // RUN: %clang --target=sparc-unknown-netbsd7.0.0 -static \
 // RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-SPARC-7 %s
@@ -264,6 +270,14 @@
 // ARM-7:  

[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-24 Thread Fangrui Song via cfe-commits

MaskRay wrote:

I think Windows does not work likely because `ld` is absent in PATH. You need 
`-Bxxx/bin` to specify a directory that contains `ld`, but I don't remember 
whether `ld.exe` is needed instead.

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


[clang] 6876514 - Fix assertion failure mangling an unresolved template argument that

2023-09-24 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2023-09-24T11:52:58-07:00
New Revision: 68765143c6765a694d40d4c3fea43893cc025433

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

LOG: Fix assertion failure mangling an unresolved template argument that
corresponds to a parameter pack.

Fixes #67244.

Added: 


Modified: 
clang/lib/AST/ItaniumMangle.cpp
clang/test/CodeGenCXX/mangle-concept.cpp

Removed: 




diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index e7a5a6b6b8119c0..4cb1ab56a1e618a 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -5788,13 +5788,14 @@ struct CXXNameMangler::TemplateArgManglingInfo {
  "no parameter for argument");
   Param = ResolvedTemplate->getTemplateParameters()->getParam(ParamIdx);
 
-  // If we reach an expanded parameter pack whose argument isn't in pack
-  // form, that means Sema couldn't figure out which arguments belonged to
-  // it, because it contains a pack expansion. Track the expanded pack for
-  // all further template arguments until we hit that pack expansion.
+  // If we reach a parameter pack whose argument isn't in pack form, that
+  // means Sema couldn't or didn't figure out which arguments belonged to
+  // it, because it contains a pack expansion or because Sema bailed out of
+  // computing parameter / argument correspondence before this point. Track
+  // the pack as the corresponding parameter for all further template
+  // arguments until we hit a pack expansion, at which point we don't know
+  // the correspondence between parameters and arguments at all.
   if (Param->isParameterPack() && Arg.getKind() != TemplateArgument::Pack) 
{
-assert(getExpandedPackSize(Param) &&
-   "failed to form pack argument for parameter pack");
 UnresolvedExpandedPack = Param;
   }
 }

diff  --git a/clang/test/CodeGenCXX/mangle-concept.cpp 
b/clang/test/CodeGenCXX/mangle-concept.cpp
index dec26aeaeca464c..391cf09ede8555d 100644
--- a/clang/test/CodeGenCXX/mangle-concept.cpp
+++ b/clang/test/CodeGenCXX/mangle-concept.cpp
@@ -220,3 +220,11 @@ namespace test7 {
   }
   template void f();
 }
+
+namespace gh67244 {
+  template constexpr bool B = true;
+  template concept C = B;
+  template T> void f(T) {}
+  // CHECK: define {{.*}} @_ZN7gh672441fITkNS_1CIifEEiEEvT_(
+  template void f(int);
+}



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


[clang] [Driver] -include: deprecate probing .gch (PR #67084)

2023-09-24 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> Xcode is actively using this feature: the `.pch` extension is used for 
> headers that are to be precompiled, the `.pch.gch` extension is used for the 
> actual precompiled header, and Clang is expected to expand the given 
> `-include X.pch` argument into `-include-pch X.pch.gch`.
> 
> We're okay with changing the build system to explicitly pass `-include-pch 
> X.pch.gch` to the compiler, but I think it would be more prudent for Clang to 
> emit a deprecation warning for now and only remove this feature (land this 
> patch) after the next upstream release is cut.

Sounds good. Switched to a `-Wdeprecated` diagnostic.

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


[clang] [Driver] -include: deprecate probing .gch (PR #67084)

2023-09-24 Thread Fangrui Song via cfe-commits

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


[clang] [Driver] -include: deprecate probing .gch (PR #67084)

2023-09-24 Thread Fangrui Song via cfe-commits

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


[clang] [Driver] -include: do not probe .gch (PR #67084)

2023-09-24 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/67084

>From f3479f95f7c11e36de4fff5dc01bb27a02db Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Tue, 12 Sep 2023 18:31:18 -0700
Subject: [PATCH] [Driver] -include: deprecate probing .gch

`-include a.h` probes `a.h.pch` and `a.h.gch`, if not found, falls back to
`a.h`. `.pch` is the preferred extension name. Probing .gch is supposed to
provide compatibility with build systems that do
```
clang -x c-header a.h -o out/a.h.gch
clang -include out/a.h -c a.c  # out/a.h.gch is present while out/a.h is absent
```
(not sure what projects actually do this with Clang)

But it can often get in the way [^0][^1][^2] when GCC and Clang are mixed as 
the file
format is incompatible with GCC's. Let's deprecate .gch probing.
Some tests using `-include` are switched to `.pch`.
`test/PCH/pch-dir.c` shows the -Wdeprecated warning.

[^0]: 
https://discourse.llvm.org/t/how-to-have-clang-ignore-gch-directories/51835
[^1]: https://bugreports.qt.io/browse/QTCREATORBUG-22427
[^2]: https://gitlab.kitware.com/cmake/cmake/-/issues/22081
---
 clang/docs/ReleaseNotes.rst | 2 ++
 clang/include/clang/Basic/DiagnosticDriverKinds.td  | 3 +++
 clang/lib/Driver/ToolChains/Clang.cpp   | 1 +
 .../Inputs/modules-pch-common-submodule/cdb_pch.json| 2 +-
 .../Inputs/modules-pch-common-via-submodule/cdb_pch.json| 2 +-
 clang/test/ClangScanDeps/Inputs/modules-pch/cdb_pch.json| 2 +-
 clang/test/ClangScanDeps/modules-pch-common-submodule.c | 2 +-
 clang/test/ClangScanDeps/modules-pch-common-via-submodule.c | 2 +-
 clang/test/ClangScanDeps/modules-pch.c  | 6 +++---
 clang/test/Index/cindex-from-source.m   | 2 +-
 clang/test/PCH/pch-dir.c| 2 ++
 clang/test/SemaCXX/warn-unused-local-typedef-serialize.cpp  | 2 +-
 12 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8b5e48d1758d96d..9dbc0f99a0407ad 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -43,6 +43,8 @@ C/C++ Language Potentially Breaking Changes
 
 - The default extension name for PCH generation (``-c -xc-header`` and ``-c
   -xc++-header``) is now ``.pch`` instead of ``.gch``.
+- ``-include a.h`` probing ``a.h.gch`` is deprecated. Change the extension name
+  to ``.pch`` or use ``-include-pch a.h.gch``.
 
 C++ Specific Potentially Breaking Changes
 -
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 61ac792d6fda46a..839e7930b51efcd 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -431,6 +431,9 @@ def warn_drv_overriding_option : Warning<
 def warn_drv_treating_input_as_cxx : Warning<
   "treating '%0' input as '%1' when in C++ mode, this behavior is deprecated">,
   InGroup;
+def warn_drv_include_probe_gch : Warning<
+  "'%0' probing .gch is deprecated. Use '-include-pch %1' or switch to .pch 
instead">,
+  InGroup;
 def warn_drv_pch_not_first_include : Warning<
   "precompiled header '%0' was ignored because '%1' is not first '-include'">;
 def warn_missing_sysroot : Warning<"no such sysroot directory: '%0'">,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 40e60585a8b8d6e..feb69fd5092caab 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1284,6 +1284,7 @@ void Clang::AddPreprocessingOptions(Compilation , const 
JobAction ,
 llvm::sys::path::replace_extension(P, "gch");
 if (D.getVFS().exists(P)) {
   FoundPCH = true;
+  D.Diag(diag::warn_drv_include_probe_gch) << A->getAsString(Args) << 
P;
 }
   }
 
diff --git 
a/clang/test/ClangScanDeps/Inputs/modules-pch-common-submodule/cdb_pch.json 
b/clang/test/ClangScanDeps/Inputs/modules-pch-common-submodule/cdb_pch.json
index dc2fc550b019194..f27d24045889a03 100644
--- a/clang/test/ClangScanDeps/Inputs/modules-pch-common-submodule/cdb_pch.json
+++ b/clang/test/ClangScanDeps/Inputs/modules-pch-common-submodule/cdb_pch.json
@@ -1,7 +1,7 @@
 [
   {
 "directory": "DIR",
-"command": "clang -x c-header DIR/pch.h -fmodules -gmodules 
-fimplicit-module-maps -fmodules-cache-path=DIR/cache -o DIR/pch.h.gch",
+"command": "clang -x c-header DIR/pch.h -fmodules -gmodules 
-fimplicit-module-maps -fmodules-cache-path=DIR/cache -o DIR/pch.h.pch",
 "file": "DIR/pch.h"
   }
 ]
diff --git 
a/clang/test/ClangScanDeps/Inputs/modules-pch-common-via-submodule/cdb_pch.json 
b/clang/test/ClangScanDeps/Inputs/modules-pch-common-via-submodule/cdb_pch.json
index dc2fc550b019194..f27d24045889a03 100644
--- 
a/clang/test/ClangScanDeps/Inputs/modules-pch-common-via-submodule/cdb_pch.json
+++ 

[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-09-24 Thread via cfe-commits

https://github.com/goldsteinn updated 
https://github.com/llvm/llvm-project/pull/67166

>From a2e343dab6e698621a9121c767d2dca285d27b5d Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Fri, 22 Sep 2023 08:21:21 -0500
Subject: [PATCH 1/9] [InstSimplify] Add tests for simplify `llvm.ptrmask`; NFC

Differential Revision: https://reviews.llvm.org/D156632
---
 llvm/test/Transforms/InstSimplify/ptrmask.ll | 163 +++
 1 file changed, 163 insertions(+)
 create mode 100644 llvm/test/Transforms/InstSimplify/ptrmask.ll

diff --git a/llvm/test/Transforms/InstSimplify/ptrmask.ll 
b/llvm/test/Transforms/InstSimplify/ptrmask.ll
new file mode 100644
index 000..1b85d8863fa79b2
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/ptrmask.ll
@@ -0,0 +1,163 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 2
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
+
+declare ptr @llvm.ptrmask.p0.i32(ptr, i32)
+declare ptr @llvm.ptrmask.p0.i64(ptr, i64)
+
+define ptr @ptrmask_simplify_poison_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_poison_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 
poison)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 poison)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_undef_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_undef_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr [[P]], i32 
undef)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i32(ptr %p, i32 undef)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_0_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_0_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 0)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 0)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_1s_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_1s_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 -1)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 -1)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_1s_mask_i32_fail(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_1s_mask_i32_fail
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr [[P]], i32 -1)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i32(ptr %p, i32 -1)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_poison_ptr(i64 %m) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_poison_ptr
+; CHECK-SAME: (i64 [[M:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr poison, i64 
[[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr poison, i64 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_undef_ptr(i32 %m) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_undef_ptr
+; CHECK-SAME: (i32 [[M:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr undef, i32 
[[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i32(ptr undef, i32 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_null_ptr(i64 %m) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_null_ptr
+; CHECK-SAME: (i64 [[M:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr null, i64 [[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr null, i64 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_ptrmask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_ptrmask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[M:%.*]] = ptrtoint ptr [[P]] to i64
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 
[[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %m = ptrtoint ptr %p to i64
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_ptrmask_i32_fail(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_ptrmask_i32_fail
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[M:%.*]] = ptrtoint ptr [[P]] to i32
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr [[P]], i32 
[[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %m = ptrtoint ptr %p to i32
+  %r = call ptr @llvm.ptrmask.p0.i32(ptr %p, i32 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_aligned_unused(ptr align 64 %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_aligned_unused
+; CHECK-SAME: (ptr align 64 [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 -64)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 -64)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_aligned_unused_i32_fail(ptr align 64 %p) {
+; CHECK-LABEL: define ptr 

[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-09-24 Thread via cfe-commits


@@ -1984,10 +1984,30 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst 
) {
 //-> (ptrmask p, (and A, B))
 if (match(Op0, m_OneUse(m_Intrinsic(
m_Value(InnerPtr), m_Value(InnerMask) {
+  // See if combining the two masks is free.
+  bool OkayToMerge = InnerMask->getType() == Op1->getType();
+  bool NeedsNew = false;
+  if (!OkayToMerge) {
+if (match(InnerMask, m_ImmConstant())) {
+  InnerMask = Builder.CreateZExtOrTrunc(InnerMask, Op1->getType());
+  OkayToMerge = true;
+} else if (match(Op1, m_ImmConstant())) {
+  Op1 = Builder.CreateZExtOrTrunc(Op1, InnerMask->getType());
+  OkayToMerge = true;
+  // Need to create a new one here, as the intrinsic id needs to 
change.
+  NeedsNew = true;
+}
+  }

goldsteinn wrote:

Done (only canonicalize constants, could do all masks though).

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


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-09-24 Thread via cfe-commits


@@ -898,6 +910,53 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, 
APInt DemandedMask,
 }
 break;
   }
+  case Intrinsic::ptrmask: {
+// Fail loudly in case this is ever changed.
+// Likely not much needs to be changed here to support vector types.
+assert(!I->getOperand(0)->getType()->isVectorTy() &&
+   !I->getOperand(1)->getType()->isVectorTy() &&
+   "These simplifications where written at a time when ptrmask did 
"
+   "not support vector types and may not work for vectors");
+
+unsigned MaskWidth = 
I->getOperand(1)->getType()->getScalarSizeInBits();
+RHSKnown = KnownBits(MaskWidth);
+// If either the LHS or the RHS are Zero, the result is zero.
+if (SimplifyDemandedBits(I, 0, DemandedMask, LHSKnown, Depth + 1) ||
+SimplifyDemandedBits(
+I, 1, (DemandedMask & ~LHSKnown.Zero).zextOrTrunc(MaskWidth),
+RHSKnown, Depth + 1))
+  return I;
+
+RHSKnown = RHSKnown.zextOrTrunc(BitWidth);
+assert(!RHSKnown.hasConflict() && "Bits known to be one AND zero?");
+assert(!LHSKnown.hasConflict() && "Bits known to be one AND zero?");
+
+Known = LHSKnown & RHSKnown;
+KnownBitsComputed = DemandedMask.isAllOnes();
+
+// If the client is only demanding bits we know to be zero, return
+// `llvm.ptrmask(p, 0)`. We can't return `null` here due to pointer
+// provenance, but making the mask zero will be easily optimizable in
+// the backend.
+if (DemandedMask.isSubsetOf(Known.Zero))
+  return replaceOperand(
+  *I, 1, Constant::getNullValue(I->getOperand(1)->getType()));

goldsteinn wrote:

Added proper tests.

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


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-09-24 Thread via cfe-commits


@@ -898,6 +910,53 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, 
APInt DemandedMask,
 }
 break;
   }
+  case Intrinsic::ptrmask: {
+// Fail loudly in case this is ever changed.
+// Likely not much needs to be changed here to support vector types.
+assert(!I->getOperand(0)->getType()->isVectorTy() &&
+   !I->getOperand(1)->getType()->isVectorTy() &&
+   "These simplifications where written at a time when ptrmask did 
"
+   "not support vector types and may not work for vectors");
+
+unsigned MaskWidth = 
I->getOperand(1)->getType()->getScalarSizeInBits();
+RHSKnown = KnownBits(MaskWidth);
+// If either the LHS or the RHS are Zero, the result is zero.
+if (SimplifyDemandedBits(I, 0, DemandedMask, LHSKnown, Depth + 1) ||
+SimplifyDemandedBits(
+I, 1, (DemandedMask & ~LHSKnown.Zero).zextOrTrunc(MaskWidth),
+RHSKnown, Depth + 1))
+  return I;
+
+RHSKnown = RHSKnown.zextOrTrunc(BitWidth);
+assert(!RHSKnown.hasConflict() && "Bits known to be one AND zero?");
+assert(!LHSKnown.hasConflict() && "Bits known to be one AND zero?");
+
+Known = LHSKnown & RHSKnown;
+KnownBitsComputed = DemandedMask.isAllOnes();

goldsteinn wrote:

At the moment sure, but could imagine otherwise?

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


[clang] [Driver] Some adjustments for relocatable linking on OpenBSD (PR #67254)

2023-09-24 Thread Brad Smith via cfe-commits

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


[clang] [Driver] Some adjustments for reloctable linking on OpenBSD (PR #67254)

2023-09-24 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/67254

>From fdcdea6353a7931a9e57dd3d0b4f6cf1b35085c3 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 24 Sep 2023 00:20:53 -0400
Subject: [PATCH] [Driver] Some adjustments for relocatable linking on OpenBSD

---
 clang/lib/Driver/ToolChains/OpenBSD.cpp | 8 +---
 clang/test/Driver/openbsd.c | 4 +++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index 91fe3837b81..8d88379ef4c10e7 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -121,6 +121,7 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   bool Profiling = Args.hasArg(options::OPT_pg);
   bool Pie = Args.hasArg(options::OPT_pie);
   bool Nopie = Args.hasArg(options::OPT_nopie);
+  bool Relocatable = Args.hasArg(options::OPT_r);
 
   // Silence warning for "clang -g foo.o -o foo"
   Args.ClaimAllArgs(options::OPT_g_Group);
@@ -138,7 +139,7 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   else if (Arch == llvm::Triple::mips64el)
 CmdArgs.push_back("-EL");
 
-  if (!Args.hasArg(options::OPT_nostdlib) && !Shared) {
+  if (!Args.hasArg(options::OPT_nostdlib) && !Shared && !Relocatable) {
 CmdArgs.push_back("-e");
 CmdArgs.push_back("__start");
   }
@@ -149,10 +150,11 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   } else {
 if (Args.hasArg(options::OPT_rdynamic))
   CmdArgs.push_back("-export-dynamic");
-CmdArgs.push_back("-Bdynamic");
+if (!Relocatable)
+  CmdArgs.push_back("-Bdynamic");
 if (Shared) {
   CmdArgs.push_back("-shared");
-} else if (!Args.hasArg(options::OPT_r)) {
+} else if (!Relocatable) {
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/usr/libexec/ld.so");
 }
diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index 05d290a309c40c0..a8db20200cd473d 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -36,10 +36,12 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64-LD %s
 // RUN: %clang --target=mips64el-unknown-openbsd -### %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s
-// CHECK-LD-R: "-r"
+// CHECK-LD-R-NOT: "-e" "__start"
+// CHECK-LD-R-NOT: "-Bdynamic"
 // CHECK-LD-R-NOT: "-dynamic-linker"
 // CHECK-LD-R-NOT: "-l
 // CHECK-LD-R-NOT: crt{{[^./\\]+}}.o
+// CHECK-LD-R: "-r"
 // CHECK-LD-S: "-cc1" "-triple" "i686-pc-openbsd"
 // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" 
"-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" 
"-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" 
"{{.*}}crtend.o"
 // CHECK-LD-T: "-cc1" "-triple" "i686-pc-openbsd"

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


[clang] [Driver] Hook up NetBSD/riscv64 support (PR #67256)

2023-09-24 Thread Fangrui Song via cfe-commits


@@ -124,6 +130,14 @@
 // AARCH64_BE-7: "-lm" "-lc"
 // AARCH64_BE-7: "{{.*}}/usr/lib{{/|}}crtend.o" 
"{{.*}}/usr/lib{{/|}}crtn.o"
 
+// RISCV64: "-cc1" "-triple" "riscv64-unknown-netbsd"
+// RISCV64: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"

MaskRay wrote:

Use `-SAME:` for continuation lines for new tests:)

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


[clang] [Driver] Hook up NetBSD/riscv64 support (PR #67256)

2023-09-24 Thread Fangrui Song via cfe-commits

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


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


[clang] [Clang][CodeGen] Add __builtin_bcopy (PR #67130)

2023-09-24 Thread Carlos Eduardo Seo via cfe-commits

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


[clang] 7523550 - [Clang][CodeGen] Add __builtin_bcopy (#67130)

2023-09-24 Thread via cfe-commits

Author: Carlos Eduardo Seo
Date: 2023-09-24T11:58:14-03:00
New Revision: 7523550853dbb0c66c17f424d60201bde4ec3bb7

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

LOG: [Clang][CodeGen] Add __builtin_bcopy (#67130)

Add __builtin_bcopy to the list of GNU builtins. This was causing a
series of test failures in glibc.

Adjust the tests to reflect the changes in codegen.

Fixes #51409.
Fixes #63065.

Added: 


Modified: 
clang/include/clang/Basic/Builtins.def
clang/lib/AST/Decl.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/Analysis/bstring.c
clang/test/Analysis/security-syntax-checks.m
clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-macros.c

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 586dcf05170eb58..6ea8484606cfd5d 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -565,7 +565,7 @@ BUILTIN(__builtin_va_copy, "vAA", "n")
 BUILTIN(__builtin_stdarg_start, "vA.", "nt")
 BUILTIN(__builtin_assume_aligned, "v*vC*z.", "nctE")
 BUILTIN(__builtin_bcmp, "ivC*vC*z", "FnE")
-BUILTIN(__builtin_bcopy, "vv*v*z", "n")
+BUILTIN(__builtin_bcopy, "vvC*v*z", "nF")
 BUILTIN(__builtin_bzero, "vv*z", "nF")
 BUILTIN(__builtin_free, "vv*", "nF")
 BUILTIN(__builtin_malloc, "v*z", "nF")
@@ -1161,6 +1161,7 @@ LIBBUILTIN(strndup, "c*cC*z", "f", STRING_H, 
ALL_GNU_LANGUAGES)
 LIBBUILTIN(index, "c*cC*i",   "f", STRINGS_H, ALL_GNU_LANGUAGES)
 LIBBUILTIN(rindex, "c*cC*i",  "f", STRINGS_H, ALL_GNU_LANGUAGES)
 LIBBUILTIN(bzero, "vv*z", "f", STRINGS_H, ALL_GNU_LANGUAGES)
+LIBBUILTIN(bcopy, "vvC*v*z",  "f", STRINGS_H, ALL_GNU_LANGUAGES)
 LIBBUILTIN(bcmp, "ivC*vC*z",  "fE",STRINGS_H, ALL_GNU_LANGUAGES)
 // In some systems str[n]casejmp is a macro that expands to _str[n]icmp.
 // We undefine then here to avoid wrong name.

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 08ae2087cfe70eb..82d1ddadeac92ba 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4356,6 +4356,10 @@ unsigned FunctionDecl::getMemoryFunctionKind() const {
   case Builtin::BIbzero:
 return Builtin::BIbzero;
 
+  case Builtin::BI__builtin_bcopy:
+  case Builtin::BIbcopy:
+return Builtin::BIbcopy;
+
   case Builtin::BIfree:
 return Builtin::BIfree;
 
@@ -4387,6 +4391,8 @@ unsigned FunctionDecl::getMemoryFunctionKind() const {
 return Builtin::BIstrlen;
   if (FnInfo->isStr("bzero"))
 return Builtin::BIbzero;
+  if (FnInfo->isStr("bcopy"))
+return Builtin::BIbcopy;
 } else if (isInStdNamespace()) {
   if (FnInfo->isStr("free"))
 return Builtin::BIfree;

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 4a73403cb3b9a72..c175f274319b8c4 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3703,6 +3703,20 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false);
 return RValue::get(nullptr);
   }
+
+  case Builtin::BIbcopy:
+  case Builtin::BI__builtin_bcopy: {
+Address Src = EmitPointerWithAlignment(E->getArg(0));
+Address Dest = EmitPointerWithAlignment(E->getArg(1));
+Value *SizeVal = EmitScalarExpr(E->getArg(2));
+EmitNonNullArgCheck(RValue::get(Src.getPointer()), E->getArg(0)->getType(),
+E->getArg(0)->getExprLoc(), FD, 0);
+EmitNonNullArgCheck(RValue::get(Dest.getPointer()), 
E->getArg(1)->getType(),
+E->getArg(1)->getExprLoc(), FD, 0);
+Builder.CreateMemMove(Dest, Src, SizeVal, false);
+return RValue::get(Dest.getPointer());
+  }
+
   case Builtin::BImemcpy:
   case Builtin::BI__builtin_memcpy:
   case Builtin::BImempcpy:

diff  --git a/clang/test/Analysis/bstring.c b/clang/test/Analysis/bstring.c
index a7c7bdb23683e76..5d86241a4ac9a81 100644
--- a/clang/test/Analysis/bstring.c
+++ b/clang/test/Analysis/bstring.c
@@ -483,8 +483,7 @@ int memcmp8(char *a, size_t n) {
 //===--===
 
 #define bcopy BUILTIN(bcopy)
-// __builtin_bcopy is not defined with const in Builtins.def.
-void bcopy(/*const*/ void *s1, void *s2, size_t n);
+void bcopy(const void *s1, void *s2, size_t n);
 
 
 void bcopy0 (void) {

diff  --git a/clang/test/Analysis/security-syntax-checks.m 
b/clang/test/Analysis/security-syntax-checks.m
index ab6a5311f49efad..154f0c1bae427c0 100644
--- a/clang/test/Analysis/security-syntax-checks.m
+++ b/clang/test/Analysis/security-syntax-checks.m
@@ -57,9 +57,9 @@ int test_bcmp(void *a, void *b, size_t n) {
 }
 
 // Obsolete function bcopy
-void 

[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-09-24 Thread via cfe-commits


@@ -6397,6 +6397,48 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value 
*Op0, Value *Op1,
   return Constant::getNullValue(ReturnType);
 break;
   }
+  case Intrinsic::ptrmask: {
+// Fail loudly in case this is ever changed.
+// TODO: If vector types are supported the logic that checks if the mask is
+// useless should be updated to use generic constants.
+assert(!Op0->getType()->isVectorTy() && !Op1->getType()->isVectorTy() &&
+   "These simplifications where written at a time when ptrmask did not 
"
+   "support vector types and may not work for vectors");
+
+// NOTE: We can't apply these simplifications based on the value of Op1
+// because we need to preserve provenance.
+if (isa(Op0))
+  return Op0;
+
+if (Q.isUndefValue(Op0))
+  return Constant::getNullValue(Op0->getType());
+
+if (match(Op0, m_Zero()))
+  return Constant::getNullValue(Op0->getType());
+
+if (Op1->getType()->getScalarSizeInBits() ==
+Q.DL.getPointerTypeSizeInBits(Op0->getType())) {
+  if (match(Op1, m_PtrToInt(m_Specific(Op0
+return Op0;
+
+  // TODO: We may have attributes assosiated with the return value of the

goldsteinn wrote:

How about "TODO(unimportant)" if someone is searching for why attributes are 
being lost, may help them debug.

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


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-09-24 Thread via cfe-commits


@@ -6397,6 +6397,48 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value 
*Op0, Value *Op1,
   return Constant::getNullValue(ReturnType);
 break;
   }
+  case Intrinsic::ptrmask: {
+// Fail loudly in case this is ever changed.
+// TODO: If vector types are supported the logic that checks if the mask is
+// useless should be updated to use generic constants.
+assert(!Op0->getType()->isVectorTy() && !Op1->getType()->isVectorTy() &&
+   "These simplifications where written at a time when ptrmask did not 
"
+   "support vector types and may not work for vectors");

goldsteinn wrote:

I guess my feeling is since its untested, we shouldn't assume it works. Seems 
lower cost to just delete these lines when/if adding vec support than to 
potentially leave buggy codes.

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


[clang] Extension: allow recursive macros (PR #65851)

2023-09-24 Thread via cfe-commits

kelbon wrote:

Version with `__THIS_MACRO__` instead of new preprocessor directive is ready, 
so actual examples are like

```C++
#define reverse(head, ...) __VA_OPT__(__THIS_MACRO__(__VA_ARGS__) , ) head
```
`__THIS_MACRO__` behaves exactly as macro name(`reverse` in this case), but its 
allowed to be expanded recursively

@cor3ntin i dont understand what github wants from me (changes requested)

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


[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)

2023-09-24 Thread Yingwei Zheng via cfe-commits

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


[clang] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)

2023-09-24 Thread Yingwei Zheng via cfe-commits

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


  1   2   >