[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

2024-05-16 Thread via cfe-commits

cor3ntin wrote:

@joanahalili 
> We are seeing a widespread breakage due to this commit and could use having 
> the flag -fno-relaxed-template-template-args un-deprecated for a while. This 
> would help do a cleanup on our end.

Can you provide more information? How widespread are we talking about? You have 
example of common breakages?
Thanks

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


[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2024-05-16 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

I'm not sure a crash is ever expected, but it's a known issue.

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


[clang] [Clang][OpenMP] Fix multi arch compilation for -march option (PR #92290)

2024-05-16 Thread Saiyedul Islam via cfe-commits

saiislam wrote:

Thanks for the review and comments. Closing the PR.

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


[clang] [Clang][OpenMP] Fix multi arch compilation for -march option (PR #92290)

2024-05-16 Thread Saiyedul Islam via cfe-commits

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


[clang] [clang-tools-extra] [clang] Fix CXXNewExpr end source location for 'new struct S' (PR #92266)

2024-05-16 Thread Arseniy Zaostrovnykh via cfe-commits

https://github.com/necto updated https://github.com/llvm/llvm-project/pull/92266

>From eeb24ddbf261fd7667dd05feee14637bc379d182 Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Wed, 15 May 2024 16:02:07 +0200
Subject: [PATCH 1/3] Fix CXXNewExpr end source location for 'new struct S'

---
 clang/lib/Parse/ParseDeclCXX.cpp  | 1 +
 clang/test/Misc/ast-source-ranges.cpp | 5 +
 2 files changed, 6 insertions(+)
 create mode 100644 clang/test/Misc/ast-source-ranges.cpp

diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 65ddebca49bc6..32c4e923243a9 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1883,6 +1883,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   if (Tok.is(tok::identifier)) {
 Name = Tok.getIdentifierInfo();
 NameLoc = ConsumeToken();
+DS.SetRangeEnd(NameLoc);
 
 if (Tok.is(tok::less) && getLangOpts().CPlusPlus) {
   // The name was supposed to refer to a template, but didn't.
diff --git a/clang/test/Misc/ast-source-ranges.cpp 
b/clang/test/Misc/ast-source-ranges.cpp
new file mode 100644
index 0..9c0ab9449a6f5
--- /dev/null
+++ b/clang/test/Misc/ast-source-ranges.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -ast-dump %s  2>&1 | FileCheck %s
+
+struct Sock {};
+void leakNewFn() { new struct Sock; }
+// CHECK: CXXNewExpr {{.*}}  'struct Sock *'

>From 28d5f458542d1fed2b3d82543c93e61a2768637c Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Wed, 15 May 2024 16:53:53 +0200
Subject: [PATCH 2/3] Fix clang-tidy:make-unique

---
 .../test/clang-tidy/checkers/modernize/make-unique.cpp | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
index 7934c6e93ffbd..fe512a8f3bf32 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
@@ -606,11 +606,8 @@ void invoke_template() {
   template_fun(foo);
 }
 
-void no_fix_for_invalid_new_loc() {
-  // FIXME: Although the code is valid, the end location of `new struct Base` 
is
-  // invalid. Correct it once https://bugs.llvm.org/show_bug.cgi?id=35952 is
-  // fixed.
+void fix_for_c_style_struct() {
   auto T = std::unique_ptr(new struct Base);
   // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use std::make_unique instead
-  // CHECK-FIXES: auto T = std::unique_ptr(new struct Base);
+  // CHECK-FIXES: auto T = std::make_unique();
 }

>From 21077adfefd5a255735cb7f6f0bb690a1e880e62 Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Thu, 16 May 2024 09:27:25 +0200
Subject: [PATCH 3/3] Move the AST dump test to the conventional file

---
 clang/test/AST/ast-dump-expr.cpp  | 5 +
 clang/test/Misc/ast-source-ranges.cpp | 5 -
 2 files changed, 5 insertions(+), 5 deletions(-)
 delete mode 100644 clang/test/Misc/ast-source-ranges.cpp

diff --git a/clang/test/AST/ast-dump-expr.cpp b/clang/test/AST/ast-dump-expr.cpp
index 69e65e22d61d0..9b29ab1bbb228 100644
--- a/clang/test/AST/ast-dump-expr.cpp
+++ b/clang/test/AST/ast-dump-expr.cpp
@@ -583,3 +583,8 @@ void NonADLCall3() {
   f(x);
 }
 } // namespace test_adl_call_three
+
+struct Sock {};
+void leakNewFn() { new struct Sock; }
+// CHECK: CXXNewExpr {{.*}}  'struct Sock *'
+
diff --git a/clang/test/Misc/ast-source-ranges.cpp 
b/clang/test/Misc/ast-source-ranges.cpp
deleted file mode 100644
index 9c0ab9449a6f5..0
--- a/clang/test/Misc/ast-source-ranges.cpp
+++ /dev/null
@@ -1,5 +0,0 @@
-// RUN: %clang_cc1 -ast-dump %s  2>&1 | FileCheck %s
-
-struct Sock {};
-void leakNewFn() { new struct Sock; }
-// CHECK: CXXNewExpr {{.*}}  'struct Sock *'

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


[clang] [clang-tools-extra] [clang] Fix CXXNewExpr end source location for 'new struct S' (PR #92266)

2024-05-16 Thread Arseniy Zaostrovnykh via cfe-commits


@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -ast-dump %s  2>&1 | FileCheck %s

necto wrote:

thanks for the pointer, moved!

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


[clang] [clang-tools-extra] [clang] Fix CXXNewExpr end source location for 'new struct S' (PR #92266)

2024-05-16 Thread Arseniy Zaostrovnykh via cfe-commits

necto wrote:

> `clang-tidy/checkers/modernize/make-unique.cpp` is failing for whatever 
> reason. Otherwise LGTM.

Indeed, turns out this PR fixes #35300 

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


[clang] [clang-tools-extra] [clang] Fix CXXNewExpr end source location for 'new struct S' (PR #92266)

2024-05-16 Thread Arseniy Zaostrovnykh via cfe-commits

https://github.com/necto updated https://github.com/llvm/llvm-project/pull/92266

>From eeb24ddbf261fd7667dd05feee14637bc379d182 Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Wed, 15 May 2024 16:02:07 +0200
Subject: [PATCH 1/3] Fix CXXNewExpr end source location for 'new struct S'

---
 clang/lib/Parse/ParseDeclCXX.cpp  | 1 +
 clang/test/Misc/ast-source-ranges.cpp | 5 +
 2 files changed, 6 insertions(+)
 create mode 100644 clang/test/Misc/ast-source-ranges.cpp

diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 65ddebca49bc6..32c4e923243a9 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1883,6 +1883,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   if (Tok.is(tok::identifier)) {
 Name = Tok.getIdentifierInfo();
 NameLoc = ConsumeToken();
+DS.SetRangeEnd(NameLoc);
 
 if (Tok.is(tok::less) && getLangOpts().CPlusPlus) {
   // The name was supposed to refer to a template, but didn't.
diff --git a/clang/test/Misc/ast-source-ranges.cpp 
b/clang/test/Misc/ast-source-ranges.cpp
new file mode 100644
index 0..9c0ab9449a6f5
--- /dev/null
+++ b/clang/test/Misc/ast-source-ranges.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -ast-dump %s  2>&1 | FileCheck %s
+
+struct Sock {};
+void leakNewFn() { new struct Sock; }
+// CHECK: CXXNewExpr {{.*}}  'struct Sock *'

>From 28d5f458542d1fed2b3d82543c93e61a2768637c Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Wed, 15 May 2024 16:53:53 +0200
Subject: [PATCH 2/3] Fix clang-tidy:make-unique

---
 .../test/clang-tidy/checkers/modernize/make-unique.cpp | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
index 7934c6e93ffbd..fe512a8f3bf32 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
@@ -606,11 +606,8 @@ void invoke_template() {
   template_fun(foo);
 }
 
-void no_fix_for_invalid_new_loc() {
-  // FIXME: Although the code is valid, the end location of `new struct Base` 
is
-  // invalid. Correct it once https://bugs.llvm.org/show_bug.cgi?id=35952 is
-  // fixed.
+void fix_for_c_style_struct() {
   auto T = std::unique_ptr(new struct Base);
   // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use std::make_unique instead
-  // CHECK-FIXES: auto T = std::unique_ptr(new struct Base);
+  // CHECK-FIXES: auto T = std::make_unique();
 }

>From 21077adfefd5a255735cb7f6f0bb690a1e880e62 Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Thu, 16 May 2024 09:27:25 +0200
Subject: [PATCH 3/3] Move the AST dump test to the conventional file

---
 clang/test/AST/ast-dump-expr.cpp  | 5 +
 clang/test/Misc/ast-source-ranges.cpp | 5 -
 2 files changed, 5 insertions(+), 5 deletions(-)
 delete mode 100644 clang/test/Misc/ast-source-ranges.cpp

diff --git a/clang/test/AST/ast-dump-expr.cpp b/clang/test/AST/ast-dump-expr.cpp
index 69e65e22d61d0..9b29ab1bbb228 100644
--- a/clang/test/AST/ast-dump-expr.cpp
+++ b/clang/test/AST/ast-dump-expr.cpp
@@ -583,3 +583,8 @@ void NonADLCall3() {
   f(x);
 }
 } // namespace test_adl_call_three
+
+struct Sock {};
+void leakNewFn() { new struct Sock; }
+// CHECK: CXXNewExpr {{.*}}  'struct Sock *'
+
diff --git a/clang/test/Misc/ast-source-ranges.cpp 
b/clang/test/Misc/ast-source-ranges.cpp
deleted file mode 100644
index 9c0ab9449a6f5..0
--- a/clang/test/Misc/ast-source-ranges.cpp
+++ /dev/null
@@ -1,5 +0,0 @@
-// RUN: %clang_cc1 -ast-dump %s  2>&1 | FileCheck %s
-
-struct Sock {};
-void leakNewFn() { new struct Sock; }
-// CHECK: CXXNewExpr {{.*}}  'struct Sock *'

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


[clang] [clang] Implement CWG2428 "Deprecating a concept" (PR #92295)

2024-05-16 Thread via cfe-commits


@@ -45,6 +45,34 @@ void fallthrough(int n) {
 #endif
 }
 
+namespace cwg2428 { // cwg2428: 19
+#if __cplusplus >= 202002L
+template 
+concept C [[deprecated]] = true; // #C

cor3ntin wrote:

As it turns out, GCC does support GNU-style attributes 
https://compiler-explorer.com/z/dccfdofKf
We should probably follow suite. Sorry for the confusion Vlad
(Which means you need to add tests + support for that)

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


[clang] [clang] Implement CWG2428 "Deprecating a concept" (PR #92295)

2024-05-16 Thread via cfe-commits

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


[libunwind] [libunwind] fix unwinding from signal handler (PR #92291)

2024-05-16 Thread Azat Khuzhin via cfe-commits

azat wrote:

>[Build and Test libc++ / stage3 (generic-ubsan, libcxx-runners-8-set) 
>(pull_request) Failing after 
>10m](https://github.com/llvm/llvm-project/actions/runs/9099207645/job/25013031369?pr=92291)

Looks like unrelated?

```
2024-05-15T17:48:22.3468783Z ##[error]The runner has received a shutdown 
signal. This can happen when the runner service is stopped, or a manually 
started runner is canceled.
```

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


[clang] [Clang][Sema] Don't build CXXDependentScopeMemberExprs for potentially implicit class member access expressions (PR #92318)

2024-05-16 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

`Sema.h` changes look good to me.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-16 Thread Shengchen Kan via cfe-commits


@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {

KanRobert wrote:

Will the feature be emitted in IR?

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-16 Thread Shengchen Kan via cfe-commits

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-16 Thread Shengchen Kan via cfe-commits


@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {

KanRobert wrote:

> `mcmodel` maybe not a good reference here since it's target independent.

```
  if (Opts.MicrosoftExt && getTriple().getArch() == llvm::Triple::x86) {
switch (SSELevel) {
case AVX512F:
case AVX2:
case AVX:
case SSE42:
case SSE41:
case SSSE3:
case SSE3:
case SSE2:
  Builder.defineMacro("_M_IX86_FP", Twine(2));
  break;
case SSE1:
  Builder.defineMacro("_M_IX86_FP", Twine(1));
  break;
default:
  Builder.defineMacro("_M_IX86_FP", Twine(0));
  break;
}
  }
```


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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Nikolas Klauser via cfe-commits

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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Nikolas Klauser via cfe-commits

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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang
@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-clang-codegen

Author: Nikolas Klauser (philnik777)


Changes

This is also very useful for generic code. For example this would allow libc++ 
to vectorize `{min,max,minmax}_element` without having to use platform-specific 
intrinsics. I've done some testing and even at `-O0` Clang compiles the code to 
the expected instructions for architectures where the mask vector has the same 
bit count as the element vector (i.e. every SIMD ISA except AVX512 that I'm 
aware of) as long as the comparison operation is visible.

---

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


32 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+20) 
- (modified) clang/include/clang/Basic/Builtins.td (+6) 
- (modified) clang/include/clang/Basic/BuiltinsX86.def (-24) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+3-1) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+6-25) 
- (modified) clang/lib/Headers/avx512bf16intrin.h (+12-12) 
- (modified) clang/lib/Headers/avx512bitalgintrin.h (+6-6) 
- (modified) clang/lib/Headers/avx512bwintrin.h (+386-396) 
- (modified) clang/lib/Headers/avx512cdintrin.h (+24-24) 
- (modified) clang/lib/Headers/avx512dqintrin.h (+134-134) 
- (modified) clang/lib/Headers/avx512fintrin.h (+958-957) 
- (modified) clang/lib/Headers/avx512fp16intrin.h (+90-85) 
- (modified) clang/lib/Headers/avx512ifmaintrin.h (+12-12) 
- (modified) clang/lib/Headers/avx512ifmavlintrin.h (+24-25) 
- (modified) clang/lib/Headers/avx512vbmi2intrin.h (+84-86) 
- (modified) clang/lib/Headers/avx512vbmiintrin.h (+21-22) 
- (modified) clang/lib/Headers/avx512vbmivlintrin.h (+42-43) 
- (modified) clang/lib/Headers/avx512vlbf16intrin.h (+24-24) 
- (modified) clang/lib/Headers/avx512vlbitalgintrin.h (+12-12) 
- (modified) clang/lib/Headers/avx512vlbwintrin.h (+776-788) 
- (modified) clang/lib/Headers/avx512vlcdintrin.h (+48-48) 
- (modified) clang/lib/Headers/avx512vldqintrin.h (+190-190) 
- (modified) clang/lib/Headers/avx512vlfp16intrin.h (+212-223) 
- (modified) clang/lib/Headers/avx512vlintrin.h (+1798-1982) 
- (modified) clang/lib/Headers/avx512vlvbmi2intrin.h (+168-168) 
- (modified) clang/lib/Headers/avx512vlvnniintrin.h (+48-48) 
- (modified) clang/lib/Headers/avx512vnniintrin.h (+24-24) 
- (modified) clang/lib/Headers/avx512vpopcntdqintrin.h (+6-4) 
- (modified) clang/lib/Headers/avx512vpopcntdqvlintrin.h (+12-8) 
- (modified) clang/lib/Headers/gfniintrin.h (+33-34) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+56) 
- (added) clang/test/Sema/builtin-selectvector.c (+18) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 96691b45d63a3..6513676438ffb 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3019,6 +3019,26 @@ C-style cast applied to each element of the first 
argument.
 
 Query for this feature with ``__has_builtin(__builtin_convertvector)``.
 
+``__builtin_selectvector``
+--
+
+``__builtin_selectvector`` is used to express generic vector element selection.
+
+**Signature**:
+
+.. code-block:: c++
+
+  template 
+  simd_vec __builtin_selectvector(simd_vec lhs, simd_vec rhs,
+simd_vec cond)
+
+**Description**:
+
+The returned vector is equivalent to
+``simd_vec{cond[0] ? rhs[0] : lhs[0], ..., cond[N - 1] ? rhs[N - 1] : 
lhs[N - 1]}``.
+
+Query for this feature with ``__has_builtin(__builtin_selectvector)``.
+
 ``__builtin_bitreverse``
 
 
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index d6ceb450bd106..279330d9b5251 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1176,6 +1176,12 @@ def ConvertVector : Builtin {
   let Prototype = "void(...)";
 }
 
+def SelectVector : Builtin {
+  let Spellings = ["__builtin_selectvector"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
 def AllocaUninitialized : Builtin {
   let Spellings = ["__builtin_alloca_uninitialized"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow];
diff --git a/clang/include/clang/Basic/BuiltinsX86.def 
b/clang/include/clang/Basic/BuiltinsX86.def
index eafcc219c1096..2e099b3ab4f05 100644
--- a/clang/include/clang/Basic/BuiltinsX86.def
+++ b/clang/include/clang/Basic/BuiltinsX86.def
@@ -1973,30 +1973,6 @@ TARGET_BUILTIN(__builtin_ia32_vfcmulcph256_mask,  
"V8fV8fV8fV8fUc", "ncV:256:",
 TARGET_BUILTIN(__builtin_ia32_vfcmulcph512_mask,  "V16fV16fV16fV16fUsIi", 
"ncV:512:", "avx512fp16,evex512")
 
 // generic select intrinsics
-TARGET_BUILTIN(__builtin_ia32_selectb_128, "V16cUsV16cV16c", "ncV:128:", 
"avx512bw,avx512vl")
-TARGET_BUILTIN(__builtin_ia32_selectb_256, "V32cUiV32cV32c", "ncV:256:", 
"avx512bw,avx512vl")
-TARGET_BUILT

[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

I don't understand why the order of emitted instructions changes based on how 
exactly Clang is compiled, but other than that this should be ready. Hopefully 
someone spots what the problem could be.

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


[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder' (PR #91445)

2024-05-16 Thread Balázs Kéri via cfe-commits

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/91445

From d839faf7a30851a172d812137b30635c741870f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Wed, 8 May 2024 10:10:24 +0200
Subject: [PATCH 1/8] [clang][analyzer] Add checker
 'Security.SetgidSetuidOrder'.

---
 clang/docs/analyzer/checkers.rst  |  28 +++
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   5 +
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   1 +
 .../Checkers/SetgidSetuidOrderChecker.cpp | 196 ++
 .../system-header-simulator-setgid-setuid.h   |  15 ++
 clang/test/Analysis/setgid-setuid-order.c | 170 +++
 6 files changed, 415 insertions(+)
 create mode 100644 
clang/lib/StaticAnalyzer/Checkers/SetgidSetuidOrderChecker.cpp
 create mode 100644 
clang/test/Analysis/Inputs/system-header-simulator-setgid-setuid.h
 create mode 100644 clang/test/Analysis/setgid-setuid-order.c

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 0d87df36ced0e..d0c0c7a535c62 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1179,6 +1179,34 @@ security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C)
strncpy(buf, "a", 1); // warn
  }
 
+security.SetgidSetuidOrder (C)
+""
+When dropping user-level and group-level privileges in a program by using
+``setuid`` and ``setgid`` calls, it is important to reset the group-level
+privileges (with ``setgid``) first. Function ``setgid`` will likely fail if
+the superuser privileges are already dropped.
+
+The checker checks for sequences of ``setuid(getuid())`` and
+``setgid(getgid())`` calls (in this order). If such a sequence is found and
+there is no other privilege-changing function call (``seteuid``, ``setreuid``,
+``setresuid`` and the GID versions of these) in between, a warning is
+generated. The checker finds only exactly ``setuid(getuid())`` calls (and the
+GID versions), not for example if the result of ``getuid()`` is stored in a
+variable.
+
+This check corresponds to SEI CERT Rule `POS36-C 
`_.
+
+.. code-block:: c
+
+ void test1() {
+   if (setuid(getuid()) == -1) {
+ /* handle error condition */
+   }
+   if (setgid(getgid()) == -1) { // warn
+ /* handle error condition */
+   }
+ }
+
 .. _unix-checkers:
 
 unix
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 520286b57c9fd..cc954828901af 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1011,6 +1011,11 @@ def FloatLoopCounter : Checker<"FloatLoopCounter">,
   Dependencies<[SecuritySyntaxChecker]>,
   Documentation;
 
+def SetgidSetuidOrderChecker : Checker<"SetgidSetuidOrder">,
+  HelpText<"Warn on possible reversed order of 'setgid(getgid()))' and 
'setuid(getuid())' (CERT: "
+   "POS36-C)">,
+  Documentation;
+
 } // end "security"
 
 let ParentPackage = ENV in {
diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 4443ffd092938..45d3788f105dc 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -103,6 +103,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   ReturnUndefChecker.cpp
   ReturnValueChecker.cpp
   RunLoopAutoreleaseLeakChecker.cpp
+  SetgidSetuidOrderChecker.cpp
   SimpleStreamChecker.cpp
   SmartPtrChecker.cpp
   SmartPtrModeling.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/SetgidSetuidOrderChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/SetgidSetuidOrderChecker.cpp
new file mode 100644
index 0..11cc748cb40b1
--- /dev/null
+++ b/clang/lib/StaticAnalyzer/Checkers/SetgidSetuidOrderChecker.cpp
@@ -0,0 +1,196 @@
+//===-- ChrootChecker.cpp - chroot usage checks 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines chroot checker, which checks improper use of chroot.
+//
+//===--===//
+
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include 

[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-16 Thread Freddy Ye via cfe-commits


@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {

FreddyLeaf wrote:

> Will the feature be emitted in IR?

yes, I was referring `prefer-no-gather`

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


[clang] [clang] Implement a bitwise_copyable builtin type trait. (PR #86512)

2024-05-16 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/86512

>From 10d06e728d836f4aaad7dbf1a6b06b57e4092bb1 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Mon, 25 Mar 2024 15:10:51 +0100
Subject: [PATCH 1/3] [clang] Implement a bitwise_copyable builtin type trait.

This patch implements a `__is_bitwise_copyable` builtin in clang.

The bitwise copyable types act as the trivially copyable types, but
they support a wider range of types (e.g. classes with virtual methods) --
their underlying types can be safely copied by `memcopy` or `memmove`,
the clang compiler guarantees that both source and destination objects
have the same *object* representations after the copy operation, and the
lifetime of the destination object implicitly starts.

A particular use case of this builtin is to clone an object via memcopy
(without running the constructor):

```
Message* clone(const Message* src, char* buffer, int size) {
  if constexpr __is_bitwise_copyable(Message) {
// bitwise copy to buffer, and implicitly create objects at the buffer
__builtin_memcpy(buffer, src, size);
return std::launder(reinterpret_cast(buffer));
  }
  // Fallback the operator new, which calls the constructor to start the 
lifetime.
  return new(buffer) Message(src);
}
```

Note that the definition of bitwise copyable is not tied to the Rule Of
Five, so users of this builtin must guarantee that program semantic constraints
are satisfied, e.g. no double resource deallocations.

Context: https://discourse.llvm.org/t/extension-for-creating-objects-via-memcpy
---
 clang/include/clang/AST/Type.h| 12 +
 clang/include/clang/Basic/TokenKinds.def  |  1 +
 clang/lib/AST/Type.cpp| 23 
 clang/lib/Sema/SemaExprCXX.cpp|  4 +++
 .../SemaCXX/builtin-is-bitwise-copyable.cpp   | 26 +++
 5 files changed, 66 insertions(+)
 create mode 100644 clang/test/SemaCXX/builtin-is-bitwise-copyable.cpp

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index e6643469e0b33..ff60f1c4b3520 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1120,6 +1120,18 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext &Context) const;
 
+  /// Return true if this is a bitwise copyable type.
+  ///
+  /// This is an extension in clang: bitwise copyable types act as trivially
+  /// copyable types, underlying bytes of bitwise copyable type can be safely
+  /// copied by memcpy or memmove. Clang guarantees that both source and
+  /// destination objects have the same **object** representations after the
+  /// copy, and the lifetime of the destination object implicitly starts.
+  ///
+  /// bitwise copyable types cover a wider range of types, e.g. classes with
+  /// virtual methods.
+  bool isBitwiseCopyableType(const ASTContext &Context) const;
+
   /// Return true if this is a trivially copyable type
   bool isTriviallyCopyConstructibleType(const ASTContext &Context) const;
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 56c4b17f769d7..ce2298543fac6 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -527,6 +527,7 @@ TYPE_TRAIT_2(__is_pointer_interconvertible_base_of, 
IsPointerInterconvertibleBas
 #include "clang/Basic/TransformTypeTraits.def"
 
 // Clang-only C++ Type Traits
+TYPE_TRAIT_1(__is_bitwise_copyable, IsBitwiseCopyable, KEYCXX)
 TYPE_TRAIT_1(__is_trivially_relocatable, IsTriviallyRelocatable, KEYCXX)
 TYPE_TRAIT_1(__is_trivially_equality_comparable, 
IsTriviallyEqualityComparable, KEYCXX)
 TYPE_TRAIT_1(__is_bounded_array, IsBoundedArray, KEYCXX)
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index e31741cd44240..5c0b89545a92b 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2731,6 +2731,29 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
&Context) const {
  /*IsCopyConstructible=*/false);
 }
 
+bool QualType::isBitwiseCopyableType(const ASTContext & Context) const {
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isIncompleteType() || CanonicalType->isDependentType())
+return false;
+  // Trivially copyable types are bitwise copyable, e.g. scalar types.
+  if (CanonicalType.isTriviallyCopyableType(Context))
+return true;
+
+  if (CanonicalType->isArrayType())
+return Context.getBaseElementType(CanonicalType)
+.isBitwiseCopyableType(Context);
+
+  if (const auto *RD = CanonicalType->getAsCXXRecordDecl()) {
+for (auto *const Field : RD->fields()) {
+  QualType T = Context.getBaseElementType(Field->getType());
+  if (!T.isBitwiseCopyableType(Context))
+return false;
+}
+return true;
+  }
+  return false;
+}
+
 bool QualType::isTriviallyCo

[clang] [clang] Implement a bitwise_copyable builtin type trait. (PR #86512)

2024-05-16 Thread Haojian Wu via cfe-commits

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


[clang] [clang] Implement a bitwise_copyable builtin type trait. (PR #86512)

2024-05-16 Thread Haojian Wu via cfe-commits


@@ -3958,6 +3958,50 @@ Note that the `size` argument must be a compile time 
constant.
 
 Note that this intrinsic cannot yet be called in a ``constexpr`` context.
 
+``__is_bitwise_cloneable``
+-
+
+A type trait is used to check whether a type can be safely copied by memcpy.
+
+**Syntax**:
+
+.. code-block:: c++
+
+  bool __is_bitwise_cloneable(Type)
+
+** Example of Use**:
+
+.. code-block:: c++
+
+  // Return a cloned object of the given default instance.
+  Foo* Clone(const Foo* default_instance, char* buffer, unsigned size) {
+if constexpr __is_bitwise_cloneable(decltype(*default_instance)) {
+  // Fast path via memcopy, without calling class constructor.
+  memcpy(buffer, default_instance, size);
+  // Explicitly start the lifetime of the cloned object.
+  return __builtin_start_object_lifetime(reinterpret_cast(buffer));
+}
+// Fallback the operator new, which invoke the class constructor.
+return new(buffer) Foo(*default_instance);
+  }
+
+**Description**:
+
+It is common for library owners to perform memcpy/memmove on types that aren't
+trivally copyable for performance reason. However, according to the C++ 
standard,

hokein wrote:

Done.

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


[clang] [clang] Implement a bitwise_copyable builtin type trait. (PR #86512)

2024-05-16 Thread Haojian Wu via cfe-commits

https://github.com/hokein commented:

thanks for the review.

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


[clang] [clang] Implement a bitwise_copyable builtin type trait. (PR #86512)

2024-05-16 Thread Haojian Wu via cfe-commits


@@ -2718,6 +2718,36 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
&Context) const {
  /*IsCopyConstructible=*/false);
 }
 
+bool QualType::isBitwiseCloneableType(const ASTContext & Context) const {
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isIncompleteType() || CanonicalType->isDependentType())
+return false;
+  // Trivially copyable types are bitwise clonable, e.g. scalar types.
+  if (CanonicalType.isTriviallyCopyableType(Context))
+return true;
+
+  if (CanonicalType->isArrayType())
+return Context.getBaseElementType(CanonicalType)
+.isBitwiseCloneableType(Context);
+
+  if (const auto *RD = CanonicalType->getAsCXXRecordDecl()) {
+for (auto Base : RD->bases())
+  if (!Base.getType().isBitwiseCloneableType(Context))

hokein wrote:

Good point, added a FIXME (we could use an extra bit in the class definition 
class to cache the result).

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


[clang] [clang] Implement a bitwise_copyable builtin type trait. (PR #86512)

2024-05-16 Thread Haojian Wu via cfe-commits


@@ -2718,6 +2718,36 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
&Context) const {
  /*IsCopyConstructible=*/false);
 }
 
+bool QualType::isBitwiseCloneableType(const ASTContext & Context) const {
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isIncompleteType() || CanonicalType->isDependentType())
+return false;
+  // Trivially copyable types are bitwise clonable, e.g. scalar types.
+  if (CanonicalType.isTriviallyCopyableType(Context))
+return true;
+
+  if (CanonicalType->isArrayType())
+return Context.getBaseElementType(CanonicalType)
+.isBitwiseCloneableType(Context);
+
+  if (const auto *RD = CanonicalType->getAsCXXRecordDecl()) {
+for (auto Base : RD->bases())
+  if (!Base.getType().isBitwiseCloneableType(Context))
+return false;
+for (auto VBase : RD->vbases())
+  if (!VBase.getType().isBitwiseCloneableType(Context))
+return false;
+
+for (auto *const Field : RD->fields()) {
+  QualType T = Context.getBaseElementType(Field->getType());

hokein wrote:

Switched to `isBitwiseCloneableType(Field->getType())`.

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


[clang] [clang] Implement a bitwise_copyable builtin type trait. (PR #86512)

2024-05-16 Thread Haojian Wu via cfe-commits


@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Scalar types are bitwise clonable.
+static_assert(__is_bitwise_cloneable(int));
+static_assert(__is_bitwise_cloneable(int*));
+// array
+static_assert(__is_bitwise_cloneable(int[10]));
+
+// non-scalar types.
+static_assert(!__is_bitwise_cloneable(int&));
+
+
+struct Forward; // expected-note 2{{forward declaration of 'Forward'}}
+static_assert(!__is_bitwise_cloneable(Forward)); // expected-error 
{{incomplete type 'Forward' used in type trait expression}}
+
+struct Foo { int a; };
+static_assert(__is_bitwise_cloneable(Foo));
+
+struct DynamicClass { virtual int Foo(); };
+static_assert(__is_bitwise_cloneable(DynamicClass));

hokein wrote:

Done.

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


[clang] [clang] Implement a bitwise_copyable builtin type trait. (PR #86512)

2024-05-16 Thread Haojian Wu via cfe-commits


@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Scalar types are bitwise clonable.
+static_assert(__is_bitwise_cloneable(int));
+static_assert(__is_bitwise_cloneable(int*));
+// array
+static_assert(__is_bitwise_cloneable(int[10]));
+
+// non-scalar types.
+static_assert(!__is_bitwise_cloneable(int&));
+
+
+struct Forward; // expected-note 2{{forward declaration of 'Forward'}}
+static_assert(!__is_bitwise_cloneable(Forward)); // expected-error 
{{incomplete type 'Forward' used in type trait expression}}
+
+struct Foo { int a; };
+static_assert(__is_bitwise_cloneable(Foo));
+
+struct DynamicClass { virtual int Foo(); };
+static_assert(__is_bitwise_cloneable(DynamicClass));
+
+struct Bar { int& b; }; // trivially copyable
+static_assert(__is_trivially_copyable(Bar));
+static_assert(__is_bitwise_cloneable(Bar));

hokein wrote:

This is a tricky bit.

The question arises: should we consider all trivially copyable types to be 
bitwise cloneable? My inclination is to say yes. Since memcpy is `safe` on all 
trivially copyable types, it's probably a good idea to ensure that 
bitwise_clonable covers as many types as possible.

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


[clang] [AST] RecursiveASTVisitor: Don't traverse the alias deduction guides in the default mode. (PR #91454)

2024-05-16 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/91454

>From e560fe2bf2d4bdc07a71682aa4d3a4bee8730b80 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Wed, 8 May 2024 12:11:10 +0200
Subject: [PATCH 1/2] [AST] RecursiveASTVisitor: Don't traverse the alias
 deduction guides in default mode.

---
 clang/include/clang/AST/RecursiveASTVisitor.h | 28 --
 .../DeductionGuide.cpp| 89 +++
 2 files changed, 110 insertions(+), 7 deletions(-)
 create mode 100644 
clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp

diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index f9b145b4e86a5..2517189c95300 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -736,13 +736,27 @@ bool RecursiveASTVisitor::TraverseDecl(Decl *D) {
 
   // As a syntax visitor, by default we want to ignore declarations for
   // implicit declarations (ones not typed explicitly by the user).
-  if (!getDerived().shouldVisitImplicitCode() && D->isImplicit()) {
-// For an implicit template type parameter, its type constraints are not
-// implicit and are not represented anywhere else. We still need to visit
-// them.
-if (auto *TTPD = dyn_cast(D))
-  return TraverseTemplateTypeParamDeclConstraints(TTPD);
-return true;
+  if (!getDerived().shouldVisitImplicitCode()) {
+if (D->isImplicit()) {
+  // For an implicit template type parameter, its type constraints are not
+  // implicit and are not represented anywhere else. We still need to visit
+  // them.
+  if (auto *TTPD = dyn_cast(D))
+return TraverseTemplateTypeParamDeclConstraints(TTPD);
+  return true;
+}
+
+// Deduction guides for alias templates are always synthesized, so they
+// should not be traversed unless shouldVisitImplicitCode() returns true.
+//
+// It's important to note that checking the implicit bit is not efficient
+// for the alias case. For deduction guides synthesized from explicit
+// user-defined deduction guides, we must maintain the explicit bit to
+// ensure correct overload resolution.
+if (auto *FTD = dyn_cast(D))
+  if (llvm::isa_and_present(
+  FTD->getDeclName().getCXXDeductionGuideTemplate()))
+return true;
   }
 
   switch (D->getKind()) {
diff --git 
a/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp 
b/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
new file mode 100644
index 0..abfdbaea4a615
--- /dev/null
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
@@ -0,0 +1,89 @@
+//===- unittest/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include 
+
+using namespace clang;
+
+namespace {
+
+class DeductionGuideVisitor
+: public ExpectedLocationVisitor {
+public:
+  DeductionGuideVisitor(bool ShouldVisitImplicitCode)
+  : ShouldVisitImplicitCode(ShouldVisitImplicitCode) {}
+  bool VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
+std::string Storage;
+llvm::raw_string_ostream Stream(Storage);
+D->print(Stream);
+Match(Stream.str(),D->getLocation());
+return true;
+  }
+
+  bool shouldVisitTemplateInstantiations() const {
+return false;
+  }
+
+  bool shouldVisitImplicitCode() const {
+return ShouldVisitImplicitCode;
+  }
+  bool ShouldVisitImplicitCode;
+};
+
+TEST(RecursiveASTVisitor, DeductionGuideNonImplicitMode) {
+  DeductionGuideVisitor Visitor(/*ShouldVisitImplicitCode*/ false);
+  // Verify that the synthezied deduction guide for alias is not visited in
+  // RAV's implicit mode.
+  Visitor.ExpectMatch("Foo(T) -> Foo", 11, 1);
+  Visitor.DisallowMatch("Bar(type-parameter-0-0) -> Foo", 14, 1);
+  EXPECT_TRUE(Visitor.runOver(
+R"cpp(
+template 
+concept False = true;
+
+template  
+struct Foo { 
+  Foo(T);
+};
+
+template requires False
+Foo(T) -> Foo;
+
+template 
+using Bar = Foo;
+Bar s(1); 
+   )cpp"
+  , DeductionGuideVisitor::Lang_CXX2a));
+}
+
+TEST(RecursiveASTVisitor, DeductionGuideImplicitMode) {
+  DeductionGuideVisitor Visitor(/*ShouldVisitImplicitCode*/ true);
+  Visitor.ExpectMatch("Foo(T) -> Foo", 11, 1);
+  Visitor.ExpectMatch("Bar(type-parameter-0-0) -> Foo", 14, 1);
+  EXPECT_TRUE(Visitor.runOver(
+R"cpp(
+template 
+concept False = true;
+
+template  
+struct Foo { 
+  Foo(T);
+};
+
+template requires False
+Foo(T) -> Foo;
+
+template 
+using Bar = Foo;
+Bar s(1); 
+   )cpp"
+  , DeductionGuideVisitor::Lang_CXX2a));
+}
+
+} // end anonymous namespace

>From f449f1f990203

[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-16 Thread Shengchen Kan via cfe-commits


@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {

KanRobert wrote:

> > Will the feature be emitted in IR?
> 
> yes, I was referring `prefer-no-gather`

Then it's not expected. `prefer-no-gather` is a real tuning feature.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-16 Thread Freddy Ye via cfe-commits


@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {

FreddyLeaf wrote:

SSELevel relies on feature string in IR attribute as well. it's same situation 
here.

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


[clang] [clang-tools-extra] [clang] Fix CXXNewExpr end source location for 'new struct S' (PR #92266)

2024-05-16 Thread Haojian Wu via cfe-commits

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

thanks, still good.

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


[clang] [clang-tools-extra] [clang] Fix CXXNewExpr end source location for 'new struct S' (PR #92266)

2024-05-16 Thread Haojian Wu via cfe-commits


@@ -583,3 +583,8 @@ void NonADLCall3() {
   f(x);
 }
 } // namespace test_adl_call_three
+

hokein wrote:

nit: wrap the code within `namespace GH35300 { ...}`.

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


[clang] [clang-tools-extra] [clang] Fix CXXNewExpr end source location for 'new struct S' (PR #92266)

2024-05-16 Thread Haojian Wu via cfe-commits

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-16 Thread Freddy Ye via cfe-commits


@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {

FreddyLeaf wrote:

> > > Will the feature be emitted in IR?
> > 
> > 
> > yes, I was referring `prefer-no-gather`
> 
> Then it's not expected. `prefer-no-gather` is a real tuning feature.

actually, no cpus enabled this tuning feature.

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-16 Thread Shengchen Kan via cfe-commits


@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {

KanRobert wrote:

> SSELevel relies on feature string in IR attribute as well.
Which one do you mean?

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


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-16 Thread Shengchen Kan via cfe-commits

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


[clang] [clang-tools-extra] [clang] Fix CXXNewExpr end source location for 'new struct S' (PR #92266)

2024-05-16 Thread Arseniy Zaostrovnykh via cfe-commits

https://github.com/necto updated https://github.com/llvm/llvm-project/pull/92266

>From eeb24ddbf261fd7667dd05feee14637bc379d182 Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Wed, 15 May 2024 16:02:07 +0200
Subject: [PATCH 1/4] Fix CXXNewExpr end source location for 'new struct S'

---
 clang/lib/Parse/ParseDeclCXX.cpp  | 1 +
 clang/test/Misc/ast-source-ranges.cpp | 5 +
 2 files changed, 6 insertions(+)
 create mode 100644 clang/test/Misc/ast-source-ranges.cpp

diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 65ddebca49bc6..32c4e923243a9 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1883,6 +1883,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   if (Tok.is(tok::identifier)) {
 Name = Tok.getIdentifierInfo();
 NameLoc = ConsumeToken();
+DS.SetRangeEnd(NameLoc);
 
 if (Tok.is(tok::less) && getLangOpts().CPlusPlus) {
   // The name was supposed to refer to a template, but didn't.
diff --git a/clang/test/Misc/ast-source-ranges.cpp 
b/clang/test/Misc/ast-source-ranges.cpp
new file mode 100644
index 0..9c0ab9449a6f5
--- /dev/null
+++ b/clang/test/Misc/ast-source-ranges.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -ast-dump %s  2>&1 | FileCheck %s
+
+struct Sock {};
+void leakNewFn() { new struct Sock; }
+// CHECK: CXXNewExpr {{.*}}  'struct Sock *'

>From 28d5f458542d1fed2b3d82543c93e61a2768637c Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Wed, 15 May 2024 16:53:53 +0200
Subject: [PATCH 2/4] Fix clang-tidy:make-unique

---
 .../test/clang-tidy/checkers/modernize/make-unique.cpp | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
index 7934c6e93ffbd..fe512a8f3bf32 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
@@ -606,11 +606,8 @@ void invoke_template() {
   template_fun(foo);
 }
 
-void no_fix_for_invalid_new_loc() {
-  // FIXME: Although the code is valid, the end location of `new struct Base` 
is
-  // invalid. Correct it once https://bugs.llvm.org/show_bug.cgi?id=35952 is
-  // fixed.
+void fix_for_c_style_struct() {
   auto T = std::unique_ptr(new struct Base);
   // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use std::make_unique instead
-  // CHECK-FIXES: auto T = std::unique_ptr(new struct Base);
+  // CHECK-FIXES: auto T = std::make_unique();
 }

>From 21077adfefd5a255735cb7f6f0bb690a1e880e62 Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Thu, 16 May 2024 09:27:25 +0200
Subject: [PATCH 3/4] Move the AST dump test to the conventional file

---
 clang/test/AST/ast-dump-expr.cpp  | 5 +
 clang/test/Misc/ast-source-ranges.cpp | 5 -
 2 files changed, 5 insertions(+), 5 deletions(-)
 delete mode 100644 clang/test/Misc/ast-source-ranges.cpp

diff --git a/clang/test/AST/ast-dump-expr.cpp b/clang/test/AST/ast-dump-expr.cpp
index 69e65e22d61d0..9b29ab1bbb228 100644
--- a/clang/test/AST/ast-dump-expr.cpp
+++ b/clang/test/AST/ast-dump-expr.cpp
@@ -583,3 +583,8 @@ void NonADLCall3() {
   f(x);
 }
 } // namespace test_adl_call_three
+
+struct Sock {};
+void leakNewFn() { new struct Sock; }
+// CHECK: CXXNewExpr {{.*}}  'struct Sock *'
+
diff --git a/clang/test/Misc/ast-source-ranges.cpp 
b/clang/test/Misc/ast-source-ranges.cpp
deleted file mode 100644
index 9c0ab9449a6f5..0
--- a/clang/test/Misc/ast-source-ranges.cpp
+++ /dev/null
@@ -1,5 +0,0 @@
-// RUN: %clang_cc1 -ast-dump %s  2>&1 | FileCheck %s
-
-struct Sock {};
-void leakNewFn() { new struct Sock; }
-// CHECK: CXXNewExpr {{.*}}  'struct Sock *'

>From 4eeb467d612ccf184399df95172311e6f68ea60d Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh 
Date: Thu, 16 May 2024 10:33:12 +0200
Subject: [PATCH 4/4] wrap test into a GH35300 namespace

---
 clang/test/AST/ast-dump-expr.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/test/AST/ast-dump-expr.cpp b/clang/test/AST/ast-dump-expr.cpp
index e848cee2637ed..604868103dab8 100644
--- a/clang/test/AST/ast-dump-expr.cpp
+++ b/clang/test/AST/ast-dump-expr.cpp
@@ -584,7 +584,9 @@ void NonADLCall3() {
 }
 } // namespace test_adl_call_three
 
+namespace GH35300 {
 struct Sock {};
 void leakNewFn() { new struct Sock; }
 // CHECK: CXXNewExpr {{.*}}  'struct Sock *'
+}
 

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


[clang] [clang-tools-extra] [clang] Fix CXXNewExpr end source location for 'new struct S' (PR #92266)

2024-05-16 Thread Arseniy Zaostrovnykh via cfe-commits


@@ -583,3 +583,8 @@ void NonADLCall3() {
   f(x);
 }
 } // namespace test_adl_call_three
+

necto wrote:

Done

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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Simon Pilgrim via cfe-commits


@@ -3019,6 +3019,26 @@ C-style cast applied to each element of the first 
argument.
 
 Query for this feature with ``__has_builtin(__builtin_convertvector)``.
 
+``__builtin_selectvector``
+--
+
+``__builtin_selectvector`` is used to express generic vector element selection.

RKSimon wrote:

Extend this description to explicitly describe the input/output types and 
mechanism - don't just rely on the code snippet (although that's a nice 
accompaniment): The input must all be vectors of the same same number of 
elements, the 2 first operands must be the same type etc. etc. (basically 
everything in SemaChecking).

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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Simon Pilgrim via cfe-commits


@@ -232,225 +232,225 @@ typedef char __v2qi __attribute__((__vector_size__(2)));
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_mask_add_epi32(__m256i __W, __mmask8 __U, __m256i __A, __m256i __B)
 {
-  return (__m256i)__builtin_ia32_selectd_256((__mmask8)__U,
- (__v8si)_mm256_add_epi32(__A, 
__B),
- (__v8si)__W);
+  return (__m256i)__builtin_selectvector((__v8si)_mm256_add_epi32(__A, __B),
+ (__v8si)__W,
+ __builtin_bit_cast(__vecmask8, __U));
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_maskz_add_epi32(__mmask8 __U, __m256i __A, __m256i __B)
 {
-  return (__m256i)__builtin_ia32_selectd_256((__mmask8)__U,
- (__v8si)_mm256_add_epi32(__A, 
__B),
- (__v8si)_mm256_setzero_si256());
+  return (__m256i)__builtin_selectvector((__v8si)_mm256_add_epi32(__A, __B),
+ (__v8si)_mm256_setzero_si256(),
+ __builtin_bit_cast(__vecmask8, __U));
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_mask_add_epi64(__m256i __W, __mmask8 __U, __m256i __A, __m256i __B)
 {
-  return (__m256i)__builtin_ia32_selectq_256((__mmask8)__U,
- (__v4di)_mm256_add_epi64(__A, 
__B),
- (__v4di)__W);
+  return (__m256i)__builtin_selectvector((__v4di)_mm256_add_epi64(__A, __B),
+ (__v4di)__W,
+ __builtin_bit_cast(__vecmask4, __U));
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_maskz_add_epi64(__mmask8 __U, __m256i __A, __m256i __B)
 {
-  return (__m256i)__builtin_ia32_selectq_256((__mmask8)__U,
- (__v4di)_mm256_add_epi64(__A, 
__B),
- (__v4di)_mm256_setzero_si256());
+  return (__m256i)__builtin_selectvector((__v4di)_mm256_add_epi64(__A, __B),
+ (__v4di)_mm256_setzero_si256(),
+ __builtin_bit_cast(__vecmask4, __U));
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_mask_sub_epi32(__m256i __W, __mmask8 __U, __m256i __A, __m256i __B)
 {
-  return (__m256i)__builtin_ia32_selectd_256((__mmask8)__U,
- (__v8si)_mm256_sub_epi32(__A, 
__B),
- (__v8si)__W);
+  return (__m256i)__builtin_selectvector((__v8si)_mm256_sub_epi32(__A, __B),
+ (__v8si)__W,
+ __builtin_bit_cast(__vecmask8, __U));
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_maskz_sub_epi32(__mmask8 __U, __m256i __A, __m256i __B)
 {
-  return (__m256i)__builtin_ia32_selectd_256((__mmask8)__U,
- (__v8si)_mm256_sub_epi32(__A, 
__B),
- (__v8si)_mm256_setzero_si256());
+  return (__m256i)__builtin_selectvector((__v8si)_mm256_sub_epi32(__A, __B),
+ (__v8si)_mm256_setzero_si256(),
+ __builtin_bit_cast(__vecmask8, __U));
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_mask_sub_epi64(__m256i __W, __mmask8 __U, __m256i __A, __m256i __B)
 {
-  return (__m256i)__builtin_ia32_selectq_256((__mmask8)__U,
- (__v4di)_mm256_sub_epi64(__A, 
__B),
- (__v4di)__W);
+  return (__m256i)__builtin_selectvector((__v4di)_mm256_sub_epi64(__A, __B),
+ (__v4di)__W,
+ __builtin_bit_cast(__vecmask4, __U));
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_maskz_sub_epi64(__mmask8 __U, __m256i __A, __m256i __B)
 {
-  return (__m256i)__builtin_ia32_selectq_256((__mmask8)__U,
- (__v4di)_mm256_sub_epi64(__A, 
__B),
- (__v4di)_mm256_setzero_si256());
+  return (__m256i)__builtin_selectvector((__v4di)_mm256_sub_epi64(__A, __B),
+ (__v4di)_mm256_setzero_si256(),
+ __builtin_bit_cast(__vecmask4, __U));
 }
 
 static __inline__ __m128i __DEFAULT_FN_ATTRS128
 _mm_mask_add_epi32(__m128i __W, __mmask8 __U, __m128i __A, __m128i __B)
 {
-  return (__m128i)__builtin_ia32_selectd_128((__mmask8)__U,
- (__v4si)_mm_add_epi32(__A, __B),
- (__v4si)__W);
+  return (__m128i)__builtin_selectvector((__v4si)_mm_add_epi32(__A, __

[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon commented:

constexpr handling?

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


[clang] [Clang] Fix P2564 handling of variable initializers (PR #89565)

2024-05-16 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

@katzdm 
It seems after this a `warn_impcast_integer_precision_constant` warning went 
missing:

https://godbolt.org/z/ndsPb44b4

Is that expected?

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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-16 Thread Matt Arsenault via cfe-commits


@@ -243,11 +243,16 @@ def VOP_READFIRSTLANE : VOPProfile <[i32, i32, untyped, 
untyped]> {
 // FIXME: Specify SchedRW for READFIRSTLANE_B32
 // TODO: There is VOP3 encoding also
 def V_READFIRSTLANE_B32 : VOP1_Pseudo <"v_readfirstlane_b32", 
VOP_READFIRSTLANE,
-   getVOP1Pat.ret, 1> {
+   [], 1> {
   let isConvergent = 1;
 }
 
+foreach vt = Reg32Types.types in {
+  def : GCNPat<(vt (AMDGPUreadfirstlane (vt VRegOrLdsSrc_32:$src0))),
+(V_READFIRSTLANE_B32 (vt VRegOrLdsSrc_32:$src0))

arsenm wrote:

```suggestion
(vt (V_READFIRSTLANE_B32 (vt VRegOrLdsSrc_32:$src0)))
```

This may fix your pattern type deduction issue 

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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-16 Thread Matt Arsenault via cfe-commits


@@ -780,14 +780,22 @@ defm V_SUBREV_U32 : VOP2Inst <"v_subrev_u32", 
VOP_I32_I32_I32_ARITH, null_frag,
 
 // These are special and do not read the exec mask.
 let isConvergent = 1, Uses = [] in {
-def V_READLANE_B32 : VOP2_Pseudo<"v_readlane_b32", VOP_READLANE,
-  [(set i32:$vdst, (int_amdgcn_readlane i32:$src0, i32:$src1))]>;
+def V_READLANE_B32 : VOP2_Pseudo<"v_readlane_b32", VOP_READLANE,[]>;
 let IsNeverUniform = 1, Constraints = "$vdst = $vdst_in", 
DisableEncoding="$vdst_in" in {
-def V_WRITELANE_B32 : VOP2_Pseudo<"v_writelane_b32", VOP_WRITELANE,
-  [(set i32:$vdst, (int_amdgcn_writelane i32:$src0, i32:$src1, 
i32:$vdst_in))]>;
+def V_WRITELANE_B32 : VOP2_Pseudo<"v_writelane_b32", VOP_WRITELANE, []>;
 } // End IsNeverUniform, $vdst = $vdst_in, DisableEncoding $vdst_in
 } // End isConvergent = 1
 
+foreach vt = Reg32Types.types in {
+  def : GCNPat<(vt (AMDGPUreadlane vt:$src0, i32:$src1)),
+(V_READLANE_B32 VRegOrLdsSrc_32:$src0, SCSrc_b32:$src1)

arsenm wrote:

Same here, supply the type to the result instruction 

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


[clang] [clang] Disallow VLA type compound literals (PR #91891)

2024-05-16 Thread Tomasz Stanisławski via cfe-commits


@@ -7274,12 +7274,19 @@ Sema::BuildCompoundLiteralExpr(SourceLocation 
LParenLoc, TypeSourceInfo *TInfo,
   // init a VLA in C++ in all cases (such as with non-trivial 
constructors).
   // FIXME: should we allow this construct in C++ when it makes sense to do
   // so?
-  std::optional NumInits;
-  if (const auto *ILE = dyn_cast(LiteralExpr))
-NumInits = ILE->getNumInits();
-  if ((LangOpts.CPlusPlus || NumInits.value_or(0)) &&
-  !tryToFixVariablyModifiedVarType(TInfo, literalType, LParenLoc,
-   diag::err_variable_object_no_init))
+  //
+  // But: C99-C23 6.5.2.5 Compound literals constraint 1: The type name
+  // shall specify an object type or an array of unknown size, but not a
+  // variable length array type. This seems odd, as it allows int a[size] =
+  // {}; but forbids int a[size] = (int[size]){}; As this is what the

tstanisl wrote:

technically speaking `int a[size] = (int[size]){};` is disallowed in **ALL** C 
standards. A better example would be:
```
int * a = (int[size]){};
```

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


[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)

2024-05-16 Thread Mital Ashok via cfe-commits


@@ -5591,7 +5592,11 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
   IsRValRef1);
   Args2.push_back(Obj2Ty);
 }
-size_t NumComparedArguments = NumCallArguments1 + ShouldConvert1;
+size_t NumComparedArguments = NumCallArguments1;
+// Either added an argument above or the prototype includes an explicit
+// object argument we need to count
+if (Method1)
+  ++NumComparedArguments;

MitalAshok wrote:

@mizvekov It would look something like this: 
b19a252f50e3b6d5dd50b0e51ec2865bb83fd5c9

But I think it's more error-prone because instead of `+1` in one place, it's 
sometimes a `+1` in all the places `ExplicitCallArguments` is set

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


[clang] [clang] Disallow VLA type compound literals (PR #91891)

2024-05-16 Thread via cfe-commits
Jim M. R. =?utf-8?q?Teichgräber?=,Jim M. R. =?utf-8?q?Teichgräber?=,
Jim M. R. =?utf-8?q?Teichgräber?=,Jim M. R. =?utf-8?q?Teichgräber?Message-ID:
In-Reply-To: 



@@ -7274,12 +7274,19 @@ Sema::BuildCompoundLiteralExpr(SourceLocation 
LParenLoc, TypeSourceInfo *TInfo,
   // init a VLA in C++ in all cases (such as with non-trivial 
constructors).
   // FIXME: should we allow this construct in C++ when it makes sense to do
   // so?
-  std::optional NumInits;
-  if (const auto *ILE = dyn_cast(LiteralExpr))
-NumInits = ILE->getNumInits();
-  if ((LangOpts.CPlusPlus || NumInits.value_or(0)) &&
-  !tryToFixVariablyModifiedVarType(TInfo, literalType, LParenLoc,
-   diag::err_variable_object_no_init))
+  //
+  // But: C99-C23 6.5.2.5 Compound literals constraint 1: The type name
+  // shall specify an object type or an array of unknown size, but not a
+  // variable length array type. This seems odd, as it allows int a[size] =
+  // {}; but forbids int a[size] = (int[size]){}; As this is what the

Sirraide wrote:

Ah yeah, true, you can’t do that with non-variable-length arrays either. We can 
update that comment as an NFC fix.

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


[clang] 1795fa5 - [NFC] Update example in comment

2024-05-16 Thread via cfe-commits

Author: Sirraide
Date: 2024-05-16T12:08:39+02:00
New Revision: 1795fa58bac5092f758bf27e1b27a2b07bab

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

LOG: [NFC] Update example in comment

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index cc507524e2fc2..151cda5d68b01 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7133,10 +7133,10 @@ Sema::BuildCompoundLiteralExpr(SourceLocation 
LParenLoc, TypeSourceInfo *TInfo,
   //
   // But: C99-C23 6.5.2.5 Compound literals constraint 1: The type name
   // shall specify an object type or an array of unknown size, but not a
-  // variable length array type. This seems odd, as it allows int a[size] =
-  // {}; but forbids int a[size] = (int[size]){}; As this is what the
-  // standard says, this is what's implemented here for C (except for the
-  // extension that permits constant foldable size arrays)
+  // variable length array type. This seems odd, as it allows 'int a[size] 
=
+  // {}', but forbids 'int *a = (int[size]){}'. As this is what the 
standard
+  // says, this is what's implemented here for C (except for the extension
+  // that permits constant foldable size arrays)
 
   auto diagID = LangOpts.CPlusPlus
 ? diag::err_variable_object_no_init



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


[clang] [clang] Disallow VLA type compound literals (PR #91891)

2024-05-16 Thread via cfe-commits
Jim M. R. =?utf-8?q?Teichgräber?=,Jim M. R. =?utf-8?q?Teichgräber?=,
Jim M. R. =?utf-8?q?Teichgräber?=,Jim M. R. =?utf-8?q?Teichgräber?Message-ID:
In-Reply-To: 



@@ -7274,12 +7274,19 @@ Sema::BuildCompoundLiteralExpr(SourceLocation 
LParenLoc, TypeSourceInfo *TInfo,
   // init a VLA in C++ in all cases (such as with non-trivial 
constructors).
   // FIXME: should we allow this construct in C++ when it makes sense to do
   // so?
-  std::optional NumInits;
-  if (const auto *ILE = dyn_cast(LiteralExpr))
-NumInits = ILE->getNumInits();
-  if ((LangOpts.CPlusPlus || NumInits.value_or(0)) &&
-  !tryToFixVariablyModifiedVarType(TInfo, literalType, LParenLoc,
-   diag::err_variable_object_no_init))
+  //
+  // But: C99-C23 6.5.2.5 Compound literals constraint 1: The type name
+  // shall specify an object type or an array of unknown size, but not a
+  // variable length array type. This seems odd, as it allows int a[size] =
+  // {}; but forbids int a[size] = (int[size]){}; As this is what the

Sirraide wrote:

Alright, done.

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


[clang] 5ffd154 - [analyzer] Clean up list of taint propagation functions (#91635)

2024-05-16 Thread via cfe-commits

Author: Donát Nagy
Date: 2024-05-16T12:10:56+02:00
New Revision: 5ffd154cf61390c1ed32a1b0eb134929f78c0fbe

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

LOG: [analyzer] Clean up list of taint propagation functions (#91635)

This commit refactors GenericTaintChecker and performs various
improvements in the list of taint propagation functions:

1. The matching mode (usually `CDM::CLibrary` or
`CDM::CLibraryMaybeHardened`) was specified to avoid matching e.g. C++
methods or functions from a user-defined namespace that happen to share
the name of a well-known library function.
2. With these matching modes, a `CallDescription` can automatically
match builtin variants of the functions, so entries that explicitly
specified a builtin function were removed. This eliminated
inconsistencies where the "normal" and the builtin variant of the same
function was handled differently (e.g. `__builtin_strlcat` was covered,
while plain `strlcat` wasn't; while `__builtin_memcpy` and `memcpy` were
both on the list with different propagation rules).
3. The modeling of the functions `strlcat` and `strncat` was updated to
propagate taint from the first argument (index 0), because a tainted
string should remain tainted even if we append something else to it.
Note that this was already applied to `strcat` and `wcsncat` by commit
6ceb1c0ef9f544be0eed65e46cc7d99941a001bf.
4. Some functions were updated to propagate taint from a size/length
argument to the result: e.g. `memcmp(p, q, get_tainted_int())` will now
return a tainted value (because the attacker can manipulate it). This
principle was already present in some propagation rules (e.g.
`__builtin_memcpy` was handled this way), and even after this commit
there are still some functions where it isn't applied. (I only aimed for
consistency within the same function family.)
5. Functions that have hardened `__FOO_chk()` variants are matched in
`CDM:CLibraryMaybeHardened` to ensure consistent handling of the
"normal" and the hardened variant. I added special handling for the
hardened variants of "sprintf" and "snprintf" because there the extra
parameters are inserted into the middle of the parameter list.
6. Modeling of `sscanf_s` was added, to complete the group of `fscanf`,
`fscanf_s` and `sscanf`.
7. The `Source()` specifications for `gets`, `gets_s` and `wgetch` were
ill-formed: they were specifying variadic arguments starting at argument
index `ReturnValueIndex`. (That is, in addition to the return value they
were propagating taint to all arguments.)
8. Functions that were related to each other were grouped together. (I
know that this makes the diff harder to read, but I felt that the full
list is unreadable without some reorganization.)
9. I spotted and removed some redundant curly braces. Perhaps would be
good to switch to a cleaner layout with less nested braces...
10. I updated some obsolete comments and added two TODOs for issues that
should be fixed in followup commits.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
index a0190c30bfd28..eb40a4cd3d902 100644
--- a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -400,17 +400,14 @@ class GenericTaintChecker : public 
Checker {
   void taintUnsafeSocketProtocol(const CallEvent &Call,
  CheckerContext &C) const;
 
-  /// Default taint rules are initalized with the help of a CheckerContext to
-  /// access the names of built-in functions like memcpy.
+  /// The taint rules are initalized with the help of a CheckerContext to
+  /// access user-provided configuration.
   void initTaintRules(CheckerContext &C) const;
 
-  /// CallDescription currently cannot restrict matches to the global namespace
-  /// only, which is why multiple CallDescriptionMaps are used, as we want to
-  /// disambiguate global C functions from functions inside user-defined
-  /// namespaces.
-  // TODO: Remove separation to simplify matching logic once CallDescriptions
-  // are more expressive.
-
+  // TODO: The two separate `CallDescriptionMap`s were introduced when
+  // `CallDescription` was unable to restrict matches to the global namespace
+  // only. This limitation no longer exists, so the following two maps should
+  // be unified.
   mutable std::optional StaticTaintRules;
   mutable std::optional DynamicTaintRules;
 };
@@ -506,7 +503,8 @@ void GenericTaintRuleParser::consumeRulesFromConfig(const 
Config &C,
 GenericTaintRule &&Rule,
 

[clang] [analyzer] Clean up list of taint propagation functions (PR #91635)

2024-05-16 Thread Donát Nagy via cfe-commits

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


[clang] [clang][c++20] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-05-16 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/85837

>From 61abd7b6089ecb87eaf6886e251969d4db87e223 Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Tue, 19 Mar 2024 19:05:36 +0300
Subject: [PATCH 1/2] [clang][c++20] Fix code coverage mapping crash with
 generalized NTTPs

Introduced in #78041, originally reported as #79957 and fixed partially
in #80050.

`OpaqueValueExpr` used with `TemplateArgument::StructuralValue` has no
corresponding source expression.

A test case with subobject-referring NTTP added.
---
 clang/lib/CodeGen/CoverageMappingGen.cpp | 3 ++-
 clang/test/CoverageMapping/templates.cpp | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index cc8ab7a5b4369..48896fa03d9ff 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2187,7 +2187,8 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
-Visit(OVE->getSourceExpr());
+if (const Expr *SE = OVE->getSourceExpr())
+  Visit(SE);
   }
 };
 
diff --git a/clang/test/CoverageMapping/templates.cpp 
b/clang/test/CoverageMapping/templates.cpp
index 143e566a33cb8..7e7f2208f1145 100644
--- a/clang/test/CoverageMapping/templates.cpp
+++ b/clang/test/CoverageMapping/templates.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
 
 template
 void unused(T x) {
@@ -30,5 +30,6 @@ namespace structural_value_crash {
 
   void test() {
 tpl_fn();
+tpl_fn<&arr[1]>();
   }
 }

>From 9684fed244607e3c7923c0a3118945c559e2d5d5 Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Thu, 16 May 2024 12:18:17 +0300
Subject: [PATCH 2/2] Fix up: check `isUnique` instead of source expr presence

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

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 48896fa03d9ff..5f62d2ae46bdb 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2187,8 +2187,8 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
-if (const Expr *SE = OVE->getSourceExpr())
-  Visit(SE);
+if (OVE->isUnique())
+  Visit(OVE->getSourceExpr());
   }
 };
 

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


[clang-tools-extra] ba2e4fe - [clang] Fix CXXNewExpr end source location for 'new struct S' (#92266)

2024-05-16 Thread via cfe-commits

Author: Arseniy Zaostrovnykh
Date: 2024-05-16T12:14:53+02:00
New Revision: ba2e4fe4e7f79e49fcac54ea20f5b899dc687cfc

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

LOG: [clang] Fix CXXNewExpr end source location for 'new struct S' (#92266)

Currently, `new struct S` fails to set any valid end source location
because the token corresponding to `S` is consumed in
`ParseClassSpecifier` and is not accessible in the
`ParseDeclarationSpecifiers` that normally sets the end source location.

Fixes #35300

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/AST/ast-dump-expr.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
index 7934c6e93ffbd..fe512a8f3bf32 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
@@ -606,11 +606,8 @@ void invoke_template() {
   template_fun(foo);
 }
 
-void no_fix_for_invalid_new_loc() {
-  // FIXME: Although the code is valid, the end location of `new struct Base` 
is
-  // invalid. Correct it once https://bugs.llvm.org/show_bug.cgi?id=35952 is
-  // fixed.
+void fix_for_c_style_struct() {
   auto T = std::unique_ptr(new struct Base);
   // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use std::make_unique instead
-  // CHECK-FIXES: auto T = std::unique_ptr(new struct Base);
+  // CHECK-FIXES: auto T = std::make_unique();
 }

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 65ddebca49bc6..32c4e923243a9 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1883,6 +1883,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   if (Tok.is(tok::identifier)) {
 Name = Tok.getIdentifierInfo();
 NameLoc = ConsumeToken();
+DS.SetRangeEnd(NameLoc);
 
 if (Tok.is(tok::less) && getLangOpts().CPlusPlus) {
   // The name was supposed to refer to a template, but didn't.

diff  --git a/clang/test/AST/ast-dump-expr.cpp 
b/clang/test/AST/ast-dump-expr.cpp
index 4df5ba4276abd..604868103dab8 100644
--- a/clang/test/AST/ast-dump-expr.cpp
+++ b/clang/test/AST/ast-dump-expr.cpp
@@ -583,3 +583,10 @@ void NonADLCall3() {
   f(x);
 }
 } // namespace test_adl_call_three
+
+namespace GH35300 {
+struct Sock {};
+void leakNewFn() { new struct Sock; }
+// CHECK: CXXNewExpr {{.*}}  'struct Sock *'
+}
+



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


[clang] [clang-tools-extra] [clang] Fix CXXNewExpr end source location for 'new struct S' (PR #92266)

2024-05-16 Thread Balazs Benics via cfe-commits

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

2024-05-16 Thread via cfe-commits

Sirraide wrote:

@dougsonos Btw, feel free to remind reviewers that this pr exists every week or 
so if no-one reviews it. Just adding a comment with the text ‘ping’ is how we 
usually handle that.

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


[clang] [clang] Disallow VLA type compound literals (PR #91891)

2024-05-16 Thread Jim M . R . Teichgräber via cfe-commits


@@ -7274,12 +7274,19 @@ Sema::BuildCompoundLiteralExpr(SourceLocation 
LParenLoc, TypeSourceInfo *TInfo,
   // init a VLA in C++ in all cases (such as with non-trivial 
constructors).
   // FIXME: should we allow this construct in C++ when it makes sense to do
   // so?
-  std::optional NumInits;
-  if (const auto *ILE = dyn_cast(LiteralExpr))
-NumInits = ILE->getNumInits();
-  if ((LangOpts.CPlusPlus || NumInits.value_or(0)) &&
-  !tryToFixVariablyModifiedVarType(TInfo, literalType, LParenLoc,
-   diag::err_variable_object_no_init))
+  //
+  // But: C99-C23 6.5.2.5 Compound literals constraint 1: The type name
+  // shall specify an object type or an array of unknown size, but not a
+  // variable length array type. This seems odd, as it allows int a[size] =
+  // {}; but forbids int a[size] = (int[size]){}; As this is what the

J-MR-T wrote:

Sorry, I should have been more clear, I didn't mean it would be allowed in 
another C standard, just that it's unexpected from a language point of view. 
But it's not that important anyway, so I hope the new version works better :). 

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


[clang] [clang] Implement CWG2428 "Deprecating a concept" (PR #92295)

2024-05-16 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/92295

>From a0d5a234431f3db2f0283ffa0909bf8c254aa611 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 15 May 2024 20:20:43 +0300
Subject: [PATCH 1/3] [clang] Implement CWG2428 "Deprecating a concept"

---
 clang/include/clang/Sema/Sema.h   |  3 ++-
 clang/lib/Parse/ParseTemplate.cpp | 15 +--
 clang/lib/Sema/SemaTemplate.cpp   |  8 +++-
 clang/test/CXX/drs/cwg24xx.cpp| 28 
 clang/www/cxx_dr_status.html  | 22 +-
 5 files changed, 63 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..330076ca77371 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9356,7 +9356,8 @@ class Sema final : public SemaBase {
   Decl *ActOnConceptDefinition(Scope *S,
MultiTemplateParamsArg TemplateParameterLists,
const IdentifierInfo *Name,
-   SourceLocation NameLoc, Expr *ConstraintExpr);
+   SourceLocation NameLoc, Expr *ConstraintExpr,
+   const ParsedAttributesView &Attrs);
 
   void CheckConceptRedefinition(ConceptDecl *NewDecl, LookupResult &Previous,
 bool &AddToScope);
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index 665253a6674d2..b8f2b3f9657e7 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -167,9 +167,11 @@ Parser::DeclGroupPtrTy 
Parser::ParseTemplateDeclarationOrSpecialization(
   LastParamListWasEmpty);
 
   // Parse the actual template declaration.
-  if (Tok.is(tok::kw_concept))
-return Actions.ConvertDeclToDeclGroup(
-ParseConceptDefinition(TemplateInfo, DeclEnd));
+  if (Tok.is(tok::kw_concept)) {
+Decl *ConceptDecl = ParseConceptDefinition(TemplateInfo, DeclEnd);
+ParsingTemplateParams.complete(ConceptDecl);
+return Actions.ConvertDeclToDeclGroup(ConceptDecl);
+  }
 
   return ParseDeclarationAfterTemplate(
   Context, TemplateInfo, ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
@@ -316,7 +318,8 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo 
&TemplateInfo,
   const IdentifierInfo *Id = Result.Identifier;
   SourceLocation IdLoc = Result.getBeginLoc();
 
-  DiagnoseAndSkipCXX11Attributes();
+  ParsedAttributes Attrs(AttrFactory);
+  MaybeParseCXX11Attributes(Attrs);
 
   if (!TryConsumeToken(tok::equal)) {
 Diag(Tok.getLocation(), diag::err_expected) << tok::equal;
@@ -335,8 +338,8 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo 
&TemplateInfo,
   ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
   Expr *ConstraintExpr = ConstraintExprResult.get();
   return Actions.ActOnConceptDefinition(getCurScope(),
-*TemplateInfo.TemplateParams,
-Id, IdLoc, ConstraintExpr);
+*TemplateInfo.TemplateParams, Id, 
IdLoc,
+ConstraintExpr, Attrs);
 }
 
 /// ParseTemplateParameters - Parses a template-parameter-list enclosed in
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c7aac068e264b..2da933896b4da 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -5583,6 +5583,8 @@ Sema::CheckConceptTemplateId(const CXXScopeSpec &SS,
   /*UpdateArgsWithConversions=*/false))
 return ExprError();
 
+  DiagnoseUseOfDecl(NamedConcept, ConceptNameInfo.getLoc());
+
   auto *CSD = ImplicitConceptSpecializationDecl::Create(
   Context, NamedConcept->getDeclContext(), NamedConcept->getLocation(),
   CanonicalConverted);
@@ -9787,7 +9789,8 @@ Decl *Sema::ActOnTemplateDeclarator(Scope *S,
 
 Decl *Sema::ActOnConceptDefinition(
 Scope *S, MultiTemplateParamsArg TemplateParameterLists,
-const IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr) {
+const IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr,
+const ParsedAttributesView &Attrs) {
   DeclContext *DC = CurContext;
 
   if (!DC->getRedeclContext()->isFileContext()) {
@@ -9849,6 +9852,9 @@ Decl *Sema::ActOnConceptDefinition(
   ActOnDocumentableDecl(NewDecl);
   if (AddToScope)
 PushOnScopeChains(NewDecl, S);
+
+  ProcessDeclAttributeList(S, NewDecl, Attrs);
+
   return NewDecl;
 }
 
diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index 9f876cd870834..805a95c30470e 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -45,6 +45,34 @@ void fallthrough(int n) {
 #endif
 }
 
+namespace cwg2428 { // cwg2428: 19
+#if __cplusplus >= 202002L
+template 
+concept C [[deprecated]] = true; // #C
+
+template 
+concept C3 =

[clang] [clang] Implement CWG2428 "Deprecating a concept" (PR #92295)

2024-05-16 Thread Vlad Serebrennikov via cfe-commits


@@ -45,6 +45,38 @@ void fallthrough(int n) {
 #endif
 }
 
+namespace cwg2428 { // cwg2428: 19
+#if __cplusplus >= 202002L
+template 
+concept C [[deprecated]] = true; // #cwg2428-C
+
+template 
+[[deprecated]] concept C2 = true;
+// expected-error@-1 {{expected unqualified-id}}
+
+template 
+concept C3 = C;
+// expected-warning@-1 {{'C' is deprecated}}
+//   expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated 
here}}
+
+template 
+// expected-warning@-1 {{'C' is deprecated}}
+//   expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated 
here}}
+requires C
+// expected-warning@-1 {{'C' is deprecated}}
+//   expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated 
here}}
+void f() {
+  bool b = C;
+  // expected-warning@-1 {{'C' is deprecated}}
+  //   expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated 
here}}
+};
+
+void g(C auto a) {};
+// expected-warning@-1 {{'C' is deprecated}}
+//   expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated 
here}}
+#endif
+} // namespace cwg2428
+

Endilll wrote:

Thank you for the test! It wasn't passing, so I added it and made it work.

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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Phoebe Wang via cfe-commits


@@ -3744,6 +3744,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 return RValue::get(Result);
   }
 
+  case Builtin::BI__builtin_selectvector: {
+return RValue::get(Builder.CreateSelect(EmitScalarExpr(E->getArg(2)),

phoebewang wrote:

Should we check all one (or all zero) like we did in `EmitX86Select`?

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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Phoebe Wang via cfe-commits


@@ -3019,6 +3019,26 @@ C-style cast applied to each element of the first 
argument.
 
 Query for this feature with ``__has_builtin(__builtin_convertvector)``.
 
+``__builtin_selectvector``
+--
+
+``__builtin_selectvector`` is used to express generic vector element selection.
+
+**Signature**:
+
+.. code-block:: c++
+
+  template 
+  simd_vec __builtin_selectvector(simd_vec lhs, simd_vec rhs,
+simd_vec cond)

phoebewang wrote:

Maybe put `cond` the first operand to match with `select` and the old X86 
builtins?

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


[clang] 239f8b9 - [AST] RecursiveASTVisitor: Don't traverse the alias deduction guides in the default mode. (#91454)

2024-05-16 Thread via cfe-commits

Author: Haojian Wu
Date: 2024-05-16T12:44:47+02:00
New Revision: 239f8b9eb0725b4c6ff8342717b6abbfc9a7915a

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

LOG: [AST] RecursiveASTVisitor: Don't traverse the alias deduction guides in 
the default mode. (#91454)

By default (`shouldVisitImplicitCode()` returns `false`), RAV should not
traverse AST nodes that are not spelled in the source code. Deduction
guides for alias templates are always synthesized, so they should not be
traversed.

This is usually done by checking the implicit bit of the Decl. However,
this doesn't work deduction guides that are synthesized from explicit
user-defined deduction guides, as we must maintain the explicit bit to
ensure correct overload resolution.

Added: 
clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp

Modified: 
clang/include/clang/AST/RecursiveASTVisitor.h

Removed: 




diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 782f60844506f..f5cefedb07e0e 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -736,13 +736,27 @@ bool RecursiveASTVisitor::TraverseDecl(Decl *D) {
 
   // As a syntax visitor, by default we want to ignore declarations for
   // implicit declarations (ones not typed explicitly by the user).
-  if (!getDerived().shouldVisitImplicitCode() && D->isImplicit()) {
-// For an implicit template type parameter, its type constraints are not
-// implicit and are not represented anywhere else. We still need to visit
-// them.
-if (auto *TTPD = dyn_cast(D))
-  return TraverseTemplateTypeParamDeclConstraints(TTPD);
-return true;
+  if (!getDerived().shouldVisitImplicitCode()) {
+if (D->isImplicit()) {
+  // For an implicit template type parameter, its type constraints are not
+  // implicit and are not represented anywhere else. We still need to visit
+  // them.
+  if (auto *TTPD = dyn_cast(D))
+return TraverseTemplateTypeParamDeclConstraints(TTPD);
+  return true;
+}
+
+// Deduction guides for alias templates are always synthesized, so they
+// should not be traversed unless shouldVisitImplicitCode() returns true.
+//
+// It's important to note that checking the implicit bit is not efficient
+// for the alias case. For deduction guides synthesized from explicit
+// user-defined deduction guides, we must maintain the explicit bit to
+// ensure correct overload resolution.
+if (auto *FTD = dyn_cast(D))
+  if (llvm::isa_and_present(
+  FTD->getDeclName().getCXXDeductionGuideTemplate()))
+return true;
   }
 
   switch (D->getKind()) {

diff  --git 
a/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp 
b/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
new file mode 100644
index 0..274f275ea66a9
--- /dev/null
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
@@ -0,0 +1,85 @@
+//===- unittest/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include 
+
+using namespace clang;
+
+namespace {
+
+class DeductionGuideVisitor
+: public ExpectedLocationVisitor {
+public:
+  DeductionGuideVisitor(bool ShouldVisitImplicitCode)
+  : ShouldVisitImplicitCode(ShouldVisitImplicitCode) {}
+  bool VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
+std::string Storage;
+llvm::raw_string_ostream Stream(Storage);
+D->print(Stream);
+Match(Stream.str(), D->getLocation());
+return true;
+  }
+
+  bool shouldVisitTemplateInstantiations() const { return false; }
+
+  bool shouldVisitImplicitCode() const { return ShouldVisitImplicitCode; }
+  bool ShouldVisitImplicitCode;
+};
+
+TEST(RecursiveASTVisitor, DeductionGuideNonImplicitMode) {
+  DeductionGuideVisitor Visitor(/*ShouldVisitImplicitCode*/ false);
+  // Verify that the synthezied deduction guide for alias is not visited in
+  // RAV's implicit mode.
+  Visitor.ExpectMatch("Foo(T) -> Foo", 11, 1);
+  Visitor.DisallowMatch("Bar(type-parameter-0-0) -> Foo", 14, 1);
+  EXPECT_TRUE(Visitor.runOver(
+  R"cpp(
+template 
+concept False = true;
+
+template  
+struct Foo { 
+  Foo(T);
+};
+
+template requires False
+Foo(T) -> Foo;
+
+template 
+using Bar = Foo;
+Bar s(1); 
+   )cpp",
+  DeductionGuideVisitor::Lang_CXX2a));
+}
+
+TEST(RecursiveASTVisitor, Deduction

[clang] [AST] RecursiveASTVisitor: Don't traverse the alias deduction guides in the default mode. (PR #91454)

2024-05-16 Thread Haojian Wu via cfe-commits

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


[clang] [clang] Implement CWG2428 "Deprecating a concept" (PR #92295)

2024-05-16 Thread Vlad Serebrennikov via cfe-commits


@@ -45,6 +45,34 @@ void fallthrough(int n) {
 #endif
 }
 
+namespace cwg2428 { // cwg2428: 19
+#if __cplusplus >= 202002L
+template 
+concept C [[deprecated]] = true; // #C

Endilll wrote:

Non-standard spellings of this attribute are out of scope of the Core issue, so 
I'd like to left them for a subsequent PR.

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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Phoebe Wang via cfe-commits


@@ -41,6 +41,22 @@ typedef long long __m512i_u 
__attribute__((__vector_size__(64), __aligned__(1)))
 typedef unsigned char __mmask8;
 typedef unsigned short __mmask16;
 
+#ifdef __cplusplus
+typedef bool __vecmask2 __attribute__((__ext_vector_type__(2)));
+typedef bool __vecmask4 __attribute__((__ext_vector_type__(4)));

phoebewang wrote:

We used `__mmask8` for `v2i1` and `v4i1` too. I don't we can bitcast them 
directly.

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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Phoebe Wang via cfe-commits


@@ -77,9 +77,9 @@ _mm512_cvtne2ps_pbh(__m512 __A, __m512 __B) {
 ///conversion of __B, and higher 256 bits come from conversion of __A.
 static __inline__ __m512bh __DEFAULT_FN_ATTRS512
 _mm512_mask_cvtne2ps_pbh(__m512bh __W, __mmask32 __U, __m512 __A, __m512 __B) {
-  return (__m512bh)__builtin_ia32_selectpbf_512((__mmask32)__U,
-(__v32bf)_mm512_cvtne2ps_pbh(__A, __B),
-(__v32bf)__W);
+  return (__m512bh)__builtin_selectvector(
+  (__v32bf)_mm512_cvtne2ps_pbh(__A, __B), (__v32bf)__W,
+  __builtin_bit_cast(__vecmask32, __U));

phoebewang wrote:

Can we use (__vecmask32) dirctly like `__v32bf` etc?

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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Phoebe Wang via cfe-commits


@@ -41,6 +41,22 @@ typedef long long __m512i_u 
__attribute__((__vector_size__(64), __aligned__(1)))
 typedef unsigned char __mmask8;
 typedef unsigned short __mmask16;
 
+#ifdef __cplusplus
+typedef bool __vecmask2 __attribute__((__ext_vector_type__(2)));
+typedef bool __vecmask4 __attribute__((__ext_vector_type__(4)));
+typedef bool __vecmask8 __attribute__((__ext_vector_type__(8)));
+typedef bool __vecmask16 __attribute__((__ext_vector_type__(16)));
+typedef bool __vecmask32 __attribute__((__ext_vector_type__(32)));
+typedef bool __vecmask64 __attribute__((__ext_vector_type__(64)));
+#else
+typedef _Bool __vecmask2 __attribute__((__ext_vector_type__(2)));

phoebewang wrote:

I'm a bit concerning about the ABI when people abuse them in function call.

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


[clang] [clang] Implement CWG2428 "Deprecating a concept" (PR #92295)

2024-05-16 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/92295

>From a0d5a234431f3db2f0283ffa0909bf8c254aa611 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 15 May 2024 20:20:43 +0300
Subject: [PATCH 1/4] [clang] Implement CWG2428 "Deprecating a concept"

---
 clang/include/clang/Sema/Sema.h   |  3 ++-
 clang/lib/Parse/ParseTemplate.cpp | 15 +--
 clang/lib/Sema/SemaTemplate.cpp   |  8 +++-
 clang/test/CXX/drs/cwg24xx.cpp| 28 
 clang/www/cxx_dr_status.html  | 22 +-
 5 files changed, 63 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..330076ca77371 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9356,7 +9356,8 @@ class Sema final : public SemaBase {
   Decl *ActOnConceptDefinition(Scope *S,
MultiTemplateParamsArg TemplateParameterLists,
const IdentifierInfo *Name,
-   SourceLocation NameLoc, Expr *ConstraintExpr);
+   SourceLocation NameLoc, Expr *ConstraintExpr,
+   const ParsedAttributesView &Attrs);
 
   void CheckConceptRedefinition(ConceptDecl *NewDecl, LookupResult &Previous,
 bool &AddToScope);
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index 665253a6674d2..b8f2b3f9657e7 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -167,9 +167,11 @@ Parser::DeclGroupPtrTy 
Parser::ParseTemplateDeclarationOrSpecialization(
   LastParamListWasEmpty);
 
   // Parse the actual template declaration.
-  if (Tok.is(tok::kw_concept))
-return Actions.ConvertDeclToDeclGroup(
-ParseConceptDefinition(TemplateInfo, DeclEnd));
+  if (Tok.is(tok::kw_concept)) {
+Decl *ConceptDecl = ParseConceptDefinition(TemplateInfo, DeclEnd);
+ParsingTemplateParams.complete(ConceptDecl);
+return Actions.ConvertDeclToDeclGroup(ConceptDecl);
+  }
 
   return ParseDeclarationAfterTemplate(
   Context, TemplateInfo, ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
@@ -316,7 +318,8 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo 
&TemplateInfo,
   const IdentifierInfo *Id = Result.Identifier;
   SourceLocation IdLoc = Result.getBeginLoc();
 
-  DiagnoseAndSkipCXX11Attributes();
+  ParsedAttributes Attrs(AttrFactory);
+  MaybeParseCXX11Attributes(Attrs);
 
   if (!TryConsumeToken(tok::equal)) {
 Diag(Tok.getLocation(), diag::err_expected) << tok::equal;
@@ -335,8 +338,8 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo 
&TemplateInfo,
   ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
   Expr *ConstraintExpr = ConstraintExprResult.get();
   return Actions.ActOnConceptDefinition(getCurScope(),
-*TemplateInfo.TemplateParams,
-Id, IdLoc, ConstraintExpr);
+*TemplateInfo.TemplateParams, Id, 
IdLoc,
+ConstraintExpr, Attrs);
 }
 
 /// ParseTemplateParameters - Parses a template-parameter-list enclosed in
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c7aac068e264b..2da933896b4da 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -5583,6 +5583,8 @@ Sema::CheckConceptTemplateId(const CXXScopeSpec &SS,
   /*UpdateArgsWithConversions=*/false))
 return ExprError();
 
+  DiagnoseUseOfDecl(NamedConcept, ConceptNameInfo.getLoc());
+
   auto *CSD = ImplicitConceptSpecializationDecl::Create(
   Context, NamedConcept->getDeclContext(), NamedConcept->getLocation(),
   CanonicalConverted);
@@ -9787,7 +9789,8 @@ Decl *Sema::ActOnTemplateDeclarator(Scope *S,
 
 Decl *Sema::ActOnConceptDefinition(
 Scope *S, MultiTemplateParamsArg TemplateParameterLists,
-const IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr) {
+const IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr,
+const ParsedAttributesView &Attrs) {
   DeclContext *DC = CurContext;
 
   if (!DC->getRedeclContext()->isFileContext()) {
@@ -9849,6 +9852,9 @@ Decl *Sema::ActOnConceptDefinition(
   ActOnDocumentableDecl(NewDecl);
   if (AddToScope)
 PushOnScopeChains(NewDecl, S);
+
+  ProcessDeclAttributeList(S, NewDecl, Attrs);
+
   return NewDecl;
 }
 
diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index 9f876cd870834..805a95c30470e 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -45,6 +45,34 @@ void fallthrough(int n) {
 #endif
 }
 
+namespace cwg2428 { // cwg2428: 19
+#if __cplusplus >= 202002L
+template 
+concept C [[deprecated]] = true; // #C
+
+template 
+concept C3 =

[clang] a960573 - [clang] CTAD: implement the missing IsDeducible constraint for alias templates (#89358)

2024-05-16 Thread via cfe-commits

Author: Haojian Wu
Date: 2024-05-16T13:01:18+02:00
New Revision: a9605730a481707623358d3b12220f05cfdc50a8

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

LOG: [clang] CTAD: implement the missing IsDeducible constraint for alias 
templates  (#89358)

Fixes https://github.com/llvm/llvm-project/issues/85192
Fixes https://github.com/llvm/llvm-project/issues/84492

This patch implements the "IsDeducible" constraint where the template
arguments of the alias template can be deduced from the returned type of
the synthesized deduction guide, per C++ [over.match.class.deduct]p4. In
the implementation, we perform the deduction directly, which is more
efficient than the way specified in the standard.

Also update relevant CTAD tests which were incorrectly compiled due to
the missing constraint.

Added: 


Modified: 
clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Sema/Sema.h
clang/lib/Basic/TypeTraits.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/AST/ast-dump-ctad-alias.cpp
clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
clang/test/SemaTemplate/deduction-guide.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 56c4b17f769d7..b5a0e9df9f7ae 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -538,6 +538,9 @@ TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_converts_from_temporary, 
ReferenceConvertsFromTemporary, KEYCXX)
+// IsDeducible is only used internally by clang for CTAD implementation and
+// is not exposed to users.
+TYPE_TRAIT_2(/*EmptySpellingName*/, IsDeducible, KEYCXX)
 
 // Embarcadero Expression Traits
 EXPRESSION_TRAIT(__is_lvalue_expr, IsLValueExpr, KEYCXX)

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..66d5e2d4a4ade 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9492,6 +9492,15 @@ class Sema final : public SemaBase {
   ArrayRef TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  /// Deduce the template arguments of the given template from \p FromType.
+  /// Used to implement the IsDeducible constraint for alias CTAD per C++
+  /// [over.match.class.deduct]p4.
+  ///
+  /// It only supports class or type alias templates.
+  TemplateDeductionResult
+  DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType,
+  sema::TemplateDeductionInfo &Info);
+
   TemplateDeductionResult DeduceTemplateArguments(
   TemplateParameterList *TemplateParams, ArrayRef Ps,
   ArrayRef As, sema::TemplateDeductionInfo &Info,

diff  --git a/clang/lib/Basic/TypeTraits.cpp b/clang/lib/Basic/TypeTraits.cpp
index 4dbf678dc395b..8d6794223ccaf 100644
--- a/clang/lib/Basic/TypeTraits.cpp
+++ b/clang/lib/Basic/TypeTraits.cpp
@@ -13,6 +13,7 @@
 #include "clang/Basic/TypeTraits.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
+#include 
 using namespace clang;
 
 static constexpr const char *TypeTraitNames[] = {
@@ -81,6 +82,15 @@ const char *clang::getTraitName(UnaryExprOrTypeTrait T) {
 
 const char *clang::getTraitSpelling(TypeTrait T) {
   assert(T <= TT_Last && "invalid enum value!");
+  if (T == BTT_IsDeducible) {
+// The __is_deducible is an internal-only type trait. To hide it from
+// external users, we define it with an empty spelling name, preventing the
+// clang parser from recognizing its token kind.
+// However, other components such as the AST dump still require the real
+// type trait name. Therefore, we return the real name when needed.
+assert(std::strlen(TypeTraitSpellings[T]) == 0);
+return "__is_deducible";
+  }
   return TypeTraitSpellings[T];
 }
 

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 34e12078a8c92..e4601f7d6c47d 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6143,7 +6143,15 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
 
 return Self.IsPointerInterconvertibleBaseOf(Lhs, Rhs);
   }
-default: llvm_unreachable("not a BTT");
+  case BTT_IsDeducible: {
+const auto *TSTToBeDeduced = cast(LhsT);
+sema::TemplateDeductionInfo Info(KeyLoc);
+return Self.DeduceTemplateArgumentsFromType(
+   TSTToBeDeduced->getTemplateName().getAsTemplate

[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

2024-05-16 Thread Haojian Wu via cfe-commits

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


[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-05-16 Thread Alex Voicu via cfe-commits


@@ -23,8 +26,8 @@ struct B : A {
 void g(A *a) { a->foo(); }
 
 // CHECK1-LABEL: define{{.*}} void @_ZN5test14fooAEv()
-// CHECK1: call void @_ZN5test11AC1Ev(ptr
-// CHECK1: %[[VTABLE:.*]] = load ptr addrspace(1), ptr %{{.*}}
+// CHECK1: call{{.*}} void @_ZN5test11AC1Ev(ptr {{((addrspace(4)){0,1})}}

AlexVlx wrote:

Right, so what I'll do is: merge this as is, and then revisit the test and 
rework it along the lines you and @jrtc27 are suggesting, since it looks as if 
I'll need to mess with it again for another piece of work.

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


[clang] [clang] Implement a bitwise_copyable builtin type trait. (PR #86512)

2024-05-16 Thread Ilya Biryukov via cfe-commits


@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Scalar types are bitwise clonable.
+static_assert(__is_bitwise_cloneable(int));
+static_assert(__is_bitwise_cloneable(int*));
+// array
+static_assert(__is_bitwise_cloneable(int[10]));
+
+// non-scalar types.
+static_assert(!__is_bitwise_cloneable(int&));
+
+
+struct Forward; // expected-note 2{{forward declaration of 'Forward'}}
+static_assert(!__is_bitwise_cloneable(Forward)); // expected-error 
{{incomplete type 'Forward' used in type trait expression}}
+
+struct Foo { int a; };
+static_assert(__is_bitwise_cloneable(Foo));
+
+struct DynamicClass { virtual int Foo(); };
+static_assert(__is_bitwise_cloneable(DynamicClass));
+
+struct Bar { int& b; }; // trivially copyable
+static_assert(__is_trivially_copyable(Bar));
+static_assert(__is_bitwise_cloneable(Bar));

ilya-biryukov wrote:

I think it makes a lot of sense to make this a strict superset of trivially 
copyable types.
But why isn't next example bitwise-cloneable then?

```cpp
struct Bar2 { Bar2(const Bar2&); int& b; };
static_assert(!__is_trivially_copyable(Bar2));
static_assert(!__is_bitwise_cloneable(Bar2)); 
```
`Bar2` is not trivially copyable because of the presence of a user-defined 
constructor, we chose to drop that requirement for the new trait. Why isn't the 
type bitwise-cloneable?

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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-16 Thread Vikram Hegde via cfe-commits


@@ -243,11 +243,16 @@ def VOP_READFIRSTLANE : VOPProfile <[i32, i32, untyped, 
untyped]> {
 // FIXME: Specify SchedRW for READFIRSTLANE_B32
 // TODO: There is VOP3 encoding also
 def V_READFIRSTLANE_B32 : VOP1_Pseudo <"v_readfirstlane_b32", 
VOP_READFIRSTLANE,
-   getVOP1Pat.ret, 1> {
+   [], 1> {
   let isConvergent = 1;
 }
 
+foreach vt = Reg32Types.types in {
+  def : GCNPat<(vt (AMDGPUreadfirstlane (vt VRegOrLdsSrc_32:$src0))),
+(V_READFIRSTLANE_B32 (vt VRegOrLdsSrc_32:$src0))

vikramRH wrote:

Unfortunately no, Had tried this and couple of other variations. the issue 
seems to be too specific to GIsel pointers..

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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-16 Thread Matt Arsenault via cfe-commits


@@ -243,11 +243,16 @@ def VOP_READFIRSTLANE : VOPProfile <[i32, i32, untyped, 
untyped]> {
 // FIXME: Specify SchedRW for READFIRSTLANE_B32
 // TODO: There is VOP3 encoding also
 def V_READFIRSTLANE_B32 : VOP1_Pseudo <"v_readfirstlane_b32", 
VOP_READFIRSTLANE,
-   getVOP1Pat.ret, 1> {
+   [], 1> {
   let isConvergent = 1;
 }
 
+foreach vt = Reg32Types.types in {
+  def : GCNPat<(vt (AMDGPUreadfirstlane (vt VRegOrLdsSrc_32:$src0))),
+(V_READFIRSTLANE_B32 (vt VRegOrLdsSrc_32:$src0))

arsenm wrote:

What is the problem? 

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


[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder' (PR #91445)

2024-05-16 Thread Balazs Benics via cfe-commits
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 


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

LGTM now, modulo the license concern mentioned 
[here](https://github.com/llvm/llvm-project/pull/91445#discussion_r1599766388).
I approve this, given that is checked/resolved.

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


[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder' (PR #91445)

2024-05-16 Thread Balazs Benics via cfe-commits
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 


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


[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder' (PR #91445)

2024-05-16 Thread Balazs Benics via cfe-commits
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,75 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,security.SetgidSetuidOrder 
-analyzer-output=text -verify %s
+
+typedef int uid_t;
+typedef int gid_t;
+
+int setuid(uid_t);
+int setgid(gid_t);
+
+uid_t getuid();
+gid_t getgid();
+
+
+
+void test_note_1() {
+  if (setuid(getuid()) == -1) // expected-note{{Assuming the condition is 
false}} \
+  // expected-note{{Taking false branch}}
+return;
+  if (setuid(getuid()) == -1) // expected-note{{Call to 'setuid' found here 
that removes superuser privileges}} \
+  // expected-note{{Assuming the condition is 
false}} \
+  // expected-note{{Taking false branch}}
+return;
+  if (setgid(getgid()) == -1) // expected-warning{{A 'setgid(getgid())' call 
following a 'setuid(getuid())' call is likely to fail}} \
+  // expected-note{{A 'setgid(getgid())' call 
following a 'setuid(getuid())' call is likely to fail}}
+return;
+}
+
+void test_note_2() {
+  if (setuid(getuid()) == -1) // expected-note{{Call to 'setuid' found here 
that removes superuser privileges}} \
+  // expected-note{{Assuming the condition is 
false}} \
+  // expected-note{{Taking false branch}} \
+  // expected-note{{Assuming the condition is 
false}} \
+  // expected-note{{Taking false branch}}

steakhal wrote:

```suggestion
  // expected-note 2 {{Assuming the condition is 
false}} \
  // expected-note 2 {{Taking false branch}}
```

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


[clang] [clang] Add __builtin_start_object_lifetime builtin. (PR #82776)

2024-05-16 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

I second @cor3ntin's concern here. We are adding a builtin that is named very 
similarly to the one from C++23 standard, but not actually having the semantics 
that is desired.

I believe we do need the effect that __builtin_launder provides to allow memcpy 
for types that have vtables, which was original motivation for this change and 
#86512. However, we could get those guarantees by using __builtin_launder 
directly.
Looking at the code, the __builtin_launder currently has a sole effect of 
preventing optimizations that would load an incorrect vtable when 
-fstrict-vtable-pointers is passed and same storage is reused for different 
types.

I feel it's better to just go with std::launder on our end at this point and 
instead focus on preventing misoptimizations from TBAA to get a proper 
implementation of start_lifetime_as. It carries a risk of hitting a 
misoptimization in the future on our end, but seems very unlikely unless we 
start using TBAA or LLVM starts optimizing much more aggressively based on C++ 
notion of object lifetimes, neither of which should go unnoticed.

@hokein WDYT?

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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-16 Thread Vikram Hegde via cfe-commits


@@ -243,11 +243,16 @@ def VOP_READFIRSTLANE : VOPProfile <[i32, i32, untyped, 
untyped]> {
 // FIXME: Specify SchedRW for READFIRSTLANE_B32
 // TODO: There is VOP3 encoding also
 def V_READFIRSTLANE_B32 : VOP1_Pseudo <"v_readfirstlane_b32", 
VOP_READFIRSTLANE,
-   getVOP1Pat.ret, 1> {
+   [], 1> {
   let isConvergent = 1;
 }
 
+foreach vt = Reg32Types.types in {
+  def : GCNPat<(vt (AMDGPUreadfirstlane (vt VRegOrLdsSrc_32:$src0))),
+(V_READFIRSTLANE_B32 (vt VRegOrLdsSrc_32:$src0))

vikramRH wrote:

Attaching example match table snippets for v2i16 and p3 here, should make the 
scenario bit more clear,
for v2i16
 ```
GIM_Try, /*On fail goto*//*Label 3499*/ GIMT_Encode4(202699), // Rule ID 2117 //
GIM_CheckIntrinsicID, /*MI*/0, /*Op*/1, 
GIMT_Encode2(Intrinsic::amdgcn_writelane),
GIM_RootCheckType, /*Op*/0, /*Type*/GILLT_v2s16,
GIM_RootCheckType, /*Op*/2, /*Type*/GILLT_v2s16,
GIM_RootCheckType, /*Op*/3, /*Type*/GILLT_s32,
GIM_RootCheckType, /*Op*/4, /*Type*/GILLT_v2s16,
GIM_RootCheckRegBankForClass, /*Op*/0, 
/*RC*/GIMT_Encode2(AMDGPU::VGPR_32RegClassID),
// (intrinsic_wo_chain:{ *:[v2i16] } 2863:{ *:[iPTR] }, v2i16:{ 
*:[v2i16] }:$src0, i32:{ *:[i32] }:$src1, v2i16:{ *:[v2i16] }:$src2)  =>  
(V_WRITELANE_B32:{ *:[v2i16] } SCSrc_b32:{ *:[v2i16] }:$src0, SCSrc_b32:{ 
*:[i32] }:$src1, VGPR_32:{ *:[v2i16] }:$src2)
GIR_BuildRootMI, /*Opcode*/GIMT_Encode2(AMDGPU::V_WRITELANE_B32),
```

and for p3,
```
GIM_Try, /*On fail goto*//*Label 3502*/ GIMT_Encode4(202816), // Rule ID 2129 //
GIM_CheckIntrinsicID, /*MI*/0, /*Op*/1, 
GIMT_Encode2(Intrinsic::amdgcn_writelane),
GIM_RootCheckType, /*Op*/0, /*Type*/GILLT_s32,
GIM_RootCheckType, /*Op*/2, /*Type*/GILLT_p2s32,
GIM_RootCheckType, /*Op*/3, /*Type*/GILLT_s32,
GIM_RootCheckType, /*Op*/4, /*Type*/GILLT_p2s32,
GIM_RootCheckRegBankForClass, /*Op*/0, 
/*RC*/GIMT_Encode2(AMDGPU::VGPR_32RegClassID),
// (intrinsic_wo_chain:{ *:[i32] } 2863:{ *:[iPTR] }, p2:{ *:[i32] 
}:$src0, i32:{ *:[i32] }:$src1, p2:{ *:[i32] }:$src2)  =>  (V_WRITELANE_B32:{ 
*:[i32] } SCSrc_b32:{ *:[i32] }:$src0, SCSrc_b32:{ *:[i32] }:$src1, VGPR_32:{ 
*:[i32] }:$src2)
GIR_BuildRootMI, /*Opcode*/GIMT_Encode2(AMDGPU::V_WRITELANE_B32),
```

The destination type check for p3 case is still for "GILLT_s32",



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


[clang] [llvm] wip: Move instrumentation passes (PR #92171)

2024-05-16 Thread Egor Pasko via cfe-commits


@@ -101,6 +101,7 @@ void initializeEarlyMachineLICMPass(PassRegistry&);
 void initializeEarlyTailDuplicatePass(PassRegistry&);
 void initializeEdgeBundlesPass(PassRegistry&);
 void initializeEHContGuardCatchretPass(PassRegistry &);
+void initializeEntryExitInstrumenterPass(PassRegistry&);

pasko wrote:

Removed.

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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-16 Thread Vikram Hegde via cfe-commits

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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-16 Thread Vikram Hegde via cfe-commits

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


[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)

2024-05-16 Thread Aaron Ballman via cfe-commits


@@ -14574,9 +14574,17 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
   default:
 return false;
 
+  case Builtin::BI__builtin_frexpl:
+// AIX library function `frexpl` has 'long double' type and not
+// PPCDoubleDouble type. To make sure we generate the right value, don't
+// constant evaluate it and instead defer to a libcall.
+if (Info.Ctx.getTargetInfo().getTriple().isPPC() &&
+(&Info.Ctx.getTargetInfo().getLongDoubleFormat() !=
+ &llvm::APFloat::PPCDoubleDouble()))
+  return false;
+LLVM_FALLTHROUGH;
   case Builtin::BI__builtin_frexp:
-  case Builtin::BI__builtin_frexpf:
-  case Builtin::BI__builtin_frexpl: {
+  case Builtin::BI__builtin_frexpf: {

AaronBallman wrote:

> For compile-time evaluation, the APFloats associated with long double on AIX 
> have the IEEE double format (and the evaluation works fine).

Does the evaluation produce the same results as would happen at runtime despite 
the different format?

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


[clang] [Clang][Sema] Don't build CXXDependentScopeMemberExprs for potentially implicit class member access expressions (PR #92318)

2024-05-16 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/92318

>From 6c8646dbb04cc5898fe7f67c9923036b2f68b56d Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 15 May 2024 16:13:03 -0400
Subject: [PATCH 1/3] [Clang][Sema] Don't build CXXDependentScopeMemberExprs
 for potentially implicit class member access expressions

---
 clang/include/clang/Sema/Sema.h   | 11 +--
 clang/lib/Sema/SemaCXXScopeSpec.cpp   |  8 ++
 clang/lib/Sema/SemaExpr.cpp   | 31 ++
 clang/lib/Sema/SemaTemplate.cpp   | 98 ++-
 clang/lib/Sema/TreeTransform.h|  6 +-
 .../class.mfct/class.mfct.non-static/p3.cpp   | 91 -
 ...ms-function-specialization-class-scope.cpp | 52 ++
 .../ms-lookup-template-base-classes.cpp   | 12 +--
 .../ASTMatchers/ASTMatchersNodeTest.cpp   |  6 +-
 9 files changed, 206 insertions(+), 109 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..779e3134b3067 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5366,11 +5366,9 @@ class Sema final : public SemaBase {
   bool UseArgumentDependentLookup(const CXXScopeSpec &SS, const LookupResult 
&R,
   bool HasTrailingLParen);
 
-  ExprResult
-  BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
-const DeclarationNameInfo &NameInfo,
-bool IsAddressOfOperand, const Scope *S,
-TypeSourceInfo **RecoveryTSI = nullptr);
+  ExprResult BuildQualifiedDeclarationNameExpr(
+  CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo,
+  bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI = nullptr);
 
   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R,
   bool NeedsADL,
@@ -8982,7 +8980,8 @@ class Sema final : public SemaBase {
   ExprResult
   BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
const DeclarationNameInfo &NameInfo,
-   const TemplateArgumentListInfo *TemplateArgs);
+   const TemplateArgumentListInfo *TemplateArgs,
+   bool IsAddressOfOperand);
 
   TemplateNameKind ActOnTemplateName(Scope *S, CXXScopeSpec &SS,
  SourceLocation TemplateKWLoc,
diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index fca5bd131bbc0..c405fbc0aa421 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -796,6 +796,14 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, 
NestedNameSpecInfo &IdInfo,
 Diag(IdInfo.IdentifierLoc,
  diag::ext_undeclared_unqual_id_with_dependent_base)
 << IdInfo.Identifier << ContainingClass;
+// Fake up a nested-name-specifier that starts with the
+// injected-class-name of the enclosing class.
+QualType T = Context.getTypeDeclType(ContainingClass);
+TypeLocBuilder TLB;
+TLB.pushTrivial(Context, T, IdInfo.IdentifierLoc);
+SS.Extend(Context, /*TemplateKWLoc=*/SourceLocation(),
+  TLB.getTypeLocInContext(Context, T), IdInfo.IdentifierLoc);
+// Add the identifier to form a dependent name.
 SS.Extend(Context, IdInfo.Identifier, IdInfo.IdentifierLoc,
   IdInfo.CCLoc);
 return false;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ec84798e4ce60..ad6cfb632fd94 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2946,26 +2946,14 @@ Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS,
 /// this path.
 ExprResult Sema::BuildQualifiedDeclarationNameExpr(
 CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo,
-bool IsAddressOfOperand, const Scope *S, TypeSourceInfo **RecoveryTSI) {
-  if (NameInfo.getName().isDependentName())
-return BuildDependentDeclRefExpr(SS, /*TemplateKWLoc=*/SourceLocation(),
- NameInfo, /*TemplateArgs=*/nullptr);
-
-  DeclContext *DC = computeDeclContext(SS, false);
-  if (!DC)
-return BuildDependentDeclRefExpr(SS, /*TemplateKWLoc=*/SourceLocation(),
- NameInfo, /*TemplateArgs=*/nullptr);
-
-  if (RequireCompleteDeclContext(SS, DC))
-return ExprError();
-
+bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI) {
   LookupResult R(*this, NameInfo, LookupOrdinaryName);
-  LookupQualifiedName(R, DC);
+  LookupParsedName(R, /*S=*/nullptr, &SS, /*ObjectType=*/QualType());
 
   if (R.isAmbiguous())
 return ExprError();
 
-  if (R.getResultKind() == LookupResult::NotFoundInCurrentInstantiation)
+  if (R.wasNotFoundInCurrentInstantiation() || SS.isInvalid())
 return

[clang] [llvm] [DebugInfo] Use DW_op_bit_piece for structured bindings of bitfields (PR #85665)

2024-05-16 Thread John Brawn via cfe-commits


@@ -6178,10 +6178,16 @@ The current supported opcode vocabulary is limited:
   the last entry from the second last entry and appends the result to the
   expression stack.
 - ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression.
-- ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and 
``8``
-  here, respectively) of the variable fragment from the working expression. 
Note
-  that contrary to DW_OP_bit_piece, the offset is describing the location
-  within the described source variable.
+- ``DW_OP_LLVM_fragment, 16, 8`` specifies that the top of the expression stack
+  is a fragment of the source language variable with the given offset and size
+  (``16`` and ``8`` here, respectively). Note that the offset and size are the
+  opposite way around to ``DW_OP_bit_piece``, and the offset is within the
+  source language variable.
+- ``DW_OP_bit_piece, 8, 16`` specifies that the source language variable can be
+  found in the sequence of bits at the given size and offset (``8`` and ``16``
+  here, respectively) within the top of the expression stack. Note that the
+  offset and size are the opposite way around to ``DW_OP_LLVM_fragment``, and 
the
+  offset is within the LLVM variable (if that's at the top of the stack).

john-brawn-arm wrote:

Ah, I see, I hadn't noticed that (I'd just read the description of 
DW_OP_bit_piece and hadn't read the general description of composite location 
descriptions). I had been understanding something like "DW_OP_reg0 RAX, 
DW_OP_bit_piece 0x3 0x0" to mean "this variable can be found in the 3 bits at 
offset 0 in RAX", but it actually means something closer to "the bottom 3 bits 
of this variable can be found in the 3 bits at offset 0 in RAX".

I think this doesn't make much difference though if we restrict DW_OP_bit_piece 
in the llvm.dbg intrinsics to use it only  for its ability to describe a value 
stored in part of a register, with the other bits not being described, as I 
think that's what the behaviour I've currently implemented is. Though maybe it 
would be better to instead use DW_OP_and and DW_OP_shr to extract the bits from 
the register. I'll think about this some more.

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


[clang] [clang] Use constant rounding mode for floating literals (PR #90877)

2024-05-16 Thread Aaron Ballman via cfe-commits

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

The changes should come with a release note so that users know about the 
behavioral change, but otherwise LGTM.

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


[clang] [Clang][Sema] Avoid pack expansion for expanded empty PackIndexingExprs (PR #92385)

2024-05-16 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/92385

We previously doubled the id-expression expansion, even when the pack was 
expanded to empty. The previous condition for determining whether we should 
expand couldn't distinguish between cases where 'the expansion was previously 
postponed' and 'the expansion occurred but resulted in emptiness.'

In the latter scenario, we crash because we have not been examining the current 
lambda's parent local instantiation scope since 
[D98068](https://reviews.llvm.org/D98068): Any Decls instantiated in the parent 
scope are not visible to the generic lambda, and thus any attempt of looking 
for instantiated Decls in the lambda is capped to the current Lambda's LIS.

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

>From 7acbb1dd89dbe266c3e53ab30178ac570722c759 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Thu, 16 May 2024 19:06:25 +0800
Subject: [PATCH] [Clang][Sema] Avoid pack expansion for expanded empty
 PackIndexingExprs

We previously doubled the id-expression expansion, even when the pack
was expanded to empty. The previous condition for determining whether
we should expand couldn't distinguish between cases where 'the expansion
was previously postponed' and 'the expansion occurred but resulted in
emptiness.'

In the latter scenario, we crash because we have not been examining the
current lambda's parent local instantiation scope since D98068: Any
Decls instantiated in the parent scope are not visible to the generic
lambda. And thus any attempt of looking for instantiated Decls in the lambda
is capped to the current Lambda's LIS.

Fixes https://github.com/llvm/llvm-project/issues/92230
---
 clang/include/clang/AST/ExprCXX.h  | 14 ++
 clang/lib/AST/ExprCXX.cpp  | 16 
 clang/lib/Sema/SemaTemplateVariadic.cpp|  2 +-
 clang/lib/Sema/TreeTransform.h |  6 ++
 clang/test/SemaCXX/cxx2c-pack-indexing.cpp |  8 ++--
 5 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index fac65628ffede..2617cd36d0df9 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -4381,11 +4381,13 @@ class PackIndexingExpr final
 
   PackIndexingExpr(QualType Type, SourceLocation EllipsisLoc,
SourceLocation RSquareLoc, Expr *PackIdExpr, Expr 
*IndexExpr,
-   ArrayRef SubstitutedExprs = {})
+   ArrayRef SubstitutedExprs = {},
+   bool EmptyPack = false)
   : Expr(PackIndexingExprClass, Type, VK_LValue, OK_Ordinary),
 EllipsisLoc(EllipsisLoc), RSquareLoc(RSquareLoc),
 SubExprs{PackIdExpr, IndexExpr},
-TransformedExpressions(SubstitutedExprs.size()) {
+TransformedExpressions(EmptyPack ? size_t(-1)
+ : SubstitutedExprs.size()) {
 
 auto *Exprs = getTrailingObjects();
 std::uninitialized_copy(SubstitutedExprs.begin(), SubstitutedExprs.end(),
@@ -4408,10 +4410,13 @@ class PackIndexingExpr final
   SourceLocation EllipsisLoc,
   SourceLocation RSquareLoc, Expr *PackIdExpr,
   Expr *IndexExpr, std::optional 
Index,
-  ArrayRef SubstitutedExprs = {});
+  ArrayRef SubstitutedExprs = {},
+  bool EmptyPack = false);
   static PackIndexingExpr *CreateDeserialized(ASTContext &Context,
   unsigned NumTransformedExprs);
 
+  bool isEmptyPack() const { return TransformedExpressions == size_t(-1); }
+
   /// Determine the location of the 'sizeof' keyword.
   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
 
@@ -4446,7 +4451,8 @@ class PackIndexingExpr final
   }
 
   ArrayRef getExpressions() const {
-return {getTrailingObjects(), TransformedExpressions};
+return {getTrailingObjects(),
+isEmptyPack() ? 0 : TransformedExpressions};
   }
 
   static bool classof(const Stmt *T) {
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 7e9343271ac3c..01cdd2709b472 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -1665,12 +1665,11 @@ NonTypeTemplateParmDecl 
*SubstNonTypeTemplateParmExpr::getParameter() const {
   getReplacedTemplateParameterList(getAssociatedDecl())->asArray()[Index]);
 }
 
-PackIndexingExpr *PackIndexingExpr::Create(ASTContext &Context,
-   SourceLocation EllipsisLoc,
-   SourceLocation RSquareLoc,
-   Expr *PackIdExpr, Expr *IndexExpr,
-   std::optional Index,
-   ArrayRef SubstitutedExprs) {
+PackIndexi

[clang] [Clang][Sema] Avoid pack expansion for expanded empty PackIndexingExprs (PR #92385)

2024-05-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

We previously doubled the id-expression expansion, even when the pack was 
expanded to empty. The previous condition for determining whether we should 
expand couldn't distinguish between cases where 'the expansion was previously 
postponed' and 'the expansion occurred but resulted in emptiness.'

In the latter scenario, we crash because we have not been examining the current 
lambda's parent local instantiation scope since 
[D98068](https://reviews.llvm.org/D98068): Any Decls instantiated in the parent 
scope are not visible to the generic lambda, and thus any attempt of looking 
for instantiated Decls in the lambda is capped to the current Lambda's LIS.

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

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


5 Files Affected:

- (modified) clang/include/clang/AST/ExprCXX.h (+10-4) 
- (modified) clang/lib/AST/ExprCXX.cpp (+8-8) 
- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+1-1) 
- (modified) clang/lib/Sema/TreeTransform.h (+2-4) 
- (modified) clang/test/SemaCXX/cxx2c-pack-indexing.cpp (+6-2) 


``diff
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index fac65628ffede..2617cd36d0df9 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -4381,11 +4381,13 @@ class PackIndexingExpr final
 
   PackIndexingExpr(QualType Type, SourceLocation EllipsisLoc,
SourceLocation RSquareLoc, Expr *PackIdExpr, Expr 
*IndexExpr,
-   ArrayRef SubstitutedExprs = {})
+   ArrayRef SubstitutedExprs = {},
+   bool EmptyPack = false)
   : Expr(PackIndexingExprClass, Type, VK_LValue, OK_Ordinary),
 EllipsisLoc(EllipsisLoc), RSquareLoc(RSquareLoc),
 SubExprs{PackIdExpr, IndexExpr},
-TransformedExpressions(SubstitutedExprs.size()) {
+TransformedExpressions(EmptyPack ? size_t(-1)
+ : SubstitutedExprs.size()) {
 
 auto *Exprs = getTrailingObjects();
 std::uninitialized_copy(SubstitutedExprs.begin(), SubstitutedExprs.end(),
@@ -4408,10 +4410,13 @@ class PackIndexingExpr final
   SourceLocation EllipsisLoc,
   SourceLocation RSquareLoc, Expr *PackIdExpr,
   Expr *IndexExpr, std::optional 
Index,
-  ArrayRef SubstitutedExprs = {});
+  ArrayRef SubstitutedExprs = {},
+  bool EmptyPack = false);
   static PackIndexingExpr *CreateDeserialized(ASTContext &Context,
   unsigned NumTransformedExprs);
 
+  bool isEmptyPack() const { return TransformedExpressions == size_t(-1); }
+
   /// Determine the location of the 'sizeof' keyword.
   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
 
@@ -4446,7 +4451,8 @@ class PackIndexingExpr final
   }
 
   ArrayRef getExpressions() const {
-return {getTrailingObjects(), TransformedExpressions};
+return {getTrailingObjects(),
+isEmptyPack() ? 0 : TransformedExpressions};
   }
 
   static bool classof(const Stmt *T) {
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 7e9343271ac3c..01cdd2709b472 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -1665,12 +1665,11 @@ NonTypeTemplateParmDecl 
*SubstNonTypeTemplateParmExpr::getParameter() const {
   getReplacedTemplateParameterList(getAssociatedDecl())->asArray()[Index]);
 }
 
-PackIndexingExpr *PackIndexingExpr::Create(ASTContext &Context,
-   SourceLocation EllipsisLoc,
-   SourceLocation RSquareLoc,
-   Expr *PackIdExpr, Expr *IndexExpr,
-   std::optional Index,
-   ArrayRef SubstitutedExprs) {
+PackIndexingExpr *
+PackIndexingExpr::Create(ASTContext &Context, SourceLocation EllipsisLoc,
+ SourceLocation RSquareLoc, Expr *PackIdExpr,
+ Expr *IndexExpr, std::optional Index,
+ ArrayRef SubstitutedExprs, bool EmptyPack) {
   QualType Type;
   if (Index && !SubstitutedExprs.empty())
 Type = SubstitutedExprs[*Index]->getType();
@@ -1679,8 +1678,9 @@ PackIndexingExpr *PackIndexingExpr::Create(ASTContext 
&Context,
 
   void *Storage =
   Context.Allocate(totalSizeToAlloc(SubstitutedExprs.size()));
-  return new (Storage) PackIndexingExpr(
-  Type, EllipsisLoc, RSquareLoc, PackIdExpr, IndexExpr, SubstitutedExprs);
+  return new (Storage)
+  PackIndexingExpr(Type, EllipsisLoc, RSquareLoc, PackIdExpr, IndexExpr,
+   SubstitutedExprs, EmptyPack);
 }
 
 Nam

[clang] [Clang][AArch64] Require SVE or SSVE for scalable types. (PR #91356)

2024-05-16 Thread Paul Walker via cfe-commits

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


[clang] [Clang][AArch64] Require SVE or SSVE for scalable types. (PR #91356)

2024-05-16 Thread Paul Walker via cfe-commits


@@ -9,6 +9,12 @@
 
 #include 
 
+#if defined __ARM_FEATURE_SME
+#define MODE_ATTR __arm_streaming
+#else
+#define MODE_ATTR __arm_streaming_compatible

paulwalker-arm wrote:

Do you need to use `__arm_streaming_compatible` here?  Now we've agreed this 
keyword has no effect on the target features in use I think `MODE_ATTR` should 
remain blank to mirror the expected usage when SME is not in use.

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


[clang] [Clang][AArch64] Require SVE or SSVE for scalable types. (PR #91356)

2024-05-16 Thread Paul Walker via cfe-commits


@@ -8982,11 +8982,18 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) 
{
 const FunctionDecl *FD = cast(CurContext);
 llvm::StringMap CallerFeatureMap;
 Context.getFunctionFeatureMap(CallerFeatureMap, FD);
-if (!Builtin::evaluateRequiredTargetFeatures(
-"sve", CallerFeatureMap)) {
-  Diag(NewVD->getLocation(), diag::err_sve_vector_in_non_sve_target) << T;
-  NewVD->setInvalidDecl();
-  return;

paulwalker-arm wrote:

Is dropping the immediate return upon setting up a diagnostic intentional?

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


[clang] [Clang][AArch64] Require SVE or SSVE for scalable types. (PR #91356)

2024-05-16 Thread Paul Walker via cfe-commits

https://github.com/paulwalker-arm commented:

After further discussion I know understand the `__arm_streaming_compatible` 
keyword has no affect on the target features in play and only tells the 
compiler not to emit any SM state changing instructions as part of the calling 
convention.

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


[clang] [Clang][AArch64] Require SVE or SSVE for scalable types. (PR #91356)

2024-05-16 Thread Paul Walker via cfe-commits

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


[clang] [clang] Implement CWG2428 "Deprecating a concept" (PR #92295)

2024-05-16 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/92295

>From a0d5a234431f3db2f0283ffa0909bf8c254aa611 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 15 May 2024 20:20:43 +0300
Subject: [PATCH 1/5] [clang] Implement CWG2428 "Deprecating a concept"

---
 clang/include/clang/Sema/Sema.h   |  3 ++-
 clang/lib/Parse/ParseTemplate.cpp | 15 +--
 clang/lib/Sema/SemaTemplate.cpp   |  8 +++-
 clang/test/CXX/drs/cwg24xx.cpp| 28 
 clang/www/cxx_dr_status.html  | 22 +-
 5 files changed, 63 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..330076ca77371 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9356,7 +9356,8 @@ class Sema final : public SemaBase {
   Decl *ActOnConceptDefinition(Scope *S,
MultiTemplateParamsArg TemplateParameterLists,
const IdentifierInfo *Name,
-   SourceLocation NameLoc, Expr *ConstraintExpr);
+   SourceLocation NameLoc, Expr *ConstraintExpr,
+   const ParsedAttributesView &Attrs);
 
   void CheckConceptRedefinition(ConceptDecl *NewDecl, LookupResult &Previous,
 bool &AddToScope);
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index 665253a6674d2..b8f2b3f9657e7 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -167,9 +167,11 @@ Parser::DeclGroupPtrTy 
Parser::ParseTemplateDeclarationOrSpecialization(
   LastParamListWasEmpty);
 
   // Parse the actual template declaration.
-  if (Tok.is(tok::kw_concept))
-return Actions.ConvertDeclToDeclGroup(
-ParseConceptDefinition(TemplateInfo, DeclEnd));
+  if (Tok.is(tok::kw_concept)) {
+Decl *ConceptDecl = ParseConceptDefinition(TemplateInfo, DeclEnd);
+ParsingTemplateParams.complete(ConceptDecl);
+return Actions.ConvertDeclToDeclGroup(ConceptDecl);
+  }
 
   return ParseDeclarationAfterTemplate(
   Context, TemplateInfo, ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
@@ -316,7 +318,8 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo 
&TemplateInfo,
   const IdentifierInfo *Id = Result.Identifier;
   SourceLocation IdLoc = Result.getBeginLoc();
 
-  DiagnoseAndSkipCXX11Attributes();
+  ParsedAttributes Attrs(AttrFactory);
+  MaybeParseCXX11Attributes(Attrs);
 
   if (!TryConsumeToken(tok::equal)) {
 Diag(Tok.getLocation(), diag::err_expected) << tok::equal;
@@ -335,8 +338,8 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo 
&TemplateInfo,
   ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
   Expr *ConstraintExpr = ConstraintExprResult.get();
   return Actions.ActOnConceptDefinition(getCurScope(),
-*TemplateInfo.TemplateParams,
-Id, IdLoc, ConstraintExpr);
+*TemplateInfo.TemplateParams, Id, 
IdLoc,
+ConstraintExpr, Attrs);
 }
 
 /// ParseTemplateParameters - Parses a template-parameter-list enclosed in
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c7aac068e264b..2da933896b4da 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -5583,6 +5583,8 @@ Sema::CheckConceptTemplateId(const CXXScopeSpec &SS,
   /*UpdateArgsWithConversions=*/false))
 return ExprError();
 
+  DiagnoseUseOfDecl(NamedConcept, ConceptNameInfo.getLoc());
+
   auto *CSD = ImplicitConceptSpecializationDecl::Create(
   Context, NamedConcept->getDeclContext(), NamedConcept->getLocation(),
   CanonicalConverted);
@@ -9787,7 +9789,8 @@ Decl *Sema::ActOnTemplateDeclarator(Scope *S,
 
 Decl *Sema::ActOnConceptDefinition(
 Scope *S, MultiTemplateParamsArg TemplateParameterLists,
-const IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr) {
+const IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr,
+const ParsedAttributesView &Attrs) {
   DeclContext *DC = CurContext;
 
   if (!DC->getRedeclContext()->isFileContext()) {
@@ -9849,6 +9852,9 @@ Decl *Sema::ActOnConceptDefinition(
   ActOnDocumentableDecl(NewDecl);
   if (AddToScope)
 PushOnScopeChains(NewDecl, S);
+
+  ProcessDeclAttributeList(S, NewDecl, Attrs);
+
   return NewDecl;
 }
 
diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index 9f876cd870834..805a95c30470e 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -45,6 +45,34 @@ void fallthrough(int n) {
 #endif
 }
 
+namespace cwg2428 { // cwg2428: 19
+#if __cplusplus >= 202002L
+template 
+concept C [[deprecated]] = true; // #C
+
+template 
+concept C3 =

[clang] [clang] Implement CWG2428 "Deprecating a concept" (PR #92295)

2024-05-16 Thread Vlad Serebrennikov via cfe-commits


@@ -45,6 +45,34 @@ void fallthrough(int n) {
 #endif
 }
 
+namespace cwg2428 { // cwg2428: 19
+#if __cplusplus >= 202002L
+template 
+concept C [[deprecated]] = true; // #C

Endilll wrote:

I added support for GNU and MSVC spellings.

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


[clang] [clang] Implement CWG2428 "Deprecating a concept" (PR #92295)

2024-05-16 Thread via cfe-commits


@@ -316,7 +318,8 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo 
&TemplateInfo,
   const IdentifierInfo *Id = Result.Identifier;
   SourceLocation IdLoc = Result.getBeginLoc();
 
-  DiagnoseAndSkipCXX11Attributes();
+  ParsedAttributes Attrs(AttrFactory);
+  MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, Attrs);

cor3ntin wrote:

Did you check MSVC for the `PAKM_Declspec` ?

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


[clang] [clang] Implement CWG2428 "Deprecating a concept" (PR #92295)

2024-05-16 Thread via cfe-commits


@@ -8092,6 +8092,18 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
 }
 
+void Sema::CheckConstrainedAuto(TypeSourceInfo *TS) {
+  if (getLangOpts().CPlusPlus20) {
+if (const AutoType *AutoT = TS->getType()->getAs()) {

cor3ntin wrote:

I think this check should be kept on the call site and the function can take an 
`AutoType` as parameter

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


[clang] [clang] Implement CWG2428 "Deprecating a concept" (PR #92295)

2024-05-16 Thread via cfe-commits


@@ -8092,6 +8092,18 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
 }
 
+void Sema::CheckConstrainedAuto(TypeSourceInfo *TS) {
+  if (getLangOpts().CPlusPlus20) {

cor3ntin wrote:

Does the check for `getLangOpts().CPlusPlus20` does anything here?

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


[clang] [clang-tools-extra] [llvm] [mlir] [polly] [test]: fix filecheck annotation typos (PR #91854)

2024-05-16 Thread via cfe-commits

klensy wrote:

Moved flang fixed to https://github.com/llvm/llvm-project/pull/92387

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


  1   2   3   4   5   >