[clang] [libc] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)

2024-11-11 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 a9cd941f392dbf99ddfcde9721bd5c485823bdf0 
35f20bbe5ce45194dff68c52018cb3cf04b533f7 --extensions h,c -- 
clang/lib/Headers/amdgpuintrin.h clang/lib/Headers/gpuintrin.h 
clang/lib/Headers/nvptxintrin.h clang/test/Headers/gpuintrin.c 
clang/test/Headers/gpuintrin_lang.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Headers/nvptxintrin.h b/clang/lib/Headers/nvptxintrin.h
index e66c13bb1c..c585f71f60 100644
--- a/clang/lib/Headers/nvptxintrin.h
+++ b/clang/lib/Headers/nvptxintrin.h
@@ -191,7 +191,7 @@ _DEFAULT_FN_ATTRS [[noreturn]] static __inline__ void 
__gpu_exit(void) {
 // Suspend the thread briefly to assist the scheduler during busy loops.
 _DEFAULT_FN_ATTRS static __inline__ void __gpu_thread_suspend(void) {
   if (__nvvm_reflect("__CUDA_ARCH") >= 700)
-LIBC_INLINE_ASM("nanosleep.u32 64;" :: : "memory");
+LIBC_INLINE_ASM("nanosleep.u32 64;" ::: "memory");
 }
 
 _Pragma("omp end declare variant");

``




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


[clang] [StaticAnalyzer] early return if sym is concrete on assuming (PR #115579)

2024-11-11 Thread Balazs Benics via cfe-commits

https://github.com/steakhal commented:

> Thanks for the commit, I'm satisfied with it :)
> 
> I actually like that these two related changes (the checker change and the 
> constraint manager improvement) are handled together in a single commit -- 
> this way somebody who browses the commit log can directly see the "other 
> half" of the change (without following cumbersome links through "this commit 
> is mentioned in the commit message of that one" or opening this github 
> review). Also, the checker change is so trivial (+2 lines) that the full 
> combined commit is still small enough to be easily understood.

I agree.

The patch looks good to me. I made some recommendations for improving the tests.

I have one question. In the StdLibraryFn checker you added a test for 
`isSink()`.
I thought that the crash was that some `assume(..., true|false)` returned a 
null State, that we dereferenced. Where was that assume call and how did we 
unconditionally dereference it?

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


[clang] [StaticAnalyzer] early return if sym is concrete on assuming (PR #115579)

2024-11-11 Thread Balazs Benics via cfe-commits

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


[clang] [StaticAnalyzer] early return if sym is concrete on assuming (PR #115579)

2024-11-11 Thread Balazs Benics via cfe-commits


@@ -0,0 +1,31 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify
+
+void clang_analyzer_eval(int);
+
+void test_derived_sym_simplification_on_assume(int s0, int s1) {
+  int elem = s0 + s1 + 1;
+  if (elem-- == 0) // elem = s0 + s1
+return;
+
+  if (elem-- == 0) // elem = s0 + s1 - 1
+return;
+
+  if (s0 < 1) // s0: [1, 2147483647]

steakhal wrote:

You should use `clang_analyzer_value()` to demonstrate these ranges. That way 
these wouldn't ever go stale, unlike comments.

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-11 Thread Utkarsh Saxena via cfe-commits


@@ -3967,6 +3967,80 @@ Attribute ``trivial_abi`` has no effect in the following 
cases:
   }];
 }
 
+
+def LifetimeCaptureByDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Similar to `lifetimebound`_, the ``lifetime_capture_by(X)`` attribute on a 
function
+parameter or implicit object parameter indicates that that objects that are 
referred to
+by that parameter may also be referred to by the capturing entity ``X``.
+
+The ``lifetimebound`` attribute on a function parameter or implicit object

usx95 wrote:

Aah. missed to push this change. Thanks.

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


[clang] [StaticAnalyzer] early return if sym is concrete on assuming (PR #115579)

2024-11-11 Thread Balazs Benics via cfe-commits


@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=unix.StdCLibraryFunctions \
+// RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -triple x86_64-unknown-linux-gnu \
+// RUN:   -verify
+
+// expected-no-diagnostics
+
+#include "Inputs/std-c-library-functions-POSIX.h"
+
+void _add_one_to_index_C(int *indices, int *shape) {
+  int k = 1;
+  for (; k >= 0; k--)
+if (indices[k] < shape[k])
+  indices[k]++;
+else
+  indices[k] = 0;
+}
+
+void PyObject_CopyData_sptr(char *i, char *j, int *indices, int itemsize,
+int *shape, struct sockaddr *restrict sa) {
+  int elements = 1;
+  for (int k = 0; k < 2; k++)
+elements += shape[k];
+
+  // no contradiction after 3 iterations when 'elements' could be
+  // simplified to 0

steakhal wrote:

Can we dump some value to inspect that something got simplified here?
To me, having no reports in the test doesn't derive any information about what 
the test supposed to test.
By judging the file name, it crashed somewhere, but it's not clear at during 
which statement evaluation and in what constraints.

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-11 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/111499

>From 85df517d9e09f355691fa797e80514e738999f1b Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Sun, 10 Nov 2024 07:42:49 +
Subject: [PATCH] Introduce [[clang::lifetime_capture_by]]

---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Basic/Attr.td |  33 ++
 clang/include/clang/Basic/AttrDocs.td |  69 
 .../clang/Basic/DiagnosticSemaKinds.td|  12 ++
 clang/include/clang/Sema/Sema.h   |   8 ++
 clang/lib/AST/TypePrinter.cpp |  15 +++
 clang/lib/Sema/SemaDecl.cpp   |   1 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 103 ++
 clang/lib/Sema/SemaType.cpp   |  13 +++
 clang/test/AST/attr-lifetime-capture-by.cpp   |   9 ++
 .../test/SemaCXX/attr-lifetime-capture-by.cpp |  42 +++
 11 files changed, 308 insertions(+)
 create mode 100644 clang/test/AST/attr-lifetime-capture-by.cpp
 create mode 100644 clang/test/SemaCXX/attr-lifetime-capture-by.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c3424e0e6f34c9c..93cce21156634d5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -449,6 +449,9 @@ Attribute Changes in Clang
 - Fix a bug where clang doesn't automatically apply the ``[[gsl::Owner]]`` or
   ``[[gsl::Pointer]]`` to STL explicit template specialization decls. 
(#GH109442)
 
+- Clang now supports ``[[clang::lifetime_capture_by(X)]]``. Similar to 
lifetimebound, this can be
+  used to specify when a reference to a function parameter is captured by 
another capturing entity ``X``.
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index a631e81d40aa686..6a77967c32cbcba 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1889,6 +1889,39 @@ def LifetimeBound : DeclOrTypeAttr {
   let SimpleHandler = 1;
 }
 
+def LifetimeCaptureBy : DeclOrTypeAttr {
+  let Spellings = [Clang<"lifetime_capture_by", 0>];
+  let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
+  let Args = [VariadicParamOrParamIdxArgument<"Params">];
+  let Documentation = [LifetimeCaptureByDocs];
+  let AdditionalMembers = [{
+private:
+  SmallVector ArgIdents;
+  SmallVector ArgLocs;
+
+public:
+  static constexpr int THIS = 0;
+  static constexpr int INVALID = -1;
+  static constexpr int UNKNOWN = -2;
+  static constexpr int GLOBAL = -3;
+
+  void setArgs(SmallVector&& Idents,
+   SmallVector&& Locs) { 
+assert(Idents.size() == Locs.size());
+assert(Idents.size() == params_Size);
+ArgIdents = std::move(Idents);
+ArgLocs = std::move(Locs);
+  }
+  
+  ArrayRef getArgIdents() const { return ArgIdents; }
+  ArrayRef getArgLocs() const { return ArgLocs; }
+  void setParamIdx(size_t Idx, int Val) { 
+assert(Idx < params_Size);
+params_[Idx] = Val;
+  }
+}];
+}
+
 def TrivialABI : InheritableAttr {
   // This attribute does not have a C [[]] spelling because it requires the
   // CPlusPlus language option.
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b64dbef6332e6a8..21fcd183e8969c6 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3918,6 +3918,75 @@ have their lifetimes extended.
   }];
 }
 
+def LifetimeCaptureByDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Similar to `lifetimebound`_, the ``lifetime_capture_by(X)`` attribute on a 
function
+parameter or implicit object parameter indicates that that objects that are 
referred to
+by that parameter may also be referred to by the capturing entity ``X``.
+
+By default, a reference is considered to refer to its referenced object, a
+pointer is considered to refer to its pointee, a ``std::initializer_list``
+is considered to refer to its underlying array, and aggregates (arrays and
+simple ``struct``\s) are considered to refer to all objects that their
+transitive subobjects refer to.
+
+The capturing entity ``X`` can be one of the following:
+- Another (named) function parameter. 
+  
+  .. code-block:: c++
+
+void addToSet(std::string_view a [[clang::lifetime_capture_by(s)]], 
std::set& s) {
+  s.insert(a);
+}
+
+- ``this`` (in case of member functions).
+  
+  .. code-block:: c++
+
+class S {
+  void addToSet(std::string_view a [[clang::lifetime_capture_by(this)]]) {
+s.insert(a);
+  }
+  std::set s;
+};
+
+- 'global', 'unknown' (without quotes).
+  
+  .. code-block:: c++
+
+std::set s;
+void addToSet(std::string_view a [[clang::lifetime_capture_by(global)]]) {
+  s.insert(a);
+}
+void addSomewhere(std::string_view a 
[[clang::lifetime_capture_by(unknown)]]);
+
+The attribute can be applied to the impl

[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-11 Thread Utkarsh Saxena via cfe-commits


@@ -3967,6 +3967,80 @@ Attribute ``trivial_abi`` has no effect in the following 
cases:
   }];
 }
 
+
+def LifetimeCaptureByDocs : Documentation {

usx95 wrote:

Done.

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


[libclc] [libclc] Move sign to the CLC builtins library (PR #115699)

2024-11-11 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

> So is the sign function currently implemented in the OpenCL headers?

The sign function for SPIR-V/Mesa is currently implemented by libclc 
[here](https://github.com/llvm/llvm-project/blob/main/libclc/generic/lib/common/sign.cl).
 With this change, `sign` now calls `__clc_sign` which has the same 
implementation. We just need to do a bit of extra inlining of CLC functions 
into OpenCL functions to maintain more or less the same SPIR-V.

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


[libclc] [libclc] Move sign to the CLC builtins library (PR #115699)

2024-11-11 Thread Fraser Cormack via cfe-commits

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


[clang] [analyzer][NFC] Make RegionStore dumps deterministic (PR #115615)

2024-11-11 Thread Balazs Benics via cfe-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/115615

>From 26f0cfabe3328c8eb8a861dd5d1d541921499f0c Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Sat, 9 Nov 2024 15:55:08 +0100
Subject: [PATCH 1/2] [analyzer][NFC] Make RegionStore dumps deterministic

Dump the memory space clusters before the other clusters, in
alphabetical order. Then default bindings over direct bindings, and if
any has symbolic offset, then those should come before the ones with
concrete offsets.
In theory, we should either have a symbolic offset OR concrete offsets,
but never both at the same time.
---
 clang/lib/StaticAnalyzer/Core/RegionStore.cpp | 86 ---
 1 file changed, 73 insertions(+), 13 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp 
b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index 674099dd7e1f0f..6bad9a93a30169 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -67,9 +67,10 @@ class BindingKey {
 isa(r)) &&
"Not a base");
   }
-public:
 
+public:
   bool isDirect() const { return P.getInt() & Direct; }
+  bool isDefault() const { return !isDirect(); }
   bool hasSymbolicOffset() const { return P.getInt() & Symbolic; }
 
   const MemRegion *getRegion() const { return P.getPointer(); }
@@ -232,27 +233,86 @@ class RegionBindingsRef : public 
llvm::ImmutableMapRef StringifyCache;
+auto ToString = [&StringifyCache](const MemRegion *R) {
+  auto [Place, Inserted] = StringifyCache.try_emplace(R);
+  if (!Inserted)
+return Place->second;
+  std::string Res;
+  raw_string_ostream OS(Res);
+  OS << R;
+  Place->second = Res;
+  return Res;
+};
+
+using Cluster =
+std::pair>;
+using Binding = std::pair;
+
+const auto MemSpaceBeforeRegionName = [&ToString](const Cluster *L,
+  const Cluster *R) {
+  if (isa(L->first) && !isa(R->first))
+return true;
+  if (!isa(L->first) && isa(R->first))
+return false;
+  return ToString(L->first) < ToString(R->first);
+};
+
+const auto SymbolicBeforeOffset = [&ToString](const BindingKey &L,
+  const BindingKey &R) {
+  if (L.hasSymbolicOffset() && !R.hasSymbolicOffset())
+return true;
+  if (!L.hasSymbolicOffset() && R.hasSymbolicOffset())
+return false;
+  if (L.hasSymbolicOffset() && R.hasSymbolicOffset())
+return ToString(L.getRegion()) < ToString(R.getRegion());
+  return L.getOffset() < R.getOffset();
+};
+
+const auto DefaultBindingBeforeDirectBindings =
+[&SymbolicBeforeOffset](const Binding *LPtr, const Binding *RPtr) {
+  const BindingKey &L = LPtr->first;
+  const BindingKey &R = RPtr->first;
+  if (L.isDefault() && !R.isDefault())
+return true;
+  if (!L.isDefault() && R.isDefault())
+return false;
+  assert(L.isDefault() == R.isDefault());
+  return SymbolicBeforeOffset(L, R);
+};
+
+const auto AddrOf = [](const auto &Item) { return &Item; };
+
+std::vector SortedClusters;
+SortedClusters.reserve(std::distance(begin(), end()));
+append_range(SortedClusters, map_range(*this, AddrOf));
+llvm::sort(SortedClusters, MemSpaceBeforeRegionName);
+
+for (auto [Idx, C] : llvm::enumerate(SortedClusters)) {
+  const auto &[BaseRegion, Bindings] = *C;
   Indent(Out, Space, IsDot)
-  << "{ \"cluster\": \"" << I.getKey() << "\", \"pointer\": \""
-  << (const void *)I.getKey() << "\", \"items\": [" << NL;
+  << "{ \"cluster\": \"" << BaseRegion << "\", \"pointer\": \""
+  << (const void *)BaseRegion << "\", \"items\": [" << NL;
+
+  std::vector SortedBindings;
+  SortedBindings.reserve(std::distance(Bindings.begin(), Bindings.end()));
+  append_range(SortedBindings, map_range(Bindings, AddrOf));
+  llvm::sort(SortedBindings, DefaultBindingBeforeDirectBindings);
 
   ++Space;
-  const ClusterBindings &CB = I.getData();
-  for (ClusterBindings::iterator CI = CB.begin(), CE = CB.end(); CI != CE;
-   ++CI) {
-Indent(Out, Space, IsDot) << "{ " << CI.getKey() << ", \"value\": ";
-CI.getData().printJson(Out, /*AddQuotes=*/true);
+  for (auto [Idx, B] : llvm::enumerate(SortedBindings)) {
+const auto &[Key, Value] = *B;
+Indent(Out, Space, IsDot) << "{ " << Key << ", \"value\": ";
+Value.printJson(Out, /*AddQuotes=*/true);
 Out << " }";
-if (std::next(CI) != CE)
+if (Idx != SortedBindings.size() - 1)
   Out << ',';
 Out << NL;
   }
-
   --Space;
   Indent(Out, Space, IsDot) << "]}";
-  if (std::next(I) != E)
+  if (Idx != SortedClusters.size() - 1)
 Out << ',';
   Out << NL;
 }

>From 48d25454ba3a5a

[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-11-11 Thread Jon Roelofs via cfe-commits

jroelofs wrote:

I think this diagnostic should not be firing on `%x` format specifiers:

https://clang.godbolt.org/z/YGh1qdq1h

```
#include 

void bad() {
int u = 0;
printf("%x\n", u);
}
```

```
:5:20: warning: format specifies type 'unsigned int' but the argument 
has type 'int' [-Wformat]
5 | printf("%x\n", u);
  | ~~ ^
  | %x
1 warning generated.
```

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


[clang] [analyzer][NFC] Make RegionStore dumps deterministic (PR #115615)

2024-11-11 Thread Balazs Benics via cfe-commits


@@ -232,27 +233,86 @@ class RegionBindingsRef : public 
llvm::ImmutableMapRef StringifyCache;
+auto ToString = [&StringifyCache](const MemRegion *R) {
+  auto [Place, Inserted] = StringifyCache.try_emplace(R);
+  if (!Inserted)
+return Place->second;
+  std::string Res;
+  raw_string_ostream OS(Res);
+  OS << R;
+  Place->second = Res;
+  return Res;
+};
+
+using Cluster =
+std::pair>;
+using Binding = std::pair;
+
+const auto MemSpaceBeforeRegionName = [&ToString](const Cluster *L,
+  const Cluster *R) {
+  if (isa(L->first) && !isa(R->first))
+return true;
+  if (!isa(L->first) && isa(R->first))
+return false;
+  return ToString(L->first) < ToString(R->first);
+};
+
+const auto SymbolicBeforeOffset = [&ToString](const BindingKey &L,
+  const BindingKey &R) {
+  if (L.hasSymbolicOffset() && !R.hasSymbolicOffset())
+return true;
+  if (!L.hasSymbolicOffset() && R.hasSymbolicOffset())
+return false;
+  if (L.hasSymbolicOffset() && R.hasSymbolicOffset())
+return ToString(L.getRegion()) < ToString(R.getRegion());
+  return L.getOffset() < R.getOffset();
+};
+
+const auto DefaultBindingBeforeDirectBindings =
+[&SymbolicBeforeOffset](const Binding *LPtr, const Binding *RPtr) {
+  const BindingKey &L = LPtr->first;
+  const BindingKey &R = RPtr->first;
+  if (L.isDefault() && !R.isDefault())
+return true;
+  if (!L.isDefault() && R.isDefault())
+return false;
+  assert(L.isDefault() == R.isDefault());
+  return SymbolicBeforeOffset(L, R);
+};
+

steakhal wrote:

Good idea. One minor remark is that with using this tuple technique, the 
stringifications would happen eagerly instead of lazily, but this is dump code, 
so it shouldn't matter. Thanks for the suggestion!

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


[clang] [llvm] [Offload] Move HIP and CUDA to new driver by default (PR #84420)

2024-11-11 Thread Joseph Huber via cfe-commits

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

>From 8d63e56aa5af8b86d757d1f1ff68267d3dd1ccd4 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 7 Mar 2024 15:48:00 -0600
Subject: [PATCH] [Offload] Move HIP and CUDA to new driver by default

Summary:
This patch updates the `--offload-new-driver` flag to be default for all
current offloading languages. This mostly just required updating a lot
of tests to use the old format. I tried to update them where possible,
but some were directly checking the old format.

This is not intended to be landed immediately, but to allow for greater
testing. One potential issue I've discovered is the lack of SPIR-V
support or handling for `--offload`.
---
 clang/lib/Driver/Driver.cpp   |  8 +++---
 clang/lib/Driver/ToolChains/Clang.cpp | 19 ++
 clang/test/Driver/cl-offload.cu   |  5 ++--
 clang/test/Driver/cuda-arch-translation.cu| 26 +--
 clang/test/Driver/cuda-bindings.cu| 24 -
 clang/test/Driver/cuda-options.cu | 23 
 clang/test/Driver/cuda-output-asm.cu  |  4 ---
 clang/test/Driver/hip-gz-options.hip  |  1 -
 clang/test/Driver/hip-invalid-target-id.hip   |  4 +--
 clang/test/Driver/hip-macros.hip  |  3 ---
 clang/test/Driver/hip-offload-arch.hip|  4 +--
 clang/test/Driver/hip-options.hip |  6 +
 clang/test/Driver/hip-sanitize-options.hip|  2 +-
 clang/test/Driver/hip-save-temps.hip  | 12 -
 .../test/Driver/hip-toolchain-device-only.hip |  4 ---
 clang/test/Driver/hip-toolchain-mllvm.hip |  2 --
 clang/test/Driver/hip-toolchain-no-rdc.hip|  2 +-
 clang/test/Driver/invalid-offload-options.cpp |  2 +-
 .../ClangLinkerWrapper.cpp|  9 +--
 clang/unittests/Tooling/ToolingTest.cpp   |  6 ++---
 llvm/lib/Object/OffloadBinary.cpp | 13 +++---
 21 files changed, 83 insertions(+), 96 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 93e85f7dffe35a0..212af24f4fe8cd7 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4183,11 +4183,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
   handleArguments(C, Args, Inputs, Actions);
 
   bool UseNewOffloadingDriver =
-  C.isOffloadingHostKind(Action::OFK_OpenMP) ||
-  Args.hasFlag(options::OPT_foffload_via_llvm,
-   options::OPT_fno_offload_via_llvm, false) ||
+  C.getActiveOffloadKinds() != Action::OFK_None &&
   Args.hasFlag(options::OPT_offload_new_driver,
-   options::OPT_no_offload_new_driver, false);
+   options::OPT_no_offload_new_driver, true);
 
   // Builder to be used to build offloading actions.
   std::unique_ptr OffloadBuilder =
@@ -4913,7 +4911,7 @@ Action *Driver::ConstructPhaseAction(
offloadDeviceOnly() ||
(TargetDeviceOffloadKind == Action::OFK_HIP &&
 !Args.hasFlag(options::OPT_offload_new_driver,
-  options::OPT_no_offload_new_driver, false)))
+  options::OPT_no_offload_new_driver, true)))
   ? types::TY_LLVM_IR
   : types::TY_LLVM_BC;
   return C.MakeAction(Input, Output);
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0952262c360185e..6f0895a7c97ffe2 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5041,8 +5041,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   bool IsHostOffloadingAction =
   JA.isHostOffloading(Action::OFK_OpenMP) ||
   (JA.isHostOffloading(C.getActiveOffloadKinds()) &&
+   C.getActiveOffloadKinds() != Action::OFK_None &&
Args.hasFlag(options::OPT_offload_new_driver,
-options::OPT_no_offload_new_driver, false));
+options::OPT_no_offload_new_driver, true));
 
   bool IsRDCMode =
   Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
@@ -5374,7 +5375,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 if (IsUsingLTO) {
   if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) 
&&
   !Args.hasFlag(options::OPT_offload_new_driver,
-options::OPT_no_offload_new_driver, false) &&
+options::OPT_no_offload_new_driver, true) &&
   !Triple.isAMDGPU()) {
 D.Diag(diag::err_drv_unsupported_opt_for_target)
 << Args.getLastArg(options::OPT_foffload_lto,
@@ -6843,16 +6844,12 @@ void Clang::ConstructJob(Compilation &C, const 
JobAction &JA,
 Args.addOptOutFlag(CmdArgs, options::OPT_fopenmp_extensions,
options::OPT_fno_openmp_extensions);
   }
-  // Forward the offload runtime change t

[clang] [PAC][clang][Driver] Add signed GOT flag (PR #96160)

2024-11-11 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Sorry, I made a mistake by approving #85235, which added a lot of driver 
options. It's not clear who are the initial ELF ptrauth users, but I am not 
sure with a very small user base, there are a lot of demands to customize the 
protection in such a fine-grained manner.

Using cc1 options looks fine.

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


[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-11-11 Thread Fangrui Song via cfe-commits

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


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


[clang] 9d4837f - [clang][deps][modules] Allocate input file paths lazily (#114457)

2024-11-11 Thread via cfe-commits

Author: Jan Svoboda
Date: 2024-11-11T09:46:50-08:00
New Revision: 9d4837f47c48c634d4a0ac799188e1f5332495ef

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

LOG: [clang][deps][modules] Allocate input file paths lazily (#114457)

This PR builds on top of #113984 and attempts to avoid allocating input
file paths eagerly. Instead, the `InputFileInfo` type used by
`ASTReader` now only holds `StringRef`s that point into the PCM file
buffer, and the full input file paths get resolved on demand.

The dependency scanner makes use of this in a bit of a roundabout way:
`ModuleDeps` now only holds (an owning copy of) the short unresolved
input file paths, which get resolved lazily. This can be a big win, I'm
seeing up to a 5% speedup.

Added: 


Modified: 
clang/include/clang/Serialization/ModuleFile.h
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/test/ClangScanDeps/diagnostics.c
clang/test/ClangScanDeps/header-search-pruning-transitive.c
clang/test/ClangScanDeps/link-libraries.c
clang/test/ClangScanDeps/modules-context-hash.c
clang/test/ClangScanDeps/modules-dep-args.c
clang/test/ClangScanDeps/modules-extern-submodule.c
clang/test/ClangScanDeps/modules-extern-unrelated.m
clang/test/ClangScanDeps/modules-file-path-isolation.c
clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
clang/test/ClangScanDeps/modules-full-by-mod-name.c
clang/test/ClangScanDeps/modules-full.cpp
clang/test/ClangScanDeps/modules-implicit-dot-private.m
clang/test/ClangScanDeps/modules-incomplete-umbrella.c
clang/test/ClangScanDeps/modules-inferred.m
clang/test/ClangScanDeps/modules-no-undeclared-includes.c
clang/test/ClangScanDeps/modules-pch-common-submodule.c
clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
clang/test/ClangScanDeps/modules-pch.c
clang/test/ClangScanDeps/modules-priv-fw-from-pub.m
clang/test/ClangScanDeps/modules-redefinition.m
clang/test/ClangScanDeps/modules-symlink-dir-vfs.c
clang/test/ClangScanDeps/modules-transitive.c
clang/test/ClangScanDeps/optimize-vfs.m
clang/test/ClangScanDeps/removed-args.c
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ModuleFile.h 
b/clang/include/clang/Serialization/ModuleFile.h
index 29d3354d07a129..f20cb2f9f35ae8 100644
--- a/clang/include/clang/Serialization/ModuleFile.h
+++ b/clang/include/clang/Serialization/ModuleFile.h
@@ -62,8 +62,9 @@ enum ModuleKind {
 
 /// The input file info that has been loaded from an AST file.
 struct InputFileInfo {
-  std::string FilenameAsRequested;
-  std::string Filename;
+  StringRef UnresolvedImportedFilenameAsRequested;
+  StringRef UnresolvedImportedFilename;
+
   uint64_t ContentHash;
   off_t StoredSize;
   time_t StoredTime;
@@ -71,6 +72,10 @@ struct InputFileInfo {
   bool Transient;
   bool TopLevel;
   bool ModuleMap;
+
+  bool isValid() const {
+return !UnresolvedImportedFilenameAsRequested.empty();
+  }
 };
 
 /// The input file that has been loaded from this AST file, along with

diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h 
b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index 3de19d756da00d..c2071a6eadedd1 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -120,10 +120,6 @@ struct ModuleDeps {
   /// additionally appear in \c FileDeps as a dependency.
   std::string ClangModuleMapFile;
 
-  /// A collection of absolute paths to files that this module directly depends
-  /// on, not including transitive dependencies.
-  llvm::StringSet<> FileDeps;
-
   /// A collection of absolute paths to module map files that this module needs
   /// to know about. The ordering is significant.
   std::vector ModuleMapFileDeps;
@@ -143,13 +139,25 @@ struct ModuleDeps {
   /// an entity from this module is used.
   llvm::SmallVector LinkLibraries;
 
+  /// Invokes \c Cb for all file dependencies of this module. Each provided
+  /// \c StringRef is only valid within the individual callback invocation.
+  void forEachFileDep(llvm::function_ref Cb) const;
+
   /// Get (or compute) the compiler invocation that can be used to build this
   /// module. Does not include argv[0].
   const std::vector &getBuildArguments();
 
 private:
+  friend class ModuleDepCollector;
   friend class ModuleDepCollectorPP;
 
+  /// The base directory for relative paths in \c FileDeps.
+  std::string FileDepsBaseDir;
+
+  /// A collection of paths to files that this module di

[clang] [clang][deps][modules] Allocate input file paths lazily (PR #114457)

2024-11-11 Thread Jan Svoboda via cfe-commits

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


[clang] 3a03513 - Revert "[clang] Introduce [[clang::lifetime_capture_by(X)]] (#111499)"

2024-11-11 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2024-11-11T20:57:26+01:00
New Revision: 3a03513fc6ef8f3272d33be19164243c9dbf0452

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

LOG: Revert "[clang] Introduce [[clang::lifetime_capture_by(X)]] (#111499)"

This reverts commit 8c4331c1abeb33eabf3cdbefa7f2b6e0540e7f4f.

Causes a large compile-time regression, see:
https://llvm-compile-time-tracker.com/compare.php?from=4a68e4cbd2423dcacada8162ab7c4bb8d7f7e2cf&to=8c4331c1abeb33eabf3cdbefa7f2b6e0540e7f4f&stat=instructions:u

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/TypePrinter.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaType.cpp

Removed: 
clang/test/AST/attr-lifetime-capture-by.cpp
clang/test/SemaCXX/attr-lifetime-capture-by.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e817b0ceb3fd06..e235a04f78112b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -449,9 +449,6 @@ Attribute Changes in Clang
 - Fix a bug where clang doesn't automatically apply the ``[[gsl::Owner]]`` or
   ``[[gsl::Pointer]]`` to STL explicit template specialization decls. 
(#GH109442)
 
-- Clang now supports ``[[clang::lifetime_capture_by(X)]]``. Similar to 
lifetimebound, this can be
-  used to specify when a reference to a function parameter is captured by 
another capturing entity ``X``.
-
 Improvements to Clang's diagnostics
 ---
 

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 6a77967c32cbcb..a631e81d40aa68 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1889,39 +1889,6 @@ def LifetimeBound : DeclOrTypeAttr {
   let SimpleHandler = 1;
 }
 
-def LifetimeCaptureBy : DeclOrTypeAttr {
-  let Spellings = [Clang<"lifetime_capture_by", 0>];
-  let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
-  let Args = [VariadicParamOrParamIdxArgument<"Params">];
-  let Documentation = [LifetimeCaptureByDocs];
-  let AdditionalMembers = [{
-private:
-  SmallVector ArgIdents;
-  SmallVector ArgLocs;
-
-public:
-  static constexpr int THIS = 0;
-  static constexpr int INVALID = -1;
-  static constexpr int UNKNOWN = -2;
-  static constexpr int GLOBAL = -3;
-
-  void setArgs(SmallVector&& Idents,
-   SmallVector&& Locs) { 
-assert(Idents.size() == Locs.size());
-assert(Idents.size() == params_Size);
-ArgIdents = std::move(Idents);
-ArgLocs = std::move(Locs);
-  }
-  
-  ArrayRef getArgIdents() const { return ArgIdents; }
-  ArrayRef getArgLocs() const { return ArgLocs; }
-  void setParamIdx(size_t Idx, int Val) { 
-assert(Idx < params_Size);
-params_[Idx] = Val;
-  }
-}];
-}
-
 def TrivialABI : InheritableAttr {
   // This attribute does not have a C [[]] spelling because it requires the
   // CPlusPlus language option.

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 21fcd183e8969c..b64dbef6332e6a 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3918,75 +3918,6 @@ have their lifetimes extended.
   }];
 }
 
-def LifetimeCaptureByDocs : Documentation {
-  let Category = DocCatFunction;
-  let Content = [{
-Similar to `lifetimebound`_, the ``lifetime_capture_by(X)`` attribute on a 
function
-parameter or implicit object parameter indicates that that objects that are 
referred to
-by that parameter may also be referred to by the capturing entity ``X``.
-
-By default, a reference is considered to refer to its referenced object, a
-pointer is considered to refer to its pointee, a ``std::initializer_list``
-is considered to refer to its underlying array, and aggregates (arrays and
-simple ``struct``\s) are considered to refer to all objects that their
-transitive subobjects refer to.
-
-The capturing entity ``X`` can be one of the following:
-- Another (named) function parameter. 
-  
-  .. code-block:: c++
-
-void addToSet(std::string_view a [[clang::lifetime_capture_by(s)]], 
std::set& s) {
-  s.insert(a);
-}
-
-- ``this`` (in case of member functions).
-  
-  .. code-block:: c++
-
-class S {
-  void addToSet(std::string_view a [[clang::lifetime_capture_by(this)]]) {
-s.insert(a);
-  }
-  std::set s;
-};
-
-- 'global', 'unknown' (without quotes).
-  
-  .. code-block:: c++
-
-std::set s;
-void addToSet(std::string_view a [[clang::lifetime_capture_by(global)]]) {
-  s.insert(a);
-}
-void addSomewhere(std::str

[clang] [libc] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)

2024-11-11 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-hexagon-elf` running 
on `hexagon-build-03` while building `clang` at step 5 "ninja check 1".

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


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

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'Clang :: Headers/gpuintrin_lang.c' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/stage1/bin/clang 
-cc1 -internal-isystem 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/stage1/lib/clang/20/include
 -nostdsysteminc -internal-isystem 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/Inputs/include
-internal-isystem 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/../../lib/Headers/cuda_wrappers
-internal-isystem 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/../../lib/Headers/
-fcuda-is-device -triple nvptx64 -emit-llvm 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/gpuintrin_lang.c
 -o -  | 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/stage1/bin/FileCheck
 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/gpuintrin_lang.c
 --check-prefix=CUDA
+ /local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/stage1/bin/clang 
-cc1 -internal-isystem 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/stage1/lib/clang/20/include
 -nostdsysteminc -internal-isystem 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/Inputs/include
 -internal-isystem 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/../../lib/Headers/cuda_wrappers
 -internal-isystem 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/../../lib/Headers/
 -fcuda-is-device -triple nvptx64 -emit-llvm 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/gpuintrin_lang.c
 -o -
+ 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/stage1/bin/FileCheck
 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/gpuintrin_lang.c
 --check-prefix=CUDA
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/gpuintrin_lang.c:39:15:
 error: CUDA-NEXT: expected string not found in input
// CUDA-NEXT: [[TMP0:%.*]] = call range(i32 0, 1024) i32 
@llvm.nvvm.read.ptx.sreg.tid.x()
  ^
:8:7: note: scanning from here
entry:
  ^
:9:2: note: possible intended match here
 %0 = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
 ^

Input file: 
Check file: 
/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/gpuintrin_lang.c

-dump-input=help explains the following input dump.

Input was:
<<
   1: ; ModuleID = 
'/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/gpuintrin_lang.c'
 
   2: source_filename = 
"/local/mnt/workspace/bots/hexagon-build-03/clang-hexagon-elf/llvm/clang/test/Headers/gpuintrin_lang.c"
 
   3: target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64" 
   4: target triple = "nvptx64" 
   5:  
   6: ; Function Attrs: convergent noinline nounwind optnone 
   7: define dso_local i32 @foo() #0 { 
   8: entry: 
next:39'0   X error: no match found
   9:  %0 = call i32 @llvm.nvvm.read.ptx.sreg.tid.x() 
next:39'0 
next:39'1  ?   possible 
intended match
  10:  ret i32 %0 
next:39'0 
  11: } 
next:39'0 ~~
  12:  
next:39'0 ~
  13: ; Function Attrs: nocallback nofree nosync nounwind speculatable 
willreturn memory(none) 
next:39'0 
~
  14: declare noundef i32 @llvm.nvvm.read.ptx.sreg.tid.x() #1 
next:39'0 
   .
   .
   .
...

```



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


[clang] [clang][deps] Only write preprocessor info into PCMs (PR #115239)

2024-11-11 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-m68k-linux-cross` 
running on `suse-gary-m68k-cross` while building `clang` at step 5 "ninja check 
1".

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


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

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
...
 from 
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h:13,
 from 
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp:17:
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/include/clang/Sema/Sema.h:463:7:
 warning: ‘clang::Sema’ declared with greater visibility than the type of its 
field ‘clang::Sema::UnusedFileScopedDecls’ [-Wattributes]
  463 | class Sema final : public SemaBase {
  |   ^~~~
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/include/clang/Sema/Sema.h:463:7:
 warning: ‘clang::Sema’ declared with greater visibility than the type of its 
field ‘clang::Sema::TentativeDefinitions’ [-Wattributes]
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/include/clang/Sema/Sema.h:463:7:
 warning: ‘clang::Sema’ declared with greater visibility than the type of its 
field ‘clang::Sema::ExtVectorDecls’ [-Wattributes]
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/include/clang/Sema/Sema.h:463:7:
 warning: ‘clang::Sema’ declared with greater visibility than the type of its 
field ‘clang::Sema::DelegatingCtorDecls’ [-Wattributes]
[211/378] Building CXX object 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/LookupTest.cpp.o
[212/378] Building CXX object 
tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o
FAILED: tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o 
/usr/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_STATIC -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/tools/clang/unittests/AST
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/unittests/AST
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/include
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/tools/clang/include
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/include
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/llvm/include
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/third-party/unittest/googletest/include
 
-I/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/third-party/unittest/googlemock/include
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic 
-Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull 
-Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move 
-Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-fno-strict-aliasing -O3 -DNDEBUG -std=c++17  -Wno-variadic-macros 
-fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -Wno-suggest-override -MD 
-MT tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o -MF 
tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o.d -o 
tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o -c 
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/unittests/AST/ASTImporterTest.cpp
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
[213/378] Building CXX object 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/RecursiveASTVisitorTests/Class.cpp.o
[214/378] Building CXX object 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/QualTypeNamesTest.cpp.o
[215/378] Building CXX object 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/RangeSelectorTest.cpp.o
[216/378] Building CXX object 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/RecursiveASTVisitorTests/CXXBoolLiteralExpr.cpp.o
[217/378] Building CXX object 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/RecursiveASTVisitorTests/CXXMemberCall.cpp.o
[218/378] Building CXX object 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/RecursiveASTVisitorTests/Attr.cpp.o
[219/378] Building 

[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-11 Thread Evgenii Stepanov via cfe-commits

eugenis wrote:

Please note that this change also introduces new memory leaks on the waterfall:
https://lab.llvm.org/buildbot/#/builders/169/builds/5193

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


[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-11 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

LGTM

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


[clang] Emit constrained atan2 intrinsic for clang builtin (PR #113636)

2024-11-11 Thread Tex Riddell via cfe-commits

tex3d wrote:

@farzonl 
> Here are just a handful of tests that we might want to update, but there are 
> others:

I'm updating these tests that were called out.  What others do I need to look 
for?  How do I know if I've found all the tests I need to update?

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


[clang] [Clang] enhance diagnostic by attaching source location to deduced type in trailing return without auto (PR #115786)

2024-11-11 Thread Oleksandr T. via cfe-commits

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

Fixes #78694

>From da1b3982e84114cb1214ca5c3d8ed520d1589b83 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 12 Nov 2024 00:59:37 +0200
Subject: [PATCH] [Clang] enhance diagnostic by attaching source location to
 deduced type in trailing return without auto

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/Sema/SemaType.cpp   | 15 ---
 .../CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp | 13 -
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e235a04f78112b..f4cd7f99cdce14 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -652,6 +652,7 @@ Bug Fixes to C++ Support
   an implicitly instantiated class template specialization. (#GH51051)
 - Fixed an assertion failure caused by invalid enum forward declarations. 
(#GH112208)
 - Name independent data members were not correctly initialized from default 
member initializers. (#GH114069)
+- Clang now uses deduced type locations in trailing return without auto 
diagnostics. (#GH78694)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 515b9f689a248a..c50d15a3adc442 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -4887,9 +4887,18 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
   cast(T)->getKeyword() !=
   AutoTypeKeyword::Auto ||
   cast(T)->isConstrained())) {
-S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(),
-   diag::err_trailing_return_without_auto)
-<< T << D.getDeclSpec().getSourceRange();
+SourceLocation Loc = D.getDeclSpec().getTypeSpecTypeLoc();
+SourceRange SR = D.getDeclSpec().getSourceRange();
+if (Loc.isInvalid()) {
+  TypeSourceInfo *TSI = nullptr;
+  S.GetTypeFromParser(FTI.getTrailingReturnType(), &TSI);
+  if (TSI) {
+TypeLoc TSILoc = TSI->getTypeLoc();
+Loc = TSILoc.getBeginLoc();
+SR = TSILoc.getSourceRange();
+  }
+}
+S.Diag(Loc, diag::err_trailing_return_without_auto) << T << SR;
 D.setInvalidType(true);
 // FIXME: recover and fill decls in `TypeLoc`s.
 AreDeclaratorChunksValid = false;
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp 
b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp
index ce90728861605f..e43eb8e48c7272 100644
--- a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp
@@ -1,7 +1,18 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+// RUN: not %clang_cc1 -fsyntax-only -std=c++11 
-fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines=1 %s 2>&1 | 
FileCheck %s -strict-whitespace
 
 auto a() -> int; // ok
 const auto b() -> int; // expected-error {{function with trailing return type 
must specify return type 'auto', not 'const auto'}}
 auto *c() -> int; // expected-error {{function with trailing return type must 
specify return type 'auto', not 'auto *'}}
 auto (d() -> int); // expected-error {{trailing return type may not be nested 
within parentheses}}
 auto e() -> auto (*)() -> auto (*)() -> void; // ok: same as void 
(*(*e())())();
+
+namespace GH78694 {
+
+template  struct B {
+  // CHECK:  error: function with trailing return type must specify return 
type 'auto', not 'void'
+  // CHECK-NEXT: {{^}}  template  B(U) -> B;
+  // CHECK-NEXT: {{^}} ^~{{$}}
+  template  B(U) -> B; // expected-error {{function with 
trailing return type must specify return type 'auto', not 'void'}}
+};
+}

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


[clang] [Clang] enhance diagnostic by attaching source location to deduced type in trailing return without auto (PR #115786)

2024-11-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #78694

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Sema/SemaType.cpp (+12-3) 
- (modified) clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp (+12-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e235a04f78112b..f4cd7f99cdce14 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -652,6 +652,7 @@ Bug Fixes to C++ Support
   an implicitly instantiated class template specialization. (#GH51051)
 - Fixed an assertion failure caused by invalid enum forward declarations. 
(#GH112208)
 - Name independent data members were not correctly initialized from default 
member initializers. (#GH114069)
+- Clang now uses deduced type locations in trailing return without auto 
diagnostics. (#GH78694)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 515b9f689a248a..c50d15a3adc442 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -4887,9 +4887,18 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
   cast(T)->getKeyword() !=
   AutoTypeKeyword::Auto ||
   cast(T)->isConstrained())) {
-S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(),
-   diag::err_trailing_return_without_auto)
-<< T << D.getDeclSpec().getSourceRange();
+SourceLocation Loc = D.getDeclSpec().getTypeSpecTypeLoc();
+SourceRange SR = D.getDeclSpec().getSourceRange();
+if (Loc.isInvalid()) {
+  TypeSourceInfo *TSI = nullptr;
+  S.GetTypeFromParser(FTI.getTrailingReturnType(), &TSI);
+  if (TSI) {
+TypeLoc TSILoc = TSI->getTypeLoc();
+Loc = TSILoc.getBeginLoc();
+SR = TSILoc.getSourceRange();
+  }
+}
+S.Diag(Loc, diag::err_trailing_return_without_auto) << T << SR;
 D.setInvalidType(true);
 // FIXME: recover and fill decls in `TypeLoc`s.
 AreDeclaratorChunksValid = false;
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp 
b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp
index ce90728861605f..e43eb8e48c7272 100644
--- a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp
@@ -1,7 +1,18 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+// RUN: not %clang_cc1 -fsyntax-only -std=c++11 
-fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines=1 %s 2>&1 | 
FileCheck %s -strict-whitespace
 
 auto a() -> int; // ok
 const auto b() -> int; // expected-error {{function with trailing return type 
must specify return type 'auto', not 'const auto'}}
 auto *c() -> int; // expected-error {{function with trailing return type must 
specify return type 'auto', not 'auto *'}}
 auto (d() -> int); // expected-error {{trailing return type may not be nested 
within parentheses}}
 auto e() -> auto (*)() -> auto (*)() -> void; // ok: same as void 
(*(*e())())();
+
+namespace GH78694 {
+
+template  struct B {
+  // CHECK:  error: function with trailing return type must specify return 
type 'auto', not 'void'
+  // CHECK-NEXT: {{^}}  template  B(U) -> B;
+  // CHECK-NEXT: {{^}} ^~{{$}}
+  template  B(U) -> B; // expected-error {{function with 
trailing return type must specify return type 'auto', not 'void'}}
+};
+}

``




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


[clang] [clang][ASTImporter] Allow import of similar friend template with different depth (PR #115734)

2024-11-11 Thread Michael Buch via cfe-commits


@@ -6120,6 +6119,19 @@ ExpectedDecl 
ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
   // see ASTTests test ImportExistingFriendClassTemplateDef.
   continue;
 }
+// When importing a friend, it is possible that multiple declarations
+// with same name can co-exist in specific cases (if a template 
contains
+// a friend template and has a specialization). For this case the
+// declarations should match, except that the "template depth" is
+// different. No linking of previous declaration is needed in this 
case.
+// FIXME: This condition may need refinement.
+if (D->getFriendObjectKind() != Decl::FOK_None &&
+FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
+D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
+IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
+  /*IgnoreTemplateParmDepth=*/true))
+  continue;

Michael137 wrote:

It feels like the logic on 6103 and this here could be merged together? Should 
`IgnoreTemplateParmDepth` on 6104 just be changed to also be set if the 
`FriendObjectKind` matches? Then I *think* everything should work out as 
expected

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


[clang] [clang][OpenMP][NFC] Move 'allocate' clause modifier parsing into fun… (PR #115775)

2024-11-11 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev approved this pull request.


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


[clang] [clang][FMV] Fix crash with cpu_specific attribute. (PR #115762)

2024-11-11 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/115762

Raised here https://github.com/llvm/llvm-project/issues/115299.

The commit a2d3099 introduced `replaceDeclarationWith`, but it shouldn't be 
called by the fallthrough code which handles the cpu_specific attribute.

>From aff962d795e56f7b41af44860feb77e656091b78 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Mon, 11 Nov 2024 20:10:01 +
Subject: [PATCH] [clang][FMV] Fix crash with cpu_specific attribute.

Raised here https://github.com/llvm/llvm-project/issues/115299.

The commit a2d3099 introduced `replaceDeclarationWith`, but it
shouldn't be called by the fallthrough code which handles the
cpu_specific attribute.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 --
 clang/test/CodeGen/attr-cpuspecific.c | 12 ++--
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index ba376f9ecfacde..27b1ccb8137356 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4597,8 +4597,6 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   assert(isa(Resolver) &&
  "Resolver should be created for the first time");
   SetCommonAttributes(FD, cast(Resolver));
-  if (ResolverGV)
-replaceDeclarationWith(ResolverGV, Resolver);
   return Resolver;
 }
 
diff --git a/clang/test/CodeGen/attr-cpuspecific.c 
b/clang/test/CodeGen/attr-cpuspecific.c
index 628892d5809b4e..91f6c9e9e06b88 100644
--- a/clang/test/CodeGen/attr-cpuspecific.c
+++ b/clang/test/CodeGen/attr-cpuspecific.c
@@ -114,8 +114,8 @@ void ThreeVersionsSameAttr(void){}
 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.Z() #[[K]]
 
 ATTR(cpu_specific(knl))
-void CpuSpecificNoDispatch(void) {}
-// CHECK: define {{.*}}void @CpuSpecificNoDispatch.Z() #[[K:[0-9]+]]
+void CpuSpecificNoDispatch(void (*f)(void)) {}
+// CHECK: define {{.*}}void @CpuSpecificNoDispatch.Z(ptr noundef %f) 
#[[K:[0-9]+]]
 
 ATTR(cpu_dispatch(knl))
 void OrderDispatchUsageSpecific(void);
@@ -151,9 +151,9 @@ void usages(void) {
   ThreeVersionsSameAttr();
   // LINUX: @ThreeVersionsSameAttr.ifunc()
   // WINDOWS: @ThreeVersionsSameAttr()
-  CpuSpecificNoDispatch();
-  // LINUX: @CpuSpecificNoDispatch.ifunc()
-  // WINDOWS: @CpuSpecificNoDispatch()
+  CpuSpecificNoDispatch((void (*)(void))CpuSpecificNoDispatch);
+  // LINUX: @CpuSpecificNoDispatch.ifunc(ptr noundef 
@CpuSpecificNoDispatch.ifunc)
+  // WINDOWS: @CpuSpecificNoDispatch(ptr noundef @CpuSpecificNoDispatch)
   OrderDispatchUsageSpecific();
   // LINUX: @OrderDispatchUsageSpecific.ifunc()
   // WINDOWS: @OrderDispatchUsageSpecific()
@@ -162,7 +162,7 @@ void usages(void) {
   // WINDOWS: @OrderSpecificUsageDispatch()
 }
 
-// LINUX: declare void @CpuSpecificNoDispatch.ifunc()
+// LINUX: declare void @CpuSpecificNoDispatch.ifunc(ptr)
 
 // has an extra config to emit!
 ATTR(cpu_dispatch(ivybridge, knl, atom))

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


[clang] [clang][FMV] Fix crash with cpu_specific attribute. (PR #115762)

2024-11-11 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Alexandros Lamprineas (labrinea)


Changes

Raised here https://github.com/llvm/llvm-project/issues/115299.

The commit a2d3099 introduced `replaceDeclarationWith`, but it shouldn't be 
called by the fallthrough code which handles the cpu_specific attribute.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (-2) 
- (modified) clang/test/CodeGen/attr-cpuspecific.c (+6-6) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index ba376f9ecfacde..27b1ccb8137356 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4597,8 +4597,6 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   assert(isa(Resolver) &&
  "Resolver should be created for the first time");
   SetCommonAttributes(FD, cast(Resolver));
-  if (ResolverGV)
-replaceDeclarationWith(ResolverGV, Resolver);
   return Resolver;
 }
 
diff --git a/clang/test/CodeGen/attr-cpuspecific.c 
b/clang/test/CodeGen/attr-cpuspecific.c
index 628892d5809b4e..91f6c9e9e06b88 100644
--- a/clang/test/CodeGen/attr-cpuspecific.c
+++ b/clang/test/CodeGen/attr-cpuspecific.c
@@ -114,8 +114,8 @@ void ThreeVersionsSameAttr(void){}
 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.Z() #[[K]]
 
 ATTR(cpu_specific(knl))
-void CpuSpecificNoDispatch(void) {}
-// CHECK: define {{.*}}void @CpuSpecificNoDispatch.Z() #[[K:[0-9]+]]
+void CpuSpecificNoDispatch(void (*f)(void)) {}
+// CHECK: define {{.*}}void @CpuSpecificNoDispatch.Z(ptr noundef %f) 
#[[K:[0-9]+]]
 
 ATTR(cpu_dispatch(knl))
 void OrderDispatchUsageSpecific(void);
@@ -151,9 +151,9 @@ void usages(void) {
   ThreeVersionsSameAttr();
   // LINUX: @ThreeVersionsSameAttr.ifunc()
   // WINDOWS: @ThreeVersionsSameAttr()
-  CpuSpecificNoDispatch();
-  // LINUX: @CpuSpecificNoDispatch.ifunc()
-  // WINDOWS: @CpuSpecificNoDispatch()
+  CpuSpecificNoDispatch((void (*)(void))CpuSpecificNoDispatch);
+  // LINUX: @CpuSpecificNoDispatch.ifunc(ptr noundef 
@CpuSpecificNoDispatch.ifunc)
+  // WINDOWS: @CpuSpecificNoDispatch(ptr noundef @CpuSpecificNoDispatch)
   OrderDispatchUsageSpecific();
   // LINUX: @OrderDispatchUsageSpecific.ifunc()
   // WINDOWS: @OrderDispatchUsageSpecific()
@@ -162,7 +162,7 @@ void usages(void) {
   // WINDOWS: @OrderSpecificUsageDispatch()
 }
 
-// LINUX: declare void @CpuSpecificNoDispatch.ifunc()
+// LINUX: declare void @CpuSpecificNoDispatch.ifunc(ptr)
 
 // has an extra config to emit!
 ATTR(cpu_dispatch(ivybridge, knl, atom))

``




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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-11 Thread Nikita Popov via cfe-commits

nikic wrote:

I've reverted this change, because it causes a large compile-time regression, 
see 
https://llvm-compile-time-tracker.com/compare.php?from=4a68e4cbd2423dcacada8162ab7c4bb8d7f7e2cf&to=8c4331c1abeb33eabf3cdbefa7f2b6e0540e7f4f&stat=instructions:u.

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


[clang] [clang][AST] Add 'IgnoreTemplateParmDepth' to structural equivalence cache (PR #115518)

2024-11-11 Thread Michael Buch via cfe-commits

Michael137 wrote:

> > Another possible solution: Use two `NonEquivalentDecls` sets, one for 
> > `IgnoreTemplateParmDepth = true` and one for `false`. This may use less 
> > memory (no rarely used third value in the key) but requires more code 
> > changes.
> 
> I like this idea, and I think it can be implemented without significant code 
> changes -- see my inline comments for details.
> 
> (Disclaimer: I didn't check my change so there might be other locations where 
> you didn't need to change between the old "set of pairs" and your "set of 
> 3-tuples", but the suggested "two sets of pairs in an array" would behave 
> differently -- but it would be a simplification even if you needed one or two 
> lines of additional logic.)
> 
> However the current "set of 3-tuples" approach is also OK if you prefer it.

One thing I don't like about having two separate caches is the prospect of what 
this looks like if we add another parameter affecting the equivalence. For 
example, we already have another parameter `StrictTypeSpelling`, which by the 
looks of it could affect the result of an equivalence check. That just doesn't 
feel like a future-proof solution. Encoding the flag that affects that hash of 
the cache entry in the entry itself (like @balazske did in the first iteration 
of this PR) would be my preferred approach.

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


[clang] [libc] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)

2024-11-11 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-solaris11-sparcv9` 
running on `solaris11-sparcv9` while building `clang` at step 5 "ninja check 1".

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


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

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'Clang :: Headers/gpuintrin_lang.c' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/bin/clang
 -cc1 -internal-isystem 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/lib/clang/20/include
 -nostdsysteminc -internal-isystem 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/Inputs/include
-internal-isystem 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/../../lib/Headers/cuda_wrappers
-internal-isystem 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/../../lib/Headers/
-fcuda-is-device -triple nvptx64 -emit-llvm 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/gpuintrin_lang.c
 -o -  | 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/bin/FileCheck
 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/gpuintrin_lang.c
 --check-prefix=CUDA
+ 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/bin/clang
 -cc1 -internal-isystem 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/lib/clang/20/include
 -nostdsysteminc -internal-isystem 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/Inputs/include
 -internal-isystem 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/../../lib/Headers/cuda_wrappers
 -internal-isystem 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/../../lib/Headers/
 -fcuda-is-device -triple nvptx64 -emit-llvm 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/gpuintrin_lang.c
 -o -
+ 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/bin/FileCheck
 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/gpuintrin_lang.c
 --check-prefix=CUDA
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/gpuintrin_lang.c:39:15:
 error: CUDA-NEXT: expected string not found in input
// CUDA-NEXT: [[TMP0:%.*]] = call range(i32 0, 1024) i32 
@llvm.nvvm.read.ptx.sreg.tid.x()
  ^
:8:7: note: scanning from here
entry:
  ^
:9:2: note: possible intended match here
 %0 = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
 ^

Input file: 
Check file: 
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/gpuintrin_lang.c

-dump-input=help explains the following input dump.

Input was:
<<
   1: ; ModuleID = 
'/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/gpuintrin_lang.c'
 
   2: source_filename = 
"/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/Headers/gpuintrin_lang.c"
 
   3: target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64" 
   4: target triple = "nvptx64" 
   5:  
   6: ; Function Attrs: convergent noinline nounwind optnone 
   7: define dso_local i32 @foo() #0 { 
   8: entry: 
next:39'0   X error: no match found
   9:  %0 = call i32 @llvm.nvvm.read.ptx.sreg.tid.x() 
next:39'0 
next:39'1  ?   possible 
intended match
  10:  ret i32 %0 
next:39'0 
  11: } 
next:39'0 ~~
  12:  
next:39'0 ~
  13: ; Function Attrs: nocallback nofree nosync nounwind speculatable 
willreturn memory(none) 
next:39'0 
~
  14: declare noundef i32 @llvm.nvvm.read.ptx.sreg.tid.x() #1 
next:39'0 
   .
   .
   .
...

```



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


[clang] [clang][deps] Only write preprocessor info into PCMs (PR #115239)

2024-11-11 Thread Jan Svoboda via cfe-commits

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


[clang] 25d1ac1 - [clang][deps] Only write preprocessor info into PCMs (#115239)

2024-11-11 Thread via cfe-commits

Author: Jan Svoboda
Date: 2024-11-11T13:07:08-08:00
New Revision: 25d1ac11d537debb217c65c2bcdd087a60cff58e

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

LOG: [clang][deps] Only write preprocessor info into PCMs (#115239)

This patch builds on top of
https://github.com/llvm/llvm-project/pull/115237 and
https://github.com/llvm/llvm-project/pull/115235, only passing the
`Preprocessor` object to `ASTWriter`. This reduces the size of scanning
PCM files by 1/3 and speeds up scans by 16%.

Added: 


Modified: 
clang/include/clang/Lex/HeaderSearchOptions.h
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/GeneratePCH.cpp
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/HeaderSearchOptions.h 
b/clang/include/clang/Lex/HeaderSearchOptions.h
index c85e3d27281701..7a16926c186d2c 100644
--- a/clang/include/clang/Lex/HeaderSearchOptions.h
+++ b/clang/include/clang/Lex/HeaderSearchOptions.h
@@ -255,6 +255,10 @@ class HeaderSearchOptions {
   LLVM_PREFERRED_TYPE(bool)
   unsigned ModulesHashContent : 1;
 
+  /// Whether AST files should only contain the preprocessor information.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned ModulesSerializeOnlyPreprocessor : 1;
+
   /// Whether we should include all things that could impact the module in the
   /// hash.
   ///
@@ -288,6 +292,7 @@ class HeaderSearchOptions {
 ModulesSkipHeaderSearchPaths(false),
 ModulesSkipPragmaDiagnosticMappings(false),
 ModulesPruneNonAffectingModuleMaps(true), ModulesHashContent(false),
+ModulesSerializeOnlyPreprocessor(false),
 ModulesStrictContextHash(false), ModulesIncludeVFSUsage(false),
 AllowModuleMapSubdirectorySearch(true) {}
 

diff  --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index da35b32699811a..161b2ef7c86a49 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -929,9 +929,9 @@ class PCHGenerator : public SemaConsumer {
   void anchor() override;
 
   Preprocessor &PP;
+  llvm::PointerUnion Subject;
   std::string OutputFile;
   std::string isysroot;
-  Sema *SemaPtr;
   std::shared_ptr Buffer;
   llvm::BitstreamWriter Stream;
   ASTWriter Writer;
@@ -946,9 +946,7 @@ class PCHGenerator : public SemaConsumer {
   bool isComplete() const { return Buffer->IsComplete; }
   PCHBuffer *getBufferPtr() { return Buffer.get(); }
   StringRef getOutputFile() const { return OutputFile; }
-  DiagnosticsEngine &getDiagnostics() const {
-return SemaPtr->getDiagnostics();
-  }
+  DiagnosticsEngine &getDiagnostics() const;
   Preprocessor &getPreprocessor() { return PP; }
 
   virtual Module *getEmittingModule(ASTContext &Ctx);
@@ -964,7 +962,7 @@ class PCHGenerator : public SemaConsumer {
bool GeneratingReducedBMI = false);
   ~PCHGenerator() override;
 
-  void InitializeSema(Sema &S) override { SemaPtr = &S; }
+  void InitializeSema(Sema &S) override;
   void HandleTranslationUnit(ASTContext &Ctx) override;
   void HandleVTable(CXXRecordDecl *RD) override { Writer.handleVTable(RD); }
   ASTMutationListener *GetASTMutationListener() override;

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index e14061caccd63c..cf987df0e2154d 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -3522,6 +3522,9 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
 break;
   }
 
+  if (Record.empty())
+break;
+
   if (SpecialTypes.size() != Record.size())
 return llvm::createStringError(std::errc::illegal_byte_sequence,
"invalid special-types record");

diff  --git a/clang/lib/Serialization/GeneratePCH.cpp 
b/clang/lib/Serialization/GeneratePCH.cpp
index fdd240b03fd8df..7a8a951b34f251 100644
--- a/clang/lib/Serialization/GeneratePCH.cpp
+++ b/clang/lib/Serialization/GeneratePCH.cpp
@@ -29,8 +29,8 @@ PCHGenerator::PCHGenerator(
 bool AllowASTWithErrors, bool IncludeTimestamps,
 bool BuildingImplicitModule, bool ShouldCacheASTInMemory,
 bool GeneratingReducedBMI)
-: PP(PP), OutputFile(OutputFile), isysroot(isysroot.str()),
-  SemaPtr(nullptr), Buffer(std::move(Buffer)), Stream(this->Buffer->Data),
+: PP(PP), Subject(&PP), OutputFile(OutputFile), isysroot(isysroot.str()),
+  Buffer(std::move(Buffer)), Stream(this->Buffer->Data),
   Writer(Stream, this->Buffer->Data, ModuleCache, Extensions,
  IncludeTimestamps, BuildingImplicitModule, GeneratingReducedBMI),
   AllowASTWithErrors(AllowASTWithErrors),
@@ -56,6 

[clang] [NFC][Clang] Use range for loops in ClangDiagnosticsEmitter (PR #115573)

2024-11-11 Thread Rahul Joshi via cfe-commits

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


[clang] [NFC][Clang] Use range for loops in ClangDiagnosticsEmitter (PR #115573)

2024-11-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rahul Joshi (jurahul)


Changes

Use range based for loops in Clang diagnostics emitter.

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


1 Files Affected:

- (modified) clang/utils/TableGen/ClangDiagnosticsEmitter.cpp (+71-108) 


``diff
diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp 
b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index 34e2e8f47ae71a..889c8d5ac5fbcd 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -44,17 +44,12 @@ class DiagGroupParentMap {
 
 public:
   DiagGroupParentMap(const RecordKeeper &records) : Records(records) {
-ArrayRef DiagGroups =
-Records.getAllDerivedDefinitions("DiagGroup");
-for (unsigned i = 0, e = DiagGroups.size(); i != e; ++i) {
-  std::vector SubGroups =
-  DiagGroups[i]->getValueAsListOfDefs("SubGroups");
-  for (unsigned j = 0, e = SubGroups.size(); j != e; ++j)
-Mapping[SubGroups[j]].push_back(DiagGroups[i]);
-}
+for (const Record *Group : Records.getAllDerivedDefinitions("DiagGroup"))
+  for (const Record *SubGroup : Group->getValueAsListOfDefs("SubGroups"))
+Mapping[SubGroup].push_back(Group);
   }
 
-  const std::vector &getParents(const Record *Group) {
+  ArrayRef getParents(const Record *Group) {
 return Mapping[Group];
   }
 };
@@ -69,10 +64,8 @@ getCategoryFromDiagGroup(const Record *Group,
 
   // The diag group may the subgroup of one or more other diagnostic groups,
   // check these for a category as well.
-  const std::vector &Parents =
-  DiagGroupParents.getParents(Group);
-  for (unsigned i = 0, e = Parents.size(); i != e; ++i) {
-CatName = getCategoryFromDiagGroup(Parents[i], DiagGroupParents);
+  for (const Record *Parent : DiagGroupParents.getParents(Group)) {
+CatName = getCategoryFromDiagGroup(Parent, DiagGroupParents);
 if (!CatName.empty()) return CatName;
   }
   return "";
@@ -107,10 +100,9 @@ namespace {
   CategoryStrings.push_back("");
   CategoryIDs[""] = 0;
 
-  ArrayRef Diags =
-  Records.getAllDerivedDefinitions("Diagnostic");
-  for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
-std::string Category = getDiagnosticCategory(Diags[i], ParentInfo);
+  for (const Record *Diag :
+   Records.getAllDerivedDefinitions("Diagnostic")) {
+std::string Category = getDiagnosticCategory(Diag, ParentInfo);
 if (Category.empty()) continue;  // Skip diags with no category.
 
 unsigned &ID = CategoryIDs[Category];
@@ -158,9 +150,7 @@ static bool diagGroupBeforeByName(const Record *LHS, const 
Record *RHS) {
 static void groupDiagnostics(ArrayRef Diags,
  ArrayRef DiagGroups,
  std::map &DiagsInGroup) {
-
-  for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
-const Record *R = Diags[i];
+  for (const Record *R : Diags) {
 const auto *DI = dyn_cast(R->getValueInit("Group"));
 if (!DI)
   continue;
@@ -173,8 +163,7 @@ static void groupDiagnostics(ArrayRef Diags,
 
   // Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
   // groups (these are warnings that GCC supports that clang never produces).
-  for (unsigned i = 0, e = DiagGroups.size(); i != e; ++i) {
-const Record *Group = DiagGroups[i];
+  for (const Record *Group : DiagGroups) {
 GroupInfo &GI =
 DiagsInGroup[std::string(Group->getValueAsString("GroupName"))];
 GI.GroupName = Group->getName();
@@ -185,10 +174,8 @@ static void groupDiagnostics(ArrayRef 
Diags,
   }
 
   // Assign unique ID numbers to the groups.
-  unsigned IDNo = 0;
-  for (std::map::iterator
-   I = DiagsInGroup.begin(), E = DiagsInGroup.end(); I != E; ++I, ++IDNo)
-I->second.IDNo = IDNo;
+  for (auto [IdNo, Iter] : enumerate(DiagsInGroup))
+Iter.second.IDNo = IdNo;
 
   // Warn if the same group is defined more than once (including implicitly).
   for (auto &Group : DiagsInGroup) {
@@ -297,10 +284,8 @@ bool InferPedantic::isSubGroupOfGroup(const Record *Group, 
StringRef GName) {
   if (GName == GroupName)
 return true;
 
-  const std::vector &Parents =
-  DiagGroupParents.getParents(Group);
-  for (unsigned i = 0, e = Parents.size(); i != e; ++i)
-if (isSubGroupOfGroup(Parents[i], GName))
+  for (const Record *Parent : DiagGroupParents.getParents(Group))
+if (isSubGroupOfGroup(Parent, GName))
   return true;
 
   return false;
@@ -308,15 +293,12 @@ bool InferPedantic::isSubGroupOfGroup(const Record 
*Group, StringRef GName) {
 
 /// Determine if the diagnostic is an extension.
 bool InferPedantic::isExtension(const Record *Diag) {
-  const std::string &ClsName =
-  std::string(Diag->getValueAsDef("Class")->getName());
-  return ClsName == "CLASS_EXTENSION";
+  return Diag->getValueAsDef("Class")->getName() == "CLASS_EXTENSION";
 }
 
 bool InferPed

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

2024-11-11 Thread via cfe-commits


@@ -4008,6 +3996,38 @@ TemplateDeductionResult 
Sema::FinishTemplateArgumentDeduction(
 Owner = FunctionTemplate->getLexicalDeclContext();
   FunctionDecl *FD = FunctionTemplate->getTemplatedDecl();
 
+  // C++20 [temp.deduct.general]p5: (CWG2369)
+  // If the function template has associated constraints, those constraints are
+  // checked for satisfaction. If the constraints are not satisfied, type
+  // deduction fails.
+  // FIXME: We haven't implemented CWG2369 for lambdas yet, because we need
+  // to figure out how to instantiate lambda captures to the scope without
+  // first instantiating the lambda.
+  bool IsLambda = isLambdaCallOperator(FD) || isLambdaConversionOperator(FD);
+  if (!IsLambda && !IsIncomplete) {
+if (CheckFunctionTemplateConstraints(
+Info.getLocation(),
+FunctionTemplate->getCanonicalDecl()->getTemplatedDecl(),
+CanonicalBuilder, Info.AssociatedConstraintsSatisfaction))
+  return TemplateDeductionResult::MiscellaneousDeductionFailure;
+if (!Info.AssociatedConstraintsSatisfaction.IsSatisfied) {
+  Info.reset(Info.takeSugared(),
+ TemplateArgumentList::CreateCopy(Context, CanonicalBuilder));

cor3ntin wrote:

ping @mizvekov 

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


[clang] [clang][OpenMP][NFC] Move 'allocate' clause modifier parsing into fun… (PR #115775)

2024-11-11 Thread David Pagan via cfe-commits

https://github.com/ddpagan created 
https://github.com/llvm/llvm-project/pull/115775

…ction

Parsing of 'allocate' clause modifier ('allocator') has been moved into a 
separate function in anticipation of adding another modifier ('align').

>From 78e9809b743f74207dfab2e2271d91a04b2f75ca Mon Sep 17 00:00:00 2001
From: Dave Pagan 
Date: Mon, 11 Nov 2024 14:41:47 -0600
Subject: [PATCH] [clang][OpenMP][NFC] Move 'allocate' clause modifier parsing
 into function

Parsing of 'allocate' clause modifier ('allocator') has been moved into
a separate function in anticipation of adding another modifier ('align').
---
 clang/lib/Parse/ParseOpenMP.cpp | 48 +
 1 file changed, 31 insertions(+), 17 deletions(-)

diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 59a33eafa6be4f..c253133f611b0b 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4519,6 +4519,36 @@ static bool parseStepSize(Parser &P, 
SemaOpenMP::OpenMPVarListDataTy &Data,
   return false;
 }
 
+/// Parse 'allocate' clause modifiers.
+///   If allocator-modifier exists, return an expression for it and set
+///   Data field noting modifier was specified.
+///
+static ExprResult
+parseOpenMPAllocateClauseModifiers(Parser &P, OpenMPClauseKind Kind,
+   SemaOpenMP::OpenMPVarListDataTy &Data) {
+  const Token &Tok = P.getCurToken();
+  Preprocessor &PP = P.getPreprocessor();
+  ExprResult Tail;
+  auto Modifier = static_cast(
+  getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok), P.getLangOpts()));
+  if (Modifier == OMPC_ALLOCATE_allocator) {
+Data.AllocClauseModifier = Modifier;
+P.ConsumeToken();
+BalancedDelimiterTracker AllocateT(P, tok::l_paren,
+   tok::annot_pragma_openmp_end);
+if (Tok.is(tok::l_paren)) {
+  AllocateT.consumeOpen();
+  Tail = P.ParseAssignmentExpression();
+  AllocateT.consumeClose();
+} else {
+  P.Diag(Tok, diag::err_expected) << tok::l_paren;
+}
+  } else {
+Tail = P.ParseAssignmentExpression();
+  }
+  return Tail;
+}
+
 /// Parses clauses with list.
 bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
 OpenMPClauseKind Kind,
@@ -4800,23 +4830,7 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind 
DKind,
 // iterator(iterators-definition)
 ExprResult Tail;
 if (Kind == OMPC_allocate) {
-  auto Modifier = static_cast(
-  getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok), getLangOpts()));
-  if (Modifier == OMPC_ALLOCATE_allocator) {
-Data.AllocClauseModifier = Modifier;
-ConsumeToken();
-BalancedDelimiterTracker AllocateT(*this, tok::l_paren,
-   tok::annot_pragma_openmp_end);
-if (Tok.is(tok::l_paren)) {
-  AllocateT.consumeOpen();
-  Tail = ParseAssignmentExpression();
-  AllocateT.consumeClose();
-} else {
-  Diag(Tok, diag::err_expected) << tok::l_paren;
-}
-  } else {
-Tail = ParseAssignmentExpression();
-  }
+  Tail = parseOpenMPAllocateClauseModifiers(*this, Kind, Data);
 } else {
   HasIterator = true;
   EnterScope(Scope::OpenMPDirectiveScope | Scope::DeclScope);

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


[clang] [clang][OpenMP][NFC] Move 'allocate' clause modifier parsing into fun… (PR #115775)

2024-11-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: David Pagan (ddpagan)


Changes

…ction

Parsing of 'allocate' clause modifier ('allocator') has been moved into a 
separate function in anticipation of adding another modifier ('align').

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


1 Files Affected:

- (modified) clang/lib/Parse/ParseOpenMP.cpp (+31-17) 


``diff
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 59a33eafa6be4f..c253133f611b0b 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4519,6 +4519,36 @@ static bool parseStepSize(Parser &P, 
SemaOpenMP::OpenMPVarListDataTy &Data,
   return false;
 }
 
+/// Parse 'allocate' clause modifiers.
+///   If allocator-modifier exists, return an expression for it and set
+///   Data field noting modifier was specified.
+///
+static ExprResult
+parseOpenMPAllocateClauseModifiers(Parser &P, OpenMPClauseKind Kind,
+   SemaOpenMP::OpenMPVarListDataTy &Data) {
+  const Token &Tok = P.getCurToken();
+  Preprocessor &PP = P.getPreprocessor();
+  ExprResult Tail;
+  auto Modifier = static_cast(
+  getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok), P.getLangOpts()));
+  if (Modifier == OMPC_ALLOCATE_allocator) {
+Data.AllocClauseModifier = Modifier;
+P.ConsumeToken();
+BalancedDelimiterTracker AllocateT(P, tok::l_paren,
+   tok::annot_pragma_openmp_end);
+if (Tok.is(tok::l_paren)) {
+  AllocateT.consumeOpen();
+  Tail = P.ParseAssignmentExpression();
+  AllocateT.consumeClose();
+} else {
+  P.Diag(Tok, diag::err_expected) << tok::l_paren;
+}
+  } else {
+Tail = P.ParseAssignmentExpression();
+  }
+  return Tail;
+}
+
 /// Parses clauses with list.
 bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
 OpenMPClauseKind Kind,
@@ -4800,23 +4830,7 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind 
DKind,
 // iterator(iterators-definition)
 ExprResult Tail;
 if (Kind == OMPC_allocate) {
-  auto Modifier = static_cast(
-  getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok), getLangOpts()));
-  if (Modifier == OMPC_ALLOCATE_allocator) {
-Data.AllocClauseModifier = Modifier;
-ConsumeToken();
-BalancedDelimiterTracker AllocateT(*this, tok::l_paren,
-   tok::annot_pragma_openmp_end);
-if (Tok.is(tok::l_paren)) {
-  AllocateT.consumeOpen();
-  Tail = ParseAssignmentExpression();
-  AllocateT.consumeClose();
-} else {
-  Diag(Tok, diag::err_expected) << tok::l_paren;
-}
-  } else {
-Tail = ParseAssignmentExpression();
-  }
+  Tail = parseOpenMPAllocateClauseModifiers(*this, Kind, Data);
 } else {
   HasIterator = true;
   EnterScope(Scope::OpenMPDirectiveScope | Scope::DeclScope);

``




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


[clang] [Clang] Add `-fdefault-generic-addrspace` flag for targeting GPUs (PR #115777)

2024-11-11 Thread Joseph Huber via cfe-commits

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

Summary:
GPU targets support several different address spaces which have
differing semantics. When targeting C/C++ we have a very pessimistic
view that these address spaces are completely incompatible. This has a
lot of unfortable effects that limit using address spaces in C++ as well
as making it more difficult to work with. Flat addressing is supported
by the major GPU targets, so it's highly desierable to use.

The C/C++ standard says nothing about address spaces, so we cannot make
any assumptions. However, OpenCL has an option that causes all pointers
to be seen as 'generic'. This patch adds support for making every
address space as `__generic` by default, similar to the CL extensions.
This allows us to use this behavior outside of OpenCL mode. I have
re-used the language option as it seemed easier than creating a second
one.

This works in most cases, however it does cause some problems for cases
like this, as the default pointer type is now `__generic T` so it fails
to bind to `T`. But since this is an opt-in thing it seems fine to force
the user to add an extra template, or remove the qualifiers.
```c
template void foo(T *, T);
```


>From edae36c65c94b70215648c9e482690b945bcac13 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Mon, 11 Nov 2024 16:10:31 -0600
Subject: [PATCH] [Clang] Add `-fdefault-generic-addrspace` flag for targeting
 GPUs

Summary:
GPU targets support several different address spaces which have
differing semantics. When targeting C/C++ we have a very pessimistic
view that these address spaces are completely incompatible. This has a
lot of unfortable effects that limit using address spaces in C++ as well
as making it more difficult to work with. Flat addressing is supported
by the major GPU targets, so it's highly desierable to use.

The C/C++ standard says nothing about address spaces, so we cannot make
any assumptions. However, OpenCL has an option that causes all pointers
to be seen as 'generic'. This patch adds support for making every
address space as `__generic` by default, similar to the CL extensions.
This allows us to use this behavior outside of OpenCL mode. I have
re-used the language option as it seemed easier than creating a second
one.

This works in most cases, however it does cause some problems for cases
like this, as the default pointer type is now `__generic T` so it fails
to bind to `T`. But since this is an opt-in thing it seems fine to force
the user to add an extra template, or remove the qualifiers.
```c
template void foo(T *, T);
```
---
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/Driver/ToolChains/Clang.cpp |   3 +
 clang/lib/Frontend/CompilerInvocation.cpp |   4 +
 clang/lib/Sema/Sema.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/lib/Sema/SemaType.cpp   |  11 +-
 clang/test/CodeGen/generic-addrspace.cpp  | 219 ++
 7 files changed, 239 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/generic-addrspace.cpp

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1304ef3c5a228b..0d6f2c3410e9a0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3710,6 +3710,9 @@ def fopenmp_assume_no_nested_parallelism : Flag<["-"], 
"fopenmp-assume-no-nested
 } // let Visibility = [ClangOption, CC1Option, FC1Option]
 } // let Flags = [NoArgumentUnused, HelpHidden]
 
+def fdefault_generic_addrspace : Flag<["-"], "fdefault-generic-addrspace">, 
Group,
+  Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Allow pointers to be implicitly casted to other address spaces.">;
 def fopenmp_offload_mandatory : Flag<["-"], "fopenmp-offload-mandatory">, 
Group,
   Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>,
   HelpText<"Do not create a host fallback if offloading to the device fails.">,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0952262c360185..d997a1d232e83d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7067,6 +7067,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (Args.hasArg(options::OPT_nogpulib))
 CmdArgs.push_back("-nogpulib");
 
+  if (Args.hasArg(options::OPT_fdefault_generic_addrspace))
+CmdArgs.push_back("-fdefault-generic-addrspace");
+
   if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index b5fd35aaa1e841..b44f04d0f275e0 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3662,6 +3662,9 @@ void CompilerInvocationBase::GenerateLangArg

[clang] [Clang] Add `-fdefault-generic-addrspace` flag for targeting GPUs (PR #115777)

2024-11-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Joseph Huber (jhuber6)


Changes

Summary:
GPU targets support several different address spaces which have
differing semantics. When targeting C/C++ we have a very pessimistic
view that these address spaces are completely incompatible. This has a
lot of unfortable effects that limit using address spaces in C++ as well
as making it more difficult to work with. Flat addressing is supported
by the major GPU targets, so it's highly desierable to use.

The C/C++ standard says nothing about address spaces, so we cannot make
any assumptions. However, OpenCL has an option that causes all pointers
to be seen as 'generic'. This patch adds support for making every
address space as `__generic` by default, similar to the CL extensions.
This allows us to use this behavior outside of OpenCL mode. I have
re-used the language option as it seemed easier than creating a second
one.

This works in most cases, however it does cause some problems for cases
like this, as the default pointer type is now `__generic T` so it fails
to bind to `T`. But since this is an opt-in thing it seems fine to force
the user to add an extra template, or remove the qualifiers.
```c
template void foo(T *, T);
```


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


7 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+3) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+3) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+4) 
- (modified) clang/lib/Sema/Sema.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaType.cpp (+7-4) 
- (added) clang/test/CodeGen/generic-addrspace.cpp (+219) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1304ef3c5a228b..0d6f2c3410e9a0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3710,6 +3710,9 @@ def fopenmp_assume_no_nested_parallelism : Flag<["-"], 
"fopenmp-assume-no-nested
 } // let Visibility = [ClangOption, CC1Option, FC1Option]
 } // let Flags = [NoArgumentUnused, HelpHidden]
 
+def fdefault_generic_addrspace : Flag<["-"], "fdefault-generic-addrspace">, 
Group,
+  Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Allow pointers to be implicitly casted to other address spaces.">;
 def fopenmp_offload_mandatory : Flag<["-"], "fopenmp-offload-mandatory">, 
Group,
   Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>,
   HelpText<"Do not create a host fallback if offloading to the device fails.">,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0952262c360185..d997a1d232e83d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7067,6 +7067,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (Args.hasArg(options::OPT_nogpulib))
 CmdArgs.push_back("-nogpulib");
 
+  if (Args.hasArg(options::OPT_fdefault_generic_addrspace))
+CmdArgs.push_back("-fdefault-generic-addrspace");
+
   if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index b5fd35aaa1e841..b44f04d0f275e0 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3662,6 +3662,9 @@ void CompilerInvocationBase::GenerateLangArgs(const 
LangOptions &Opts,
   if (Opts.Blocks && !(Opts.OpenCL && Opts.OpenCLVersion == 200))
 GenerateArg(Consumer, OPT_fblocks);
 
+  if (Opts.OpenCLGenericAddressSpace)
+GenerateArg(Consumer, OPT_fdefault_generic_addrspace);
+
   if (Opts.ConvergentFunctions)
 GenerateArg(Consumer, OPT_fconvergent_functions);
   else
@@ -3939,6 +3942,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, 
ArgList &Args,
   // These need to be parsed now. They are used to set OpenCL defaults.
   Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);
   Opts.DeclareOpenCLBuiltins = Args.hasArg(OPT_fdeclare_opencl_builtins);
+  Opts.OpenCLGenericAddressSpace = Args.hasArg(OPT_fdefault_generic_addrspace);
 
   LangOptions::setLangDefaults(Opts, IK.getLanguage(), T, Includes, LangStd);
 
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 2b51765e80864a..2920220948d145 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1579,7 +1579,7 @@ NamedDecl *Sema::getCurFunctionOrMethodDecl() const {
 }
 
 LangAS Sema::getDefaultCXXMethodAddrSpace() const {
-  if (getLangOpts().OpenCL)
+  if (getLangOpts().OpenCL || getLangOpts().OpenCLGenericAddressSpace)
 return getASTContext().getDefaultOpenCLPointeeAddrSpace();
   return LangAS::Default;
 }
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clan

[clang] [Clang] Add `-fdefault-generic-addrspace` flag for targeting GPUs (PR #115777)

2024-11-11 Thread Joseph Huber via cfe-commits

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

>From 34eb41f58518c79c627b5c1cc522c4e142c2d420 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Mon, 11 Nov 2024 16:10:31 -0600
Subject: [PATCH] [Clang] Add `-fdefault-generic-addrspace` flag for targeting
 GPUs

Summary:
GPU targets support several different address spaces which have
differing semantics. When targeting C/C++ we have a very pessimistic
view that these address spaces are completely incompatible. This has a
lot of unfortable effects that limit using address spaces in C++ as well
as making it more difficult to work with. Flat addressing is supported
by the major GPU targets, so it's highly desierable to use.

The C/C++ standard says nothing about address spaces, so we cannot make
any assumptions. However, OpenCL has an option that causes all pointers
to be seen as 'generic'. This patch adds support for making every
address space as `__generic` by default, similar to the CL extensions.
This allows us to use this behavior outside of OpenCL mode. I have
re-used the language option as it seemed easier than creating a second
one.

This works in most cases, however it does cause some problems for cases
like this, as the default pointer type is now `__generic T` so it fails
to bind to `T`. But since this is an opt-in thing it seems fine to force
the user to add an extra template, or remove the qualifiers.
```c
template void foo(T *, T);
```
---
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/Driver/ToolChains/Clang.cpp |   3 +
 clang/lib/Frontend/CompilerInvocation.cpp |   4 +
 clang/lib/Sema/Sema.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/lib/Sema/SemaType.cpp   |  11 +-
 clang/test/CodeGen/generic-addrspace.cpp  | 180 ++
 7 files changed, 200 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/generic-addrspace.cpp

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1304ef3c5a228b..0d6f2c3410e9a0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3710,6 +3710,9 @@ def fopenmp_assume_no_nested_parallelism : Flag<["-"], 
"fopenmp-assume-no-nested
 } // let Visibility = [ClangOption, CC1Option, FC1Option]
 } // let Flags = [NoArgumentUnused, HelpHidden]
 
+def fdefault_generic_addrspace : Flag<["-"], "fdefault-generic-addrspace">, 
Group,
+  Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Allow pointers to be implicitly casted to other address spaces.">;
 def fopenmp_offload_mandatory : Flag<["-"], "fopenmp-offload-mandatory">, 
Group,
   Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>,
   HelpText<"Do not create a host fallback if offloading to the device fails.">,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0952262c360185..d997a1d232e83d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7067,6 +7067,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (Args.hasArg(options::OPT_nogpulib))
 CmdArgs.push_back("-nogpulib");
 
+  if (Args.hasArg(options::OPT_fdefault_generic_addrspace))
+CmdArgs.push_back("-fdefault-generic-addrspace");
+
   if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index b5fd35aaa1e841..b44f04d0f275e0 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3662,6 +3662,9 @@ void CompilerInvocationBase::GenerateLangArgs(const 
LangOptions &Opts,
   if (Opts.Blocks && !(Opts.OpenCL && Opts.OpenCLVersion == 200))
 GenerateArg(Consumer, OPT_fblocks);
 
+  if (Opts.OpenCLGenericAddressSpace)
+GenerateArg(Consumer, OPT_fdefault_generic_addrspace);
+
   if (Opts.ConvergentFunctions)
 GenerateArg(Consumer, OPT_fconvergent_functions);
   else
@@ -3939,6 +3942,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, 
ArgList &Args,
   // These need to be parsed now. They are used to set OpenCL defaults.
   Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);
   Opts.DeclareOpenCLBuiltins = Args.hasArg(OPT_fdeclare_opencl_builtins);
+  Opts.OpenCLGenericAddressSpace = Args.hasArg(OPT_fdefault_generic_addrspace);
 
   LangOptions::setLangDefaults(Opts, IK.getLanguage(), T, Includes, LangStd);
 
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 2b51765e80864a..2920220948d145 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1579,7 +1579,7 @@ NamedDecl *Sema::getCurFunctionOrMethodDecl() const {
 }
 
 LangAS Sema::getDefaultCXXMethodAddrSpace() const {
-  if (getLangOpts().OpenCL)
+  if (getLan

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

2024-11-11 Thread Matheus Izvekov via cfe-commits


@@ -4008,6 +3996,38 @@ TemplateDeductionResult 
Sema::FinishTemplateArgumentDeduction(
 Owner = FunctionTemplate->getLexicalDeclContext();
   FunctionDecl *FD = FunctionTemplate->getTemplatedDecl();
 
+  // C++20 [temp.deduct.general]p5: (CWG2369)
+  // If the function template has associated constraints, those constraints are
+  // checked for satisfaction. If the constraints are not satisfied, type
+  // deduction fails.
+  // FIXME: We haven't implemented CWG2369 for lambdas yet, because we need
+  // to figure out how to instantiate lambda captures to the scope without
+  // first instantiating the lambda.
+  bool IsLambda = isLambdaCallOperator(FD) || isLambdaConversionOperator(FD);
+  if (!IsLambda && !IsIncomplete) {
+if (CheckFunctionTemplateConstraints(
+Info.getLocation(),
+FunctionTemplate->getCanonicalDecl()->getTemplatedDecl(),
+CanonicalBuilder, Info.AssociatedConstraintsSatisfaction))
+  return TemplateDeductionResult::MiscellaneousDeductionFailure;
+if (!Info.AssociatedConstraintsSatisfaction.IsSatisfied) {
+  Info.reset(Info.takeSugared(),
+ TemplateArgumentList::CreateCopy(Context, CanonicalBuilder));

mizvekov wrote:

Yeah, what @zyn0217 said is correct, the canonical argument list will have 
references persist in AST nodes, so it needs to be copied here.

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


[clang-tools-extra] Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (PR #114255)

2024-11-11 Thread via cfe-commits

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

>From 2835f0eae90061d390d1b011b6a98bf43be1a0c6 Mon Sep 17 00:00:00 2001
From: higher-performance 
Date: Wed, 30 Oct 2024 12:01:00 -0400
Subject: [PATCH] Extend bugprone-use-after-move check to handle
 std::optional::reset() and std::any::reset() similarly to smart pointers

---
 .../clang-tidy/bugprone/UseAfterMoveCheck.cpp |  9 +++--
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 +++
 .../checks/bugprone/use-after-move.rst| 15 +---
 .../checkers/bugprone/use-after-move.cpp  | 37 ++-
 4 files changed, 54 insertions(+), 12 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
index 8f4b5e8092ddaa..960133159dbbf5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -315,9 +315,10 @@ void UseAfterMoveFinder::getReinits(
   "::std::unordered_map", "::std::unordered_multiset",
   "::std::unordered_multimap"));
 
-  auto StandardSmartPointerTypeMatcher = hasType(hasUnqualifiedDesugaredType(
-  recordType(hasDeclaration(cxxRecordDecl(hasAnyName(
-  "::std::unique_ptr", "::std::shared_ptr", "::std::weak_ptr"));
+  auto StandardResettableOwnerTypeMatcher = hasType(
+  hasUnqualifiedDesugaredType(recordType(hasDeclaration(cxxRecordDecl(
+  hasAnyName("::std::unique_ptr", "::std::shared_ptr",
+ "::std::weak_ptr", "::std::optional", "::std::any"));
 
   // Matches different types of reinitialization.
   auto ReinitMatcher =
@@ -340,7 +341,7 @@ void UseAfterMoveFinder::getReinits(
callee(cxxMethodDecl(hasAnyName("clear", "assign",
// reset() on standard smart pointers.
cxxMemberCallExpr(
-   on(expr(DeclRefMatcher, StandardSmartPointerTypeMatcher)),
+   on(expr(DeclRefMatcher, 
StandardResettableOwnerTypeMatcher)),
callee(cxxMethodDecl(hasName("reset",
// Methods that have the [[clang::reinitializes]] attribute.
cxxMemberCallExpr(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 442fb7180555ea..ace1c037aba0c4 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -190,6 +190,11 @@ Changes in existing checks
   ` check to allow specifying
   additional functions to match.
 
+- Improved :doc:`bugprone-use-after-move
+  ` to avoid triggering on
+  ``reset()`` calls on moved-from ``std::optional`` and ``std::any`` objects,
+  similarly to smart pointers.
+
 - Improved :doc:`cert-flp30-c ` check to
   fix false positive that floating point variable is only used in increment
   expression.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/use-after-move.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/use-after-move.rst
index 08bb5374bab1f4..965fc2d3c29e24 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/use-after-move.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/use-after-move.rst
@@ -196,11 +196,13 @@ Any occurrence of the moved variable that is not a 
reinitialization (see below)
 is considered to be a use.
 
 An exception to this are objects of type ``std::unique_ptr``,
-``std::shared_ptr`` and ``std::weak_ptr``, which have defined move behavior
-(objects of these classes are guaranteed to be empty after they have been moved
-from). Therefore, an object of these classes will only be considered to be used
-if it is dereferenced, i.e. if ``operator*``, ``operator->`` or ``operator[]``
-(in the case of ``std::unique_ptr``) is called on it.
+``std::shared_ptr``, ``std::weak_ptr``, ``std::optional``, and ``std::any``.
+An exception to this are objects of type ``std::unique_ptr``,
+``std::shared_ptr``, ``std::weak_ptr``, ``std::optional``, and ``std::any``, 
which
+can be reinitialized via ``reset``. For smart pointers specifically, the
+moved-from objects have a well-defined state of being ``nullptr``s, and only
+``operator*``, ``operator->`` and ``operator[]`` are considered bad accesses as
+they would be dereferencing a ``nullptr``.
 
 If multiple uses occur after a move, only the first of these is flagged.
 
@@ -222,7 +224,8 @@ The check considers a variable to be reinitialized in the 
following cases:
 ``unordered_multimap``.
 
   - ``reset()`` is called on the variable and the variable is of type
-``std::unique_ptr``, ``std::shared_ptr`` or ``std::weak_ptr``.
+``std::unique_ptr``, ``std::shared_ptr``, ``std::weak_ptr``,
+``std::optional``, or ``std::any``.
 
   - A member function marked with the ``[[clang::reinitializes]]`` attribute is
 called on the variable.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/

[clang] [NFC][Clang] Use range for loops in ClangDiagnosticsEmitter (PR #115573)

2024-11-11 Thread Kazu Hirata via cfe-commits


@@ -185,10 +174,8 @@ static void groupDiagnostics(ArrayRef 
Diags,
   }
 
   // Assign unique ID numbers to the groups.
-  unsigned IDNo = 0;
-  for (std::map::iterator
-   I = DiagsInGroup.begin(), E = DiagsInGroup.end(); I != E; ++I, ++IDNo)
-I->second.IDNo = IDNo;
+  for (auto [IdNo, Iter] : enumerate(DiagsInGroup))
+Iter.second.IDNo = IdNo;

kazutakahirata wrote:

If you are taking each element by value (as as opposed to reference), does 
`Iter.second.IDNo = Idno;` actually update the original?  Or does it just 
update the copy?

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


[clang] [Clang] Add `-fdefault-generic-addrspace` flag for targeting GPUs (PR #115777)

2024-11-11 Thread Matt Arsenault via cfe-commits


@@ -1579,7 +1579,7 @@ NamedDecl *Sema::getCurFunctionOrMethodDecl() const {
 }
 
 LangAS Sema::getDefaultCXXMethodAddrSpace() const {
-  if (getLangOpts().OpenCL)
+  if (getLangOpts().OpenCL || getLangOpts().OpenCLGenericAddressSpace)

arsenm wrote:

I think this whole thing is just working around a defect in how OpenCL was 
implemented. There should be no difference between generic and default address 
space 

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


[clang] [Clang] Add `-fdefault-generic-addrspace` flag for targeting GPUs (PR #115777)

2024-11-11 Thread Joseph Huber via cfe-commits


@@ -1579,7 +1579,7 @@ NamedDecl *Sema::getCurFunctionOrMethodDecl() const {
 }
 
 LangAS Sema::getDefaultCXXMethodAddrSpace() const {
-  if (getLangOpts().OpenCL)
+  if (getLangOpts().OpenCL || getLangOpts().OpenCLGenericAddressSpace)

jhuber6 wrote:

I think it's because the DefaultAS applies to every single language and it 
wasn't deemed proper to modify C/C++ behavior? I'm not an expert, maybe if 
@AnastasiaStulova chimes in. Regardless, I'm mostly just working with the 
smallest number of changes with what we've got that gives me the desired result.

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


[clang] [llvm] [HLSL][SPIRV][DXIL] Implement `WaveActiveSum` intrinsic (PR #112400)

2024-11-11 Thread Justin Bogner via cfe-commits


@@ -1824,6 +1824,23 @@ static bool CheckAnyScalarOrVector(Sema *S, CallExpr 
*TheCall,
   return false;
 }
 
+static bool CheckNotScalarType(Sema *S, CallExpr *TheCall, QualType Scalar,
+   unsigned ArgIndex) {
+  assert(TheCall->getNumArgs() >= ArgIndex);
+  QualType ArgType = TheCall->getArg(ArgIndex)->getType();
+  auto *VTy = ArgType->getAs();
+  // is the scalar or vector
+  if (S->Context.hasSameUnqualifiedType(ArgType, Scalar) ||
+  (VTy &&
+   S->Context.hasSameUnqualifiedType(VTy->getElementType(), Scalar))) {
+S->Diag(TheCall->getArg(0)->getBeginLoc(),
+diag::err_typecheck_expect_scalar_or_vector_not_type)
+<< ArgType << Scalar;
+return true;
+  }
+  return false;
+}

bogner wrote:

This function seems like it's being made generic in a way that isn't 
particularly useful. Do we have cases where we reject a single specific scalar 
type, and that that type is something other than bool?

Also, I find the error message kind of confusing:
```
invalid operand of type 'bool' where 'bool' or a vector of such type is not 
allowed
```
This is redundant, isn't it? What information is this providing that "invalid 
operand of type 'bool'" wouldn't?

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


[clang] [llvm] [HLSL][SPIRV][DXIL] Implement `WaveActiveSum` intrinsic (PR #112400)

2024-11-11 Thread Justin Bogner via cfe-commits


@@ -2217,6 +2217,105 @@ __attribute__((convergent)) double3 
WaveReadLaneAt(double3, int32_t);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_read_lane_at)
 __attribute__((convergent)) double4 WaveReadLaneAt(double4, int32_t);
 
+//===--===//
+// WaveActiveSum builtins
+//===--===//
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
+__attribute((convergent)) half WaveActiveSum(half);

bogner wrote:

Please use the `__attribute__((convergent))` spelling to be consistent with the 
rest of the file.

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


[clang] [Clang] Add `-fdefault-generic-addrspace` flag for targeting GPUs (PR #115777)

2024-11-11 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

https://godbolt.org/z/qWGaejTx9 for this case, I'm wondering if there's a way 
to resolve this by considering the AS as part of the pointer, since I don't 
know if AS means anything on a non-pointer type.

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


[clang] [clang][Fuchsia] Have global dtors use llvm.global_dtors over atexit (PR #115788)

2024-11-11 Thread via cfe-commits

https://github.com/PiJoules created 
https://github.com/llvm/llvm-project/pull/115788

None

>From 809856e87ba89165061cdd42904d99439793f322 Mon Sep 17 00:00:00 2001
From: Leonard Chan 
Date: Mon, 11 Nov 2024 15:40:47 -0800
Subject: [PATCH] [clang][Fuchsia] Have global dtors use llvm.global_dtors over
 atexit

---
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  8 ++
 clang/test/CodeGenCXX/fuchsia-global-dtor.cpp | 25 +++
 2 files changed, 33 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/fuchsia-global-dtor.cpp

diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 9b3c2f1b2af677..7dda27e02e9ea1 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -518,6 +518,14 @@ class FuchsiaCXXABI final : public ItaniumCXXABI {
   explicit FuchsiaCXXABI(CodeGen::CodeGenModule &CGM)
   : ItaniumCXXABI(CGM) {}
 
+  // Rather than using the defaul [__cxa_]atexit, instead use llvm.global_dtors
+  // which will result in .fini_array being used.
+  void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
+  llvm::FunctionCallee dtor,
+  llvm::Constant *addr) override {
+return CGM.AddCXXDtorEntry(dtor, addr);
+  }
+
 private:
   bool constructorsAndDestructorsReturnThis() const override { return true; }
 };
diff --git a/clang/test/CodeGenCXX/fuchsia-global-dtor.cpp 
b/clang/test/CodeGenCXX/fuchsia-global-dtor.cpp
new file mode 100644
index 00..ff3066059af91d
--- /dev/null
+++ b/clang/test/CodeGenCXX/fuchsia-global-dtor.cpp
@@ -0,0 +1,25 @@
+/// Global destructors targetting Fuchsia should not use [__cxa_]atexit. 
Instead
+/// they should be invoked through llvm.global_dtors.
+
+// RUN: %clang_cc1 %s -triple aarch64-unknown-fuchsia -emit-llvm -o - | 
FileCheck %s
+
+// CHECK-NOT: atexit
+
+// CHECK:  @llvm.global_dtors = appending global [1 x { i32, ptr, ptr }]
+// CHECK-SAME:   [{ i32, ptr, ptr } { i32 {{.*}}, ptr [[MODULE_DTOR:@.*]], ptr 
{{.*}} }]
+
+// CHECK:  define internal void [[MODULE_DTOR]]() {{.*}}{
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %0 = call ptr @_ZN1AD1Ev(ptr @DestroyFirst)
+// CHECK-NEXT:   %1 = call ptr @_ZN1AD1Ev(ptr @DestroySecond)
+// CHECK-NEXT:   %2 = call ptr @_ZN1AD1Ev(ptr @DestroyThird)
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+
+struct A {
+  ~A() {}
+};
+
+A DestroyThird;
+A DestroySecond;
+A DestroyFirst;

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


[clang] [clang][Fuchsia] Have global dtors use llvm.global_dtors over atexit (PR #115788)

2024-11-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (PiJoules)


Changes



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


2 Files Affected:

- (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+8) 
- (added) clang/test/CodeGenCXX/fuchsia-global-dtor.cpp (+25) 


``diff
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 9b3c2f1b2af677..7dda27e02e9ea1 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -518,6 +518,14 @@ class FuchsiaCXXABI final : public ItaniumCXXABI {
   explicit FuchsiaCXXABI(CodeGen::CodeGenModule &CGM)
   : ItaniumCXXABI(CGM) {}
 
+  // Rather than using the defaul [__cxa_]atexit, instead use llvm.global_dtors
+  // which will result in .fini_array being used.
+  void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
+  llvm::FunctionCallee dtor,
+  llvm::Constant *addr) override {
+return CGM.AddCXXDtorEntry(dtor, addr);
+  }
+
 private:
   bool constructorsAndDestructorsReturnThis() const override { return true; }
 };
diff --git a/clang/test/CodeGenCXX/fuchsia-global-dtor.cpp 
b/clang/test/CodeGenCXX/fuchsia-global-dtor.cpp
new file mode 100644
index 00..ff3066059af91d
--- /dev/null
+++ b/clang/test/CodeGenCXX/fuchsia-global-dtor.cpp
@@ -0,0 +1,25 @@
+/// Global destructors targetting Fuchsia should not use [__cxa_]atexit. 
Instead
+/// they should be invoked through llvm.global_dtors.
+
+// RUN: %clang_cc1 %s -triple aarch64-unknown-fuchsia -emit-llvm -o - | 
FileCheck %s
+
+// CHECK-NOT: atexit
+
+// CHECK:  @llvm.global_dtors = appending global [1 x { i32, ptr, ptr }]
+// CHECK-SAME:   [{ i32, ptr, ptr } { i32 {{.*}}, ptr [[MODULE_DTOR:@.*]], ptr 
{{.*}} }]
+
+// CHECK:  define internal void [[MODULE_DTOR]]() {{.*}}{
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %0 = call ptr @_ZN1AD1Ev(ptr @DestroyFirst)
+// CHECK-NEXT:   %1 = call ptr @_ZN1AD1Ev(ptr @DestroySecond)
+// CHECK-NEXT:   %2 = call ptr @_ZN1AD1Ev(ptr @DestroyThird)
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+
+struct A {
+  ~A() {}
+};
+
+A DestroyThird;
+A DestroySecond;
+A DestroyFirst;

``




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


[clang] [Clang] Add `-fdefault-generic-addrspace` flag for targeting GPUs (PR #115777)

2024-11-11 Thread Artem Belevich via cfe-commits

Artem-B wrote:

> This has a lot of unfortable effects that limit using address spaces in C++ 
> as well
> as making it more difficult to work with.

Can you give some examples? 

It sounds that what you really want is for address space qualifiers to not be 
part of a type signature. OpenCL sort of happens to avoid that by sticking 
`__generic` AS qualifier on all pointers without one, and thus make plain 
pointers *become* `__generic` ones, which gets some C++ code happy, but that 
does look like a quirk of OpenCL. Normally, we a) do not have an explicit 
generic AS (or it would be indistinguishable from a plain pointer as it is on 
LLVM level w/ AS(0)), and b) when we specialize a function with an AS-specific 
pointer type, we generally do want it to be that type.

Clang and C++ indeed still have issues with AS-qualified pointers.
E.g. attempts to define function overloads with `AS(0)` and plain pointers 
result in an error about conflicting name mangling: 
https://godbolt.org/z/fW3dP4an5

Yet C++ does not consider the types equivalent, so you can't pass plain pointer 
as AS(0)-qualified argument and vice versa: https://godbolt.org/z/K4PEv9e7j 

It's a bug that needs fixing, IMO. We either treat unqualified ans AS(0) 
pointer types as different, and give them different mangling. Or we should 
treat AS(0) and plain pointer types the same, diagnose AS0/plain overloads as 
redefinitions (no need to wait til we run into mangling conflict) and allow 
using them interchangeably.

Would straightening this out help with the issue you're trying to solve?

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-11 Thread Justin Stitt via cfe-commits


@@ -6664,6 +6664,13 @@ def err_builtin_counted_by_ref_invalid_lhs_use : Error<
 def err_builtin_counted_by_ref_has_side_effects : Error<
   "'__builtin_counted_by_ref' argument cannot have side-effects">;
 
+def warn_wraps_attr_var_decl_type_not_integer : Warning<
+  "using attribute '%select{wraps|no_wraps}0' with non-integer type '%1' has 
no function and is potentially misleading">,
+  InGroup;

JustinStitt wrote:

how about dropping "has no function and" so the final sentence becomes 
something like:

`"using attribute 'wraps' with non-integer type '%1' is potentially misleading"`
 

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


[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-11 Thread Matt Arsenault via cfe-commits


@@ -5133,6 +5133,132 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Builder.SetInsertPoint(ContBB);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__scoped_atomic_thread_fence: {
+auto ScopeModel = AtomicScopeModel::create(AtomicScopeModelKind::Generic);
+
+Value *Order = EmitScalarExpr(E->getArg(0));
+Value *Scope = EmitScalarExpr(E->getArg(1));
+if (isa(Order) && isa(Scope)) {
+  int Ord = cast(Order)->getZExtValue();
+  int Scp = cast(Scope)->getZExtValue();

arsenm wrote:

dyn_cast instead of isa + cast 

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


[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-11 Thread Matt Arsenault via cfe-commits


@@ -5133,6 +5133,132 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Builder.SetInsertPoint(ContBB);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__scoped_atomic_thread_fence: {
+auto ScopeModel = AtomicScopeModel::create(AtomicScopeModelKind::Generic);
+
+Value *Order = EmitScalarExpr(E->getArg(0));
+Value *Scope = EmitScalarExpr(E->getArg(1));
+if (isa(Order) && isa(Scope)) {
+  int Ord = cast(Order)->getZExtValue();
+  int Scp = cast(Scope)->getZExtValue();
+  SyncScope SS = ScopeModel->isValid(Scp)
+ ? ScopeModel->map(Scp)
+ : ScopeModel->map(ScopeModel->getFallBackValue());
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+break;
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+Builder.CreateFence(
+llvm::AtomicOrdering::Acquire,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Acquire,
+getLLVMContext()));
+break;
+  case 3: // memory_order_release
+Builder.CreateFence(
+llvm::AtomicOrdering::Release,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Release,
+getLLVMContext()));
+break;
+  case 4: // memory_order_acq_rel
+Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::AcquireRelease,
+getLLVMContext()));
+break;
+  case 5: // memory_order_seq_cst
+Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::SequentiallyConsistent,
+getLLVMContext()));
+break;
+  }
+  return RValue::get(nullptr);
+}
+
+llvm::BasicBlock *ContBB = createBasicBlock("atomic.scope.continue", 
CurFn);
+
+llvm::DenseMap OrderBBs;

arsenm wrote:

I don't see why this needs to be a map 

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


[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-11 Thread Joseph Huber via cfe-commits

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

>From 9b8cb87e0e12899df3a5af7f312f637a6c242921 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Fri, 8 Nov 2024 15:42:04 -0600
Subject: [PATCH 1/4] [Clang] Add support for scoped atomic thread fence

Summary:
Previously we added support for all of the atomic GNU extensions with
optional memory scoped except for `__atomic_thread_fence`. This patch
adds support for that. This should ideally allow us to generically emit
these LLVM scopes.
---
 clang/include/clang/Basic/Builtins.td |   6 +
 clang/lib/CodeGen/CGBuiltin.cpp   | 129 +++
 clang/test/CodeGen/scoped-fence-ops.c | 179 ++
 3 files changed, 314 insertions(+)
 create mode 100644 clang/test/CodeGen/scoped-fence-ops.c

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 4360e0bf9840f13..82ba26085e9267f 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1995,6 +1995,12 @@ def AtomicThreadFence : Builtin {
   let Prototype = "void(int)";
 }
 
+def ScopedAtomicThreadFence : Builtin {
+  let Spellings = ["__scoped_atomic_thread_fence"];
+  let Attributes = [NoThrow];
+  let Prototype = "void(int, int)";
+}
+
 def AtomicSignalFence : Builtin {
   let Spellings = ["__atomic_signal_fence"];
   let Attributes = [NoThrow];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 430ac5626f89d7f..c8f90df2546f256 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5162,6 +5162,135 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Builder.SetInsertPoint(ContBB);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__scoped_atomic_thread_fence: {
+auto ScopeModel = AtomicScopeModel::create(AtomicScopeModelKind::Generic);
+
+Value *Order = EmitScalarExpr(E->getArg(0));
+Value *Scope = EmitScalarExpr(E->getArg(1));
+if (isa(Order) && isa(Scope)) {
+  int Ord = cast(Order)->getZExtValue();
+  int Scp = cast(Scope)->getZExtValue();
+  SyncScope SS = ScopeModel->isValid(Scp)
+ ? ScopeModel->map(Scp)
+ : ScopeModel->map(ScopeModel->getFallBackValue());
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+break;
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+Builder.CreateFence(
+llvm::AtomicOrdering::Acquire,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Acquire,
+getLLVMContext()));
+break;
+  case 3: // memory_order_release
+Builder.CreateFence(
+llvm::AtomicOrdering::Release,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Release,
+getLLVMContext()));
+break;
+  case 4: // memory_order_acq_rel
+Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::AcquireRelease,
+getLLVMContext()));
+break;
+  case 5: // memory_order_seq_cst
+Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::SequentiallyConsistent,
+getLLVMContext()));
+break;
+  }
+  return RValue::get(nullptr);
+}
+
+llvm::BasicBlock *ContBB = createBasicBlock("atomic.scope.continue", 
CurFn);
+
+llvm::DenseMap OrderBBs;
+if (isa(Order)) {
+  int Ord = cast(Order)->getZExtValue();
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+ContBB->eraseFromParent();
+return RValue::get(nullptr);
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+OrderBBs[Builder.GetInsertBlock()] = llvm::AtomicOrdering::Acquire;
+break;
+  case 3: // memory_order_release
+OrderBBs[Builder.GetInsertBlock()] = llvm::AtomicOrdering::Release;
+break;
+  case 4: // memory_order_acq_rel
+OrderBBs[Builder.GetInsertBlock()] =
+llvm::AtomicOrdering::AcquireRelease;
+break;
+  case 5: // memory_order_seq_cst
+OrderBBs[Builder.GetInsertBlock()] =
+llvm::AtomicOrdering::SequentiallyConsistent;
+break;
+  }
+} else {
+  llvm::BasicBlock *AcquireBB, *Re

[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-11 Thread Joseph Huber via cfe-commits

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

>From 9b8cb87e0e12899df3a5af7f312f637a6c242921 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Fri, 8 Nov 2024 15:42:04 -0600
Subject: [PATCH 1/4] [Clang] Add support for scoped atomic thread fence

Summary:
Previously we added support for all of the atomic GNU extensions with
optional memory scoped except for `__atomic_thread_fence`. This patch
adds support for that. This should ideally allow us to generically emit
these LLVM scopes.
---
 clang/include/clang/Basic/Builtins.td |   6 +
 clang/lib/CodeGen/CGBuiltin.cpp   | 129 +++
 clang/test/CodeGen/scoped-fence-ops.c | 179 ++
 3 files changed, 314 insertions(+)
 create mode 100644 clang/test/CodeGen/scoped-fence-ops.c

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 4360e0bf9840f13..82ba26085e9267f 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1995,6 +1995,12 @@ def AtomicThreadFence : Builtin {
   let Prototype = "void(int)";
 }
 
+def ScopedAtomicThreadFence : Builtin {
+  let Spellings = ["__scoped_atomic_thread_fence"];
+  let Attributes = [NoThrow];
+  let Prototype = "void(int, int)";
+}
+
 def AtomicSignalFence : Builtin {
   let Spellings = ["__atomic_signal_fence"];
   let Attributes = [NoThrow];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 430ac5626f89d7f..c8f90df2546f256 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5162,6 +5162,135 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Builder.SetInsertPoint(ContBB);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__scoped_atomic_thread_fence: {
+auto ScopeModel = AtomicScopeModel::create(AtomicScopeModelKind::Generic);
+
+Value *Order = EmitScalarExpr(E->getArg(0));
+Value *Scope = EmitScalarExpr(E->getArg(1));
+if (isa(Order) && isa(Scope)) {
+  int Ord = cast(Order)->getZExtValue();
+  int Scp = cast(Scope)->getZExtValue();
+  SyncScope SS = ScopeModel->isValid(Scp)
+ ? ScopeModel->map(Scp)
+ : ScopeModel->map(ScopeModel->getFallBackValue());
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+break;
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+Builder.CreateFence(
+llvm::AtomicOrdering::Acquire,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Acquire,
+getLLVMContext()));
+break;
+  case 3: // memory_order_release
+Builder.CreateFence(
+llvm::AtomicOrdering::Release,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Release,
+getLLVMContext()));
+break;
+  case 4: // memory_order_acq_rel
+Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::AcquireRelease,
+getLLVMContext()));
+break;
+  case 5: // memory_order_seq_cst
+Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::SequentiallyConsistent,
+getLLVMContext()));
+break;
+  }
+  return RValue::get(nullptr);
+}
+
+llvm::BasicBlock *ContBB = createBasicBlock("atomic.scope.continue", 
CurFn);
+
+llvm::DenseMap OrderBBs;
+if (isa(Order)) {
+  int Ord = cast(Order)->getZExtValue();
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+ContBB->eraseFromParent();
+return RValue::get(nullptr);
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+OrderBBs[Builder.GetInsertBlock()] = llvm::AtomicOrdering::Acquire;
+break;
+  case 3: // memory_order_release
+OrderBBs[Builder.GetInsertBlock()] = llvm::AtomicOrdering::Release;
+break;
+  case 4: // memory_order_acq_rel
+OrderBBs[Builder.GetInsertBlock()] =
+llvm::AtomicOrdering::AcquireRelease;
+break;
+  case 5: // memory_order_seq_cst
+OrderBBs[Builder.GetInsertBlock()] =
+llvm::AtomicOrdering::SequentiallyConsistent;
+break;
+  }
+} else {
+  llvm::BasicBlock *AcquireBB, *Re

[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-11 Thread Justin Stitt via cfe-commits

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


[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-11 Thread Joseph Huber via cfe-commits


@@ -5133,6 +5133,132 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Builder.SetInsertPoint(ContBB);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__scoped_atomic_thread_fence: {
+auto ScopeModel = AtomicScopeModel::create(AtomicScopeModelKind::Generic);
+
+Value *Order = EmitScalarExpr(E->getArg(0));
+Value *Scope = EmitScalarExpr(E->getArg(1));
+if (isa(Order) && isa(Scope)) {
+  int Ord = cast(Order)->getZExtValue();
+  int Scp = cast(Scope)->getZExtValue();
+  SyncScope SS = ScopeModel->isValid(Scp)
+ ? ScopeModel->map(Scp)
+ : ScopeModel->map(ScopeModel->getFallBackValue());
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+break;
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+Builder.CreateFence(
+llvm::AtomicOrdering::Acquire,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Acquire,
+getLLVMContext()));
+break;
+  case 3: // memory_order_release
+Builder.CreateFence(
+llvm::AtomicOrdering::Release,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Release,
+getLLVMContext()));
+break;
+  case 4: // memory_order_acq_rel
+Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::AcquireRelease,
+getLLVMContext()));
+break;
+  case 5: // memory_order_seq_cst
+Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::SequentiallyConsistent,
+getLLVMContext()));
+break;
+  }
+  return RValue::get(nullptr);
+}
+
+llvm::BasicBlock *ContBB = createBasicBlock("atomic.scope.continue", 
CurFn);
+
+llvm::DenseMap OrderBBs;

jhuber6 wrote:

Forgot to change it to a vector of pairs after I didn't need the map part.

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


[clang] [Clang] Add `-fdefault-generic-addrspace` flag for targeting GPUs (PR #115777)

2024-11-11 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> > This has a lot of unfortable effects that limit using address spaces in C++ 
> > as well
> > as making it more difficult to work with.
> 
> Can you give some examples?
> 
> It sounds that what you really want is for address space qualifiers to not be 
> part of a type signature. OpenCL sort of happens to avoid that by sticking 
> `__generic` AS qualifier on all pointers without one, and thus make plain 
> pointers _become_ `__generic` ones, which gets some C++ code happy, but that 
> does look like a quirk of OpenCL. Normally, we a) do not have an explicit 
> generic AS (or it would be indistinguishable from a plain pointer as it is on 
> LLVM level w/ AS(0)), and b) when we specialize a function with an 
> AS-specific pointer type, we generally do want it to be that type.
> 
> Clang and C++ indeed still have issues with AS-qualified pointers. E.g. 
> attempts to define function overloads with `AS(0)` and plain pointers result 
> in an error about conflicting name mangling: https://godbolt.org/z/fW3dP4an5
> 
> Yet C++ does not consider the types equivalent, so you can't pass plain 
> pointer as AS(0)-qualified argument and vice versa: 
> https://godbolt.org/z/K4PEv9e7j
> 
> It's a bug that needs fixing, IMO. We either treat unqualified ans AS(0) 
> pointer types as different, and give them different mangling. Or we should 
> treat AS(0) and plain pointer types the same, diagnose AS0/plain overloads as 
> redefinitions (no need to wait til we run into mangling conflict) and allow 
> using them interchangeably.
> 
> Would straightening this out help with the issue you're trying to solve?

Stuff like this is mostly what I'm talking about 
https://godbolt.org/z/1K8KGdqe9. I previously wanted to relax the handling of 
the default address space for all targets, but that made @AlexVlx unhappy in 
https://github.com/llvm/llvm-project/pull/112248.

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


[clang] [Clang] Add `-fdefault-generic-addrspace` flag for targeting GPUs (PR #115777)

2024-11-11 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> > > This has a lot of unfortable effects that limit using address spaces in 
> > > C++ as well
> > > as making it more difficult to work with.
> > 
> > 
> > Can you give some examples?
> > It sounds that what you really want is for address space qualifiers to not 
> > be part of a type signature. OpenCL sort of happens to avoid that by 
> > sticking `__generic` AS qualifier on all pointers without one, and thus 
> > make plain pointers _become_ `__generic` ones, which gets some C++ code 
> > happy, but that does look like a quirk of OpenCL. Normally, we a) do not 
> > have an explicit generic AS (or it would be indistinguishable from a plain 
> > pointer as it is on LLVM level w/ AS(0)), and b) when we specialize a 
> > function with an AS-specific pointer type, we generally do want it to be 
> > that type.
> > Clang and C++ indeed still have issues with AS-qualified pointers. E.g. 
> > attempts to define function overloads with `AS(0)` and plain pointers 
> > result in an error about conflicting name mangling: 
> > https://godbolt.org/z/fW3dP4an5
> > Yet C++ does not consider the types equivalent, so you can't pass plain 
> > pointer as AS(0)-qualified argument and vice versa: 
> > https://godbolt.org/z/K4PEv9e7j
> > It's a bug that needs fixing, IMO. We either treat unqualified ans AS(0) 
> > pointer types as different, and give them different mangling. Or we should 
> > treat AS(0) and plain pointer types the same, diagnose AS0/plain overloads 
> > as redefinitions (no need to wait til we run into mangling conflict) and 
> > allow using them interchangeably.
> > Would straightening this out help with the issue you're trying to solve?
> 
> Stuff like this is mostly what I'm talking about 
> https://godbolt.org/z/1K8KGdqe9. I previously wanted to relax the handling of 
> the default address space for all targets, but that made @AlexVlx unhappy in 
> #112248. It's not it not being the type signature, it's more just having 
> default conversion rules. The case I provided with the template is just an 
> edge case that this changes away from C++, which is a little weird.

Honestly I would prefer to just have an option that lets `DefaultAS` work as 
the generic one... Then we wouldn't have the weirdness that templates suddenly 
stop working because all pointers are `void __generic *`

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


[clang] [codegen] Fix crash in codegan caused by pointer calculation overflow (PR #115791)

2024-11-11 Thread via cfe-commits

https://github.com/vabridgers created 
https://github.com/llvm/llvm-project/pull/115791

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

Under certain conditions, the front end does not detect a possible overflow 
address calculations until codegen. This change emits a warning instead of 
allowing the compiler to crash.

```
clang: /clang/lib/CodeGen/CGExprScalar.cpp:5834: llvm::Value* 
clang::CodeGen::CodeGenFunction::EmitCheckedInBoundsGEP(
llvm::Type*, llvm::Value*, llvm::ArrayRef, bool, bool, 
clang::SourceLocation, const llvm::Twine&):
Assertion `(!isa(EvaluatedGEP.TotalOffset) || 
EvaluatedGEP.OffsetOverflows == Builder.getFalse())
&& "If the offset got constant-folded, we don't expect that there was an " 
"overflow."' failed.

0.  Program arguments: clang -c --target=x86_64-- -fsanitize=undefined 
ubsan-emit-bounds-check-crash-x86.c
1.   parser at end of file
2.  ubsan-emit-bounds-check-crash-x86.c:4:5: LLVM IR generation of 
declaration 'main'
3.  ubsan-emit-bounds-check-crash-x86.c:4:5: Generating code for 
declaration 'main'
...
 #9  
clang::CodeGen::CodeGenFunction::EmitCheckedInBoundsGEP(clang::CodeGen::Address,
 llvm::ArrayRef, llvm::Type*, bool, bool, 
clang::SourceLocation,
 clang::CharUnits, llvm::Twine const&)
 llvm::ArrayRef, clang::QualType, bool, bool, 
clang::SourceLocation,
 clang::QualType*, clang::Expr const*, llvm::Twine const&) 
CGExpr.cpp:0:0
 bool)
```

>From 90d95dd89a9c2f7b8c8b71c1042ad61d0a6e6729 Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Tue, 12 Nov 2024 00:56:14 +0100
Subject: [PATCH] [codegen] Fix crash in codegan caused by pointer calculation
 overflow

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

Under certain conditions, the front end does not detect a possible
overflow address calculations until codegen. This change emits
a warning instead of allowing the compiler to crash.

clang: /clang/lib/CodeGen/CGExprScalar.cpp:5834: llvm::Value* 
clang::CodeGen::CodeGenFunction::EmitCheckedInBoundsGEP(
llvm::Type*, llvm::Value*, llvm::ArrayRef, bool, bool, 
clang::SourceLocation, const llvm::Twine&):
Assertion `(!isa(EvaluatedGEP.TotalOffset) || 
EvaluatedGEP.OffsetOverflows == Builder.getFalse())
&& "If the offset got constant-folded, we don't expect that there was an " 
"overflow."' failed.

0.  Program arguments: clang -c --target=x86_64-- -fsanitize=undefined 
ubsan-emit-bounds-check-crash-x86.c
1.   parser at end of file
2.  ubsan-emit-bounds-check-crash-x86.c:4:5: LLVM IR generation of 
declaration 'main'
3.  ubsan-emit-bounds-check-crash-x86.c:4:5: Generating code for 
declaration 'main'
...
 #9  
clang::CodeGen::CodeGenFunction::EmitCheckedInBoundsGEP(clang::CodeGen::Address,
 llvm::ArrayRef, llvm::Type*, bool, bool, 
clang::SourceLocation,
 clang::CharUnits, llvm::Twine const&)
 llvm::ArrayRef, clang::QualType, bool, bool, 
clang::SourceLocation,
 clang::QualType*, clang::Expr const*, llvm::Twine const&) 
CGExpr.cpp:0:0
 bool)
---
 clang/lib/CodeGen/CGExprScalar.cpp  | 13 +
 .../CodeGen/ubsan-emit-bounds-check-crash-msp.c |  7 +++
 .../CodeGen/ubsan-emit-bounds-check-crash-x86.c |  7 +++
 3 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/CodeGen/ubsan-emit-bounds-check-crash-msp.c
 create mode 100644 clang/test/CodeGen/ubsan-emit-bounds-check-crash-x86.c

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 287d911e10ba58..5ed865820a9151 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -5831,10 +5831,15 @@ CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type 
*ElemTy, Value *Ptr,
   GEPOffsetAndOverflow EvaluatedGEP =
   EmitGEPOffsetInBytes(Ptr, GEPVal, getLLVMContext(), CGM, Builder);
 
-  assert((!isa(EvaluatedGEP.TotalOffset) ||
-  EvaluatedGEP.OffsetOverflows == Builder.getFalse()) &&
- "If the offset got constant-folded, we don't expect that there was an 
"
- "overflow.");
+  if (!(!isa(EvaluatedGEP.TotalOffset) ||
+EvaluatedGEP.OffsetOverflows == Builder.getFalse())) {
+DiagnosticsEngine &Diags = CGM.getDiags();
+unsigned DiagID = Diags.getCustomDiagID(
+DiagnosticsEngine::Error, "Expression caused pointer calculation "
+  "overflow during code generation");
+Diags.Report(Loc, DiagID);
+return GEPVal;
+  }
 
   auto *Zero = llvm::ConstantInt::getNullValue(IntPtrTy);
 
diff --git a/clang/test/CodeGen/ubsan-emit-bounds-check-crash-msp.c 
b/clang/test/CodeGen/ubsan-emit-bounds-check-crash-msp.c
new file mode 100644
index 00..b4da2f2b7ee720
--- /dev/null
+++ b/clang/test/CodeGen/ubsan-emit-bounds-check-crash-msp.c
@@ -0,0 +1,7 @@
+// REQUIRES: msp430-registered-target
+// RUN: %clang -c -fsanitize=undefined -

[clang] [codegen] Fix crash in codegan caused by pointer calculation overflow (PR #115791)

2024-11-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: None (vabridgers)


Changes

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

Under certain conditions, the front end does not detect a possible overflow 
address calculations until codegen. This change emits a warning instead of 
allowing the compiler to crash.

```
clang: /clang/lib/CodeGen/CGExprScalar.cpp:5834: llvm::Value* 
clang::CodeGen::CodeGenFunction::EmitCheckedInBoundsGEP(
llvm::Type*, llvm::Value*, llvm::ArrayRef, bool, bool, 
clang::SourceLocation, const llvm::Twine&):
Assertion `(!isa(EvaluatedGEP.TotalOffset) || 
EvaluatedGEP.OffsetOverflows == Builder.getFalse())
&& "If the offset got constant-folded, we don't expect that there 
was an " "overflow."' failed.

0.  Program arguments: clang -c --target=x86_64-- -fsanitize=undefined 
ubsan-emit-bounds-check-crash-x86.c
1.   parser at end of file
2.  ubsan-emit-bounds-check-crash-x86.c:4:5: LLVM IR generation of 
declaration 'main'
3.  ubsan-emit-bounds-check-crash-x86.c:4:5: Generating code for 
declaration 'main'
...
 #9  
clang::CodeGen::CodeGenFunction::EmitCheckedInBoundsGEP(clang::CodeGen::Address,
 llvm::ArrayRef, llvm::Type*, bool, bool, 
clang::SourceLocation,
 clang::CharUnits, llvm::Twine const&)
 llvm::ArrayRef, clang::QualType, bool, bool, 
clang::SourceLocation,
 clang::QualType*, clang::Expr const*, llvm::Twine const&) 
CGExpr.cpp:0:0
 bool)
```

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+9-4) 
- (added) clang/test/CodeGen/ubsan-emit-bounds-check-crash-msp.c (+7) 
- (added) clang/test/CodeGen/ubsan-emit-bounds-check-crash-x86.c (+7) 


``diff
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 287d911e10ba58..5ed865820a9151 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -5831,10 +5831,15 @@ CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type 
*ElemTy, Value *Ptr,
   GEPOffsetAndOverflow EvaluatedGEP =
   EmitGEPOffsetInBytes(Ptr, GEPVal, getLLVMContext(), CGM, Builder);
 
-  assert((!isa(EvaluatedGEP.TotalOffset) ||
-  EvaluatedGEP.OffsetOverflows == Builder.getFalse()) &&
- "If the offset got constant-folded, we don't expect that there was an 
"
- "overflow.");
+  if (!(!isa(EvaluatedGEP.TotalOffset) ||
+EvaluatedGEP.OffsetOverflows == Builder.getFalse())) {
+DiagnosticsEngine &Diags = CGM.getDiags();
+unsigned DiagID = Diags.getCustomDiagID(
+DiagnosticsEngine::Error, "Expression caused pointer calculation "
+  "overflow during code generation");
+Diags.Report(Loc, DiagID);
+return GEPVal;
+  }
 
   auto *Zero = llvm::ConstantInt::getNullValue(IntPtrTy);
 
diff --git a/clang/test/CodeGen/ubsan-emit-bounds-check-crash-msp.c 
b/clang/test/CodeGen/ubsan-emit-bounds-check-crash-msp.c
new file mode 100644
index 00..b4da2f2b7ee720
--- /dev/null
+++ b/clang/test/CodeGen/ubsan-emit-bounds-check-crash-msp.c
@@ -0,0 +1,7 @@
+// REQUIRES: msp430-registered-target
+// RUN: %clang -c -fsanitize=undefined -Wno-tentative-definition-array 
-Wno-return-type -Wno-unused-value -Wno-array-bounds -Xclang -verify 
--target=msp430-- %s
+int a;
+_Complex double b[1][1];
+void c(void) {
+  b[a][8920]; // expected-error {{Expression caused pointer calculation 
overflow during code generation}}
+}
diff --git a/clang/test/CodeGen/ubsan-emit-bounds-check-crash-x86.c 
b/clang/test/CodeGen/ubsan-emit-bounds-check-crash-x86.c
new file mode 100644
index 00..63bda82c14ae20
--- /dev/null
+++ b/clang/test/CodeGen/ubsan-emit-bounds-check-crash-x86.c
@@ -0,0 +1,7 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -c -Wno-tentative-definition-array -Wno-return-type 
-Wno-unused-value -Wno-array-bounds -Xclang -verify --target=x86_64-- 
-fsanitize=undefined %s 
+int **a[];
+int main() {
+  (*a)[33002202220]; // expected-error {{Expression caused pointer 
calculation overflow during code generation}}
+  return 0;
+}

``




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


[clang] [codegen] Fix crash in codegan caused by pointer calculation overflow (PR #115791)

2024-11-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (vabridgers)


Changes

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

Under certain conditions, the front end does not detect a possible overflow 
address calculations until codegen. This change emits a warning instead of 
allowing the compiler to crash.

```
clang: /clang/lib/CodeGen/CGExprScalar.cpp:5834: llvm::Value* 
clang::CodeGen::CodeGenFunction::EmitCheckedInBoundsGEP(
llvm::Type*, llvm::Value*, llvm::ArrayRef, bool, bool, 
clang::SourceLocation, const llvm::Twine&):
Assertion `(!isa(EvaluatedGEP.TotalOffset) || 
EvaluatedGEP.OffsetOverflows == Builder.getFalse())
&& "If the offset got constant-folded, we don't expect that there 
was an " "overflow."' failed.

0.  Program arguments: clang -c --target=x86_64-- -fsanitize=undefined 
ubsan-emit-bounds-check-crash-x86.c
1.   parser at end of file
2.  ubsan-emit-bounds-check-crash-x86.c:4:5: LLVM IR generation of 
declaration 'main'
3.  ubsan-emit-bounds-check-crash-x86.c:4:5: Generating code for 
declaration 'main'
...
 #9  
clang::CodeGen::CodeGenFunction::EmitCheckedInBoundsGEP(clang::CodeGen::Address,
 llvm::ArrayRef, llvm::Type*, bool, bool, 
clang::SourceLocation,
 clang::CharUnits, llvm::Twine const&)
 llvm::ArrayRef, clang::QualType, bool, bool, 
clang::SourceLocation,
 clang::QualType*, clang::Expr const*, llvm::Twine const&) 
CGExpr.cpp:0:0
 bool)
```

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+9-4) 
- (added) clang/test/CodeGen/ubsan-emit-bounds-check-crash-msp.c (+7) 
- (added) clang/test/CodeGen/ubsan-emit-bounds-check-crash-x86.c (+7) 


``diff
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 287d911e10ba58..5ed865820a9151 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -5831,10 +5831,15 @@ CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type 
*ElemTy, Value *Ptr,
   GEPOffsetAndOverflow EvaluatedGEP =
   EmitGEPOffsetInBytes(Ptr, GEPVal, getLLVMContext(), CGM, Builder);
 
-  assert((!isa(EvaluatedGEP.TotalOffset) ||
-  EvaluatedGEP.OffsetOverflows == Builder.getFalse()) &&
- "If the offset got constant-folded, we don't expect that there was an 
"
- "overflow.");
+  if (!(!isa(EvaluatedGEP.TotalOffset) ||
+EvaluatedGEP.OffsetOverflows == Builder.getFalse())) {
+DiagnosticsEngine &Diags = CGM.getDiags();
+unsigned DiagID = Diags.getCustomDiagID(
+DiagnosticsEngine::Error, "Expression caused pointer calculation "
+  "overflow during code generation");
+Diags.Report(Loc, DiagID);
+return GEPVal;
+  }
 
   auto *Zero = llvm::ConstantInt::getNullValue(IntPtrTy);
 
diff --git a/clang/test/CodeGen/ubsan-emit-bounds-check-crash-msp.c 
b/clang/test/CodeGen/ubsan-emit-bounds-check-crash-msp.c
new file mode 100644
index 00..b4da2f2b7ee720
--- /dev/null
+++ b/clang/test/CodeGen/ubsan-emit-bounds-check-crash-msp.c
@@ -0,0 +1,7 @@
+// REQUIRES: msp430-registered-target
+// RUN: %clang -c -fsanitize=undefined -Wno-tentative-definition-array 
-Wno-return-type -Wno-unused-value -Wno-array-bounds -Xclang -verify 
--target=msp430-- %s
+int a;
+_Complex double b[1][1];
+void c(void) {
+  b[a][8920]; // expected-error {{Expression caused pointer calculation 
overflow during code generation}}
+}
diff --git a/clang/test/CodeGen/ubsan-emit-bounds-check-crash-x86.c 
b/clang/test/CodeGen/ubsan-emit-bounds-check-crash-x86.c
new file mode 100644
index 00..63bda82c14ae20
--- /dev/null
+++ b/clang/test/CodeGen/ubsan-emit-bounds-check-crash-x86.c
@@ -0,0 +1,7 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -c -Wno-tentative-definition-array -Wno-return-type 
-Wno-unused-value -Wno-array-bounds -Xclang -verify --target=x86_64-- 
-fsanitize=undefined %s 
+int **a[];
+int main() {
+  (*a)[33002202220]; // expected-error {{Expression caused pointer 
calculation overflow during code generation}}
+  return 0;
+}

``




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


[clang] [clang][OpenMP][NFC] Move 'allocate' clause modifier parsing into fun… (PR #115775)

2024-11-11 Thread David Pagan via cfe-commits

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


[clang] e8c4842 - [clang][OpenMP][NFC] Move 'allocate' clause modifier parsing into fun… (#115775)

2024-11-11 Thread via cfe-commits

Author: David Pagan
Date: 2024-11-11T16:11:16-08:00
New Revision: e8c4842f0ce7a81440e2147a0c9bcc690714a6e5

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

LOG: [clang][OpenMP][NFC] Move 'allocate' clause modifier parsing into fun… 
(#115775)

…ction

Parsing of 'allocate' clause modifier ('allocator') has been moved into
a separate function in anticipation of adding another modifier
('align').

Added: 


Modified: 
clang/lib/Parse/ParseOpenMP.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 59a33eafa6be4f..c253133f611b0b 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4519,6 +4519,36 @@ static bool parseStepSize(Parser &P, 
SemaOpenMP::OpenMPVarListDataTy &Data,
   return false;
 }
 
+/// Parse 'allocate' clause modifiers.
+///   If allocator-modifier exists, return an expression for it and set
+///   Data field noting modifier was specified.
+///
+static ExprResult
+parseOpenMPAllocateClauseModifiers(Parser &P, OpenMPClauseKind Kind,
+   SemaOpenMP::OpenMPVarListDataTy &Data) {
+  const Token &Tok = P.getCurToken();
+  Preprocessor &PP = P.getPreprocessor();
+  ExprResult Tail;
+  auto Modifier = static_cast(
+  getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok), P.getLangOpts()));
+  if (Modifier == OMPC_ALLOCATE_allocator) {
+Data.AllocClauseModifier = Modifier;
+P.ConsumeToken();
+BalancedDelimiterTracker AllocateT(P, tok::l_paren,
+   tok::annot_pragma_openmp_end);
+if (Tok.is(tok::l_paren)) {
+  AllocateT.consumeOpen();
+  Tail = P.ParseAssignmentExpression();
+  AllocateT.consumeClose();
+} else {
+  P.Diag(Tok, diag::err_expected) << tok::l_paren;
+}
+  } else {
+Tail = P.ParseAssignmentExpression();
+  }
+  return Tail;
+}
+
 /// Parses clauses with list.
 bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
 OpenMPClauseKind Kind,
@@ -4800,23 +4830,7 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind 
DKind,
 // iterator(iterators-definition)
 ExprResult Tail;
 if (Kind == OMPC_allocate) {
-  auto Modifier = static_cast(
-  getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok), getLangOpts()));
-  if (Modifier == OMPC_ALLOCATE_allocator) {
-Data.AllocClauseModifier = Modifier;
-ConsumeToken();
-BalancedDelimiterTracker AllocateT(*this, tok::l_paren,
-   tok::annot_pragma_openmp_end);
-if (Tok.is(tok::l_paren)) {
-  AllocateT.consumeOpen();
-  Tail = ParseAssignmentExpression();
-  AllocateT.consumeClose();
-} else {
-  Diag(Tok, diag::err_expected) << tok::l_paren;
-}
-  } else {
-Tail = ParseAssignmentExpression();
-  }
+  Tail = parseOpenMPAllocateClauseModifiers(*this, Kind, Data);
 } else {
   HasIterator = true;
   EnterScope(Scope::OpenMPDirectiveScope | Scope::DeclScope);



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


[clang] [clang][OpenMP][NFC] Move 'allocate' clause modifier parsing into fun… (PR #115775)

2024-11-11 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`libc-x86_64-debian-gcc-fullbuild-dbg` running on 
`libc-x86_64-debian-fullbuild` while building `clang` at step 4 "annotate".

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


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

```
Step 4 (annotate) failure: 'python 
../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[   OK ] LlvmLibcFStatTest.NonExistentFile (4 us)
Ran 2 tests.  PASS: 2  FAIL: 0
[955/1099] Running unit test libc.test.src.sys.statvfs.linux.statvfs_test
[==] Running 2 tests from 1 test suite.
[ RUN  ] LlvmLibcSysStatvfsTest.StatvfsBasic
[   OK ] LlvmLibcSysStatvfsTest.StatvfsBasic (21 us)
[ RUN  ] LlvmLibcSysStatvfsTest.StatvfsInvalidPath
[   OK ] LlvmLibcSysStatvfsTest.StatvfsInvalidPath (263 us)
Ran 2 tests.  PASS: 2  FAIL: 0
[956/1099] Running unit test libc.test.src.sys.statvfs.linux.fstatvfs_test
FAILED: 
projects/libc/test/src/sys/statvfs/linux/CMakeFiles/libc.test.src.sys.statvfs.linux.fstatvfs_test
 
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/sys/statvfs/linux/CMakeFiles/libc.test.src.sys.statvfs.linux.fstatvfs_test
 
cd 
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/sys/statvfs/linux
 && 
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/src/sys/statvfs/linux/libc.test.src.sys.statvfs.linux.fstatvfs_test.__build__
[==] Running 2 tests from 1 test suite.
[ RUN  ] LlvmLibcSysFStatvfsTest.FStatvfsBasic
[   OK ] LlvmLibcSysFStatvfsTest.FStatvfsBasic (26 us)
[ RUN  ] LlvmLibcSysFStatvfsTest.FStatvfsInvalidPath
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp:39:
 FAILURE
Failed to match LIBC_NAMESPACE::mkdirat(AT_FDCWD, TEST_DIR, S_IRWXU) against 
Succeeds(0).
Expected return value to be equal to 0 but got -1.
Expected errno to be equal to "Success" but got "File exists".
[  FAILED  ] LlvmLibcSysFStatvfsTest.FStatvfsInvalidPath
Ran 2 tests.  PASS: 1  FAIL: 1
[957/1099] Running unit test libc.test.src.sys.utsname.uname_test
[==] Running 1 test from 1 test suite.
[ RUN  ] LlvmLibcUnameTest.GetMachineName
[   OK ] LlvmLibcUnameTest.GetMachineName (63 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[958/1099] Running unit test libc.test.src.sys.wait.wait4_test
[==] Running 1 test from 1 test suite.
[ RUN  ] LlvmLibcwait4Test.NoHangTest
[   OK ] LlvmLibcwait4Test.NoHangTest (6 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[959/1099] Running unit test libc.test.src.sys.wait.waitpid_test
[==] Running 1 test from 1 test suite.
[ RUN  ] LlvmLibcWaitPidTest.NoHangTest
[   OK ] LlvmLibcWaitPidTest.NoHangTest (4 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[960/1099] Running unit test libc.test.src.sys.epoll.linux.epoll_ctl_test
[==] Running 1 test from 1 test suite.
[ RUN  ] LlvmLibcEpollCtlTest.Basic
[   OK ] LlvmLibcEpollCtlTest.Basic (64 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[961/1099] Running unit test libc.test.src.sys.prctl.linux.prctl_test
[==] Running 2 tests from 1 test suite.
[ RUN  ] LlvmLibcSysPrctlTest.GetSetName
[   OK ] LlvmLibcSysPrctlTest.GetSetName (44 us)
[ RUN  ] LlvmLibcSysPrctlTest.GetTHPDisable
[   OK ] LlvmLibcSysPrctlTest.GetTHPDisable (40 us)
Ran 2 tests.  PASS: 2  FAIL: 0

```



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


[clang] [llvm] [llvm] Add triples for managarm (PR #87845)

2024-11-11 Thread via cfe-commits

https://github.com/no92 updated https://github.com/llvm/llvm-project/pull/87845

>From 9d681fdec1f5f86244dd0ba429f35805e1ddde61 Mon Sep 17 00:00:00 2001
From: no92 
Date: Fri, 6 Sep 2024 21:17:53 +0200
Subject: [PATCH 1/4] [llvm] Add managarm OS target

---
 llvm/include/llvm/ADT/bit.h|  2 +-
 llvm/include/llvm/TargetParser/Triple.h|  6 ++
 llvm/lib/Support/Unix/Path.inc | 13 -
 llvm/lib/TargetParser/Triple.cpp   |  4 
 llvm/unittests/TargetParser/TripleTest.cpp | 18 ++
 5 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h
index c42b5e686bdc9c..7a36ef2eb5163d 100644
--- a/llvm/include/llvm/ADT/bit.h
+++ b/llvm/include/llvm/ADT/bit.h
@@ -29,7 +29,7 @@
 
 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) ||
\
 defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) ||  
\
-defined(__OpenBSD__) || defined(__DragonFly__)
+defined(__OpenBSD__) || defined(__DragonFly__) || defined(__managarm__)
 #include 
 #elif defined(_AIX)
 #include 
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 779bd9017d7f12..3ff75723b35f1d 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -207,6 +207,7 @@ class Triple {
 Linux,
 Lv2, // PS3
 MacOSX,
+Managarm,
 NetBSD,
 OpenBSD,
 Solaris,
@@ -297,6 +298,7 @@ class Triple {
 Amplification,
 OpenCL,
 OpenHOS,
+Mlibc,
 
 PAuthTest,
 
@@ -821,6 +823,10 @@ class Triple {
 
   bool isVulkanOS() const { return getOS() == Triple::Vulkan; }
 
+  bool isOSManagarm() const {
+return getOS() == Triple::Managarm;
+  }
+
   bool isShaderStageEnvironment() const {
 EnvironmentType Env = getEnvironment();
 return Env == Triple::Pixel || Env == Triple::Vertex ||
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 44097bad7b46ed..f7e5d8748b3540 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -74,7 +74,8 @@ extern char **environ;
 
 #include 
 #if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) &&   
\
-!defined(__linux__) && !defined(__FreeBSD_kernel__) && !defined(_AIX)
+!defined(__linux__) && !defined(__FreeBSD_kernel__) && !defined(_AIX) &&   
\
+!defined(__managarm__)
 #include 
 #define STATVFS statvfs
 #define FSTATVFS fstatvfs
@@ -83,7 +84,7 @@ extern char **environ;
 #if defined(__OpenBSD__) || defined(__FreeBSD__)
 #include 
 #include 
-#elif defined(__linux__)
+#elif defined(__linux__) || defined(__managarm__)
 #if defined(HAVE_LINUX_MAGIC_H)
 #include 
 #else
@@ -129,7 +130,8 @@ const file_t kInvalidFile = -1;
 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || 
 \
 defined(__FreeBSD_kernel__) || defined(__linux__) || defined(__CYGWIN__) 
|| \
 defined(__DragonFly__) || defined(_AIX) || defined(__GNU__) || 
 \
-(defined(__sun__) && defined(__svr4__) || defined(__HAIKU__))
+(defined(__sun__) && defined(__svr4__) || defined(__HAIKU__)) ||   
 \
+defined(__managarm__)
 static int test_dir(char ret[PATH_MAX], const char *dir, const char *bin) {
   struct stat sb;
   char fullpath[PATH_MAX];
@@ -250,7 +252,8 @@ std::string getMainExecutable(const char *argv0, void 
*MainAddr) {
   // If we don't have procfs mounted, fall back to argv[0]
   if (getprogpath(exe_path, argv0) != NULL)
 return exe_path;
-#elif defined(__linux__) || defined(__CYGWIN__) || defined(__gnu_hurd__)
+#elif defined(__linux__) || defined(__CYGWIN__) || defined(__gnu_hurd__) ||
\
+defined(__managarm__)
   char exe_path[PATH_MAX];
   const char *aPath = "/proc/self/exe";
   if (sys::fs::exists(aPath)) {
@@ -477,7 +480,7 @@ std::error_code remove(const Twine &path, bool 
IgnoreNonExisting) {
 }
 
 static bool is_local_impl(struct STATVFS &Vfs) {
-#if defined(__linux__) || defined(__GNU__)
+#if defined(__linux__) || defined(__GNU__) || defined(__managarm__)
 #ifndef NFS_SUPER_MAGIC
 #define NFS_SUPER_MAGIC 0x6969
 #endif
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index b271f29d265cfe..656f06f0116cdd 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -277,6 +277,7 @@ StringRef Triple::getOSTypeName(OSType Kind) {
   case Linux: return "linux";
   case Lv2: return "lv2";
   case MacOSX: return "macosx";
+  case Managarm: return "managarm";
   case Mesa3D: return "mesa3d";
   case NVCL: return "nvcl";
   case NaCl: return "nacl";
@@ -360,6 +361,7 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType 
Kind) {
   case OpenHOS: return "ohos";
   case PAuthTest:
 return "pauthtest";
+  case Mlibc: return "mlibc";
   }
 
   llvm_unreachable("Invalid EnvironmentType!");
@@ -653,6 +655,7 @@ static Triple::OSType parseOS(Str

[clang] [llvm] [llvm] Add triples for managarm (PR #87845)

2024-11-11 Thread via cfe-commits

https://github.com/no92 updated https://github.com/llvm/llvm-project/pull/87845

>From 9d681fdec1f5f86244dd0ba429f35805e1ddde61 Mon Sep 17 00:00:00 2001
From: no92 
Date: Fri, 6 Sep 2024 21:17:53 +0200
Subject: [PATCH 1/3] [llvm] Add managarm OS target

---
 llvm/include/llvm/ADT/bit.h|  2 +-
 llvm/include/llvm/TargetParser/Triple.h|  6 ++
 llvm/lib/Support/Unix/Path.inc | 13 -
 llvm/lib/TargetParser/Triple.cpp   |  4 
 llvm/unittests/TargetParser/TripleTest.cpp | 18 ++
 5 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h
index c42b5e686bdc9c..7a36ef2eb5163d 100644
--- a/llvm/include/llvm/ADT/bit.h
+++ b/llvm/include/llvm/ADT/bit.h
@@ -29,7 +29,7 @@
 
 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) ||
\
 defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) ||  
\
-defined(__OpenBSD__) || defined(__DragonFly__)
+defined(__OpenBSD__) || defined(__DragonFly__) || defined(__managarm__)
 #include 
 #elif defined(_AIX)
 #include 
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 779bd9017d7f12..3ff75723b35f1d 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -207,6 +207,7 @@ class Triple {
 Linux,
 Lv2, // PS3
 MacOSX,
+Managarm,
 NetBSD,
 OpenBSD,
 Solaris,
@@ -297,6 +298,7 @@ class Triple {
 Amplification,
 OpenCL,
 OpenHOS,
+Mlibc,
 
 PAuthTest,
 
@@ -821,6 +823,10 @@ class Triple {
 
   bool isVulkanOS() const { return getOS() == Triple::Vulkan; }
 
+  bool isOSManagarm() const {
+return getOS() == Triple::Managarm;
+  }
+
   bool isShaderStageEnvironment() const {
 EnvironmentType Env = getEnvironment();
 return Env == Triple::Pixel || Env == Triple::Vertex ||
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 44097bad7b46ed..f7e5d8748b3540 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -74,7 +74,8 @@ extern char **environ;
 
 #include 
 #if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) &&   
\
-!defined(__linux__) && !defined(__FreeBSD_kernel__) && !defined(_AIX)
+!defined(__linux__) && !defined(__FreeBSD_kernel__) && !defined(_AIX) &&   
\
+!defined(__managarm__)
 #include 
 #define STATVFS statvfs
 #define FSTATVFS fstatvfs
@@ -83,7 +84,7 @@ extern char **environ;
 #if defined(__OpenBSD__) || defined(__FreeBSD__)
 #include 
 #include 
-#elif defined(__linux__)
+#elif defined(__linux__) || defined(__managarm__)
 #if defined(HAVE_LINUX_MAGIC_H)
 #include 
 #else
@@ -129,7 +130,8 @@ const file_t kInvalidFile = -1;
 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || 
 \
 defined(__FreeBSD_kernel__) || defined(__linux__) || defined(__CYGWIN__) 
|| \
 defined(__DragonFly__) || defined(_AIX) || defined(__GNU__) || 
 \
-(defined(__sun__) && defined(__svr4__) || defined(__HAIKU__))
+(defined(__sun__) && defined(__svr4__) || defined(__HAIKU__)) ||   
 \
+defined(__managarm__)
 static int test_dir(char ret[PATH_MAX], const char *dir, const char *bin) {
   struct stat sb;
   char fullpath[PATH_MAX];
@@ -250,7 +252,8 @@ std::string getMainExecutable(const char *argv0, void 
*MainAddr) {
   // If we don't have procfs mounted, fall back to argv[0]
   if (getprogpath(exe_path, argv0) != NULL)
 return exe_path;
-#elif defined(__linux__) || defined(__CYGWIN__) || defined(__gnu_hurd__)
+#elif defined(__linux__) || defined(__CYGWIN__) || defined(__gnu_hurd__) ||
\
+defined(__managarm__)
   char exe_path[PATH_MAX];
   const char *aPath = "/proc/self/exe";
   if (sys::fs::exists(aPath)) {
@@ -477,7 +480,7 @@ std::error_code remove(const Twine &path, bool 
IgnoreNonExisting) {
 }
 
 static bool is_local_impl(struct STATVFS &Vfs) {
-#if defined(__linux__) || defined(__GNU__)
+#if defined(__linux__) || defined(__GNU__) || defined(__managarm__)
 #ifndef NFS_SUPER_MAGIC
 #define NFS_SUPER_MAGIC 0x6969
 #endif
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index b271f29d265cfe..656f06f0116cdd 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -277,6 +277,7 @@ StringRef Triple::getOSTypeName(OSType Kind) {
   case Linux: return "linux";
   case Lv2: return "lv2";
   case MacOSX: return "macosx";
+  case Managarm: return "managarm";
   case Mesa3D: return "mesa3d";
   case NVCL: return "nvcl";
   case NaCl: return "nacl";
@@ -360,6 +361,7 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType 
Kind) {
   case OpenHOS: return "ohos";
   case PAuthTest:
 return "pauthtest";
+  case Mlibc: return "mlibc";
   }
 
   llvm_unreachable("Invalid EnvironmentType!");
@@ -653,6 +655,7 @@ static Triple::OSType parseOS(Str

[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-11 Thread Phoebe Wang via cfe-commits


@@ -273,6 +273,9 @@ def FeatureAMXCOMPLEX : SubtargetFeature<"amx-complex", 
"HasAMXCOMPLEX", "true",
 def FeatureAMXFP8 : SubtargetFeature<"amx-fp8", "HasAMXFP8", "true",
  "Support AMX-FP8 instructions",
  [FeatureAMXTILE]>;
+def FeatureAMXMOVRS : SubtargetFeature<"amx-movrs", "HasAMXMOVRS", "true",
+ "Support AMX-MOVRS instructions",
+ [FeatureAMXTILE]>;

phoebewang wrote:

Align within `<`

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-11 Thread Phoebe Wang via cfe-commits


@@ -370,6 +370,71 @@ let Predicates = [HasAMXTRANSPOSE, In64BitMode] in {
   }
 } // HasAMXTILE, HasAMXTRANSPOSE
 
+let Predicates = [HasAMXMOVRS, HasAMXTRANSPOSE, In64BitMode], SchedRW = 
[WriteSystem] in {
+  def T2RPNTLVWZ0RS   : I<0xf8, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz0rs\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5;
+  def T2RPNTLVWZ0RST1 : I<0xf9, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz0rst1\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5;
+  def T2RPNTLVWZ1RS   : I<0xf8, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz1rs\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5, PD;
+  def T2RPNTLVWZ1RST1 : I<0xf9, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz1rst1\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5, PD;
+  let isPseudo = true in {
+def PT2RPNTLVWZ0RSV   : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+def PT2RPNTLVWZ0RST1V : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+def PT2RPNTLVWZ1RSV   : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+def PT2RPNTLVWZ1RST1V : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+  }
+  let  usesCustomInserter = 1 in {
+def PT2RPNTLVWZ0RS   : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+def PT2RPNTLVWZ0RST1 : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+def PT2RPNTLVWZ1RS   : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+def PT2RPNTLVWZ1RST1 : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+  }
+} // HasAMXMOVRS, HasAMXTRANSPOSE
+
+let Predicates = [HasAMXMOVRS, In64BitMode], SchedRW = [WriteSystem] in {
+  def TILELOADDRS : I<0x4a, MRMSrcMemFSIB, (outs TILE:$dst),
+(ins sibmem:$src1),
+"tileloaddrs\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T8, XD;
+  def TILELOADDRST1 : I<0x4a, MRMSrcMemFSIB, (outs TILE:$dst),
+(ins sibmem:$src1),
+"tileloaddrst1\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T8, PD;
+
+  let isPseudo = true, mayLoad = 1 in

phoebewang wrote:

`let isPseudo = true, mayLoad = 1 in {` to include both.

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-11 Thread Phoebe Wang via cfe-commits


@@ -1880,6 +1880,7 @@ const StringMap sys::getHostCPUFeatures() {
!getX86CpuIDAndInfoEx(0x1e, 0x1, &EAX, &EBX, &ECX, &EDX);
   Features["amx-fp8"] = HasLeaf1E && ((EAX >> 4) & 1) && HasAMXSave;
   Features["amx-transpose"] = HasLeaf1E && ((EAX >> 5) & 1) && HasAMXSave;
+  Features["amx-movrs"] = HasLeaf1E && ((EAX >> 8) & 1) && HasAMXSave;

phoebewang wrote:

Put it in the order of offset.

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-11 Thread Phoebe Wang via cfe-commits


@@ -370,6 +370,71 @@ let Predicates = [HasAMXTRANSPOSE, In64BitMode] in {
   }
 } // HasAMXTILE, HasAMXTRANSPOSE
 
+let Predicates = [HasAMXMOVRS, HasAMXTRANSPOSE, In64BitMode], SchedRW = 
[WriteSystem] in {
+  def T2RPNTLVWZ0RS   : I<0xf8, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz0rs\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5;
+  def T2RPNTLVWZ0RST1 : I<0xf9, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz0rst1\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5;
+  def T2RPNTLVWZ1RS   : I<0xf8, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz1rs\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5, PD;
+  def T2RPNTLVWZ1RST1 : I<0xf9, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz1rst1\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5, PD;
+  let isPseudo = true in {
+def PT2RPNTLVWZ0RSV   : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+def PT2RPNTLVWZ0RST1V : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+def PT2RPNTLVWZ1RSV   : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+def PT2RPNTLVWZ1RST1V : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+  }
+  let  usesCustomInserter = 1 in {
+def PT2RPNTLVWZ0RS   : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+def PT2RPNTLVWZ0RST1 : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+def PT2RPNTLVWZ1RS   : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+def PT2RPNTLVWZ1RST1 : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+  }
+} // HasAMXMOVRS, HasAMXTRANSPOSE
+
+let Predicates = [HasAMXMOVRS, In64BitMode], SchedRW = [WriteSystem] in {
+  def TILELOADDRS : I<0x4a, MRMSrcMemFSIB, (outs TILE:$dst),
+(ins sibmem:$src1),
+"tileloaddrs\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T8, XD;
+  def TILELOADDRST1 : I<0x4a, MRMSrcMemFSIB, (outs TILE:$dst),
+(ins sibmem:$src1),
+"tileloaddrst1\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T8, PD;
+
+  let isPseudo = true, mayLoad = 1 in
+  def PTILELOADDRSV : PseudoI<(outs TILE:$dst), (ins GR16:$src1,
+GR16:$src2,
+opaquemem:$src3), []>;
+  let isPseudo = true, mayLoad = 1 in
+  def PTILELOADDRST1V : PseudoI<(outs TILE:$dst), (ins GR16:$src1,
+  GR16:$src2,
+  opaquemem:$src3), []>;
+  let  usesCustomInserter = 1 in {

phoebewang wrote:

Two spaces here.

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-11 Thread Phoebe Wang via cfe-commits


@@ -0,0 +1,201 @@
+/* ===--- amxmovrstransposeintrin.h - AMX_MOVRS_TRANSPOSE intrinsics -*- C++
+ * -*-===

phoebewang wrote:

Adjust for 1 line.

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-11 Thread Phoebe Wang via cfe-commits


@@ -656,6 +656,11 @@ _storebe_i64(void * __P, long long __D) {
 #include 
 #endif
 
+#if !defined(__SCE__) || __has_feature(modules) || defined(__AMX_MOVRS__)
+#include 
+#include 

phoebewang wrote:

This needs to be guarded with
```
#if !defined(__SCE__) || __has_feature(modules) || \
(defined(__AMX_MOVRS__) && defined(__AMX_TRANSPOSE__))
```

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-11 Thread Phoebe Wang via cfe-commits


@@ -370,6 +370,71 @@ let Predicates = [HasAMXTRANSPOSE, In64BitMode] in {
   }
 } // HasAMXTILE, HasAMXTRANSPOSE
 
+let Predicates = [HasAMXMOVRS, HasAMXTRANSPOSE, In64BitMode], SchedRW = 
[WriteSystem] in {
+  def T2RPNTLVWZ0RS   : I<0xf8, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz0rs\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5;
+  def T2RPNTLVWZ0RST1 : I<0xf9, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz0rst1\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5;
+  def T2RPNTLVWZ1RS   : I<0xf8, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz1rs\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5, PD;
+  def T2RPNTLVWZ1RST1 : I<0xf9, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz1rst1\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5, PD;
+  let isPseudo = true in {
+def PT2RPNTLVWZ0RSV   : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+def PT2RPNTLVWZ0RST1V : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+def PT2RPNTLVWZ1RSV   : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+def PT2RPNTLVWZ1RST1V : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+  }
+  let  usesCustomInserter = 1 in {
+def PT2RPNTLVWZ0RS   : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+def PT2RPNTLVWZ0RST1 : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+def PT2RPNTLVWZ1RS   : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+def PT2RPNTLVWZ1RST1 : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+  }
+} // HasAMXMOVRS, HasAMXTRANSPOSE
+
+let Predicates = [HasAMXMOVRS, In64BitMode], SchedRW = [WriteSystem] in {
+  def TILELOADDRS : I<0x4a, MRMSrcMemFSIB, (outs TILE:$dst),
+(ins sibmem:$src1),
+"tileloaddrs\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T8, XD;
+  def TILELOADDRST1 : I<0x4a, MRMSrcMemFSIB, (outs TILE:$dst),
+(ins sibmem:$src1),
+"tileloaddrst1\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T8, PD;
+
+  let isPseudo = true, mayLoad = 1 in
+  def PTILELOADDRSV : PseudoI<(outs TILE:$dst), (ins GR16:$src1,
+GR16:$src2,
+opaquemem:$src3), []>;
+  let isPseudo = true, mayLoad = 1 in
+  def PTILELOADDRST1V : PseudoI<(outs TILE:$dst), (ins GR16:$src1,
+  GR16:$src2,
+  opaquemem:$src3), []>;
+  let  usesCustomInserter = 1 in {
+let mayLoad = 1 in

phoebewang wrote:

Combine `mayLoad = 1` with `usesCustomInserter = 1`

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-11 Thread Phoebe Wang via cfe-commits


@@ -0,0 +1,14 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown \
+// RUN: -target-feature +amx-int8 -target-feature +amx-bf16 \
+// RUN: -target-feature +amx-element -verify

phoebewang wrote:

amx-movrs

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-11 Thread Phoebe Wang via cfe-commits


@@ -5305,6 +5339,13 @@ void X86DAGToDAGISel::Select(SDNode *Node) {
   ReplaceNode(Node, CNode);
   return;
 }
+case Intrinsic::x86_t2rpntlvwz0rs:
+case Intrinsic::x86_t2rpntlvwz0rst1:
+case Intrinsic::x86_t2rpntlvwz1rs:
+case Intrinsic::x86_t2rpntlvwz1rst1:
+  if (!Subtarget->hasAMXTRANSPOSE() || !Subtarget->hasAMXMOVRS())

phoebewang wrote:

Use `!Subtarget->hasAMXMOVRS()` only since we check 
`!Subtarget->hasAMXTRANSPOSE()` later.

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


[clang] [llvm] Emit constrained atan2 intrinsic for clang builtin (PR #113636)

2024-11-11 Thread Tex Riddell via cfe-commits

https://github.com/tex3d updated 
https://github.com/llvm/llvm-project/pull/113636

>From a6776121bb118fe4083ccb94fa582cca1aef7f9b Mon Sep 17 00:00:00 2001
From: Tex Riddell 
Date: Tue, 15 Oct 2024 16:18:44 -0700
Subject: [PATCH 1/4] Emit constrained atan2 intrinsic for clang builtin

This change is part of this proposal: 
https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294

- `Builtins.td` - Add f16 support for libm atan2 builtin
- `CGBuiltin.cpp` - Emit constraint atan2 intrinsic for clang builtin

Part of Implement the atan2 HLSL Function #70096.
---
 clang/include/clang/Basic/Builtins.td |  6 +++---
 clang/lib/CodeGen/CGBuiltin.cpp   | 11 ++
 clang/test/CodeGen/X86/math-builtins.c| 14 ++---
 .../test/CodeGen/constrained-math-builtins.c  |  7 +++
 clang/test/CodeGen/libcalls.c |  7 +++
 clang/test/CodeGen/math-libcalls.c| 20 +--
 .../test/CodeGenCXX/builtin-calling-conv.cpp  | 10 +-
 clang/test/CodeGenOpenCL/builtins-f16.cl  |  3 +++
 8 files changed, 49 insertions(+), 29 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 87a798183d6e19..305b085f69420a 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -227,10 +227,10 @@ def FminimumNumF16F128 : Builtin, F16F128MathTemplate {
   let Prototype = "T(T, T)";
 }
 
-def Atan2F128 : Builtin {
-  let Spellings = ["__builtin_atan2f128"];
+def Atan2F16F128 : Builtin, F16F128MathTemplate {
+  let Spellings = ["__builtin_atan2"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, 
ConstIgnoringErrnoAndExceptions];
-  let Prototype = "__float128(__float128, __float128)";
+  let Prototype = "T(T, T)";
 }
 
 def CopysignF16 : Builtin {
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5c3df5124517d6..9b63fcbedc8c45 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2798,6 +2798,17 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::atan, 
Intrinsic::experimental_constrained_atan));
 
+case Builtin::BIatan2:
+case Builtin::BIatan2f:
+case Builtin::BIatan2l:
+case Builtin::BI__builtin_atan2:
+case Builtin::BI__builtin_atan2f:
+case Builtin::BI__builtin_atan2f16:
+case Builtin::BI__builtin_atan2l:
+case Builtin::BI__builtin_atan2f128:
+  return RValue::get(emitBinaryMaybeConstrainedFPBuiltin(
+  *this, E, Intrinsic::atan2, 
Intrinsic::experimental_constrained_atan2));
+
 case Builtin::BIceil:
 case Builtin::BIceilf:
 case Builtin::BIceill:
diff --git a/clang/test/CodeGen/X86/math-builtins.c 
b/clang/test/CodeGen/X86/math-builtins.c
index 48465df21cca19..bf107437fc63a3 100644
--- a/clang/test/CodeGen/X86/math-builtins.c
+++ b/clang/test/CodeGen/X86/math-builtins.c
@@ -45,10 +45,10 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 
   __builtin_atan2(f,f);__builtin_atan2f(f,f) ;  __builtin_atan2l(f, f); 
__builtin_atan2f128(f,f);
 
-// NO__ERRNO: declare double @atan2(double noundef, double noundef) 
[[READNONE:#[0-9]+]]
-// NO__ERRNO: declare float @atan2f(float noundef, float noundef) [[READNONE]]
-// NO__ERRNO: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) 
[[READNONE]]
-// NO__ERRNO: declare fp128 @atan2f128(fp128 noundef, fp128 noundef) 
[[READNONE]]
+// NO__ERRNO: declare double @llvm.atan2.f64(double, double) 
[[READNONE_INTRINSIC:#[0-9]+]]
+// NO__ERRNO: declare float @llvm.atan2.f32(float, float) 
[[READNONE_INTRINSIC]]
+// NO__ERRNO: declare x86_fp80 @llvm.atan2.f80(x86_fp80, x86_fp80) 
[[READNONE_INTRINSIC]]
+// NO__ERRNO: declare fp128 @llvm.atan2.f128(fp128, fp128) 
[[READNONE_INTRINSIC]]
 // HAS_ERRNO: declare double @atan2(double noundef, double noundef) 
[[NOT_READNONE]]
 // HAS_ERRNO: declare float @atan2f(float noundef, float noundef) 
[[NOT_READNONE]]
 // HAS_ERRNO: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) 
[[NOT_READNONE]]
@@ -56,7 +56,7 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 
   __builtin_copysign(f,f); __builtin_copysignf(f,f); __builtin_copysignl(f,f); 
__builtin_copysignf128(f,f);
 
-// NO__ERRNO: declare double @llvm.copysign.f64(double, double) 
[[READNONE_INTRINSIC:#[0-9]+]]
+// NO__ERRNO: declare double @llvm.copysign.f64(double, double) 
[[READNONE_INTRINSIC]]
 // NO__ERRNO: declare float @llvm.copysign.f32(float, float) 
[[READNONE_INTRINSIC]]
 // NO__ERRNO: declare x86_fp80 @llvm.copysign.f80(x86_fp80, x86_fp80) 
[[READNONE_INTRINSIC]]
 // NO__ERRNO: declare fp128 @llvm.copysign.f128(fp128, fp128) 
[[READNONE_INTRINSIC]]
@@ -179,7 +179,7 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 
   __builtin_acosh(f

[clang] [codegen] Fix crash in codegan caused by pointer calculation overflow (PR #115791)

2024-11-11 Thread via cfe-commits

vabridgers wrote:

I know the diagnostic could probably be better, just trying to get the code 
review party started. 

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


[clang] [llvm] [RISCV] Add TT-Ascalon-d8 processor (PR #115100)

2024-11-11 Thread Petr Penzin via cfe-commits


@@ -104,6 +104,62 @@
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=syntacore-scr1-max | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR1-MAX %s
 // MTUNE-SYNTACORE-SCR1-MAX: "-tune-cpu" "syntacore-scr1-max"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=tt-ascalon-d8 | 
FileCheck -check-prefix=MTUNE-TT-ASCALON-D8 %s
+// MTUNE-TT-ASCALON-D8: "-tune-cpu" "tt-ascalon-d8"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=tt-ascalon-d8 | 
FileCheck -check-prefix=MCPU-TT-ASCALON-D8 %s
+// MCPU-TT-ASCALON-D8: "-target-cpu" "tt-ascalon-d8"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+m" "-target-feature" "+a"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+f" "-target-feature" "+d"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+c" "-target-feature" "+v"

ppenzin wrote:

Addressed

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


[clang] da032a6 - [Wunsafe-buffer-usage] Fix false positives in handling string literals. (#115552)

2024-11-11 Thread via cfe-commits

Author: Malavika Samak
Date: 2024-11-11T16:47:28-08:00
New Revision: da032a609c1bde6f6775cf1650e08a205920d920

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

LOG: [Wunsafe-buffer-usage] Fix false positives in handling string literals. 
(#115552)

Do not warn when a string literal is indexed and the idex value is
within the bounds of the length of the string.

(rdar://139106996)

Co-authored-by: MalavikaSamak 

Added: 


Modified: 
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 2c68409b846bc8..b683826503c74c 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -436,21 +436,31 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
 
   const auto *BaseDRE =
   dyn_cast(Node.getBase()->IgnoreParenImpCasts());
-  if (!BaseDRE)
-return false;
-  if (!BaseDRE->getDecl())
-return false;
-  const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
-  BaseDRE->getDecl()->getType());
-  if (!CATy)
+  const auto *SLiteral =
+  dyn_cast(Node.getBase()->IgnoreParenImpCasts());
+  uint64_t size;
+
+  if (!BaseDRE && !SLiteral)
 return false;
 
+  if (BaseDRE) {
+if (!BaseDRE->getDecl())
+  return false;
+const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
+BaseDRE->getDecl()->getType());
+if (!CATy) {
+  return false;
+}
+size = CATy->getLimitedSize();
+  } else if (SLiteral) {
+size = SLiteral->getLength() + 1;
+  }
+
   if (const auto *IdxLit = dyn_cast(Node.getIdx())) {
 const APInt ArrIdx = IdxLit->getValue();
 // FIXME: ArrIdx.isNegative() we could immediately emit an error as that's 
a
 // bug
-if (ArrIdx.isNonNegative() &&
-ArrIdx.getLimitedValue() < CATy->getLimitedSize())
+if (ArrIdx.isNonNegative() && ArrIdx.getLimitedValue() < size)
   return true;
   }
 

diff  --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
index 8b2f103ec66708..c6c93a27e4b969 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
@@ -38,3 +38,17 @@ void constant_idx_unsafe(unsigned idx) {
 // expected-note@-1{{change type of 'buffer' to 
'std::array' to label it for hardening}}
   buffer[10] = 0;   // expected-note{{used in buffer access here}}
 }
+
+void constant_id_string(unsigned idx) {
+  char safe_char = "abc"[1]; // no-warning
+  safe_char = ""[0];
+  safe_char = "\0"[0];
+ 
+  char abcd[5] = "abc";
+  abcd[2]; // no-warning
+
+  char unsafe_char = "abc"[3];
+  unsafe_char = "abc"[-1]; //expected-warning{{unsafe buffer access}}
+  unsafe_char = ""[1]; //expected-warning{{unsafe buffer access}} 
+  unsafe_char = ""[idx]; //expected-warning{{unsafe buffer access}}
+}



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


[clang] [Wunsafe-buffer-usage] Fix false positives in handling string literals. (PR #115552)

2024-11-11 Thread Malavika Samak via cfe-commits

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


[clang] [Clang] Add `-fdefault-generic-addrspace` flag for targeting GPUs (PR #115777)

2024-11-11 Thread Artem Belevich via cfe-commits

Artem-B wrote:

I think I generally agree with @AlexVlx argument. While the patch may solve you 
immediate issue, I think it's not going to give you a usable compilation model 
for AS-qualified pointers.

If you are defining your own C++ extension along the lines of CUDA/HIP/OpenCL, 
you would have some wiggle room on how you want things to behave, but if you 
want it to be a regular C++ compilation, you've got to play by C++ rules. The 
diagnostics in your example looks quite sensible to me -- you're asking 
compiler to do  with things of different types, but you do not provide 
implementation for it. and because C++ has no idea about what can and can't be 
done with non-default AS, it's all on you to do it.

I don't think you can have this cake (explicit AS-qualified pointers) and eat 
it (make them all usable out of the box in a consistent manner, magically 
compatible with everything C++). Sticking `__generic` on plain pointer types 
will likely lead to issues. 

For example, it looks like the pointer promotion will be ABI-breaking. How will 
you mangle function names with pointer arguments? Normally AS is encoded in the 
mangled name. And both the caller and callee must be in sync in order to call 
the right function -> therefore everything must be compiled with the same 
setting of this flag, including libc, etc. 


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


[clang] [llvm] [RISCV] Add TT-Ascalon-d8 processor (PR #115100)

2024-11-11 Thread Petr Penzin via cfe-commits

https://github.com/ppenzin updated 
https://github.com/llvm/llvm-project/pull/115100

>From 246f1374b31ac11041deffe2f4afc35ee93cc66f Mon Sep 17 00:00:00 2001
From: Petr Penzin 
Date: Tue, 5 Nov 2024 13:11:48 -0600
Subject: [PATCH 1/4] [RISCV] Add TT-Ascalon-d8 processor

Ascalon is an out-of-order CPU core from Tenstorrent. Overview:
https://tenstorrent.com/ip/tt-ascalon

Adding 8-wide version, -mcpu=tt-ascalon-d8. Scheduling model will be
added in a separate PR.

Co-authored-by: Anton Blanchard 
---
 clang/test/Driver/riscv-cpus.c| 54 +++
 .../test/Misc/target-invalid-cpu-note/riscv.c |  2 +
 llvm/docs/ReleaseNotes.md |  1 +
 llvm/lib/Target/RISCV/RISCVProcessors.td  | 48 +
 4 files changed, 105 insertions(+)

diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index d36639d16ad4cb..468e01c8d934da 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -104,6 +104,60 @@
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=syntacore-scr1-max | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR1-MAX %s
 // MTUNE-SYNTACORE-SCR1-MAX: "-tune-cpu" "syntacore-scr1-max"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=tt-ascalon-d8 | 
FileCheck -check-prefix=MTUNE-TT-ASCALON-D8 %s
+// MTUNE-TT-ASCALON-D8: "-tune-cpu" "tt-ascalon-d8"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=tt-ascalon-d8 | 
FileCheck -check-prefix=MCPU-TT-ASCALON-D8 %s
+// MCPU-TT-ASCALON-D8: "-target-cpu" "tt-ascalon-d8"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+m" "-target-feature" "+a"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+f" "-target-feature" "+d"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+c" "-target-feature" "+v"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+h" "-target-feature" "+zicbom"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zicbop"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zicboz"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zicntr"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zicond"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zicsr"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zifencei"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zihintntl"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zihintpause"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zihpm"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zmmul"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zawrs"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zfa"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zfbfmin"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zfh"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zfhmin"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zca" "-target-feature" "+zcb"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zba" "-target-feature" "+zbb"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zbs" "-target-feature" "+zkt"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvbb"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvbc"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zve32f"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zve32x"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zve64d"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zve64f"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zve64x"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvfbfmin"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvfbfwma"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvfh"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvfhmin"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvkb"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvkg"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvkn"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvknc"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvkned"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvkng"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvknhb"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvkt"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvl128b"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvl256b"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvl32b"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+zvl64b"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+svinval"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+svnapot"
+// MCPU-TT-ASCALON-D8-SAME: "-target-feature" "+svpbmt"
+
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=veyron-v1 | FileCheck 
-check-prefix=MCPU-VEYRON-V1 %s
 // MCPU-VEYRON-V1: "-target-cpu" "veyron-v1"
 // MCPU-VEYRON-V1: "-target-feature" "+m"
diff --git a/clang/test/Misc/target-invalid-cpu-note/riscv.c 
b/clang/test/Misc/target-invalid-cpu-note/riscv.c
index 7bbf3574af3c35..8c5df5884cd791 100644
--- a/clang/test/Misc/target-invalid-cpu-note/riscv.c
+++ b/clang/test/Misc/target-invalid-cpu-note/riscv.c
@@ -41,6 +41,7 @@
 // RISCV64-SAME: {{^}}, syntacore-scr4-rv64
 // RISCV64-SAME: {{^}}, syntacore-scr5-rv64
 

[clang] [Clang] Add `-fdefault-generic-addrspace` flag for targeting GPUs (PR #115777)

2024-11-11 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> I think I generally agree with @AlexVlx argument. While the patch may solve 
> you immediate issue, I think it's not going to give you a usable compilation 
> model for AS-qualified pointers.
> 
> If you are defining your own C++ extension along the lines of 
> CUDA/HIP/OpenCL, you would have some wiggle room on how you want things to 
> behave, but if you want it to be a regular C++ compilation, you've got to 
> play by C++ rules. The diagnostics in your example looks quite sensible to me 
> -- you're asking compiler to do with things of different types, but you do 
> not provide implementation for it. and because C++ has no idea about what can 
> and can't be done with non-default AS, it's all on you to do it.
> 
> I don't think you can have this cake (explicit AS-qualified pointers) and eat 
> it (make them all usable out of the box in a consistent manner, magically 
> compatible with everything C++). Sticking `__generic` on plain pointer types 
> will likely lead to issues.
> 
> For example, it looks like the pointer promotion will be ABI-breaking. How 
> will you mangle function names with pointer arguments? Normally AS is encoded 
> in the mangled name. And both the caller and callee must be in sync in order 
> to call the right function -> therefore everything must be compiled with the 
> same setting of this flag, including libc, etc.

I agree in general that C/C++ has no semantic meaning ascribed to address 
spaces, so we cannot rely on intelligent semantic checking since C++ is 
strongly typed. Realizing that this literally changes all the address spaces 
makes it a bit difficult to argue that it's just C++, however it's pretty much 
impossible to use classes as-is since we cannot convert `this` to the object's 
address space.

I think this approach is fine as an opt-in to have really lenient rules, since 
that's what AMDGPU and CUDA support already... But doing it with 
`opencl_generic` does not seem the way as you mentioned, since now every 
function gets a different mangling, and templates all work different.

This was the 'easy' solution, alternatives would be to allow this for target 
specific address spaces (i.e. AMDGPU supports any addrspace to default). 
Another solution would be to do the same treatment here but with `DefaultAS` 
instead. I'd say the third solution is to just put C-style casts everywhere, 
but that doesn't really work for classes as evidenced here.

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


[clang] [-Wunsafe-buffer-usage] Fix false positives in warning againt 2-parameter std::span constructor (PR #115797)

2024-11-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Malavika Samak (malavikasamak)


Changes

Do not warn when two parameter constructor receives pointer address from a 
std::addressof method and the span size is set to 1.

(rdar://139298119)

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


2 Files Affected:

- (modified) clang/lib/Analysis/UnsafeBufferUsage.cpp (+8) 
- (modified) 
clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp 
(+17) 


``diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 2c68409b846bc8..507e61564fc3f8 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -410,6 +410,14 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) 
{
   // Check form 3:
   return Arg1CV && Arg1CV->isOne();
 break;
+  case Stmt::CallExprClass:
+if(const auto *CE = dyn_cast(Arg0)) {
+  const auto FnDecl = CE->getDirectCallee();
+  if(FnDecl && FnDecl->getNameAsString() == "addressof" && 
FnDecl->isInStdNamespace()) {
+return Arg1CV && Arg1CV->isOne();
+  }
+}
+break;
   default:
 break;
   }
diff --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp
index c138fe088b3ba9..30b6d4ba9fb904 100644
--- 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp
+++ 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp
@@ -21,6 +21,12 @@ namespace std {
 
   template< class T >
   T&& move( T&& t ) noexcept;
+
+  template 
+  _Tp* addressof(_Tp& __x) {
+return &__x;
+  }
+ 
 }
 
 namespace irrelevant_constructors {
@@ -74,15 +80,26 @@ namespace construct_wt_ptr_size {
 return std::span{p, 10};// expected-warning{{the 
two-parameter std::span construction is unsafe as it can introduce mismatch 
between buffer size and the bound information}}
   }
 
+  // addressof method defined outside std namespace.
+  template 
+  _Tp* addressof(_Tp& __x) {
+return &__x;
+  }
+
   void notWarnSafeCases(unsigned n, int *p) {
 int X;
 unsigned Y = 10;
 std::span S = std::span{&X, 1}; // no-warning
+S = std::span{std::addressof(X), 1}; // no-warning
 int Arr[10];
 typedef int TenInts_t[10];
 TenInts_t Arr2;
 
 S = std::span{&X, 2};// expected-warning{{the 
two-parameter std::span construction is unsafe as it can introduce mismatch 
between buffer size and the bound information}}
+S = std::span{std::addressof(X), 2}; // expected-warning{{the 
two-parameter std::span construction is unsafe as it can introduce mismatch 
between buffer size and the bound information}}
+// Warn when a non std method also named addressof
+S = std::span{addressof(X), 1}; // expected-warning{{the two-parameter 
std::span construction is unsafe as it can introduce mismatch between buffer 
size and the bound information}}
+
 S = std::span{new int[10], 10};  // no-warning
 S = std::span{new int[n], n};// no-warning
 S = std::span{new int, 1};   // no-warning

``




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


[clang] [-Wunsafe-buffer-usage] Fix false positives in warning againt 2-parameter std::span constructor (PR #115797)

2024-11-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-analysis

Author: Malavika Samak (malavikasamak)


Changes

Do not warn when two parameter constructor receives pointer address from a 
std::addressof method and the span size is set to 1.

(rdar://139298119)

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


2 Files Affected:

- (modified) clang/lib/Analysis/UnsafeBufferUsage.cpp (+8) 
- (modified) 
clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp 
(+17) 


``diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 2c68409b846bc8..507e61564fc3f8 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -410,6 +410,14 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) 
{
   // Check form 3:
   return Arg1CV && Arg1CV->isOne();
 break;
+  case Stmt::CallExprClass:
+if(const auto *CE = dyn_cast(Arg0)) {
+  const auto FnDecl = CE->getDirectCallee();
+  if(FnDecl && FnDecl->getNameAsString() == "addressof" && 
FnDecl->isInStdNamespace()) {
+return Arg1CV && Arg1CV->isOne();
+  }
+}
+break;
   default:
 break;
   }
diff --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp
index c138fe088b3ba9..30b6d4ba9fb904 100644
--- 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp
+++ 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp
@@ -21,6 +21,12 @@ namespace std {
 
   template< class T >
   T&& move( T&& t ) noexcept;
+
+  template 
+  _Tp* addressof(_Tp& __x) {
+return &__x;
+  }
+ 
 }
 
 namespace irrelevant_constructors {
@@ -74,15 +80,26 @@ namespace construct_wt_ptr_size {
 return std::span{p, 10};// expected-warning{{the 
two-parameter std::span construction is unsafe as it can introduce mismatch 
between buffer size and the bound information}}
   }
 
+  // addressof method defined outside std namespace.
+  template 
+  _Tp* addressof(_Tp& __x) {
+return &__x;
+  }
+
   void notWarnSafeCases(unsigned n, int *p) {
 int X;
 unsigned Y = 10;
 std::span S = std::span{&X, 1}; // no-warning
+S = std::span{std::addressof(X), 1}; // no-warning
 int Arr[10];
 typedef int TenInts_t[10];
 TenInts_t Arr2;
 
 S = std::span{&X, 2};// expected-warning{{the 
two-parameter std::span construction is unsafe as it can introduce mismatch 
between buffer size and the bound information}}
+S = std::span{std::addressof(X), 2}; // expected-warning{{the 
two-parameter std::span construction is unsafe as it can introduce mismatch 
between buffer size and the bound information}}
+// Warn when a non std method also named addressof
+S = std::span{addressof(X), 1}; // expected-warning{{the two-parameter 
std::span construction is unsafe as it can introduce mismatch between buffer 
size and the bound information}}
+
 S = std::span{new int[10], 10};  // no-warning
 S = std::span{new int[n], n};// no-warning
 S = std::span{new int, 1};   // no-warning

``




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


[clang] [-Wunsafe-buffer-usage] Fix false positives in warning againt 2-parameter std::span constructor (PR #115797)

2024-11-11 Thread Malavika Samak via cfe-commits

https://github.com/malavikasamak created 
https://github.com/llvm/llvm-project/pull/115797

Do not warn when two parameter constructor receives pointer address from a 
std::addressof method and the span size is set to 1.

(rdar://139298119)

>From a60c18973c0ea5b59c7c5f38813083e862f70e6e Mon Sep 17 00:00:00 2001
From: MalavikaSamak 
Date: Mon, 11 Nov 2024 17:18:40 -0800
Subject: [PATCH] [-Wunsafe-buffer-usage] Fix false positive in warnging againt
 2-parameter std::span constructor

Do not warn when two parameter constructor receives pointer address from a 
std::addressof method
and the span size is set to 1.

(rdar://139298119)
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp|  8 
 ...buffer-usage-in-container-span-construct.cpp | 17 +
 2 files changed, 25 insertions(+)

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 2c68409b846bc8..507e61564fc3f8 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -410,6 +410,14 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) 
{
   // Check form 3:
   return Arg1CV && Arg1CV->isOne();
 break;
+  case Stmt::CallExprClass:
+if(const auto *CE = dyn_cast(Arg0)) {
+  const auto FnDecl = CE->getDirectCallee();
+  if(FnDecl && FnDecl->getNameAsString() == "addressof" && 
FnDecl->isInStdNamespace()) {
+return Arg1CV && Arg1CV->isOne();
+  }
+}
+break;
   default:
 break;
   }
diff --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp
index c138fe088b3ba9..30b6d4ba9fb904 100644
--- 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp
+++ 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp
@@ -21,6 +21,12 @@ namespace std {
 
   template< class T >
   T&& move( T&& t ) noexcept;
+
+  template 
+  _Tp* addressof(_Tp& __x) {
+return &__x;
+  }
+ 
 }
 
 namespace irrelevant_constructors {
@@ -74,15 +80,26 @@ namespace construct_wt_ptr_size {
 return std::span{p, 10};// expected-warning{{the 
two-parameter std::span construction is unsafe as it can introduce mismatch 
between buffer size and the bound information}}
   }
 
+  // addressof method defined outside std namespace.
+  template 
+  _Tp* addressof(_Tp& __x) {
+return &__x;
+  }
+
   void notWarnSafeCases(unsigned n, int *p) {
 int X;
 unsigned Y = 10;
 std::span S = std::span{&X, 1}; // no-warning
+S = std::span{std::addressof(X), 1}; // no-warning
 int Arr[10];
 typedef int TenInts_t[10];
 TenInts_t Arr2;
 
 S = std::span{&X, 2};// expected-warning{{the 
two-parameter std::span construction is unsafe as it can introduce mismatch 
between buffer size and the bound information}}
+S = std::span{std::addressof(X), 2}; // expected-warning{{the 
two-parameter std::span construction is unsafe as it can introduce mismatch 
between buffer size and the bound information}}
+// Warn when a non std method also named addressof
+S = std::span{addressof(X), 1}; // expected-warning{{the two-parameter 
std::span construction is unsafe as it can introduce mismatch between buffer 
size and the bound information}}
+
 S = std::span{new int[10], 10};  // no-warning
 S = std::span{new int[n], n};// no-warning
 S = std::span{new int, 1};   // no-warning

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


[clang] [webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and [[clang::noescape]]. (PR #114897)

2024-11-11 Thread Ryosuke Niwa via cfe-commits


@@ -45,32 +52,118 @@ class UncountedLambdaCapturesChecker
   bool shouldVisitTemplateInstantiations() const { return true; }
   bool shouldVisitImplicitCode() const { return false; }
 
-  bool VisitLambdaExpr(LambdaExpr *L) {
-Checker->visitLambdaExpr(L);
+  bool TraverseCXXMethodDecl(CXXMethodDecl *CXXMD) {
+llvm::SaveAndRestore SavedDecl(ClsType);
+ClsType = CXXMD->getThisType();
+return Base::TraverseDecl(CXXMD);
+  }
+
+  bool shouldCheckThis() {
+auto result = !ClsType.isNull() ? isUnsafePtr(ClsType) : std::nullopt;
+return result && *result;
+  }
+
+  bool VisitDeclRefExpr(DeclRefExpr *DRE) {
+if (DeclRefExprsToIgnore.contains(DRE))
+  return true;
+auto *VD = dyn_cast_or_null(DRE->getDecl());
+if (!VD)
+  return true;
+auto *Init = VD->getInit();
+if (!Init)
+  return true;
+auto *L = dyn_cast_or_null(Init->IgnoreParenCasts());
+if (!L)
+  return true;
+Checker->visitLambdaExpr(L, shouldCheckThis());
 return true;
   }
+
+  // WTF::switchOn(T, F... f) is a variadic template function and couldn't
+  // be annotated with NOESCAPE. We hard code it here to workaround that.
+  bool shouldTreatAllArgAsNoEscape(FunctionDecl *Decl) {
+auto *NsDecl = Decl->getParent();
+if (!NsDecl || !isa(NsDecl))
+  return false;
+return safeGetName(NsDecl) == "WTF" && safeGetName(Decl) == "switchOn";
+  }
+
+  bool VisitCallExpr(CallExpr *CE) {
+checkCalleeLambda(CE);
+if (auto *Callee = CE->getDirectCallee()) {
+  bool TreatAllArgsAsNoEscape = shouldTreatAllArgAsNoEscape(Callee);
+  unsigned ArgIndex = 0;
+  for (auto *Param : Callee->parameters()) {
+if (ArgIndex >= CE->getNumArgs())
+  break;

rniwa wrote:

Sure, we can do that.

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


[clang] [webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and [[clang::noescape]]. (PR #114897)

2024-11-11 Thread Ryosuke Niwa via cfe-commits


@@ -89,7 +182,25 @@ class UncountedLambdaCapturesChecker
 }
 
 printQuotedQualifiedName(Os, Capture.getCapturedVar());
-Os << " to uncounted type is unsafe.";
+Os << " to ref-counted / CheckedPtr capable type is unsafe.";
+
+PathDiagnosticLocation BSLoc(Capture.getLocation(), 
BR->getSourceManager());
+auto Report = std::make_unique(Bug, Os.str(), BSLoc);
+BR->emitReport(std::move(Report));
+  }
+
+  void reportBugOnThisPtr(const LambdaCapture &Capture) const {
+SmallString<100> Buf;
+llvm::raw_svector_ostream Os(Buf);
+
+if (Capture.isExplicit()) {
+  Os << "Captured ";
+} else {
+  Os << "Implicitly captured ";
+}
+
+Os << "raw-pointer 'this' to ref-counted / CheckedPtr capable type is "

rniwa wrote:

Rephrased to say "ref-counted type or CheckedPtr-capable type"

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


[clang] [Clang][Driver] Ensure clang can construct toolchain target names (PR #115798)

2024-11-11 Thread Matthew Mirvish via cfe-commits

https://github.com/mincrmatt12 created 
https://github.com/llvm/llvm-project/pull/115798

This adds an extra validation step to 
`ToolChain::getTargetAndModeFromProgramName` to actually try constructing the 
target info for the triple it deduces, instead of just relying on the LLVM 
target registry.

Some targets, like `xtensa`, are supported by LLVM but are not supported by 
clang, so just checking the LLVM registry causes inconsistency.

This is based on the discussion from clangd/clangd#2184 (and indeed would solve 
that issue) - the approach here of "construct the target info and check for 
null" is taken from 
[clangd](https://github.com/llvm/llvm-project/blob/5716f836d25e93bf8f664a14fe55c70e07a369be/clang-tools-extra/clangd/SystemIncludeExtractor.cpp#L253).

>From f111040a50db8275b1d6aaee3cf5e4b8af2b08f5 Mon Sep 17 00:00:00 2001
From: Matthew Mirvish 
Date: Mon, 11 Nov 2024 20:20:20 -0500
Subject: [PATCH] [Clang][Driver] Ensure clang can construct toolchain target
 names

This adds an extra validation step to
`ToolChain::getTargetAndModeFromProgramName` to actually try
constructing the target info for the triple it deduces, instead of just
relying on the LLVM target registry.

Some targets, like `xtensa`, are supported by LLVM but are not supported
by clang, so just checking the LLVM registry causes inconsistency.
---
 clang/lib/Driver/ToolChain.cpp | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 646dbc0faf5a9f..e094a5fd0267f3 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -16,6 +16,8 @@
 #include "ToolChains/InterfaceStubs.h"
 #include "clang/Basic/ObjCRuntime.h"
 #include "clang/Basic/Sanitizers.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/Action.h"
 #include "clang/Driver/Driver.h"
@@ -496,8 +498,21 @@ ToolChain::getTargetAndModeFromProgramName(StringRef PN) {
   StringRef Prefix(ProgName);
   Prefix = Prefix.slice(0, LastComponent);
   std::string IgnoredError;
+
+  // First, check if the target is a supported LLVM target.
   bool IsRegistered =
   llvm::TargetRegistry::lookupTarget(std::string(Prefix), IgnoredError);
+  // If so, further check that clang is able to use it as a target.
+  if (IsRegistered) {
+std::shared_ptr TargetOpts(new TargetOptions);
+TargetOpts->Triple = Prefix.str();
+DiagnosticsEngine Diags(new DiagnosticIDs, new DiagnosticOptions,
+new IgnoringDiagConsumer);
+llvm::IntrusiveRefCntPtr Target =
+clang::TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+if (!Target)
+  IsRegistered = false;
+  }
   return ParsedClangName{std::string(Prefix), ModeSuffix, DS->ModeFlag,
  IsRegistered};
 }

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


[clang] [-Wunsafe-buffer-usage] Fix false positives in warning againt 2-parameter std::span constructor (PR #115797)

2024-11-11 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 b816c2628919de9a978132347f039ad23794837d 
a60c18973c0ea5b59c7c5f38813083e862f70e6e --extensions cpp -- 
clang/lib/Analysis/UnsafeBufferUsage.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 507e61564f..ae6863fb7c 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -411,9 +411,10 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) 
{
   return Arg1CV && Arg1CV->isOne();
 break;
   case Stmt::CallExprClass:
-if(const auto *CE = dyn_cast(Arg0)) {
+if (const auto *CE = dyn_cast(Arg0)) {
   const auto FnDecl = CE->getDirectCallee();
-  if(FnDecl && FnDecl->getNameAsString() == "addressof" && 
FnDecl->isInStdNamespace()) {
+  if (FnDecl && FnDecl->getNameAsString() == "addressof" &&
+  FnDecl->isInStdNamespace()) {
 return Arg1CV && Arg1CV->isOne();
   }
 }

``




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


[clang] [Clang][Driver] Ensure clang can construct toolchain target names (PR #115798)

2024-11-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Matthew Mirvish (mincrmatt12)


Changes

This adds an extra validation step to 
`ToolChain::getTargetAndModeFromProgramName` to actually try constructing the 
target info for the triple it deduces, instead of just relying on the LLVM 
target registry.

Some targets, like `xtensa`, are supported by LLVM but are not supported by 
clang, so just checking the LLVM registry causes inconsistency.

This is based on the discussion from clangd/clangd#2184 (and indeed 
would solve that issue) - the approach here of "construct the target info and 
check for null" is taken from 
[clangd](https://github.com/llvm/llvm-project/blob/5716f836d25e93bf8f664a14fe55c70e07a369be/clang-tools-extra/clangd/SystemIncludeExtractor.cpp#L253).

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


1 Files Affected:

- (modified) clang/lib/Driver/ToolChain.cpp (+15) 


``diff
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 646dbc0faf5a9f..e094a5fd0267f3 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -16,6 +16,8 @@
 #include "ToolChains/InterfaceStubs.h"
 #include "clang/Basic/ObjCRuntime.h"
 #include "clang/Basic/Sanitizers.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/Action.h"
 #include "clang/Driver/Driver.h"
@@ -496,8 +498,21 @@ ToolChain::getTargetAndModeFromProgramName(StringRef PN) {
   StringRef Prefix(ProgName);
   Prefix = Prefix.slice(0, LastComponent);
   std::string IgnoredError;
+
+  // First, check if the target is a supported LLVM target.
   bool IsRegistered =
   llvm::TargetRegistry::lookupTarget(std::string(Prefix), IgnoredError);
+  // If so, further check that clang is able to use it as a target.
+  if (IsRegistered) {
+std::shared_ptr TargetOpts(new TargetOptions);
+TargetOpts->Triple = Prefix.str();
+DiagnosticsEngine Diags(new DiagnosticIDs, new DiagnosticOptions,
+new IgnoringDiagConsumer);
+llvm::IntrusiveRefCntPtr Target =
+clang::TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+if (!Target)
+  IsRegistered = false;
+  }
   return ParsedClangName{std::string(Prefix), ModeSuffix, DS->ModeFlag,
  IsRegistered};
 }

``




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


[clang] [Clang] Fix dependent expression handling for assumptions (PR #115646)

2024-11-11 Thread Younan Zhang via cfe-commits

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-11 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/111499

>From a0f866bd9072a7334a3209a5dc668b39154093c1 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Sun, 10 Nov 2024 07:42:49 +
Subject: [PATCH] Introduce [[clang::lifetime_capture_by]]

---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Basic/Attr.td |  33 ++
 clang/include/clang/Basic/AttrDocs.td |  74 +
 .../clang/Basic/DiagnosticSemaKinds.td|  12 ++
 clang/include/clang/Sema/Sema.h   |   8 ++
 clang/lib/AST/TypePrinter.cpp |  15 +++
 clang/lib/Sema/SemaDecl.cpp   |   1 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 103 ++
 clang/lib/Sema/SemaType.cpp   |  13 +++
 clang/test/AST/attr-lifetime-capture-by.cpp   |   9 ++
 .../test/SemaCXX/attr-lifetime-capture-by.cpp |  42 +++
 11 files changed, 313 insertions(+)
 create mode 100644 clang/test/AST/attr-lifetime-capture-by.cpp
 create mode 100644 clang/test/SemaCXX/attr-lifetime-capture-by.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c3424e0e6f34c9c..93cce21156634d5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -449,6 +449,9 @@ Attribute Changes in Clang
 - Fix a bug where clang doesn't automatically apply the ``[[gsl::Owner]]`` or
   ``[[gsl::Pointer]]`` to STL explicit template specialization decls. 
(#GH109442)
 
+- Clang now supports ``[[clang::lifetime_capture_by(X)]]``. Similar to 
lifetimebound, this can be
+  used to specify when a reference to a function parameter is captured by 
another capturing entity ``X``.
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index a631e81d40aa686..6a77967c32cbcba 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1889,6 +1889,39 @@ def LifetimeBound : DeclOrTypeAttr {
   let SimpleHandler = 1;
 }
 
+def LifetimeCaptureBy : DeclOrTypeAttr {
+  let Spellings = [Clang<"lifetime_capture_by", 0>];
+  let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
+  let Args = [VariadicParamOrParamIdxArgument<"Params">];
+  let Documentation = [LifetimeCaptureByDocs];
+  let AdditionalMembers = [{
+private:
+  SmallVector ArgIdents;
+  SmallVector ArgLocs;
+
+public:
+  static constexpr int THIS = 0;
+  static constexpr int INVALID = -1;
+  static constexpr int UNKNOWN = -2;
+  static constexpr int GLOBAL = -3;
+
+  void setArgs(SmallVector&& Idents,
+   SmallVector&& Locs) { 
+assert(Idents.size() == Locs.size());
+assert(Idents.size() == params_Size);
+ArgIdents = std::move(Idents);
+ArgLocs = std::move(Locs);
+  }
+  
+  ArrayRef getArgIdents() const { return ArgIdents; }
+  ArrayRef getArgLocs() const { return ArgLocs; }
+  void setParamIdx(size_t Idx, int Val) { 
+assert(Idx < params_Size);
+params_[Idx] = Val;
+  }
+}];
+}
+
 def TrivialABI : InheritableAttr {
   // This attribute does not have a C [[]] spelling because it requires the
   // CPlusPlus language option.
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b64dbef6332e6a8..87f6591f0b4c666 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3967,6 +3967,80 @@ Attribute ``trivial_abi`` has no effect in the following 
cases:
   }];
 }
 
+
+def LifetimeCaptureByDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Similar to `lifetimebound`_, the ``lifetime_capture_by(X)`` attribute on a 
function
+parameter or implicit object parameter indicates that that objects that are 
referred to
+by that parameter may also be referred to by the capturing entity ``X``.
+
+The ``lifetimebound`` attribute on a function parameter or implicit object
+parameter indicates that objects that are referred to by that parameter may
+also be referred to by the return value of the annotated function (or, for a
+parameter of a constructor, by the value of the constructed object).
+
+By default, a reference is considered to refer to its referenced object, a
+pointer is considered to refer to its pointee, a ``std::initializer_list``
+is considered to refer to its underlying array, and aggregates (arrays and
+simple ``struct``\s) are considered to refer to all objects that their
+transitive subobjects refer to.
+
+The capturing entity ``X`` can be one of the following:
+- Another (named) function parameter. 
+  
+  .. code-block:: c++
+
+void addToSet(std::string_view a [[clang::lifetime_capture_by(s)]], 
std::set& s) {
+  s.insert(a);
+}
+
+- ``this`` (in case of member functions).
+  
+  .. code-block:: c++
+
+class S {
+  void addToSet(std::string_view a [[clang::lifetime_capture_by(this)]]) {
+s.insert(a);
+  }
+  std:

[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-11 Thread Haojian Wu via cfe-commits


@@ -3967,6 +3967,69 @@ Attribute ``trivial_abi`` has no effect in the following 
cases:
   }];
 }
 
+
+def LifetimeCaptureByDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``lifetime_capture_by(X)`` attribute on a function parameter or 
implicit object
+parameter indicates that references to arguments passed to such parameters may 
be
+captured by the capturing entity ``X``.
+
+The capturing entity ``X`` can be one of the following:
+- Another (named) function parameter. 
+  
+  .. code-block:: c++
+
+void addToSet(std::string_view a [[clang::lifetime_capture_by(s)]], 
std::set& s) {
+  s.insert(a);
+}
+
+- ``this`` (in case of member functions).
+  
+  .. code-block:: c++
+
+class S {
+  void addToSet(std::string_view a [[clang::lifetime_capture_by(this)]]) {
+s.insert(a);
+  }
+  std::set s;
+};
+
+- 'global', 'unknown' (without quotes).
+  
+  .. code-block:: c++
+
+std::set s;
+void addToSet(std::string_view a [[clang::lifetime_capture_by(global)]]) {

hokein wrote:

I think it is an ambiguous case, we could emit a diagnostic.

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


[clang] [clang] Set FPOptions at the beginning of CompoundStmt (PR #111654)

2024-11-11 Thread Serge Pavlov via cfe-commits

https://github.com/spavloff updated 
https://github.com/llvm/llvm-project/pull/111654

>From a47216330a0e14025ba2c29a884d6a96d472dd73 Mon Sep 17 00:00:00 2001
From: Serge Pavlov 
Date: Wed, 9 Oct 2024 12:55:22 +0700
Subject: [PATCH 1/2] [clang] Set FPOptions at the beginning of CompoundStmt

CompoundStmt has FPOptions, that should be set for IRBuilder when
generating code if that statement.

It must fix the issue #84648.
---
 clang/include/clang/AST/Stmt.h |  9 +
 clang/lib/CodeGen/CGStmt.cpp   |  5 +
 clang/test/CodeGen/fast-math.c | 18 +-
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 83fafbabb1d460..805148bce4aff1 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1684,6 +1684,15 @@ class CompoundStmt final
 return hasStoredFPFeatures() ? getStoredFPFeatures() : FPOptionsOverride();
   }
 
+  /// Get FPOptions inside this statement. They may differ from the outer
+  /// options due to pragmas.
+  /// \param CurFPOptions FPOptions outside this statement.
+  FPOptions getInsideFPOptions(FPOptions CurFPOptions) const {
+return hasStoredFPFeatures()
+   ? getStoredFPFeatures().applyOverrides(CurFPOptions)
+   : CurFPOptions;
+  }
+
   using body_iterator = Stmt **;
   using body_range = llvm::iterator_range;
 
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 41dc91c578c800..da9bf76a54f963 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -522,6 +522,11 @@ CodeGenFunction::EmitCompoundStmtWithoutScope(const 
CompoundStmt &S,
   assert((!GetLast || (GetLast && ExprResult)) &&
  "If GetLast is true then the CompoundStmt must have a 
StmtExprResult");
 
+  // Optionally set up the new FP environment, if the compound statement
+  // contains a pragma that modifies it.
+  FPOptions NewFP = S.getInsideFPOptions(CurFPFeatures);
+  CGFPOptionsRAII SavedFPFeatues(*this, NewFP);
+
   Address RetAlloca = Address::invalid();
 
   for (auto *CurStmt : S.body()) {
diff --git a/clang/test/CodeGen/fast-math.c b/clang/test/CodeGen/fast-math.c
index 6ebd65a22c92be..048a5aeb9649ba 100644
--- a/clang/test/CodeGen/fast-math.c
+++ b/clang/test/CodeGen/fast-math.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -ffast-math -ffp-contract=fast -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -ffast-math -ffp-contract=fast -emit-llvm -O2 -o - %s | 
FileCheck %s
 float f0, f1, f2;
 
 void foo(void) {
@@ -9,3 +9,19 @@ void foo(void) {
 
   // CHECK: ret
 }
+
+float issue_84648a(float *x) {
+  return x[0] == x[1] ? x[1] : x[0];
+}
+
+// CHECK-LABEL: define{{.*}} float @issue_84648a(ptr {{.*}})
+// CHECK:   [[VAL:%.+]] = load float, ptr
+// CHECK:   ret float [[VAL]]
+
+float issue_84648b(float *x) {
+#pragma float_control(precise, on)
+  return x[0] == x[1] ? x[1] : x[0];
+}
+
+// CHECK-LABEL: define{{.*}} float @issue_84648b(ptr{{.*}} %x)
+// CHECK:   fcmp oeq

>From 63ccc1758ba9d01813ff2b129e533a15926db32e Mon Sep 17 00:00:00 2001
From: Serge Pavlov 
Date: Mon, 11 Nov 2024 21:28:57 +0700
Subject: [PATCH 2/2] Rename getInsideFPOptions to getActiveFPOptions

---
 clang/include/clang/AST/Stmt.h | 4 ++--
 clang/lib/CodeGen/CGStmt.cpp   | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 805148bce4aff1..eb423cc3469d1a 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1684,10 +1684,10 @@ class CompoundStmt final
 return hasStoredFPFeatures() ? getStoredFPFeatures() : FPOptionsOverride();
   }
 
-  /// Get FPOptions inside this statement. They may differ from the outer
+  /// Get FPOptions active inside this statement. They may differ from the 
outer
   /// options due to pragmas.
   /// \param CurFPOptions FPOptions outside this statement.
-  FPOptions getInsideFPOptions(FPOptions CurFPOptions) const {
+  FPOptions getActiveFPOptions(FPOptions CurFPOptions) const {
 return hasStoredFPFeatures()
? getStoredFPFeatures().applyOverrides(CurFPOptions)
: CurFPOptions;
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index da9bf76a54f963..d5ee66f2946458 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -524,7 +524,7 @@ CodeGenFunction::EmitCompoundStmtWithoutScope(const 
CompoundStmt &S,
 
   // Optionally set up the new FP environment, if the compound statement
   // contains a pragma that modifies it.
-  FPOptions NewFP = S.getInsideFPOptions(CurFPFeatures);
+  FPOptions NewFP = S.getActiveFPOptions(CurFPFeatures);
   CGFPOptionsRAII SavedFPFeatues(*this, NewFP);
 
   Address RetAlloca = Address::invalid();

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


  1   2   3   4   >