[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-06 Thread Charalampos Mitrodimas via cfe-commits

https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From 83d29e896b7ae0b5b259cbf179143e526dc37b1c Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

Warning '-Wundefined-func-template' incorrectly indicates that no
definition is available for a pure virtual function. However, a
definition is not needed for a pure virtual function.

Fixes #74016

Signed-off-by: Charalampos Mitrodimas 
---
 clang/docs/ReleaseNotes.rst   |  3 ++
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  3 +-
 .../instantiate-pure-virtual-function.cpp | 48 +++
 3 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 828dd10e3d6db..10dce199b9fd1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -514,6 +514,9 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+- Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
+  functions.
+  (`#74016 `_)
 - Fixed an issue where a class template specialization whose declaration is
   instantiated in one module and whose definition is instantiated in another
   module may end up with members associated with the wrong declaration of the
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index d768bb72e07c0..a034de0697b2b 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4952,7 +4952,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 std::make_pair(Function, PointOfInstantiation));
 } else if (TSK == TSK_ImplicitInstantiation) {
   if (AtEndOfTU && !getDiagnostics().hasErrorOccurred() &&
-  !getSourceManager().isInSystemHeader(PatternDecl->getBeginLoc())) {
+  !getSourceManager().isInSystemHeader(PatternDecl->getBeginLoc()) &&
+  !Function->isPure()) {
 Diag(PointOfInstantiation, diag::warn_func_template_missing)
   << Function;
 Diag(PatternDecl->getLocation(), diag::note_forward_template_decl);
diff --git a/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp 
b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
new file mode 100644
index 0..d188adc9ed034
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+
+namespace GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};
+
+namespace non_pure_virtual_function {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+
+virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
+// expected-note@-1 {{forward declaration of template entity is here}}
+// expected-note@-2 {{forward declaration of template entity is here}}
+// expected-note@-3 {{forward declaration of template entity is here}}
+  };
+
+  template  class D : public B { // expected-warning 
{{instantiation of function 'non_pure_virtual_function::B::bar' required 
here, but no definition is available}}
+// expected-warning@-1 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-warning@-2 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-note@-3 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-4 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-5 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-6 {{used here}}
+
+  public:
+constexpr void bar(unsigned int) override { }
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};

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


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-06 Thread Charalampos Mitrodimas via cfe-commits

charmitro wrote:

> Perhaps needs a release note.

> Can you add a release note indicating #74016 was fixed? Otherwise LGTM.

Release note added.

> If you wanted to make a follow up {R to rename `isPure` to `isPureVirtual`, i 
> think that might be helpful (to avoid confusion with the `gnu::pure` 
> attribute)

Yes, this could be helpful. I'll create a follow up PR for this.


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


[flang] [clang] [flang][driver] Rename `flang-new` as `flang` (PR #74377)

2023-12-06 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

Clang PRs often update the release notes and features.

ala: The LLVM 19 release will not contain flang-new.

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


[clang] [Driver] Add riscv64-suse-linux triple (PR #74513)

2023-12-06 Thread Andreas Schwab via cfe-commits

andreas-schwab wrote:

This breaks valid use cases.

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


[clang] [Sema] Warning for _Float16 passed to format specifier '%f' (PR #74439)

2023-12-06 Thread Haocong Lu via cfe-commits

https://github.com/Luhaocong updated 
https://github.com/llvm/llvm-project/pull/74439

>From 47ec17023ebc75a61951930b77e08bb2f726775b Mon Sep 17 00:00:00 2001
From: Lu Haocong 
Date: Tue, 5 Dec 2023 16:45:22 +0800
Subject: [PATCH] [Sema] Warning for _Float16 passed to format specifier '%f'

According to https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2844.pdf,
default argument promotions for _FloatN types has been removed.

A warning is needed to notice user to promote _Float16 to double
explicitly, and then pass it to format specifier '%f', which is
consistent with GCC.
---
 clang/lib/AST/FormatString.cpp  |  1 -
 clang/test/AST/variadic-promotion.c |  5 +
 clang/test/Sema/attr-format.c   |  7 +++
 clang/test/SemaCXX/attr-format.cpp  |  1 +
 clang/test/SemaCXX/format-strings-scanf.cpp | 16 ++--
 5 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index e0c9e18cfe3a2..c5d14b4af7ff1 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -488,7 +488,6 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return NoMatchPromotionTypeConfusion;
   break;
 case BuiltinType::Half:
-case BuiltinType::Float16:
 case BuiltinType::Float:
   if (T == C.DoubleTy)
 return MatchPromotion;
diff --git a/clang/test/AST/variadic-promotion.c 
b/clang/test/AST/variadic-promotion.c
index 41c7fec8d7943..7cbadb832ca80 100644
--- a/clang/test/AST/variadic-promotion.c
+++ b/clang/test/AST/variadic-promotion.c
@@ -18,3 +18,8 @@ void test_floating_promotion(__fp16 *f16, float f32, double 
f64) {
 // CHECK: ImplicitCastExpr {{.*}} 'double' 
 // CHECK-NEXT: 'float'
 }
+
+void test_Float16_no_default_promotion(_Float16 f16) {
+  variadic(1, f16);
+// CHECK-NOT: ImplicitCastExpr {{.*}} 'double' 
+}
diff --git a/clang/test/Sema/attr-format.c b/clang/test/Sema/attr-format.c
index 1f4c864d4f78b..bdfd8425c4e9a 100644
--- a/clang/test/Sema/attr-format.c
+++ b/clang/test/Sema/attr-format.c
@@ -16,6 +16,8 @@ typedef const char *xpto;
 void j(xpto c, va_list list) __attribute__((format(printf, 1, 0))); // no-error
 void k(xpto c) __attribute__((format(printf, 1, 0)));   // no-error
 
+void l(char *a, _Float16 b) __attribute__((format(printf, 1, 2))); // 
expected-warning {{GCC requires a function with the 'format' attribute to be 
variadic}}
+
 void y(char *str) __attribute__((format(strftime, 1, 0))); // 
no-error
 void z(char *str, int c, ...) __attribute__((format(strftime, 1, 2))); // 
expected-error {{strftime format attribute requires 3rd parameter to be 0}}
 
@@ -93,6 +95,11 @@ void call_nonvariadic(void) {
   d3("%s", 123); // expected-warning{{format specifies type 'char *' but the 
argument has type 'int'}}
 }
 
+void call_no_default_promotion(void) {
+  a("%f", (_Float16)1.0); // expected-warning{{format specifies type 'double' 
but the argument has type '_Float16'}}
+  l("%f", (_Float16)1.0); // expected-warning{{format specifies type 'double' 
but the argument has type '_Float16'}}
+}
+
 __attribute__((format(printf, 1, 2)))
 void forward_fixed(const char *fmt, _Bool b, char i, short j, int k, float l, 
double m) { // expected-warning{{GCC requires a function with the 'format' 
attribute to be variadic}}
   forward_fixed(fmt, b, i, j, k, l, m);
diff --git a/clang/test/SemaCXX/attr-format.cpp 
b/clang/test/SemaCXX/attr-format.cpp
index adc05fc46776c..4509c3a95e8ef 100644
--- a/clang/test/SemaCXX/attr-format.cpp
+++ b/clang/test/SemaCXX/attr-format.cpp
@@ -81,6 +81,7 @@ void do_format() {
 
   format("%c %c %hhd %hd %d\n", (char)'a', 'a', 'a', (short)123, (int)123);
   format("%f %f %f\n", (__fp16)123.f, 123.f, 123.);
+  format("%f", (_Float16)123.f);// expected-warning{{format specifies type 
'double' but the argument has type '_Float16'}}
   format("%Lf", (__fp16)123.f); // expected-warning{{format specifies type 
'long double' but the argument has type '__fp16'}}
   format("%Lf", 123.f); // expected-warning{{format specifies type 'long 
double' but the argument has type 'float'}}
   format("%hhi %hhu %hi %hu %i %u", b, b, b, b, b, b);
diff --git a/clang/test/SemaCXX/format-strings-scanf.cpp 
b/clang/test/SemaCXX/format-strings-scanf.cpp
index 25fe5346791a0..406c2069e28ca 100644
--- a/clang/test/SemaCXX/format-strings-scanf.cpp
+++ b/clang/test/SemaCXX/format-strings-scanf.cpp
@@ -22,6 +22,7 @@ union bag {
 unsigned long long ull;
 signed long long sll;
 __fp16 f16;
+_Float16 Float16;
 float ff;
 double fd;
 long double fl;
@@ -51,18 +52,21 @@ void test(void) {
 // expected-warning@+1{{format specifies type 'int *' but the argument has 
type 'short *'}}
 scan("%hhi %i %li", &b.ss, &b.ss, &b.ss);
 
-// expected-warning@+3{{format specifies type 'float *' but the argument 
has type '__fp16 *'}}
+// expe

[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-06 Thread via cfe-commits

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

LGTM, thanks

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


[clang] [clang] Add separate C++23 extension flag for attrs on lambda (PR #74553)

2023-12-06 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov commented:

This is useful to us to have attributes on lambdas early in C++20 mode before 
switching to C++23. I only have a nitpick about naming and happy to approve 
after its addressed.

And let's give @AaronBallman a few days to jump in.

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


[clang] [clang] Add separate C++23 extension flag for attrs on lambda (PR #74553)

2023-12-06 Thread Ilya Biryukov via cfe-commits

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


[clang] [clang] Add separate C++23 extension flag for attrs on lambda (PR #74553)

2023-12-06 Thread Ilya Biryukov via cfe-commits


@@ -1126,6 +1126,8 @@ def FutureAttrs : 
DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
 CXX20Attrs]>;
 
+def CXX23AttrsOnLambda : DiagGroup<"c++23-attrs-on-lambda">;

ilya-biryukov wrote:

Other warning flags spell `attribute` as a full word, I suggest we do the same 
here.\
Something like `c++23-lambda-attributes` looks like a good option.




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


[clang] [clang] Add separate C++23 extension flag for attrs on lambda (PR #74553)

2023-12-06 Thread Ilya Biryukov via cfe-commits

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


[llvm] [clang] [AArch64] Add soft-float ABI (PR #74460)

2023-12-06 Thread via cfe-commits

https://github.com/ostannard updated 
https://github.com/llvm/llvm-project/pull/74460

>From 316854b6558811aaa03b9f96be1849e0426f8aac Mon Sep 17 00:00:00 2001
From: Oliver Stannard 
Date: Fri, 1 Dec 2023 10:06:57 +
Subject: [PATCH 1/6] [AArch64] Split feature tests for FP and SIMD

AArch64TargetInfo defaults to having the FP feature enabled, but this
function was ignoring that and checking for SIMD instructions instead.

This won't affect most users, because the driver explicitly enables or
disables fp-armv8, which gets handled by
AArch64TargetInfo::handleTargetFeatures to turn FP and SIMD on or off.
However, it will make testing future patches easier, and allow testing
for the presense of FP registers/instructions in CC1 tests.

Change-Id: I2d2b3569dca5fa1dc40c5c6d1dabf7741b8c480e
---
 clang/lib/Basic/Targets/AArch64.cpp   |   3 +-
 .../test/CodeGen/attr-target-clones-aarch64.c | 126 +++---
 2 files changed, 107 insertions(+), 22 deletions(-)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c31f2e0bee543..23090dad83ad7 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -649,7 +649,8 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const 
{
   return llvm::StringSwitch(Feature)
   .Cases("aarch64", "arm64", "arm", true)
   .Case("fmv", HasFMV)
-  .Cases("neon", "fp", "simd", FPU & NeonMode)
+  .Case("fp", FPU & FPUMode)
+  .Cases("neon", "simd", FPU & NeonMode)
   .Case("jscvt", HasJSCVT)
   .Case("fcma", HasFCMA)
   .Case("rng", HasRandGen)
diff --git a/clang/test/CodeGen/attr-target-clones-aarch64.c 
b/clang/test/CodeGen/attr-target-clones-aarch64.c
index 3f2f2fdd24e8a..4404dd0da8e5e 100644
--- a/clang/test/CodeGen/attr-target-clones-aarch64.c
+++ b/clang/test/CodeGen/attr-target-clones-aarch64.c
@@ -1,6 +1,6 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-attributes --check-globals --include-generated-funcs
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -emit-llvm -o - %s | 
FileCheck %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature -fmv -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-NOFMV
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature -fp-armv8 -S 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature -fp-armv8 
-target-feature -fmv -S -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK-NOFMV
 
 int __attribute__((target_clones("lse+aes", "sve2"))) ftc(void) { return 0; }
 int __attribute__((target_clones("sha2", "sha2+memtag2", " default "))) 
ftc_def(void) { return 1; }
@@ -22,6 +22,8 @@ int __attribute__((target_clones("default"))) main() {
 inline int __attribute__((target_clones("fp16", "sve2-bitperm+fcma", 
"default"))) ftc_inline2(void) { return 2; };
 
 
+
+//.
 // CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
 // CHECK: @ftc.ifunc = weak_odr ifunc i32 (), ptr @ftc.resolver
 // CHECK: @ftc_def.ifunc = weak_odr ifunc i32 (), ptr @ftc_def.resolver
@@ -30,19 +32,25 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 // CHECK: @ftc_inline1.ifunc = weak_odr ifunc i32 (), ptr @ftc_inline1.resolver
 // CHECK: @ftc_inline2.ifunc = weak_odr ifunc i32 (), ptr @ftc_inline2.resolver
 // CHECK: @ftc_inline3.ifunc = weak_odr ifunc i32 (), ptr @ftc_inline3.resolver
-
+//.
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: @ftc._MlseMaes(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 0
+//
+//
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: @ftc._Msve2(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 0
+//
+//
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: @ftc(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 0
+//
+//
 // CHECK-LABEL: @ftc.resolver(
 // CHECK-NEXT:  resolver_entry:
 // CHECK-NEXT:call void @__init_cpu_features_resolver()
@@ -63,18 +71,26 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 // CHECK-NEXT:ret ptr @ftc._Msve2
 // CHECK:   resolver_else2:
 // CHECK-NEXT:ret ptr @ftc
+//
+//
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: @ftc_def._Msha2(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 1
+//
+//
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: @ftc_def._Msha2Mmemtag2(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 1
+//
+//
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: @ftc_def(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 1
+//
+//
 // CHECK-LABEL: @ftc_def.resolver(
 // CHECK-NEXT:  resolver_entry:
 // CHECK-NEXT:call void @__init_cpu_features_resolver()
@@ -95,14 +111,20 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 // CHECK-NEXT:ret ptr @ftc_def._Msha2
 // CHECK:   

[libcxx] [clang] [compiler-rt] [llvm] [flang] [libc] [clang-tools-extra] [mlir] [mlir][gpu] Support dynamic_shared_memory Op with vector dialect (PR #74475)

2023-12-06 Thread Guray Ozen via cfe-commits

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


[llvm] [clang] [AArch64] Add soft-float ABI (PR #74460)

2023-12-06 Thread via cfe-commits


@@ -534,7 +540,8 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(Address VAListAddr, 
QualType Ty,
 BaseTy = ArrTy->getElementType();
 NumRegs = ArrTy->getNumElements();
   }
-  bool IsFPR = BaseTy->isFloatingPointTy() || BaseTy->isVectorTy();
+  bool IsFPR = Kind == AArch64ABIKind::AAPCS &&

ostannard wrote:

Done

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


[llvm] [clang] [AArch64] Add soft-float ABI (PR #74460)

2023-12-06 Thread via cfe-commits

ostannard wrote:

> I'm a little surprised we don't need any LLVM backend changes, but I guess in 
> soft-float mode we basically treat floats as ints anyway, so maybe things 
> just work. I'd like to see appropriate regression tests, though (if they 
> don't already exist).

Yes, the backend already treated floats as if they were an integer of the same 
width, so no changes are needed there. I've added a test for the backend.

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


[clang] [clang] Add separate C++23 extension flag for attrs on lambda (PR #74553)

2023-12-06 Thread Utkarsh Saxena via cfe-commits

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

>From 9be87da42e48895cf23d90a3ed735b7a36b1ccb3 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 6 Dec 2023 04:51:45 +0100
Subject: [PATCH 1/3] [clang] Add separate C++23 extension flag for attrs on
 lambda

---
 clang/include/clang/Basic/DiagnosticGroups.td   |  4 +++-
 clang/include/clang/Basic/DiagnosticParseKinds.td   |  2 +-
 clang/test/SemaCXX/coro-lifetimebound.cpp   | 10 ++
 clang/test/SemaCXX/coro-return-type-and-wrapper.cpp |  9 ++---
 4 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index ff028bbbf7426..81443fb16a1f3 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1126,6 +1126,8 @@ def FutureAttrs : 
DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
 CXX20Attrs]>;
 
+def CXX23AttrsOnLambda : DiagGroup<"c++23-attrs-on-lambda">;
+
 // A warning group for warnings about using C++11 features as extensions in
 // earlier C++ versions.
 def CXX11 : DiagGroup<"c++11-extensions", [CXX11ExtraSemi, 
CXX11InlineNamespace,
@@ -1145,7 +1147,7 @@ def CXX20 : DiagGroup<"c++20-extensions", 
[CXX20Designator, CXX20Attrs]>;
 
 // A warning group for warnings about using C++23 features as extensions in
 // earlier C++ versions.
-def CXX23 : DiagGroup<"c++23-extensions">;
+def CXX23 : DiagGroup<"c++23-extensions", [CXX23AttrsOnLambda]>;
 
 // A warning group for warnings about using C++26 features as extensions in
 // earlier C++ versions.
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 21fe6066d5876..bc7bd7589ef14 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1035,7 +1035,7 @@ def err_capture_default_first : Error<
   "capture default must be first">;
 def ext_decl_attrs_on_lambda : ExtWarn<
   "%select{an attribute specifier sequence|%0}1 in this position "
-  "is a C++23 extension">, InGroup;
+  "is a C++23 extension">, InGroup;
 def ext_lambda_missing_parens : ExtWarn<
   "lambda without a parameter clause is a C++23 extension">,
   InGroup;
diff --git a/clang/test/SemaCXX/coro-lifetimebound.cpp 
b/clang/test/SemaCXX/coro-lifetimebound.cpp
index d3e2d673ebb3c..ec8997036feb4 100644
--- a/clang/test/SemaCXX/coro-lifetimebound.cpp
+++ b/clang/test/SemaCXX/coro-lifetimebound.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused 
-Wno-c++23-attrs-on-lambda
 
 #include "Inputs/std-coroutine.h"
 
@@ -64,14 +64,8 @@ Co bar_coro(const int &b, int c) {
   : bar_coro(0, 1); // expected-warning {{returning address of local 
temporary object}}
 }
 
-#define CORO_WRAPPER \
-  _Pragma("clang diagnostic push") \
-  _Pragma("clang diagnostic ignored \"-Wc++23-extensions\"") \
-  [[clang::coro_wrapper]] \
-  _Pragma("clang diagnostic pop")
-
 void lambdas() {
-  auto unsafe_lambda = [] CORO_WRAPPER (int b) {
+  auto unsafe_lambda = [] [[clang::coro_wrapper]] (int b) {
 return foo_coro(b); // expected-warning {{address of stack memory 
associated with parameter}}
   };
   auto coro_lambda = [] (const int&) -> Co {
diff --git a/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp 
b/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp
index 5f8076f1c782a..d52d1e4cea399 100644
--- a/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp
+++ b/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-c++23-attrs-on-lambda
 #include "Inputs/std-coroutine.h"
 
 using std::suspend_always;
@@ -45,11 +45,6 @@ Co non_marked_wrapper(int b) { return foo_coro(b); }
 } // namespace using_decl
 
 namespace lambdas {
-#define CORO_WRAPPER \
-  _Pragma("clang diagnostic push") \
-  _Pragma("clang diagnostic ignored \"-Wc++23-extensions\"") \
-  [[clang::coro_wrapper]] \
-  _Pragma("clang diagnostic pop")
 
 void foo() {
   auto coro_lambda = []() -> Gen {
@@ -59,7 +54,7 @@ void foo() {
   auto not_allowed_wrapper = []() -> Gen {
 return foo_coro(1);
   };
-  auto allowed_wrapper = [] CORO_WRAPPER() -> Gen {
+  auto allowed_wrapper = [] [[clang::coro_wrapper]] () -> Gen {
 return foo_coro(1);
   };
 }

>From 14532988c00fc0ce6530a05a899abbc3976bd374 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 6 Dec 202

[clang] 6704d6a - [SME2] Add LUTI2 and LUTI4 quad Builtins and Intrinsics (#73317)

2023-12-06 Thread via cfe-commits

Author: Matthew Devereau
Date: 2023-12-06T10:08:04Z
New Revision: 6704d6aadd34e3b984ef6dbe85b18895beee9831

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

LOG: [SME2] Add LUTI2 and LUTI4 quad Builtins and Intrinsics (#73317)

See https://github.com/ARM-software/acle/pull/217

Patch by: Hassnaa Hamdi 

Added: 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x4.c
llvm/test/CodeGen/AArch64/sme2-intrinsics-luti2-lane-x4.ll
llvm/test/CodeGen/AArch64/sme2-intrinsics-luti4-lane-x4.ll

Modified: 
clang/include/clang/Basic/arm_sme.td
clang/include/clang/Basic/arm_sve_sme_incl.td
clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp
clang/utils/TableGen/SveEmitter.cpp
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
llvm/lib/Target/AArch64/SMEInstrFormats.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 7cdb531b5aae4..08d484acb3c10 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -321,9 +321,18 @@ let TargetGuard = "sme2" in {
 let TargetGuard = "sme2" in {
   def SVLDR_ZT : Inst<"svldr_zt", "viQ", "", MergeNone, "aarch64_sme_ldr_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA], [ImmCheck<0, 
ImmCheck0_0>]>;
   def SVSTR_ZT : Inst<"svstr_zt", "vi%", "", MergeNone, "aarch64_sme_str_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
+}
 
 //
 // Zero ZT0
 //
+let TargetGuard = "sme2" in {
   def SVZERO_ZT : Inst<"svzero_zt", "vi", "", MergeNone, 
"aarch64_sme_zero_zt", [IsOverloadNone, IsStreamingCompatible, IsSharedZA], 
[ImmCheck<0, ImmCheck0_0>]>;
 }
+
+// lookup table expand four contiguous registers
+//
+let TargetGuard = "sme2" in {
+  def SVLUTI2_LANE_ZT_X4 : Inst<"svluti2_lane_zt_{d}_x4", "4.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x4", [IsStreaming, 
IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_3>]>;
+  def SVLUTI4_LANE_ZT_X4 : Inst<"svluti4_lane_zt_{d}_x4", "4.di[i", 
"sUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x4", [IsStreaming, 
IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, 
ImmCheck0_1>]>;
+}

diff  --git a/clang/include/clang/Basic/arm_sve_sme_incl.td 
b/clang/include/clang/Basic/arm_sve_sme_incl.td
index 21dac067ab66e..040ce95a57de3 100644
--- a/clang/include/clang/Basic/arm_sve_sme_incl.td
+++ b/clang/include/clang/Basic/arm_sve_sme_incl.td
@@ -93,6 +93,7 @@
 // m: uint32_t
 // n: uint64_t
 
+// [: svuint8_t
 // t: svint32_t
 // z: svuint32_t
 // g: svuint64_t

diff  --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c
new file mode 100644
index 0..8c38d829a7f4c
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c
@@ -0,0 +1,280 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+// CHECK-LABEL: @test_svluti2_lane_zt_u8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call { , , ,  } 
@llvm.aarch64.sme.luti2.lane.zt.x4.nxv16i8(i32 0,  
[[ZN:%.*]], i32 3)
+// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { , , ,  } [[TMP0]], 0
+// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( poison,  [[TMP1]], i64 0)
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , , ,  } [[TMP0]], 1
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( [[TMP2]],  [[TMP3]], i64 16)
+// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { , , ,  } [[TMP0]], 2
+// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( [[TMP4]],  [[TMP5]], i64 32)
+// CHECK-NEXT:[[TMP7:%.*]] = extractvalue { , , ,  } [[TMP0]], 3
+// CHECK-NEXT:[[TMP8:%.*]] = tail call  
@llvm.vector.insert.nxv64i8.nxv16i8( [[TMP6]],  [[TMP7]], i64 48)
+// CHECK-NEXT:ret  [[TMP8]]
+//
+//

[llvm] [clang-tools-extra] [clang] [libc] [libcxx] [compiler-rt] [flang] [SME2] Add LUTI2 and LUTI4 quad Builtins and Intrinsics (PR #73317)

2023-12-06 Thread Matthew Devereau via cfe-commits

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


[compiler-rt] [llvm] [clang] [clang-tools-extra] [flang] Use mmap/munmap for allocating memory in emutls when available. (PR #73946)

2023-12-06 Thread via cfe-commits

https://github.com/andre-kempe-arm updated 
https://github.com/llvm/llvm-project/pull/73946

>From c4293e365638a75e5dcb19c505532279b76271af Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Kempe?= 
Date: Thu, 30 Nov 2023 10:05:28 +
Subject: [PATCH] Use mmap/munmap for allocating memory in emutls when
 available.

Using malloc and free to manage memory creates problems for projects
which provide own implementations of these functions, but still want to
C++'s thread_local functionality while allocating or freeing memory.

We can resolve this conflict using mmap and munmap to manage memory in
emutls .
---
 compiler-rt/lib/builtins/emutls.c | 122 +-
 1 file changed, 105 insertions(+), 17 deletions(-)

diff --git a/compiler-rt/lib/builtins/emutls.c 
b/compiler-rt/lib/builtins/emutls.c
index 390ffb25f6cf0..9c01b94466dd4 100644
--- a/compiler-rt/lib/builtins/emutls.c
+++ b/compiler-rt/lib/builtins/emutls.c
@@ -48,6 +48,10 @@ static void emutls_shutdown(emutls_address_array *array);
 #ifndef _WIN32
 
 #include 
+#include 
+#include 
+#include 
+#include 
 
 static pthread_mutex_t emutls_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_key_t emutls_pthread_key;
@@ -62,6 +66,67 @@ typedef unsigned int gcc_pointer 
__attribute__((mode(pointer)));
 #define EMUTLS_USE_POSIX_MEMALIGN 0
 #endif
 
+static __inline void *emutls_alloc(size_t size) {
+
+#if !defined(MAP_ANONYMOUS)
+#define MAP_ANONYMOUS 0
+#endif
+
+#define REQUIRED_ADDITIONAL_SPACE sizeof(size_t)
+#define REQUIRED_ALIGNMENT alignof(max_align_t)
+
+  // The size of the allocation is stored immediately in bytes returned by 
mmap.
+  // The payload available to the user then starts after an fixed size offset 
to
+  // ensure correct alignment of the memory. This way the originally mmapped
+  // memory can be calculated by subtracting the alignment offset from the
+  // pointer.
+
+  COMPILE_TIME_ASSERT(REQUIRED_ADDITIONAL_SPACE <= REQUIRED_ALIGNMENT);
+
+  // Memory returned by mmap is aligned to page size boundary. We assume that
+  // the page size meets the alignment requirement imposed by
+  // REQUIRED_ALIGNMENT.
+  void *const object =
+  mmap(NULL, size + REQUIRED_ALIGNMENT, PROT_READ | PROT_WRITE,
+   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+
+  if (object == MAP_FAILED) {
+perror("emutls: mmapping new memory failed");
+abort();
+  }
+
+  (*(size_t *)object) = size;
+
+  return (void *)((char *)(object) + REQUIRED_ALIGNMENT);
+}
+
+static __inline void emutls_free(void *ptr) {
+  void *const object = ((char *)ptr) - REQUIRED_ALIGNMENT;
+  size_t const size = (*(size_t *)object);
+
+  if (-1 == munmap(object, size)) {
+perror("emutls: munmapping memory failed");
+abort();
+  }
+}
+
+static __inline void *emutls_realloc(void *old_data, size_t new_size) {
+
+  void *const old_object = ((char *)old_data) - REQUIRED_ALIGNMENT;
+  size_t const old_size = (*(size_t *)old_object);
+
+  void *const new_data = emutls_alloc(new_size);
+
+  // The array is always resized to accommodate more data and never shrinks.
+  // Therefore,  old_size < new_size always holds and it's save to copy the
+  // data the without checking for the minimum value.
+  memcpy(new_data, old_data, old_size);
+
+  emutls_free(old_data);
+
+  return new_data;
+}
+
 static __inline void *emutls_memalign_alloc(size_t align, size_t size) {
   void *base;
 #if EMUTLS_USE_POSIX_MEMALIGN
@@ -69,9 +134,8 @@ static __inline void *emutls_memalign_alloc(size_t align, 
size_t size) {
 abort();
 #else
 #define EXTRA_ALIGN_PTR_BYTES (align - 1 + sizeof(void *))
-  char *object;
-  if ((object = (char *)malloc(EXTRA_ALIGN_PTR_BYTES + size)) == NULL)
-abort();
+  char *const object = (char *)emutls_alloc(EXTRA_ALIGN_PTR_BYTES + size);
+
   base = (void *)(((uintptr_t)(object + EXTRA_ALIGN_PTR_BYTES)) &
   ~(uintptr_t)(align - 1));
 
@@ -85,7 +149,7 @@ static __inline void emutls_memalign_free(void *base) {
   free(base);
 #else
   // The mallocated address is in ((void**)base)[-1]
-  free(((void **)base)[-1]);
+  emutls_free(((void **)base)[-1]);
 #endif
 }
 
@@ -110,13 +174,15 @@ static void emutls_key_destructor(void *ptr) {
 emutls_setspecific(array);
   } else {
 emutls_shutdown(array);
-free(ptr);
+emutls_free(array);
   }
 }
 
 static __inline void emutls_init(void) {
-  if (pthread_key_create(&emutls_pthread_key, emutls_key_destructor) != 0)
+  if (pthread_key_create(&emutls_pthread_key, emutls_key_destructor) != 0) {
+perror("emutls: pthread_key_create failed");
 abort();
+  }
   emutls_key_created = true;
 }
 
@@ -160,6 +226,26 @@ static __inline void win_abort(DWORD last_err, const char 
*hint) {
   abort();
 }
 
+static __inline void *emutls_alloc(size_t size) {
+  void *const object = malloc(size);
+
+  if (object == NULL)
+win_abort(GetLastError(), "malloc");
+
+  return object;
+}
+
+static __inline void emutls_free(void *ptr) { free(ptr); }
+
+static __inline void *emutls_rea

[clang] 6b1aa31 - [clang] Substitute alias templates from correct context (#74335)

2023-12-06 Thread via cfe-commits

Author: Mariya Podchishchaeva
Date: 2023-12-06T11:14:17+01:00
New Revision: 6b1aa319754e76366edd88e10034e0539710d946

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

LOG: [clang] Substitute alias templates from correct context (#74335)

Current context set to where alias was met, not where it is declared
caused incorrect access check in case alias referenced private members
of the parent class.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaCXXScopeSpec.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/temp/temp.decls/temp.alias/p3.cpp
clang/test/SemaCXX/alias-template.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 89ea2f0930cec..b3c7552f2efe6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -658,6 +658,9 @@ Bug Fixes in This Version
   Fixes (`#64467 `_)
 - Clang's ``-Wchar-subscripts`` no longer warns on chars whose values are 
known non-negative constants.
   Fixes (`#18763 `_)
+- Fixed false positive error emitted when templated alias inside a class
+  used private members of the same class.
+  Fixes (`#41693 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index 44a40215b90df..4bd96722a4b67 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -30,6 +30,20 @@ static CXXRecordDecl *getCurrentInstantiationOf(QualType T,
 return nullptr;
 
   const Type *Ty = T->getCanonicalTypeInternal().getTypePtr();
+  if (isa(Ty)) {
+if (auto *Record = dyn_cast(CurContext)) {
+  if (isa(Record) ||
+  Record->getDescribedClassTemplate()) {
+const Type *ICNT = Record->getTypeForDecl();
+QualType Injected =
+cast(ICNT)->getInjectedSpecializationType();
+
+if (Ty == Injected->getCanonicalTypeInternal().getTypePtr())
+  return Record;
+  }
+}
+  }
+
   if (const RecordType *RecordTy = dyn_cast(Ty)) {
 CXXRecordDecl *Record = cast(RecordTy->getDecl());
 if (!Record->isDependentContext() ||
@@ -37,10 +51,12 @@ static CXXRecordDecl *getCurrentInstantiationOf(QualType T,
   return Record;
 
 return nullptr;
-  } else if (isa(Ty))
+  }
+
+  if (isa(Ty))
 return cast(Ty)->getDecl();
-  else
-return nullptr;
+
+  return nullptr;
 }
 
 /// Compute the DeclContext that is associated with the given type.

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 09bbf14d39af5..a586014e0cb1b 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3990,9 +3990,16 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 if (Inst.isInvalid())
   return QualType();
 
-CanonType = SubstType(Pattern->getUnderlyingType(),
-  TemplateArgLists, AliasTemplate->getLocation(),
-  AliasTemplate->getDeclName());
+{
+  bool ForLambdaCallOperator = false;
+  if (const auto *Rec = dyn_cast(Pattern->getDeclContext()))
+ForLambdaCallOperator = Rec->isLambda();
+  Sema::ContextRAII SavedContext(*this, Pattern->getDeclContext(),
+ !ForLambdaCallOperator);
+  CanonType =
+  SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
+AliasTemplate->getLocation(), 
AliasTemplate->getDeclName());
+}
 if (CanonType.isNull()) {
   // If this was enable_if and we failed to find the nested type
   // within enable_if in a SFINAE context, dig out the specific

diff  --git a/clang/test/CXX/temp/temp.decls/temp.alias/p3.cpp 
b/clang/test/CXX/temp/temp.decls/temp.alias/p3.cpp
index 2d46502e1d9b3..2b33a4ef566da 100644
--- a/clang/test/CXX/temp/temp.decls/temp.alias/p3.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.alias/p3.cpp
@@ -2,11 +2,12 @@
 
 // The example given in the standard (this is rejected for other reasons 
anyway).
 template struct A;
-template using B = typename A::U; // expected-error {{no type 
named 'U' in 'A'}}
+template using B = typename A::U; // expected-error {{no type 
named 'U' in 'A'}}
+  // expected-note@-1 {{in 
instantiation of template class 'A' requested here}}
 template struct A {
   typedef B U; // expected-note {{in instantiation of template type alias 
'B' requested here}}
 };
-B b;
+B b; // expected-note {{in instantiation of template type alias 'B' 
requested here}}
 
 te

[clang] [clang] Substitute alias templates from correct context (PR #74335)

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [AArch64][Clang] Fix linker error for function multiversioning (PR #74358)

2023-12-06 Thread via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/74358

>From e881c254fbfd5920c4eae895913aa4e6282b2d12 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Mon, 20 Nov 2023 21:21:28 +0100
Subject: [PATCH] [AArch64][Clang] Fix linker error for function
 multiversioning.

AArch64 part of #71706.

Default version is now mangled with .default.
Resolver for the TargetVersion need to be emmited from the
CodeGenModule::EmitMultiVersionFunctionDefinition.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  28 +-
 .../test/CodeGen/attr-target-clones-aarch64.c | 187 --
 clang/test/CodeGen/attr-target-version.c  | 549 +-
 .../CodeGenCXX/attr-target-clones-aarch64.cpp |  26 +-
 clang/test/CodeGenCXX/attr-target-version.cpp | 168 +++---
 5 files changed, 656 insertions(+), 302 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 6a20723bf2bca0..b8882fd9281377 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1688,8 +1688,10 @@ static void AppendCPUSpecificCPUDispatchMangling(const 
CodeGenModule &CGM,
 static void AppendTargetVersionMangling(const CodeGenModule &CGM,
 const TargetVersionAttr *Attr,
 raw_ostream &Out) {
-  if (Attr->isDefaultVersion())
+  if (Attr->isDefaultVersion()) {
+Out << ".default";
 return;
+  }
   Out << "._";
   const TargetInfo &TI = CGM.getTarget();
   llvm::SmallVector Feats;
@@ -1752,8 +1754,10 @@ static void AppendTargetClonesMangling(const 
CodeGenModule &CGM,
   const TargetInfo &TI = CGM.getTarget();
   if (TI.getTriple().isAArch64()) {
 StringRef FeatureStr = Attr->getFeatureStr(VersionIndex);
-if (FeatureStr == "default")
+if (FeatureStr == "default") {
+  Out << ".default";
   return;
+}
 Out << "._";
 SmallVector Features;
 FeatureStr.split(Features, "+");
@@ -3999,6 +4003,8 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
 // Ensure that the resolver function is also emitted.
 GetOrCreateMultiVersionResolver(GD);
+  } else if (FD->hasAttr()) {
+GetOrCreateMultiVersionResolver(GD);
   } else
 EmitGlobalFunctionDefinition(GD, GV);
 }
@@ -4180,14 +4186,7 @@ void CodeGenModule::emitMultiVersionFunctions() {
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
-  // In Aarch64, default versions of multiversioned functions are mangled 
to
-  // their 'normal' assembly name. This deviates from other targets which
-  // append a '.default' string. As a result we need to continue appending
-  // .ifunc in Aarch64.
-  // FIXME: Should Aarch64 mangling for 'default' multiversion function and
-  // in turn ifunc function match that of other targets?
-  if (FD->isTargetClonesMultiVersion() &&
-  !getTarget().getTriple().isAArch64()) {
+  if (FD->isTargetClonesMultiVersion()) {
 const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
 llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
@@ -4368,14 +4367,7 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // a separate resolver).
   std::string ResolverName = MangledName;
   if (getTarget().supportsIFunc()) {
-// In Aarch64, default versions of multiversioned functions are mangled to
-// their 'normal' assembly name. This deviates from other targets which
-// append a '.default' string. As a result we need to continue appending
-// .ifunc in Aarch64.
-// FIXME: Should Aarch64 mangling for 'default' multiversion function and
-// in turn ifunc function match that of other targets?
-if (!FD->isTargetClonesMultiVersion() ||
-getTarget().getTriple().isAArch64())
+if (!FD->isTargetClonesMultiVersion())
   ResolverName += ".ifunc";
   } else if (FD->isTargetMultiVersion()) {
 ResolverName += ".resolver";
diff --git a/clang/test/CodeGen/attr-target-clones-aarch64.c 
b/clang/test/CodeGen/attr-target-clones-aarch64.c
index 3f2f2fdd24e8aa..5ea3f4a9b0b112 100644
--- a/clang/test/CodeGen/attr-target-clones-aarch64.c
+++ b/clang/test/CodeGen/attr-target-clones-aarch64.c
@@ -22,27 +22,44 @@ int __attribute__((target_clones("default"))) main() {
 inline int __attribute__((target_clones("fp16", "sve2-bitperm+fcma", 
"default"))) ftc_inline2(void) { return 2; };
 
 
-// CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
-// CHECK: @ftc.ifunc = weak_odr ifunc i32 (), ptr @ftc.resolver
-// CHECK: @ftc_def.ifunc = weak_odr ifunc i32 (), ptr @ftc_def.resolver
-// CHECK: @ftc_dup1.ifunc = weak_odr ifunc i32 (), ptr @

[clang] [AArch64][Clang] Fix linker error for function multiversioning (PR #74358)

2023-12-06 Thread via cfe-commits

https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/74358

>From 4a8fcefbafd5abd5f59545da27b742737dd586b7 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Mon, 20 Nov 2023 21:21:28 +0100
Subject: [PATCH] [AArch64][Clang] Fix linker error for function
 multiversioning.

AArch64 part of #71706.

Default version is now mangled with .default.
Resolver for the TargetVersion need to be emitted from the
CodeGenModule::EmitMultiVersionFunctionDefinition.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  28 +-
 .../test/CodeGen/attr-target-clones-aarch64.c | 187 --
 clang/test/CodeGen/attr-target-version.c  | 549 +-
 .../CodeGenCXX/attr-target-clones-aarch64.cpp |  26 +-
 clang/test/CodeGenCXX/attr-target-version.cpp | 168 +++---
 5 files changed, 656 insertions(+), 302 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 6a20723bf2bca0..b8882fd9281377 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1688,8 +1688,10 @@ static void AppendCPUSpecificCPUDispatchMangling(const 
CodeGenModule &CGM,
 static void AppendTargetVersionMangling(const CodeGenModule &CGM,
 const TargetVersionAttr *Attr,
 raw_ostream &Out) {
-  if (Attr->isDefaultVersion())
+  if (Attr->isDefaultVersion()) {
+Out << ".default";
 return;
+  }
   Out << "._";
   const TargetInfo &TI = CGM.getTarget();
   llvm::SmallVector Feats;
@@ -1752,8 +1754,10 @@ static void AppendTargetClonesMangling(const 
CodeGenModule &CGM,
   const TargetInfo &TI = CGM.getTarget();
   if (TI.getTriple().isAArch64()) {
 StringRef FeatureStr = Attr->getFeatureStr(VersionIndex);
-if (FeatureStr == "default")
+if (FeatureStr == "default") {
+  Out << ".default";
   return;
+}
 Out << "._";
 SmallVector Features;
 FeatureStr.split(Features, "+");
@@ -3999,6 +4003,8 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
 // Ensure that the resolver function is also emitted.
 GetOrCreateMultiVersionResolver(GD);
+  } else if (FD->hasAttr()) {
+GetOrCreateMultiVersionResolver(GD);
   } else
 EmitGlobalFunctionDefinition(GD, GV);
 }
@@ -4180,14 +4186,7 @@ void CodeGenModule::emitMultiVersionFunctions() {
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
-  // In Aarch64, default versions of multiversioned functions are mangled 
to
-  // their 'normal' assembly name. This deviates from other targets which
-  // append a '.default' string. As a result we need to continue appending
-  // .ifunc in Aarch64.
-  // FIXME: Should Aarch64 mangling for 'default' multiversion function and
-  // in turn ifunc function match that of other targets?
-  if (FD->isTargetClonesMultiVersion() &&
-  !getTarget().getTriple().isAArch64()) {
+  if (FD->isTargetClonesMultiVersion()) {
 const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
 llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
@@ -4368,14 +4367,7 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // a separate resolver).
   std::string ResolverName = MangledName;
   if (getTarget().supportsIFunc()) {
-// In Aarch64, default versions of multiversioned functions are mangled to
-// their 'normal' assembly name. This deviates from other targets which
-// append a '.default' string. As a result we need to continue appending
-// .ifunc in Aarch64.
-// FIXME: Should Aarch64 mangling for 'default' multiversion function and
-// in turn ifunc function match that of other targets?
-if (!FD->isTargetClonesMultiVersion() ||
-getTarget().getTriple().isAArch64())
+if (!FD->isTargetClonesMultiVersion())
   ResolverName += ".ifunc";
   } else if (FD->isTargetMultiVersion()) {
 ResolverName += ".resolver";
diff --git a/clang/test/CodeGen/attr-target-clones-aarch64.c 
b/clang/test/CodeGen/attr-target-clones-aarch64.c
index 3f2f2fdd24e8aa..5ea3f4a9b0b112 100644
--- a/clang/test/CodeGen/attr-target-clones-aarch64.c
+++ b/clang/test/CodeGen/attr-target-clones-aarch64.c
@@ -22,27 +22,44 @@ int __attribute__((target_clones("default"))) main() {
 inline int __attribute__((target_clones("fp16", "sve2-bitperm+fcma", 
"default"))) ftc_inline2(void) { return 2; };
 
 
-// CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
-// CHECK: @ftc.ifunc = weak_odr ifunc i32 (), ptr @ftc.resolver
-// CHECK: @ftc_def.ifunc = weak_odr ifunc i32 (), ptr @ftc_def.resolver
-// CHECK: @ftc_dup1.ifunc = weak_odr ifunc i32 (), ptr @

[clang] [AArch64][Clang] Fix linker error for function multiversioning (PR #74358)

2023-12-06 Thread via cfe-commits

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


[clang] [lldb] [clang][DebugInfo] Revert "emit variable definitions for constant-initialized static data-members" (PR #74580)

2023-12-06 Thread Michael Buch via cfe-commits

https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/74580

This commit reverts the changes in 
https://github.com/llvm/llvm-project/pull/71780 and all of its follow-up 
patches.

We got reports of the `.debug_names/.debug_gnu_pubnames/gdb_index/etc.` 
sections growing by a non-trivial amount for some large projects. While GCC 
does index definitions for static data member constants, they do so *only* for 
explicitly `constexpr` members. We were indexing *all* constant-initialized 
const-static members, which is likely where the significant size difference 
comes from. However, only emitting explicitly `constexpr` variables into the 
index doesn't seem like a good way forward, since from clang's perspective 
`const`-static integrals are `constexpr` too, and that shouldn't be any 
different in the debug-info component. Also, as new code moves to `constexpr` 
instead of `const` static for constants, such solution would just delay the 
growth of the Names index.

To prevent the size regression we revert to not emitting definitions for static 
data-members that have no location.

To support access to such constants from LLDB we'll most likely have to have to 
make LLDB find the constants by looking at the containing class first.

>From fe9624fdf898a2a629bb34f070d0e084f6dc0aa9 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 5 Dec 2023 14:52:00 +
Subject: [PATCH] [clang][DebugInfo] Revert "emit variable definitions for
 constant-initialized static data-members"

This commit reverts the changes in 
https://github.com/llvm/llvm-project/pull/71780
and all of its follow-up patches.

We got reports of the `.debug_names/.debug_gnu_pubnames/gdb_index/etc.`
sections growing by a non-trivial amount for some large projects. While
GCC does index definitions for static data member constants, they
do so *only* for explicitly `constexpr` members. We were indexing
*all* constant-initialized const-static members, which is likely where
the significant size difference comes from. However, only emitting explicitly
`constexpr` variables into the index doesn't seem like a good way
forward, since from clang's perspective `const`-static integrals
are `constexpr` too, and that shouldn't be any different in the debug-info
component. Also, as new code moves to `constexpr` instead of `const` static
for constants, such solution would just delay the growth of the Names index.

To prevent the size regression we revert to not emitting definitions for
static data-members that have no location.

To support access to such constants from LLDB we'll most likely have to
have to make LLDB find the constants by looking at the containing class
first.
---
 clang/lib/CodeGen/CGDebugInfo.cpp |  73 
 clang/lib/CodeGen/CGDebugInfo.h   |   6 -
 clang/test/CodeGenCXX/debug-info-class.cpp|  12 +-
 .../debug-info-static-inline-member.cpp   | 104 --
 .../CodeGenCXX/debug-info-static-member.cpp   |  20 +---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  |  64 +--
 .../SymbolFile/DWARF/DWARFASTParserClang.h|  11 --
 7 files changed, 10 insertions(+), 280 deletions(-)
 delete mode 100644 clang/test/CodeGenCXX/debug-info-static-inline-member.cpp

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 602e325e560f9..7cf661994a29c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,29 +69,6 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext &Ctx) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
-/// Given a VarDecl corresponding to either the definition or
-/// declaration of a C++ static data member, if it has a constant
-/// initializer and is evaluatable, return the evaluated value.
-/// Returns std::nullopt otherwise.
-static std::optional
-evaluateConstantInitializer(const clang::VarDecl *VD,
-const clang::ASTContext &Ctx) {
-  assert(VD != nullptr);
-
-  if (!VD->isStaticDataMember())
-return std::nullopt;
-
-  if (!VD->isUsableInConstantExpressions(Ctx))
-return std::nullopt;
-
-  auto const *InitExpr = VD->getAnyInitializer();
-  Expr::EvalResult Result;
-  if (!InitExpr->EvaluateAsConstantExpr(Result, Ctx))
-return std::nullopt;
-
-  return Result.Val;
-}
-
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
   DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
@@ -1724,7 +1701,6 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, 
llvm::DIType *RecordTy,
   llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
   RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Tag, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
-  StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;
 }
 
@@ -5628,41 +5604,6 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl 
*VD, const AP

[clang] [lldb] [clang][DebugInfo] Revert "emit definitions for constant-initialized static data-members" (PR #74580)

2023-12-06 Thread Michael Buch via cfe-commits

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


[clang] [lldb] [clang][DebugInfo] Revert "emit definitions for constant-initialized static data-members" (PR #74580)

2023-12-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Michael Buch (Michael137)


Changes

This commit reverts the changes in 
https://github.com/llvm/llvm-project/pull/71780 and all of its follow-up 
patches.

We got reports of the `.debug_names/.debug_gnu_pubnames/gdb_index/etc.` 
sections growing by a non-trivial amount for some large projects. While GCC 
does index definitions for static data member constants, they do so *only* for 
explicitly `constexpr` members. We were indexing *all* constant-initialized 
const-static members, which is likely where the significant size difference 
comes from. However, only emitting explicitly `constexpr` variables into the 
index doesn't seem like a good way forward, since from clang's perspective 
`const`-static integrals are `constexpr` too, and that shouldn't be any 
different in the debug-info component. Also, as new code moves to `constexpr` 
instead of `const` static for constants, such solution would just delay the 
growth of the Names index.

To prevent the size regression we revert to not emitting definitions for static 
data-members that have no location.

To support access to such constants from LLDB we'll most likely have to have to 
make LLDB find the constants by looking at the containing class first.

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


7 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (-73) 
- (modified) clang/lib/CodeGen/CGDebugInfo.h (-6) 
- (modified) clang/test/CodeGenCXX/debug-info-class.cpp (+4-8) 
- (removed) clang/test/CodeGenCXX/debug-info-static-inline-member.cpp (-104) 
- (modified) clang/test/CodeGenCXX/debug-info-static-member.cpp (+4-16) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
(+2-62) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h (-11) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 602e325e560f9..7cf661994a29c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,29 +69,6 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext &Ctx) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
-/// Given a VarDecl corresponding to either the definition or
-/// declaration of a C++ static data member, if it has a constant
-/// initializer and is evaluatable, return the evaluated value.
-/// Returns std::nullopt otherwise.
-static std::optional
-evaluateConstantInitializer(const clang::VarDecl *VD,
-const clang::ASTContext &Ctx) {
-  assert(VD != nullptr);
-
-  if (!VD->isStaticDataMember())
-return std::nullopt;
-
-  if (!VD->isUsableInConstantExpressions(Ctx))
-return std::nullopt;
-
-  auto const *InitExpr = VD->getAnyInitializer();
-  Expr::EvalResult Result;
-  if (!InitExpr->EvaluateAsConstantExpr(Result, Ctx))
-return std::nullopt;
-
-  return Result.Val;
-}
-
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
   DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
@@ -1724,7 +1701,6 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, 
llvm::DIType *RecordTy,
   llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
   RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Tag, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
-  StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;
 }
 
@@ -5628,41 +5604,6 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl 
*VD, const APValue &Init) {
   TemplateParameters, Align));
 }
 
-void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) {
-  assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
-  if (VD->hasAttr())
-return;
-
-  const auto CacheIt = DeclCache.find(VD);
-  if (CacheIt != DeclCache.end())
-return;
-
-  const auto InitVal = evaluateConstantInitializer(VD, CGM.getContext());
-  if (!InitVal)
-return;
-
-  llvm::DIFile *Unit = nullptr;
-  llvm::DIScope *DContext = nullptr;
-  unsigned LineNo;
-  StringRef DeclName, LinkageName;
-  QualType T;
-  llvm::MDTuple *TemplateParameters = nullptr;
-  collectVarDeclProps(VD, Unit, LineNo, T, DeclName, LinkageName,
-  TemplateParameters, DContext);
-
-  auto Align = getDeclAlignIfRequired(VD, CGM.getContext());
-  llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD);
-  llvm::DIExpression *InitExpr = createConstantValueExpression(VD, *InitVal);
-
-  // Omit linkage name for variable definitions that represent constants.
-  // There hasn't been a need from consumers yet to have it attached.
-  DeclCache[VD].reset(DBuilder.createGlobalVariableExpression(
-  TheCU, DeclName, /* LinkageName */ {}, Unit, LineNo,
-  getOrCreateType(T, Unit), true, true, InitExpr,
-  getOrCreateStaticDataMemberDeclarationOrNull(VD), TemplateParameters,
-  Align, Annotations));
-}
-
 void CGDebugInfo::Em

[clang] [lldb] [clang][DebugInfo] Revert "emit definitions for constant-initialized static data-members" (PR #74580)

2023-12-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-debuginfo

Author: Michael Buch (Michael137)


Changes

This commit reverts the changes in 
https://github.com/llvm/llvm-project/pull/71780 and all of its follow-up 
patches.

We got reports of the `.debug_names/.debug_gnu_pubnames/gdb_index/etc.` 
sections growing by a non-trivial amount for some large projects. While GCC 
does index definitions for static data member constants, they do so *only* for 
explicitly `constexpr` members. We were indexing *all* constant-initialized 
const-static members, which is likely where the significant size difference 
comes from. However, only emitting explicitly `constexpr` variables into the 
index doesn't seem like a good way forward, since from clang's perspective 
`const`-static integrals are `constexpr` too, and that shouldn't be any 
different in the debug-info component. Also, as new code moves to `constexpr` 
instead of `const` static for constants, such solution would just delay the 
growth of the Names index.

To prevent the size regression we revert to not emitting definitions for static 
data-members that have no location.

To support access to such constants from LLDB we'll most likely have to have to 
make LLDB find the constants by looking at the containing class first.

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


7 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (-73) 
- (modified) clang/lib/CodeGen/CGDebugInfo.h (-6) 
- (modified) clang/test/CodeGenCXX/debug-info-class.cpp (+4-8) 
- (removed) clang/test/CodeGenCXX/debug-info-static-inline-member.cpp (-104) 
- (modified) clang/test/CodeGenCXX/debug-info-static-member.cpp (+4-16) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
(+2-62) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h (-11) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 602e325e560f9..7cf661994a29c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,29 +69,6 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext &Ctx) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
-/// Given a VarDecl corresponding to either the definition or
-/// declaration of a C++ static data member, if it has a constant
-/// initializer and is evaluatable, return the evaluated value.
-/// Returns std::nullopt otherwise.
-static std::optional
-evaluateConstantInitializer(const clang::VarDecl *VD,
-const clang::ASTContext &Ctx) {
-  assert(VD != nullptr);
-
-  if (!VD->isStaticDataMember())
-return std::nullopt;
-
-  if (!VD->isUsableInConstantExpressions(Ctx))
-return std::nullopt;
-
-  auto const *InitExpr = VD->getAnyInitializer();
-  Expr::EvalResult Result;
-  if (!InitExpr->EvaluateAsConstantExpr(Result, Ctx))
-return std::nullopt;
-
-  return Result.Val;
-}
-
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
   DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
@@ -1724,7 +1701,6 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, 
llvm::DIType *RecordTy,
   llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
   RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Tag, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
-  StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;
 }
 
@@ -5628,41 +5604,6 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl 
*VD, const APValue &Init) {
   TemplateParameters, Align));
 }
 
-void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) {
-  assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
-  if (VD->hasAttr())
-return;
-
-  const auto CacheIt = DeclCache.find(VD);
-  if (CacheIt != DeclCache.end())
-return;
-
-  const auto InitVal = evaluateConstantInitializer(VD, CGM.getContext());
-  if (!InitVal)
-return;
-
-  llvm::DIFile *Unit = nullptr;
-  llvm::DIScope *DContext = nullptr;
-  unsigned LineNo;
-  StringRef DeclName, LinkageName;
-  QualType T;
-  llvm::MDTuple *TemplateParameters = nullptr;
-  collectVarDeclProps(VD, Unit, LineNo, T, DeclName, LinkageName,
-  TemplateParameters, DContext);
-
-  auto Align = getDeclAlignIfRequired(VD, CGM.getContext());
-  llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD);
-  llvm::DIExpression *InitExpr = createConstantValueExpression(VD, *InitVal);
-
-  // Omit linkage name for variable definitions that represent constants.
-  // There hasn't been a need from consumers yet to have it attached.
-  DeclCache[VD].reset(DBuilder.createGlobalVariableExpression(
-  TheCU, DeclName, /* LinkageName */ {}, Unit, LineNo,
-  getOrCreateType(T, Unit), true, true, InitExpr,
-  getOrCreateStaticDataMemberDeclarationOrNull(VD), TemplateParameters,
-  Align, Annotations));
-}
-
 void CGDebugInfo

[libc] [compiler-rt] [clang-tools-extra] [clang] [llvm] [flang] [libcxx] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/74512

>From 169d962b64b8ae242c3a6d332677296cf7503839 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 5 Dec 2023 10:28:44 -0800
Subject: [PATCH 1/2] [clang] Avoid -Wshadow warning when init-capture named
 same as class field

Shadowing warning doesn't make much sense since field is not available
in lambda's body without capturing this.

Fixes https://github.com/llvm/llvm-project/issues/71976
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaDecl.cpp   |  8 +---
 clang/test/SemaCXX/warn-shadow-in-lambdas.cpp | 18 ++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 828dd10e3d6db..7ac81e16492d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -655,6 +655,9 @@ Bug Fixes in This Version
   Fixes (`#64467 `_)
 - Clang's ``-Wchar-subscripts`` no longer warns on chars whose values are 
known non-negative constants.
   Fixes (`#18763 `_)
+- Clang's ``-Wshadow`` no longer warns when init-capture named same as class
+  field.
+  Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f12424d33b7da..65d095b2431dd 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8395,10 +8395,11 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;
-  if (isa(D) && isa(ShadowedDecl) && NewDC &&
-  isa(NewDC)) {
+  if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+if (!isa(ShadowedDecl))
+  return;
 if (RD->getLambdaCaptureDefault() == LCD_None) {
   // Try to avoid warnings for lambdas with an explicit capture list.
   const auto *LSI = cast(getCurFunction());
@@ -8416,7 +8417,8 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 }
   }
 
-  if (cast(ShadowedDecl)->hasLocalStorage()) {
+  if (const auto *VD = dyn_cast(ShadowedDecl);
+  VD && VD->hasLocalStorage()) {
 // A variable can't shadow a local variable in an enclosing scope, if
 // they are separated by a non-capturing declaration context.
 for (DeclContext *ParentDC = NewDC;
diff --git a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp 
b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
index bda6a65c02168..58af7a2e65c55 100644
--- a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -179,3 +179,21 @@ void f() {
 #endif
 }
 }
+
+namespace GH71976 {
+struct A {
+  int b = 5;
+  int foo() {
+return [b = b]() { return b; }();
+  }
+};
+
+struct B {
+  int a;
+  void foo() {
+auto b = [a = this->a] {
+
+};
+  }
+};
+}

>From 3798e1f25a8d812c082ac5815c490eb9c7f67e62 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 6 Dec 2023 02:24:59 -0800
Subject: [PATCH 2/2] Apply comments

---
 clang/docs/ReleaseNotes.rst   | 4 ++--
 clang/lib/Sema/SemaDecl.cpp   | 1 +
 clang/test/SemaCXX/warn-shadow-in-lambdas.cpp | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d1f3ed22cf2e..f5e0d4fa39737 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -661,8 +661,8 @@ Bug Fixes in This Version
 - Fixed false positive error emitted when templated alias inside a class
   used private members of the same class.
   Fixes (`#41693 `_)
-- Clang's ``-Wshadow`` no longer warns when init-capture named same as class
-  field.
+- Clang's ``-Wshadow`` no longer warns when an init-capture is named the same 
as
+  a class field.
   Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 65d095b2431dd..f590d1b3ade81 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8398,6 +8398,7 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
   if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+// If it is not VarDecl then it can not shadow.
 if (!isa(ShadowedDecl))
   return;
 if (RD->getLambdaCaptureDefault() == LCD_None) {
diff --git a/clang/test/SemaCXX/warn-shadow-in-lam

[clang-tools-extra] [clang] [llvm] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Ping.

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


[clang] [Clang] Emit TBAA info for enums in C (PR #73326)

2023-12-06 Thread Paul Walker via cfe-commits

paulwalker-arm wrote:

Do you think it's worth adding something to the Clang release note?

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


[libc] [compiler-rt] [clang-tools-extra] [clang] [llvm] [flang] [mlir] [libcxx] [mlir][nvvm] Introduce `fence.mbarrier.init` (PR #74058)

2023-12-06 Thread Guray Ozen via cfe-commits

https://github.com/grypp updated https://github.com/llvm/llvm-project/pull/74058

>From 9f35504e81246f97a9d8c14a06043685660ae15e Mon Sep 17 00:00:00 2001
From: Guray Ozen 
Date: Fri, 1 Dec 2023 11:10:40 +0100
Subject: [PATCH 1/3] [mlir][nvvm] Introduce `fence.mbarrier.init`

This PR introduce `fence.mbarrier.init` OP
---
 mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td   | 10 ++
 mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir |  8 
 2 files changed, 18 insertions(+)

diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td 
b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
index ecad1a16eb6c5..f400c18b5f32c 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
@@ -422,6 +422,16 @@ def NVVM_SetMaxRegisterOp : 
NVVM_PTXBuilder_Op<"setmaxregister"> {
   let hasVerifier = 1;
 }
 
+def NVVM_FenceMbarrierInitOp : NVVM_PTXBuilder_Op<"fence.mbarrier.init"> {
+  let arguments = (ins );
+  let assemblyFormat = "attr-dict";
+  let extraClassDefinition = [{
+std::string $cppClass::getPtx() {
+  return std::string("fence.mbarrier_init.release.cluster;");
+}
+  }];
+}
+
 def ShflKindBfly : I32EnumAttrCase<"bfly", 0>;
 def ShflKindUp   : I32EnumAttrCase<"up", 1>;
 def ShflKindDown : I32EnumAttrCase<"down", 2>;
diff --git a/mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir 
b/mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir
index 5482cc194192d..8366f1d109b1c 100644
--- a/mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir
+++ b/mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir
@@ -629,3 +629,11 @@ func.func @cp_bulk_commit() {
   nvvm.cp.async.bulk.commit.group
   func.return
 }
+
+// -
+
+func.func @fence_mbarrier_init() {
+  //CHECK: llvm.inline_asm has_side_effects asm_dialect = att 
"fence.mbarrier_init.release.cluster;"
+  nvvm.fence.mbarrier.init
+  func.return
+}

>From 34e29b2bef58739dbcc2e34efcec644accd5c089 Mon Sep 17 00:00:00 2001
From: Guray Ozen 
Date: Fri, 1 Dec 2023 16:00:37 +0100
Subject: [PATCH 2/3] add descripton

---
 mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td 
b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
index f400c18b5f32c..adc60e72fdf82 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
@@ -424,6 +424,12 @@ def NVVM_SetMaxRegisterOp : 
NVVM_PTXBuilder_Op<"setmaxregister"> {
 
 def NVVM_FenceMbarrierInitOp : NVVM_PTXBuilder_Op<"fence.mbarrier.init"> {
   let arguments = (ins );
+let description = [{
+Fence operation that applies on the prior nvvm.mbarrier.init
+[For more information, see PTX ISA]
+
(https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-membar)
+  }];
+  
   let assemblyFormat = "attr-dict";
   let extraClassDefinition = [{
 std::string $cppClass::getPtx() {

>From c5d66888946d4397fb29cafa2555f13b9bec8e42 Mon Sep 17 00:00:00 2001
From: Guray Ozen 
Date: Wed, 6 Dec 2023 11:40:56 +0100
Subject: [PATCH 3/3] fix typo in test

---
 mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir 
b/mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir
index ec79ad3e8c187..a4336a30999a1 100644
--- a/mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir
+++ b/mlir/test/Conversion/NVVMToLLVM/nvvm-to-llvm.mlir
@@ -636,7 +636,8 @@ func.func @cp_bulk_commit() {
 func.func @fence_mbarrier_init() {
   //CHECK: llvm.inline_asm has_side_effects asm_dialect = att 
"fence.mbarrier_init.release.cluster;"
   nvvm.fence.mbarrier.init
-
+  func.return 
+}
 // -
 
 func.func @fence_proxy() {

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


[flang] [clang-tools-extra] [clang] [llvm] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-12-06 Thread Yi Wu via cfe-commits


@@ -37,5 +80,17 @@ void FORTRAN_PROCEDURE_NAME(getarg)(
   (void)RTNAME(GetCommandArgument)(
   n, &value, nullptr, nullptr, __FILE__, __LINE__);
 }
+
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *arg, std::int64_t length) {
+  std::array str;

yi-wu-arm wrote:

Thanks for pointing this out!

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


[flang] [llvm] [clang-tools-extra] [clang] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-12-06 Thread Yi Wu via cfe-commits


@@ -39,6 +39,17 @@
 // overload will have a dummy parameter whose type indicates whether or not it
 // should be preferred. Any other parameters required for SFINAE should have
 // default values provided.
+
+// outside anonymous namespace, function reused

yi-wu-arm wrote:

Thanks, I will use that instead.

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


[mlir] [compiler-rt] [libc] [flang] [clang] [libcxx] [llvm] [clang-tools-extra] [mlir][nvvm] Introduce `fence.mbarrier.init` (PR #74058)

2023-12-06 Thread via cfe-commits

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


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


[flang] [llvm] [clang-tools-extra] [clang] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-12-06 Thread Yi Wu via cfe-commits


@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, GETPID, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, 
FP_CLASS, INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, GETLOG, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, 
RANDOM_SEED, SYSTEM_CLOCK |

yi-wu-arm wrote:

Should I create a new row in this markdown table called `Library subroutine`?

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


[llvm] [clang] [AArch64] Add soft-float ABI (PR #74460)

2023-12-06 Thread via cfe-commits

ktkachov-arm wrote:

Changing the ABI through the architecture flags i.e. +nofp has potential to 
greatly confuse users, who may come from other architectures that have 
soft-float ABIs already (including 32-bit arm)

- Does this also happen when using +nosimd?
- What about users like the Linux kernel that build with -mgeneral-regs-only?
- There is already an -mabi= option. How come it doesn't affect what is a 
pretty major ABI decision?

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


[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)

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



@@ -1894,6 +1894,8 @@ void TypePrinter::printAttributedAfter(const 
AttributedType *T,
   case attr::ArmMveStrictPolymorphism:
 OS << "__clang_arm_mve_strict_polymorphism";
 break;
+  case attr::RequiresCapability:
+OS << "requires_capability(blah)";

tbaederr wrote:

Ping

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


[llvm] [clang-tools-extra] [clang] [flang] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-12-06 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/70917

>From 0e98aa7ca15b05b91813eaeeb6ae1305e5f5384d Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:49:13 +
Subject: [PATCH 01/15] GETLOG runtime and extension implementation: get login
 username

Get login username, ussage:
CHARACTER(32) :: login
CALL getlog(login)
WRITE(*,*) login
---
 flang/docs/Intrinsics.md  |  2 +-
 .../Optimizer/Builder/Runtime/RTBuilder.h |  8 
 flang/include/flang/Runtime/command.h |  6 +++
 flang/include/flang/Runtime/extensions.h  |  2 +
 flang/runtime/command.cpp | 40 +++
 flang/runtime/extensions.cpp  |  6 +++
 flang/unittests/Runtime/CommandTest.cpp   | 15 ++-
 7 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e55..cfe5dcd141e98 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, GETLOG, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, 
RANDOM_SEED, SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h 
b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index b2774263e7a31..830df7ad006b5 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -62,6 +62,14 @@ using FuncTypeBuilderFunc = mlir::FunctionType 
(*)(mlir::MLIRContext *);
 /// standard type `i32` when `sizeof(int)` is 4.
 template 
 static constexpr TypeBuilderFunc getModel();
+
+template <>
+constexpr TypeBuilderFunc getModel() {
+  return [](mlir::MLIRContext *context) -> mlir::Type {
+return mlir::IntegerType::get(context, 8 * sizeof(unsigned int));
+  };
+}
+
 template <>
 constexpr TypeBuilderFunc getModel() {
   return [](mlir::MLIRContext *context) -> mlir::Type {
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec62893905454..1c212ef61697c 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -47,6 +47,12 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name,
 bool trim_name = true, const Descriptor *errmsg = nullptr,
 const char *sourceFile = nullptr, int line = 0);
 }
+
+// Try to get the name of current user
+// Returns a STATUS as described in the standard.
+std::int32_t RTNAME(GetLog)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 } // namespace Fortran::runtime
 
 #endif // FORTRAN_RUNTIME_COMMAND_H_
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb..d199d5e387b86 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -28,5 +28,7 @@ std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t &n, std::int8_t *arg, std::int64_t length);
 
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *name, std::int64_t length);
+
 } // extern "C"
 #endif // FORTRAN_RUNTIME_EXTENSIONS_H_
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e57..6b2f313e227a1 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -15,6 +15,30 @@
 #include 
 #include 
 
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+
+#include  // UNLEN=256
+
+inline char *getlogin() {
+  char *username = NULL;
+  DWORD size = UNLEN + 1; // Constant for the maximum username length
+  username = (char *)malloc(size);
+
+  if (GetUserName(username, &size)) {
+// Username 

[clang-tools-extra] [compiler-rt] [clang] [flang] [libcxx] [llvm] [libc] [mlir] [mlir][nvvm] Introduce `fence.mbarrier.init` (PR #74058)

2023-12-06 Thread Guray Ozen via cfe-commits

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


[clang] [AArch64][SME2] Add multi-vector builtins for cvt (PR #74450)

2023-12-06 Thread Kerry McLaughlin via cfe-commits

https://github.com/kmclaughlin-arm approved this pull request.

LGTM!

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


[lldb] [clang] [clang][DebugInfo] Revert "emit definitions for constant-initialized static data-members" (PR #74580)

2023-12-06 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/74580

>From fe9624fdf898a2a629bb34f070d0e084f6dc0aa9 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 5 Dec 2023 14:52:00 +
Subject: [PATCH 1/2] [clang][DebugInfo] Revert "emit variable definitions for
 constant-initialized static data-members"

This commit reverts the changes in 
https://github.com/llvm/llvm-project/pull/71780
and all of its follow-up patches.

We got reports of the `.debug_names/.debug_gnu_pubnames/gdb_index/etc.`
sections growing by a non-trivial amount for some large projects. While
GCC does index definitions for static data member constants, they
do so *only* for explicitly `constexpr` members. We were indexing
*all* constant-initialized const-static members, which is likely where
the significant size difference comes from. However, only emitting explicitly
`constexpr` variables into the index doesn't seem like a good way
forward, since from clang's perspective `const`-static integrals
are `constexpr` too, and that shouldn't be any different in the debug-info
component. Also, as new code moves to `constexpr` instead of `const` static
for constants, such solution would just delay the growth of the Names index.

To prevent the size regression we revert to not emitting definitions for
static data-members that have no location.

To support access to such constants from LLDB we'll most likely have to
have to make LLDB find the constants by looking at the containing class
first.
---
 clang/lib/CodeGen/CGDebugInfo.cpp |  73 
 clang/lib/CodeGen/CGDebugInfo.h   |   6 -
 clang/test/CodeGenCXX/debug-info-class.cpp|  12 +-
 .../debug-info-static-inline-member.cpp   | 104 --
 .../CodeGenCXX/debug-info-static-member.cpp   |  20 +---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  |  64 +--
 .../SymbolFile/DWARF/DWARFASTParserClang.h|  11 --
 7 files changed, 10 insertions(+), 280 deletions(-)
 delete mode 100644 clang/test/CodeGenCXX/debug-info-static-inline-member.cpp

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 602e325e560f9..7cf661994a29c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,29 +69,6 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext &Ctx) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
-/// Given a VarDecl corresponding to either the definition or
-/// declaration of a C++ static data member, if it has a constant
-/// initializer and is evaluatable, return the evaluated value.
-/// Returns std::nullopt otherwise.
-static std::optional
-evaluateConstantInitializer(const clang::VarDecl *VD,
-const clang::ASTContext &Ctx) {
-  assert(VD != nullptr);
-
-  if (!VD->isStaticDataMember())
-return std::nullopt;
-
-  if (!VD->isUsableInConstantExpressions(Ctx))
-return std::nullopt;
-
-  auto const *InitExpr = VD->getAnyInitializer();
-  Expr::EvalResult Result;
-  if (!InitExpr->EvaluateAsConstantExpr(Result, Ctx))
-return std::nullopt;
-
-  return Result.Val;
-}
-
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
   DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
@@ -1724,7 +1701,6 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, 
llvm::DIType *RecordTy,
   llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
   RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Tag, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
-  StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;
 }
 
@@ -5628,41 +5604,6 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl 
*VD, const APValue &Init) {
   TemplateParameters, Align));
 }
 
-void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) {
-  assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
-  if (VD->hasAttr())
-return;
-
-  const auto CacheIt = DeclCache.find(VD);
-  if (CacheIt != DeclCache.end())
-return;
-
-  const auto InitVal = evaluateConstantInitializer(VD, CGM.getContext());
-  if (!InitVal)
-return;
-
-  llvm::DIFile *Unit = nullptr;
-  llvm::DIScope *DContext = nullptr;
-  unsigned LineNo;
-  StringRef DeclName, LinkageName;
-  QualType T;
-  llvm::MDTuple *TemplateParameters = nullptr;
-  collectVarDeclProps(VD, Unit, LineNo, T, DeclName, LinkageName,
-  TemplateParameters, DContext);
-
-  auto Align = getDeclAlignIfRequired(VD, CGM.getContext());
-  llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD);
-  llvm::DIExpression *InitExpr = createConstantValueExpression(VD, *InitVal);
-
-  // Omit linkage name for variable definitions that represent constants.
-  // There hasn't been a need from consumers yet to have it attached.
-  DeclCache[VD].reset(DBuilder.createGlobalVariableExpression(
-  TheCU, DeclName, /* LinkageName 

[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2023-12-06 Thread Shivam Gupta via cfe-commits

xgupta wrote:

> @cor3ntin Could you describe the format of the `release note` briefly so I 
> can `amend` my `commit` accordingly?
Like this - 
https://github.com/llvm/llvm-project/pull/74553/files#diff-ec770381d76c859f5f572db789175fe44410a72608f58ad5dbb14335ba56eb97

You also need to clang-format this patch with git clang-format HEAD~1.

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


[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2023-12-06 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/70594

>From 1923c212515033dbb92f09c6d11cd2b679261459 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 29 Oct 2023 18:37:17 +0530
Subject: [PATCH] [clang] Fix a crash in debug mode

Resolves Issue #35603

This bug was caused due to the assertions being too strict,
loosened by stripping qualifiers from the base class but not
from the type of the initializer.

Added Release Notes for the same.
---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/Sema/GH35603.cpp| 19 +++
 3 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/GH35603.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2595737e8b3b1..25cdc31b0caa6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -670,6 +670,9 @@ Bug Fixes to C++ Support
   default initializing a base class in a constant expression context. Fixes:
   (`#69890 `_)
 
+- Fix crash when inheriting from a cv-qualified type. Fixes:
+  (`#35603 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5947805f9576f..07f0a12385b46 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6431,7 +6431,7 @@ static bool HandleConstructorCall(const Expr *E, const 
LValue &This,
   // Non-virtual base classes are initialized in the order in the class
   // definition. We have already checked for virtual base classes.
   assert(!BaseIt->isVirtual() && "virtual base for literal type");
-  assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
+  assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
  "base class initializers not in expected order");
   ++BaseIt;
 #endif
diff --git a/clang/test/Sema/GH35603.cpp b/clang/test/Sema/GH35603.cpp
new file mode 100644
index 0..853552108ec2b
--- /dev/null
+++ b/clang/test/Sema/GH35603.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
+
+// expected-no-diagnostics
+
+struct A {};
+using CA = const A;
+
+struct S1 : CA {
+  constexpr S1() : CA() {}
+};
+
+struct S2 : A {
+  constexpr S2() : CA() {}
+};
+
+struct S3 : CA {
+  constexpr S3() : A() {}
+};

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


[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-12-06 Thread Nikita Popov via cfe-commits

nikic wrote:

Okay, it looks like the mpeg2decode regression is indeed fixed. I think the 
only somewhat significant regression left is `Shootout-C++-ary2`, but in my IR 
diffs I don't see any regression there (only improvements with a bunch of 
conditions being optimized away).

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


[flang] [llvm] [libcxx] [libcxxabi] [compiler-rt] [lldb] [libunwind] [mlir] [clang-tools-extra] [lld] [libc] [openmp] [clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/73099

>From 1d70b7726e7d1f11622a6d5c8246b0737e024c8d Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 19 Sep 2023 08:37:18 -0700
Subject: [PATCH 1/8] [C23] Implement N3018: The constexpr specifier for object
 definitions

The implementation mostly reuses C++ code paths where possible,
including narrowing check in order to provide diagnostic messages in
case initializer for constexpr variable is not exactly representable in
target type.

The following won't work due to lack of support for other features:
- Diagnosing of underspecified declarations involving constexpr
- Constexpr attached to compound literals

Also due to lack of support for char8_t some of examples with utf-8
strings don't work properly.
---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  16 +
 clang/include/clang/Basic/TokenKinds.def  |   2 +-
 clang/lib/AST/Decl.cpp|  16 +-
 clang/lib/AST/ExprConstant.cpp|  17 +-
 clang/lib/Parse/ParseDecl.cpp |   2 +
 clang/lib/Sema/SemaDecl.cpp   | 204 +++--
 clang/lib/Sema/SemaOverload.cpp   |  36 ++-
 clang/test/C/C2x/n3018.c  |  86 ++
 clang/test/Parser/c23-constexpr.c |   6 +
 clang/test/Sema/constexpr.c   | 275 ++
 clang/www/c_status.html   |   2 +-
 12 files changed, 627 insertions(+), 36 deletions(-)
 create mode 100644 clang/test/C/C2x/n3018.c
 create mode 100644 clang/test/Parser/c23-constexpr.c
 create mode 100644 clang/test/Sema/constexpr.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b65106b9106d4..cae1707f3e30f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -208,6 +208,7 @@ C23 Feature Support
 
 - Clang now supports  which defines several macros for 
performing
   checked integer arithmetic. It is also exposed in pre-C23 modes.
+- Clang now supports ``N3018 The constexpr specifier for object definitions``.
 
 - Completed the implementation of
   `N2508 `_. We
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 990692c06d7d3..11f24583dc55a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2932,6 +2932,22 @@ def warn_private_extern : Warning<
 def note_private_extern : Note<
   "use __attribute__((visibility(\"hidden\"))) attribute instead">;
 
+// C23 constexpr
+def err_c23_thread_local_constexpr : Error<
+  "thread-local storage is not allowed with constexpr">;
+def err_c23_extern_constexpr : Error<
+  "extern specifier is not allowed with constexpr">;
+def err_c23_constexpr_not_variable : Error<
+  "constexpr is only allowed in variable declarations">;
+def err_c23_constexpr_invalid_type : Error<
+  "constexpr variable cannot have type %0">;
+def err_c23_constexpr_init_not_representable : Error<
+  "constexpr initializer evaluates to %0 which is not exactly representable in 
type %1">;
+def err_c23_constexpr_init_type_mismatch : Error<
+  "constexpr initializer for type %0 is of type %1">;
+def err_c23_constexpr_pointer_not_null : Error<
+  "constexpr pointer initializer is not null">;
+
 // C++ Concepts
 def err_concept_decls_may_only_appear_in_global_namespace_scope : Error<
   "concept declarations may only appear in global or namespace scope">;
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 3ab420821d82b..e9e8f59247662 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -393,7 +393,7 @@ CXX11_KEYWORD(alignas   , KEYC23)
 CXX11_UNARY_EXPR_OR_TYPE_TRAIT(alignof, AlignOf, KEYC23)
 CXX11_KEYWORD(char16_t  , KEYNOMS18)
 CXX11_KEYWORD(char32_t  , KEYNOMS18)
-CXX11_KEYWORD(constexpr , 0)
+CXX11_KEYWORD(constexpr , KEYC23)
 CXX11_KEYWORD(decltype  , 0)
 CXX11_KEYWORD(noexcept  , 0)
 CXX11_KEYWORD(nullptr   , KEYC23)
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3a..678a366ed29ad 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2461,7 +2461,7 @@ bool VarDecl::mightBeUsableInConstantExpressions(const 
ASTContext &C) const {
 
   // OpenCL permits const integral variables to be used in constant
   // expressions, like in C++98.
-  if (!Lang.CPlusPlus && !Lang.OpenCL)
+  if (!Lang.CPlusPlus && !Lang.OpenCL && !Lang.C23)
 return false;
 
   // Function parameters are never usable in constant expressions.
@@ -2485,12 +2485,12 @@ bool VarDecl::mightBeUsableInConstantExpressions(const 
ASTContext &C) const {
 
   // In C++, const, non-volatile var

[flang] [llvm] [libcxx] [libcxxabi] [compiler-rt] [lldb] [libunwind] [mlir] [clang-tools-extra] [lld] [libc] [openmp] [clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -14270,6 +14318,113 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, 
SourceLocation IdentLoc,
   : IdentLoc);
 }
 
+static ImplicitConversionKind GetConversionKind(QualType FromType,
+QualType ToType) {
+  if (ToType->isIntegerType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Integral;
+if (FromType->isIntegerType())
+  return ICK_Integral_Conversion;
+  }
+
+  if (ToType->isFloatingType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Conversion;
+if (FromType->isIntegerType())
+  return ICK_Floating_Integral;
+  }
+
+  return ICK_Identity;
+}
+
+static bool CheckC23ConstexprInitConversion(Sema &S, const Expr *Init) {
+  assert(S.getLangOpts().C23);
+  const Expr *InitNoCast = Init->IgnoreParenImpCasts();
+  StandardConversionSequence SCS;
+  SCS.setAsIdentityConversion();
+  auto FromType = InitNoCast->getType();
+  auto ToType = Init->getType();
+  SCS.setToType(0, FromType);
+  SCS.setToType(1, ToType);
+  SCS.Second = GetConversionKind(FromType, ToType);
+
+  APValue Value;
+  QualType PreNarrowingType;
+  // Reuse C++ narrowing check.
+  switch (SCS.getNarrowingKind(S.Context, Init, Value, PreNarrowingType,
+   /*IgnoreFloatToIntegralConversion*/ false)) {
+  // The value doesn't fit.
+  case NK_Constant_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_not_representable)
+<< Value.getAsString(S.Context, PreNarrowingType) << ToType;
+return true;
+
+  // Conversion to a narrower type.
+  case NK_Type_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_type_mismatch)
+<< ToType << FromType;
+return true;
+
+  // Since we only reuse narrowing check for C23 constexpr variables here, 
we're
+  // not really interested in these cases.
+  case NK_Dependent_Narrowing:
+  case NK_Variable_Narrowing:
+  case NK_Not_Narrowing:
+return false;
+  }
+  llvm_unreachable("unhandled case in switch");
+}
+
+static bool CheckC23ConstexprInitStringLiteral(const StringLiteral *SE,
+   Sema &SemaRef,
+   SourceLocation Loc) {
+  assert(SemaRef.getLangOpts().C23);
+  // String literals have the target type attached but underneath may contain
+  // values that don't really fit into the target type. Check that every
+  // character fits.
+  const ConstantArrayType *CAT =
+  SemaRef.Context.getAsConstantArrayType(SE->getType());
+  QualType CharType = CAT->getElementType();
+  uint32_t BitWidth = SemaRef.Context.getTypeSize(CharType);
+  bool isUnsigned = CharType->isUnsignedIntegerType();
+  llvm::APSInt Value(BitWidth, isUnsigned);
+  for (unsigned I = 0, N = SE->getLength(); I != N; ++I) {
+int64_t C = SE->getCodeUnitS(I, SemaRef.Context.getCharWidth());
+Value = C;
+if (Value != C) {
+  SemaRef.Diag(Loc, diag::err_c23_constexpr_init_not_representable)

Fznamznon wrote:

Yeah why not. Looks better this way

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


[flang] [llvm] [libcxx] [libcxxabi] [compiler-rt] [lldb] [libunwind] [mlir] [clang-tools-extra] [lld] [libc] [openmp] [clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -1914,6 +1914,17 @@ class StringLiteral final
 llvm_unreachable("Unsupported character width!");
   }
 
+  // Get code unit but preserve sign info.
+  int64_t getCodeUnitS(size_t I, uint64_t ByteWidth) const {

Fznamznon wrote:

It is a number of bits in byte, but ok

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


[clang] [AArch64][SME2] Add multi-vector builtins for cvt (PR #74450)

2023-12-06 Thread Dinar Temirbulatov via cfe-commits


@@ -0,0 +1,242 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -target-feature +bf16 -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -target-feature +bf16 -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1  -D__SVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -target-feature +sme2 -target-feature +bf16 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s

dtemirbulatov wrote:

I used **-target-feature +b16b16** for BF16 support, not sure now how correct 
now, I am waiting for Carol to resolve a correct nameing after that I can 
rebase my change. 

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


[clang] [llvm] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-12-06 Thread Yingwei Zheng via cfe-commits

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

The regression in `Shootout-C++-ary2` may be caused by ThinLTO. But I think it 
is OK to go ahead and merge :)


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


[clang] [clang][AMDGPU] Update amdgpu_waves_per_eu attr docs (PR #74587)

2023-12-06 Thread Pierre van Houtryve via cfe-commits

https://github.com/Pierre-vh created 
https://github.com/llvm/llvm-project/pull/74587

None

>From f4f909df09dda7e2d21389f7b44f67e89997c44b Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Wed, 6 Dec 2023 12:47:56 +0100
Subject: [PATCH] [clang][AMDGPU] Update amdgpu_waves_per_eu attr docs

---
 clang/include/clang/Basic/AttrDocs.td | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index bbe4de94cbabe..88f7c65e6e847 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2659,8 +2659,9 @@ An error will be given if:
   - Specified values violate subtarget specifications;
   - Specified values are not compatible with values provided through other
 attributes;
-  - The AMDGPU target backend is unable to create machine code that can meet 
the
-request.
+
+The AMDGPU target backend will emit a warning whenever it is unable to
+create machine code that meets the request.
   }];
 }
 

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


[clang] [clang][AMDGPU] Update amdgpu_waves_per_eu attr docs (PR #74587)

2023-12-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Pierre van Houtryve (Pierre-vh)


Changes



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


1 Files Affected:

- (modified) clang/include/clang/Basic/AttrDocs.td (+3-2) 


``diff
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index bbe4de94cbabe..88f7c65e6e847 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2659,8 +2659,9 @@ An error will be given if:
   - Specified values violate subtarget specifications;
   - Specified values are not compatible with values provided through other
 attributes;
-  - The AMDGPU target backend is unable to create machine code that can meet 
the
-request.
+
+The AMDGPU target backend will emit a warning whenever it is unable to
+create machine code that meets the request.
   }];
 }
 

``




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


[clang] [CUDA][Win32] Add `fma(long double,..)` to math forward declares. (PR #73756)

2023-12-06 Thread via cfe-commits

blinkfrog wrote:

I would like to share some thoughts regarding the proposed fix involving the 
#ifdef _MSC_VER check in the LLVM PR for the fma function ambiguity issue. I am 
sorry if I say something stupid.

In the typical workflow with AdaptiveCpp and CUDA backend on Windows, MSVC is 
used only for compiling LLVM and Clang. However, the actual compilation of SYCL 
programs targeting the CUDA backend is performed using Clang with the 
AdaptiveCpp plugin.

Given this workflow, the #ifdef _MSC_VER check may not be effective because 
_MSC_VER is specific to the MSVC compiler and is not defined when using Clang, 
even on Windows. Consequently, this check might not activate during our 
compilation process, and the ambiguity issue with the `fma` function may 
persist.

A more suitable approach might be to use a different check that can effectively 
detect the Windows platform in the Clang environment, such as _WIN32, ensuring 
that the fix is applied in the relevant scenarios. Probably, better would be to 
check `_MSVC_STL_VERSION `, but this probably won't work, as standard 
libraries, where it is defined, are included after LLVM headers I think.

I wanted to bring this to your attention to ensure that the proposed solution 
addresses the issue in the context of workflows similar to ours.

Thank you for considering this point.

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


[clang] Move documentation about -verify from a header to public docs (PR #73694)

2023-12-06 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

@AaronBallman After moving the docs, none of the code blocks are rendering:
https://clang.llvm.org/docs/InternalsManual.html#verifying-diagnostics

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


[clang] Move documentation about -verify from a header to public docs (PR #73694)

2023-12-06 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

It would also be nice to fix the link to full `-verify` docs in 
https://clang.llvm.org/docs/InternalsManual.html#the-diagnosticconsumer-interface

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits

https://github.com/urnathan updated 
https://github.com/llvm/llvm-project/pull/74155

>From 89c05618bb75fd073343046f3b54bde5f2254719 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Wed, 15 Nov 2023 15:27:16 -0500
Subject: [PATCH 1/5] [clang] Strict aliasing warning ala GCC [PR50066]

This implements -Wstrict-aliasing(=[123])? along the same lines as
GCC. It's not 100% the same for reasons expanded on below. The default
is level 3, and I have verified that bootstrapping does not trigger
any warnings (just like building with GCC).

As with GCC, higher levels result in fewer warnings, reducing the
number of false positives at the cost of missing (some) potential
cases. Unlike GCC, this is entirely in the FE, we do not propagate any
checking into the IR (so there are cases GCC will detect we do not, I
have not encountered any). GCC's documentation is not very specific
about which cases are detected. I examined GCC's source code to reverse
engineer the algorithm[*], and as can be seen from the testcases, noted
GCC's behaviour.

The strict aliasing check relies on TBAA. LLVM's representation is
semantically different to GCCs for structured types. I have tried to
keep with the spirit of the warning.

The warning checks reinterpret_casts that are CK_BitCast or
CK_LValueBitCast. It also checks C-style casts that are equivalent (to
the extent available, as a C-style bitcast could be a well-formed
static cast).

level=1 looks for reinterpret casts from T * to U * (or an lvalue of
type T to U &), where T and U are not TBAA compatible.

level=2 requires the src expression be an lvalue something of
known(ish) static type. I.e a variable, array dereference or member
access.

level=3 requires level 2 and that the resultant pointer is actually
referenced (lvalue->rvalue or lvalue written). Here we can do better
than GCC, which doesn't represent this in the IR -- we merely get a
dereference (and reference types are modeled as pointers with
auto-dereference semantics). There is one exception to this, which is
by-value aggregate arguments. These end up invoking a copy constructor
(passing a reference of course), but are IMHO morally an rvalue -- so
should trigger.

The warning hooks into clang's code-generator's TBAA machinery. For
scalar types the TBAA is straight forwards, comparing LLVM's MDNode
representaion. For record & union types we check if one of the types
is (recursively) the same (or TBAA compatible) as the first direct
base or a field(s) of the record at offset zero (i.e. the first member
of a record, or any members of a union). This covers both C++ and
C-Style inheritance. Also. the member maybe alias_any, or in
ubiquitous-char's alias set, which is also permissible.

The warning is similar to the alignment check that
CheckCompatibleReinterpretCast does, perhaps some merging could occur
if this is accepted?

[*] I implemented what turned into GCC's level=1 way back when.

WIP: adjust tests
---
 clang/include/clang/AST/ASTConsumer.h |   25 +
 clang/include/clang/Basic/DiagnosticGroups.td |6 -
 clang/include/clang/Basic/DiagnosticOptions.h |4 +
 .../clang/Basic/DiagnosticSemaKinds.td|8 +
 clang/include/clang/Driver/Options.td |6 +
 clang/include/clang/Sema/Sema.h   |   11 +
 clang/lib/CodeGen/BackendConsumer.h   |1 +
 clang/lib/CodeGen/CodeGenAction.cpp   |4 +
 clang/lib/CodeGen/CodeGenModule.h |1 +
 clang/lib/CodeGen/CodeGenTBAA.cpp |  134 ++
 clang/lib/CodeGen/CodeGenTBAA.h   |5 +-
 clang/lib/CodeGen/ModuleBuilder.cpp   |2 +
 clang/lib/Frontend/CompilerInvocation.cpp |3 +
 clang/lib/Frontend/FrontendAction.cpp |8 +
 clang/lib/Sema/SemaCast.cpp   |  139 ++
 clang/lib/Sema/SemaExpr.cpp   |   17 +-
 clang/lib/Sema/SemaExprMember.cpp |2 +
 clang/lib/Sema/SemaInit.cpp   |5 +
 clang/test/Misc/warning-flags-tree.c  |4 -
 clang/test/Sema/strict-aliasing-warn.c|  192 +++
 clang/test/SemaCXX/strict-aliasing-warn.cpp   | 1375 +
 21 files changed, 1939 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/Sema/strict-aliasing-warn.c
 create mode 100644 clang/test/SemaCXX/strict-aliasing-warn.cpp

diff --git a/clang/include/clang/AST/ASTConsumer.h 
b/clang/include/clang/AST/ASTConsumer.h
index ebcd8059284d8..d5731ed6adf63 100644
--- a/clang/include/clang/AST/ASTConsumer.h
+++ b/clang/include/clang/AST/ASTConsumer.h
@@ -21,6 +21,7 @@ namespace clang {
   class DeclGroupRef;
   class ASTMutationListener;
   class ASTDeserializationListener; // layering violation because void* is ugly
+  class QualType;
   class SemaConsumer; // layering violation required for safe SemaConsumer
   class TagDecl;
   class VarDecl;
@@ -37,6 +38,27 @@ class ASTConsumer {
 
   friend class SemaConsumer;
 
+public:
+  /// Allow type-based aliasing information to be interrogated by the

[clang-tools-extra] [compiler-rt] [llvm] [libc] [libcxx] [flang] [clang] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2023-12-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -8395,10 +8395,11 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;
-  if (isa(D) && isa(ShadowedDecl) && NewDC &&
-  isa(NewDC)) {
+  if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+if (!isa(ShadowedDecl))

Fznamznon wrote:

You mean add a comment saying that it is a case when an init-capture references 
class field?

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits


@@ -498,3 +498,137 @@ 
CodeGenTBAA::mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo,
   // access type regardless of their base types.
   return TBAAAccessInfo::getMayAliasInfo();
 }
+
+// Determine the aliasing kind bit-converting from type Src to type Dst.
+CodeGenTBAA::AliasingKind CodeGenTBAA::getAliasingKind(QualType &Dst,
+   QualType &Src) {
+  assert(!Src->isVoidType() && !Dst->isVoidType());
+  if (TypeHasMayAlias(Src) || TypeHasMayAlias(Dst))
+return AK_Ok;
+
+  Src = QualType{Src->getBaseElementTypeUnsafe(), 0};
+  Dst = QualType{Dst->getBaseElementTypeUnsafe(), 0};
+
+  auto *SrcDecl = Src->getAsRecordDecl();
+  auto *DstDecl = Dst->getAsRecordDecl();
+
+  const llvm::MDNode *AnyTBAA = getChar();
+  const llvm::MDNode *SrcTBAA = nullptr;
+  const llvm::MDNode *DstTBAA = nullptr;
+
+  if (!SrcDecl) {
+SrcTBAA = getTypeInfo(Src);
+if (!SrcTBAA || SrcTBAA == AnyTBAA)

urnathan wrote:

Yeah, I didn't because it was a class member, but scoped is better. done.

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits


@@ -498,3 +498,137 @@ 
CodeGenTBAA::mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo,
   // access type regardless of their base types.
   return TBAAAccessInfo::getMayAliasInfo();
 }
+
+// Determine the aliasing kind bit-converting from type Src to type Dst.
+CodeGenTBAA::AliasingKind CodeGenTBAA::getAliasingKind(QualType &Dst,
+   QualType &Src) {
+  assert(!Src->isVoidType() && !Dst->isVoidType());
+  if (TypeHasMayAlias(Src) || TypeHasMayAlias(Dst))
+return AK_Ok;
+
+  Src = QualType{Src->getBaseElementTypeUnsafe(), 0};
+  Dst = QualType{Dst->getBaseElementTypeUnsafe(), 0};
+
+  auto *SrcDecl = Src->getAsRecordDecl();
+  auto *DstDecl = Dst->getAsRecordDecl();
+
+  const llvm::MDNode *AnyTBAA = getChar();
+  const llvm::MDNode *SrcTBAA = nullptr;
+  const llvm::MDNode *DstTBAA = nullptr;
+
+  if (!SrcDecl) {
+SrcTBAA = getTypeInfo(Src);
+if (!SrcTBAA || SrcTBAA == AnyTBAA)
+  return AK_Ok;
+  }
+  if (!DstDecl) {
+DstTBAA = getTypeInfo(Dst);
+if (!DstTBAA || DstTBAA == AnyTBAA)
+  return AK_Ok;
+  }
+
+  auto IsAncestor = [](const llvm::MDNode *Ancestor,
+   const llvm::MDNode *Descendant) {
+assert(Ancestor != Descendant && "Identical TBAA");
+while (Descendant->getNumOperands() != 1) {
+  Descendant = cast(Descendant->getOperand(1));
+  if (Descendant == Ancestor)
+return true;
+}
+return false;
+  };
+
+  assert(SrcTBAA != AnyTBAA && DstTBAA != AnyTBAA &&

urnathan wrote:

Ah, I found the current placement better -- as a reminder to the code below 
that that particular condition did not need to be handled.  The assert got 
added explicitly when I needed that reminder!

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits


@@ -2026,6 +2027,137 @@ static TryCastResult TryConstCast(Sema &Self, 
ExprResult &SrcExpr,
   return TC_Success;
 }
 
+// We're dereferencing E, either by turning into an RValue, or by dereferencing
+// it. Check whether it's a deref of a reinterpret cast that has aliasing
+// issues.
+void Sema::CheckStrictAliasingDeref(Expr const *E, bool IsLValue) {
+  if (Diags.getDiagnosticOptions().StrictAliasing < 3)
+return;
+
+  assert(IsLValue || E->getType()->isAnyPointerType());
+  CastExpr const *CE = nullptr;
+  for (;;) {
+CE = dyn_cast(E->IgnoreParens());
+if (!CE)
+  return;
+
+if (IsLValue || CE->getCastKind() != CK_ArrayToPointerDecay)
+  break;
+
+E = CE->getSubExpr();
+IsLValue = true;
+  }
+
+  if (CE->getCastKind() != (IsLValue ? CK_LValueBitCast : CK_BitCast))
+return;
+
+  if (CE->getSubExpr()->getType()->isVoidPointerType())
+return;
+
+  QualType DestTy = CE->getType();
+  if (!IsLValue)
+DestTy = DestTy->getPointeeType();
+
+  CheckStrictAliasing(CE->getSubExpr(), DestTy, IsLValue, 
CE->getSourceRange());
+}
+
+/// We're building a cast from E to pointer type DestType. If ISLValueCast is
+/// true, DestType is the pointer equivalent of the reference type we're 
casting
+/// to.
+void Sema::CheckStrictAliasingCast(Expr const *E, QualType DestType,
+   bool IsLValueCast, SourceRange Range) {
+  if (Diags.getDiagnosticOptions().StrictAliasing < 1 ||

urnathan wrote:

Heh, that's amusing :)  this started as a switch, and then changed when I found 
the switch to be line noise..

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-06 Thread Clement Courbet via cfe-commits


@@ -261,21 +262,27 @@ void 
UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
  this);
 }
 
+UnnecessaryCopyInitialization::CheckContext::CheckContext(

legrosbuffle wrote:

Given that we are deriving `IssueFix`, `IsVarUnused`, `IsVarOnlyUsedAsConst` 
from `Var`, `BlockStmt`, ... it sounds natural to have a ctor there. Otherwise 
we risk creating a `CheckContext` in an invalid state.

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-06 Thread Clement Courbet via cfe-commits


@@ -290,69 +296,72 @@ void UnnecessaryCopyInitialization::check(
   // instantiations where the types differ and rely on implicit conversion 
would
   // no longer compile if we switched to a reference.
   if (differentReplacedTemplateParams(
-  NewVar->getType(), constructorArgumentType(OldVar, Result.Nodes),
+  Context.Var.getType(), constructorArgumentType(OldVar, Result.Nodes),
   *Result.Context))
 return;
 
   if (OldVar == nullptr) {
-handleCopyFromMethodReturn(*NewVar, *BlockStmt, *Stmt, IssueFix, ObjectArg,
-   *Result.Context);
+// `auto NewVar = functionCall();`
+handleCopyFromMethodReturn(Context, ObjectArg);
   } else {
-handleCopyFromLocalVar(*NewVar, *OldVar, *BlockStmt, *Stmt, IssueFix,
-   *Result.Context);
+// `auto NewVar = OldVar;`
+handleCopyFromLocalVar(Context, *OldVar);
   }
 }
 
-void UnnecessaryCopyInitialization::makeDiagnostic(
-DiagnosticBuilder Diagnostic, const VarDecl &Var, const Stmt &BlockStmt,
-const DeclStmt &Stmt, ASTContext &Context, bool IssueFix) {
-  const bool IsVarUnused = isVariableUnused(Var, BlockStmt, Context);
-  Diagnostic << &Var << IsVarUnused;
-  if (!IssueFix)
-return;
-  if (IsVarUnused)
-recordRemoval(Stmt, Context, Diagnostic);
-  else
-recordFixes(Var, Context, Diagnostic);
-}
-
 void UnnecessaryCopyInitialization::handleCopyFromMethodReturn(
-const VarDecl &Var, const Stmt &BlockStmt, const DeclStmt &Stmt,
-bool IssueFix, const VarDecl *ObjectArg, ASTContext &Context) {
-  bool IsConstQualified = Var.getType().isConstQualified();
-  if (!IsConstQualified && !isOnlyUsedAsConst(Var, BlockStmt, Context))
+const CheckContext &Ctx, const VarDecl *ObjectArg) {
+  bool IsConstQualified = Ctx.Var.getType().isConstQualified();
+  if (!IsConstQualified && !Ctx.IsVarOnlyUsedAsConst)
 return;
   if (ObjectArg != nullptr &&
-  !isInitializingVariableImmutable(*ObjectArg, BlockStmt, Context,
+  !isInitializingVariableImmutable(*ObjectArg, Ctx.BlockStmt, Ctx.ASTCtx,
ExcludedContainerTypes))
 return;
-
-  auto Diagnostic =
-  diag(Var.getLocation(),
-   "the %select{|const qualified }0variable %1 is copy-constructed "
-   "from a const reference%select{"
-   "%select{ but is only used as const reference|}0"
-   "| but is never used}2; consider "
-   "%select{making it a const reference|removing the statement}2")
-  << IsConstQualified;
-  makeDiagnostic(std::move(Diagnostic), Var, BlockStmt, Stmt, Context,
- IssueFix);
+  diagnoseCopyFromMethodReturn(Ctx, ObjectArg);
 }
 
 void UnnecessaryCopyInitialization::handleCopyFromLocalVar(
-const VarDecl &Var, const VarDecl &OldVar, const Stmt &BlockStmt,
-const DeclStmt &Stmt, bool IssueFix, ASTContext &Context) {
-  if (!isOnlyUsedAsConst(Var, BlockStmt, Context) ||
-  !isInitializingVariableImmutable(OldVar, BlockStmt, Context,
+const CheckContext &Ctx, const VarDecl &OldVar) {
+  if (!Ctx.IsVarOnlyUsedAsConst ||
+  !isInitializingVariableImmutable(OldVar, Ctx.BlockStmt, Ctx.ASTCtx,
ExcludedContainerTypes))
 return;
-  auto Diagnostic = diag(Var.getLocation(),
- "local copy %1 of the variable %0 is never modified"
- "%select{| and never used}2; consider "
- "%select{avoiding the copy|removing the statement}2")
-<< &OldVar;
-  makeDiagnostic(std::move(Diagnostic), Var, BlockStmt, Stmt, Context,
- IssueFix);
+  diagnoseCopyFromLocalVar(Ctx, OldVar);
+}
+
+void UnnecessaryCopyInitialization::diagnoseCopyFromMethodReturn(
+const CheckContext &Ctx, const VarDecl *ObjectArg) {

legrosbuffle wrote:

Thanks for the catch, this is a leftover from the previous iteration. Removed. 

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-06 Thread Clement Courbet via cfe-commits


@@ -32,14 +32,34 @@ class UnnecessaryCopyInitialization : public ClangTidyCheck 
{
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
 
+protected:
+  // A helper to manipulate the state common to
+  // `CopyFromMethodReturn` and `CopyFromLocalVar`.
+  struct CheckContext {
+CheckContext(const ast_matchers::MatchFinder::MatchResult &Result);
+const VarDecl &Var;
+const Stmt &BlockStmt;
+const DeclStmt &VarDeclStmt;
+clang::ASTContext &ASTCtx;
+const bool IssueFix;
+const bool IsVarUnused;
+const bool IsVarOnlyUsedAsConst;
+  };
+
+  // Create diagnostics. These are virtual so that derived classes can change
+  // behaviour.
+  virtual void diagnoseCopyFromMethodReturn(const CheckContext &Ctx,

legrosbuffle wrote:

`ObjectArg` is a pointer because it can be null (unlike other variables, which 
are always non-null. Anyway, this is no longer provided as pre the previous 
comment.

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits

urnathan wrote:

> Making Sema pull the TBAA info out of clang/lib/CodeGen is a layering 
> violation (and probably breaks if we aren't actually generating code). If we 
> need some notion of "aliasing" in Sema, we should pull the relevant code into 
> clang/lib/AST.

That's unfortunate.  The code will not call the TBAA stuff if the code 
generator doesn't provide that predicate -- so if not generating optimized code 
the warning is inactive.  This is the same as with GCC btw. To be clear what's 
exposed is a new predicate allowing querying of type conversion's TBAAness -- 
the representations of TBAA etc are not exposed.  The CodeGen TBAA machinery 
builds on llvm's aliasing MDNodes. It would seem a large task to replicate that 
in AST (and I presume propagating llvm's bits further into AST is even worse?)

> I don't have any experience with this warning, so I'm not sure how effective 
> it is at detecting issues; do a significant fraction of issues actually show 
> up at a pure syntactic level? Do you have any idea what false positive rate 
> we should expect?

I think at level 3 the false positive rate is very low. Given GCC's extended 
this over the years from the simple check I had (IIRC any reinterpret_cast 
between pointers/references to TBAA incompatible types) to the semantics it has 
now suggests the warning is useful. and the level 3 default is satisfactory. 
But I don't have hard data.

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits

urnathan wrote:

> FWIW the GCC doc is 
> https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstrict-aliasing_003dn
>  It says for Level 3 "If optimization is enabled, it also runs in the back 
> end, where it deals with multiple statement cases using flow-sensitive 
> points-to information."
> 
> Do you know how it works? Any example?

I do not now how it works -- didn't go poking there.  Neither do I have 
examples.

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits

urnathan wrote:

> Thank you for your efforts! I scratched the surface a bit; not qualified to 
> do an in-depth review. Can you also add a release note?

Thanks for your comments.  A release note is added.

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits

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


[clang] Move documentation about -verify from a header to public docs (PR #73694)

2023-12-06 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> @AaronBallman After moving the docs, none of the code blocks are rendering: 
> https://clang.llvm.org/docs/InternalsManual.html#verifying-diagnostics

huh? there are zero sphinx diagnostics about the blocks, so that's exciting.

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


[clang] Move documentation about -verify from a header to public docs (PR #73694)

2023-12-06 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

Neato! `.. code-block: c++` should be: `.. code-block:: c++` -- did someone 
disable sphinx diagnostics or something? That should have been diagnosed...

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


[clang] [clang] Catch missing format attributes (PR #70024)

2023-12-06 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovicsyrmia updated 
https://github.com/llvm/llvm-project/pull/70024

From 9d49cf51be0ad67f57c862ef70221d37c727033f Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 13 Oct 2023 14:45:15 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/docs/ReleaseNotes.rst   |  4 +-
 clang/include/clang/Basic/DiagnosticGroups.td |  2 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 clang/include/clang/Sema/Sema.h   |  4 ++
 clang/lib/Sema/SemaChecking.cpp   |  4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 65 +++
 clang/test/Sema/attr-format-missing.c | 58 +
 7 files changed, 137 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9cc2a72f4c864..1ca055f65f211 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -65,7 +65,9 @@ Improvements to Clang's diagnostics
 ^^^
 - We now generate a diagnostic for signed integer overflow due to unary minus
   in a non-constant expression context. This fixes
-  `Issue 31643 `_
+  `Issue 31643 `_.
+- We now generate a diagnostic for missing format attributes
+  `Issue 60718 `_.
 
 Non-comprehensive list of changes in this release
 -
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 17fdcffa2d427..b8b77df84beb2 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -482,7 +482,7 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
+def MissingFormatAttribute: DiagGroup<"missing-format-attribute">;
 def : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6d6f474f6dcda..3cd2270b2fc41 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -936,6 +936,9 @@ def err_opencl_invalid_param : Error<
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
 def warn_enum_value_overflow : Warning<"overflow in enumeration value">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup, DefaultIgnore;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 741c2503127af..064506e709603 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10615,6 +10615,10 @@ class Sema final {
 ChangedStateAtExit
   };
 
+  void DiagnoseMissingFormatAttributes(const FunctionDecl *FDecl,
+   ArrayRef Args,
+   SourceLocation Loc);
+
   void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind,
  SourceLocation IncludeLoc);
   void DiagnoseUnterminatedPragmaAlignPack();
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4602284309491..d3ac6cb519c56 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -6014,8 +6014,10 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 }
   }
 
-  if (FD)
+  if (FD) {
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
+DiagnoseMissingFormatAttributes(FD, Args, Range.getBegin());
+  }
 }
 
 /// CheckConstructorCall - Check a constructor call for correctness and safety
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1a0bfb3d91bcc..87235a2975610 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6849,6 +6849,71 @@ static void handleSwiftAsyncAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
 checkSwiftAsyncErrorBlock(S, D, ErrorAttr, AsyncAttr);
 }
 
+// Warn if parent function misses format attribute. Parent function misses
+// format attribute if there is an argument format string forwarded to calling
+// function with format attribute, parent function has a parameter which is
+// either char or

[clang] a9673bd - Fix code blocks so that they render properly

2023-12-06 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-12-06T07:41:31-05:00
New Revision: a9673bd1ca217e46800f3c2b705c1bed01fdc457

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

LOG: Fix code blocks so that they render properly

It's rather disturbing that malformed syntax does not generate any
warnings or errors when building either locally or on the bots.

Added: 


Modified: 
clang/docs/InternalsManual.rst

Removed: 




diff  --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst
index f8e3da5f97368..4994b3ffa6ebb 100644
--- a/clang/docs/InternalsManual.rst
+++ b/clang/docs/InternalsManual.rst
@@ -3375,7 +3375,7 @@ truncated text instead.)
 Here's an example of the most commonly used way to specify expected
 diagnostics:
 
-.. code-block: c++
+.. code-block:: c++
 
   int A = B; // expected-error {{use of undeclared identifier 'B'}}
 
@@ -3385,7 +3385,7 @@ more readable, you can use slash-newline to separate out 
the diagnostics.
 Alternatively, it is possible to specify the line on which the diagnostic
 should appear by appending ``@`` to ``expected-``, for example:
 
-.. code-block: c++
+.. code-block:: c++
 
   #warning some text
   // expected-warning@10 {{some text}}
@@ -3398,7 +3398,7 @@ header file, it may be beneficial to be able to declare 
the file in which the
 diagnostic will appear, rather than placing the ``expected-*`` directive in the
 actual file itself. This can be done using the following syntax:
 
-.. code-block: c++
+.. code-block:: c++
 
   // expected-error@path/include.h:15 {{error message}}
 
@@ -3413,7 +3413,7 @@ diagnostic can instead be indicated by a marker of the 
form ``#``.
 Markers are specified by including them in a comment, and then referenced by
 appending the marker to the diagnostic with ``@#``, as with:
 
-.. code-block: c++
+.. code-block:: c++
 
   #warning some text  // #1
   // ... other code ...
@@ -3428,14 +3428,14 @@ syntax is ``expected-  {{diag text}}``, where 
 is one of
 integer. This allows the diagnostic to appear as many times as specified. For
 example:
 
-.. code-block: c++
+.. code-block:: c++
 
   void f(); // expected-note 2 {{previous declaration is here}}
 
 Where the diagnostic is expected to occur a minimum number of times, this can
 be specified by appending a ``+`` to the number. For example:
 
-.. code-block: c++
+.. code-block:: c++
 
   void f(); // expected-note 0+ {{previous declaration is here}}
   void g(); // expected-note 1+ {{previous declaration is here}}
@@ -3445,13 +3445,13 @@ swallowed if it occurs, but will not generate an error 
if it does not occur. In
 the second example, the diagnostic must occur at least once. As a short-hand,
 "one or more" can be specified simply by ``+``. For example:
 
-.. code-block: c++
+.. code-block:: c++
 
   void g(); // expected-note + {{previous declaration is here}}
 
 A range can also be specified by ``-``. For example:
 
-.. code-block: c++
+.. code-block:: c++
 
   void f(); // expected-note 0-1 {{previous declaration is here}}
 
@@ -3460,13 +3460,13 @@ In this example, the diagnostic may appear only once, 
if at all.
 Regex matching mode may be selected by appending ``-re`` to the diagnostic type
 and including regexes wrapped in double curly braces in the directive, such as:
 
-.. code-block: c++
+.. code-block:: text
 
   expected-error-re {{format specifies type 'wchar_t **' (aka '{{.+}}')}}
 
 Examples matching error: "variable has incomplete type 'struct s'"
 
-.. code-block: c++
+.. code-block:: c++
 
   // expected-error {{variable has incomplete type 'struct s'}}
   // expected-error {{variable has incomplete type}}



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


[flang] [llvm] [clang-tools-extra] [clang] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-12-06 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/70917

>From 0e98aa7ca15b05b91813eaeeb6ae1305e5f5384d Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:49:13 +
Subject: [PATCH 01/16] GETLOG runtime and extension implementation: get login
 username

Get login username, ussage:
CHARACTER(32) :: login
CALL getlog(login)
WRITE(*,*) login
---
 flang/docs/Intrinsics.md  |  2 +-
 .../Optimizer/Builder/Runtime/RTBuilder.h |  8 
 flang/include/flang/Runtime/command.h |  6 +++
 flang/include/flang/Runtime/extensions.h  |  2 +
 flang/runtime/command.cpp | 40 +++
 flang/runtime/extensions.cpp  |  6 +++
 flang/unittests/Runtime/CommandTest.cpp   | 15 ++-
 7 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e55..cfe5dcd141e98 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, GETLOG, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, 
RANDOM_SEED, SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h 
b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index b2774263e7a31..830df7ad006b5 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -62,6 +62,14 @@ using FuncTypeBuilderFunc = mlir::FunctionType 
(*)(mlir::MLIRContext *);
 /// standard type `i32` when `sizeof(int)` is 4.
 template 
 static constexpr TypeBuilderFunc getModel();
+
+template <>
+constexpr TypeBuilderFunc getModel() {
+  return [](mlir::MLIRContext *context) -> mlir::Type {
+return mlir::IntegerType::get(context, 8 * sizeof(unsigned int));
+  };
+}
+
 template <>
 constexpr TypeBuilderFunc getModel() {
   return [](mlir::MLIRContext *context) -> mlir::Type {
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec62893905454..1c212ef61697c 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -47,6 +47,12 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name,
 bool trim_name = true, const Descriptor *errmsg = nullptr,
 const char *sourceFile = nullptr, int line = 0);
 }
+
+// Try to get the name of current user
+// Returns a STATUS as described in the standard.
+std::int32_t RTNAME(GetLog)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 } // namespace Fortran::runtime
 
 #endif // FORTRAN_RUNTIME_COMMAND_H_
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb..d199d5e387b86 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -28,5 +28,7 @@ std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t &n, std::int8_t *arg, std::int64_t length);
 
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *name, std::int64_t length);
+
 } // extern "C"
 #endif // FORTRAN_RUNTIME_EXTENSIONS_H_
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e57..6b2f313e227a1 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -15,6 +15,30 @@
 #include 
 #include 
 
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+
+#include  // UNLEN=256
+
+inline char *getlogin() {
+  char *username = NULL;
+  DWORD size = UNLEN + 1; // Constant for the maximum username length
+  username = (char *)malloc(size);
+
+  if (GetUserName(username, &size)) {
+// Username 

[clang] e8ce188 - Fix a cross reference

2023-12-06 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-12-06T07:49:03-05:00
New Revision: e8ce1889eee83eb03fbd8d2dc1627f0e97fd26f0

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

LOG: Fix a cross reference

Instead of linking to the doxygen documentation, link to the new sphinx
documentation instead.

Added: 


Modified: 
clang/docs/InternalsManual.rst

Removed: 




diff  --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst
index 4994b3ffa6ebb..05fadf5a03446 100644
--- a/clang/docs/InternalsManual.rst
+++ b/clang/docs/InternalsManual.rst
@@ -477,9 +477,8 @@ mode.  Instead of formatting and printing out the 
diagnostics, this
 implementation just captures and remembers the diagnostics as they fly by.
 Then ``-verify`` compares the list of produced diagnostics to the list of
 expected ones.  If they disagree, it prints out its own output.  Full
-documentation for the ``-verify`` mode can be found in the Clang API
-documentation for `VerifyDiagnosticConsumer
-`_.
+documentation for the ``-verify`` mode can be found at
+:ref:`verifying-diagnostics`.
 
 There are many other possible implementations of this interface, and this is
 why we prefer diagnostics to pass down rich structured information in
@@ -3314,6 +3313,8 @@ Testing
 All functional changes to Clang should come with test coverage demonstrating
 the change in behavior.
 
+.. _verifying-diagnostics:
+
 Verifying Diagnostics
 ^
 Clang ``-cc1`` supports the ``-verify`` command line option as a way to



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


[clang] Move documentation about -verify from a header to public docs (PR #73694)

2023-12-06 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> It would also be nice to fix the link to full `-verify` docs in 
> https://clang.llvm.org/docs/InternalsManual.html#the-diagnosticconsumer-interface

Done.

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > FWIW the GCC doc is 
> > https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstrict-aliasing_003dn
> >  It says for Level 3 "If optimization is enabled, it also runs in the back 
> > end, where it deals with multiple statement cases using flow-sensitive 
> > points-to information."
> > Do you know how it works? Any example?
> 
> I do not now how it works -- didn't go poking there. Neither do I have 
> examples.

My understanding (which could be totally wrong) is that the logic for when to 
emit the level 3 diagnostics rests mostly in the optimizer passes. This is not 
something I think Clang should emulate as it creates a very poor user 
experience in practice (not just with strict aliasing diagnostics -- I don't 
think *any* diagnostics other than remarks should be emitted based on LLVM 
optimization decisions aside from the `error` and `warning` attributes which 
are special circumstances).

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-06 Thread Clement Courbet via cfe-commits

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Vlad Serebrennikov via cfe-commits


@@ -498,3 +498,137 @@ 
CodeGenTBAA::mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo,
   // access type regardless of their base types.
   return TBAAAccessInfo::getMayAliasInfo();
 }
+
+// Determine the aliasing kind bit-converting from type Src to type Dst.
+CodeGenTBAA::AliasingKind CodeGenTBAA::getAliasingKind(QualType &Dst,
+   QualType &Src) {
+  assert(!Src->isVoidType() && !Dst->isVoidType());
+  if (TypeHasMayAlias(Src) || TypeHasMayAlias(Dst))
+return AK_Ok;
+
+  Src = QualType{Src->getBaseElementTypeUnsafe(), 0};
+  Dst = QualType{Dst->getBaseElementTypeUnsafe(), 0};
+
+  auto *SrcDecl = Src->getAsRecordDecl();
+  auto *DstDecl = Dst->getAsRecordDecl();
+
+  const llvm::MDNode *AnyTBAA = getChar();
+  const llvm::MDNode *SrcTBAA = nullptr;
+  const llvm::MDNode *DstTBAA = nullptr;
+
+  if (!SrcDecl) {
+SrcTBAA = getTypeInfo(Src);
+if (!SrcTBAA || SrcTBAA == AnyTBAA)
+  return AK_Ok;
+  }
+  if (!DstDecl) {
+DstTBAA = getTypeInfo(Dst);
+if (!DstTBAA || DstTBAA == AnyTBAA)
+  return AK_Ok;
+  }
+
+  auto IsAncestor = [](const llvm::MDNode *Ancestor,
+   const llvm::MDNode *Descendant) {
+assert(Ancestor != Descendant && "Identical TBAA");
+while (Descendant->getNumOperands() != 1) {
+  Descendant = cast(Descendant->getOperand(1));
+  if (Descendant == Ancestor)
+return true;
+}
+return false;
+  };
+
+  assert(SrcTBAA != AnyTBAA && DstTBAA != AnyTBAA &&

Endilll wrote:

Sure, I'm not insisting.

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Vlad Serebrennikov via cfe-commits


@@ -37,6 +38,27 @@ class ASTConsumer {
 
   friend class SemaConsumer;
 
+public:
+  /// Allow type-based aliasing information to be interrogated by the AST
+  /// producer (for diagnostics).
+  class TypeAliasing {

Endilll wrote:

Sorry I didn't make myself clear enough. I thought that `TypeAliasing` exists 
for the sole purpose of providing a scope for unscoped enumeration, so my idea 
was that this whole class can be replaces with a scoped enum.

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Vlad Serebrennikov via cfe-commits


@@ -498,3 +498,137 @@ 
CodeGenTBAA::mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo,
   // access type regardless of their base types.
   return TBAAAccessInfo::getMayAliasInfo();
 }
+
+// Determine the aliasing kind bit-converting from type Src to type Dst.
+CodeGenTBAA::AliasingKind CodeGenTBAA::getAliasingKind(QualType &Dst,
+   QualType &Src) {
+  assert(!Src->isVoidType() && !Dst->isVoidType());
+  if (TypeHasMayAlias(Src) || TypeHasMayAlias(Dst))
+return AK_Ok;
+
+  Src = QualType{Src->getBaseElementTypeUnsafe(), 0};
+  Dst = QualType{Dst->getBaseElementTypeUnsafe(), 0};
+
+  auto *SrcDecl = Src->getAsRecordDecl();
+  auto *DstDecl = Dst->getAsRecordDecl();
+
+  const llvm::MDNode *AnyTBAA = getChar();
+  const llvm::MDNode *SrcTBAA = nullptr;
+  const llvm::MDNode *DstTBAA = nullptr;
+
+  if (!SrcDecl) {
+SrcTBAA = getTypeInfo(Src);
+if (!SrcTBAA || SrcTBAA == AnyTBAA)

Endilll wrote:

Are you sure `signed char` is allowed to alias everything, like `char` and 
`unsigned char`? It's not there in the strict aliasing rule.

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits


@@ -128,6 +128,10 @@ class DiagnosticOptions : public 
RefCountedBase{
   /// whether -Wsystem-headers is enabled on a per-module basis.
   std::vector SystemHeaderWarningsModules;
 
+  /// Level of scrutiny reinterpret_casts get for type-unsafe aliasing
+  /// checks. Requires an ASTConsumer that provides TBAA information.
+  unsigned StrictAliasing;

urnathan wrote:

I was misled by the -Wundef-prefix pattern that I followed.  Should have looked 
closer and found the DiagnosticOptions.def file.

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


[clang-tools-extra] [clang] [flang] [llvm] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-12-06 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/70917

>From 0e98aa7ca15b05b91813eaeeb6ae1305e5f5384d Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:49:13 +
Subject: [PATCH 01/17] GETLOG runtime and extension implementation: get login
 username

Get login username, ussage:
CHARACTER(32) :: login
CALL getlog(login)
WRITE(*,*) login
---
 flang/docs/Intrinsics.md  |  2 +-
 .../Optimizer/Builder/Runtime/RTBuilder.h |  8 
 flang/include/flang/Runtime/command.h |  6 +++
 flang/include/flang/Runtime/extensions.h  |  2 +
 flang/runtime/command.cpp | 40 +++
 flang/runtime/extensions.cpp  |  6 +++
 flang/unittests/Runtime/CommandTest.cpp   | 15 ++-
 7 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e55..cfe5dcd141e98 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, GETLOG, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, 
RANDOM_SEED, SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h 
b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index b2774263e7a31..830df7ad006b5 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -62,6 +62,14 @@ using FuncTypeBuilderFunc = mlir::FunctionType 
(*)(mlir::MLIRContext *);
 /// standard type `i32` when `sizeof(int)` is 4.
 template 
 static constexpr TypeBuilderFunc getModel();
+
+template <>
+constexpr TypeBuilderFunc getModel() {
+  return [](mlir::MLIRContext *context) -> mlir::Type {
+return mlir::IntegerType::get(context, 8 * sizeof(unsigned int));
+  };
+}
+
 template <>
 constexpr TypeBuilderFunc getModel() {
   return [](mlir::MLIRContext *context) -> mlir::Type {
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec62893905454..1c212ef61697c 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -47,6 +47,12 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name,
 bool trim_name = true, const Descriptor *errmsg = nullptr,
 const char *sourceFile = nullptr, int line = 0);
 }
+
+// Try to get the name of current user
+// Returns a STATUS as described in the standard.
+std::int32_t RTNAME(GetLog)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 } // namespace Fortran::runtime
 
 #endif // FORTRAN_RUNTIME_COMMAND_H_
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb..d199d5e387b86 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -28,5 +28,7 @@ std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t &n, std::int8_t *arg, std::int64_t length);
 
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *name, std::int64_t length);
+
 } // extern "C"
 #endif // FORTRAN_RUNTIME_EXTENSIONS_H_
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e57..6b2f313e227a1 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -15,6 +15,30 @@
 #include 
 #include 
 
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+
+#include  // UNLEN=256
+
+inline char *getlogin() {
+  char *username = NULL;
+  DWORD size = UNLEN + 1; // Constant for the maximum username length
+  username = (char *)malloc(size);
+
+  if (GetUserName(username, &size)) {
+// Username 

[clang] Add SME2 builtins for pfalse and ptrue (PR #71953)

2023-12-06 Thread Sander de Smalen via cfe-commits


@@ -0,0 +1,34 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+#include 
+
+// CHECK-LABEL: @test_svptrue_c8_attr(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call target("aarch64.svcount") 
@llvm.aarch64.sve.ptrue.c8()
+// CHECK-NEXT:ret target("aarch64.svcount") [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svptrue_c8_attrv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call target("aarch64.svcount") 
@llvm.aarch64.sve.ptrue.c8()
+// CPP-CHECK-NEXT:ret target("aarch64.svcount") [[TMP0]]
+//
+svcount_t test_svptrue_c8_attr(void) __arm_streaming {

sdesmalen-arm wrote:

If you make the intrinsic `IsStreamingCompatible`, you should be able to add 
the RUN lines I think?

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


[clang] Add SME2 builtins for pfalse and ptrue (PR #71953)

2023-12-06 Thread Sander de Smalen via cfe-commits


@@ -1981,6 +1979,11 @@ def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", 
"QcQsQiQl", MergeNone, "aarch64_sv
 defm SVREVD : SInstZPZ<"svrevd", "csilUcUsUiUl", "aarch64_sve_revd">;
 }
 
+let TargetGuard = "sve2p1|sme2" in {
+  def SVPTRUE_COUNT  : SInst<"svptrue_{d}", "}v", "QcQsQiQl", MergeNone, 
"aarch64_sve_ptrue_{d}", [IsOverloadNone, IsStreaming], []>;

sdesmalen-arm wrote:

```suggestion
  def SVPTRUE_COUNT  : SInst<"svptrue_{d}", "}v", "QcQsQiQl", MergeNone, 
"aarch64_sve_ptrue_{d}", [IsOverloadNone, IsStreamingCompatible], []>;
```
As pointed out 
[here](https://github.com/llvm/llvm-project/pull/71927/files#r1395522522), this 
will need an attribute like `IsStreamingOrHasSVE2p1`, for which the compiler 
will give a diagnostic when compiling for +sme2 and the function is not in 
streaming mode.

To move this patch forward without that diagnostic, you could make this 
`IsStreamingCompatible` for now. Can you also add a `FIXME` to say we need to 
change this later?

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


[clang] [llvm] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-12-06 Thread Nikita Popov via cfe-commits

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


[clang] [AArch64][SME] Warn when using a streaming builtin from a non-streaming function (PR #74064)

2023-12-06 Thread Sander de Smalen via cfe-commits


@@ -3183,6 +3140,114 @@ bool Sema::CheckSVEBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   return HasError;
 }
 
+static ArmStreamingType getArmStreamingFnType(const FunctionDecl *FD) {
+  if (FD->hasAttr())
+return ArmStreaming;
+  if (const auto *T = FD->getType()->getAs()) {
+if (T->getAArch64SMEAttributes() & FunctionType::SME_PStateSMEnabledMask)
+  return ArmStreaming;
+if (T->getAArch64SMEAttributes() & 
FunctionType::SME_PStateSMCompatibleMask)
+  return ArmStreamingCompatible;
+  }
+  return ArmNonStreaming;
+}
+
+static void checkArmStreamingBuiltin(Sema &S, CallExpr *TheCall,
+ const FunctionDecl *FD,
+ ArmStreamingType BuiltinType) {
+  ArmStreamingType FnType = getArmStreamingFnType(FD);
+
+  if (FnType == ArmStreaming && BuiltinType == ArmNonStreaming) {
+S.Diag(TheCall->getBeginLoc(), 
diag::warn_attribute_arm_sm_incompat_builtin)
+<< TheCall->getSourceRange() << "streaming";
+  }
+
+  if (FnType == ArmStreamingCompatible &&
+  BuiltinType != ArmStreamingCompatible) {
+S.Diag(TheCall->getBeginLoc(), 
diag::warn_attribute_arm_sm_incompat_builtin)
+<< TheCall->getSourceRange() << "streaming compatible";
+return;
+  }
+
+  if (FnType == ArmNonStreaming && BuiltinType == ArmStreaming) {
+S.Diag(TheCall->getBeginLoc(), 
diag::warn_attribute_arm_sm_incompat_builtin)
+<< TheCall->getSourceRange() << "non-streaming";
+  }
+}
+
+static bool hasSMEZAState(const FunctionDecl *FD) {
+  if (FD->hasAttr())
+return true;
+  if (const auto *T = FD->getType()->getAs())
+if (T->getAArch64SMEAttributes() & FunctionType::SME_PStateZASharedMask)
+  return true;
+  return false;
+}
+
+static bool hasSMEZAState(unsigned BuiltinID) {
+  switch (BuiltinID) {
+  default:
+return false;
+#define GET_SME_BUILTIN_HAS_ZA_STATE
+#include "clang/Basic/arm_sme_builtins_za_state.inc"
+#undef GET_SME_BUILTIN_HAS_ZA_STATE
+  }
+}
+
+bool Sema::CheckSMEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
+  if (const FunctionDecl *FD = getCurFunctionDecl()) {
+std::optional BuiltinType;
+
+switch (BuiltinID) {
+default:
+  break;
+#define GET_SME_STREAMING_ATTRS
+#include "clang/Basic/arm_sme_streaming_attrs.inc"
+#undef GET_SME_STREAMING_ATTRS
+}
+
+if (BuiltinType)
+  checkArmStreamingBuiltin(*this, TheCall, FD, *BuiltinType);
+
+if (hasSMEZAState(BuiltinID) && !hasSMEZAState(FD))
+  Diag(TheCall->getBeginLoc(),
+   diag::warn_attribute_arm_za_builtin_no_za_state)
+  << TheCall->getSourceRange();
+  }
+
+  // Range check SME intrinsics that take immediate values.
+  SmallVector, 3> ImmChecks;
+
+  switch (BuiltinID) {
+  default:
+return false;
+#define GET_SME_IMMEDIATE_CHECK
+#include "clang/Basic/arm_sme_sema_rangechecks.inc"
+#undef GET_SME_IMMEDIATE_CHECK
+  }
+
+  return ParseSVEImmChecks(TheCall, ImmChecks);
+}
+
+bool Sema::CheckSVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {

sdesmalen-arm wrote:

Can you commit the change to move the immediate checks to `ParseSVEImmChecks` 
as an NFC patch and rebase this one?

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


[clang] [AArch64][SME] Warn when using a streaming builtin from a non-streaming function (PR #74064)

2023-12-06 Thread Sander de Smalen via cfe-commits


@@ -3172,6 +3117,18 @@ bool Sema::CheckSVEBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   if (SemaBuiltinConstantArgRange(TheCall, ArgNum, 0, 255))
 HasError = true;
   break;
+case SVETypeFlags::ImmCheck1_1:

sdesmalen-arm wrote:

Why have these case statements moved?

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


[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits

https://github.com/urnathan updated 
https://github.com/llvm/llvm-project/pull/74155

>From 89c05618bb75fd073343046f3b54bde5f2254719 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Wed, 15 Nov 2023 15:27:16 -0500
Subject: [PATCH 1/6] [clang] Strict aliasing warning ala GCC [PR50066]

This implements -Wstrict-aliasing(=[123])? along the same lines as
GCC. It's not 100% the same for reasons expanded on below. The default
is level 3, and I have verified that bootstrapping does not trigger
any warnings (just like building with GCC).

As with GCC, higher levels result in fewer warnings, reducing the
number of false positives at the cost of missing (some) potential
cases. Unlike GCC, this is entirely in the FE, we do not propagate any
checking into the IR (so there are cases GCC will detect we do not, I
have not encountered any). GCC's documentation is not very specific
about which cases are detected. I examined GCC's source code to reverse
engineer the algorithm[*], and as can be seen from the testcases, noted
GCC's behaviour.

The strict aliasing check relies on TBAA. LLVM's representation is
semantically different to GCCs for structured types. I have tried to
keep with the spirit of the warning.

The warning checks reinterpret_casts that are CK_BitCast or
CK_LValueBitCast. It also checks C-style casts that are equivalent (to
the extent available, as a C-style bitcast could be a well-formed
static cast).

level=1 looks for reinterpret casts from T * to U * (or an lvalue of
type T to U &), where T and U are not TBAA compatible.

level=2 requires the src expression be an lvalue something of
known(ish) static type. I.e a variable, array dereference or member
access.

level=3 requires level 2 and that the resultant pointer is actually
referenced (lvalue->rvalue or lvalue written). Here we can do better
than GCC, which doesn't represent this in the IR -- we merely get a
dereference (and reference types are modeled as pointers with
auto-dereference semantics). There is one exception to this, which is
by-value aggregate arguments. These end up invoking a copy constructor
(passing a reference of course), but are IMHO morally an rvalue -- so
should trigger.

The warning hooks into clang's code-generator's TBAA machinery. For
scalar types the TBAA is straight forwards, comparing LLVM's MDNode
representaion. For record & union types we check if one of the types
is (recursively) the same (or TBAA compatible) as the first direct
base or a field(s) of the record at offset zero (i.e. the first member
of a record, or any members of a union). This covers both C++ and
C-Style inheritance. Also. the member maybe alias_any, or in
ubiquitous-char's alias set, which is also permissible.

The warning is similar to the alignment check that
CheckCompatibleReinterpretCast does, perhaps some merging could occur
if this is accepted?

[*] I implemented what turned into GCC's level=1 way back when.

WIP: adjust tests
---
 clang/include/clang/AST/ASTConsumer.h |   25 +
 clang/include/clang/Basic/DiagnosticGroups.td |6 -
 clang/include/clang/Basic/DiagnosticOptions.h |4 +
 .../clang/Basic/DiagnosticSemaKinds.td|8 +
 clang/include/clang/Driver/Options.td |6 +
 clang/include/clang/Sema/Sema.h   |   11 +
 clang/lib/CodeGen/BackendConsumer.h   |1 +
 clang/lib/CodeGen/CodeGenAction.cpp   |4 +
 clang/lib/CodeGen/CodeGenModule.h |1 +
 clang/lib/CodeGen/CodeGenTBAA.cpp |  134 ++
 clang/lib/CodeGen/CodeGenTBAA.h   |5 +-
 clang/lib/CodeGen/ModuleBuilder.cpp   |2 +
 clang/lib/Frontend/CompilerInvocation.cpp |3 +
 clang/lib/Frontend/FrontendAction.cpp |8 +
 clang/lib/Sema/SemaCast.cpp   |  139 ++
 clang/lib/Sema/SemaExpr.cpp   |   17 +-
 clang/lib/Sema/SemaExprMember.cpp |2 +
 clang/lib/Sema/SemaInit.cpp   |5 +
 clang/test/Misc/warning-flags-tree.c  |4 -
 clang/test/Sema/strict-aliasing-warn.c|  192 +++
 clang/test/SemaCXX/strict-aliasing-warn.cpp   | 1375 +
 21 files changed, 1939 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/Sema/strict-aliasing-warn.c
 create mode 100644 clang/test/SemaCXX/strict-aliasing-warn.cpp

diff --git a/clang/include/clang/AST/ASTConsumer.h 
b/clang/include/clang/AST/ASTConsumer.h
index ebcd8059284d8..d5731ed6adf63 100644
--- a/clang/include/clang/AST/ASTConsumer.h
+++ b/clang/include/clang/AST/ASTConsumer.h
@@ -21,6 +21,7 @@ namespace clang {
   class DeclGroupRef;
   class ASTMutationListener;
   class ASTDeserializationListener; // layering violation because void* is ugly
+  class QualType;
   class SemaConsumer; // layering violation required for safe SemaConsumer
   class TagDecl;
   class VarDecl;
@@ -37,6 +38,27 @@ class ASTConsumer {
 
   friend class SemaConsumer;
 
+public:
+  /// Allow type-based aliasing information to be interrogated by the

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits


@@ -0,0 +1,192 @@
+// RUN: %clang_cc1 %s -O0 -Wstrict-aliasing -S -o %t -verify=quiet
+// RUN: %clang_cc1 %s -O2 -Wstrict-aliasing=0 -S -o %t -verify=quiet
+// RUN: %clang_cc1 %s -O2 -Wno-strict-aliasing -S -o %t -verify=quiet
+// RUN: %clang_cc1 %s -O2 -Wstrict-aliasing=1 -S -o %t 
-verify=level1,level12,level123
+// RUN: %clang_cc1 %s -O2 -Wstrict-aliasing=2 -S -o %t 
-verify=level2,level23,level12,level123
+// RUN: %clang_cc1 %s -O2 -Wstrict-aliasing=3 -S -o %t -verify=level23,level123
+// RUN: %clang_cc1 %s -O2 -Wstrict-aliasing -S -o %t -verify=level23,level123
+// RUN: %clang_cc1 %s -O2 -S -o %t -verify=level23,level123
+
+// quiet-no-diagnostics
+
+#if _LP64
+// These names make more sense on an ilp32 machine
+typedef long INT;
+typedef long long LONG;
+typedef unsigned long UINT;
+#else
+typedef int INT;
+typedef long LONG;
+typedef unsigned int UINT;
+#endif
+typedef short SHORT;
+
+INT ScalarINT;
+INT Ary[2];
+struct {int m;} Struct;
+
+_Complex int CPLx;
+
+void ByVal(long long);
+void ByPtr(void *);
+
+void VarPtr(INT *Ptr) {
+  // GCC: 1
+  // level1-warning@+1{{type-punned pointer might break}}
+  ByPtr((LONG *)(Ptr));
+  // level1-note@-1{{not alias compatible}}
+
+  // GCC:
+  ByPtr((LONG *)((void *)(Ptr)));
+
+  // GCC: 1
+  // level1-warning@+1{{type-punned pointer might break}}
+  ByVal(*(LONG *)(Ptr));
+  // level1-note@-1{{not alias compatible}}
+}
+
+void Object() {
+  // GCC: 1, 2
+  // level2-warning@+2{{type-punned pointer breaks}}
+  // level1-warning@+1{{type-punned pointer might break}}
+  ByPtr((LONG *)(&ScalarINT));
+  // level12-note@-1{{not alias compatible}}
+
+  // GCC:
+  ByPtr((LONG *)((void *)(&ScalarINT)));
+
+  // GCC: 1, 2, 3
+  // level23-warning@+2{{type-punned pointer breaks}}
+  // level1-warning@+1{{type-punned pointer might break}}
+  ByVal(*(LONG *)(&ScalarINT));
+  // level123-note@-1{{not alias compatible}}
+}
+
+// Level 1, 2, 3 - 1, 2, 3
+void DetectedVariants() {
+  // GCC: 1, 2, 3
+  // level23-warning@+2{{type-punned pointer breaks}}
+  // level1-warning@+1{{type-punned pointer might break}}
+  ByVal(*(LONG *)(&Ary[1]));
+  // level123-note@-1{{not alias compatible}}
+
+  // GCC: 1, 2, 3
+  // level23-warning@+2{{type-punned pointer breaks}}
+  // level1-warning@+1{{type-punned pointer might break}}
+  ByVal(*(LONG *)(&Struct.m));
+  // level123-note@-1{{not alias compatible}}
+
+  // GCC: 1, 2, 3
+  // level23-warning@+2{{type-punned pointer breaks}}
+  // level1-warning@+1{{type-punned pointer might break}}
+  ByVal(*(LONG *)(&(&Struct)->m));
+  // level123-note@-1{{not alias compatible}}
+
+  // GCC: 1, 2, 3
+  // level23-warning@+2{{type-punned pointer breaks}}
+  // level1-warning@+1{{type-punned pointer might break}}
+  ByVal(*(LONG *)(&__real__(CPLx)));
+  // level123-note@-1{{not alias compatible}}
+
+  // GCC: 1, 2, 3
+  // level23-warning@+2{{type-punned pointer breaks}}
+  // level1-warning@+1{{type-punned pointer might break}}
+  ByVal(*(LONG *)(&__imag__(CPLx)));
+  // level123-note@-1{{not alias compatible}}
+}
+
+void Ok() {
+  // GCC:
+  ByPtr((UINT *)(&ScalarINT));
+  // GCC:
+  ByPtr((UINT *)((void *)(&ScalarINT)));
+  // GCC:
+  ByVal(*(UINT *)(&ScalarINT));
+}
+
+// Level 1, 2, 3 - 1, 2, 3
+void Parens() {
+  // GCC: 1, 2, 3
+  // level23-warning@+2{{type-punned pointer breaks}}
+  // level1-warning@+1{{type-punned pointer might break}}
+  ByVal(*((LONG *)((&(ScalarINT);
+  // level123-note@-1{{not alias compatible}}
+
+  // GCC: 1, 2, 3
+  // level23-warning@+2{{type-punned pointer breaks}}
+  // level1-warning@+1{{type-punned pointer might break}}
+  ByVal(*((LONG *)((&(Ary[1]);
+  // level123-note@-1{{not alias compatible}}
+}
+
+// Clang models may_alias as a decl attribute, not a type attribute.
+
+typedef int MA __attribute__((may_alias));
+
+void Frob(MA *a) {
+  ByPtr((short *)(a));
+  ByVal(*(short *)(a));
+}
+
+struct Inner { int m; };
+struct Outer1 { struct Inner i; };
+struct Outer2 { struct Outer1 o; };
+struct Inner i;
+struct Outer2 o;
+
+void ByValInner (struct Inner);
+void ByValOuter2 (struct Outer2);
+
+void Inherit() {
+  // Check we see through multiple levels
+  int in;
+
+  ByValOuter2(*(struct Outer2 *)&in);
+  ByValOuter2(*(struct Outer2 *)&i);
+  ByValInner(*(struct Inner *)&o.o);
+  ByValInner(*(struct Inner *)&o);
+  ByVal(*(int *)&o);
+}
+
+// PR 50066
+typedef unsigned char uchar;
+
+void Double(double);
+
+int main() {
+  double d = 2.34;
+  int i[2];
+  Double(d);
+
+  // GCC: 1, 2, 3
+  // level23-warning@+2{{type-punned pointer breaks}}
+  // level1-warning@+1{{type-punned pointer might break}}
+  *(long long *)i =
+  // level123-note@-1{{not alias compatible}}
+
+  // GCC: 1, 2, 3
+  // level23-warning@+2{{type-punned pointer breaks}}
+  // level1-warning@+1{{type-punned pointer might break}}
+  *(long long *)&d;
+  // level123-note@-1{{not alias compatible}}
+
+  // GCC: 1, 2, 3
+  // level23-warning@+2{{type-punned pointer breaks}}
+  // level1-warnin

[clang] [flang] [llvm] [NFC][AMDGPU] Move address space enum to LLVM directory (PR #73944)

2023-12-06 Thread Dominik Adamski via cfe-commits

DominikAdamski wrote:

@lenary Thank you for your input.
@kparzysz @lenary Shall I add all address spaces which are mentioned in [other 
LLVM 
header](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/AMDGPU/AMDGPU.h#L395-L456)?
 Currently I added address spaces which were mentioned in 
[Clang](https://github.com/llvm/llvm-project/pull/73944/files#diff-06ca78b74b85e093d5b7eddd16b24b4781b2025e6e8bf6c035345155c2649a4d)
 . 

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


[clang] [AArch64][SME] Warn when using a streaming builtin from a non-streaming function (PR #74064)

2023-12-06 Thread Sam Tebbs via cfe-commits


@@ -3183,6 +3140,114 @@ bool Sema::CheckSVEBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   return HasError;
 }
 
+static ArmStreamingType getArmStreamingFnType(const FunctionDecl *FD) {
+  if (FD->hasAttr())
+return ArmStreaming;
+  if (const auto *T = FD->getType()->getAs()) {
+if (T->getAArch64SMEAttributes() & FunctionType::SME_PStateSMEnabledMask)
+  return ArmStreaming;
+if (T->getAArch64SMEAttributes() & 
FunctionType::SME_PStateSMCompatibleMask)
+  return ArmStreamingCompatible;
+  }
+  return ArmNonStreaming;
+}
+
+static void checkArmStreamingBuiltin(Sema &S, CallExpr *TheCall,
+ const FunctionDecl *FD,
+ ArmStreamingType BuiltinType) {
+  ArmStreamingType FnType = getArmStreamingFnType(FD);
+
+  if (FnType == ArmStreaming && BuiltinType == ArmNonStreaming) {
+S.Diag(TheCall->getBeginLoc(), 
diag::warn_attribute_arm_sm_incompat_builtin)
+<< TheCall->getSourceRange() << "streaming";
+  }
+
+  if (FnType == ArmStreamingCompatible &&
+  BuiltinType != ArmStreamingCompatible) {
+S.Diag(TheCall->getBeginLoc(), 
diag::warn_attribute_arm_sm_incompat_builtin)
+<< TheCall->getSourceRange() << "streaming compatible";
+return;
+  }
+
+  if (FnType == ArmNonStreaming && BuiltinType == ArmStreaming) {
+S.Diag(TheCall->getBeginLoc(), 
diag::warn_attribute_arm_sm_incompat_builtin)
+<< TheCall->getSourceRange() << "non-streaming";
+  }
+}
+
+static bool hasSMEZAState(const FunctionDecl *FD) {
+  if (FD->hasAttr())
+return true;
+  if (const auto *T = FD->getType()->getAs())
+if (T->getAArch64SMEAttributes() & FunctionType::SME_PStateZASharedMask)
+  return true;
+  return false;
+}
+
+static bool hasSMEZAState(unsigned BuiltinID) {
+  switch (BuiltinID) {
+  default:
+return false;
+#define GET_SME_BUILTIN_HAS_ZA_STATE
+#include "clang/Basic/arm_sme_builtins_za_state.inc"
+#undef GET_SME_BUILTIN_HAS_ZA_STATE
+  }
+}
+
+bool Sema::CheckSMEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
+  if (const FunctionDecl *FD = getCurFunctionDecl()) {
+std::optional BuiltinType;
+
+switch (BuiltinID) {
+default:
+  break;
+#define GET_SME_STREAMING_ATTRS
+#include "clang/Basic/arm_sme_streaming_attrs.inc"
+#undef GET_SME_STREAMING_ATTRS
+}
+
+if (BuiltinType)
+  checkArmStreamingBuiltin(*this, TheCall, FD, *BuiltinType);
+
+if (hasSMEZAState(BuiltinID) && !hasSMEZAState(FD))
+  Diag(TheCall->getBeginLoc(),
+   diag::warn_attribute_arm_za_builtin_no_za_state)
+  << TheCall->getSourceRange();
+  }
+
+  // Range check SME intrinsics that take immediate values.
+  SmallVector, 3> ImmChecks;
+
+  switch (BuiltinID) {
+  default:
+return false;
+#define GET_SME_IMMEDIATE_CHECK
+#include "clang/Basic/arm_sme_sema_rangechecks.inc"
+#undef GET_SME_IMMEDIATE_CHECK
+  }
+
+  return ParseSVEImmChecks(TheCall, ImmChecks);
+}
+
+bool Sema::CheckSVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {

SamTebbs33 wrote:

Sure thing

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


[clang] [AArch64][SME] Warn when using a streaming builtin from a non-streaming function (PR #74064)

2023-12-06 Thread Sam Tebbs via cfe-commits


@@ -3172,6 +3117,18 @@ bool Sema::CheckSVEBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   if (SemaBuiltinConstantArgRange(TheCall, ArgNum, 0, 255))
 HasError = true;
   break;
+case SVETypeFlags::ImmCheck1_1:

SamTebbs33 wrote:

I'm actually not sure. When building the compiler was telling me that these 
cases weren't being checked for so I added them. I'm not sure what caused them 
to disappear in the first place. I'll revert this chunk.

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


[clang] [llvm] Irdl (PR #74589)

2023-12-06 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam created 
https://github.com/llvm/llvm-project/pull/74589

None

>From 707f1625a626faae14b8e24f7e3cf10a2ed621ce Mon Sep 17 00:00:00 2001
From: Tom Honermann 
Date: Sun, 24 Sep 2023 22:38:01 -0400
Subject: [PATCH 1/6] [clang][DFP] Add basic builtin type representation for
 decimal floating point types.

This change adds basic type representation support for the decimal
floating point types defined by ISO/IEC TS 18661-2 and adopted for C23.
These types will also serve as the underlying native types for the
library types defined by ISO/IEC TR 24733 and as implemented in
libstdcxx. This change does not include representation support in
LLVM IR, in debugging information, or in C++ mangling for the MS ABI;
such support will be added in later patches.
---
 clang/include/clang/AST/ASTContext.h  |  2 ++
 clang/include/clang/AST/BuiltinTypes.def  | 17 
 clang/include/clang/Basic/TargetInfo.h| 17 
 clang/include/clang/Basic/TokenKinds.def  |  4 +++-
 .../include/clang/Serialization/ASTBitCodes.h |  9 +
 clang/lib/AST/ASTContext.cpp  | 20 +++
 clang/lib/AST/ExprConstant.cpp|  2 ++
 clang/lib/AST/ItaniumMangle.cpp   |  9 +
 clang/lib/AST/MicrosoftMangle.cpp |  6 ++
 clang/lib/AST/NSAPI.cpp   |  3 +++
 clang/lib/AST/PrintfFormatString.cpp  |  4 
 clang/lib/AST/Type.cpp|  7 +++
 clang/lib/AST/TypeLoc.cpp |  3 +++
 clang/lib/Basic/TargetInfo.cpp|  5 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  7 +++
 clang/lib/CodeGen/CodeGenTypes.cpp|  8 
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  3 +++
 clang/lib/Index/USRGeneration.cpp |  6 ++
 clang/lib/Sema/SemaType.cpp   | 16 ++-
 clang/lib/Serialization/ASTCommon.cpp |  9 +
 clang/lib/Serialization/ASTReader.cpp |  9 +
 clang/test/Sema/types.c   |  4 +++-
 clang/tools/libclang/CIndex.cpp   |  1 +
 23 files changed, 168 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 4ee32c76a95d8..f862456797b5f 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1098,6 +1098,8 @@ class ASTContext : public RefCountedBase {
   CanQualType SatShortFractTy, SatFractTy, SatLongFractTy;
   CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy,
   SatUnsignedLongFractTy;
+  // ISO/IEC TS 18661-2, ISO/IEC TR 24733, and C23 decimal floating-point.
+  CanQualType DecimalFloat32Ty, DecimalFloat64Ty, DecimalFloat128Ty;
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
   CanQualType BFloat16Ty;
   CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index c04f6f6f12719..3a0f78fb6a33f 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -44,6 +44,10 @@
 #define FLOATING_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId)
 #endif
 
+#ifndef DECIMAL_FLOATING_TYPE
+#define DECIMAL_FLOATING_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId)
+#endif
+
 #ifndef PLACEHOLDER_TYPE
 #define PLACEHOLDER_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId)
 #endif
@@ -221,6 +225,18 @@ FLOATING_TYPE(Float128, Float128Ty)
 // '__ibm128'
 FLOATING_TYPE(Ibm128, Ibm128Ty)
 
+//===- Decimal floating point types 
---===//
+// ISO/IEC TS 18661-2, ISO/IEC TR 24733, and C23 decimal floating-point.
+
+// '_Decimal32'
+DECIMAL_FLOATING_TYPE(DecimalFloat32, DecimalFloat32Ty)
+
+// '_Decimal64'
+DECIMAL_FLOATING_TYPE(DecimalFloat64, DecimalFloat64Ty)
+
+// '_Decimal128'
+DECIMAL_FLOATING_TYPE(DecimalFloat128, DecimalFloat128Ty)
+
 //===- Language-specific types 
===//
 
 // This is the type of C++0x 'nullptr'.
@@ -336,6 +352,7 @@ LAST_BUILTIN_TYPE(OMPIterator)
 #undef SHARED_SINGLETON_TYPE
 #undef PLACEHOLDER_TYPE
 #undef FLOATING_TYPE
+#undef DECIMAL_FLOATING_TYPE
 #undef SIGNED_TYPE
 #undef UNSIGNED_TYPE
 #undef BUILTIN_TYPE
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 61be52149341f..ddf166c971fec 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -95,6 +95,11 @@ struct TransferrableTargetInfo {
   unsigned char LongLongWidth, LongLongAlign;
   unsigned char Int128Align;
 
+  // Decimal floating-point bit widths and alignment.
+  unsigned char DecimalFloat32Width, DecimalFloat32Align;
+  unsigned char DecimalFloat64Width, DecimalFloat64Align;
+  unsigned char DecimalFloat128Width, DecimalFloat128Align;
+
   // Fixed point bit widths
   unsigned char ShortAcc

[clang] [llvm] [SME2] Add LUTI2 and LUTI4 double Builtins and Intrinsics (PR #73305)

2023-12-06 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm approved this pull request.

LGTM

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


[clang] [llvm] Irdl (PR #74589)

2023-12-06 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 50c66600b8c54b24a73e37e0305dd3bf26c19859 
7b404ff8ac18a28d161e1deee35ae2e6a053dfe6 -- 
clang/test/Driver/dfp-enablement-lang.c 
clang/test/Driver/dfp-enablement-target.c clang/test/Sema/dfp-types.c 
clang/test/SemaCXX/dfp-types.cpp clang/include/clang/AST/ASTContext.h 
clang/include/clang/AST/Type.h clang/include/clang/Basic/TargetInfo.h 
clang/include/clang/Basic/TargetOptions.h 
clang/include/clang/Serialization/ASTBitCodes.h clang/lib/AST/ASTContext.cpp 
clang/lib/AST/ExprConstant.cpp clang/lib/AST/ItaniumMangle.cpp 
clang/lib/AST/MicrosoftMangle.cpp clang/lib/AST/NSAPI.cpp 
clang/lib/AST/PrintfFormatString.cpp clang/lib/AST/Type.cpp 
clang/lib/AST/TypeLoc.cpp clang/lib/Basic/TargetInfo.cpp 
clang/lib/Basic/Targets.cpp clang/lib/Basic/Targets/OSTargets.h 
clang/lib/Basic/Targets/X86.h clang/lib/CodeGen/BackendUtil.cpp 
clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CodeGenTypes.cpp 
clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/Driver/ToolChains/Clang.cpp 
clang/lib/Frontend/CompilerInstance.cpp clang/lib/Frontend/InitPreprocessor.cpp 
clang/lib/Index/USRGeneration.cpp clang/lib/Sema/SemaChecking.cpp 
clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaType.cpp 
clang/lib/Serialization/ASTCommon.cpp clang/lib/Serialization/ASTReader.cpp 
clang/test/Sema/types.c clang/tools/libclang/CIndex.cpp 
llvm/include/llvm-c/Core.h llvm/include/llvm/Bitcode/LLVMBitCodes.h 
llvm/include/llvm/IR/DataLayout.h llvm/include/llvm/IR/IRBuilder.h 
llvm/include/llvm/IR/Type.h llvm/include/llvm/Target/TargetOptions.h 
llvm/lib/AsmParser/LLLexer.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/IR/AsmWriter.cpp 
llvm/lib/IR/Core.cpp llvm/lib/IR/DataLayout.cpp llvm/lib/IR/LLVMContextImpl.cpp 
llvm/lib/IR/LLVMContextImpl.h llvm/lib/IR/Type.cpp 
llvm/lib/Target/X86/X86TargetMachine.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index f862456797b..eb89c734893 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -197,7 +197,7 @@ class ASTContext : public RefCountedBase {
   mutable std::vector VariableArrayTypes;
   mutable llvm::FoldingSet DependentSizedArrayTypes;
   mutable llvm::FoldingSet
-DependentSizedExtVectorTypes;
+  DependentSizedExtVectorTypes;
   mutable llvm::FoldingSet
   DependentAddressSpaceTypes;
   mutable llvm::FoldingSet VectorTypes;
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 3fcec7b594a..332f83b4542 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2177,7 +2177,7 @@ public:
 
   /// Floating point categories.
   bool isDecimalFloatingType() const;
-   // C23 6.2.5p13 (_Decimal32/64/128)
+  // C23 6.2.5p13 (_Decimal32/64/128)
   bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
// C23 6.2.5p14 (standard + decimal float)
// C23 H.2.4p5  (+interchange +extended FP)
@@ -3095,9 +3095,7 @@ public:
   /// an array with a static size (e.g. int X[static 4]), or an array
   /// with a star size (e.g. int X[*]).
   /// 'static' is only allowed on function parameters.
-  enum ArraySizeModifier {
-Normal, Static, Star
-  };
+  enum ArraySizeModifier { Normal, Static, Star };
 
 private:
   /// The element type of the array.
@@ -3431,7 +3429,6 @@ public:
   QualType ElementType, Expr *SizeExpr);
 };
 
-
 /// Represents a GCC generic vector type. This type is created using
 /// __attribute__((vector_size(n)), where "n" specifies the vector size in
 /// bytes; or from an Altivec __vector or vector declaration.
@@ -3528,8 +3525,8 @@ class DependentVectorType : public Type, public 
llvm::FoldingSetNode {
   SourceLocation Loc;
 
   DependentVectorType(const ASTContext &Context, QualType ElementType,
-   QualType CanonType, Expr *SizeExpr,
-   SourceLocation Loc, VectorType::VectorKind vecKind);
+  QualType CanonType, Expr *SizeExpr, SourceLocation Loc,
+  VectorType::VectorKind vecKind);
 
 public:
   Expr *getSizeExpr() const { return SizeExpr; }
@@ -4758,8 +4755,8 @@ public:
 /// This class is used internally by the ASTContext to manage
 /// canonical, dependent types, only. Clients will only see instances
 /// of this class via TypeOfExprType nodes.
-class DependentTypeOfExprType
-  : public TypeOfExprType, public llvm::FoldingSetNode {
+class DependentTypeOfExprType : public TypeOfExprType,
+public llvm::FoldingSetNode {
   const ASTContext &Context

[clang] [CUDA][Win32] Add `fma(long double,..)` to math forward declares. (PR #73756)

2023-12-06 Thread Evgeny Mankov via cfe-commits


@@ -70,6 +70,9 @@ __DEVICE__ double floor(double);
 __DEVICE__ float floor(float);
 __DEVICE__ double fma(double, double, double);
 __DEVICE__ float fma(float, float, float);
+#ifdef _MSC_VER
+__DEVICE__ long double fma(long double, long double, long double);

emankov wrote:

That is it, it is only a compile-time story, and the situation when the 
successfully compiled code "fails somewhere in ptxas" on runtime would never 
happen till CUDA implementation of `long double fma` appears, or am I missing 
something?

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-06 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle updated 
https://github.com/llvm/llvm-project/pull/73921

>From 851460af6526f175bc34b105a0f5f130a2f1c6b1 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Thu, 30 Nov 2023 11:08:51 +0100
Subject: [PATCH 1/3] [clang-tidy] performance-unnecessary-copy-init

Refactor diagnostic emission and add a hook so that derived checks
can observe for which variables a warning has been emitted.
---
 .../UnnecessaryCopyInitialization.cpp | 73 +--
 .../UnnecessaryCopyInitialization.h   |  7 ++
 2 files changed, 41 insertions(+), 39 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp 
b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
index 990e20400fbfc..a9ef3faf8c343 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -15,6 +15,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/Basic/Diagnostic.h"
 #include 
+#include 
 
 namespace clang::tidy::performance {
 namespace {
@@ -302,6 +303,19 @@ void UnnecessaryCopyInitialization::check(
   }
 }
 
+void UnnecessaryCopyInitialization::makeDiagnostic(
+DiagnosticBuilder Diagnostic, const VarDecl &Var, const Stmt &BlockStmt,
+const DeclStmt &Stmt, ASTContext &Context, bool IssueFix) {
+  const bool IsVarUnused = isVariableUnused(Var, BlockStmt, Context);
+  Diagnostic << &Var << IsVarUnused;
+  if (!IssueFix)
+return;
+  if (IsVarUnused)
+recordRemoval(Stmt, Context, Diagnostic);
+  else
+recordFixes(Var, Context, Diagnostic);
+}
+
 void UnnecessaryCopyInitialization::handleCopyFromMethodReturn(
 const VarDecl &Var, const Stmt &BlockStmt, const DeclStmt &Stmt,
 bool IssueFix, const VarDecl *ObjectArg, ASTContext &Context) {
@@ -312,52 +326,33 @@ void 
UnnecessaryCopyInitialization::handleCopyFromMethodReturn(
   !isInitializingVariableImmutable(*ObjectArg, BlockStmt, Context,
ExcludedContainerTypes))
 return;
-  if (isVariableUnused(Var, BlockStmt, Context)) {
-auto Diagnostic =
-diag(Var.getLocation(),
- "the %select{|const qualified }0variable %1 is copy-constructed "
- "from a const reference but is never used; consider "
- "removing the statement")
-<< IsConstQualified << &Var;
-if (IssueFix)
-  recordRemoval(Stmt, Context, Diagnostic);
-  } else {
-auto Diagnostic =
-diag(Var.getLocation(),
- "the %select{|const qualified }0variable %1 is copy-constructed "
- "from a const reference%select{ but is only used as const "
- "reference|}0; consider making it a const reference")
-<< IsConstQualified << &Var;
-if (IssueFix)
-  recordFixes(Var, Context, Diagnostic);
-  }
+
+  auto Diagnostic =
+  diag(Var.getLocation(),
+   "the %select{|const qualified }0variable %1 is copy-constructed "
+   "from a const reference%select{"
+   "%select{ but is only used as const reference|}0"
+   "| but is never used}2; consider "
+   "%select{making it a const reference|removing the statement}2")
+  << IsConstQualified;
+  makeDiagnostic(std::move(Diagnostic), Var, BlockStmt, Stmt, Context,
+ IssueFix);
 }
 
 void UnnecessaryCopyInitialization::handleCopyFromLocalVar(
-const VarDecl &NewVar, const VarDecl &OldVar, const Stmt &BlockStmt,
+const VarDecl &Var, const VarDecl &OldVar, const Stmt &BlockStmt,
 const DeclStmt &Stmt, bool IssueFix, ASTContext &Context) {
-  if (!isOnlyUsedAsConst(NewVar, BlockStmt, Context) ||
+  if (!isOnlyUsedAsConst(Var, BlockStmt, Context) ||
   !isInitializingVariableImmutable(OldVar, BlockStmt, Context,
ExcludedContainerTypes))
 return;
-
-  if (isVariableUnused(NewVar, BlockStmt, Context)) {
-auto Diagnostic = diag(NewVar.getLocation(),
-   "local copy %0 of the variable %1 is never modified 
"
-   "and never used; "
-   "consider removing the statement")
-  << &NewVar << &OldVar;
-if (IssueFix)
-  recordRemoval(Stmt, Context, Diagnostic);
-  } else {
-auto Diagnostic =
-diag(NewVar.getLocation(),
- "local copy %0 of the variable %1 is never modified; "
- "consider avoiding the copy")
-<< &NewVar << &OldVar;
-if (IssueFix)
-  recordFixes(NewVar, Context, Diagnostic);
-  }
+  auto Diagnostic = diag(Var.getLocation(),
+ "local copy %1 of the variable %0 is never modified"
+ "%select{| and never used}2; consider "
+ "%select{avoiding the copy|removing the statement}2")
+<< &OldVar;
+  makeDiagnostic(std::move(Diagnostic), Var, BlockStmt, Stm

[clang] [Clang][SVE2p1]Add svboolx2 and svboolx4 types for svcreate, svget, s… (PR #74594)

2023-12-06 Thread via cfe-commits

https://github.com/CarolineConcatto created 
https://github.com/llvm/llvm-project/pull/74594

…vset

According to the PR#257[1]

[1]ARM-software/acle#257

Co-authored by: Matthew Devereau 

>From 037dd51fd05ccd70f10dbf4ca75dd1f45e6548c4 Mon Sep 17 00:00:00 2001
From: Caroline Concatto 
Date: Wed, 6 Dec 2023 14:02:23 +
Subject: [PATCH] [Clang][SVE2p1]Add svboolx2 and svboolx4 types for svcreate,
 svget, svset

According to the PR#257[1]

[1]ARM-software/acle#257

Co-authored by: Matthew Devereau 
---
 clang/include/clang/Basic/arm_sve.td  | 12 
 .../acle_sve2p1_create2_bool.c| 38 ++
 .../acle_sve2p1_create4_bool.c| 42 +++
 .../acle_sve2p1_get2_bool.c   | 49 +
 .../acle_sve2p1_get4_bool.c   | 72 +++
 .../acle_sve2p1_set2_bool.c   | 52 ++
 .../acle_sve2p1_set4_bool.c   | 66 +
 7 files changed, 331 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_create2_bool.c
 create mode 100644 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_create4_bool.c
 create mode 100644 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_get2_bool.c
 create mode 100644 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_get4_bool.c
 create mode 100644 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_set2_bool.c
 create mode 100644 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_set4_bool.c

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 3f69a3df9e616..9d4051a3ed34c 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1296,6 +1296,11 @@ def SVCREATE_3_BF16 : SInst<"svcreate3[_{d}]", "3ddd",  
"b", MergeNone, "", [IsT
 def SVCREATE_4_BF16 : SInst<"svcreate4[_{d}]", "4", "b", MergeNone, "", 
[IsTupleCreate]>;
 }
 
+let TargetGuard = "sve2p1" in {
+  def SVCREATE_2_B : SInst<"svcreate2[_{d}]", "2dd",   "Pc", MergeNone, "", 
[IsTupleCreate]>;
+  def SVCREATE_4_B : SInst<"svcreate4[_{d}]", "4", "Pc", MergeNone, "", 
[IsTupleCreate]>;
+}
+
 

 // Vector insertion and extraction
 def SVGET_2 : SInst<"svget2[_{d}]", "d2i", "csilUcUsUiUlhfd", MergeNone, "", 
[IsTupleGet], [ImmCheck<1, ImmCheck0_1>]>;
@@ -1316,6 +1321,13 @@ def SVSET_3_BF16 : SInst<"svset3[_{d}]", "33id", "b", 
MergeNone, "", [IsTupleSet
 def SVSET_4_BF16 : SInst<"svset4[_{d}]", "44id", "b", MergeNone, "", 
[IsTupleSet], [ImmCheck<1, ImmCheck0_3>]>;
 }
 
+let TargetGuard = "sve2p1" in {
+  def SVGET_2_B : SInst<"svget2[_{d}]", "d2i", "Pc", MergeNone, "", 
[IsTupleGet], [ImmCheck<1, ImmCheck0_1>]>;
+  def SVGET_4_B : SInst<"svget4[_{d}]", "d4i", "Pc", MergeNone, "", 
[IsTupleGet], [ImmCheck<1, ImmCheck0_3>]>;
+
+  def SVSET_2_B : SInst<"svset2[_{d}]", "22id", "Pc", MergeNone, "", 
[IsTupleSet], [ImmCheck<1, ImmCheck0_1>]>;
+  def SVSET_4_B : SInst<"svset4[_{d}]", "44id", "Pc", MergeNone, "", 
[IsTupleSet], [ImmCheck<1, ImmCheck0_3>]>;
+}
 

 // SVE2 WhileGE/GT
 let TargetGuard = "sve2" in {
diff --git 
a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_create2_bool.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_create2_bool.c
new file mode 100644
index 0..eb5a19b1d9d32
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_create2_bool.c
@@ -0,0 +1,38 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s \
+// RUN: | opt -S -passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s \
+// RUN: | opt -S -passes=mem2reg,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s 
\
+// RUN: | opt -S -passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s\
+// RUN: | opt -S -passes=mem2reg,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3

[clang] [Clang][SVE2p1]Add svboolx2 and svboolx4 types for svcreate, svget, s… (PR #74594)

2023-12-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (CarolineConcatto)


Changes

…vset

According to the PR#257[1]

[1]ARM-software/acle#257

Co-authored by: Matthew Devereau 

---

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


7 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+12) 
- (added) 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_create2_bool.c (+38) 
- (added) 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_create4_bool.c (+42) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_get2_bool.c 
(+49) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_get4_bool.c 
(+72) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_set2_bool.c 
(+52) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_set4_bool.c 
(+66) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 3f69a3df9e616..9d4051a3ed34c 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1296,6 +1296,11 @@ def SVCREATE_3_BF16 : SInst<"svcreate3[_{d}]", "3ddd",  
"b", MergeNone, "", [IsT
 def SVCREATE_4_BF16 : SInst<"svcreate4[_{d}]", "4", "b", MergeNone, "", 
[IsTupleCreate]>;
 }
 
+let TargetGuard = "sve2p1" in {
+  def SVCREATE_2_B : SInst<"svcreate2[_{d}]", "2dd",   "Pc", MergeNone, "", 
[IsTupleCreate]>;
+  def SVCREATE_4_B : SInst<"svcreate4[_{d}]", "4", "Pc", MergeNone, "", 
[IsTupleCreate]>;
+}
+
 

 // Vector insertion and extraction
 def SVGET_2 : SInst<"svget2[_{d}]", "d2i", "csilUcUsUiUlhfd", MergeNone, "", 
[IsTupleGet], [ImmCheck<1, ImmCheck0_1>]>;
@@ -1316,6 +1321,13 @@ def SVSET_3_BF16 : SInst<"svset3[_{d}]", "33id", "b", 
MergeNone, "", [IsTupleSet
 def SVSET_4_BF16 : SInst<"svset4[_{d}]", "44id", "b", MergeNone, "", 
[IsTupleSet], [ImmCheck<1, ImmCheck0_3>]>;
 }
 
+let TargetGuard = "sve2p1" in {
+  def SVGET_2_B : SInst<"svget2[_{d}]", "d2i", "Pc", MergeNone, "", 
[IsTupleGet], [ImmCheck<1, ImmCheck0_1>]>;
+  def SVGET_4_B : SInst<"svget4[_{d}]", "d4i", "Pc", MergeNone, "", 
[IsTupleGet], [ImmCheck<1, ImmCheck0_3>]>;
+
+  def SVSET_2_B : SInst<"svset2[_{d}]", "22id", "Pc", MergeNone, "", 
[IsTupleSet], [ImmCheck<1, ImmCheck0_1>]>;
+  def SVSET_4_B : SInst<"svset4[_{d}]", "44id", "Pc", MergeNone, "", 
[IsTupleSet], [ImmCheck<1, ImmCheck0_3>]>;
+}
 

 // SVE2 WhileGE/GT
 let TargetGuard = "sve2" in {
diff --git 
a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_create2_bool.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_create2_bool.c
new file mode 100644
index 0..eb5a19b1d9d32
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_create2_bool.c
@@ -0,0 +1,38 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s \
+// RUN: | opt -S -passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s \
+// RUN: | opt -S -passes=mem2reg,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s 
\
+// RUN: | opt -S -passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s\
+// RUN: | opt -S -passes=mem2reg,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
+#endif
+
+// CHECK-LABEL: @test_svcreate2_s8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.insert.nxv32i1.nxv16i1( poison,  [[X0:%.*]], i64 0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.insert.nxv32i1.nxv16i1( [[TMP0]],  [[X1:%.*]], i64 16)
+// CHECK-NEXT:ret  [[TMP1]]
+//
+// CPP-CHECK-LABEL: @_Z17test_svcreate2_s8u10__SVBool_tS_(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.insert.nxv32i1.nxv16i1( poison,  [[X0:%.*]], i64 0)
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@l

[clang] [llvm] Irdl2 (PR #74596)

2023-12-06 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam created 
https://github.com/llvm/llvm-project/pull/74596

None

>From 707f1625a626faae14b8e24f7e3cf10a2ed621ce Mon Sep 17 00:00:00 2001
From: Tom Honermann 
Date: Sun, 24 Sep 2023 22:38:01 -0400
Subject: [PATCH 1/6] [clang][DFP] Add basic builtin type representation for
 decimal floating point types.

This change adds basic type representation support for the decimal
floating point types defined by ISO/IEC TS 18661-2 and adopted for C23.
These types will also serve as the underlying native types for the
library types defined by ISO/IEC TR 24733 and as implemented in
libstdcxx. This change does not include representation support in
LLVM IR, in debugging information, or in C++ mangling for the MS ABI;
such support will be added in later patches.
---
 clang/include/clang/AST/ASTContext.h  |  2 ++
 clang/include/clang/AST/BuiltinTypes.def  | 17 
 clang/include/clang/Basic/TargetInfo.h| 17 
 clang/include/clang/Basic/TokenKinds.def  |  4 +++-
 .../include/clang/Serialization/ASTBitCodes.h |  9 +
 clang/lib/AST/ASTContext.cpp  | 20 +++
 clang/lib/AST/ExprConstant.cpp|  2 ++
 clang/lib/AST/ItaniumMangle.cpp   |  9 +
 clang/lib/AST/MicrosoftMangle.cpp |  6 ++
 clang/lib/AST/NSAPI.cpp   |  3 +++
 clang/lib/AST/PrintfFormatString.cpp  |  4 
 clang/lib/AST/Type.cpp|  7 +++
 clang/lib/AST/TypeLoc.cpp |  3 +++
 clang/lib/Basic/TargetInfo.cpp|  5 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  7 +++
 clang/lib/CodeGen/CodeGenTypes.cpp|  8 
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  3 +++
 clang/lib/Index/USRGeneration.cpp |  6 ++
 clang/lib/Sema/SemaType.cpp   | 16 ++-
 clang/lib/Serialization/ASTCommon.cpp |  9 +
 clang/lib/Serialization/ASTReader.cpp |  9 +
 clang/test/Sema/types.c   |  4 +++-
 clang/tools/libclang/CIndex.cpp   |  1 +
 23 files changed, 168 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 4ee32c76a95d8..f862456797b5f 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1098,6 +1098,8 @@ class ASTContext : public RefCountedBase {
   CanQualType SatShortFractTy, SatFractTy, SatLongFractTy;
   CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy,
   SatUnsignedLongFractTy;
+  // ISO/IEC TS 18661-2, ISO/IEC TR 24733, and C23 decimal floating-point.
+  CanQualType DecimalFloat32Ty, DecimalFloat64Ty, DecimalFloat128Ty;
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
   CanQualType BFloat16Ty;
   CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index c04f6f6f12719..3a0f78fb6a33f 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -44,6 +44,10 @@
 #define FLOATING_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId)
 #endif
 
+#ifndef DECIMAL_FLOATING_TYPE
+#define DECIMAL_FLOATING_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId)
+#endif
+
 #ifndef PLACEHOLDER_TYPE
 #define PLACEHOLDER_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId)
 #endif
@@ -221,6 +225,18 @@ FLOATING_TYPE(Float128, Float128Ty)
 // '__ibm128'
 FLOATING_TYPE(Ibm128, Ibm128Ty)
 
+//===- Decimal floating point types 
---===//
+// ISO/IEC TS 18661-2, ISO/IEC TR 24733, and C23 decimal floating-point.
+
+// '_Decimal32'
+DECIMAL_FLOATING_TYPE(DecimalFloat32, DecimalFloat32Ty)
+
+// '_Decimal64'
+DECIMAL_FLOATING_TYPE(DecimalFloat64, DecimalFloat64Ty)
+
+// '_Decimal128'
+DECIMAL_FLOATING_TYPE(DecimalFloat128, DecimalFloat128Ty)
+
 //===- Language-specific types 
===//
 
 // This is the type of C++0x 'nullptr'.
@@ -336,6 +352,7 @@ LAST_BUILTIN_TYPE(OMPIterator)
 #undef SHARED_SINGLETON_TYPE
 #undef PLACEHOLDER_TYPE
 #undef FLOATING_TYPE
+#undef DECIMAL_FLOATING_TYPE
 #undef SIGNED_TYPE
 #undef UNSIGNED_TYPE
 #undef BUILTIN_TYPE
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 61be52149341f..ddf166c971fec 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -95,6 +95,11 @@ struct TransferrableTargetInfo {
   unsigned char LongLongWidth, LongLongAlign;
   unsigned char Int128Align;
 
+  // Decimal floating-point bit widths and alignment.
+  unsigned char DecimalFloat32Width, DecimalFloat32Align;
+  unsigned char DecimalFloat64Width, DecimalFloat64Align;
+  unsigned char DecimalFloat128Width, DecimalFloat128Align;
+
   // Fixed point bit widths
   unsigned char ShortAcc

[llvm] [clang] Irdl2 (PR #74596)

2023-12-06 Thread Zahira Ammarguellat via cfe-commits

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


[llvm] [mlir] [clang] [AMDGPU] - Add address space for strided buffers (PR #74471)

2023-12-06 Thread Jessica Del via cfe-commits

https://github.com/OutOfCache updated 
https://github.com/llvm/llvm-project/pull/74471

>From 94ed734c0d8864a08e3b77600dda811040270bd9 Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Tue, 5 Dec 2023 13:45:58 +0100
Subject: [PATCH 1/3] [AMDGPU] - Add address space for strided buffers

This is an experimental address space for strided buffers.
These buffers can have structs as elements and
a stride > 1.
These pointers allow the indexed access in units of stride,
i.e., they point at `buffer[index * stride]`.
Thus, we can use the `idxen` modifier for buffer loads.

We assign address space 9 to 192-bit buffer pointers which
contain a 128-bit descriptor, a 32-bit offset and a 32-bit
index. Essentially, they are fat buffer pointers with
an additional 32-bit index.
---
 llvm/docs/AMDGPUUsage.rst | 48 -
 llvm/lib/Target/AMDGPU/AMDGPU.h   | 32 +
 .../lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp |  7 +-
 .../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp |  2 +-
 .../AMDGPU/AMDGPUTargetTransformInfo.cpp  |  3 +-
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 13 +++-
 .../CodeGen/AMDGPU/amdgpu-alias-analysis.ll   | 70 +++
 .../AMDGPU/vectorize-buffer-fat-pointer.ll| 19 -
 8 files changed, 154 insertions(+), 40 deletions(-)

diff --git a/llvm/docs/AMDGPUUsage.rst b/llvm/docs/AMDGPUUsage.rst
index 7fb3d70bbeffe..ff45efac7e848 100644
--- a/llvm/docs/AMDGPUUsage.rst
+++ b/llvm/docs/AMDGPUUsage.rst
@@ -703,23 +703,24 @@ supported for the ``amdgcn`` target.
   .. table:: AMDGPU Address Spaces
  :name: amdgpu-address-spaces-table
 
- = === === 
 === 
- ..
 64-Bit Process Address Space
- - --- --- 
 
- Address Space NameLLVM IR Address HSA Segment Hardware
 Address NULL Value
-   Space NumberNameName
 Size
- = === === 
 === 
- Generic   0   flatflat
 64  0x
- Global1   global  global  
 64  0x
- Region2   N/A GDS 
 32  *not implemented for AMDHSA*
- Local 3   group   LDS 
 32  0x
- Constant  4   constant*same as 
global* 64  0x
- Private   5   private scratch 
 32  0x
- Constant 32-bit   6   *TODO*  
 0x
- Buffer Fat Pointer (experimental) 7   *TODO*
- Buffer Resource (experimental)8   *TODO*
- Streamout Registers   128 N/A GS_REGS
- = === === 
 === 
+ = === === 
 === 
+ ..
 64-Bit Process Address Space
+ - --- --- 
 
+ Address Space NameLLVM IR Address HSA Segment 
Hardware Address NULL Value
+   Space NumberNameName
 Size
+ = === === 
 === 
+ Generic   0   flatflat
 64  0x
+ Global1   global  global  
 64  0x
+ Region2   N/A GDS 
 32  *not implemented for AMDHSA*
+ Local 3   group   LDS 
 32  0x
+ Constant  4   constant*same 
as global* 64  0x
+ Private   5   private scratch 
 32  0x
+ Constant 32-bit   6   *TODO*  
 0x
+ Buffer Fat Pointer (experimental) 7   *TODO*
+

  1   2   3   4   5   >