[clang] b4b35a5 - [clang] [unittest] Add a test for Generic_GCC::GCCVersion::Parse (#69078)

2023-10-18 Thread via cfe-commits

Author: Martin Storsjö
Date: 2023-10-18T12:36:27+03:00
New Revision: b4b35a5d2b4ee26bf79b8a92715dd200f3f9cc49

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

LOG: [clang] [unittest] Add a test for Generic_GCC::GCCVersion::Parse (#69078)

This adds actual test cases for all the cases that are listed in a code
comment in the implementation of this function; having such test
coverage eases doing further modifications to the function.

Added: 
clang/unittests/Driver/GCCVersionTest.cpp

Modified: 
clang/unittests/Driver/CMakeLists.txt

Removed: 




diff  --git a/clang/unittests/Driver/CMakeLists.txt 
b/clang/unittests/Driver/CMakeLists.txt
index e37c158d7137a88..752037f78fb147d 100644
--- a/clang/unittests/Driver/CMakeLists.txt
+++ b/clang/unittests/Driver/CMakeLists.txt
@@ -9,6 +9,7 @@ set(LLVM_LINK_COMPONENTS
 add_clang_unittest(ClangDriverTests
   DistroTest.cpp
   DXCModeTest.cpp
+  GCCVersionTest.cpp
   ToolChainTest.cpp
   ModuleCacheTest.cpp
   MultilibBuilderTest.cpp

diff  --git a/clang/unittests/Driver/GCCVersionTest.cpp 
b/clang/unittests/Driver/GCCVersionTest.cpp
new file mode 100644
index 000..9ae335bca77dc12
--- /dev/null
+++ b/clang/unittests/Driver/GCCVersionTest.cpp
@@ -0,0 +1,52 @@
+//===- unittests/Driver/GCCVersionTest.cpp --- GCCVersion parser tests 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Unit tests for Generic_GCC::GCCVersion
+//
+//===--===//
+
+#include "../../lib/Driver/ToolChains/Gnu.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace clang::driver;
+
+namespace {
+
+struct VersionParseTest {
+  std::string Text;
+
+  int Major, Minor, Patch;
+  std::string MajorStr, MinorStr, PatchSuffix;
+};
+
+const VersionParseTest TestCases[] = {
+{"5", 5, -1, -1, "5", "", ""},
+{"4.4", 4, 4, -1, "4", "4", ""},
+{"4.4-patched", 4, 4, -1, "4", "4", "-patched"},
+{"4.4.0", 4, 4, 0, "4", "4", ""},
+{"4.4.x", 4, 4, -1, "4", "4", ""},
+{"4.4.2-rc4", 4, 4, 2, "4", "4", "-rc4"},
+{"4.4.x-patched", 4, 4, -1, "4", "4", ""},
+{"not-a-version", -1, -1, -1, "", "", ""},
+};
+
+TEST(GCCVersionTest, Parse) {
+  for (const auto &TC : TestCases) {
+auto V = toolchains::Generic_GCC::GCCVersion::Parse(TC.Text);
+EXPECT_EQ(V.Text, TC.Text);
+EXPECT_EQ(V.Major, TC.Major);
+EXPECT_EQ(V.Minor, TC.Minor);
+EXPECT_EQ(V.Patch, TC.Patch);
+EXPECT_EQ(V.MajorStr, TC.MajorStr);
+EXPECT_EQ(V.MinorStr, TC.MinorStr);
+EXPECT_EQ(V.PatchSuffix, TC.PatchSuffix);
+  }
+}
+
+} // end anonymous namespace



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


[clang] [clang] [unittest] Add a test for Generic_GCC::GCCVersion::Parse (PR #69078)

2023-10-18 Thread Martin Storsjö via cfe-commits

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


[clang] [clang] [Gnu] Improve GCCVersion parsing to match versions such as "10-win32" (PR #69079)

2023-10-18 Thread Martin Storsjö via cfe-commits

https://github.com/mstorsjo updated 
https://github.com/llvm/llvm-project/pull/69079

From 468befbb3eeaa0a23b001141976108157608e11d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Sat, 14 Oct 2023 00:55:18 +0300
Subject: [PATCH] [clang] [Gnu] Improve GCCVersion parsing to match versions
 such as "10-win32"

In earlier GCC versions, the Debian/Ubuntu provided mingw toolchains
were packaged in /usr/lib/gcc/ with version strings such
as "5.3-win32", which were matched and found since
6afcd64eb65fca233a7b173f88cffb2c2c9c114c. However in recent versions,
they have stopped including the minor version number and only
have version strings such as "10-win32" and "10-posix".

Generalize the parsing code to tolerate the patch suffix to be
present on a version number with only a major number.

Refactor the string parsing code to highlight the overall structure
of the parsing. This implementation should yield the same result
as before, except for when there's only one segment and it has
trailing, non-number contents.

This allows Clang to find the GCC libraries and headers in
Debian/Ubuntu provided MinGW cross compilers.
---
 clang/lib/Driver/ToolChains/Gnu.cpp   | 82 +++
 clang/unittests/Driver/GCCVersionTest.cpp |  1 +
 2 files changed, 55 insertions(+), 28 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index cdd911af9a73361..e6f94836c4110a1 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2007,45 +2007,71 @@ Generic_GCC::GCCVersion 
Generic_GCC::GCCVersion::Parse(StringRef VersionText) {
   std::pair First = VersionText.split('.');
   std::pair Second = First.second.split('.');
 
-  GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""};
-  if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0)
-return BadVersion;
-  GoodVersion.MajorStr = First.first.str();
-  if (First.second.empty())
-return GoodVersion;
+  StringRef MajorStr = First.first;
   StringRef MinorStr = Second.first;
-  if (Second.second.empty()) {
-if (size_t EndNumber = MinorStr.find_first_not_of("0123456789")) {
-  GoodVersion.PatchSuffix = std::string(MinorStr.substr(EndNumber));
-  MinorStr = MinorStr.slice(0, EndNumber);
-}
-  }
-  if (MinorStr.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0)
-return BadVersion;
-  GoodVersion.MinorStr = MinorStr.str();
+  StringRef PatchStr = Second.second;
 
-  // First look for a number prefix and parse that if present. Otherwise just
-  // stash the entire patch string in the suffix, and leave the number
-  // unspecified. This covers versions strings such as:
-  //   5(handled above)
+  GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""};
+
+  // Parse version number strings such as:
+  //   5
   //   4.4
   //   4.4-patched
   //   4.4.0
   //   4.4.x
   //   4.4.2-rc4
   //   4.4.x-patched
-  // And retains any patch number it finds.
-  StringRef PatchText = Second.second;
-  if (!PatchText.empty()) {
-if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) {
-  // Try to parse the number and any suffix.
-  if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) ||
-  GoodVersion.Patch < 0)
-return BadVersion;
-  GoodVersion.PatchSuffix = std::string(PatchText.substr(EndNumber));
+  //   10-win32
+  // Split on '.', handle 1, 2 or 3 such segments. Each segment must contain
+  // purely a number, except for the last one, where a non-number suffix
+  // is stored in PatchSuffix. The third segment is allowed to not contain
+  // a number at all.
+
+  auto HandleLastNumber = [&](StringRef Segment, int &Number,
+  std::string &OutStr) -> bool {
+// Look for a number prefix and parse that, and split out any trailing
+// string into GoodVersion.PatchSuffix.
+
+if (size_t EndNumber = Segment.find_first_not_of("0123456789")) {
+  StringRef NumberStr = Segment.slice(0, EndNumber);
+  if (NumberStr.getAsInteger(10, Number) || Number < 0)
+return false;
+  OutStr = NumberStr;
+  GoodVersion.PatchSuffix = Segment.substr(EndNumber);
+  return true;
 }
+return false;
+  };
+  auto HandleNumber = [](StringRef Segment, int &Number) -> bool {
+if (Segment.getAsInteger(10, Number) || Number < 0)
+  return false;
+return true;
+  };
+
+  if (MinorStr.empty()) {
+// If no minor string, major is the last segment
+if (!HandleLastNumber(MajorStr, GoodVersion.Major, GoodVersion.MajorStr))
+  return BadVersion;
+return GoodVersion;
+  } else {
+if (!HandleNumber(MajorStr, GoodVersion.Major))
+  return BadVersion;
+GoodVersion.MajorStr = MajorStr;
+  }
+  if (PatchStr.empty()) {
+// If no patch string, minor is the last segment
+if (!HandleLastNumber(MinorStr, GoodVersion.Minor, GoodVersion.MinorStr))
+ 

[clang] [clang] [Gnu] Improve GCCVersion parsing to match versions such as "10-win32" (PR #69079)

2023-10-18 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

The prerequisite to this PR has been merged now.

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


[clang] 675231e - [SVE ACLE] Allow default zero initialisation for svcount_t. (#69321)

2023-10-18 Thread via cfe-commits

Author: Paul Walker
Date: 2023-10-18T10:40:07+01:00
New Revision: 675231eb09ca37a8b76f748c0b73a1e26604ff20

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

LOG: [SVE ACLE] Allow default zero initialisation for svcount_t. (#69321)

This matches the behaviour of the other SVE ACLE types.

Added: 


Modified: 
clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/IR/Type.cpp
llvm/test/CodeGen/AArch64/sve-zeroinit.ll

Removed: 




diff  --git a/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp 
b/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
index 2088e80acfc80f4..464275f164c2a54 100644
--- a/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
+++ b/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
@@ -55,6 +55,7 @@
 // CHECK-NEXT:[[B8:%.*]] = alloca , align 2
 // CHECK-NEXT:[[B8X2:%.*]] = alloca , align 2
 // CHECK-NEXT:[[B8X4:%.*]] = alloca , align 2
+// CHECK-NEXT:[[CNT:%.*]] = alloca target("aarch64.svcount"), align 2
 // CHECK-NEXT:store  zeroinitializer, ptr [[S8]], align 
16
 // CHECK-NEXT:store  zeroinitializer, ptr [[S16]], align 
16
 // CHECK-NEXT:store  zeroinitializer, ptr [[S32]], align 
16
@@ -106,6 +107,7 @@
 // CHECK-NEXT:store  zeroinitializer, ptr [[B8]], align 2
 // CHECK-NEXT:store  zeroinitializer, ptr [[B8X2]], 
align 2
 // CHECK-NEXT:store  zeroinitializer, ptr [[B8X4]], 
align 2
+// CHECK-NEXT:store target("aarch64.svcount") zeroinitializer, ptr 
[[CNT]], align 2
 // CHECK-NEXT:ret void
 //
 void test_locals(void) {
@@ -164,6 +166,8 @@ void test_locals(void) {
   __SVBool_t b8{};
   __clang_svboolx2_t b8x2{};
   __clang_svboolx4_t b8x4{};
+
+  __SVCount_t cnt{};
 }
 
 // CHECK-LABEL: define dso_local void @_Z12test_copy_s8u10__SVInt8_t
@@ -879,3 +883,17 @@ void test_copy_b8x2(__clang_svboolx2_t a) {
 void test_copy_b8x4(__clang_svboolx4_t a) {
   __clang_svboolx4_t b{a};
 }
+
+// CHECK-LABEL: define dso_local void @_Z13test_copy_cntu11__SVCount_t
+// CHECK-SAME: (target("aarch64.svcount") [[A:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca target("aarch64.svcount"), align 2
+// CHECK-NEXT:[[B:%.*]] = alloca target("aarch64.svcount"), align 2
+// CHECK-NEXT:store target("aarch64.svcount") [[A]], ptr [[A_ADDR]], align 
2
+// CHECK-NEXT:[[TMP0:%.*]] = load target("aarch64.svcount"), ptr 
[[A_ADDR]], align 2
+// CHECK-NEXT:store target("aarch64.svcount") [[TMP0]], ptr [[B]], align 2
+// CHECK-NEXT:ret void
+//
+void test_copy_cnt(__SVCount_t a) {
+  __SVCount_t b{a};
+}

diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp 
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 4bb0ba6f083109b..eabc76334fae1f2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1738,6 +1738,12 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value 
*V) {
 if (const auto *NC = dyn_cast(C))
   return getValue(NC->getGlobalValue());
 
+if (VT == MVT::aarch64svcount) {
+  assert(C->isNullValue() && "Can only zero this target type!");
+  return DAG.getNode(ISD::BITCAST, getCurSDLoc(), VT,
+ DAG.getConstant(0, getCurSDLoc(), MVT::nxv16i1));
+}
+
 VectorType *VecTy = cast(V->getType());
 
 // Now that we know the number and type of the elements, get that number of

diff  --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 97febcd99b4114f..006278d16484c1c 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -841,7 +841,8 @@ static TargetTypeInfo getTargetTypeInfo(const TargetExtType 
*Ty) {
 
   // Opaque types in the AArch64 name space.
   if (Name == "aarch64.svcount")
-return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16));
+return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16),
+  TargetExtType::HasZeroInit);
 
   return TargetTypeInfo(Type::getVoidTy(C));
 }

diff  --git a/llvm/test/CodeGen/AArch64/sve-zeroinit.ll 
b/llvm/test/CodeGen/AArch64/sve-zeroinit.ll
index c436bb7f822b7a3..eab39d0ef402526 100644
--- a/llvm/test/CodeGen/AArch64/sve-zeroinit.ll
+++ b/llvm/test/CodeGen/AArch64/sve-zeroinit.ll
@@ -86,3 +86,10 @@ define  @test_zeroinit_16xi1() {
 ; CHECK-NEXT:  ret
   ret  zeroinitializer
 }
+
+define target("aarch64.svcount") @test_zeroinit_svcount() 
"target-features"="+sme2" {
+; CHECK-LABEL: test_zeroinit_svcount
+; CHECK:   pfalse p0.b
+; CHECK-NEXT:  ret
+  ret target("aarch64.svcount") zeroinitializer
+}



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

[clang] [SVE ACLE] Allow default zero initialisation for svcount_t. (PR #69321)

2023-10-18 Thread Paul Walker via cfe-commits

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


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-18 Thread Rainer Orth via cfe-commits


@@ -2,8 +2,9 @@
 ! invocation. These libraries are added on top of other standard runtime
 ! libraries that the Clang driver will include.
 
-! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
+! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,UNIX

rorth wrote:

Done: since I'd already touched almost half the instances, I changed them all 
for consistency.

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


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-18 Thread Rainer Orth via cfe-commits


@@ -21,12 +22,12 @@
 !   run on any other platform, such as Windows that use a .exe
 !   suffix. Clang's driver will try to resolve the path to the ld
 !   executable and may find the GNU linker from MinGW or Cygwin.
-! GNU-LABEL:  "{{.*}}ld{{(\.exe)?}}"
-! GNU-SAME: "[[object_file]]"
-! GNU-SAME: -lFortran_main
-! GNU-SAME: -lFortranRuntime
-! GNU-SAME: -lFortranDecimal
-! GNU-SAME: -lm
+! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
+! UNIX-SAME: "[[object_file]]"
+! UNIX-SAME: -lFortran_main

rorth wrote:

Right: they fit nicely even with the double quotes.  To avoid swamping the 
patch with unrelated changes, I've only adjusted the `UNIX` case.

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


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-18 Thread Rainer Orth via cfe-commits

https://github.com/rorth updated https://github.com/llvm/llvm-project/pull/65644

>From 31bdd3477d9f54996b71584598bdd75f2cef31db Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Thu, 7 Sep 2023 19:19:32 +0200
Subject: [PATCH 1/3] [Driver] Link Flang runtime on Solaris

I noticed that `flang-new` cannot link Fortran executables on Solaris since
the runtime libs are missing.

This patch fixes this, following `Gnu.cpp`.  The `linker-flags.f90` testcase
is augmented to test for this.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.
---
 clang/lib/Driver/ToolChains/Solaris.cpp | 8 
 flang/test/Driver/linker-flags.f90  | 1 +
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 36fe12608eefc6c..252c71d3379eab4 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -223,6 +223,14 @@ void solaris::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
   CmdArgs.push_back("-lm");
 }
+// Additional linker set-up and flags for Fortran. This is required in 
order
+// to generate executables. As Fortran runtime depends on the C runtime,
+// these dependencies need to be listed before the C runtime below.
+if (D.IsFlangMode()) {
+  addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs);
+  addFortranRuntimeLibs(getToolChain(), CmdArgs);
+  CmdArgs.push_back("-lm");
+}
 if (Args.hasArg(options::OPT_fstack_protector) ||
 Args.hasArg(options::OPT_fstack_protector_strong) ||
 Args.hasArg(options::OPT_fstack_protector_all)) {
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 09b8a224df13828..717dcc7775e2126 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -4,6 +4,7 @@
 
 ! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
 ! RUN: %flang -### -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,DARWIN
+! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
 ! RUN: %flang -### -target x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,MINGW
 
 ! NOTE: Clang's driver library, clangDriver, usually adds 'libcmt' and

>From bf1b865045ed4f484f24746aa18405d93e760979 Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Tue, 17 Oct 2023 20:43:23 +0200
Subject: [PATCH 2/3] Rename `GNU` label to `UNIX` to better match use.

---
 flang/test/Driver/linker-flags.f90 | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 717dcc7775e2126..fd61825eb4023a5 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -2,9 +2,9 @@
 ! invocation. These libraries are added on top of other standard runtime
 ! libraries that the Clang driver will include.
 
-! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
+! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,UNIX
 ! RUN: %flang -### -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,DARWIN
-! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
+! RUN: %flang -### -target sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,UNIX
 ! RUN: %flang -### -target x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,MINGW
 
 ! NOTE: Clang's driver library, clangDriver, usually adds 'libcmt' and
@@ -22,12 +22,12 @@
 !   run on any other platform, such as Windows that use a .exe
 !   suffix. Clang's driver will try to resolve the path to the ld
 !   executable and may find the GNU linker from MinGW or Cygwin.
-! GNU-LABEL:  "{{.*}}ld{{(\.exe)?}}"
-! GNU-SAME: "[[object_file]]"
-! GNU-SAME: -lFortran_main
-! GNU-SAME: -lFortranRuntime
-! GNU-SAME: -lFortranDecimal
-! GNU-SAME: -lm
+! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
+! UNIX-SAME: "[[object_file]]"
+! UNIX-SAME: -lFortran_main
+! UNIX-SAME: -lFortranRuntime
+! UNIX-SAME: -lFortranDecimal
+! UNIX-SAME: -lm
 
 ! DARWIN-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! DARWIN-SAME: "[[object_file]]"

>From 5e7ca991bd8b87b754e982d9836460dc0f31e59f Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Wed, 18 Oct 2023 12:01:15 +0200
Subject: [PATCH 3/3] Use `--target=`.  Join `-l` lines for `UNIX` case.

---
 flang/test/Driver/linker-flags.f90 | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/te

[clang] [AMDGPU] Fix image intrinsic optimizer on loads from different resources (PR #69355)

2023-10-18 Thread Jay Foad via cfe-commits

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


[clang-tools-extra] [AMDGPU] Fix image intrinsic optimizer on loads from different resources (PR #69355)

2023-10-18 Thread Jay Foad via cfe-commits

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


[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

2023-10-18 Thread Sunil K via Phabricator via cfe-commits
koops updated this revision to Diff 557749.
koops added a comment.

Removed the tail-allocation.
Other changes suggested in the previous review.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123235/new/

https://reviews.llvm.org/D123235

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/atomic_ast_print.cpp
  clang/test/OpenMP/atomic_messages.cpp
  clang/tools/libclang/CIndex.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -209,6 +209,7 @@
 def OMPC_Update : Clause<"update"> { let clangClass = "OMPUpdateClause"; }
 def OMPC_Capture : Clause<"capture"> { let clangClass = "OMPCaptureClause"; }
 def OMPC_Compare : Clause<"compare"> { let clangClass = "OMPCompareClause"; }
+def OMPC_Fail : Clause<"fail"> { let clangClass = "OMPFailClause"; }
 def OMPC_SeqCst : Clause<"seq_cst"> { let clangClass = "OMPSeqCstClause"; }
 def OMPC_AcqRel : Clause<"acq_rel"> { let clangClass = "OMPAcqRelClause"; }
 def OMPC_Acquire : Clause<"acquire"> { let clangClass = "OMPAcquireClause"; }
@@ -637,7 +638,8 @@
 VersionedClause,
 VersionedClause,
 VersionedClause,
-VersionedClause
+VersionedClause,
+VersionedClause
   ];
 }
 def OMP_Target : Directive<"target"> {
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -2167,6 +2167,7 @@
 CHECK_SIMPLE_CLAUSE(Doacross, OMPC_doacross)
 CHECK_SIMPLE_CLAUSE(OmpxAttribute, OMPC_ompx_attribute)
 CHECK_SIMPLE_CLAUSE(OmpxBare, OMPC_ompx_bare)
+CHECK_SIMPLE_CLAUSE(Fail, OMPC_fail)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
 CHECK_REQ_SCALAR_INT_CLAUSE(NumTasks, OMPC_num_tasks)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2402,6 +2402,8 @@
 
 void OMPClauseEnqueue::VisitOMPCompareClause(const OMPCompareClause *) {}
 
+void OMPClauseEnqueue::VisitOMPFailClause(const OMPFailClause *) {}
+
 void OMPClauseEnqueue::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
 
 void OMPClauseEnqueue::VisitOMPAcqRelClause(const OMPAcqRelClause *) {}
Index: clang/test/OpenMP/atomic_messages.cpp
===
--- clang/test/OpenMP/atomic_messages.cpp
+++ clang/test/OpenMP/atomic_messages.cpp
@@ -958,6 +958,25 @@
 // expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'capture' clause}}
 #pragma omp atomic compare compare capture capture
   { v = a; if (a > b) a = b; }
+// expected-error@+1 {{expected 'compare' clause with the 'fail' modifier}}
+#pragma omp atomic fail(seq_cst)
+  if(v == a) { v = a; }
+// expected-error@+2 {{expected '(' after 'fail'}}
+// expected-error@+1 {{expected a memory order clause}}
+#pragma omp atomic compare fail
+  if(v < a) { v = a; }
+// expected-error@+1 {{expected a memory order clause}}
+#pragma omp atomic compare fail(capture)
+  if(v < a) { v = a; }
+ // expected-error@+2 {{expected ')' after 'atomic compare fail'}}
+ // expected-warning@+1 {{extra tokens at the end of '#pragma omp atomic' are ignored}}
+#pragma omp atomic compare fail(seq_cst | acquire)
+  if(v < a) { v = a; }
+// expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'fail' clause}}
+#pragma omp atomic compare fail(relaxed) fail(seq_cst)
+  if(v < a) { v = a; }
+
+
 #endif
   // expected-note@+1 {{in instantiation of function template specialization 'mixed' requested here}}
   return mixed();
Index: clang/test/OpenMP/atomic_ast_print.cpp
===
--- clang/test/OpenMP/atomic_ast_print.cpp
+++ clang/test/OpenMP/atomic_ast_print.cpp
@@ -226,6 +226,16 @@
   { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture hint(6)
   { v = a == b; if (v) a = c; }
+#pragma omp atomic compare fail(acq_rel)
+  { if (a < c) { a = c; } }
+#pragma omp atomic compare fail(acquire)
+  { if (a < c) { a = c; } }
+#pragma omp atomic compare fail(release)
+  { if (a < c) { a = c; } }
+

[clang-tools-extra] [analyzer] Add std::variant checker (PR #66481)

2023-10-18 Thread Gábor Spaits via cfe-commits

spaits wrote:

@steakhal we have also run the checker on multiple open source projects (a few 
weeks ago) and it did not crash. (It did not have any findings. There were only 
two C++ 17 projects and they had retrieved value from std::variant at most 20 
times).

Could you please take another look at the commit and give feedback, when you'll 
have time for it?

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


[clang] [clang][Interp] Implement __builtin_bit_cast (PR #68288)

2023-10-18 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

@AaronBallman This is still in a rough WIP state, but I've added support for 
bitcasts with bitfields involved, take a look at the tests if you have some 
time.

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


[clang-tools-extra] [include-cleaner] Handle symbols from system headers. (PR #66089)

2023-10-18 Thread kadir çetinkaya via cfe-commits

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


[clang-tools-extra] [include-cleaner] Handle symbols from system headers. (PR #66089)

2023-10-18 Thread kadir çetinkaya via cfe-commits


@@ -176,6 +180,104 @@ headersForSpecialSymbol(const Symbol &S, const 
SourceManager &SM,
   return std::nullopt;
 }
 
+// A hand-mainained list of include mappings for system headers.
+// The first element is the suffix of the physical file path for the system
+// header, the second element is the final verbatim header spelling.
+const std::pair IncludeMappings[] = {
+{"bits/types/struct_timeval.h", ""},
+{"bits/pthreadtypes.h", ""},
+{"bits/types/struct_iovec.h", ""},
+{"linux/limits.h", ""},
+{"bits/getopt_core.h", ""},
+{"asm-generic/socket.h", ""},
+{"bits/posix1_lim.h", ""},
+{"bits/time.h", "time.h"},
+{"bits/getopt_ext.h", ""},
+{"bits/types/sigset_t.h", ""},
+{"bits/types/siginfo_t.h", ""},
+{"bits/types/FILE.h", ""},
+{"asm/unistd_64.h", ""},
+{"bits/stat.h", ""},
+{"asm-generic/ioctls.h", ""},
+{"asm-generic/errno.h", ""},
+{"asm-generic/int-ll64.h", ""},
+{"bits/sigaction.h", ""},
+{"bits/types/struct_rusage.h", ""},
+{"sys/syscall.h", ""},
+{"linux/prctl.h", ""},
+{"sys/ucontext.h", ""},
+{"bits/types/clockid_t.h", ""},
+{"bits/types/mbstate_t.h", ""},
+{"bits/types/mbstate_t.h", ""},
+{"bits/types/struct_itimerspec.h", ""},
+{"bits/types/time_t.h", ""},
+{"bits/sockaddr.h", ""},
+};
+// The maximum number of path components in a key from SuffixHeaderMapping.
+// Used to minimize the number of lookups in suffix path mappings.
+constexpr int MaxSuffixComponents = 3;
+
+// A mapping for system headers based on a set of filename rules.
+class SystemIncludeMap {
+public:
+  static const SystemIncludeMap &get() {

kadircet wrote:

i think it's important that we also make these mappings different per language. 
most of them will likely be language independent, but at least libc extensions 
are likely to have different spellings for c vs c++.

moreover these fell more like private -> public mappings we perform via 
PragmaIncludes, so what about just moving them there? that way we can also 
initialize the mapping based on language options and also benefit all the other 
users of pragma includes with similar mappings?

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


[clang-tools-extra] [include-cleaner] Handle symbols from system headers. (PR #66089)

2023-10-18 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet commented:

thanks a lot, and so sorry for taking so long on getting to this

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


[clang-tools-extra] [include-cleaner] Handle symbols from system headers. (PR #66089)

2023-10-18 Thread kadir çetinkaya via cfe-commits


@@ -176,6 +180,104 @@ headersForSpecialSymbol(const Symbol &S, const 
SourceManager &SM,
   return std::nullopt;
 }
 
+// A hand-mainained list of include mappings for system headers.
+// The first element is the suffix of the physical file path for the system
+// header, the second element is the final verbatim header spelling.
+const std::pair IncludeMappings[] = {
+{"bits/types/struct_timeval.h", ""},
+{"bits/pthreadtypes.h", ""},
+{"bits/types/struct_iovec.h", ""},
+{"linux/limits.h", ""},
+{"bits/getopt_core.h", ""},
+{"asm-generic/socket.h", ""},
+{"bits/posix1_lim.h", ""},
+{"bits/time.h", "time.h"},
+{"bits/getopt_ext.h", ""},
+{"bits/types/sigset_t.h", ""},
+{"bits/types/siginfo_t.h", ""},
+{"bits/types/FILE.h", ""},
+{"asm/unistd_64.h", ""},
+{"bits/stat.h", ""},
+{"asm-generic/ioctls.h", ""},
+{"asm-generic/errno.h", ""},
+{"asm-generic/int-ll64.h", ""},
+{"bits/sigaction.h", ""},
+{"bits/types/struct_rusage.h", ""},
+{"sys/syscall.h", ""},
+{"linux/prctl.h", ""},
+{"sys/ucontext.h", ""},
+{"bits/types/clockid_t.h", ""},
+{"bits/types/mbstate_t.h", ""},
+{"bits/types/mbstate_t.h", ""},
+{"bits/types/struct_itimerspec.h", ""},
+{"bits/types/time_t.h", ""},
+{"bits/sockaddr.h", ""},
+};
+// The maximum number of path components in a key from SuffixHeaderMapping.
+// Used to minimize the number of lookups in suffix path mappings.
+constexpr int MaxSuffixComponents = 3;
+
+// A mapping for system headers based on a set of filename rules.
+class SystemIncludeMap {
+public:
+  static const SystemIncludeMap &get() {
+static SystemIncludeMap Instance;
+static const auto *SystemHeaderMap = [] {
+  const size_t Size = sizeof(IncludeMappings) / sizeof(IncludeMappings[0]);
+  auto *HeaderMap = new std::multimap();
+  for (size_t I = 0; I < Size; I++) {
+HeaderMap->insert(IncludeMappings[I]);
+  }
+  return HeaderMap;
+}();
+
+// // Check MaxSuffixComponents constant is correct.
+assert(llvm::all_of(*SystemHeaderMap, [](const auto &KeyAndValue) {
+  return std::distance(
+ llvm::sys::path::begin(KeyAndValue.first,
+llvm::sys::path::Style::posix),
+ llvm::sys::path::end(KeyAndValue.first)) <=
+ MaxSuffixComponents;
+}));
+// ... and precise.
+assert(llvm::any_of(*SystemHeaderMap, [](const auto &KeyAndValue) {
+  return std::distance(
+ llvm::sys::path::begin(KeyAndValue.first,
+llvm::sys::path::Style::posix),
+ llvm::sys::path::end(KeyAndValue.first)) ==
+ MaxSuffixComponents;
+}));
+
+Instance.SuffixHeaderMapping = SystemHeaderMap;

kadircet wrote:

you're modifying a global with every call here, in a non-thread safe way.

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


[clang-tools-extra] [include-cleaner] Handle symbols from system headers. (PR #66089)

2023-10-18 Thread kadir çetinkaya via cfe-commits


@@ -176,6 +180,104 @@ headersForSpecialSymbol(const Symbol &S, const 
SourceManager &SM,
   return std::nullopt;
 }
 
+// A hand-mainained list of include mappings for system headers.
+// The first element is the suffix of the physical file path for the system
+// header, the second element is the final verbatim header spelling.
+const std::pair IncludeMappings[] = {
+{"bits/types/struct_timeval.h", ""},
+{"bits/pthreadtypes.h", ""},
+{"bits/types/struct_iovec.h", ""},
+{"linux/limits.h", ""},
+{"bits/getopt_core.h", ""},
+{"asm-generic/socket.h", ""},
+{"bits/posix1_lim.h", ""},
+{"bits/time.h", "time.h"},
+{"bits/getopt_ext.h", ""},
+{"bits/types/sigset_t.h", ""},
+{"bits/types/siginfo_t.h", ""},
+{"bits/types/FILE.h", ""},
+{"asm/unistd_64.h", ""},
+{"bits/stat.h", ""},
+{"asm-generic/ioctls.h", ""},
+{"asm-generic/errno.h", ""},
+{"asm-generic/int-ll64.h", ""},
+{"bits/sigaction.h", ""},
+{"bits/types/struct_rusage.h", ""},
+{"sys/syscall.h", ""},
+{"linux/prctl.h", ""},
+{"sys/ucontext.h", ""},
+{"bits/types/clockid_t.h", ""},
+{"bits/types/mbstate_t.h", ""},
+{"bits/types/mbstate_t.h", ""},
+{"bits/types/struct_itimerspec.h", ""},
+{"bits/types/time_t.h", ""},
+{"bits/sockaddr.h", ""},
+};
+// The maximum number of path components in a key from SuffixHeaderMapping.
+// Used to minimize the number of lookups in suffix path mappings.
+constexpr int MaxSuffixComponents = 3;
+
+// A mapping for system headers based on a set of filename rules.
+class SystemIncludeMap {
+public:
+  static const SystemIncludeMap &get() {
+static SystemIncludeMap Instance;
+static const auto *SystemHeaderMap = [] {
+  const size_t Size = sizeof(IncludeMappings) / sizeof(IncludeMappings[0]);
+  auto *HeaderMap = new std::multimap();
+  for (size_t I = 0; I < Size; I++) {
+HeaderMap->insert(IncludeMappings[I]);
+  }
+  return HeaderMap;
+}();
+
+// // Check MaxSuffixComponents constant is correct.
+assert(llvm::all_of(*SystemHeaderMap, [](const auto &KeyAndValue) {
+  return std::distance(
+ llvm::sys::path::begin(KeyAndValue.first,
+llvm::sys::path::Style::posix),
+ llvm::sys::path::end(KeyAndValue.first)) <=
+ MaxSuffixComponents;
+}));
+// ... and precise.
+assert(llvm::any_of(*SystemHeaderMap, [](const auto &KeyAndValue) {
+  return std::distance(
+ llvm::sys::path::begin(KeyAndValue.first,
+llvm::sys::path::Style::posix),
+ llvm::sys::path::end(KeyAndValue.first)) ==
+ MaxSuffixComponents;
+}));
+
+Instance.SuffixHeaderMapping = SystemHeaderMap;
+return Instance;
+  }
+
+  // Returns the overridden verbatim spellings for HeaderPath that can be
+  // directly included.
+  llvm::SmallVector
+  mapHeader(llvm::StringRef HeaderPath) const {

kadircet wrote:

what about making this one static instead and getting rid of the extra 
singleton interface?

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


[clang-tools-extra] [include-cleaner] Handle symbols from system headers. (PR #66089)

2023-10-18 Thread kadir çetinkaya via cfe-commits


@@ -176,6 +180,104 @@ headersForSpecialSymbol(const Symbol &S, const 
SourceManager &SM,
   return std::nullopt;
 }
 
+// A hand-mainained list of include mappings for system headers.
+// The first element is the suffix of the physical file path for the system
+// header, the second element is the final verbatim header spelling.
+const std::pair IncludeMappings[] = {
+{"bits/types/struct_timeval.h", ""},

kadircet wrote:

what about extracting these into a `SystemHeaderSuffixes.inc` with entries like 
`SYSTEM_HEADER_DETAIL(bits/types/struct_timeval.h, )`. that way we 
can have an easy way to inject more mappings going forward for other libraries 
in the future.

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


[clang-tools-extra] [include-cleaner] Handle symbols from system headers. (PR #66089)

2023-10-18 Thread kadir çetinkaya via cfe-commits


@@ -176,6 +180,104 @@ headersForSpecialSymbol(const Symbol &S, const 
SourceManager &SM,
   return std::nullopt;
 }
 
+// A hand-mainained list of include mappings for system headers.
+// The first element is the suffix of the physical file path for the system
+// header, the second element is the final verbatim header spelling.
+const std::pair IncludeMappings[] = {

kadircet wrote:

we discussed offline that this list is mostly for demonstration purposes, but 
wanted to remind it once again. we probably want to start with at least what we 
have in clangd, right?

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


[clang-tools-extra] [include-cleaner] Handle symbols from system headers. (PR #66089)

2023-10-18 Thread kadir çetinkaya via cfe-commits


@@ -176,6 +180,104 @@ headersForSpecialSymbol(const Symbol &S, const 
SourceManager &SM,
   return std::nullopt;
 }
 
+// A hand-mainained list of include mappings for system headers.
+// The first element is the suffix of the physical file path for the system
+// header, the second element is the final verbatim header spelling.
+const std::pair IncludeMappings[] = {
+{"bits/types/struct_timeval.h", ""},
+{"bits/pthreadtypes.h", ""},
+{"bits/types/struct_iovec.h", ""},
+{"linux/limits.h", ""},
+{"bits/getopt_core.h", ""},
+{"asm-generic/socket.h", ""},
+{"bits/posix1_lim.h", ""},
+{"bits/time.h", "time.h"},
+{"bits/getopt_ext.h", ""},
+{"bits/types/sigset_t.h", ""},
+{"bits/types/siginfo_t.h", ""},
+{"bits/types/FILE.h", ""},
+{"asm/unistd_64.h", ""},
+{"bits/stat.h", ""},
+{"asm-generic/ioctls.h", ""},
+{"asm-generic/errno.h", ""},
+{"asm-generic/int-ll64.h", ""},
+{"bits/sigaction.h", ""},
+{"bits/types/struct_rusage.h", ""},
+{"sys/syscall.h", ""},
+{"linux/prctl.h", ""},
+{"sys/ucontext.h", ""},
+{"bits/types/clockid_t.h", ""},
+{"bits/types/mbstate_t.h", ""},
+{"bits/types/mbstate_t.h", ""},
+{"bits/types/struct_itimerspec.h", ""},
+{"bits/types/time_t.h", ""},
+{"bits/sockaddr.h", ""},
+};
+// The maximum number of path components in a key from SuffixHeaderMapping.
+// Used to minimize the number of lookups in suffix path mappings.
+constexpr int MaxSuffixComponents = 3;
+
+// A mapping for system headers based on a set of filename rules.
+class SystemIncludeMap {
+public:
+  static const SystemIncludeMap &get() {
+static SystemIncludeMap Instance;
+static const auto *SystemHeaderMap = [] {
+  const size_t Size = sizeof(IncludeMappings) / sizeof(IncludeMappings[0]);
+  auto *HeaderMap = new std::multimap();
+  for (size_t I = 0; I < Size; I++) {
+HeaderMap->insert(IncludeMappings[I]);
+  }
+  return HeaderMap;
+}();
+
+// // Check MaxSuffixComponents constant is correct.
+assert(llvm::all_of(*SystemHeaderMap, [](const auto &KeyAndValue) {
+  return std::distance(
+ llvm::sys::path::begin(KeyAndValue.first,
+llvm::sys::path::Style::posix),
+ llvm::sys::path::end(KeyAndValue.first)) <=
+ MaxSuffixComponents;
+}));
+// ... and precise.
+assert(llvm::any_of(*SystemHeaderMap, [](const auto &KeyAndValue) {
+  return std::distance(
+ llvm::sys::path::begin(KeyAndValue.first,
+llvm::sys::path::Style::posix),
+ llvm::sys::path::end(KeyAndValue.first)) ==
+ MaxSuffixComponents;
+}));

kadircet wrote:

i think we can move these assertions into the lambda, no need to perform them 
every time we access the singleton

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


[clang-tools-extra] [include-cleaner] Handle symbols from system headers. (PR #66089)

2023-10-18 Thread kadir çetinkaya via cfe-commits


@@ -188,6 +290,20 @@ llvm::SmallVector> findHeaders(const 
SymbolLocation &Loc,
 OptionalFileEntryRef FE = SM.getFileEntryRefForID(FID);
 if (!FE)
   return {};
+
+if (SrcMgr::isSystem(
+SM.getSLocEntry(FID).getFile().getFileCharacteristic())) {
+  if (auto MappingHeader = 
SystemIncludeMap::get().mapHeader(FE->getName());
+  !MappingHeader.empty()) {
+for (auto &Header : MappingHeader)
+  Results.emplace_back(Header, Hints::PublicHeader);
+assert(!Results.empty());
+Results.front().Hint |= Hints::PreferredHeader;
+// FIXME: should we include the original header as well?

kadircet wrote:

yes, i think we should treat these similar to IWYU private -> public mappings.

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


[clang-tools-extra] [include-cleaner] Handle symbols from system headers. (PR #66089)

2023-10-18 Thread kadir çetinkaya via cfe-commits


@@ -188,6 +290,20 @@ llvm::SmallVector> findHeaders(const 
SymbolLocation &Loc,
 OptionalFileEntryRef FE = SM.getFileEntryRefForID(FID);
 if (!FE)
   return {};
+
+if (SrcMgr::isSystem(

kadircet wrote:

i am afraid this check might be overly strict, maybe drop this initially and 
see if we have too many false-positives?

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


[clang-tools-extra] [include-cleaner] Handle symbols from system headers. (PR #66089)

2023-10-18 Thread kadir çetinkaya via cfe-commits


@@ -176,6 +180,104 @@ headersForSpecialSymbol(const Symbol &S, const 
SourceManager &SM,
   return std::nullopt;
 }
 
+// A hand-mainained list of include mappings for system headers.
+// The first element is the suffix of the physical file path for the system
+// header, the second element is the final verbatim header spelling.
+const std::pair IncludeMappings[] = {
+{"bits/types/struct_timeval.h", ""},
+{"bits/pthreadtypes.h", ""},
+{"bits/types/struct_iovec.h", ""},
+{"linux/limits.h", ""},
+{"bits/getopt_core.h", ""},
+{"asm-generic/socket.h", ""},
+{"bits/posix1_lim.h", ""},
+{"bits/time.h", "time.h"},
+{"bits/getopt_ext.h", ""},
+{"bits/types/sigset_t.h", ""},
+{"bits/types/siginfo_t.h", ""},
+{"bits/types/FILE.h", ""},
+{"asm/unistd_64.h", ""},
+{"bits/stat.h", ""},
+{"asm-generic/ioctls.h", ""},
+{"asm-generic/errno.h", ""},
+{"asm-generic/int-ll64.h", ""},
+{"bits/sigaction.h", ""},
+{"bits/types/struct_rusage.h", ""},
+{"sys/syscall.h", ""},
+{"linux/prctl.h", ""},
+{"sys/ucontext.h", ""},
+{"bits/types/clockid_t.h", ""},
+{"bits/types/mbstate_t.h", ""},
+{"bits/types/mbstate_t.h", ""},
+{"bits/types/struct_itimerspec.h", ""},
+{"bits/types/time_t.h", ""},
+{"bits/sockaddr.h", ""},
+};
+// The maximum number of path components in a key from SuffixHeaderMapping.
+// Used to minimize the number of lookups in suffix path mappings.
+constexpr int MaxSuffixComponents = 3;
+
+// A mapping for system headers based on a set of filename rules.
+class SystemIncludeMap {
+public:
+  static const SystemIncludeMap &get() {
+static SystemIncludeMap Instance;
+static const auto *SystemHeaderMap = [] {
+  const size_t Size = sizeof(IncludeMappings) / sizeof(IncludeMappings[0]);
+  auto *HeaderMap = new std::multimap();

kadircet wrote:

why do we have a multipmap here instead of a just StringMap? do we expect to 
have suffixes that map to multiple umbrella headers?

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


[clang-tools-extra] [include-cleaner] Handle symbols from system headers. (PR #66089)

2023-10-18 Thread kadir çetinkaya via cfe-commits


@@ -176,6 +180,104 @@ headersForSpecialSymbol(const Symbol &S, const 
SourceManager &SM,
   return std::nullopt;
 }
 
+// A hand-mainained list of include mappings for system headers.
+// The first element is the suffix of the physical file path for the system
+// header, the second element is the final verbatim header spelling.
+const std::pair IncludeMappings[] = {
+{"bits/types/struct_timeval.h", ""},
+{"bits/pthreadtypes.h", ""},
+{"bits/types/struct_iovec.h", ""},
+{"linux/limits.h", ""},
+{"bits/getopt_core.h", ""},
+{"asm-generic/socket.h", ""},
+{"bits/posix1_lim.h", ""},
+{"bits/time.h", "time.h"},
+{"bits/getopt_ext.h", ""},
+{"bits/types/sigset_t.h", ""},
+{"bits/types/siginfo_t.h", ""},
+{"bits/types/FILE.h", ""},
+{"asm/unistd_64.h", ""},
+{"bits/stat.h", ""},
+{"asm-generic/ioctls.h", ""},
+{"asm-generic/errno.h", ""},
+{"asm-generic/int-ll64.h", ""},
+{"bits/sigaction.h", ""},
+{"bits/types/struct_rusage.h", ""},
+{"sys/syscall.h", ""},
+{"linux/prctl.h", ""},
+{"sys/ucontext.h", ""},
+{"bits/types/clockid_t.h", ""},
+{"bits/types/mbstate_t.h", ""},
+{"bits/types/mbstate_t.h", ""},
+{"bits/types/struct_itimerspec.h", ""},
+{"bits/types/time_t.h", ""},
+{"bits/sockaddr.h", ""},
+};
+// The maximum number of path components in a key from SuffixHeaderMapping.
+// Used to minimize the number of lookups in suffix path mappings.
+constexpr int MaxSuffixComponents = 3;
+
+// A mapping for system headers based on a set of filename rules.
+class SystemIncludeMap {
+public:
+  static const SystemIncludeMap &get() {
+static SystemIncludeMap Instance;
+static const auto *SystemHeaderMap = [] {
+  const size_t Size = sizeof(IncludeMappings) / sizeof(IncludeMappings[0]);
+  auto *HeaderMap = new std::multimap();
+  for (size_t I = 0; I < Size; I++) {
+HeaderMap->insert(IncludeMappings[I]);
+  }
+  return HeaderMap;
+}();
+
+// // Check MaxSuffixComponents constant is correct.
+assert(llvm::all_of(*SystemHeaderMap, [](const auto &KeyAndValue) {
+  return std::distance(
+ llvm::sys::path::begin(KeyAndValue.first,
+llvm::sys::path::Style::posix),
+ llvm::sys::path::end(KeyAndValue.first)) <=
+ MaxSuffixComponents;
+}));
+// ... and precise.
+assert(llvm::any_of(*SystemHeaderMap, [](const auto &KeyAndValue) {
+  return std::distance(
+ llvm::sys::path::begin(KeyAndValue.first,
+llvm::sys::path::Style::posix),
+ llvm::sys::path::end(KeyAndValue.first)) ==
+ MaxSuffixComponents;
+}));
+
+Instance.SuffixHeaderMapping = SystemHeaderMap;
+return Instance;
+  }
+
+  // Returns the overridden verbatim spellings for HeaderPath that can be
+  // directly included.
+  llvm::SmallVector
+  mapHeader(llvm::StringRef HeaderPath) const {
+if (!SuffixHeaderMapping)
+  return {};
+
+int Components = 1;
+llvm::SmallVector Headers;
+for (auto It = llvm::sys::path::rbegin(HeaderPath),
+  End = llvm::sys::path::rend(HeaderPath);
+ It != End && Components <= MaxSuffixComponents; ++It, ++Components) {
+  auto SubPath = HeaderPath.substr(It->data() - HeaderPath.begin());
+  auto FoundRange = SuffixHeaderMapping->equal_range(SubPath);
+  for (auto It = FoundRange.first; It != FoundRange.second; ++It)
+Headers.push_back(It->second);
+}
+return Headers;;

kadircet wrote:

extra `;`

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


[clang] [NVPTX] Fixed some wmma store builtins that had non-const src param. (PR #69354)

2023-10-18 Thread via cfe-commits

JackAKirk wrote:

cc @Artem-B 

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


[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

2023-10-18 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/include/clang/AST/ASTNodeTraverser.h:217-220
+if (const auto *OMPC = dyn_cast(C)) {
+  Visit(OMPC);
+  return;
+}

Why do you need special logic here?



Comment at: clang/include/clang/AST/OpenMPClause.h:2320
+
+  OMPClause *MemoryOrderClause = nullptr;
+  OpenMPClauseKind FailParameter = llvm::omp::OMPC_unknown;

That's not the best decision, better to make this kind of clause a base class 
for these new class.



Comment at: clang/include/clang/AST/OpenMPClause.h:2373
+SourceLocation StartLoc, SourceLocation LParenLoc,
+   SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc), 
ArgumentLoc(ArgumentLoc), LParenLoc(LParenLoc)  {

Formatting



Comment at: clang/include/clang/AST/OpenMPClause.h:2429
+
+  const OMPClause *const_getMemoryOrderClause() const {
+return static_cast(MemoryOrderClause);

No need for const_ prefix in the name


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123235/new/

https://reviews.llvm.org/D123235

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


[PATCH] D151439: [Clang][SVE2.1] Add builtins for 2-way svdot (vectors, indexed)

2023-10-18 Thread Caroline via Phabricator via cfe-commits
CarolineConcatto updated this revision to Diff 557751.
CarolineConcatto added a comment.
Herald added a subscriber: sunshaoce.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151439/new/

https://reviews.llvm.org/D151439

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_dot.c
  clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp

Index: clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
===
--- clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
+++ clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
@@ -107,3 +107,12 @@
   svcntp_c14(c, 3); // expected-error {{argument should be a multiple of 2}}
 }
 
+void test_svdot_lane_2way(svint32_t s32, svuint32_t u32, svint16_t s16, svuint16_t u16,
+  svfloat32_t f32, svfloat16_t f16) {
+  svdot_lane_s32_s16_s16(s32, s16, s16, 1); // expected-error {{argument value 4 is outside the valid range [0, 3]}}
+  svdot_lane_u32_u16_u16(u32, u16, u16, 1); // expected-error {{argument value 4 is outside the valid range [0, 3]}}
+  svdot_lane_f32_f16_f16(f32, f16, f16, 1); // expected-error {{argument value 4 is outside the valid range [0, 3]}}
+  svdot_lane_s32_s16_s16(s32, s16, s16, 4); // expected-error {{argument value 4 is outside the valid range [0, 3]}}
+  svdot_lane_u32_u16_u16(u32, u16, u16, 4); // expected-error {{argument value 4 is outside the valid range [0, 3]}}
+  svdot_lane_f32_f16_f16(f32, f16, f16, 4); // expected-error {{argument value 4 is outside the valid range [0, 3]}}
+}
Index: clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_dot.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_dot.c
@@ -0,0 +1,107 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+// CHECK-LABEL: @test_svdot_s32_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.sdot.x2.nxv4i32( [[OP1:%.*]],  [[OP2:%.*]],  [[OP3:%.*]])
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z17test_svdot_s32_x2u11__SVInt32_tu11__SVInt16_tu11__SVInt16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.sdot.x2.nxv4i32( [[OP1:%.*]],  [[OP2:%.*]],  [[OP3:%.*]])
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint32_t test_svdot_s32_x2(svint32_t op1, svint16_t op2, svint16_t op3)
+{
+  return SVE_ACLE_FUNC(svdot,_s32_s16_s16,)(op1, op2, op3);
+}
+
+// CHECK-LABEL: @test_svdot_u32_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.udot.x2.nxv4i32( [[OP1:%.*]],  [[OP2:%.*]],  [[OP3:%.*]])
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z17test_svdot_u32_x2u12__SVUint32_tu12__SVUint16_tu12__SVUint16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.udot.x2.nxv4i32( [[OP1:%.*]],  [[OP2:%.*]],  [[OP3:%.*]])
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svuint32_t test_svdot_u32_x2(svuint32_t op1, svuint16_t op2, svuint16_t op3)
+{
+  return SVE_ACLE_FUNC(svdot,_u32_u16_u16,)(op1, op2, op3);
+}
+
+// CHECK-LABEL: @test_svdot_f32_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.fdot.x2.nxv4f32( [[OP1:%.*]],  [[OP2:%.*]],  [[OP3:%.*]])
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z17test_svdot_f32_x2u13__SVFloat32_tu13__SVFloat16_tu13__SVFloat16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.fdot.x2.nxv4f32( [[OP1:%.*]

[PATCH] D151199: [Clang][SVE2.1] Add pfalse builtin

2023-10-18 Thread Dinar Temirbulatov via Phabricator via cfe-commits
dtemirbulatov accepted this revision.
dtemirbulatov added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151199/new/

https://reviews.llvm.org/D151199

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


[PATCH] D151197: [Clang][SVE2p1] Add svpsel builtins

2023-10-18 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin accepted this revision.
kmclaughlin added a comment.
This revision is now accepted and ready to land.

Thank you for updating this @CarolineConcatto, LGTM




Comment at: clang/include/clang/Basic/arm_sve.td:1886
 
+
+

nit: extra whitespace


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151197/new/

https://reviews.llvm.org/D151197

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


[clang] [AMDGPU] Remove Code Object V3 (PR #67118)

2023-10-18 Thread Andrew Stubbs via cfe-commits

ams-cs wrote:

@Pierre-vh Can we undo this please? Just for now.

This broke the GCC build (which uses llvm-mc) because we still use v3 like 
@tob2 said. I don't know that anyone is using Fiji in production, but it's 
still a good proportion of what we have in our compiler test farm.

As far as I know, the last good ROCm for that device was 3.8 which doesn't 
support v4.

I appreciate that this isn't ideal; I'd like to remove that device too.

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


[PATCH] D151461: [Clang][SVE2.1] Add builtins and intrinsics for SVBFMLSLB/T

2023-10-18 Thread Caroline via Phabricator via cfe-commits
CarolineConcatto updated this revision to Diff 557754.
CarolineConcatto added a comment.

-rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151461/new/

https://reviews.llvm.org/D151461

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/include/clang/Basic/arm_sve_sme_incl.td
  clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmlsl.c
  clang/utils/TableGen/SveEmitter.cpp
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
  llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfmls.ll

Index: llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfmls.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfmls.ll
@@ -0,0 +1,43 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sme2p1 -mattr=+b16b16 -verify-machineinstrs < %s | FileCheck %s
+
+define  @bfmlslb_f32( %zda,  %zn,  %zm) {
+; CHECK-LABEL: bfmlslb_f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:bfmlslb z0.s, z1.h, z2.h
+; CHECK-NEXT:ret
+  %out = call  @llvm.aarch64.sve.bfmlslb( %zda,  %zn,  %zm)
+  ret  %out
+}
+
+define  @bfmlslt_f32( %zda,  %zn,  %zm) {
+; CHECK-LABEL: bfmlslt_f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:bfmlslt z0.s, z1.h, z2.h
+; CHECK-NEXT:ret
+  %out = call  @llvm.aarch64.sve.bfmlslt( %zda,  %zn,  %zm)
+  ret  %out
+}
+
+define  @bfmlslb_lane_f32( %zda,  %zn,  %zm) {
+; CHECK-LABEL: bfmlslb_lane_f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:bfmlslb z0.s, z1.h, z2.h[7]
+; CHECK-NEXT:ret
+  %out = call  @llvm.aarch64.sve.bfmlslb.lane( %zda,  %zn,  %zm, i32 7)
+  ret  %out
+}
+
+define  @bfmlslt_lane_f32( %zda,  %zn,  %zm) {
+; CHECK-LABEL: bfmlslt_lane_f32:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:bfmlslt z0.s, z1.h, z2.h[7]
+; CHECK-NEXT:ret
+  %out = call  @llvm.aarch64.sve.bfmlslt.lane( %zda,  %zn,  %zm, i32 7)
+  ret  %out
+}
+
+declare  @llvm.aarch64.sve.bfmlslb(, , )
+declare  @llvm.aarch64.sve.bfmlslt(, , )
+declare  @llvm.aarch64.sve.bfmlslb.lane(, , , i32)
+declare  @llvm.aarch64.sve.bfmlslt.lane(, , , i32)
Index: llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
===
--- llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
+++ llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
@@ -3753,12 +3753,14 @@
 
 let Predicates = [HasSVE2p1_or_HasSME2] in {
 defm FCLAMP_ZZZ : sve2p1_fclamp<"fclamp", int_aarch64_sve_fclamp>;
+
 defm FDOT_ZZZ_S  : sve_float_dot<0b0, 0b0, ZPR32, ZPR16, "fdot", nxv8f16, int_aarch64_sve_fdot_x2>;
 defm FDOT_ZZZI_S : sve_float_dot_indexed<0b0, 0b00, ZPR16, ZPR3b16, "fdot", nxv8f16, int_aarch64_sve_fdot_lane_x2>;
-def BFMLSLB_ZZZ_S : sve2_fp_mla_long<0b110, "bfmlslb">;
-def BFMLSLT_ZZZ_S : sve2_fp_mla_long<0b111, "bfmlslt">;
-def BFMLSLB_ZZZI_S : sve2_fp_mla_long_by_indexed_elem<0b110, "bfmlslb">;
-def BFMLSLT_ZZZI_S : sve2_fp_mla_long_by_indexed_elem<0b111, "bfmlslt">;
+
+defm BFMLSLB_ZZZ_S : sve2_fp_mla_long<0b110, "bfmlslb", nxv4f32, nxv8bf16, int_aarch64_sve_bfmlslb>;
+defm BFMLSLT_ZZZ_S : sve2_fp_mla_long<0b111, "bfmlslt", nxv4f32, nxv8bf16, int_aarch64_sve_bfmlslt>;
+defm BFMLSLB_ZZZI_S : sve2_fp_mla_long_by_indexed_elem<0b110, "bfmlslb", nxv4f32, nxv8bf16, int_aarch64_sve_bfmlslb_lane>;
+defm BFMLSLT_ZZZI_S : sve2_fp_mla_long_by_indexed_elem<0b111, "bfmlslt", nxv4f32, nxv8bf16, int_aarch64_sve_bfmlslt_lane>;
 
 defm SDOT_ZZZ_HtoS  : sve2p1_two_way_dot_vv<"sdot", 0b0, int_aarch64_sve_sdot_x2>;
 defm UDOT_ZZZ_HtoS  : sve2p1_two_way_dot_vv<"udot", 0b1, int_aarch64_sve_udot_x2>;
Index: llvm/include/llvm/IR/IntrinsicsAArch64.td
===
--- llvm/include/llvm/IR/IntrinsicsAArch64.td
+++ llvm/include/llvm/IR/IntrinsicsAArch64.td
@@ -3011,6 +3011,16 @@
 [llvm_anyvector_ty, LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
 [IntrNoMem]>;
 
+  class SME2_BFMLS_Intrinsic
+: DefaultAttrsIntrinsic<[llvm_nxv4f32_ty],
+[llvm_nxv4f32_ty, llvm_nxv8bf16_ty, llvm_nxv8bf16_ty],
+[IntrNoMem]>;
+
+  class SME2_BFMLS_Lane_Intrinsic
+: DefaultAttrsIntrinsic<[llvm_nxv4f32_ty],
+[llvm_nxv4f32_ty, llvm_nxv8bf16_ty, llvm_nxv8bf16_ty, llvm_i32_ty],
+[IntrNoMem, ImmArg>]>;
+
   class SME2_ZA_ArrayVector_Read_VG2_Intrinsic
 : DefaultAttrsIntrinsic<[llvm_anyvector_ty, LLVMMatchType<0>],
 [llvm_i32_ty],
@@ -3214,6 +3224,12 @@
   def int_aarch64_sme_usmla_za32_lane_vg4x2 : SME2_Matrix_ArrayVector_VG2_Multi_Index_Intrinsic;
   def int_aarch64_sme_usmla_za32_lane_vg4x4 : SME2_Matrix_ArrayVector_VG4_Multi_Index_Intrinsic;
 
+  def int_aarch64_sve_bfmlslb : SME2_BFMLS_Intrinsic;
+  def int_aarch64_sve_bfmlslb_lane : SME2_BFMLS_Lane_Intrinsic;
+
+  def int_aa

[clang] [AMDGPU] Remove Code Object V3 (PR #67118)

2023-10-18 Thread Pierre van Houtryve via cfe-commits

Pierre-vh wrote:

I don't mind reverting, but do you have a timeline for removal of that device? 
v3 has been deprecated for a while, AFAIK.

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


[clang-tools-extra] [libc++] Add assertions for potential OOB reads in std::nth_element (PR #67023)

2023-10-18 Thread Daniel Kutenin via cfe-commits

https://github.com/danlark1 updated 
https://github.com/llvm/llvm-project/pull/67023

>From 059bbfab50592026ce2785c5f7d98eaf5c9f8bd6 Mon Sep 17 00:00:00 2001
From: Daniel Kutenin 
Date: Thu, 21 Sep 2023 14:55:11 +0100
Subject: [PATCH 1/7] Add bound checking in nth_element

---
 libcxx/include/__algorithm/nth_element.h | 28 +++-
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/__algorithm/nth_element.h 
b/libcxx/include/__algorithm/nth_element.h
index dbacf58f9ecdbc4..37e43ab0db8ca4f 100644
--- a/libcxx/include/__algorithm/nth_element.h
+++ b/libcxx/include/__algorithm/nth_element.h
@@ -116,10 +116,18 @@ __nth_element(_RandomAccessIterator __first, 
_RandomAccessIterator __nth, _Rando
 return;
 }
 while (true) {
-while (!__comp(*__first, *__i))
+while (!__comp(*__first, *__i)) {
 ++__i;
-while (__comp(*__first, *--__j))
-;
+_LIBCPP_ASSERT_UNCATEGORIZED(
+__i != __last,
+"Would read out of bounds, does your comparator 
satisfy the strict-weak ordering requirement?");
+}
+do {
+_LIBCPP_ASSERT_UNCATEGORIZED(
+__j != __first,
+"Would read out of bounds, does your comparator 
satisfy the strict-weak ordering requirement?");
+--__j;
+} while (__comp(*__first, *__j));
 if (__i >= __j)
 break;
 _Ops::iter_swap(__i, __j);
@@ -146,11 +154,19 @@ __nth_element(_RandomAccessIterator __first, 
_RandomAccessIterator __nth, _Rando
 while (true)
 {
 // __m still guards upward moving __i
-while (__comp(*__i, *__m))
+while (__comp(*__i, *__m)) {
 ++__i;
+_LIBCPP_ASSERT_UNCATEGORIZED(
+__i != __last,
+"Would read out of bounds, does your comparator 
satisfy the strict-weak ordering requirement?");
+}
 // It is now known that a guard exists for downward moving __j
-while (!__comp(*--__j, *__m))
-;
+do {
+_LIBCPP_ASSERT_UNCATEGORIZED(
+__j != __first,
+"Would read out of bounds, does your comparator 
satisfy the strict-weak ordering requirement?");
+--__j;
+} while (!__comp(*__j, *__m));
 if (__i >= __j)
 break;
 _Ops::iter_swap(__i, __j);

>From 8e128c3ce6d8dc8afb94ba2465a2585fe3b8525a Mon Sep 17 00:00:00 2001
From: Daniel Kutenin 
Date: Thu, 21 Sep 2023 15:22:18 +0100
Subject: [PATCH 2/7] Update nth_element out of bound test

---
 .../assert.sort.invalid_comparator.pass.cpp   | 77 +++
 1 file changed, 61 insertions(+), 16 deletions(-)

diff --git 
a/libcxx/test/libcxx/algorithms/alg.sorting/assert.sort.invalid_comparator.pass.cpp
 
b/libcxx/test/libcxx/algorithms/alg.sorting/assert.sort.invalid_comparator.pass.cpp
index e5e417fe7bda2d4..b02ae2118ec5f47 100644
--- 
a/libcxx/test/libcxx/algorithms/alg.sorting/assert.sort.invalid_comparator.pass.cpp
+++ 
b/libcxx/test/libcxx/algorithms/alg.sorting/assert.sort.invalid_comparator.pass.cpp
@@ -50,27 +50,37 @@
 #include "bad_comparator_values.h"
 #include "check_assertion.h"
 
-void check_oob_sort_read() {
-std::map> comparison_results; // 
terrible for performance, but really convenient
-for (auto line : std::views::split(DATA, '\n') | 
std::views::filter([](auto const& line) { return !line.empty(); })) {
-auto values = std::views::split(line, ' ');
-auto it = values.begin();
-std::size_t left = std::stol(std::string((*it).data(), (*it).size()));
-it = std::next(it);
-std::size_t right = std::stol(std::string((*it).data(), (*it).size()));
-it = std::next(it);
-bool result = static_cast(std::stol(std::string((*it).data(), 
(*it).size(;
-comparison_results[left][right] = result;
-}
-auto predicate = [&](std::size_t* left, std::size_t* right) {
+class ComparisonResults {
+public:
+ComparisonResults(std::string_view data) {
+for (auto line : std::views::split(data, '\n') | 
std::views::filter([](auto const& line) { return !line.empty(); })) {
+auto values = std::views::split(line, ' ');
+auto it = values.begin();
+std::size_t left = std::stol(std::string((*it).data(), 
(*it).size()));
+it = std::next(it);
+std::size_t right = std::stol(std::string((*it).data(), 
(*it).size()));
+it = std::next(it);
+ 

[clang] [libc++] Add assertions for potential OOB reads in std::nth_element (PR #67023)

2023-10-18 Thread Daniel Kutenin via cfe-commits

https://github.com/danlark1 updated 
https://github.com/llvm/llvm-project/pull/67023

>From 059bbfab50592026ce2785c5f7d98eaf5c9f8bd6 Mon Sep 17 00:00:00 2001
From: Daniel Kutenin 
Date: Thu, 21 Sep 2023 14:55:11 +0100
Subject: [PATCH 1/7] Add bound checking in nth_element

---
 libcxx/include/__algorithm/nth_element.h | 28 +++-
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/__algorithm/nth_element.h 
b/libcxx/include/__algorithm/nth_element.h
index dbacf58f9ecdbc4..37e43ab0db8ca4f 100644
--- a/libcxx/include/__algorithm/nth_element.h
+++ b/libcxx/include/__algorithm/nth_element.h
@@ -116,10 +116,18 @@ __nth_element(_RandomAccessIterator __first, 
_RandomAccessIterator __nth, _Rando
 return;
 }
 while (true) {
-while (!__comp(*__first, *__i))
+while (!__comp(*__first, *__i)) {
 ++__i;
-while (__comp(*__first, *--__j))
-;
+_LIBCPP_ASSERT_UNCATEGORIZED(
+__i != __last,
+"Would read out of bounds, does your comparator 
satisfy the strict-weak ordering requirement?");
+}
+do {
+_LIBCPP_ASSERT_UNCATEGORIZED(
+__j != __first,
+"Would read out of bounds, does your comparator 
satisfy the strict-weak ordering requirement?");
+--__j;
+} while (__comp(*__first, *__j));
 if (__i >= __j)
 break;
 _Ops::iter_swap(__i, __j);
@@ -146,11 +154,19 @@ __nth_element(_RandomAccessIterator __first, 
_RandomAccessIterator __nth, _Rando
 while (true)
 {
 // __m still guards upward moving __i
-while (__comp(*__i, *__m))
+while (__comp(*__i, *__m)) {
 ++__i;
+_LIBCPP_ASSERT_UNCATEGORIZED(
+__i != __last,
+"Would read out of bounds, does your comparator 
satisfy the strict-weak ordering requirement?");
+}
 // It is now known that a guard exists for downward moving __j
-while (!__comp(*--__j, *__m))
-;
+do {
+_LIBCPP_ASSERT_UNCATEGORIZED(
+__j != __first,
+"Would read out of bounds, does your comparator 
satisfy the strict-weak ordering requirement?");
+--__j;
+} while (!__comp(*__j, *__m));
 if (__i >= __j)
 break;
 _Ops::iter_swap(__i, __j);

>From 8e128c3ce6d8dc8afb94ba2465a2585fe3b8525a Mon Sep 17 00:00:00 2001
From: Daniel Kutenin 
Date: Thu, 21 Sep 2023 15:22:18 +0100
Subject: [PATCH 2/7] Update nth_element out of bound test

---
 .../assert.sort.invalid_comparator.pass.cpp   | 77 +++
 1 file changed, 61 insertions(+), 16 deletions(-)

diff --git 
a/libcxx/test/libcxx/algorithms/alg.sorting/assert.sort.invalid_comparator.pass.cpp
 
b/libcxx/test/libcxx/algorithms/alg.sorting/assert.sort.invalid_comparator.pass.cpp
index e5e417fe7bda2d4..b02ae2118ec5f47 100644
--- 
a/libcxx/test/libcxx/algorithms/alg.sorting/assert.sort.invalid_comparator.pass.cpp
+++ 
b/libcxx/test/libcxx/algorithms/alg.sorting/assert.sort.invalid_comparator.pass.cpp
@@ -50,27 +50,37 @@
 #include "bad_comparator_values.h"
 #include "check_assertion.h"
 
-void check_oob_sort_read() {
-std::map> comparison_results; // 
terrible for performance, but really convenient
-for (auto line : std::views::split(DATA, '\n') | 
std::views::filter([](auto const& line) { return !line.empty(); })) {
-auto values = std::views::split(line, ' ');
-auto it = values.begin();
-std::size_t left = std::stol(std::string((*it).data(), (*it).size()));
-it = std::next(it);
-std::size_t right = std::stol(std::string((*it).data(), (*it).size()));
-it = std::next(it);
-bool result = static_cast(std::stol(std::string((*it).data(), 
(*it).size(;
-comparison_results[left][right] = result;
-}
-auto predicate = [&](std::size_t* left, std::size_t* right) {
+class ComparisonResults {
+public:
+ComparisonResults(std::string_view data) {
+for (auto line : std::views::split(data, '\n') | 
std::views::filter([](auto const& line) { return !line.empty(); })) {
+auto values = std::views::split(line, ' ');
+auto it = values.begin();
+std::size_t left = std::stol(std::string((*it).data(), 
(*it).size()));
+it = std::next(it);
+std::size_t right = std::stol(std::string((*it).data(), 
(*it).size()));
+it = std::next(it);
+ 

[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-10-18 Thread Simon Tatham via cfe-commits

https://github.com/statham-arm created 
https://github.com/llvm/llvm-project/pull/69447

This allows a YAML-based multilib configuration to specify explicitly that a 
subset of its library directories are alternatives to each other, i.e. at most 
one of that subset should be selected.

So if you have multiple sysroots each including a full set of headers and 
libraries, you can mark them as members of the same ExclusiveGroup, and then 
you'll be sure that only one of them is selected, even if two or more are 
compatible with the compile options.

This is particularly important in multilib setups including the libc++ headers, 
where selecting the include directories from two different sysroots can cause 
an actual build failure. This occurs when including , for example: 
libc++'s stdio.h is included first, and will try to use `#include_next` to 
fetch the underlying libc's version. But if there are two include directories 
from separate multilibs, then both of their C++ include directories will end up 
on the include path first, followed by both the C directories. So the 
`#include_next` from the first libc++ stdio.h will include the second libc++ 
stdio.h, which will do nothing because it has the same include guard macro, and 
the libc header won't ever be included at all.

If more than one of the options in an ExclusiveGroup matches the given flags, 
the last one wins.

>From 5b3289a7ad40850cbe1c438345a181b01c500639 Mon Sep 17 00:00:00 2001
From: Simon Tatham 
Date: Thu, 14 Sep 2023 14:51:17 +0100
Subject: [PATCH] [Driver] Add ExclusiveGroup feature to multilib.yaml.

This allows a YAML-based multilib configuration to specify explicitly
that a subset of its library directories are alternatives to each
other, i.e. at most one of that subset should be selected.

So if you have multiple sysroots each including a full set of headers
and libraries, you can mark them as members of the same
ExclusiveGroup, and then you'll be sure that only one of them is
selected, even if two or more are compatible with the compile options.

This is particularly important in multilib setups including the libc++
headers, where selecting the include directories from two different
sysroots can cause an actual build failure. This occurs when including
, for example: libc++'s stdio.h is included first, and will
try to use `#include_next` to fetch the underlying libc's version. But
if there are two include directories from separate multilibs, then
both of their C++ include directories will end up on the include path
first, followed by both the C directories. So the `#include_next` from
the first libc++ stdio.h will include the second libc++ stdio.h, which
will do nothing because it has the same include guard macro, and the
libc header won't ever be included at all.

If more than one of the options in an ExclusiveGroup matches the given
flags, the last one wins.
---
 clang/include/clang/Driver/Multilib.h | 15 +++-
 clang/lib/Driver/Multilib.cpp | 49 ++---
 .../baremetal-multilib-exclusive-group.yaml   | 69 +++
 3 files changed, 122 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/Driver/baremetal-multilib-exclusive-group.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index 1416559414f894b..46f23a2ff5fabac 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -39,13 +39,23 @@ class Multilib {
   std::string IncludeSuffix;
   flags_list Flags;
 
+  // Optionally, a multilib can be assigned a string tag indicating that it's
+  // part of a group of mutually exclusive possibilities. If two or more
+  // multilibs have the same non-empty value of ExclusiveGroup, then only the
+  // last matching one of them will be selected.
+  //
+  // Setting this to the empty string is a special case, indicating that the
+  // directory is not mutually exclusive with anything else.
+  std::string ExclusiveGroup;
+
 public:
   /// GCCSuffix, OSSuffix & IncludeSuffix will be appended directly to the
   /// sysroot string so they must either be empty or begin with a '/' 
character.
   /// This is enforced with an assert in the constructor.
   Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
StringRef IncludeSuffix = {},
-   const flags_list &Flags = flags_list());
+   const flags_list &Flags = flags_list(),
+   StringRef ExclusiveGroup = {});
 
   /// Get the detected GCC installation path suffix for the multi-arch
   /// target variant. Always starts with a '/', unless empty
@@ -63,6 +73,9 @@ class Multilib {
   /// All elements begin with either '-' or '!'
   const flags_list &flags() const { return Flags; }
 
+  /// Get the exclusive group label.
+  const std::string &exclusiveGroup() const { return ExclusiveGroup; }
+
   LLVM_DUMP_METHOD void dump() const;
   /// print summary of the Multilib
   void print(raw_ostream &OS) const;
diff --git a/clang/lib/

[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Simon Tatham (statham-arm)


Changes

This allows a YAML-based multilib configuration to specify explicitly that a 
subset of its library directories are alternatives to each other, i.e. at most 
one of that subset should be selected.

So if you have multiple sysroots each including a full set of headers and 
libraries, you can mark them as members of the same ExclusiveGroup, and then 
you'll be sure that only one of them is selected, even if two or more are 
compatible with the compile options.

This is particularly important in multilib setups including the libc++ headers, 
where selecting the include directories from two different sysroots can cause 
an actual build failure. This occurs when including , for 
example: libc++'s stdio.h is included first, and will try to use 
`#include_next` to fetch the underlying libc's version. But if there are two 
include directories from separate multilibs, then both of their C++ include 
directories will end up on the include path first, followed by both the C 
directories. So the `#include_next` from the first libc++ stdio.h will include 
the second libc++ stdio.h, which will do nothing because it has the same 
include guard macro, and the libc header won't ever be included at all.

If more than one of the options in an ExclusiveGroup matches the given flags, 
the last one wins.

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


3 Files Affected:

- (modified) clang/include/clang/Driver/Multilib.h (+14-1) 
- (modified) clang/lib/Driver/Multilib.cpp (+39-10) 
- (added) clang/test/Driver/baremetal-multilib-exclusive-group.yaml (+69) 


``diff
diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index 1416559414f894b..46f23a2ff5fabac 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -39,13 +39,23 @@ class Multilib {
   std::string IncludeSuffix;
   flags_list Flags;
 
+  // Optionally, a multilib can be assigned a string tag indicating that it's
+  // part of a group of mutually exclusive possibilities. If two or more
+  // multilibs have the same non-empty value of ExclusiveGroup, then only the
+  // last matching one of them will be selected.
+  //
+  // Setting this to the empty string is a special case, indicating that the
+  // directory is not mutually exclusive with anything else.
+  std::string ExclusiveGroup;
+
 public:
   /// GCCSuffix, OSSuffix & IncludeSuffix will be appended directly to the
   /// sysroot string so they must either be empty or begin with a '/' 
character.
   /// This is enforced with an assert in the constructor.
   Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
StringRef IncludeSuffix = {},
-   const flags_list &Flags = flags_list());
+   const flags_list &Flags = flags_list(),
+   StringRef ExclusiveGroup = {});
 
   /// Get the detected GCC installation path suffix for the multi-arch
   /// target variant. Always starts with a '/', unless empty
@@ -63,6 +73,9 @@ class Multilib {
   /// All elements begin with either '-' or '!'
   const flags_list &flags() const { return Flags; }
 
+  /// Get the exclusive group label.
+  const std::string &exclusiveGroup() const { return ExclusiveGroup; }
+
   LLVM_DUMP_METHOD void dump() const;
   /// print summary of the Multilib
   void print(raw_ostream &OS) const;
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index ba466af39e2dcaf..a8eff30f1416852 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -29,9 +29,10 @@ using namespace driver;
 using namespace llvm::sys;
 
 Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix,
-   StringRef IncludeSuffix, const flags_list &Flags)
+   StringRef IncludeSuffix, const flags_list &Flags,
+   StringRef ExclusiveGroup)
 : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix),
-  Flags(Flags) {
+  Flags(Flags), ExclusiveGroup(ExclusiveGroup) {
   assert(GCCSuffix.empty() ||
  (StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1));
   assert(OSSuffix.empty() ||
@@ -96,13 +97,39 @@ bool MultilibSet::select(const Multilib::flags_list &Flags,
  llvm::SmallVector &Selected) const {
   llvm::StringSet<> FlagSet(expandFlags(Flags));
   Selected.clear();
-  llvm::copy_if(Multilibs, std::back_inserter(Selected),
-[&FlagSet](const Multilib &M) {
-  for (const std::string &F : M.flags())
-if (!FlagSet.contains(F))
-  return false;
-  return true;
-});
+
+  // Decide which multilibs we're going to select at all
+  std::vector IsSelected(Multilibs.size(), false);
+  std::map ExclusiveGroupMembers;
+  for (size_t i = 0, e = Multilibs.size(); i < e; ++i) {
+co

[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-10-18 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 ebdb0cbef5e9be57237403c46bfdbe985313bb1c 
5b3289a7ad40850cbe1c438345a181b01c500639 -- 
clang/include/clang/Driver/Multilib.h clang/lib/Driver/Multilib.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index 46f23a2ff..6a9533e6d 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -53,8 +53,7 @@ public:
   /// sysroot string so they must either be empty or begin with a '/' 
character.
   /// This is enforced with an assert in the constructor.
   Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
-   StringRef IncludeSuffix = {},
-   const flags_list &Flags = flags_list(),
+   StringRef IncludeSuffix = {}, const flags_list &Flags = 
flags_list(),
StringRef ExclusiveGroup = {});
 
   /// Get the detected GCC installation path suffix for the multi-arch

``




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


[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-10-18 Thread Simon Tatham via cfe-commits

https://github.com/statham-arm updated 
https://github.com/llvm/llvm-project/pull/69447

>From 3a0481134343339ce8132419fde875ac9977b734 Mon Sep 17 00:00:00 2001
From: Simon Tatham 
Date: Thu, 14 Sep 2023 14:51:17 +0100
Subject: [PATCH] [Driver] Add ExclusiveGroup feature to multilib.yaml.

This allows a YAML-based multilib configuration to specify explicitly
that a subset of its library directories are alternatives to each
other, i.e. at most one of that subset should be selected.

So if you have multiple sysroots each including a full set of headers
and libraries, you can mark them as members of the same
ExclusiveGroup, and then you'll be sure that only one of them is
selected, even if two or more are compatible with the compile options.

This is particularly important in multilib setups including the libc++
headers, where selecting the include directories from two different
sysroots can cause an actual build failure. This occurs when including
, for example: libc++'s stdio.h is included first, and will
try to use `#include_next` to fetch the underlying libc's version. But
if there are two include directories from separate multilibs, then
both of their C++ include directories will end up on the include path
first, followed by both the C directories. So the `#include_next` from
the first libc++ stdio.h will include the second libc++ stdio.h, which
will do nothing because it has the same include guard macro, and the
libc header won't ever be included at all.

If more than one of the options in an ExclusiveGroup matches the given
flags, the last one wins.
---
 clang/include/clang/Driver/Multilib.h | 16 -
 clang/lib/Driver/Multilib.cpp | 49 ++---
 .../baremetal-multilib-exclusive-group.yaml   | 69 +++
 3 files changed, 122 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/Driver/baremetal-multilib-exclusive-group.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index 1416559414f894b..6a9533e6dd831f1 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -39,13 +39,22 @@ class Multilib {
   std::string IncludeSuffix;
   flags_list Flags;
 
+  // Optionally, a multilib can be assigned a string tag indicating that it's
+  // part of a group of mutually exclusive possibilities. If two or more
+  // multilibs have the same non-empty value of ExclusiveGroup, then only the
+  // last matching one of them will be selected.
+  //
+  // Setting this to the empty string is a special case, indicating that the
+  // directory is not mutually exclusive with anything else.
+  std::string ExclusiveGroup;
+
 public:
   /// GCCSuffix, OSSuffix & IncludeSuffix will be appended directly to the
   /// sysroot string so they must either be empty or begin with a '/' 
character.
   /// This is enforced with an assert in the constructor.
   Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
-   StringRef IncludeSuffix = {},
-   const flags_list &Flags = flags_list());
+   StringRef IncludeSuffix = {}, const flags_list &Flags = 
flags_list(),
+   StringRef ExclusiveGroup = {});
 
   /// Get the detected GCC installation path suffix for the multi-arch
   /// target variant. Always starts with a '/', unless empty
@@ -63,6 +72,9 @@ class Multilib {
   /// All elements begin with either '-' or '!'
   const flags_list &flags() const { return Flags; }
 
+  /// Get the exclusive group label.
+  const std::string &exclusiveGroup() const { return ExclusiveGroup; }
+
   LLVM_DUMP_METHOD void dump() const;
   /// print summary of the Multilib
   void print(raw_ostream &OS) const;
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index ba466af39e2dcaf..a8eff30f1416852 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -29,9 +29,10 @@ using namespace driver;
 using namespace llvm::sys;
 
 Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix,
-   StringRef IncludeSuffix, const flags_list &Flags)
+   StringRef IncludeSuffix, const flags_list &Flags,
+   StringRef ExclusiveGroup)
 : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix),
-  Flags(Flags) {
+  Flags(Flags), ExclusiveGroup(ExclusiveGroup) {
   assert(GCCSuffix.empty() ||
  (StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1));
   assert(OSSuffix.empty() ||
@@ -96,13 +97,39 @@ bool MultilibSet::select(const Multilib::flags_list &Flags,
  llvm::SmallVector &Selected) const {
   llvm::StringSet<> FlagSet(expandFlags(Flags));
   Selected.clear();
-  llvm::copy_if(Multilibs, std::back_inserter(Selected),
-[&FlagSet](const Multilib &M) {
-  for (const std::string &F : M.flags())
-if (!FlagSet.contains(F))
-  return false;
-  return true

[clang] [clang] Bail out if the result of function template instantiation is not a function. (PR #69449)

2023-10-18 Thread via cfe-commits

https://github.com/VitaNuo created 
https://github.com/llvm/llvm-project/pull/69449

None

>From 27dc15e7467afa7bc4ee17a907a088e59719ca5d Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Wed, 18 Oct 2023 10:18:43 +
Subject: [PATCH] [clang] Bail out if the result of function template
 instantiation is not a function.

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  4 +++-
 .../function-decl-nested-type-alias.cpp   | 15 +++
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaTemplate/function-decl-nested-type-alias.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 3b1731edec95237..fd4dbcd2cd80587 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2649,7 +2649,9 @@ TypeSourceInfo 
*Sema::SubstFunctionDeclType(TypeSourceInfo *T,
   } else {
 Result = Instantiator.TransformType(TLB, TL);
   }
-  if (Result.isNull())
+  // When clang goes into recovery mode, it substitutes the incorrect function
+  // type with a primitive (e.g., int).
+  if (Result.isNull() || !Result->isFunctionType())
 return nullptr;
 
   return TLB.getTypeSourceInfo(Context, Result);
diff --git a/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp 
b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
new file mode 100644
index 000..45e03b3c6ba850c
--- /dev/null
+++ b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -std=c++14 -fsyntax-only -verify %s
+
+template 
+using Type = typename A::NestedType; // expected-error {{type 'float' cannot 
be used prior to '::' because it has no members}}
+
+template 
+void Func() {
+  using MyType = Type(); // expected-note{{in instantiation of template 
type alias 'Type' requested here}}
+  MyType var;
+}
+
+void Test() {
+  Func(); // expected-note{{in instantiation of function template 
specialization 'Func' requested here}}
+}
+

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


[clang] [clang] Bail out if the result of function template instantiation is not a function. (PR #69449)

2023-10-18 Thread via cfe-commits

https://github.com/VitaNuo updated 
https://github.com/llvm/llvm-project/pull/69449

>From 27dc15e7467afa7bc4ee17a907a088e59719ca5d Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Wed, 18 Oct 2023 10:18:43 +
Subject: [PATCH 1/2] [clang] Bail out if the result of function template
 instantiation is not a function.

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  4 +++-
 .../function-decl-nested-type-alias.cpp   | 15 +++
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaTemplate/function-decl-nested-type-alias.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 3b1731edec95237..fd4dbcd2cd80587 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2649,7 +2649,9 @@ TypeSourceInfo 
*Sema::SubstFunctionDeclType(TypeSourceInfo *T,
   } else {
 Result = Instantiator.TransformType(TLB, TL);
   }
-  if (Result.isNull())
+  // When clang goes into recovery mode, it substitutes the incorrect function
+  // type with a primitive (e.g., int).
+  if (Result.isNull() || !Result->isFunctionType())
 return nullptr;
 
   return TLB.getTypeSourceInfo(Context, Result);
diff --git a/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp 
b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
new file mode 100644
index 000..45e03b3c6ba850c
--- /dev/null
+++ b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -std=c++14 -fsyntax-only -verify %s
+
+template 
+using Type = typename A::NestedType; // expected-error {{type 'float' cannot 
be used prior to '::' because it has no members}}
+
+template 
+void Func() {
+  using MyType = Type(); // expected-note{{in instantiation of template 
type alias 'Type' requested here}}
+  MyType var;
+}
+
+void Test() {
+  Func(); // expected-note{{in instantiation of function template 
specialization 'Func' requested here}}
+}
+

>From a766065301f0e35d5e769c96b46bc1eba8550423 Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Wed, 18 Oct 2023 10:18:43 +
Subject: [PATCH 2/2] [clang] Bail out if the result of function template
 instantiation is not a function.

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fd4dbcd2cd80587..273ab66ead6741e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2649,8 +2649,8 @@ TypeSourceInfo 
*Sema::SubstFunctionDeclType(TypeSourceInfo *T,
   } else {
 Result = Instantiator.TransformType(TLB, TL);
   }
-  // When clang goes into recovery mode, it substitutes the incorrect function
-  // type with a primitive (e.g., int).
+  // When clang goes into recovery mode, it might substitute
+  // the incorrect function type with a primitive (e.g., int).
   if (Result.isNull() || !Result->isFunctionType())
 return nullptr;
 

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


[clang] [AMDGPU] Remove Code Object V3 (PR #67118)

2023-10-18 Thread Andrew Stubbs via cfe-commits

ams-cs wrote:

We're discussing replacing the devices with something newer, but there are 
practical and business issues with that, so no hard plans. Sorry.

I'm leaning toward officially deprecating Fiji for GCC 14, and remove it from 
GCC 15 (so, sometime next year). If we can get these devices replaced then it 
can happen sooner. For release branches we can document a fixed LLVM version to 
use, so it's only really the mainline development branch that is the problem.

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


[clang-tools-extra] [run-clang-tidy] Add option -export-directory (PR #69453)

2023-10-18 Thread Amadeus Gebauer via cfe-commits

https://github.com/amgebauer created 
https://github.com/llvm/llvm-project/pull/69453

Adding an additional parameter to run_clang_tidy.py to accept a directory where 
the clang-tidy fixes are saved to. This directory can then be used to run 
`clang-apply-replacements`.

>From fd908df80b14933c849e498769cff6152276c2c3 Mon Sep 17 00:00:00 2001
From: Amadeus Gebauer 
Date: Wed, 18 Oct 2023 14:02:44 +0200
Subject: [PATCH] [run-clang-tidy] Add option -export-directory

---
 .../clang-tidy/tool/run-clang-tidy.py | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py 
b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index 312d9241cfa57c5..b8d482809e293a5 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -372,6 +372,11 @@ def main():
 default=None,
 help="Upgrades warnings to errors. Same format as " "'-checks'",
 )
+parser.add_argument(
+"-export-directory",
+default=None,
+help="Path to the export directory. Within this directory, a file with 
the fixes will be created for every compilation unit.",
+)
 args = parser.parse_args()
 
 db_path = "compile_commands.json"
@@ -384,15 +389,17 @@ def main():
 
 clang_tidy_binary = find_binary(args.clang_tidy_binary, "clang-tidy", 
build_path)
 
-tmpdir = None
 if args.fix:
 clang_apply_replacements_binary = find_binary(
 args.clang_apply_replacements_binary, "clang-apply-replacements", 
build_path
 )
 
-if args.fix or (yaml and args.export_fixes):
+tmpdir = args.export_directory
+if tmpdir is None and (args.fix or (yaml and args.export_fixes)):
 tmpdir = tempfile.mkdtemp()
 
+delete_temporary_directory = args.export_directory is None and tmpdir is 
not None
+
 try:
 invocation = get_tidy_invocation(
 "",
@@ -474,7 +481,7 @@ def main():
 # This is a sad hack. Unfortunately subprocess goes
 # bonkers with ctrl-c and we start forking merrily.
 print("\nCtrl-C detected, goodbye.")
-if tmpdir:
+if tmpdir and delete_temporary_directory:
 shutil.rmtree(tmpdir)
 os.kill(0, 9)
 
@@ -496,7 +503,7 @@ def main():
 traceback.print_exc()
 return_code = 1
 
-if tmpdir:
+if tmpdir and delete_temporary_directory:
 shutil.rmtree(tmpdir)
 sys.exit(return_code)
 

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


[clang-tools-extra] [run-clang-tidy] Add option -export-directory (PR #69453)

2023-10-18 Thread Amadeus Gebauer via cfe-commits

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


[clang] [clang] [unittest] Add a test for Generic_GCC::GCCVersion::Parse (PR #69078)

2023-10-18 Thread Timm Baeder via cfe-commits

tbaederr wrote:

This doesn't build for me locally:
```
mold: error: undefined symbol: 
tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/GCCVersionTest.cpp.o:
 clang::driver::toolchains::Generic_GCC::GCCVersion::Parse(llvm::StringRef)
```

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


[clang] 66c9915 - [clang][Interp][NFC] Remove from(Boolean) overload

2023-10-18 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-10-18T14:23:29+02:00
New Revision: 66c99154a130553a50e499d898ef1fba5b755dcf

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

LOG: [clang][Interp][NFC] Remove from(Boolean) overload

This code is unused now that we have special casts from/to IntAP(S).

Added: 


Modified: 
clang/lib/AST/Interp/IntegralAP.h
clang/test/AST/Interp/intap.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index f17fb8e484415d2..fd120944a25043e 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -29,7 +29,6 @@ namespace interp {
 using APInt = llvm::APInt;
 using APSInt = llvm::APSInt;
 template  class Integral;
-class Boolean;
 
 template  class IntegralAP final {
 private:
@@ -104,10 +103,6 @@ template  class IntegralAP final {
 assert(Copy.isSigned() == Signed);
 return IntegralAP(Copy);
   }
-  static IntegralAP from(const Boolean &B) {
-assert(false);
-return IntegralAP::zero();
-  }
 
   static IntegralAP zero() {
 assert(false);

diff  --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index f9cbc698a3290d8..ef7a0d4f0dfdab0 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -42,6 +42,9 @@ namespace i128 {
  // ref-note {{outside the range}}
   constexpr int128_t Two = (int128_t)1 << 1ul;
   static_assert(Two == 2, "");
+  static_assert(Two, "");
+  constexpr bool CastedToBool = Two;
+  static_assert(CastedToBool, "");
 
   constexpr uint128_t AllOnes = ~static_cast(0);
   static_assert(AllOnes == UINT128_MAX, "");



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


[clang] [clang][Interp] IntegralAP zero-init (PR #68081)

2023-10-18 Thread Timm Baeder via cfe-commits


@@ -100,12 +100,13 @@ template  class IntegralAP final {
   }
   static IntegralAP from(const Boolean &B) {
 assert(false);
-return IntegralAP::zero();
+return IntegralAP::zero(1);

tbaederr wrote:

Removed that code in 
https://github.com/llvm/llvm-project/commit/66c99154a130553a50e499d898ef1fba5b755dcf.

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


[clang] [clang] [unittest] Add a test for Generic_GCC::GCCVersion::Parse (PR #69078)

2023-10-18 Thread Alex Bradbury via cfe-commits

asb wrote:

@tbaederr Just came to report the same thing!

@mstorsjo This broke builds that use `-DBUILD_SHARED_LIBS=True`. The problem 
seems to be that the `Generic_GCC` class has the `LLVM_LIBRARY_VISIBILITY` 
attribute meaning the 
`clang::driver::toolchains::Generic_GCC::GCCVersion::Parse(llvm::StringRef)` 
symbol is hidden. Removing that attribute fixes the build. It would be good for 
someone more familiar with this part of the codebase to confirm if that's an 
acceptable fix however.

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


[clang] [clang][Interp] IntegralAP zero-init (PR #68081)

2023-10-18 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/68081

>From d6b0b306353fb2d8eaef6835f6313277eaf94bbd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 3 Oct 2023 11:05:27 +0200
Subject: [PATCH] [clang][Interp] IntegralAP zero-init

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp |  4 ++--
 clang/lib/AST/Interp/IntegralAP.h| 11 ++-
 clang/lib/AST/Interp/Interp.h| 10 ++
 clang/lib/AST/Interp/Opcodes.td  | 15 ++-
 clang/test/AST/Interp/intap.cpp  | 15 +++
 5 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e9e20b222d5d34f..d9389e7b0033191 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1665,9 +1665,9 @@ bool 
ByteCodeExprGen::visitZeroInitializer(PrimType T, QualType QT,
   case PT_Uint64:
 return this->emitZeroUint64(E);
   case PT_IntAP:
+return this->emitZeroIntAP(Ctx.getBitWidth(QT), E);
   case PT_IntAPS:
-assert(false);
-return false;
+return this->emitZeroIntAPS(Ctx.getBitWidth(QT), E);
   case PT_Ptr:
 return this->emitNullPtr(E);
   case PT_FnPtr:
diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index fd120944a25043e..ebf362238ba09d5 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -78,7 +78,8 @@ template  class IntegralAP final {
 
   template  static IntegralAP from(T Value, unsigned NumBits = 0) {
 assert(NumBits > 0);
-APSInt Copy = APSInt(APInt(NumBits, static_cast(Value), Signed), 
!Signed);
+APSInt Copy =
+APSInt(APInt(NumBits, static_cast(Value), Signed), !Signed);
 
 return IntegralAP(Copy);
   }
@@ -97,16 +98,16 @@ template  class IntegralAP final {
   template 
   static IntegralAP from(Integral I, unsigned BitWidth) {
 APSInt Copy =
-APSInt(APInt(BitWidth, static_cast(I), InputSigned), !Signed);
+APSInt(APInt(BitWidth, static_cast(I), InputSigned), 
!Signed);
 Copy.setIsSigned(Signed);
 
 assert(Copy.isSigned() == Signed);
 return IntegralAP(Copy);
   }
 
-  static IntegralAP zero() {
-assert(false);
-return IntegralAP(0);
+  static IntegralAP zero(int32_t BitWidth) {
+APSInt V = APSInt(APInt(BitWidth, 0LL, Signed), !Signed);
+return IntegralAP(V);
   }
 
   constexpr unsigned bitWidth() const { return V.getBitWidth(); }
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 3d226a40f9cf608..4b081301655cfb2 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1688,6 +1688,16 @@ bool Zero(InterpState &S, CodePtr OpPC) {
   return true;
 }
 
+static inline bool ZeroIntAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth) {
+  S.Stk.push>(IntegralAP::zero(BitWidth));
+  return true;
+}
+
+static inline bool ZeroIntAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth) 
{
+  S.Stk.push>(IntegralAP::zero(BitWidth));
+  return true;
+}
+
 template ::T>
 inline bool Null(InterpState &S, CodePtr OpPC) {
   S.Stk.push();
diff --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 9d390fed152417f..e1e7e5e2efbb059 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -72,6 +72,11 @@ def IntegerTypeClass : TypeClass {
Uint32, Sint64, Uint64, IntAP, IntAPS];
 }
 
+def FixedSizeIntegralTypeClass : TypeClass {
+  let Types = [Sint8, Uint8, Sint16, Uint16, Sint32,
+   Uint32, Sint64, Uint64, Bool];
+}
+
 def NumberTypeClass : TypeClass {
   let Types = !listconcat(IntegerTypeClass.Types, [Float]);
 }
@@ -243,10 +248,18 @@ def ConstBool : ConstOpcode;
 
 // [] -> [Integer]
 def Zero : Opcode {
-  let Types = [AluTypeClass];
+  let Types = [FixedSizeIntegralTypeClass];
   let HasGroup = 1;
 }
 
+def ZeroIntAP : Opcode {
+  let Args = [ArgUint32];
+}
+
+def ZeroIntAPS : Opcode {
+  let Args = [ArgUint32];
+}
+
 // [] -> [Pointer]
 def Null : Opcode {
   let Types = [PtrTypeClass];
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index ef7a0d4f0dfdab0..27fae1b904351ce 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -17,6 +17,16 @@ constexpr MaxBitInt A_ = 0;
 constexpr MaxBitInt B_ = A_ + 1;
 static_assert(B_ == 1, "");
 
+constexpr MaxBitInt BitIntZero{};
+static_assert(BitIntZero == 0, "");
+constexpr unsigned _BitInt(128) UBitIntZero{};
+static_assert(UBitIntZero == 0, "");
+
+constexpr _BitInt(2) BitIntZero2{};
+static_assert(BitIntZero2 == 0, "");
+constexpr unsigned _BitInt(1) UBitIntZero1{};
+static_assert(UBitIntZero1 == 0, "");
+
 
 #ifdef __SIZEOF_INT128__
 namespace i128 {
@@ -49,6 +59,11 @@ namespace i128 {
   constexpr uint128_t AllOnes = ~static_cast(0);
   static_assert(AllOnes == UINT128_MAX, "");
 
+  constexpr uint128_t i128Zero{};
+  

[PATCH] D151197: [Clang][SVE2p1] Add svpsel builtins

2023-10-18 Thread Caroline via Phabricator via cfe-commits
CarolineConcatto updated this revision to Diff 557756.
CarolineConcatto added a comment.

-Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151197/new/

https://reviews.llvm.org/D151197

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel.c

Index: clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel.c
@@ -0,0 +1,165 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu \
+// RUN:   -target-feature +sve2p1 -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu \
+// RUN:   -target-feature +sve2p1 -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+// CHECK-LABEL: @test_svpsel_lane_b8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ADD:%.*]] = add i32 [[IDX:%.*]], 15
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.psel.nxv16i1( [[P1:%.*]],  [[P2:%.*]], i32 [[ADD]])
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z19test_svpsel_lane_b8u10__SVBool_tu10__SVBool_tj(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[ADD:%.*]] = add i32 [[IDX:%.*]], 15
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.psel.nxv16i1( [[P1:%.*]],  [[P2:%.*]], i32 [[ADD]])
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svbool_t test_svpsel_lane_b8(svbool_t p1, svbool_t p2, uint32_t idx) {
+  return svpsel_lane_b8(p1, p2, idx + 15);
+}
+
+// CHECK-LABEL: @test_svpsel_lane_b16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ADD:%.*]] = add i32 [[IDX:%.*]], 7
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[P2:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.psel.nxv8i1( [[P1:%.*]],  [[TMP0]], i32 [[ADD]])
+// CHECK-NEXT:ret  [[TMP1]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svpsel_lane_b16u10__SVBool_tu10__SVBool_tj(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[ADD:%.*]] = add i32 [[IDX:%.*]], 7
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[P2:%.*]])
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.psel.nxv8i1( [[P1:%.*]],  [[TMP0]], i32 [[ADD]])
+// CPP-CHECK-NEXT:ret  [[TMP1]]
+//
+svbool_t test_svpsel_lane_b16(svbool_t p1, svbool_t p2, uint32_t idx) {
+  return svpsel_lane_b16(p1, p2, idx + 7);
+}
+
+// CHECK-LABEL: @test_svpsel_lane_b32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ADD:%.*]] = add i32 [[IDX:%.*]], 3
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv4i1( [[P2:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.psel.nxv4i1( [[P1:%.*]],  [[TMP0]], i32 [[ADD]])
+// CHECK-NEXT:ret  [[TMP1]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svpsel_lane_b32u10__SVBool_tu10__SVBool_tj(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[ADD:%.*]] = add i32 [[IDX:%.*]], 3
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv4i1( [[P2:%.*]])
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.psel.nxv4i1( [[P1:%.*]],  [[TMP0]], i32 [[ADD]])
+// CPP-CHECK-NEXT:ret  [[TMP1]]
+//
+svbool_t test_svpsel_lane_b32(svbool_t p1, svbool_t p2, uint32_t idx) {
+  return svpsel_lane_b32(p1, p2, idx + 3);
+}
+
+// CHECK-LABEL: @test_svpsel_lane_b64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ADD:%.*]] = add i32 [[IDX:%.*]], 1
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[P2:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.psel.nxv2i1( [[P1:%.*]],  [[TMP0]], i32 [[ADD]])
+// CHECK-NEXT:ret  [[TMP1]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svpsel_lane_b64u10__SVBool_tu10__SVBool_tj(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[ADD:%.*]] = add i32 [[IDX:%.*]], 1
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[P2:%.*]])
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.psel.nxv2i1( [[P1:%.*]],  [[TMP0]], i32 [[ADD]])
+// CPP-CHECK-NEXT:ret  [[TMP1]]
+//
+svbool_t test_svpsel_lane_b64(svbool_t p1, svbool_t p2, uint32_t idx) {
+  return svpsel_lane_b64(p1, p2, idx + 1);
+}
+
+// CHECK-LABEL: @test_svpsel_lane_c8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ADD:%.*]] = add i32 [[IDX:%.*]], 15
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.to.svbool.taarch64.svcountt(target("aarch64.svcount") [[P1:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.psel.nx

[clang] [clang] [unittest] Add a test for Generic_GCC::GCCVersion::Parse (PR #69078)

2023-10-18 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> @tbaederr Just came to report the same thing!
> 
> @mstorsjo This broke builds that use `-DBUILD_SHARED_LIBS=True`.

Thanks! That was my guess as well, I was running a build with that enabled to 
try to reproduce @tbaederr 's issue.

> The problem seems to be that the `Generic_GCC` class has the 
> `LLVM_LIBRARY_VISIBILITY` attribute meaning the 
> `clang::driver::toolchains::Generic_GCC::GCCVersion::Parse(llvm::StringRef)` 
> symbol is hidden. Removing that attribute fixes the build. It would be good 
> for someone more familiar with this part of the codebase to confirm if that's 
> an acceptable fix however.

Thanks for the analysis! I guess that sounds reasonable, although I wonder how 
these unit test, that test internals within libclang are meant to work in this 
configuration. The number of extra exported symbols by removing 
`LLVM_LIBRARY_VISIBILITY` probably isn't that bad, I wonder if it has other 
implications wrt ABI of the shared libs?

I guess it's safest to revert this for now, so we can figure out the best path 
forward here without a rush?

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


[clang] 1072b94 - Revert "[clang] [unittest] Add a test for Generic_GCC::GCCVersion::Parse (#69078)"

2023-10-18 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2023-10-18T15:42:18+03:00
New Revision: 1072b94ed8e5a051100557185cb384364850635a

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

LOG: Revert "[clang] [unittest] Add a test for Generic_GCC::GCCVersion::Parse 
(#69078)"

This reverts commit b4b35a5d2b4ee26bf79b8a92715dd200f3f9cc49.

That commit broke builds with -DBUILD_SHARED_LIBS=ON. The reason
is that clang::driver::toolchains::Generic_GCC::GCCVersion::Parse
isn't visible outside of the shared library, because
the Generic_GCC class is marked with LLVM_LIBRARY_VISIBILITY.

Added: 


Modified: 
clang/unittests/Driver/CMakeLists.txt

Removed: 
clang/unittests/Driver/GCCVersionTest.cpp



diff  --git a/clang/unittests/Driver/CMakeLists.txt 
b/clang/unittests/Driver/CMakeLists.txt
index 752037f78fb147d..e37c158d7137a88 100644
--- a/clang/unittests/Driver/CMakeLists.txt
+++ b/clang/unittests/Driver/CMakeLists.txt
@@ -9,7 +9,6 @@ set(LLVM_LINK_COMPONENTS
 add_clang_unittest(ClangDriverTests
   DistroTest.cpp
   DXCModeTest.cpp
-  GCCVersionTest.cpp
   ToolChainTest.cpp
   ModuleCacheTest.cpp
   MultilibBuilderTest.cpp

diff  --git a/clang/unittests/Driver/GCCVersionTest.cpp 
b/clang/unittests/Driver/GCCVersionTest.cpp
deleted file mode 100644
index 9ae335bca77dc12..000
--- a/clang/unittests/Driver/GCCVersionTest.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-//===- unittests/Driver/GCCVersionTest.cpp --- GCCVersion parser tests 
===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// Unit tests for Generic_GCC::GCCVersion
-//
-//===--===//
-
-#include "../../lib/Driver/ToolChains/Gnu.h"
-#include "gtest/gtest.h"
-
-using namespace clang;
-using namespace clang::driver;
-
-namespace {
-
-struct VersionParseTest {
-  std::string Text;
-
-  int Major, Minor, Patch;
-  std::string MajorStr, MinorStr, PatchSuffix;
-};
-
-const VersionParseTest TestCases[] = {
-{"5", 5, -1, -1, "5", "", ""},
-{"4.4", 4, 4, -1, "4", "4", ""},
-{"4.4-patched", 4, 4, -1, "4", "4", "-patched"},
-{"4.4.0", 4, 4, 0, "4", "4", ""},
-{"4.4.x", 4, 4, -1, "4", "4", ""},
-{"4.4.2-rc4", 4, 4, 2, "4", "4", "-rc4"},
-{"4.4.x-patched", 4, 4, -1, "4", "4", ""},
-{"not-a-version", -1, -1, -1, "", "", ""},
-};
-
-TEST(GCCVersionTest, Parse) {
-  for (const auto &TC : TestCases) {
-auto V = toolchains::Generic_GCC::GCCVersion::Parse(TC.Text);
-EXPECT_EQ(V.Text, TC.Text);
-EXPECT_EQ(V.Major, TC.Major);
-EXPECT_EQ(V.Minor, TC.Minor);
-EXPECT_EQ(V.Patch, TC.Patch);
-EXPECT_EQ(V.MajorStr, TC.MajorStr);
-EXPECT_EQ(V.MinorStr, TC.MinorStr);
-EXPECT_EQ(V.PatchSuffix, TC.PatchSuffix);
-  }
-}
-
-} // end anonymous namespace



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


[clang-tools-extra] [run-clang-tidy] Add option -export-directory (PR #69453)

2023-10-18 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

There is already --export_fixes that can be used in +- same way.
Maybe better would be to change --export_fixes to take filename or directory 
(ends with / or exist as directory), and in that case it could save to 
directory or merge to single file.

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


[clang] [HIP] Document func ptr and virtual func (PR #68126)

2023-10-18 Thread Siu Chi Chan via cfe-commits

scchan wrote:

LGTM thanks

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


[clang] [clang] Bail out if the result of function template instantiation is not a function type. (PR #69459)

2023-10-18 Thread via cfe-commits

https://github.com/VitaNuo created 
https://github.com/llvm/llvm-project/pull/69459

…not a function.

>From d8305b64a464e5cd992c836ef13d452f62235442 Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Wed, 18 Oct 2023 12:55:04 +
Subject: [PATCH] [clang] Bail out if the result of function template
 instantiation is not a function.

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  4 +++-
 .../function-decl-nested-type-alias.cpp| 14 ++
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaTemplate/function-decl-nested-type-alias.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 23de64080a070ca..dfd7cc284eb6b73 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2662,7 +2662,9 @@ TypeSourceInfo 
*Sema::SubstFunctionDeclType(TypeSourceInfo *T,
   } else {
 Result = Instantiator.TransformType(TLB, TL);
   }
-  if (Result.isNull())
+  // When clang goes into recovery mode, it might substitute
+  // the incorrect function type with a primitive (e.g., int).
+  if (Result.isNull() || !Result->isFunctionType())
 return nullptr;
 
   return TLB.getTypeSourceInfo(Context, Result);
diff --git a/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp 
b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
new file mode 100644
index 000..139706f73d24dba
--- /dev/null
+++ b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -x c++ -std=c++14 -fsyntax-only -verify %s
+
+template 
+using Type = typename A::NestedType; // expected-error {{type 'float' cannot 
be used prior to '::' because it has no members}}
+
+template 
+void Func() {
+  using MyType = Type(); // expected-note {{in instantiation of template 
type alias 'Type' requested here}}
+  MyType var;
+}
+
+void Test() {
+  Func(); // expected-note {{in instantiation of function template 
specialization 'Func' requested here}}
+}
\ No newline at end of file

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


[clang] [clang] Bail out if the result of function template instantiation is not a function type. (PR #69459)

2023-10-18 Thread via cfe-commits

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


[clang] [clang] Bail out if the result of function template instantiation is not a function. (PR #69449)

2023-10-18 Thread Sam McCall via cfe-commits

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


[clang] [clang] Bail out if the result of function template instantiation is not a function. (PR #69449)

2023-10-18 Thread Sam McCall via cfe-commits

https://github.com/sam-mccall approved this pull request.

Thanks! Looks great, just comment nits

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


[clang] [clang] Bail out if the result of function template instantiation is not a function. (PR #69449)

2023-10-18 Thread Sam McCall via cfe-commits


@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -std=c++14 -fsyntax-only -verify %s
+
+template 
+using Type = typename A::NestedType; // expected-error {{type 'float' cannot 
be used prior to '::' because it has no members}}
+
+template 
+void Func() {
+  using MyType = Type(); // expected-note{{in instantiation of template 
type alias 'Type' requested here}}
+  MyType var;

sam-mccall wrote:

// This is a function declaration, not a variable declaration!
// After substitution, we do not have a valid function type, and used to crash.

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


[clang] [clang] Bail out if the result of function template instantiation is not a function. (PR #69449)

2023-10-18 Thread Sam McCall via cfe-commits


@@ -2649,7 +2649,9 @@ TypeSourceInfo 
*Sema::SubstFunctionDeclType(TypeSourceInfo *T,
   } else {
 Result = Instantiator.TransformType(TLB, TL);
   }
-  if (Result.isNull())
+  // When clang goes into recovery mode, it might substitute

sam-mccall wrote:

Not sure "recovery mode" is well-defined enough to refer to in this way

maybe:
When there are errors resolving types, clang may use IntTy as a fallback, 
breaking our assumption that function declarations have function types.

(I thought there was a name for this usage of IntTy but I can't find one. It 
happens e.g. at GetFullTypeForDeclarator, SemaType.cpp:5734)

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


[PATCH] D151307: [Clang][SVE2.1] Add svwhile (predicate-as-counter) builtins

2023-10-18 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin accepted this revision.
kmclaughlin added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151307/new/

https://reviews.llvm.org/D151307

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


[clang] [clang] Bail out if the result of function template instantiation is not a function type. (PR #69459)

2023-10-18 Thread via cfe-commits

https://github.com/VitaNuo updated 
https://github.com/llvm/llvm-project/pull/69459

>From d8305b64a464e5cd992c836ef13d452f62235442 Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Wed, 18 Oct 2023 12:55:04 +
Subject: [PATCH 1/2] [clang] Bail out if the result of function template
 instantiation is not a function.

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  4 +++-
 .../function-decl-nested-type-alias.cpp| 14 ++
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaTemplate/function-decl-nested-type-alias.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 23de64080a070ca..dfd7cc284eb6b73 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2662,7 +2662,9 @@ TypeSourceInfo 
*Sema::SubstFunctionDeclType(TypeSourceInfo *T,
   } else {
 Result = Instantiator.TransformType(TLB, TL);
   }
-  if (Result.isNull())
+  // When clang goes into recovery mode, it might substitute
+  // the incorrect function type with a primitive (e.g., int).
+  if (Result.isNull() || !Result->isFunctionType())
 return nullptr;
 
   return TLB.getTypeSourceInfo(Context, Result);
diff --git a/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp 
b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
new file mode 100644
index 000..139706f73d24dba
--- /dev/null
+++ b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -x c++ -std=c++14 -fsyntax-only -verify %s
+
+template 
+using Type = typename A::NestedType; // expected-error {{type 'float' cannot 
be used prior to '::' because it has no members}}
+
+template 
+void Func() {
+  using MyType = Type(); // expected-note {{in instantiation of template 
type alias 'Type' requested here}}
+  MyType var;
+}
+
+void Test() {
+  Func(); // expected-note {{in instantiation of function template 
specialization 'Func' requested here}}
+}
\ No newline at end of file

>From 4d9b1a68e9c7396951b08e816236e0aa6ff705ce Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Wed, 18 Oct 2023 13:06:09 +
Subject: [PATCH 2/2] [clang] Add comments.

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp  | 4 ++--
 clang/test/SemaTemplate/function-decl-nested-type-alias.cpp | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index dfd7cc284eb6b73..d7d5ce19b75a965 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2662,8 +2662,8 @@ TypeSourceInfo 
*Sema::SubstFunctionDeclType(TypeSourceInfo *T,
   } else {
 Result = Instantiator.TransformType(TLB, TL);
   }
-  // When clang goes into recovery mode, it might substitute
-  // the incorrect function type with a primitive (e.g., int).
+  // When there are errors resolving types, clang may use IntTy as a fallback,
+  // breaking our assumption that function declarations have function types.
   if (Result.isNull() || !Result->isFunctionType())
 return nullptr;
 
diff --git a/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp 
b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
index 139706f73d24dba..4bca990f69046b5 100644
--- a/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
+++ b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
@@ -6,6 +6,8 @@ using Type = typename A::NestedType; // expected-error {{type 
'float' cannot be
 template 
 void Func() {
   using MyType = Type(); // expected-note {{in instantiation of template 
type alias 'Type' requested here}}
+  // This is a function declaration, not a variable declaration!
+  // After substitution, we do not have a valid function type, and used to 
crash.
   MyType var;
 }
 

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


[clang] [clang][Interp] IntegralAP zero-init (PR #68081)

2023-10-18 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


[clang] [clang] Bail out if the result of function template instantiation is not a function type. (PR #69459)

2023-10-18 Thread via cfe-commits

VitaNuo wrote:

This is the same as the approved 
https://github.com/llvm/llvm-project/pull/69449. 

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


[clang] 00f34ee - [clang] Bail out if the result of function template instantiation is not a function type. (#69459)

2023-10-18 Thread via cfe-commits

Author: VitaNuo
Date: 2023-10-18T15:22:40+02:00
New Revision: 00f34eefe4ed04c95eb60074ddfdd64e65878be9

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

LOG: [clang] Bail out if the result of function template instantiation is not a 
function type. (#69459)

Added: 
clang/test/SemaTemplate/function-decl-nested-type-alias.cpp

Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 23de64080a070ca..d7d5ce19b75a965 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2662,7 +2662,9 @@ TypeSourceInfo 
*Sema::SubstFunctionDeclType(TypeSourceInfo *T,
   } else {
 Result = Instantiator.TransformType(TLB, TL);
   }
-  if (Result.isNull())
+  // When there are errors resolving types, clang may use IntTy as a fallback,
+  // breaking our assumption that function declarations have function types.
+  if (Result.isNull() || !Result->isFunctionType())
 return nullptr;
 
   return TLB.getTypeSourceInfo(Context, Result);

diff  --git a/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp 
b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
new file mode 100644
index 000..4bca990f69046b5
--- /dev/null
+++ b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -x c++ -std=c++14 -fsyntax-only -verify %s
+
+template 
+using Type = typename A::NestedType; // expected-error {{type 'float' cannot 
be used prior to '::' because it has no members}}
+
+template 
+void Func() {
+  using MyType = Type(); // expected-note {{in instantiation of template 
type alias 'Type' requested here}}
+  // This is a function declaration, not a variable declaration!
+  // After substitution, we do not have a valid function type, and used to 
crash.
+  MyType var;
+}
+
+void Test() {
+  Func(); // expected-note {{in instantiation of function template 
specialization 'Func' requested here}}
+}
\ No newline at end of file



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


[clang] [clang] Bail out if the result of function template instantiation is not a function type. (PR #69459)

2023-10-18 Thread via cfe-commits

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


[clang] [clang] Bail out if the result of function template instantiation is not a function. (PR #69449)

2023-10-18 Thread via cfe-commits

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


[clang] [clang] Bail out if the result of function template instantiation is not a function. (PR #69449)

2023-10-18 Thread via cfe-commits

VitaNuo wrote:

Pre-empted by https://github.com/llvm/llvm-project/pull/69459.

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


[clang] [CXXNameMangler] Correct the mangling of SVE ACLE types within function names. (PR #69460)

2023-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Paul Walker (paulwalker-arm)


Changes

* Mark SVE ACLE types as substitution candidates.
* Change mangling of svbfloat16_t from __SVBFloat16_t to
  __SVBfloat16_t.

https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst

This is an ABI break with the old behaviour available via
"-fclang-abi-compat=17".

---

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


286 Files Affected:

- (modified) clang/include/clang/Basic/AArch64SVEACLETypes.def (+1-1) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+14-3) 
- (modified) clang/test/AST/ast-dump-aarch64-sve-types.c (+2-2) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i32.c 
(+8-8) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i64.c 
(+8-8) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za32.c 
(+7-7) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c 
(+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za32.c 
(+7-7) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c 
(+5-5) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_read.c (+8-8) 
- (modified) clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_write.c (+8-8) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_abd.c (+33-33) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_abs.c (+7-7) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acge.c (+3-3) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acgt.c (+3-3) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acle.c (+3-3) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_aclt.c (+3-3) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_add.c (+33-33) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrb.c (+2-2) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrd.c (+2-2) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrh.c (+2-2) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrw.c (+2-2) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_and.c (+25-25) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfdot.c (+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmlalb.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmlalt.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmmla.c (+1-1) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bic.c (+25-25) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brka.c (+2-2) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkb.c (+2-2) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkn.c (+1-1) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkpa.c (+1-1) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkpb.c (+1-1) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cadd.c (+10-10) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clasta-bfloat.c 
(+2-2) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clasta.c 
(+11-11) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clastb-bfloat.c 
(+2-2) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clastb.c 
(+11-11) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clz.c (+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmla.c (+16-16) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpeq.c 
(+11-11) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpge.c 
(+11-11) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpgt.c 
(+11-11) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmple.c 
(+11-11) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmplt.c 
(+11-11) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpne.c 
(+11-11) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpuo.c (+3-3) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnot.c (+8-8) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnt-bfloat.c 
(+3-3) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnt.c (+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cntp.c (+4-4) 
- (modified) 
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create2-bfloat.c (+1-1) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create2.c 
(+11-11) 
- (modified) 
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create3-bfloat.c (+1-1) 
- (modified) clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create3.c 
(+11-11) 
- (modified) 
clang/test/CodeGen/

[clang] [CXXNameMangler] Correct the mangling of SVE ACLE types within function names. (PR #69460)

2023-10-18 Thread Paul Walker via cfe-commits

paulwalker-arm wrote:

To aid review I've split the patch into several commits mainly so the 
mechanical update of 200+ ACLE tests is separate from the much smaller code 
changes.  Given this is an ABI break I'd rather land the series as a single 
commit.

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


[clang] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-18 Thread via cfe-commits
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= 
Message-ID:
In-Reply-To: 


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


[clang] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-18 Thread via cfe-commits
Endre =?utf-8?q?F=C3=BCl=C3=B6p?= ,
Endre =?utf-8?q?F=C3=BCl=C3=B6p?= ,
Endre =?utf-8?q?F=C3=BCl=C3=B6p?= ,
Endre =?utf-8?q?F=C3=BCl=C3=B6p?= ,
Endre =?utf-8?q?F=C3=BCl=C3=B6p?= ,
Endre =?utf-8?q?F=C3=BCl=C3=B6p?= ,
Endre =?utf-8?q?F=C3=BCl=C3=B6p?= ,
Endre =?utf-8?q?F=C3=BCl=C3=B6p?= ,
Endre =?utf-8?q?F=C3=BCl=C3=B6p?= ,
Endre =?utf-8?q?F=C3=BCl=C3=B6p?= 
Message-ID:
In-Reply-To: 


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

LGTM, my only remark is a negligible grammar issue.

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


[clang] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-18 Thread via cfe-commits
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= 
Message-ID:
In-Reply-To: 



@@ -84,33 +104,74 @@ class InvalidPtrChecker
 REGISTER_SET_WITH_PROGRAMSTATE(InvalidMemoryRegions, const MemRegion *)
 
 // Stores the region of the environment pointer of 'main' (if present).
-REGISTER_TRAIT_WITH_PROGRAMSTATE(EnvPtrRegion, const MemRegion *)
+REGISTER_TRAIT_WITH_PROGRAMSTATE(MainEnvPtrRegion, const MemRegion *)
+
+// Stores the regions of environments returned by getenv calls.
+REGISTER_SET_WITH_PROGRAMSTATE(GetenvEnvPtrRegions, const MemRegion *)
 
 // Stores key-value pairs, where key is function declaration and value is
 // pointer to memory region returned by previous call of this function
 REGISTER_MAP_WITH_PROGRAMSTATE(PreviousCallResultMap, const FunctionDecl *,
const MemRegion *)
 
+const NoteTag *InvalidPtrChecker::createEnvInvalidationNote(
+CheckerContext &C, ProgramStateRef State, StringRef FunctionName) const {
+
+  const MemRegion *MainRegion = State->get();
+  const auto GetenvRegions = State->get();
+
+  return C.getNoteTag([this, MainRegion, GetenvRegions,
+   FunctionName = std::string{FunctionName}](
+  PathSensitiveBugReport &BR, llvm::raw_ostream &Out) {
+// Only handle the BugType of this checker.
+if (&BR.getBugType() != &InvalidPtrBugType)
+  return;
+
+// Mark all regions that were interesting before as NOT interesting now
+// to avoid extra notes coming from invalidation points higher up the
+// bugpath. This ensures, that only the last invalidation point is marked

DonatNagyE wrote:

```suggestion
// bugpath. This ensures that only the last invalidation point is marked
```

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


[clang] [Clang][OpenMP] Check if value is contained in array, not if it's contained in the first element (PR #69462)

2023-10-18 Thread Juan Manuel Martinez Caamaño via cfe-commits

https://github.com/jmmartinez created 
https://github.com/llvm/llvm-project/pull/69462

None

From c388e5f65d3dfc8fc193686e182e74c3dcfb27e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20MARTINEZ=20CAAMA=C3=91O?= 
Date: Wed, 18 Oct 2023 15:32:22 +0200
Subject: [PATCH] [Clang][OpenMP] Check if value is contained in array, not if
 it's contained in the first element

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 25fd940584624ee..7b2966f70bf6fc6 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2295,7 +2295,7 @@ void tools::AddStaticDeviceLibs(Compilation *C, const 
Tool *T,
   static const StringRef HostOnlyArchives[] = {
   "omp", "cudart", "m", "gcc", "gcc_s", "pthread", "hip_hcc"};
   for (auto SDLName : DriverArgs.getAllArgValues(options::OPT_l)) {
-if (!HostOnlyArchives->contains(SDLName)) {
+if (!llvm::is_contained(HostOnlyArchives, SDLName)) {
   SDLNames.insert(std::string("-l") + SDLName);
 }
   }

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


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-18 Thread Andrzej Warzyński via cfe-commits

https://github.com/banach-space approved this pull request.

LGTM, thanks for all the improvements!

Before merging, could you update the summary and briefly mention the additional 
changes made here? Otherwise people might think that these changes are 
required, but that's not strictly the case.

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


[PATCH] D151439: [Clang][SVE2.1] Add builtins for 2-way svdot (vectors, indexed)

2023-10-18 Thread Dinar Temirbulatov via Phabricator via cfe-commits
dtemirbulatov added inline comments.



Comment at: clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp:112
+  svfloat32_t f32, svfloat16_t f16) {
+  svdot_lane_s32_s16_s16(s32, s16, s16, 1); // expected-error {{argument value 
4 is outside the valid range [0, 3]}}
+  svdot_lane_u32_u16_u16(u32, u16, u16, 1); // expected-error {{argument value 
4 is outside the valid range [0, 3]}}

It looks like an incorrect error report?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151439/new/

https://reviews.llvm.org/D151439

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


[clang] [clang-format]: Split alignment of declarations around assignment (PR #69340)

2023-10-18 Thread Gedare Bloom via cfe-commits

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

>From c5d25f8de3de16ff3ed873446da017e9c26e0767 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Tue, 17 Oct 2023 08:21:55 -0600
Subject: [PATCH 1/2] [clang-format]: Split alignment of declarations around
 assignment

Function pointers are detected as a type of declaration using
FunctionTypeLParen. They are aligned based on rules for
AlignConsecutiveDeclarations. When a function pointer is on the
right-hand side of an assignment, the alignment of the function pointer
can result in excessive whitespace padding due to the ordering of
alignment, as the alignment processes a line from left-to-right and
first aligns the declarations before and after the assignment operator,
and then aligns the assignment operator. Injection of whitespace by
alignment of declarations after the equal sign followed by alignment
of the equal sign results in the excessive whitespace.

Fixes #68079.
---
 clang/lib/Format/WhitespaceManager.cpp | 43 --
 clang/lib/Format/WhitespaceManager.h   |  3 +-
 clang/unittests/Format/FormatTest.cpp  |  9 ++
 3 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index dc81060671c1712..e6bc0963b40dc75 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -108,9 +108,10 @@ const tooling::Replacements 
&WhitespaceManager::generateReplacements() {
   calculateLineBreakInformation();
   alignConsecutiveMacros();
   alignConsecutiveShortCaseStatements();
-  alignConsecutiveDeclarations();
+  alignConsecutiveDeclarationsPreAssignment();
   alignConsecutiveBitFields();
   alignConsecutiveAssignments();
+  alignConsecutiveDeclarationsPostAssignment();
   alignChainedConditionals();
   alignTrailingComments();
   alignEscapedNewlines();
@@ -973,13 +974,51 @@ void 
WhitespaceManager::alignConsecutiveShortCaseStatements() {
  Changes);
 }
 
-void WhitespaceManager::alignConsecutiveDeclarations() {
+void WhitespaceManager::alignConsecutiveDeclarationsPreAssignment() {
   if (!Style.AlignConsecutiveDeclarations.Enabled)
 return;
 
   AlignTokens(
   Style,
   [](Change const &C) {
+for (FormatToken *Prev = C.Tok->Previous; Prev; Prev = Prev->Previous)
+  if (Prev->is(tok::equal))
+return false;
+if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen))
+  return true;
+if (C.Tok->isNot(TT_StartOfName))
+  return false;
+if (C.Tok->Previous &&
+C.Tok->Previous->is(TT_StatementAttributeLikeMacro))
+  return false;
+// Check if there is a subsequent name that starts the same 
declaration.
+for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) {
+  if (Next->is(tok::comment))
+continue;
+  if (Next->is(TT_PointerOrReference))
+return false;
+  if (!Next->Tok.getIdentifierInfo())
+break;
+  if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName,
+tok::kw_operator)) {
+return false;
+  }
+}
+return true;
+  },
+  Changes, /*StartAt=*/0, Style.AlignConsecutiveDeclarations);
+}
+
+void WhitespaceManager::alignConsecutiveDeclarationsPostAssignment() {
+  if (!Style.AlignConsecutiveDeclarations.Enabled)
+return;
+
+  AlignTokens(
+  Style,
+  [](Change const &C) {
+for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next)
+  if (Next->is(tok::equal))
+return false;
 if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen))
   return true;
 if (C.Tok->isNot(TT_StartOfName))
diff --git a/clang/lib/Format/WhitespaceManager.h 
b/clang/lib/Format/WhitespaceManager.h
index df7e9add1cd446f..19bd4a3a6f7791f 100644
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -227,7 +227,8 @@ class WhitespaceManager {
   void alignConsecutiveBitFields();
 
   /// Align consecutive declarations over all \c Changes.
-  void alignConsecutiveDeclarations();
+  void alignConsecutiveDeclarationsPreAssignment();
+  void alignConsecutiveDeclarationsPostAssignment();
 
   /// Align consecutive declarations over all \c Changes.
   void alignChainedConditionals();
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 963fb8f4d441618..1dc05ff9de5f0fa 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -18783,6 +18783,15 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
" \"bb\"};\n"
"int   bbb = 0;",
Alignment);
+  // http://llvm.org/PR68079
+  verifyFormat("using Fn   = int (A::*)();\n"
+   "using RFn  = int (A

[clang] [flang][driver] support -dumpversion and -dumpmachine (PR #68896)

2023-10-18 Thread Andrzej Warzyński via cfe-commits

banach-space wrote:

> > Could this be implemented without any updates to Clang (beyond Options.td)?
> 
> The options could work by changing options.td only. However, 
> `CLANG_VERSION_STRING` and `FLANG_VERSION_STRING` could be different. This is 
> to handle that.

You are adding a support for these new flags in `flang-new`, which is 
implemented in terms of `clangDriver` - this scenario would be very unlikely at 
the moment. And even if that was desired, you'd need to update Flang's driver 
too. I'd rather keep this to the required minimum. If you really want to keep 
this, you will need to update flang/tools/flang-driver/driver.cpp too.

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-10-18 Thread via cfe-commits

alan-baker wrote:

This is preferable to defining the function in the OpenCL headers (as was noted 
in the original PR). To me, the important part is covering the OpenCL use case. 
So if we want to only check the overloads OpenCL generates I think that would 
be ok, but I expect this generic implementation is sufficient.

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


[clang] [clang-format]: Split alignment of declarations around assignment (PR #69340)

2023-10-18 Thread Gedare Bloom via cfe-commits

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

>From c5d25f8de3de16ff3ed873446da017e9c26e0767 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Tue, 17 Oct 2023 08:21:55 -0600
Subject: [PATCH 1/3] [clang-format]: Split alignment of declarations around
 assignment

Function pointers are detected as a type of declaration using
FunctionTypeLParen. They are aligned based on rules for
AlignConsecutiveDeclarations. When a function pointer is on the
right-hand side of an assignment, the alignment of the function pointer
can result in excessive whitespace padding due to the ordering of
alignment, as the alignment processes a line from left-to-right and
first aligns the declarations before and after the assignment operator,
and then aligns the assignment operator. Injection of whitespace by
alignment of declarations after the equal sign followed by alignment
of the equal sign results in the excessive whitespace.

Fixes #68079.
---
 clang/lib/Format/WhitespaceManager.cpp | 43 --
 clang/lib/Format/WhitespaceManager.h   |  3 +-
 clang/unittests/Format/FormatTest.cpp  |  9 ++
 3 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index dc81060671c1712..e6bc0963b40dc75 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -108,9 +108,10 @@ const tooling::Replacements 
&WhitespaceManager::generateReplacements() {
   calculateLineBreakInformation();
   alignConsecutiveMacros();
   alignConsecutiveShortCaseStatements();
-  alignConsecutiveDeclarations();
+  alignConsecutiveDeclarationsPreAssignment();
   alignConsecutiveBitFields();
   alignConsecutiveAssignments();
+  alignConsecutiveDeclarationsPostAssignment();
   alignChainedConditionals();
   alignTrailingComments();
   alignEscapedNewlines();
@@ -973,13 +974,51 @@ void 
WhitespaceManager::alignConsecutiveShortCaseStatements() {
  Changes);
 }
 
-void WhitespaceManager::alignConsecutiveDeclarations() {
+void WhitespaceManager::alignConsecutiveDeclarationsPreAssignment() {
   if (!Style.AlignConsecutiveDeclarations.Enabled)
 return;
 
   AlignTokens(
   Style,
   [](Change const &C) {
+for (FormatToken *Prev = C.Tok->Previous; Prev; Prev = Prev->Previous)
+  if (Prev->is(tok::equal))
+return false;
+if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen))
+  return true;
+if (C.Tok->isNot(TT_StartOfName))
+  return false;
+if (C.Tok->Previous &&
+C.Tok->Previous->is(TT_StatementAttributeLikeMacro))
+  return false;
+// Check if there is a subsequent name that starts the same 
declaration.
+for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) {
+  if (Next->is(tok::comment))
+continue;
+  if (Next->is(TT_PointerOrReference))
+return false;
+  if (!Next->Tok.getIdentifierInfo())
+break;
+  if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName,
+tok::kw_operator)) {
+return false;
+  }
+}
+return true;
+  },
+  Changes, /*StartAt=*/0, Style.AlignConsecutiveDeclarations);
+}
+
+void WhitespaceManager::alignConsecutiveDeclarationsPostAssignment() {
+  if (!Style.AlignConsecutiveDeclarations.Enabled)
+return;
+
+  AlignTokens(
+  Style,
+  [](Change const &C) {
+for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next)
+  if (Next->is(tok::equal))
+return false;
 if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen))
   return true;
 if (C.Tok->isNot(TT_StartOfName))
diff --git a/clang/lib/Format/WhitespaceManager.h 
b/clang/lib/Format/WhitespaceManager.h
index df7e9add1cd446f..19bd4a3a6f7791f 100644
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -227,7 +227,8 @@ class WhitespaceManager {
   void alignConsecutiveBitFields();
 
   /// Align consecutive declarations over all \c Changes.
-  void alignConsecutiveDeclarations();
+  void alignConsecutiveDeclarationsPreAssignment();
+  void alignConsecutiveDeclarationsPostAssignment();
 
   /// Align consecutive declarations over all \c Changes.
   void alignChainedConditionals();
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 963fb8f4d441618..1dc05ff9de5f0fa 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -18783,6 +18783,15 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
" \"bb\"};\n"
"int   bbb = 0;",
Alignment);
+  // http://llvm.org/PR68079
+  verifyFormat("using Fn   = int (A::*)();\n"
+   "using RFn  = int (A

[clang] [NFC] Remove unused variable "AOBFileNames" (PR #69463)

2023-10-18 Thread Juan Manuel Martinez Caamaño via cfe-commits

https://github.com/jmmartinez created 
https://github.com/llvm/llvm-project/pull/69463

None

From d616ff33ba0b1db6ac8f9fd3cd1b0e2a3c1a544a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20MARTINEZ=20CAAMA=C3=91O?= 
Date: Wed, 18 Oct 2023 15:45:07 +0200
Subject: [PATCH] [NFC] Remove unused variable "AOBFileNames"

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 25fd940584624ee..66790508274ab8b 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2144,7 +2144,6 @@ bool tools::GetSDLFromOffloadArchive(
   Lib = Lib.drop_front(2);
 for (auto LPath : LibraryPaths) {
   ArchiveOfBundles.clear();
-  SmallVector AOBFileNames;
   auto LibFile =
   (Lib.startswith(":") ? Lib.drop_front()
: IsMSVC ? Lib + Ext : "lib" + Lib + Ext)

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


[clang] [Clang][OpenMP] Check if value is contained in array, not if it's contained in the first element (PR #69462)

2023-10-18 Thread Juan Manuel Martinez Caamaño via cfe-commits

jmmartinez wrote:

Hello @saiislam ! Can I bother you with a review of this patch?

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


[clang-tools-extra] [run-clang-tidy] Add option -export-directory (PR #69453)

2023-10-18 Thread Amadeus Gebauer via cfe-commits

https://github.com/amgebauer updated 
https://github.com/llvm/llvm-project/pull/69453

>From d63de8e3d8e71df445983516a57cc41cf47f1a6e Mon Sep 17 00:00:00 2001
From: Amadeus Gebauer 
Date: Wed, 18 Oct 2023 14:02:44 +0200
Subject: [PATCH] [run-clang-tidy] Accept directory for -export-fixes

---
 .../clang-tidy/tool/run-clang-tidy.py | 42 ---
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py 
b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index 312d9241cfa57c5..1cce241a031c6d7 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -308,10 +308,12 @@ def main():
 if yaml:
 parser.add_argument(
 "-export-fixes",
-metavar="filename",
+metavar="file_or_directory",
 dest="export_fixes",
-help="Create a yaml file to store suggested fixes in, "
-"which can be applied with clang-apply-replacements.",
+help="A directory or a yaml file to store suggested fixes in, "
+"which can be applied with clang-apply-replacements. If the "
+"parameter is a directory, the fixes of each compilation unit are "
+"stored in individual yaml files in the directory."
 )
 parser.add_argument(
 "-j",
@@ -384,14 +386,26 @@ def main():
 
 clang_tidy_binary = find_binary(args.clang_tidy_binary, "clang-tidy", 
build_path)
 
-tmpdir = None
 if args.fix:
 clang_apply_replacements_binary = find_binary(
 args.clang_apply_replacements_binary, "clang-apply-replacements", 
build_path
 )
 
-if args.fix or (yaml and args.export_fixes):
-tmpdir = tempfile.mkdtemp()
+combine_fixes = False
+export_fixes_dir = None
+delete_fixes_dir = True
+if args.export_fixes is not None:
+assert not args.export_fixes.endswith(os.path.sep) or 
os.path.isdir(args.export_fixes), "The export fixes directory does not exist."
+
+if not os.path.isdir(args.export_fixes) and yaml:
+combine_fixes = True
+
+if os.path.isdir(args.export_fixes):
+export_fixes_dir = args.export_fixes
+delete_fixes_dir = False
+
+if export_fixes_dir is None and (args.fix or combine_fixes):
+export_fixes_dir = tempfile.mkdtemp()
 
 try:
 invocation = get_tidy_invocation(
@@ -450,7 +464,7 @@ def main():
 args=(
 args,
 clang_tidy_binary,
-tmpdir,
+export_fixes_dir,
 build_path,
 task_queue,
 lock,
@@ -474,14 +488,14 @@ def main():
 # This is a sad hack. Unfortunately subprocess goes
 # bonkers with ctrl-c and we start forking merrily.
 print("\nCtrl-C detected, goodbye.")
-if tmpdir:
-shutil.rmtree(tmpdir)
+if export_fixes_dir is not None and delete_fixes_dir:
+shutil.rmtree(export_fixes_dir)
 os.kill(0, 9)
 
-if yaml and args.export_fixes:
+if combine_fixes:
 print("Writing fixes to " + args.export_fixes + " ...")
 try:
-merge_replacement_files(tmpdir, args.export_fixes)
+merge_replacement_files(export_fixes_dir, args.export_fixes)
 except:
 print("Error exporting fixes.\n", file=sys.stderr)
 traceback.print_exc()
@@ -490,14 +504,14 @@ def main():
 if args.fix:
 print("Applying fixes ...")
 try:
-apply_fixes(args, clang_apply_replacements_binary, tmpdir)
+apply_fixes(args, clang_apply_replacements_binary, 
export_fixes_dir)
 except:
 print("Error applying fixes.\n", file=sys.stderr)
 traceback.print_exc()
 return_code = 1
 
-if tmpdir:
-shutil.rmtree(tmpdir)
+if export_fixes_dir is not None and delete_fixes_dir:
+shutil.rmtree(export_fixes_dir)
 sys.exit(return_code)
 
 

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


[clang-tools-extra] [run-clang-tidy] Add option -export-directory (PR #69453)

2023-10-18 Thread Amadeus Gebauer via cfe-commits

amgebauer wrote:

@PiotrZSL Thank you for your feedback. I implemented it the way you suggest. 
Feel free to leave comments.

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


[clang] Correctly compute conversion seq for args to fn with reversed param order (PR #68999)

2023-10-18 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

This breaks new code (expected) but does not respect 
`-Wno-ambiguous-reversed-operator`.  https://godbolt.org/z/oMsGeK1nc
@zygoloid IIUC this should be silenced by this warning but somehow does not. 
Will investigate further.
Reverting to put out large unsuppresable breakages

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


[PATCH] D151199: [Clang][SVE2.1] Add pfalse builtin

2023-10-18 Thread Caroline via Phabricator via cfe-commits
CarolineConcatto updated this revision to Diff 557758.
CarolineConcatto added a comment.

-Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151199/new/

https://reviews.llvm.org/D151199

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pfalse.c


Index: clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pfalse.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pfalse.c
@@ -0,0 +1,30 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S 
-passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S 
-passes=mem2reg,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s 
| opt -S -passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -passes=mem2reg,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
+#endif
+
+// CHECK-LABEL: @test_svpfalse_c(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call target("aarch64.svcount") 
@llvm.aarch64.sve.convert.from.svbool.taarch64.svcountt( 
zeroinitializer)
+// CHECK-NEXT:ret target("aarch64.svcount") [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z15test_svpfalse_cv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call target("aarch64.svcount") 
@llvm.aarch64.sve.convert.from.svbool.taarch64.svcountt( 
zeroinitializer)
+// CPP-CHECK-NEXT:ret target("aarch64.svcount") [[TMP0]]
+//
+svcount_t test_svpfalse_c()
+{
+  return SVE_ACLE_FUNC(svpfalse_c,,,)();
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -10155,6 +10155,13 @@
   case SVE::BI__builtin_sve_svpfalse_b:
 return ConstantInt::getFalse(Ty);
 
+  case SVE::BI__builtin_sve_svpfalse_c: {
+auto SVBoolTy = ScalableVectorType::get(Builder.getInt1Ty(), 16);
+Function *CastToSVCountF =
+CGM.getIntrinsic(Intrinsic::aarch64_sve_convert_from_svbool, Ty);
+return Builder.CreateCall(CastToSVCountF, ConstantInt::getFalse(SVBoolTy));
+  }
+
   case SVE::BI__builtin_sve_svlen_bf16:
   case SVE::BI__builtin_sve_svlen_f16:
   case SVE::BI__builtin_sve_svlen_f32:
Index: clang/include/clang/Basic/arm_sve.td
===
--- clang/include/clang/Basic/arm_sve.td
+++ clang/include/clang/Basic/arm_sve.td
@@ -1862,6 +1862,7 @@
 let TargetGuard = "sve2p1" in {
 def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [], []>;
 def SVPTRUE_COUNT  : SInst<"svptrue_{d}", "}v", "QcQsQiQl", MergeNone, 
"aarch64_sve_ptrue_{d}", [IsOverloadNone], []>;
+def SVPFALSE_COUNT_ALIAS : SInst<"svpfalse_c", "}v", "", MergeNone, "", 
[IsOverloadNone]>;
 
 def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_pext", [], [ImmCheck<1, ImmCheck0_3>]>;
 def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", 
MergeNone, "aarch64_sve_pext_x2", [], [ImmCheck<1, ImmCheck0_1>]>;


Index: clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pfalse.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pfalse.c
@@ -0,0 +1,30 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -passes=mem2reg,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -targe

[clang-tools-extra] [run-clang-tidy] Accept directory as value for -export-fixes (PR #69453)

2023-10-18 Thread Amadeus Gebauer via cfe-commits

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


[clang] cf1bde9 - [Driver] Link Flang runtime on Solaris (#65644)

2023-10-18 Thread via cfe-commits

Author: Rainer Orth
Date: 2023-10-18T16:12:10+02:00
New Revision: cf1bde9a15d711564c51e707b6200f1b5f508b9f

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

LOG: [Driver] Link Flang runtime on Solaris (#65644)

I noticed that `flang-new` cannot link Fortran executables on Solaris since the 
runtime libs are missing.

This patch fixes this, following `Gnu.cpp`. The `linker-flags.f90` testcase is 
augmented to test for this,
renaming the `GNU` label to `UNIX` so it can be reused.  Also use the current 
form `--target=` in the tests
and join the `-l` lines in the test for readibility.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Solaris.cpp
flang/test/Driver/linker-flags.f90

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 26bc45e37b24174..ecff8ddc4ee766f 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -222,6 +222,14 @@ void solaris::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
   CmdArgs.push_back("-lm");
 }
+// Additional linker set-up and flags for Fortran. This is required in 
order
+// to generate executables. As Fortran runtime depends on the C runtime,
+// these dependencies need to be listed before the C runtime below.
+if (D.IsFlangMode()) {
+  addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs);
+  addFortranRuntimeLibs(getToolChain(), CmdArgs);
+  CmdArgs.push_back("-lm");
+}
 if (Args.hasArg(options::OPT_fstack_protector) ||
 Args.hasArg(options::OPT_fstack_protector_strong) ||
 Args.hasArg(options::OPT_fstack_protector_all)) {

diff  --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 09b8a224df13828..213bc032d964504 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -2,15 +2,16 @@
 ! invocation. These libraries are added on top of other standard runtime
 ! libraries that the Clang driver will include.
 
-! RUN: %flang -### -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,GNU
-! RUN: %flang -### -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,DARWIN
-! RUN: %flang -### -target x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,MINGW
+! RUN: %flang -### --target=ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,UNIX
+! RUN: %flang -### --target=aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,DARWIN
+! RUN: %flang -### --target=sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,UNIX
+! RUN: %flang -### --target=x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,MINGW
 
 ! NOTE: Clang's driver library, clangDriver, usually adds 'libcmt' and
 !   'oldnames' on Windows, but they are not needed when compiling
 !   Fortran code and they might bring in additional dependencies.
 !   Make sure they're not added.
-! RUN: %flang -### -target aarch64-windows-msvc -fuse-ld= %S/Inputs/hello.f90 
2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt 
--implicit-check-not oldnames
+! RUN: %flang -### --target=aarch64-windows-msvc -fuse-ld= %S/Inputs/hello.f90 
2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt 
--implicit-check-not oldnames
 
 ! Compiler invocation to generate the object file
 ! CHECK-LABEL: {{.*}} "-emit-obj"
@@ -21,12 +22,9 @@
 !   run on any other platform, such as Windows that use a .exe
 !   suffix. Clang's driver will try to resolve the path to the ld
 !   executable and may find the GNU linker from MinGW or Cygwin.
-! GNU-LABEL:  "{{.*}}ld{{(\.exe)?}}"
-! GNU-SAME: "[[object_file]]"
-! GNU-SAME: -lFortran_main
-! GNU-SAME: -lFortranRuntime
-! GNU-SAME: -lFortranDecimal
-! GNU-SAME: -lm
+! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
+! UNIX-SAME: "[[object_file]]"
+! UNIX-SAME: "-lFortran_main" "-lFortranRuntime" "-lFortranDecimal" "-lm"
 
 ! DARWIN-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! DARWIN-SAME: "[[object_file]]"



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


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-18 Thread Rainer Orth via cfe-commits

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


[clang] a3a0f59 - Revert "Correctly compute conversion seq for args to fn with reversed param order (#68999)"

2023-10-18 Thread Dmitry Chernenkov via cfe-commits

Author: Dmitry Chernenkov
Date: 2023-10-18T14:13:48Z
New Revision: a3a0f59a1e1cb0ac02f06b19f730ea05a6541c96

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

LOG: Revert "Correctly compute conversion seq for args to fn with reversed 
param order (#68999)"

This reverts commit e6d0b126c824222fca2f31a2ba571c2ee2bb4760.

See PR for reason

https://github.com/llvm/llvm-project/pull/68999#issuecomment-1768541660

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaOverload.cpp
clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 443325bb0d1e17d..81cbfd90155fe0b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -117,8 +117,6 @@ C++ Language Changes
 
 C++20 Feature Support
 ^
-- Fix a bug in conversion sequence of arguments to a function with reversed 
parameter order.
-  Fixes `GH `_.
 
 C++23 Feature Support
 ^

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index c271cebb9eb638f..ce78994e6553814 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7688,7 +7688,7 @@ bool Sema::CheckNonDependentConversions(
 QualType ParamType = ParamTypes[I + Offset];
 if (!ParamType->isDependentType()) {
   unsigned ConvIdx = PO == OverloadCandidateParamOrder::Reversed
- ? Args.size() - 1 - (ThisConversions + I)
+ ? 0
  : (ThisConversions + I);
   Conversions[ConvIdx]
 = TryCopyInitialization(*this, Args[I], ParamType,

diff  --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
index 02fe37dc1be5058..5c6804eb7726b5f 100644
--- a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
@@ -324,41 +324,6 @@ bool x = X() == X(); // expected-warning {{ambiguous}}
 }
 } // namespace P2468R2
 
-namespace GH53954{
-namespace test1 {
-struct P {
-template 
-friend bool operator==(const P&, const T&); // expected-note {{candidate}} 
\
-  // expected-note {{reversed 
parameter order}}
-};
-struct A : public P {};
-struct B : public P {};
-bool check(A a, B b) { return a == b; } // expected-error {{ '==' is 
ambiguous}}
-}
-
-namespace test2 {
-struct P {
-template 
-friend bool operator==(const T&, const P&); // expected-note {{candidate}} 
\
-// expected-note {{reversed 
parameter order}}
-};
-struct A : public P {};
-struct B : public P {};
-bool check(A a, B b) { return a == b; } // expected-error {{ '==' is 
ambiguous}}
-}
-
-namespace test3 {
-struct P {
-  template
-  bool operator==(const S &) const; // expected-note {{candidate}} \
-// expected-note {{reversed parameter 
order}}
-};
-struct A : public P {};
-struct B : public P {};
-bool check(A a, B b) { return a == b; } // expected-error {{ '==' is 
ambiguous}}
-}
-}
-
 #else // NO_ERRORS
 
 namespace problem_cases {



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


[clang-tools-extra] [run-clang-tidy] Accept directory as value for -export-fixes (PR #69453)

2023-10-18 Thread Piotr Zegar via cfe-commits


@@ -384,14 +386,26 @@ def main():
 
 clang_tidy_binary = find_binary(args.clang_tidy_binary, "clang-tidy", 
build_path)
 
-tmpdir = None
 if args.fix:
 clang_apply_replacements_binary = find_binary(
 args.clang_apply_replacements_binary, "clang-apply-replacements", 
build_path
 )
 
-if args.fix or (yaml and args.export_fixes):
-tmpdir = tempfile.mkdtemp()
+combine_fixes = False
+export_fixes_dir = None
+delete_fixes_dir = True
+if args.export_fixes is not None:
+assert not args.export_fixes.endswith(os.path.sep) or 
os.path.isdir(args.export_fixes), "The export fixes directory does not exist."

PiotrZSL wrote:

actually we could create directory if it does not exist

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


[clang-tools-extra] [clang-tidy]Add new check bugprone-casting-through-void (PR #69465)

2023-10-18 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/69465

This check detects usage of ``static_cast`` pointer to the other pointer 
throght `static_cast` to `void *` in C++ code.
Fixes: #68532

>From 627f68e57b2526fb72285ef4831fc3c02a6ee6d0 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 18 Oct 2023 08:47:02 +0800
Subject: [PATCH] [clang-tidy]Add new check bugprone-casting-through-void

Fixes: #68532
---
 .../bugprone/BugproneTidyModule.cpp   |  3 ++
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../bugprone/CastingThroughVoidCheck.cpp  | 46 +++
 .../bugprone/CastingThroughVoidCheck.h| 37 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 +++
 .../checks/bugprone/casting-through-void.rst  | 11 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../bugprone/casting-through-void.cpp | 18 
 8 files changed, 123 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/casting-through-void.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 543c522899d7a52..7a910037368c832 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -16,6 +16,7 @@
 #include "BadSignalToKillThreadCheck.h"
 #include "BoolPointerImplicitConversionCheck.h"
 #include "BranchCloneCheck.h"
+#include "CastingThroughVoidCheck.h"
 #include "ComparePointerToMemberVirtualFunctionCheck.h"
 #include "CopyConstructorInitCheck.h"
 #include "DanglingHandleCheck.h"
@@ -104,6 +105,8 @@ class BugproneModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "bugprone-bool-pointer-implicit-conversion");
 CheckFactories.registerCheck("bugprone-branch-clone");
+CheckFactories.registerCheck(
+"bugprone-casting-through-void");
 CheckFactories.registerCheck(
 "bugprone-compare-pointer-to-member-virtual-function");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 0df9e439b715e5a..d443fd8d1452f16 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -11,6 +11,7 @@ add_clang_library(clangTidyBugproneModule
   BoolPointerImplicitConversionCheck.cpp
   BranchCloneCheck.cpp
   BugproneTidyModule.cpp
+  CastingThroughVoidCheck.cpp
   ComparePointerToMemberVirtualFunctionCheck.cpp
   CopyConstructorInitCheck.cpp
   DanglingHandleCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
new file mode 100644
index 000..7b9cd7dd51fc47f
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
@@ -0,0 +1,46 @@
+//===--- CastingThroughVoidCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CastingThroughVoidCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "llvm/ADT/StringSet.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void CastingThroughVoidCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  explicitCastExpr(
+  hasDestinationType(qualType(pointsTo(qualType(unless(voidType()
+ .bind("target_type")),
+  hasSourceExpression(
+  explicitCastExpr(hasSourceExpression(expr(
+   hasType(qualType().bind("source_type",
+   hasDestinationType(pointsTo(voidType())
+  .bind("cast"),
+  this);
+}
+
+void CastingThroughVoidCheck::check(const MatchFinder::MatchResult &Result) {
+  ASTContext *Context = Result.Context;
+  const auto *CE = Result.Nodes.getNodeAs("cast");
+  const auto *TT = Result.Nodes.getNodeAs("target_type");
+  const auto *ST = Result.Nodes.getNodeAs("source_type");
+  if (Context->hasSameType(*TT, *ST))
+return;
+  diag(CE->getSourceRange().getBegin(), "do not cast %0 to %1 through void *",
+   DiagnosticIDs::Level::Warning)
+

[clang-tools-extra] [clang-tidy]Add new check bugprone-casting-through-void (PR #69465)

2023-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)


Changes

This check detects usage of ``static_cast`` pointer to the other pointer 
throght `static_cast` to `void *` in C++ code.
Fixes: #68532

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


8 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp (+3) 
- (modified) clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt (+1) 
- (added) clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp 
(+46) 
- (added) clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.h (+37) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+6) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/bugprone/casting-through-void.rst 
(+11) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp 
(+18) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 543c522899d7a52..7a910037368c832 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -16,6 +16,7 @@
 #include "BadSignalToKillThreadCheck.h"
 #include "BoolPointerImplicitConversionCheck.h"
 #include "BranchCloneCheck.h"
+#include "CastingThroughVoidCheck.h"
 #include "ComparePointerToMemberVirtualFunctionCheck.h"
 #include "CopyConstructorInitCheck.h"
 #include "DanglingHandleCheck.h"
@@ -104,6 +105,8 @@ class BugproneModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "bugprone-bool-pointer-implicit-conversion");
 CheckFactories.registerCheck("bugprone-branch-clone");
+CheckFactories.registerCheck(
+"bugprone-casting-through-void");
 CheckFactories.registerCheck(
 "bugprone-compare-pointer-to-member-virtual-function");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 0df9e439b715e5a..d443fd8d1452f16 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -11,6 +11,7 @@ add_clang_library(clangTidyBugproneModule
   BoolPointerImplicitConversionCheck.cpp
   BranchCloneCheck.cpp
   BugproneTidyModule.cpp
+  CastingThroughVoidCheck.cpp
   ComparePointerToMemberVirtualFunctionCheck.cpp
   CopyConstructorInitCheck.cpp
   DanglingHandleCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
new file mode 100644
index 000..7b9cd7dd51fc47f
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
@@ -0,0 +1,46 @@
+//===--- CastingThroughVoidCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CastingThroughVoidCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "llvm/ADT/StringSet.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void CastingThroughVoidCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  explicitCastExpr(
+  hasDestinationType(qualType(pointsTo(qualType(unless(voidType()
+ .bind("target_type")),
+  hasSourceExpression(
+  explicitCastExpr(hasSourceExpression(expr(
+   hasType(qualType().bind("source_type",
+   hasDestinationType(pointsTo(voidType())
+  .bind("cast"),
+  this);
+}
+
+void CastingThroughVoidCheck::check(const MatchFinder::MatchResult &Result) {
+  ASTContext *Context = Result.Context;
+  const auto *CE = Result.Nodes.getNodeAs("cast");
+  const auto *TT = Result.Nodes.getNodeAs("target_type");
+  const auto *ST = Result.Nodes.getNodeAs("source_type");
+  if (Context->hasSameType(*TT, *ST))
+return;
+  diag(CE->getSourceRange().getBegin(), "do not cast %0 to %1 through void *",
+   DiagnosticIDs::Level::Warning)
+  << ST->getAsString() << TT->getAsString();
+}
+
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.h
new file mode 100644
index 000..542b1c50dc782e7
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/Cas

[clang-tools-extra] [run-clang-tidy] Accept directory as value for -export-fixes (PR #69453)

2023-10-18 Thread Piotr Zegar via cfe-commits


@@ -384,14 +386,26 @@ def main():
 
 clang_tidy_binary = find_binary(args.clang_tidy_binary, "clang-tidy", 
build_path)
 
-tmpdir = None
 if args.fix:
 clang_apply_replacements_binary = find_binary(
 args.clang_apply_replacements_binary, "clang-apply-replacements", 
build_path
 )
 
-if args.fix or (yaml and args.export_fixes):
-tmpdir = tempfile.mkdtemp()
+combine_fixes = False
+export_fixes_dir = None
+delete_fixes_dir = True
+if args.export_fixes is not None:
+assert not args.export_fixes.endswith(os.path.sep) or 
os.path.isdir(args.export_fixes), "The export fixes directory does not exist."
+
+if not os.path.isdir(args.export_fixes) and yaml:
+combine_fixes = True
+
+if os.path.isdir(args.export_fixes):
+export_fixes_dir = args.export_fixes
+delete_fixes_dir = False
+
+if export_fixes_dir is None and (args.fix or combine_fixes):
+export_fixes_dir = tempfile.mkdtemp()

PiotrZSL wrote:

set delete_fixes_dir  by default to False, and under this if set it to True

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


[clang-tools-extra] [run-clang-tidy] Accept directory as value for -export-fixes (PR #69453)

2023-10-18 Thread via cfe-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
b0b8e83e668ac02f81874c3548c8eb8dbf3c33f0..d63de8e3d8e71df445983516a57cc41cf47f1a6e
 clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
``





View the diff from darker here.


``diff
--- run-clang-tidy.py   2023-10-18 14:03:58.00 +
+++ run-clang-tidy.py   2023-10-18 14:18:29.065058 +
@@ -311,11 +311,11 @@
 metavar="file_or_directory",
 dest="export_fixes",
 help="A directory or a yaml file to store suggested fixes in, "
 "which can be applied with clang-apply-replacements. If the "
 "parameter is a directory, the fixes of each compilation unit are "
-"stored in individual yaml files in the directory."
+"stored in individual yaml files in the directory.",
 )
 parser.add_argument(
 "-j",
 type=int,
 default=0,
@@ -393,19 +393,21 @@
 
 combine_fixes = False
 export_fixes_dir = None
 delete_fixes_dir = True
 if args.export_fixes is not None:
-assert not args.export_fixes.endswith(os.path.sep) or 
os.path.isdir(args.export_fixes), "The export fixes directory does not exist."
+assert not args.export_fixes.endswith(os.path.sep) or os.path.isdir(
+args.export_fixes
+), "The export fixes directory does not exist."
 
 if not os.path.isdir(args.export_fixes) and yaml:
 combine_fixes = True
-
+
 if os.path.isdir(args.export_fixes):
 export_fixes_dir = args.export_fixes
 delete_fixes_dir = False
-
+
 if export_fixes_dir is None and (args.fix or combine_fixes):
 export_fixes_dir = tempfile.mkdtemp()
 
 try:
 invocation = get_tidy_invocation(

``




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


[clang-tools-extra] [run-clang-tidy] Accept directory as value for -export-fixes (PR #69453)

2023-10-18 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL commented:

Release notes will be needed, in clang-tools-extra/docs/ReleaseNotes.rst.
Additionally probably similar change should be done to clang-tidy-diff.py

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


[clang-tools-extra] [clang][dataflow]Use cast_or_null instead of cast to prevent crash (PR #68510)

2023-10-18 Thread Yitzhak Mandelbaum via cfe-commits

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

Thanks, looks good! 

You can submit as is, but if you're up for it, it would actually be better to 
add the new test case directly to the model's unittests. Something like this 
test (though just one case is enough -- please put it in a separate TEST_P): 
https://github.com/llvm/llvm-project/blob/a3a0f59a1e1cb0ac02f06b19f730ea05a6541c96/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp#L1966

In general, the lit tests for the clang tidy check only do minimal testing to 
ensure the check is properly calling the model.

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


[clang-tools-extra] [clang-tidy]Add new check bugprone-casting-through-void (PR #69465)

2023-10-18 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,46 @@
+//===--- CastingThroughVoidCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CastingThroughVoidCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "llvm/ADT/StringSet.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void CastingThroughVoidCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  explicitCastExpr(
+  hasDestinationType(qualType(pointsTo(qualType(unless(voidType()
+ .bind("target_type")),
+  hasSourceExpression(
+  explicitCastExpr(hasSourceExpression(expr(
+   hasType(qualType().bind("source_type",
+   hasDestinationType(pointsTo(voidType())
+  .bind("cast"),
+  this);
+}
+
+void CastingThroughVoidCheck::check(const MatchFinder::MatchResult &Result) {
+  ASTContext *Context = Result.Context;
+  const auto *CE = Result.Nodes.getNodeAs("cast");
+  const auto *TT = Result.Nodes.getNodeAs("target_type");
+  const auto *ST = Result.Nodes.getNodeAs("source_type");
+  if (Context->hasSameType(*TT, *ST))
+return;
+  diag(CE->getSourceRange().getBegin(), "do not cast %0 to %1 through void *",

PiotrZSL wrote:

void * -> 'void*'

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


[clang-tools-extra] [clang-tidy]Add new check bugprone-casting-through-void (PR #69465)

2023-10-18 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,46 @@
+//===--- CastingThroughVoidCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CastingThroughVoidCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "llvm/ADT/StringSet.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void CastingThroughVoidCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  explicitCastExpr(
+  hasDestinationType(qualType(pointsTo(qualType(unless(voidType()
+ .bind("target_type")),
+  hasSourceExpression(
+  explicitCastExpr(hasSourceExpression(expr(
+   hasType(qualType().bind("source_type",
+   hasDestinationType(pointsTo(voidType())
+  .bind("cast"),
+  this);
+}
+
+void CastingThroughVoidCheck::check(const MatchFinder::MatchResult &Result) {
+  ASTContext *Context = Result.Context;
+  const auto *CE = Result.Nodes.getNodeAs("cast");

PiotrZSL wrote:

move to line 41

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


  1   2   3   4   >