[clang-tools-extra] FIX : bugprone-too-small-loop-variable - false-negative when const variable is used as loop bound (PR #81183)

2024-02-08 Thread Piotr Zegar via cfe-commits


@@ -156,6 +156,10 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`bugprone-too-small-loop-variable

PiotrZSL wrote:

put this in alphabetical order by a check name.

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


[clang-tools-extra] FIX : bugprone-too-small-loop-variable - false-negative when const variable is used as loop bound (PR #81183)

2024-02-08 Thread Piotr Zegar via cfe-commits


@@ -82,10 +82,14 @@ void 
TooSmallLoopVariableCheck::registerMatchers(MatchFinder *Finder) {
   // We are interested in only those cases when the loop bound is a variable
   // value (not const, enum, etc.).
   StatementMatcher LoopBoundMatcher =
-  expr(ignoringParenImpCasts(allOf(hasType(isInteger()),
-   unless(integerLiteral()),
-   unless(hasType(isConstQualified())),
-   unless(hasType(enumType())
+  expr(ignoringParenImpCasts(allOf(
+   hasType(isInteger()), unless(integerLiteral()),
+   unless(allOf(
+   hasType(isConstQualified()),
+   declRefExpr(to(varDecl(anyOf(
+   hasInitializer(ignoringParenImpCasts(integerLiteral())),
+   isConstexpr(), isConstinit())),
+   unless(hasType(enumType())

PiotrZSL wrote:

i were thinking, instead of:
```
unless(hasType(enumType()))
```
simply write:
```
unless(declRefExpr(to(enumConstantDecl(,
unless(allOf(hasType(isConstQualified()),

declRefExpr(to(varDecl(anyOf(hasInitializer(ignoringParenImpCasts(declRefExpr(to(enumConstantDecl(),
 isConstexpr(), isConstinit())
```
Simply to exclude only those that are enum constant and those that use const 
variable that is initialized with enum constant, you could merge this with 
exist changes, and reduce duplications.

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


[clang] [Clang] Add some CodeGen tests for CWG 2xx issues (PR #80823)

2024-02-08 Thread Vlad Serebrennikov via cfe-commits


@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+

Endilll wrote:

O3 tests are removed.

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


[clang] [Clang] Add some CodeGen tests for CWG 2xx issues (PR #80823)

2024-02-08 Thread Vlad Serebrennikov via cfe-commits

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

>From 560713b5d45236956198654a10e0795eb56cad7b Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Tue, 6 Feb 2024 13:23:36 +0300
Subject: [PATCH 1/2] [Clang] Add some CodeGen tests for CWG 2xx issues

This patch covers CWG issues
[201](https://cplusplus.github.io/CWG/issues/201.html),
[210](https://cplusplus.github.io/CWG/issues/210.html),
[292](https://cplusplus.github.io/CWG/issues/292.html).

[CWG208](https://cplusplus.github.io/CWG/issues/208.html) is not covered, as it 
actually requires a libcxxabi test.
---
 clang/test/CXX/drs/dr201.cpp | 43 
 clang/test/CXX/drs/dr210.cpp | 41 ++
 clang/test/CXX/drs/dr292.cpp | 38 +++
 clang/test/CXX/drs/dr2xx.cpp |  6 ++---
 clang/www/cxx_dr_status.html |  8 +++
 5 files changed, 129 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/CXX/drs/dr201.cpp
 create mode 100644 clang/test/CXX/drs/dr210.cpp
 create mode 100644 clang/test/CXX/drs/dr292.cpp

diff --git a/clang/test/CXX/drs/dr201.cpp b/clang/test/CXX/drs/dr201.cpp
new file mode 100644
index 00..48495d337e00ff
--- /dev/null
+++ b/clang/test/CXX/drs/dr201.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+
+#if __cplusplus == 199711L
+#define NOTHROW throw()
+#else
+#define NOTHROW noexcept(true)
+#endif
+
+namespace dr201 { // dr201: 2.8
+
+struct A {
+  ~A() NOTHROW {}
+};
+
+struct B {
+  B(A) NOTHROW {}
+  ~B() NOTHROW {}
+};
+
+void foo() {
+  B b = A();
+}
+
+// CHECK-LABEL: define {{.*}} void @dr201::foo()
+// CHECK: call void @dr201::A::~A()
+// CHECK: call void @dr201::B::~B()
+// CHECK-LABEL: }
+
+} // namespace dr201
diff --git a/clang/test/CXX/drs/dr210.cpp b/clang/test/CXX/drs/dr210.cpp
new file mode 100644
index 00..c19771229596f1
--- /dev/null
+++ b/clang/test/CXX/drs/dr210.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck 

[clang] [clang][sema] Fix -Wunused-function on target_version'd file-scope Fn's (PR #81167)

2024-02-08 Thread Fangrui Song via cfe-commits

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


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


[clang] [Clang] Add some CodeGen tests for CWG 2xx issues (PR #80823)

2024-02-08 Thread Vlad Serebrennikov via cfe-commits


@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O0 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm 
-disable-llvm-passes -O3 -o - -fexceptions -fcxx-exceptions -pedantic-errors | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
+
+#if __cplusplus == 199711L
+#define NOTHROW throw()
+#else
+#define NOTHROW noexcept(true)
+#endif
+
+namespace dr201 { // dr201: 2.8

Endilll wrote:

I'll update the test to make it more clear, but I test whether a temporary is 
destroyed at the end of full expression. Which I believe is what 201 is about, 
contrary to its title.

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


[clang-tools-extra] FIX : bugprone-too-small-loop-variable - false-negative when const variable is used as loop bound (PR #81183)

2024-02-08 Thread Shourya Goel via cfe-commits

Sh0g0-1758 wrote:

done. Please review and suggest further changes. 

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


[clang-tools-extra] FIX : bugprone-too-small-loop-variable - false-negative when const variable is used as loop bound (PR #81183)

2024-02-08 Thread Shourya Goel via cfe-commits


@@ -82,10 +82,14 @@ void 
TooSmallLoopVariableCheck::registerMatchers(MatchFinder *Finder) {
   // We are interested in only those cases when the loop bound is a variable
   // value (not const, enum, etc.).
   StatementMatcher LoopBoundMatcher =
-  expr(ignoringParenImpCasts(allOf(hasType(isInteger()),
-   unless(integerLiteral()),
-   unless(hasType(isConstQualified())),
-   unless(hasType(enumType())
+  expr(ignoringParenImpCasts(allOf(
+   hasType(isInteger()), unless(integerLiteral()),
+   unless(allOf(
+   hasType(isConstQualified()),
+   declRefExpr(to(varDecl(anyOf(
+   hasInitializer(ignoringParenImpCasts(integerLiteral())),
+   isConstexpr(), isConstinit())),
+   unless(hasType(enumType())

Sh0g0-1758 wrote:

Should I change it? if so please provide me with some more details. 

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


[clang-tools-extra] FIX : bugprone-too-small-loop-variable - false-negative when const variable is used as loop bound (PR #81183)

2024-02-08 Thread Shourya Goel via cfe-commits


@@ -44,3 +44,5 @@ a larger user input.
 for (unsigned i = 0; i < size; ++i) {} // no warning with 
MagnitudeBitsUpperLimit = 31 on a system where unsigned is 32-bit
 for (int i = 0; i < size; ++i) {} // warning with MagnitudeBitsUpperLimit 
= 31 on a system where int is 32-bit
   }
+
+``-Wtautological-constant-out-of-range-compare`` compiler warning should also 
be used.

Sh0g0-1758 wrote:

done. 

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


[clang-tools-extra] FIX : bugprone-too-small-loop-variable - false-negative when const variable is used as loop bound (PR #81183)

2024-02-08 Thread Shourya Goel via cfe-commits


@@ -169,6 +169,9 @@ Miscellaneous
   option is specified. Now ``clang-apply-replacements`` applies formatting 
only with
   the option.
 
+- Fixed incorrect implementation of ``too-small-loop-variable`` check when a 
const loop
+  variable is initialized with a function declaration.
+

Sh0g0-1758 wrote:

done. 

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


[clang-tools-extra] FIX : bugprone-too-small-loop-variable - false-negative when const variable is used as loop bound (PR #81183)

2024-02-08 Thread Shourya Goel via cfe-commits

https://github.com/Sh0g0-1758 updated 
https://github.com/llvm/llvm-project/pull/81183

>From 88dac6713284ee4f0b7ce73c944f78085412645f Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 
Date: Fri, 9 Feb 2024 01:21:14 +0530
Subject: [PATCH 1/4] Fix : bugprone-too-small-loop-variable

---
 .../bugprone/TooSmallLoopVariableCheck.cpp   | 12 ++--
 clang-tools-extra/docs/ReleaseNotes.rst  |  3 +++
 .../checks/bugprone/too-small-loop-variable.rst  |  2 ++
 .../checkers/bugprone/too-small-loop-variable.cpp| 12 
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
index 8ba8b893e03a6f..8f6547f4ea9e65 100644
--- a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
@@ -81,12 +81,12 @@ void 
TooSmallLoopVariableCheck::registerMatchers(MatchFinder *Finder) {
 
   // We are interested in only those cases when the loop bound is a variable
   // value (not const, enum, etc.).
-  StatementMatcher LoopBoundMatcher =
-  expr(ignoringParenImpCasts(allOf(hasType(isInteger()),
-   unless(integerLiteral()),
-   unless(hasType(isConstQualified())),
-   unless(hasType(enumType())
-  .bind(LoopUpperBoundName);
+ StatementMatcher LoopBoundMatcher =
+   expr(ignoringParenImpCasts(allOf(hasType(isInteger()),
+unless(integerLiteral()),
+
unless(allOf(hasType(isConstQualified()), 
declRefExpr(to(varDecl(anyOf(hasInitializer(ignoringParenImpCasts(integerLiteral())),
 isConstexpr(), isConstinit())),
+unless(hasType(enumType())
+   .bind(LoopUpperBoundName);
 
   // We use the loop increment expression only to make sure we found the right
   // loop variable.
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index e50914aed5f07a..17b1349d20db8d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -169,6 +169,9 @@ Miscellaneous
   option is specified. Now ``clang-apply-replacements`` applies formatting 
only with
   the option.
 
+- Fixed incorrect implementation of ``too-small-loop-variable`` check when a 
const loop
+  variable is initialized with a function declaration.
+
 Improvements to include-fixer
 -
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst
index 0f45cc2fe11463..9ee23be45cfea0 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst
@@ -44,3 +44,5 @@ a larger user input.
 for (unsigned i = 0; i < size; ++i) {} // no warning with 
MagnitudeBitsUpperLimit = 31 on a system where unsigned is 32-bit
 for (int i = 0; i < size; ++i) {} // warning with MagnitudeBitsUpperLimit 
= 31 on a system where int is 32-bit
   }
+
+``-Wtautological-constant-out-of-range-compare`` compiler warning should also 
be used.
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable.cpp
index 3229deb93bada8..113150b168650b 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable.cpp
@@ -93,6 +93,18 @@ void voidBadForLoopWithMacroBound() {
   }
 }
 
+unsigned int getVal() {
+return 300;
+}
+
+// The iteration's upper bound has a function declaration.
+void voidBadForLoop8() {
+  const unsigned int l = getVal();
+  for (unsigned char i = 0; i < l; ++i) {
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: loop variable has narrower 
type 'unsigned char' than iteration's upper bound 'const unsigned int' 
[bugprone-too-small-loop-variable]
+  }
+}
+
 

 /// Correct loops: we should not warn here.
 

>From 41acf22b481ba6800c1d07e96d1d3ba8052b20a7 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 
Date: Fri, 9 Feb 2024 01:21:39 +0530
Subject: [PATCH 2/4] Ran git clang Formatter

---
 .../bugprone/TooSmallLoopVariableCheck.cpp   | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
index 8f6547f4ea9e65..a73d46f01d9b2d 100644
--- 

[clang] [clang-format][docs] Fix version (PR #81185)

2024-02-08 Thread Owen Pan via cfe-commits
=?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= 
Message-ID:
In-Reply-To: 


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

Good catch!

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


[clang-tools-extra] FIX : bugprone-too-small-loop-variable - false-negative when const variable is used as loop bound (PR #81183)

2024-02-08 Thread Shourya Goel via cfe-commits

https://github.com/Sh0g0-1758 updated 
https://github.com/llvm/llvm-project/pull/81183

>From 88dac6713284ee4f0b7ce73c944f78085412645f Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 
Date: Fri, 9 Feb 2024 01:21:14 +0530
Subject: [PATCH 1/3] Fix : bugprone-too-small-loop-variable

---
 .../bugprone/TooSmallLoopVariableCheck.cpp   | 12 ++--
 clang-tools-extra/docs/ReleaseNotes.rst  |  3 +++
 .../checks/bugprone/too-small-loop-variable.rst  |  2 ++
 .../checkers/bugprone/too-small-loop-variable.cpp| 12 
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
index 8ba8b893e03a6f..8f6547f4ea9e65 100644
--- a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
@@ -81,12 +81,12 @@ void 
TooSmallLoopVariableCheck::registerMatchers(MatchFinder *Finder) {
 
   // We are interested in only those cases when the loop bound is a variable
   // value (not const, enum, etc.).
-  StatementMatcher LoopBoundMatcher =
-  expr(ignoringParenImpCasts(allOf(hasType(isInteger()),
-   unless(integerLiteral()),
-   unless(hasType(isConstQualified())),
-   unless(hasType(enumType())
-  .bind(LoopUpperBoundName);
+ StatementMatcher LoopBoundMatcher =
+   expr(ignoringParenImpCasts(allOf(hasType(isInteger()),
+unless(integerLiteral()),
+
unless(allOf(hasType(isConstQualified()), 
declRefExpr(to(varDecl(anyOf(hasInitializer(ignoringParenImpCasts(integerLiteral())),
 isConstexpr(), isConstinit())),
+unless(hasType(enumType())
+   .bind(LoopUpperBoundName);
 
   // We use the loop increment expression only to make sure we found the right
   // loop variable.
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index e50914aed5f07a..17b1349d20db8d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -169,6 +169,9 @@ Miscellaneous
   option is specified. Now ``clang-apply-replacements`` applies formatting 
only with
   the option.
 
+- Fixed incorrect implementation of ``too-small-loop-variable`` check when a 
const loop
+  variable is initialized with a function declaration.
+
 Improvements to include-fixer
 -
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst
index 0f45cc2fe11463..9ee23be45cfea0 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst
@@ -44,3 +44,5 @@ a larger user input.
 for (unsigned i = 0; i < size; ++i) {} // no warning with 
MagnitudeBitsUpperLimit = 31 on a system where unsigned is 32-bit
 for (int i = 0; i < size; ++i) {} // warning with MagnitudeBitsUpperLimit 
= 31 on a system where int is 32-bit
   }
+
+``-Wtautological-constant-out-of-range-compare`` compiler warning should also 
be used.
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable.cpp
index 3229deb93bada8..113150b168650b 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable.cpp
@@ -93,6 +93,18 @@ void voidBadForLoopWithMacroBound() {
   }
 }
 
+unsigned int getVal() {
+return 300;
+}
+
+// The iteration's upper bound has a function declaration.
+void voidBadForLoop8() {
+  const unsigned int l = getVal();
+  for (unsigned char i = 0; i < l; ++i) {
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: loop variable has narrower 
type 'unsigned char' than iteration's upper bound 'const unsigned int' 
[bugprone-too-small-loop-variable]
+  }
+}
+
 

 /// Correct loops: we should not warn here.
 

>From 41acf22b481ba6800c1d07e96d1d3ba8052b20a7 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 
Date: Fri, 9 Feb 2024 01:21:39 +0530
Subject: [PATCH 2/3] Ran git clang Formatter

---
 .../bugprone/TooSmallLoopVariableCheck.cpp   | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
index 8f6547f4ea9e65..a73d46f01d9b2d 100644
--- 

[clang] [clang-format] Add BreakAfterReturnType option to deprecate AlwaysBreakAfterReturnType. (PR #80827)

2024-02-08 Thread Owen Pan via cfe-commits


@@ -1010,7 +1010,8 @@ struct FormatStyle {
   /// \version 3.7
   DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
 
-  /// The function declaration return type breaking style to use.
+  /// The function declaration return type breaking style to use.  This
+  /// option is **deprecated** and is retained for backwards compatibility.
   /// \version 3.8
   ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;

owenca wrote:

+1, but see 
https://github.com/llvm/llvm-project/pull/80827#issuecomment-1935386091.

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


[clang] [clang-format] Add BreakAfterReturnType option to deprecate AlwaysBreakAfterReturnType. (PR #80827)

2024-02-08 Thread Owen Pan via cfe-commits

owenca wrote:

@rmarker we only need to change the user-facing part and should leave the 
internal naming unchanged (at least in this patch) in order to have the 
smallest diff possible. I've added the support for deprecating/renaming 
top-level struct-type options to `dump_format_style.py` in #81093.

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


[clang] [clang-format] Rename option AlwaysBreakTemplateDeclarations (PR #81093)

2024-02-08 Thread Owen Pan via cfe-commits

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

>From b9463c6664227edd6e579840292389909be04ab2 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 7 Feb 2024 22:43:15 -0800
Subject: [PATCH 1/3] [clang-format] Rename option
 AlwaysBreakTemplateDeclarations

Drop the "Always" prefix to remove the self-contradiction.
---
 clang/docs/ClangFormatStyleOptions.rst | 117 +++--
 clang/docs/tools/dump_format_style.py  |   7 ++
 clang/include/clang/Format/Format.h|   7 +-
 clang/lib/Format/Format.cpp|   6 +-
 clang/unittests/Format/ConfigParseTest.cpp |  13 +++
 5 files changed, 91 insertions(+), 59 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0a8cc18c5b4cb5..f3da652e691451 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1659,62 +1659,8 @@ the configuration (without a prefix: ``Auto``).
 
 .. _AlwaysBreakTemplateDeclarations:
 
-**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) 
:versionbadge:`clang-format 3.4` :ref:`¶ `
-  The template declaration breaking style to use.
-
-  Possible values:
-
-  * ``BTDS_Leave`` (in configuration: ``Leave``)
-Do not change the line breaking before the declaration.
-
-.. code-block:: c++
-
-   template 
-   T foo() {
-   }
-   template  T foo(int a,
-   int b) {
-   }
-
-  * ``BTDS_No`` (in configuration: ``No``)
-Do not force break before declaration.
-``PenaltyBreakTemplateDeclaration`` is taken into account.
-
-.. code-block:: c++
-
-   template  T foo() {
-   }
-   template  T foo(int a,
-   int b) {
-   }
-
-  * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
-Force break after template declaration only when the following
-declaration spans multiple lines.
-
-.. code-block:: c++
-
-   template  T foo() {
-   }
-   template 
-   T foo(int a,
- int b) {
-   }
-
-  * ``BTDS_Yes`` (in configuration: ``Yes``)
-Always break after template declaration.
-
-.. code-block:: c++
-
-   template 
-   T foo() {
-   }
-   template 
-   T foo(int a,
- int b) {
-   }
-
-
+**AlwaysBreakTemplateDeclarations** (``deprecated``) 
:versionbadge:`clang-format 3.4` :ref:`¶ `
+  This option is renamed to ``BreakTemplateDeclarations``.
 
 .. _AttributeMacros:
 
@@ -3014,6 +2960,65 @@ the configuration (without a prefix: ``Auto``).
  string x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
+.. _BreakTemplateDeclarations:
+
+**BreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  The template declaration breaking style to use.
+
+  Possible values:
+
+  * ``BTDS_Leave`` (in configuration: ``Leave``)
+Do not change the line breaking before the declaration.
+
+.. code-block:: c++
+
+   template 
+   T foo() {
+   }
+   template  T foo(int a,
+   int b) {
+   }
+
+  * ``BTDS_No`` (in configuration: ``No``)
+Do not force break before declaration.
+``PenaltyBreakTemplateDeclaration`` is taken into account.
+
+.. code-block:: c++
+
+   template  T foo() {
+   }
+   template  T foo(int a,
+   int b) {
+   }
+
+  * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
+Force break after template declaration only when the following
+declaration spans multiple lines.
+
+.. code-block:: c++
+
+   template  T foo() {
+   }
+   template 
+   T foo(int a,
+ int b) {
+   }
+
+  * ``BTDS_Yes`` (in configuration: ``Yes``)
+Always break after template declaration.
+
+.. code-block:: c++
+
+   template 
+   T foo() {
+   }
+   template 
+   T foo(int a,
+ int b) {
+   }
+
+
+
 .. _ColumnLimit:
 
 **ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index e41891f07de2e3..203e9450ed3767 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -308,6 +308,7 @@ class State:
 enum = None
 nested_struct = None
 version = None
+deprecated = False
 
 for line in self.header:
 self.lineno += 1
@@ -327,6 +328,8 @@ class State:
 match = re.match(r"/// 

[clang] [clang-format] Update FormatToken::isSimpleTypeSpecifier() (PR #80241)

2024-02-08 Thread Owen Pan via cfe-commits

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


[clang] 763139a - [clang-format] Update FormatToken::isSimpleTypeSpecifier() (#80241)

2024-02-08 Thread via cfe-commits

Author: Owen Pan
Date: 2024-02-08T21:42:29-08:00
New Revision: 763139afc19ddf2e0f0265dc828ce8e5fbe92530

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

LOG: [clang-format] Update FormatToken::isSimpleTypeSpecifier() (#80241)

Now with a8279a8bc541, we can make the update.

Added: 


Modified: 
clang/include/clang/Format/Format.h
clang/lib/Format/FormatToken.cpp
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h

Removed: 




diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index cb14d98825400b..bb63d33dfe6d5d 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5175,6 +5175,8 @@ tooling::Replacements sortUsingDeclarations(const 
FormatStyle ,
 ArrayRef Ranges,
 StringRef FileName = "");
 
+extern LangOptions LangOpts;
+
 /// Returns the ``LangOpts`` that the formatter expects you to set.
 ///
 /// \param Style determines specific settings for lexing mode.

diff  --git a/clang/lib/Format/FormatToken.cpp 
b/clang/lib/Format/FormatToken.cpp
index b791c5a26bbe3a..69f751db896302 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,41 +34,8 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
-// FIXME: This is copy from Sema. Put it in a common place and remove
-// duplication.
 bool FormatToken::isSimpleTypeSpecifier() const {
-  switch (Tok.getKind()) {
-  case tok::kw_short:
-  case tok::kw_long:
-  case tok::kw___int64:
-  case tok::kw___int128:
-  case tok::kw_signed:
-  case tok::kw_unsigned:
-  case tok::kw_void:
-  case tok::kw_char:
-  case tok::kw_int:
-  case tok::kw_half:
-  case tok::kw_float:
-  case tok::kw_double:
-  case tok::kw___bf16:
-  case tok::kw__Float16:
-  case tok::kw___float128:
-  case tok::kw___ibm128:
-  case tok::kw_wchar_t:
-  case tok::kw_bool:
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
-#include "clang/Basic/TransformTypeTraits.def"
-  case tok::annot_typename:
-  case tok::kw_char8_t:
-  case tok::kw_char16_t:
-  case tok::kw_char32_t:
-  case tok::kw_typeof:
-  case tok::kw_decltype:
-  case tok::kw__Atomic:
-return true;
-  default:
-return false;
-  }
+  return Tok.isSimpleTypeSpecifier(LangOpts);
 }
 
 bool FormatToken::isTypeOrIdentifier() const {

diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index a87d0ba3dbbf9b..31b2b7ef77f81c 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -22,18 +22,20 @@
 namespace clang {
 namespace format {
 
+LangOptions LangOpts;
+
 FormatTokenLexer::FormatTokenLexer(
 const SourceManager , FileID ID, unsigned Column,
 const FormatStyle , encoding::Encoding Encoding,
 llvm::SpecificBumpPtrAllocator ,
 IdentifierTable )
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
-  Column(Column), TrailingWhitespace(0),
-  LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
+  Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
   Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
   Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
+  LangOpts = getFormattingLangOpts(Style);
   Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts));
   Lex->SetKeepWhitespaceMode(true);
 
@@ -1442,7 +1444,6 @@ void FormatTokenLexer::readRawToken(FormatToken ) {
 
 void FormatTokenLexer::resetLexer(unsigned Offset) {
   StringRef Buffer = SourceMgr.getBufferData(ID);
-  LangOpts = getFormattingLangOpts(Style);
   Lex.reset(new Lexer(SourceMgr.getLocForStartOfFile(ID), LangOpts,
   Buffer.begin(), Buffer.begin() + Offset, Buffer.end()));
   Lex->SetKeepWhitespaceMode(true);

diff  --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index 65dd733bd53352..52838f1d8a17f5 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -120,7 +120,6 @@ class FormatTokenLexer {
   unsigned Column;
   unsigned TrailingWhitespace;
   std::unique_ptr Lex;
-  LangOptions LangOpts;
   const SourceManager 
   FileID ID;
   const FormatStyle 



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


[clang] [llvm] [MC/DC] Refactor: Make `MCDCParams` as `std::variant` (PR #81227)

2024-02-08 Thread NAKAMURA Takumi via cfe-commits


@@ -264,9 +266,10 @@ class MCDCRecordProcessor {
   MCDCRecordProcessor(const BitVector ,
   const CounterMappingRegion ,
   ArrayRef Branches)
-  : Bitmap(Bitmap), Region(Region), Branches(Branches),
-NumConditions(Region.MCDCParams.NumConditions),
-BitmapIdx(Region.MCDCParams.BitmapIdx * CHAR_BIT),
+  : Bitmap(Bitmap), Region(Region),
+DecisionParams(Region.getDecisionParams()), Branches(Branches),
+NumConditions(DecisionParams.NumConditions),
+BitmapIdx(DecisionParams.BitmapIdx * CHAR_BIT),
 Folded(NumConditions, false), IndependencePairs(NumConditions),
 TestVectors((size_t)1 << NumConditions) {}

chapuni wrote:

I'll make this mergeable later, possibly tonight.

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


[clang] [llvm] [MC/DC] Refactor: Make `MCDCParams` as `std::variant` (PR #81227)

2024-02-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-pgo

Author: NAKAMURA Takumi (chapuni)


Changes

Introduce `MCDCDecisionParameters` and `MCDCBranchParameters` and make sure 
them not initialized as zero.

FIXME: Could we make `CoverageMappingRegion` as a smart tagged union?

---

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


6 Files Affected:

- (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+39-30) 
- (modified) llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h (+49-28) 
- (modified) llvm/lib/ProfileData/Coverage/CoverageMapping.cpp (+30-23) 
- (modified) llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp (+9-8) 
- (modified) llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp (+18-5) 
- (modified) llvm/unittests/ProfileData/CoverageMappingTest.cpp (+4-4) 


``diff
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 0c43317642bca4..da5d43cda91209 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -97,6 +97,8 @@ void CoverageSourceInfo::updateNextTokLoc(SourceLocation Loc) 
{
 namespace {
 using MCDCConditionID = CounterMappingRegion::MCDCConditionID;
 using MCDCParameters = CounterMappingRegion::MCDCParameters;
+using MCDCBranchParameters = CounterMappingRegion::MCDCBranchParameters;
+using MCDCDecisionParameters = CounterMappingRegion::MCDCDecisionParameters;
 
 /// A region of source code that can be mapped to a counter.
 class SourceMappingRegion {
@@ -185,7 +187,17 @@ class SourceMappingRegion {
 
   bool isBranch() const { return FalseCount.has_value(); }
 
-  bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
+  bool isMCDCDecision() const {
+const auto *DecisionParams =
+std::get_if();
+assert(!DecisionParams || DecisionParams->NumConditions > 0);
+return DecisionParams;
+  }
+
+  const auto () const {
+return CounterMappingRegion::getParams(
+MCDCParams);
+  }
 
   const MCDCParameters () const { return MCDCParams; }
 };
@@ -483,13 +495,13 @@ class CoverageMappingBuilder {
 SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
-Region.getCounter(), Region.getFalseCounter(),
-Region.getMCDCParams(), *CovFileID, SR.LineStart, SR.ColumnStart,
-SR.LineEnd, SR.ColumnEnd));
+Region.getCounter(), Region.getFalseCounter(), *CovFileID,
+SR.LineStart, SR.ColumnStart, SR.LineEnd, SR.ColumnEnd,
+Region.getMCDCParams()));
   } else if (Region.isMCDCDecision()) {
 MappingRegions.push_back(CounterMappingRegion::makeDecisionRegion(
-Region.getMCDCParams(), *CovFileID, SR.LineStart, SR.ColumnStart,
-SR.LineEnd, SR.ColumnEnd));
+Region.getMCDCDecisionParams(), *CovFileID, SR.LineStart,
+SR.ColumnStart, SR.LineEnd, SR.ColumnEnd));
   } else {
 MappingRegions.push_back(CounterMappingRegion::makeRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
@@ -865,8 +877,7 @@ struct CounterCoverageMappingBuilder
 std::optional StartLoc = std::nullopt,
 std::optional EndLoc = std::nullopt,
 std::optional FalseCount = std::nullopt,
-MCDCConditionID ID = 0, MCDCConditionID TrueID = 0,
-MCDCConditionID FalseID = 0) {
+const MCDCParameters  = std::monostate()) {
 
 if (StartLoc && !FalseCount) {
   MostRecentLocation = *StartLoc;
@@ -885,9 +896,7 @@ struct CounterCoverageMappingBuilder
   StartLoc = std::nullopt;
 if (EndLoc && EndLoc->isInvalid())
   EndLoc = std::nullopt;
-RegionStack.emplace_back(Count, FalseCount,
- MCDCParameters{0, 0, ID, TrueID, FalseID},
- StartLoc, EndLoc);
+RegionStack.emplace_back(Count, FalseCount, BranchParams, StartLoc, 
EndLoc);
 
 return RegionStack.size() - 1;
   }
@@ -896,8 +905,8 @@ struct CounterCoverageMappingBuilder
 std::optional StartLoc = std::nullopt,
 std::optional EndLoc = std::nullopt) {
 
-RegionStack.emplace_back(MCDCParameters{BitmapIdx, Conditions}, StartLoc,
- EndLoc);
+RegionStack.emplace_back(MCDCDecisionParameters{BitmapIdx, Conditions},
+ StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
   }
@@ -1042,9 +1051,10 @@ struct CounterCoverageMappingBuilder
 // function's SourceRegions) because it doesn't apply to any other source
 // code other than the Condition.
 if (CodeGenFunction::isInstrumentedCondition(C)) {
+  MCDCParameters BranchParams;
   MCDCConditionID ID = MCDCBuilder.getCondID(C);
-  MCDCConditionID TrueID = IDPair.TrueID;
- 

[clang] [llvm] [MC/DC] Refactor: Make `MCDCParams` as `std::variant` (PR #81227)

2024-02-08 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni created 
https://github.com/llvm/llvm-project/pull/81227

Introduce `MCDCDecisionParameters` and `MCDCBranchParameters` and make sure 
them not initialized as zero.

FIXME: Could we make `CoverageMappingRegion` as a smart tagged union?

>From c2b49a5317bf5b8af419cba814f95cc9305bec21 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Thu, 8 Feb 2024 23:12:54 +0900
Subject: [PATCH] [MC/DC] Refactor: Make `MCDCParams` as `std::variant`

Introduce `MCDCDecisionParameters` and `MCDCBranchParameters` and
make sure them not initialized as zero.

FIXME: Could we make `CoverageMappingRegion` as a smart tagged union?
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 69 +
 .../ProfileData/Coverage/CoverageMapping.h| 77 ---
 .../ProfileData/Coverage/CoverageMapping.cpp  | 53 +++--
 .../Coverage/CoverageMappingReader.cpp| 17 ++--
 .../Coverage/CoverageMappingWriter.cpp| 23 --
 .../ProfileData/CoverageMappingTest.cpp   |  8 +-
 6 files changed, 149 insertions(+), 98 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 0c43317642bca4..da5d43cda91209 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -97,6 +97,8 @@ void CoverageSourceInfo::updateNextTokLoc(SourceLocation Loc) 
{
 namespace {
 using MCDCConditionID = CounterMappingRegion::MCDCConditionID;
 using MCDCParameters = CounterMappingRegion::MCDCParameters;
+using MCDCBranchParameters = CounterMappingRegion::MCDCBranchParameters;
+using MCDCDecisionParameters = CounterMappingRegion::MCDCDecisionParameters;
 
 /// A region of source code that can be mapped to a counter.
 class SourceMappingRegion {
@@ -185,7 +187,17 @@ class SourceMappingRegion {
 
   bool isBranch() const { return FalseCount.has_value(); }
 
-  bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
+  bool isMCDCDecision() const {
+const auto *DecisionParams =
+std::get_if();
+assert(!DecisionParams || DecisionParams->NumConditions > 0);
+return DecisionParams;
+  }
+
+  const auto () const {
+return CounterMappingRegion::getParams(
+MCDCParams);
+  }
 
   const MCDCParameters () const { return MCDCParams; }
 };
@@ -483,13 +495,13 @@ class CoverageMappingBuilder {
 SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
-Region.getCounter(), Region.getFalseCounter(),
-Region.getMCDCParams(), *CovFileID, SR.LineStart, SR.ColumnStart,
-SR.LineEnd, SR.ColumnEnd));
+Region.getCounter(), Region.getFalseCounter(), *CovFileID,
+SR.LineStart, SR.ColumnStart, SR.LineEnd, SR.ColumnEnd,
+Region.getMCDCParams()));
   } else if (Region.isMCDCDecision()) {
 MappingRegions.push_back(CounterMappingRegion::makeDecisionRegion(
-Region.getMCDCParams(), *CovFileID, SR.LineStart, SR.ColumnStart,
-SR.LineEnd, SR.ColumnEnd));
+Region.getMCDCDecisionParams(), *CovFileID, SR.LineStart,
+SR.ColumnStart, SR.LineEnd, SR.ColumnEnd));
   } else {
 MappingRegions.push_back(CounterMappingRegion::makeRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
@@ -865,8 +877,7 @@ struct CounterCoverageMappingBuilder
 std::optional StartLoc = std::nullopt,
 std::optional EndLoc = std::nullopt,
 std::optional FalseCount = std::nullopt,
-MCDCConditionID ID = 0, MCDCConditionID TrueID = 0,
-MCDCConditionID FalseID = 0) {
+const MCDCParameters  = std::monostate()) {
 
 if (StartLoc && !FalseCount) {
   MostRecentLocation = *StartLoc;
@@ -885,9 +896,7 @@ struct CounterCoverageMappingBuilder
   StartLoc = std::nullopt;
 if (EndLoc && EndLoc->isInvalid())
   EndLoc = std::nullopt;
-RegionStack.emplace_back(Count, FalseCount,
- MCDCParameters{0, 0, ID, TrueID, FalseID},
- StartLoc, EndLoc);
+RegionStack.emplace_back(Count, FalseCount, BranchParams, StartLoc, 
EndLoc);
 
 return RegionStack.size() - 1;
   }
@@ -896,8 +905,8 @@ struct CounterCoverageMappingBuilder
 std::optional StartLoc = std::nullopt,
 std::optional EndLoc = std::nullopt) {
 
-RegionStack.emplace_back(MCDCParameters{BitmapIdx, Conditions}, StartLoc,
- EndLoc);
+RegionStack.emplace_back(MCDCDecisionParameters{BitmapIdx, Conditions},
+ StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
   }
@@ -1042,9 +1051,10 @@ struct CounterCoverageMappingBuilder
 // function's SourceRegions) because it doesn't apply to any other source
 // code other than 

[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-08 Thread Erich Keane via cfe-commits


@@ -0,0 +1,140 @@
+//===- StmtOpenACC.h - Classes for OpenACC directives  --*- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+/// \file
+/// This file defines OpenACC AST classes for statement-level contructs.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_AST_STMTOPENACC_H
+#define LLVM_CLANG_AST_STMTOPENACC_H
+
+#include "clang/AST/Stmt.h"
+#include "clang/Basic/OpenACCKinds.h"
+#include "clang/Basic/SourceLocation.h"
+
+namespace clang {
+/// This is the base class for an OpenACC statement-level construct, other
+/// construct types are expected to inherit from this.
+class OpenACCConstructStmt : public Stmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  /// The directive kind. Each implementation of this interface should handle
+  /// specific kinds.
+  OpenACCDirectiveKind Kind = OpenACCDirectiveKind::Invalid;
+  /// The location of the directive statement, from the '#' to the last token 
of
+  /// the directive.
+  SourceRange Range;
+
+  // TODO OPENACC: Clauses should probably be collected in this class.
+
+protected:
+  OpenACCConstructStmt(StmtClass SC, OpenACCDirectiveKind K,
+   SourceLocation Start, SourceLocation End)
+  : Stmt(SC), Kind(K), Range(Start, End) {}
+
+public:
+  OpenACCDirectiveKind getDirectiveKind() const { return Kind; }
+
+  static bool classof(const Stmt *S) {
+return S->getStmtClass() >= firstOpenACCConstructStmtConstant &&
+   S->getStmtClass() <= lastOpenACCConstructStmtConstant;
+  }
+
+  SourceLocation getBeginLoc() const { return Range.getBegin(); }
+  SourceLocation getEndLoc() const { return Range.getEnd(); }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+
+/// This is a base class for any OpenACC statement-level constructs that have 
an
+/// associated statement. This class is not intended to be instantiated, but is
+/// a convenient place to hold the associated statement.
+class OpenACCAssociatedStmtConstruct : public OpenACCConstructStmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  template  friend class RecursiveASTVisitor;
+  Stmt *AssociatedStmt = nullptr;
+
+protected:
+  OpenACCAssociatedStmtConstruct(StmtClass SC, OpenACCDirectiveKind K,
+ SourceLocation Start, SourceLocation End)
+  : OpenACCConstructStmt(SC, K, Start, End) {}
+
+  void setAssociatedStmt(Stmt *S) { AssociatedStmt = S; }
+  Stmt *getAssociatedStmt() { return AssociatedStmt; }
+  const Stmt *getAssociatedStmt() const {
+return const_cast(this)
+->getAssociatedStmt();
+  }
+
+public:
+  child_range children() {
+if (getAssociatedStmt())
+  return child_range(,  + 1);
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+/// This class represents a compute construct, representing a 'Kind' of
+/// `parallel', 'serial', or 'kernel'. These constructs are associated with a
+/// 'structured block', defined as:
+///
+///  in C or C++, an executable statement, possibly compound, with a single
+///  entry at the top and a single exit at the bottom
+///
+/// At the moment there is no real motivation to have a different AST node for
+/// those three, as they are semantically identical, and have only minor
+/// differences in the permitted list of clauses, which can be differentiated 
by
+/// the 'Kind'.
+class OpenACCComputeConstruct : public OpenACCAssociatedStmtConstruct {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  OpenACCComputeConstruct()
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
+   OpenACCDirectiveKind::Invalid,
+   SourceLocation{}, SourceLocation{}) {}
+
+  OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start,
+  SourceLocation End)
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass, K, Start,
+   End) {
+assert((K == OpenACCDirectiveKind::Parallel ||
+K == OpenACCDirectiveKind::Serial ||
+K == OpenACCDirectiveKind::Kernels) &&
+   "Only parallel, serial, and kernels constructs should be "
+   "represented by this type");
+  }
+
+public:
+  static bool classof(const Stmt *T) {
+return T->getStmtClass() == OpenACCComputeConstructClass;
+  }
+
+  static OpenACCComputeConstruct *CreateEmpty(const ASTContext , 

[clang] [Clang][Sema] Diagnosis for constexpr constructor not initializing a union member (PR #81172)

2024-02-08 Thread via cfe-commits

mahtohappy wrote:

Closing this, as created a PR from forked main branch. Correct PR 
https://github.com/llvm/llvm-project/pull/81225

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


[clang] [Clang][Sema] Diagnosis for constexpr constructor not initializing a union member (PR #81172)

2024-02-08 Thread via cfe-commits

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


[clang] [Clang][Sema] Diagnosis for constexpr constructor not initializing a union member (PR #81225)

2024-02-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (mahtohappy)


Changes

For templates, isDependentContext() is true, that's why the previous if check 
was failing.
Here, we traverse the RD and upon finding a Union declaration we check if at 
least one member of the union is initialized.
If not, it produces a diagnosis for it.
Fix #46689 

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3-2) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+37-11) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp (+4-2) 
- (added) clang/test/SemaCXX/constexpr-union-temp-ctor-cxx.cpp (+27) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32440ee64e3ebe..0072495354b8eb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -149,9 +149,10 @@ Improvements to Clang's diagnostics
   prints.
 
 - Clang now diagnoses member template declarations with multiple declarators.
+- Clang now diagnoses use of the ``template`` keyword after declarative nested 
name specifiers.
 
-- Clang now diagnoses use of the ``template`` keyword after declarative nested
-  name specifiers.
+- Clang now diagnoses constexpr constructor for not initializing atleast one 
member of union
+- Fixes(`#46689 Constexpr constructor not initializing a union member is not 
diagnosed`)
 
 - The ``-Wshorten-64-to-32`` diagnostic is now grouped under 
``-Wimplicit-int-conversion`` instead
of ``-Wconversion``. Fixes `#69444 
`_.
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index fea8c5036c80b1..f6c7410e3be92a 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -1795,6 +1795,12 @@ static bool CheckConstexprFunctionBody(Sema , 
const FunctionDecl *Dcl,
Stmt *Body,
Sema::CheckConstexprKind Kind);
 
+static bool
+checkUnionConstructorIntializer(Sema , const FunctionDecl *Dcl,
+const CXXConstructorDecl *Constructor,
+const CXXRecordDecl *RD,
+Sema::CheckConstexprKind Kind);
+
 // Check whether a function declaration satisfies the requirements of a
 // constexpr function definition or a constexpr constructor definition. If so,
 // return true. If not, produce appropriate diagnostics (unless asked not to by
@@ -2343,17 +2349,9 @@ static bool CheckConstexprFunctionBody(Sema , 
const FunctionDecl *Dcl,
 // - if the class is a union having variant members, exactly one of them
 //   shall be initialized;
 if (RD->isUnion()) {
-  if (Constructor->getNumCtorInitializers() == 0 &&
-  RD->hasVariantMembers()) {
-if (Kind == Sema::CheckConstexprKind::Diagnose) {
-  SemaRef.Diag(
-  Dcl->getLocation(),
-  SemaRef.getLangOpts().CPlusPlus20
-  ? diag::warn_cxx17_compat_constexpr_union_ctor_no_init
-  : diag::ext_constexpr_union_ctor_no_init);
-} else if (!SemaRef.getLangOpts().CPlusPlus20) {
-  return false;
-}
+  if (checkUnionConstructorIntializer(SemaRef, Dcl, Constructor, RD,
+  Kind)) {
+return false;
   }
 } else if (!Constructor->isDependentContext() &&
!Constructor->isDelegatingConstructor()) {
@@ -2393,6 +2391,17 @@ static bool CheckConstexprFunctionBody(Sema , 
const FunctionDecl *Dcl,
  Kind))
 return false;
   }
+} else if (!Constructor->isDelegatingConstructor()) {
+  for (const Decl *Decls : RD->decls()) {
+if (const auto *Inner = dyn_cast(Decls)) {
+  if (Inner->isUnion()) {
+if (checkUnionConstructorIntializer(SemaRef, Dcl, Constructor,
+Inner, Kind)) {
+  return true;
+}
+  }
+}
+  }
 }
   } else {
 if (ReturnStmts.empty()) {
@@ -2471,6 +2480,23 @@ static bool CheckConstexprFunctionBody(Sema , 
const FunctionDecl *Dcl,
   return true;
 }
 
+static bool
+checkUnionConstructorIntializer(Sema , const FunctionDecl *Dcl,
+const CXXConstructorDecl *Constructor,
+const CXXRecordDecl *RD,
+Sema::CheckConstexprKind Kind) {
+  if (Constructor->getNumCtorInitializers() == 0 && RD->hasVariantMembers()) {
+if (Kind == Sema::CheckConstexprKind::Diagnose) {
+  SemaRef.Diag(Dcl->getLocation(),
+   SemaRef.getLangOpts().CPlusPlus20
+   ? diag::warn_cxx17_compat_constexpr_union_ctor_no_init
+   : diag::ext_constexpr_union_ctor_no_init);
+} else if 

[clang] [Clang][Sema] Diagnosis for constexpr constructor not initializing a union member (PR #81225)

2024-02-08 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [Clang][Sema] Diagnosis for constexpr constructor not initializing a union member (PR #81225)

2024-02-08 Thread via cfe-commits

https://github.com/mahtohappy created 
https://github.com/llvm/llvm-project/pull/81225

For templates, isDependentContext() is true, that's why the previous if check 
was failing.
Here, we traverse the RD and upon finding a Union declaration we check if at 
least one member of the union is initialized.
If not, it produces a diagnosis for it.
Fix #46689 

>From aeb0686c76f2745111acd92c0d6b77faf69d2ed6 Mon Sep 17 00:00:00 2001
From: mahtohappy 
Date: Thu, 8 Feb 2024 10:51:22 -0800
Subject: [PATCH 1/2] [Clang][Sema] Diagnosis for constexpr constructor not
 initializing a union member

---
 clang/docs/ReleaseNotes.rst   |  5 +-
 clang/lib/Sema/SemaDeclCXX.cpp| 47 ++-
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp |  3 ++
 .../SemaCXX/constexpr-union-temp-ctor-cxx.cpp | 27 +++
 4 files changed, 69 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-union-temp-ctor-cxx.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32440ee64e3ebe..0072495354b8eb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -149,9 +149,10 @@ Improvements to Clang's diagnostics
   prints.
 
 - Clang now diagnoses member template declarations with multiple declarators.
+- Clang now diagnoses use of the ``template`` keyword after declarative nested 
name specifiers.
 
-- Clang now diagnoses use of the ``template`` keyword after declarative nested
-  name specifiers.
+- Clang now diagnoses constexpr constructor for not initializing atleast one 
member of union
+- Fixes(`#46689 Constexpr constructor not initializing a union member is not 
diagnosed`)
 
 - The ``-Wshorten-64-to-32`` diagnostic is now grouped under 
``-Wimplicit-int-conversion`` instead
of ``-Wconversion``. Fixes `#69444 
`_.
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index fea8c5036c80b1..8da4f095765661 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -1795,6 +1795,11 @@ static bool CheckConstexprFunctionBody(Sema , 
const FunctionDecl *Dcl,
Stmt *Body,
Sema::CheckConstexprKind Kind);
 
+static bool checkUnionConstructorIntializer(Sema , const FunctionDecl 
*Dcl,
+   const CXXConstructorDecl *Constructor,
+   const CXXRecordDecl *RD,
+   Sema::CheckConstexprKind Kind);
+
 // Check whether a function declaration satisfies the requirements of a
 // constexpr function definition or a constexpr constructor definition. If so,
 // return true. If not, produce appropriate diagnostics (unless asked not to by
@@ -2343,17 +2348,9 @@ static bool CheckConstexprFunctionBody(Sema , 
const FunctionDecl *Dcl,
 // - if the class is a union having variant members, exactly one of them
 //   shall be initialized;
 if (RD->isUnion()) {
-  if (Constructor->getNumCtorInitializers() == 0 &&
-  RD->hasVariantMembers()) {
-if (Kind == Sema::CheckConstexprKind::Diagnose) {
-  SemaRef.Diag(
-  Dcl->getLocation(),
-  SemaRef.getLangOpts().CPlusPlus20
-  ? diag::warn_cxx17_compat_constexpr_union_ctor_no_init
-  : diag::ext_constexpr_union_ctor_no_init);
-} else if (!SemaRef.getLangOpts().CPlusPlus20) {
-  return false;
-}
+  if (checkUnionConstructorIntializer(SemaRef, Dcl, Constructor, RD,
+  Kind)) {
+return false;
   }
 } else if (!Constructor->isDependentContext() &&
!Constructor->isDelegatingConstructor()) {
@@ -2393,6 +2390,17 @@ static bool CheckConstexprFunctionBody(Sema , 
const FunctionDecl *Dcl,
  Kind))
 return false;
   }
+} else if (!Constructor->isDelegatingConstructor()) {
+  for (const Decl *Decls : RD->decls()) {
+if (const auto *Inner = dyn_cast(Decls)) {
+  if (Inner->isUnion()) {
+if (checkUnionConstructorIntializer(SemaRef, Dcl, Constructor,
+Inner, Kind)) {
+  return true;
+}
+  }
+}
+  }
 }
   } else {
 if (ReturnStmts.empty()) {
@@ -2471,6 +2479,23 @@ static bool CheckConstexprFunctionBody(Sema , 
const FunctionDecl *Dcl,
   return true;
 }
 
+static bool
+checkUnionConstructorIntializer(Sema , const FunctionDecl *Dcl,
+const CXXConstructorDecl *Constructor,
+const CXXRecordDecl *RD,
+Sema::CheckConstexprKind Kind) {
+  if (Constructor->getNumCtorInitializers() == 0 && RD->hasVariantMembers()) {
+if (Kind == Sema::CheckConstexprKind::Diagnose) {
+ 

[clang] [llvm] [MC/DC] Refactor: Introduce `ConditionIDs` as `std::array<2>` (PR #81221)

2024-02-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: NAKAMURA Takumi (chapuni)


Changes

Its 0th element corresponds to `FalseID` and 1st to `TrueID`.

CoverageMappingGen.cpp: `DecisionIDPair` is replaced with `ConditionIDs`

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


6 Files Affected:

- (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+18-32) 
- (modified) llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h (+6-3) 
- (modified) llvm/lib/ProfileData/Coverage/CoverageMapping.cpp (+14-17) 
- (modified) llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp (+4-3) 
- (modified) llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp (+2-2) 
- (modified) llvm/unittests/ProfileData/CoverageMappingTest.cpp (+12-12) 


``diff
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 0c43317642bca4..54559af47e63dc 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -95,7 +95,6 @@ void CoverageSourceInfo::updateNextTokLoc(SourceLocation Loc) 
{
 }
 
 namespace {
-using MCDCConditionID = CounterMappingRegion::MCDCConditionID;
 using MCDCParameters = CounterMappingRegion::MCDCParameters;
 
 /// A region of source code that can be mapped to a counter.
@@ -586,11 +585,6 @@ struct EmptyCoverageMappingBuilder : public 
CoverageMappingBuilder {
 /// creation.
 struct MCDCCoverageBuilder {
 
-  struct DecisionIDPair {
-MCDCConditionID TrueID = 0;
-MCDCConditionID FalseID = 0;
-  };
-
   /// The AST walk recursively visits nested logical-AND or logical-OR binary
   /// operator nodes and then visits their LHS and RHS children nodes.  As this
   /// happens, the algorithm will assign IDs to each operator's LHS and RHS 
side
@@ -681,14 +675,14 @@ struct MCDCCoverageBuilder {
 private:
   CodeGenModule 
 
-  llvm::SmallVector DecisionStack;
+  llvm::SmallVector DecisionStack;
   llvm::DenseMap 
   llvm::DenseMap 
   MCDCConditionID NextID = 1;
   bool NotMapped = false;
 
   /// Represent a sentinel value of [0,0] for the bottom of DecisionStack.
-  static constexpr DecisionIDPair DecisionStackSentinel{0, 0};
+  static constexpr MCDCConditionIDs DecisionStackSentinel{0, 0};
 
   /// Is this a logical-AND operation?
   bool isLAnd(const BinaryOperator *E) const {
@@ -727,7 +721,7 @@ struct MCDCCoverageBuilder {
   }
 
   /// Return the LHS Decision ([0,0] if not set).
-  const DecisionIDPair () const { return DecisionStack.back(); }
+  const MCDCConditionIDs () const { return DecisionStack.back(); }
 
   /// Push the binary operator statement to track the nest level and assign IDs
   /// to the operator's LHS and RHS.  The RHS may be a larger subtree that is
@@ -744,7 +738,7 @@ struct MCDCCoverageBuilder {
 if (NotMapped)
   return;
 
-const DecisionIDPair  = DecisionStack.back();
+const MCDCConditionIDs  = DecisionStack.back();
 
 // If the operator itself has an assigned ID, this means it represents a
 // larger subtree.  In this case, assign that ID to its LHS node.  Its RHS
@@ -760,18 +754,18 @@ struct MCDCCoverageBuilder {
 
 // Push the LHS decision IDs onto the DecisionStack.
 if (isLAnd(E))
-  DecisionStack.push_back({RHSid, ParentDecision.FalseID});
+  DecisionStack.push_back({ParentDecision[0], RHSid});
 else
-  DecisionStack.push_back({ParentDecision.TrueID, RHSid});
+  DecisionStack.push_back({RHSid, ParentDecision[1]});
   }
 
   /// Pop and return the LHS Decision ([0,0] if not set).
-  DecisionIDPair pop() {
+  MCDCConditionIDs pop() {
 if (!CGM.getCodeGenOpts().MCDCCoverage || NotMapped)
   return DecisionStack.front();
 
 assert(DecisionStack.size() > 1);
-DecisionIDPair D = DecisionStack.back();
+MCDCConditionIDs D = DecisionStack.back();
 DecisionStack.pop_back();
 return D;
   }
@@ -865,8 +859,7 @@ struct CounterCoverageMappingBuilder
 std::optional StartLoc = std::nullopt,
 std::optional EndLoc = std::nullopt,
 std::optional FalseCount = std::nullopt,
-MCDCConditionID ID = 0, MCDCConditionID TrueID = 0,
-MCDCConditionID FalseID = 0) {
+MCDCConditionID ID = 0, MCDCConditionIDs Conds = {}) {
 
 if (StartLoc && !FalseCount) {
   MostRecentLocation = *StartLoc;
@@ -885,8 +878,7 @@ struct CounterCoverageMappingBuilder
   StartLoc = std::nullopt;
 if (EndLoc && EndLoc->isInvalid())
   EndLoc = std::nullopt;
-RegionStack.emplace_back(Count, FalseCount,
- MCDCParameters{0, 0, ID, TrueID, FalseID},
+RegionStack.emplace_back(Count, FalseCount, MCDCParameters{0, 0, ID, 
Conds},
  StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -1024,15 +1016,12 @@ struct CounterCoverageMappingBuilder
 return (Cond->EvaluateAsInt(Result, CVM.getCodeGenModule().getContext()));
   }
 
-  

[clang] [llvm] [MC/DC] Refactor: Introduce `ConditionIDs` as `std::array<2>` (PR #81221)

2024-02-08 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni created 
https://github.com/llvm/llvm-project/pull/81221

Its 0th element corresponds to `FalseID` and 1st to `TrueID`.

CoverageMappingGen.cpp: `DecisionIDPair` is replaced with `ConditionIDs`

>From 66bb6cc3fd339360c16c6a98ce08f34978f665e0 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Fri, 9 Feb 2024 07:56:51 +0900
Subject: [PATCH] [MC/DC] Refactor: Introduce `ConditionIDs` as `std::array<2>`

Its 0th element corresponds to `FalseID` and 1st to `TrueID`.

CoverageMappingGen.cpp: `DecisionIDPair` is replaced with `ConditionIDs`
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 50 +++
 .../ProfileData/Coverage/CoverageMapping.h|  9 ++--
 .../ProfileData/Coverage/CoverageMapping.cpp  | 31 ++--
 .../Coverage/CoverageMappingReader.cpp|  7 +--
 .../Coverage/CoverageMappingWriter.cpp|  4 +-
 .../ProfileData/CoverageMappingTest.cpp   | 24 -
 6 files changed, 56 insertions(+), 69 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 0c43317642bca4..54559af47e63dc 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -95,7 +95,6 @@ void CoverageSourceInfo::updateNextTokLoc(SourceLocation Loc) 
{
 }
 
 namespace {
-using MCDCConditionID = CounterMappingRegion::MCDCConditionID;
 using MCDCParameters = CounterMappingRegion::MCDCParameters;
 
 /// A region of source code that can be mapped to a counter.
@@ -586,11 +585,6 @@ struct EmptyCoverageMappingBuilder : public 
CoverageMappingBuilder {
 /// creation.
 struct MCDCCoverageBuilder {
 
-  struct DecisionIDPair {
-MCDCConditionID TrueID = 0;
-MCDCConditionID FalseID = 0;
-  };
-
   /// The AST walk recursively visits nested logical-AND or logical-OR binary
   /// operator nodes and then visits their LHS and RHS children nodes.  As this
   /// happens, the algorithm will assign IDs to each operator's LHS and RHS 
side
@@ -681,14 +675,14 @@ struct MCDCCoverageBuilder {
 private:
   CodeGenModule 
 
-  llvm::SmallVector DecisionStack;
+  llvm::SmallVector DecisionStack;
   llvm::DenseMap 
   llvm::DenseMap 
   MCDCConditionID NextID = 1;
   bool NotMapped = false;
 
   /// Represent a sentinel value of [0,0] for the bottom of DecisionStack.
-  static constexpr DecisionIDPair DecisionStackSentinel{0, 0};
+  static constexpr MCDCConditionIDs DecisionStackSentinel{0, 0};
 
   /// Is this a logical-AND operation?
   bool isLAnd(const BinaryOperator *E) const {
@@ -727,7 +721,7 @@ struct MCDCCoverageBuilder {
   }
 
   /// Return the LHS Decision ([0,0] if not set).
-  const DecisionIDPair () const { return DecisionStack.back(); }
+  const MCDCConditionIDs () const { return DecisionStack.back(); }
 
   /// Push the binary operator statement to track the nest level and assign IDs
   /// to the operator's LHS and RHS.  The RHS may be a larger subtree that is
@@ -744,7 +738,7 @@ struct MCDCCoverageBuilder {
 if (NotMapped)
   return;
 
-const DecisionIDPair  = DecisionStack.back();
+const MCDCConditionIDs  = DecisionStack.back();
 
 // If the operator itself has an assigned ID, this means it represents a
 // larger subtree.  In this case, assign that ID to its LHS node.  Its RHS
@@ -760,18 +754,18 @@ struct MCDCCoverageBuilder {
 
 // Push the LHS decision IDs onto the DecisionStack.
 if (isLAnd(E))
-  DecisionStack.push_back({RHSid, ParentDecision.FalseID});
+  DecisionStack.push_back({ParentDecision[0], RHSid});
 else
-  DecisionStack.push_back({ParentDecision.TrueID, RHSid});
+  DecisionStack.push_back({RHSid, ParentDecision[1]});
   }
 
   /// Pop and return the LHS Decision ([0,0] if not set).
-  DecisionIDPair pop() {
+  MCDCConditionIDs pop() {
 if (!CGM.getCodeGenOpts().MCDCCoverage || NotMapped)
   return DecisionStack.front();
 
 assert(DecisionStack.size() > 1);
-DecisionIDPair D = DecisionStack.back();
+MCDCConditionIDs D = DecisionStack.back();
 DecisionStack.pop_back();
 return D;
   }
@@ -865,8 +859,7 @@ struct CounterCoverageMappingBuilder
 std::optional StartLoc = std::nullopt,
 std::optional EndLoc = std::nullopt,
 std::optional FalseCount = std::nullopt,
-MCDCConditionID ID = 0, MCDCConditionID TrueID = 0,
-MCDCConditionID FalseID = 0) {
+MCDCConditionID ID = 0, MCDCConditionIDs Conds = {}) {
 
 if (StartLoc && !FalseCount) {
   MostRecentLocation = *StartLoc;
@@ -885,8 +878,7 @@ struct CounterCoverageMappingBuilder
   StartLoc = std::nullopt;
 if (EndLoc && EndLoc->isInvalid())
   EndLoc = std::nullopt;
-RegionStack.emplace_back(Count, FalseCount,
- MCDCParameters{0, 0, ID, TrueID, FalseID},
+RegionStack.emplace_back(Count, FalseCount, MCDCParameters{0, 0, ID, 
Conds},

[clang] [SemaCXX] Make __builtin_addressof more like std::addressof (PR #78035)

2024-02-08 Thread Shafik Yaghmour via cfe-commits


@@ -39,7 +39,43 @@ namespace addressof {
   struct U { int n : 5; } u;
   int *pbf = __builtin_addressof(u.n); // expected-error {{address of 
bit-field requested}}
 
-  S *ptmp = __builtin_addressof(S{}); // expected-error {{taking the address 
of a temporary}} expected-warning {{temporary whose address is used as value of 
local variable 'ptmp' will be destroyed at the end of the full-expression}}

shafik wrote:

Do we understand why we lost the `warning` diagnostic?

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


[clang] [libcxx] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r (PR #81213)

2024-02-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/81213

>From 8657d0de76373665c55b774b9cdffe9707288efc Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Mon, 11 Sep 2023 04:31:02 +0200
Subject: [PATCH] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r

This patch also uses the new builtins in libc++.
---
 clang/docs/LanguageExtensions.rst|   2 +
 clang/docs/ReleaseNotes.rst  |   4 +
 clang/include/clang/Basic/TokenKinds.def |   2 +
 clang/lib/Sema/SemaExprCXX.cpp   | 390 +--
 clang/test/SemaCXX/type-traits-invocable.cpp | 288 ++
 libcxx/include/__type_traits/invoke.h|  40 +-
 6 files changed, 605 insertions(+), 121 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-traits-invocable.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index e91156837290f..bf061590e5ca0 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1582,6 +1582,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_integral`` (C++, Embarcadero)
 * ``__is_interface_class`` (Microsoft):
   Returns ``false``, even for types defined with ``__interface``.
+* ``__is_invocable_r`` (Clang)
 * ``__is_literal`` (Clang):
   Synonym for ``__is_literal_type``.
 * ``__is_literal_type`` (C++, GNU, Microsoft):
@@ -1594,6 +1595,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_nothrow_assignable`` (C++, MSVC 2013)
 * ``__is_nothrow_constructible`` (C++, MSVC 2013)
 * ``__is_nothrow_destructible`` (C++, MSVC 2013)
+* ``__is_nothrow_invocable_r`` (Clang)
 * ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
   Returns true for ``std::nullptr_t`` and false for everything else. The
   corresponding standard library feature is ``std::is_null_pointer``, but
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd8a82f281f52..8a4ae646c008f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -78,6 +78,10 @@ here. Generic improvements to Clang as a whole or to its 
underlying
 infrastructure are described first, followed by language-specific
 sections with improvements to Clang's support for those languages.
 
+- The builtins `__is_invocable_r` and `__is_nothrow_invocable_r` have been 
added.
+  These are equivalent to the standard library builtins `std::is_invocable_r`
+  and `std::is_nothrow_invocable_r`.
+
 C++ Language Changes
 
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 23817cde7a935..6467a52c82cb5 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -532,6 +532,8 @@ TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_N(__is_invocable_r, IsInvocableR, KEYCXX)
+TYPE_TRAIT_N(__is_nothrow_invocable_r, IsNothrowInvocableR, KEYCXX)
 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)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 246d2313e089f..5b82de9a51323 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5468,6 +5468,266 @@ static bool EvaluateUnaryTypeTrait(Sema , 
TypeTrait UTT,
 static bool EvaluateBinaryTypeTrait(Sema , TypeTrait BTT, QualType LhsT,
 QualType RhsT, SourceLocation KeyLoc);
 
+static bool IsBaseOf(Sema , QualType LhsT, QualType RhsT,
+ SourceLocation KeyLoc) {
+  // C++0x [meta.rel]p2
+  // Base is a base class of Derived without regard to cv-qualifiers or
+  // Base and Derived are not unions and name the same class type without
+  // regard to cv-qualifiers.
+
+  const RecordType *lhsRecord = LhsT->getAs();
+  const RecordType *rhsRecord = RhsT->getAs();
+  if (!rhsRecord || !lhsRecord) {
+const ObjCObjectType *LHSObjTy = LhsT->getAs();
+const ObjCObjectType *RHSObjTy = RhsT->getAs();
+if (!LHSObjTy || !RHSObjTy)
+  return false;
+
+ObjCInterfaceDecl *BaseInterface = LHSObjTy->getInterface();
+ObjCInterfaceDecl *DerivedInterface = RHSObjTy->getInterface();
+if (!BaseInterface || !DerivedInterface)
+  return false;
+
+if (Self.RequireCompleteType(
+KeyLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr))
+  return false;
+
+return BaseInterface->isSuperClassOf(DerivedInterface);
+  }
+
+  assert(Self.Context.hasSameUnqualifiedType(LhsT, RhsT) ==
+ (lhsRecord == rhsRecord));
+
+  // Unions are never base classes, 

[clang] [llvm] [clang][driver] Set TLSDESC as the default for Android on RISC-V (PR #81198)

2024-02-08 Thread Fangrui Song via cfe-commits


@@ -3,6 +3,11 @@
 // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
 // RUN: %clang -### --target=x86_64-linux -mtls-dialect=gnu %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
 
+/// Android supports TLSDESC by default after Android version 29 and all RISC-V
+/// TLSDESC is not on by default in Linux, even on RISC-V
+// RUN: %clang -### --target=riscv64-android %s 2>&1 | FileCheck 
--check-prefix=DESC %s
+// RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s

MaskRay wrote:

Delete `riscv64-linux` check. It's redundant. 

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


[clang] [llvm] [clang][driver] Set TLSDESC as the default for Android on RISC-V (PR #81198)

2024-02-08 Thread Fangrui Song via cfe-commits

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

LGTM once the `!isAndroidVersionLT(29)` check is removed.

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


[clang] [llvm] [clang][driver] Set TLSDESC as the default for Android on RISC-V (PR #81198)

2024-02-08 Thread Fangrui Song via cfe-commits

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


[clang] [libcxx] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r (PR #81213)

2024-02-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/81213

>From f2394044b0397cbe3bd15f96f43fbf0e50def206 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Mon, 11 Sep 2023 04:31:02 +0200
Subject: [PATCH] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r

This patch also uses the new builtins in libc++.
---
 clang/docs/LanguageExtensions.rst|   2 +
 clang/docs/ReleaseNotes.rst  |   4 +
 clang/include/clang/Basic/TokenKinds.def |   2 +
 clang/lib/Sema/SemaExprCXX.cpp   | 390 +--
 clang/test/SemaCXX/type-traits-invocable.cpp | 288 ++
 libcxx/include/__type_traits/invoke.h|  36 ++
 6 files changed, 603 insertions(+), 119 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-traits-invocable.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index e91156837290f7..bf061590e5ca0b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1582,6 +1582,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_integral`` (C++, Embarcadero)
 * ``__is_interface_class`` (Microsoft):
   Returns ``false``, even for types defined with ``__interface``.
+* ``__is_invocable_r`` (Clang)
 * ``__is_literal`` (Clang):
   Synonym for ``__is_literal_type``.
 * ``__is_literal_type`` (C++, GNU, Microsoft):
@@ -1594,6 +1595,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_nothrow_assignable`` (C++, MSVC 2013)
 * ``__is_nothrow_constructible`` (C++, MSVC 2013)
 * ``__is_nothrow_destructible`` (C++, MSVC 2013)
+* ``__is_nothrow_invocable_r`` (Clang)
 * ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
   Returns true for ``std::nullptr_t`` and false for everything else. The
   corresponding standard library feature is ``std::is_null_pointer``, but
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd8a82f281f52a..8a4ae646c008f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -78,6 +78,10 @@ here. Generic improvements to Clang as a whole or to its 
underlying
 infrastructure are described first, followed by language-specific
 sections with improvements to Clang's support for those languages.
 
+- The builtins `__is_invocable_r` and `__is_nothrow_invocable_r` have been 
added.
+  These are equivalent to the standard library builtins `std::is_invocable_r`
+  and `std::is_nothrow_invocable_r`.
+
 C++ Language Changes
 
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 23817cde7a9354..6467a52c82cb5b 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -532,6 +532,8 @@ TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_N(__is_invocable_r, IsInvocableR, KEYCXX)
+TYPE_TRAIT_N(__is_nothrow_invocable_r, IsNothrowInvocableR, KEYCXX)
 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)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 246d2313e089f3..5b82de9a51323f 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5468,6 +5468,266 @@ static bool EvaluateUnaryTypeTrait(Sema , 
TypeTrait UTT,
 static bool EvaluateBinaryTypeTrait(Sema , TypeTrait BTT, QualType LhsT,
 QualType RhsT, SourceLocation KeyLoc);
 
+static bool IsBaseOf(Sema , QualType LhsT, QualType RhsT,
+ SourceLocation KeyLoc) {
+  // C++0x [meta.rel]p2
+  // Base is a base class of Derived without regard to cv-qualifiers or
+  // Base and Derived are not unions and name the same class type without
+  // regard to cv-qualifiers.
+
+  const RecordType *lhsRecord = LhsT->getAs();
+  const RecordType *rhsRecord = RhsT->getAs();
+  if (!rhsRecord || !lhsRecord) {
+const ObjCObjectType *LHSObjTy = LhsT->getAs();
+const ObjCObjectType *RHSObjTy = RhsT->getAs();
+if (!LHSObjTy || !RHSObjTy)
+  return false;
+
+ObjCInterfaceDecl *BaseInterface = LHSObjTy->getInterface();
+ObjCInterfaceDecl *DerivedInterface = RHSObjTy->getInterface();
+if (!BaseInterface || !DerivedInterface)
+  return false;
+
+if (Self.RequireCompleteType(
+KeyLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr))
+  return false;
+
+return BaseInterface->isSuperClassOf(DerivedInterface);
+  }
+
+  assert(Self.Context.hasSameUnqualifiedType(LhsT, RhsT) ==
+ (lhsRecord == rhsRecord));
+
+  // Unions are never base 

[clang] [libcxx] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r (PR #81213)

2024-02-08 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 9cc2122bf5a81f7063c2a32b2cb78c8d615578a1 
6c74eb263dd889858f3f7be328d85fe354f71835 -- 
clang/test/SemaCXX/type-traits-invocable.cpp clang/include/clang/AST/Type.h 
clang/lib/Sema/SemaExprCXX.cpp libcxx/include/__type_traits/invoke.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4f4b6492e5..d033113805 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5520,7 +5520,8 @@ static bool IsBaseOf(Sema , QualType LhsT, QualType 
RhsT,
   ->isDerivedFrom(cast(lhsRecord->getDecl()));
 }
 
-static bool IsConvertible(Sema& Self, QualType LhsT, QualType RhsT, 
SourceLocation KeyLoc, bool CheckNothrow) {
+static bool IsConvertible(Sema , QualType LhsT, QualType RhsT,
+  SourceLocation KeyLoc, bool CheckNothrow) {
   // C++0x [meta.rel]p4:
   //   Given the following function prototype:
   //
@@ -5667,7 +5668,7 @@ static bool IsInvocable(Sema , SourceLocation KWLoc,
 if (Object->isPointerType())
   Object = Object->getPointeeType();
 // bullets 2, 5 - ignore reference_wrapper
-else if (auto* RD = Object->getAsCXXRecordDecl()) {
+else if (auto *RD = Object->getAsCXXRecordDecl()) {
   if (auto *TS = dyn_cast(RD)) {
 if (TS->isInStdNamespace() && TS->getName() == "reference_wrapper")
   Object = TS->getTemplateArgs().get(0).getAsType();
@@ -5865,7 +5866,8 @@ static bool EvaluateBooleanTypeTrait(Sema , TypeTrait 
Kind,
 return IsInvocable(S, KWLoc, Args, RParenLoc,
Kind == TT_IsNothrowInvocableR);
 
-  default: llvm_unreachable("not a TT");
+  default:
+llvm_unreachable("not a TT");
   }
 
   return false;
diff --git a/libcxx/include/__type_traits/invoke.h 
b/libcxx/include/__type_traits/invoke.h
index 5286d78bf6..0920539c71 100644
--- a/libcxx/include/__type_traits/invoke.h
+++ b/libcxx/include/__type_traits/invoke.h
@@ -424,7 +424,7 @@ struct __invoke_void_return_wrapper<_Ret, true> {
 
 // is_invocable
 
-#if __has_builtin(__is_invocable_r)
+#  if __has_builtin(__is_invocable_r)
 
 template 
 struct _LIBCPP_TEMPLATE_VIS is_invocable : 
bool_constant<__is_invocable_r(void, _Fn, _Args...)> {};
@@ -438,7 +438,7 @@ inline constexpr bool is_invocable_v = 
__is_invocable_r(void, _Fn, _Args...);
 template 
 inline constexpr bool is_invocable_r_v = __is_invocable_r(_Ret, _Fn, _Args...);
 
-#else
+#  else
 
 template 
 struct _LIBCPP_TEMPLATE_VIS is_invocable : integral_constant::value> {};
@@ -452,11 +452,11 @@ inline constexpr bool is_invocable_v = is_invocable<_Fn, 
_Args...>::value;
 template 
 inline constexpr bool is_invocable_r_v = is_invocable_r<_Ret, _Fn, 
_Args...>::value;
 
-#endif // __has_builtin(__is_invocable_r)
+#  endif // __has_builtin(__is_invocable_r)
 
 // is_nothrow_invocable
 
-#if __has_builtin(__is_nothrow_invocable_r)
+#  if __has_builtin(__is_nothrow_invocable_r)
 
 template 
 struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable : 
bool_constant<__is_nothrow_invocable_r(void, _Fn, _Args...)> {};
@@ -470,7 +470,7 @@ inline constexpr bool is_nothrow_invocable_v = 
__is_nothrow_invocable_r(void, _F
 template 
 inline constexpr bool is_nothrow_invocable_r_v = 
__is_nothrow_invocable_r(_Ret, _Fn, _Args...);
 
-#else
+#  else
 
 template 
 struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable : integral_constant::value> {
@@ -486,7 +486,7 @@ inline constexpr bool is_nothrow_invocable_v = 
is_nothrow_invocable<_Fn, _Args..
 template 
 inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<_Ret, 
_Fn, _Args...>::value;
 
-#endif // __has_builtin(__is_nothrow_invocable_r)
+#  endif // __has_builtin(__is_nothrow_invocable_r)
 
 template 
 struct _LIBCPP_TEMPLATE_VIS invoke_result : __invoke_of<_Fn, _Args...> {};

``




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


[clang] [SemaCXX] Implement CWG2351 `void{}` (PR #78060)

2024-02-08 Thread Shafik Yaghmour via cfe-commits


@@ -1600,12 +1600,25 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
 return ExprError(Diag(TyBeginLoc, diag::err_init_for_function_type)
<< Ty << FullRange);
 
-  // C++17 [expr.type.conv]p2:
-  //   If the type is cv void and the initializer is (), the expression is a
-  //   prvalue of the specified type that performs no initialization.
-  if (!Ty->isVoidType() &&
-  RequireCompleteType(TyBeginLoc, ElemTy,
-  diag::err_invalid_incomplete_type_use, FullRange))
+  // C++17 [expr.type.conv]p2, per DR2351:
+  //   If the type is cv void and the initializer is () or {}, the expression 
is
+  //   a prvalue of the specified type that performs no initialization.
+  if (Ty->isVoidType()) {

shafik wrote:

I am trying to understand why the check is here, and I think it is b/c the 
diagnostic is coming from one of these two lines:

```cpp
InitializationSequence InitSeq(*this, Entity, Kind, Exprs);
  ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Exprs);
```

is that correct? So then we need to handle this case before we attempt the 
initialization sequence. 

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


[clang] [SemaCXX] Implement CWG2351 `void{}` (PR #78060)

2024-02-08 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

Just a quick question

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


[clang] [SemaCXX] Implement CWG2351 `void{}` (PR #78060)

2024-02-08 Thread Shafik Yaghmour via cfe-commits

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


[clang] [libcxx] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r (PR #81213)

2024-02-08 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-libcxx

@llvm/pr-subscribers-clang

Author: Nikolas Klauser (philnik777)


Changes

This patch also uses the new builtins in libc++.


---

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


7 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+2) 
- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/include/clang/AST/Type.h (+3) 
- (modified) clang/include/clang/Basic/TokenKinds.def (+2) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+271-119) 
- (added) clang/test/SemaCXX/type-traits-invocable.cpp (+288) 
- (modified) libcxx/include/__type_traits/invoke.h (+36) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index e91156837290f7..bf061590e5ca0b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1582,6 +1582,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_integral`` (C++, Embarcadero)
 * ``__is_interface_class`` (Microsoft):
   Returns ``false``, even for types defined with ``__interface``.
+* ``__is_invocable_r`` (Clang)
 * ``__is_literal`` (Clang):
   Synonym for ``__is_literal_type``.
 * ``__is_literal_type`` (C++, GNU, Microsoft):
@@ -1594,6 +1595,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_nothrow_assignable`` (C++, MSVC 2013)
 * ``__is_nothrow_constructible`` (C++, MSVC 2013)
 * ``__is_nothrow_destructible`` (C++, MSVC 2013)
+* ``__is_nothrow_invocable_r`` (Clang)
 * ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
   Returns true for ``std::nullptr_t`` and false for everything else. The
   corresponding standard library feature is ``std::is_null_pointer``, but
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd8a82f281f52a..8a4ae646c008f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -78,6 +78,10 @@ here. Generic improvements to Clang as a whole or to its 
underlying
 infrastructure are described first, followed by language-specific
 sections with improvements to Clang's support for those languages.
 
+- The builtins `__is_invocable_r` and `__is_nothrow_invocable_r` have been 
added.
+  These are equivalent to the standard library builtins `std::is_invocable_r`
+  and `std::is_nothrow_invocable_r`.
+
 C++ Language Changes
 
 
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index d6a55f39a4bede..fe10391ac7057c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -926,6 +926,9 @@ class QualType {
   /// Return true if this is a trivially equality comparable type.
   bool isTriviallyEqualityComparableType(const ASTContext ) const;
 
+  /// Returns true if this is an invocable type.
+  bool isInvocableType() const;
+
   /// Returns true if it is a class and it might be dynamic.
   bool mayBeDynamicClass() const;
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 23817cde7a9354..6467a52c82cb5b 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -532,6 +532,8 @@ TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_N(__is_invocable_r, IsInvocableR, KEYCXX)
+TYPE_TRAIT_N(__is_nothrow_invocable_r, IsNothrowInvocableR, KEYCXX)
 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)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 246d2313e089f3..4f4b6492e58880 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5468,6 +5468,266 @@ static bool EvaluateUnaryTypeTrait(Sema , 
TypeTrait UTT,
 static bool EvaluateBinaryTypeTrait(Sema , TypeTrait BTT, QualType LhsT,
 QualType RhsT, SourceLocation KeyLoc);
 
+static bool IsBaseOf(Sema , QualType LhsT, QualType RhsT,
+ SourceLocation KeyLoc) {
+  // C++0x [meta.rel]p2
+  // Base is a base class of Derived without regard to cv-qualifiers or
+  // Base and Derived are not unions and name the same class type without
+  // regard to cv-qualifiers.
+
+  const RecordType *lhsRecord = LhsT->getAs();
+  const RecordType *rhsRecord = RhsT->getAs();
+  if (!rhsRecord || !lhsRecord) {
+const ObjCObjectType *LHSObjTy = LhsT->getAs();
+const ObjCObjectType *RHSObjTy = RhsT->getAs();
+if (!LHSObjTy || !RHSObjTy)
+  return false;
+
+ObjCInterfaceDecl *BaseInterface = LHSObjTy->getInterface();
+ObjCInterfaceDecl 

[clang] [libcxx] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r (PR #81213)

2024-02-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/81213

This patch also uses the new builtins in libc++.


>From 6c74eb263dd889858f3f7be328d85fe354f71835 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Mon, 11 Sep 2023 04:31:02 +0200
Subject: [PATCH] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r

This patch also uses the new builtins in libc++.
---
 clang/docs/LanguageExtensions.rst|   2 +
 clang/docs/ReleaseNotes.rst  |   4 +
 clang/include/clang/AST/Type.h   |   3 +
 clang/include/clang/Basic/TokenKinds.def |   2 +
 clang/lib/Sema/SemaExprCXX.cpp   | 390 +--
 clang/test/SemaCXX/type-traits-invocable.cpp | 288 ++
 libcxx/include/__type_traits/invoke.h|  36 ++
 7 files changed, 606 insertions(+), 119 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-traits-invocable.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index e91156837290f7..bf061590e5ca0b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1582,6 +1582,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_integral`` (C++, Embarcadero)
 * ``__is_interface_class`` (Microsoft):
   Returns ``false``, even for types defined with ``__interface``.
+* ``__is_invocable_r`` (Clang)
 * ``__is_literal`` (Clang):
   Synonym for ``__is_literal_type``.
 * ``__is_literal_type`` (C++, GNU, Microsoft):
@@ -1594,6 +1595,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_nothrow_assignable`` (C++, MSVC 2013)
 * ``__is_nothrow_constructible`` (C++, MSVC 2013)
 * ``__is_nothrow_destructible`` (C++, MSVC 2013)
+* ``__is_nothrow_invocable_r`` (Clang)
 * ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
   Returns true for ``std::nullptr_t`` and false for everything else. The
   corresponding standard library feature is ``std::is_null_pointer``, but
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd8a82f281f52a..8a4ae646c008f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -78,6 +78,10 @@ here. Generic improvements to Clang as a whole or to its 
underlying
 infrastructure are described first, followed by language-specific
 sections with improvements to Clang's support for those languages.
 
+- The builtins `__is_invocable_r` and `__is_nothrow_invocable_r` have been 
added.
+  These are equivalent to the standard library builtins `std::is_invocable_r`
+  and `std::is_nothrow_invocable_r`.
+
 C++ Language Changes
 
 
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index d6a55f39a4bede..fe10391ac7057c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -926,6 +926,9 @@ class QualType {
   /// Return true if this is a trivially equality comparable type.
   bool isTriviallyEqualityComparableType(const ASTContext ) const;
 
+  /// Returns true if this is an invocable type.
+  bool isInvocableType() const;
+
   /// Returns true if it is a class and it might be dynamic.
   bool mayBeDynamicClass() const;
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 23817cde7a9354..6467a52c82cb5b 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -532,6 +532,8 @@ TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_N(__is_invocable_r, IsInvocableR, KEYCXX)
+TYPE_TRAIT_N(__is_nothrow_invocable_r, IsNothrowInvocableR, KEYCXX)
 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)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 246d2313e089f3..4f4b6492e58880 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5468,6 +5468,266 @@ static bool EvaluateUnaryTypeTrait(Sema , 
TypeTrait UTT,
 static bool EvaluateBinaryTypeTrait(Sema , TypeTrait BTT, QualType LhsT,
 QualType RhsT, SourceLocation KeyLoc);
 
+static bool IsBaseOf(Sema , QualType LhsT, QualType RhsT,
+ SourceLocation KeyLoc) {
+  // C++0x [meta.rel]p2
+  // Base is a base class of Derived without regard to cv-qualifiers or
+  // Base and Derived are not unions and name the same class type without
+  // regard to cv-qualifiers.
+
+  const RecordType *lhsRecord = LhsT->getAs();
+  const RecordType *rhsRecord = RhsT->getAs();
+  if (!rhsRecord || !lhsRecord) {
+const ObjCObjectType *LHSObjTy = 

[clang] [llvm] [clang][driver] Set TLSDESC as the default for Android on RISC-V (PR #81198)

2024-02-08 Thread Paul Kirth via cfe-commits

ilovepi wrote:

Sounds good. I’ll update this when I have a chance tomorrow. 

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


[clang] [llvm] [clang][driver] Set TLSDESC as the default for Android on RISC-V (PR #81198)

2024-02-08 Thread via cfe-commits

enh-google wrote:

i think my suggestion would be instead of
```
return isAndroid() && (!isAndroidVersionLT(29) || isRISCV64());
```
just go with
```
return isAndroid() && isRISCV64();
```

that solves today's problem, and we can worry about arm64 later[1]. (and x86-64 
if/when that's implemented. and 32-bit never.)


1. why, when arm64 tlsdesc already shipped, and rv64 hasn't shipped yet? for 
_exactly_ that reason :-) with rv64 i don't even have to [have rprichard] think 
about app compat issues, say, or [have danalbert] think about communicating the 
change to ndk users, etc...

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


[clang] [llvm] InstCombine: Enable SimplifyDemandedUseFPClass and remove flag (PR #81108)

2024-02-08 Thread Andy Kaylor via cfe-commits

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

lgtm

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


[libunwind] Use relative includes to allow source-based dependencies without `-I` (PR #80443)

2024-02-08 Thread Alexander Richardson via cfe-commits

https://github.com/arichardson commented:

It does seem like all other libunwind sources use `#include "` to find headers 
that are part of libunwind, so I think doing it for the includes that are 
installed should also be fine. I don't think installing these headers into 
separate directories and adding custom -isystem flags is a supported build 
configuration. It will also ensure that we always pick the matching header 
rather than one that happens to come first in the include order.

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


[clang] [llvm] [clang][driver] Set TLSDESC as the default for Android on RISC-V (PR #81198)

2024-02-08 Thread via cfe-commits

pirama-arumuga-nainar wrote:

LGTM but let's wait for any comments from enh and maskray as well.

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


[clang] [llvm] [clang][driver] Set TLSDESC as the default for Android on RISC-V (PR #81198)

2024-02-08 Thread via cfe-commits

https://github.com/pirama-arumuga-nainar approved this pull request.


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


[clang] [clang][fmv] Drop .ifunc from target_version's entrypoint's mangling (PR #81194)

2024-02-08 Thread Jon Roelofs via cfe-commits

https://github.com/jroelofs updated 
https://github.com/llvm/llvm-project/pull/81194

>From 92aef5a078583f69cede47374e2b97de865c5c5d Mon Sep 17 00:00:00 2001
From: Jon Roelofs 
Date: Thu, 8 Feb 2024 13:56:50 -0800
Subject: [PATCH 1/4] [clang][fmv] Drop .ifunc from target_version's
 entrypoint's mangling

Fixes: https://github.com/llvm/llvm-project/issues/81043
---
 clang/include/clang/AST/Decl.h|   4 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/CodeGen/CodeGenModule.cpp   |   4 +-
 clang/test/CodeGen/attr-target-version.c  | 129 +-
 clang/test/CodeGenCXX/attr-target-version.cpp |  87 ++--
 5 files changed, 123 insertions(+), 105 deletions(-)

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index f26fb5ad5f1331..42fdf2b56dc278 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2619,6 +2619,10 @@ class FunctionDecl : public DeclaratorDecl,
   /// the target-clones functionality.
   bool isTargetClonesMultiVersion() const;
 
+  /// True if this function is a multiversioned dispatch function as a part of
+  /// the target-version functionality.
+  bool isTargetVersionMultiVersion() const;
+
   /// \brief Get the associated-constraints of this function declaration.
   /// Currently, this will either be a vector of size 1 containing the
   /// trailing-requires-clause or an empty vector.
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 26fdfa040796ed..40e2903265bf3c 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3541,6 +3541,10 @@ bool FunctionDecl::isTargetClonesMultiVersion() const {
   return isMultiVersion() && hasAttr();
 }
 
+bool FunctionDecl::isTargetVersionMultiVersion() const {
+  return isMultiVersion() && hasAttr();
+}
+
 void
 FunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) {
   redeclarable_base::setPreviousDecl(PrevDecl);
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 36b63d78b06f83..364553e2a6f0f7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4212,7 +4212,7 @@ void CodeGenModule::emitMultiVersionFunctions() {
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
-  if (FD->isTargetClonesMultiVersion()) {
+  if (FD->isTargetClonesMultiVersion() || 
FD->isTargetVersionMultiVersion()) {
 const CGFunctionInfo  = getTypes().arrangeGlobalDeclaration(GD);
 llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
@@ -4393,7 +4393,7 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // a separate resolver).
   std::string ResolverName = MangledName;
   if (getTarget().supportsIFunc()) {
-if (!FD->isTargetClonesMultiVersion())
+if (!FD->isTargetClonesMultiVersion() && 
!FD->isTargetVersionMultiVersion())
   ResolverName += ".ifunc";
   } else if (FD->isTargetMultiVersion()) {
 ResolverName += ".resolver";
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 2a96697e4291b9..c27d48f3ecf681 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -90,13 +90,20 @@ int hoo(void) {
 
 //.
 // CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
-// CHECK: @fmv.ifunc = weak_odr ifunc i32 (), ptr @fmv.resolver
-// CHECK: @fmv_one.ifunc = weak_odr ifunc i32 (), ptr @fmv_one.resolver
-// CHECK: @fmv_two.ifunc = weak_odr ifunc i32 (), ptr @fmv_two.resolver
-// CHECK: @fmv_e.ifunc = weak_odr ifunc i32 (), ptr @fmv_e.resolver
-// CHECK: @fmv_c.ifunc = weak_odr ifunc void (), ptr @fmv_c.resolver
-// CHECK: @fmv_inline.ifunc = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
-// CHECK: @fmv_d.ifunc = internal ifunc i32 (), ptr @fmv_d.resolver
+// CHECK: @fmv.ifunc = weak_odr alias i32 (), ptr @fmv
+// CHECK: @fmv_one.ifunc = weak_odr alias i32 (), ptr @fmv_one
+// CHECK: @fmv_two.ifunc = weak_odr alias i32 (), ptr @fmv_two
+// CHECK: @fmv_e.ifunc = weak_odr alias i32 (), ptr @fmv_e
+// CHECK: @fmv_inline.ifunc = weak_odr alias i32 (), ptr @fmv_inline
+// CHECK: @fmv_d.ifunc = internal alias i32 (), ptr @fmv_d
+// CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
+// CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
+// CHECK: @fmv_one = weak_odr ifunc i32 (), ptr @fmv_one.resolver
+// CHECK: @fmv_two = weak_odr ifunc i32 (), ptr @fmv_two.resolver
+// CHECK: @fmv_e = weak_odr ifunc i32 (), ptr @fmv_e.resolver
+// CHECK: @fmv_inline = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
+// CHECK: @fmv_d = internal ifunc i32 (), ptr @fmv_d.resolver
+// CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 //.
 // CHECK: Function Attrs: noinline nounwind optnone
 

[clang] [llvm] [clang] Add fixed point precision macros (PR #81207)

2024-02-08 Thread via cfe-commits

PiJoules wrote:

cc @lntue

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


[clang] [llvm] [clang] Add fixed point precision macros (PR #81207)

2024-02-08 Thread via cfe-commits

https://github.com/PiJoules updated 
https://github.com/llvm/llvm-project/pull/81207

>From 3360e6cf2542d4a53f87d8cafdd3a5638bd4a4ef Mon Sep 17 00:00:00 2001
From: Leonard Chan 
Date: Thu, 8 Feb 2024 16:12:35 -0800
Subject: [PATCH] [clang] Add fixed point precision macros

This defines the builtin macros specified in `7.18a.3 Precision macros`
of N1169. These are the `__*__` versions of them and the formal
definitions in stdfix.h can use them.
---
 clang/lib/Frontend/InitPreprocessor.cpp  | 94 
 clang/test/Preprocessor/fixed-point.c| 67 +
 clang/test/Preprocessor/no-fixed-point.c |  7 ++
 llvm/include/llvm/ADT/APFixedPoint.h |  1 +
 llvm/lib/Support/APFixedPoint.cpp|  6 ++
 5 files changed, 175 insertions(+)
 create mode 100644 clang/test/Preprocessor/fixed-point.c
 create mode 100644 clang/test/Preprocessor/no-fixed-point.c

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 877e205e2e9bfa..14f94f41175157 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -768,6 +768,59 @@ void InitializeOpenCLFeatureTestMacros(const TargetInfo 
,
   Builder.defineMacro("__opencl_c_int64");
 }
 
+std::string ConstructFixedPointLiteral(llvm::APFixedPoint Val,
+   llvm::StringRef Suffix) {
+  if (Val.isSigned() && Val == llvm::APFixedPoint::getMin(Val.getSemantics())) 
{
+// When representing the min value of a signed fixed point type in source
+// code, we cannot simply write `-`. For example, the min
+// value of a `short _Fract` cannot be written as `-1.0hr`. This is because
+// the parser will read this (and really any negative numerical literal) as
+// a UnaryOperator that owns a FixedPointLiteral with a positive value
+// rather than just a FixedPointLiteral with a negative value. Compiling
+// `-1.0hr` results in an overflow to the maximal value of that fixed point
+// type. The correct way to represent a signed min value is to instead 
split
+// it into two halves, like `(-0.5hr-0.5hr)` which is what the standard
+// defines SFRACT_MIN as.
+std::string Literal;
+std::string HalfStr = ConstructFixedPointLiteral(Val.shr(1), Suffix);
+Literal.push_back('(');
+Literal += HalfStr;
+Literal += HalfStr;
+Literal.push_back(')');
+return Literal;
+  }
+
+  std::string Str(Val.toString());
+  Str += Suffix;
+  return Str;
+}
+
+void DefineFixedPointMacros(const TargetInfo , MacroBuilder ,
+llvm::StringRef TypeName, llvm::StringRef Suffix,
+unsigned Width, unsigned Scale, bool Signed) {
+  // Saturation doesn't affect the size or scale of a fixed point type, so we
+  // don't need it here.
+  llvm::FixedPointSemantics FXSema(
+  Width, Scale, Signed, /*IsSaturated=*/false,
+  !Signed && TI.doUnsignedFixedPointTypesHavePadding());
+  llvm::SmallString<32> MacroPrefix("__");
+  MacroPrefix += TypeName;
+  Builder.defineMacro(MacroPrefix + "_EPSILON__",
+  ConstructFixedPointLiteral(
+  llvm::APFixedPoint::getEpsilon(FXSema), Suffix));
+  Builder.defineMacro(MacroPrefix + "_FBIT__", Twine(Scale));
+  Builder.defineMacro(
+  MacroPrefix + "_MAX__",
+  ConstructFixedPointLiteral(llvm::APFixedPoint::getMax(FXSema), Suffix));
+
+  // N1169 doesn't specify MIN macros for unsigned types since they're all just
+  // zero.
+  if (Signed)
+Builder.defineMacro(
+MacroPrefix + "_MIN__",
+ConstructFixedPointLiteral(llvm::APFixedPoint::getMin(FXSema), 
Suffix));
+}
+
 static void InitializePredefinedMacros(const TargetInfo ,
const LangOptions ,
const FrontendOptions ,
@@ -1097,6 +1150,47 @@ static void InitializePredefinedMacros(const TargetInfo 
,
  TI.getTypeWidth(TI.getIntMaxType()) &&
  "uintmax_t and intmax_t have different widths?");
 
+  if (LangOpts.FixedPoint) {
+// Each unsigned type has the same width as their signed type.
+DefineFixedPointMacros(TI, Builder, "SFRACT", "hr", 
TI.getShortFractWidth(),
+   TI.getShortFractScale(), /*Signed=*/true);
+DefineFixedPointMacros(TI, Builder, "USFRACT", "uhr",
+   TI.getShortFractWidth(),
+   TI.getUnsignedShortFractScale(), /*Signed=*/false);
+DefineFixedPointMacros(TI, Builder, "FRACT", "r", TI.getFractWidth(),
+   TI.getFractScale(), /*Signed=*/true);
+DefineFixedPointMacros(TI, Builder, "UFRACT", "ur", TI.getFractWidth(),
+   TI.getUnsignedFractScale(), /*Signed=*/false);
+DefineFixedPointMacros(TI, Builder, "LFRACT", "lr", TI.getLongFractWidth(),
+   TI.getLongFractScale(), /*Signed=*/true);
+DefineFixedPointMacros(TI, Builder, 

[clang] [llvm] [clang][driver] Set TLSDESC as the default for Android on RISC-V (PR #81198)

2024-02-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Paul Kirth (ilovepi)


Changes

Sets TLSDESC as the default on Android versions newer than 29, or if its
Android on RISC-V.


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


2 Files Affected:

- (modified) clang/test/Driver/tls-dialect.c (+5) 
- (modified) llvm/include/llvm/TargetParser/Triple.h (+1-2) 


``diff
diff --git a/clang/test/Driver/tls-dialect.c b/clang/test/Driver/tls-dialect.c
index 4e105ce3cea5d9..f309f4a44fbc3f 100644
--- a/clang/test/Driver/tls-dialect.c
+++ b/clang/test/Driver/tls-dialect.c
@@ -3,6 +3,11 @@
 // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
 // RUN: %clang -### --target=x86_64-linux -mtls-dialect=gnu %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
 
+/// Android supports TLSDESC by default after Android version 29 and all RISC-V
+/// TLSDESC is not on by default in Linux, even on RISC-V
+// RUN: %clang -### --target=riscv64-android %s 2>&1 | FileCheck 
--check-prefix=DESC %s
+// RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
+
 /// LTO
 // RUN: %clang -### --target=riscv64-linux -flto -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=LTO-DESC %s
 // RUN: %clang -### --target=riscv64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 98d8490cc9f7a2..0382d97d3fe38b 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -1036,8 +1036,7 @@ class Triple {
   /// True if the target supports both general-dynamic and TLSDESC, and TLSDESC
   /// is enabled by default.
   bool hasDefaultTLSDESC() const {
-// TODO: Improve check for other platforms, like Android, and RISC-V
-return false;
+return isAndroid() && (!isAndroidVersionLT(29) || isRISCV64());
   }
 
   /// Tests whether the target uses -data-sections as default.

``




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


[clang] [llvm] [clang][driver] Set TLSDESC as the default for Android on RISC-V (PR #81198)

2024-02-08 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/81198

>From 3221a5e60c58e64dabdf23c52d33ba7ed5bdf81e Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Thu, 8 Feb 2024 14:21:49 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 llvm/include/llvm/TargetParser/Triple.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 98d8490cc9f7a2..0382d97d3fe38b 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -1036,8 +1036,7 @@ class Triple {
   /// True if the target supports both general-dynamic and TLSDESC, and TLSDESC
   /// is enabled by default.
   bool hasDefaultTLSDESC() const {
-// TODO: Improve check for other platforms, like Android, and RISC-V
-return false;
+return isAndroid() && (!isAndroidVersionLT(29) || isRISCV64());
   }
 
   /// Tests whether the target uses -data-sections as default.

>From 567ccdff99f28cbf9598628e0150458f6302cc28 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Thu, 8 Feb 2024 16:15:07 -0800
Subject: [PATCH 2/2] Update test to check for defaults on Android (enabled)
 and Linux (not enabled)

Created using spr 1.3.4
---
 clang/test/Driver/tls-dialect.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Driver/tls-dialect.c b/clang/test/Driver/tls-dialect.c
index 4e105ce3cea5d9..f309f4a44fbc3f 100644
--- a/clang/test/Driver/tls-dialect.c
+++ b/clang/test/Driver/tls-dialect.c
@@ -3,6 +3,11 @@
 // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
 // RUN: %clang -### --target=x86_64-linux -mtls-dialect=gnu %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
 
+/// Android supports TLSDESC by default after Android version 29 and all RISC-V
+/// TLSDESC is not on by default in Linux, even on RISC-V
+// RUN: %clang -### --target=riscv64-android %s 2>&1 | FileCheck 
--check-prefix=DESC %s
+// RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
+
 /// LTO
 // RUN: %clang -### --target=riscv64-linux -flto -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=LTO-DESC %s
 // RUN: %clang -### --target=riscv64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s

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


[clang] [llvm] [clang] Add fixed point precision macros (PR #81207)

2024-02-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-adt

Author: None (PiJoules)


Changes

This defines the builtin macros specified in `7.18a.3 Precision macros` of 
N1169. These are the `__*__` versions of them and the formal definitions in 
stdfix.h can use them.

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


5 Files Affected:

- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+93) 
- (added) clang/test/Preprocessor/fixed-point.c (+67) 
- (added) clang/test/Preprocessor/no-fixed-point.c (+7) 
- (modified) llvm/include/llvm/ADT/APFixedPoint.h (+1) 
- (modified) llvm/lib/Support/APFixedPoint.cpp (+6) 


``diff
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 877e205e2e9bfa..7a136fb6bdcdf9 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -768,6 +768,58 @@ void InitializeOpenCLFeatureTestMacros(const TargetInfo 
,
   Builder.defineMacro("__opencl_c_int64");
 }
 
+std::string ConstructFixedPointLiteral(llvm::APFixedPoint Val,
+   llvm::StringRef Suffix) {
+  if (Val.isSigned() && Val == llvm::APFixedPoint::getMin(Val.getSemantics())) 
{
+// When representing the min value of a signed fixed point type in source
+// code, we cannot simply write `-`. For example, the min
+// value of a `short _Fract` cannot be written as `-1.0hr`. This is because
+// the parser will read this (and really any negative numerical literal) as
+// a UnaryOperator that owns a FixedPointLiteral with a positive value
+// rather than just a FixedPointLiteral with a negative value. Compiling
+// `-1.0hr` results in an overflow to the maximal value of that fixed point
+// type. The correct way to represent a signed min value is to instead 
split
+// it into two halves, like `(-0.5hr-0.5hr)` which is what the standard
+// defines SFRACT_MIN as.
+std::string Literal;
+std::string HalfStr = ConstructFixedPointLiteral(Val.shr(1), Suffix);
+Literal.push_back('(');
+Literal += HalfStr;
+Literal += HalfStr;
+Literal.push_back(')');
+return Literal;
+  }
+
+  std::string Str(Val.toString());
+  Str += Suffix;
+  return Str;
+}
+
+void DefineFixedPointMacros(const TargetInfo , MacroBuilder ,
+llvm::StringRef TypeName, llvm::StringRef Suffix,
+unsigned Width, unsigned Scale, bool Signed) {
+  // Saturation doesn't affect the size or scale of a fixed point type, so we
+  // don't need it here.
+  llvm::FixedPointSemantics FXSema(Width, Scale, Signed, /*IsSaturated=*/false,
+   TI.doUnsignedFixedPointTypesHavePadding());
+  llvm::SmallString<32> MacroPrefix("__");
+  MacroPrefix += TypeName;
+  Builder.defineMacro(MacroPrefix + "_EPSILON__",
+  ConstructFixedPointLiteral(
+  llvm::APFixedPoint::getEpsilon(FXSema), Suffix));
+  Builder.defineMacro(MacroPrefix + "_FBIT__", Twine(Scale));
+  Builder.defineMacro(
+  MacroPrefix + "_MAX__",
+  ConstructFixedPointLiteral(llvm::APFixedPoint::getMax(FXSema), Suffix));
+
+  // N1169 doesn't specify MIN macros for unsigned types since they're all just
+  // zero.
+  if (Signed)
+Builder.defineMacro(
+MacroPrefix + "_MIN__",
+ConstructFixedPointLiteral(llvm::APFixedPoint::getMin(FXSema), 
Suffix));
+}
+
 static void InitializePredefinedMacros(const TargetInfo ,
const LangOptions ,
const FrontendOptions ,
@@ -1097,6 +1149,47 @@ static void InitializePredefinedMacros(const TargetInfo 
,
  TI.getTypeWidth(TI.getIntMaxType()) &&
  "uintmax_t and intmax_t have different widths?");
 
+  if (LangOpts.FixedPoint) {
+// Each unsigned type has the same width as their signed type.
+DefineFixedPointMacros(TI, Builder, "SFRACT", "hr", 
TI.getShortFractWidth(),
+   TI.getShortFractScale(), /*Signed=*/true);
+DefineFixedPointMacros(TI, Builder, "USFRACT", "uhr",
+   TI.getShortFractWidth(),
+   TI.getUnsignedShortFractScale(), /*Signed=*/false);
+DefineFixedPointMacros(TI, Builder, "FRACT", "r", TI.getFractWidth(),
+   TI.getFractScale(), /*Signed=*/true);
+DefineFixedPointMacros(TI, Builder, "UFRACT", "ur", TI.getFractWidth(),
+   TI.getUnsignedFractScale(), /*Signed=*/false);
+DefineFixedPointMacros(TI, Builder, "LFRACT", "lr", TI.getLongFractWidth(),
+   TI.getLongFractScale(), /*Signed=*/true);
+DefineFixedPointMacros(TI, Builder, "ULFRACT", "ulr",
+   TI.getLongFractWidth(),
+   TI.getUnsignedLongFractScale(), /*Signed=*/false);
+DefineFixedPointMacros(TI, Builder, "SACCUM", "hk", 
TI.getShortAccumWidth(),
+  

[clang] [llvm] [clang] Add fixed point precision macros (PR #81207)

2024-02-08 Thread via cfe-commits

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

This defines the builtin macros specified in `7.18a.3 Precision macros` of 
N1169. These are the `__*__` versions of them and the formal definitions in 
stdfix.h can use them.

>From 23f6ff492970eed134af025307d0c6dce3857205 Mon Sep 17 00:00:00 2001
From: Leonard Chan 
Date: Thu, 8 Feb 2024 16:12:35 -0800
Subject: [PATCH] [clang] Add fixed point precision macros

This defines the builtin macros specified in `7.18a.3 Precision macros`
of N1169. These are the `__*__` versions of them and the formal
definitions in stdfix.h can use them.
---
 clang/lib/Frontend/InitPreprocessor.cpp  | 93 
 clang/test/Preprocessor/fixed-point.c| 67 +
 clang/test/Preprocessor/no-fixed-point.c |  7 ++
 llvm/include/llvm/ADT/APFixedPoint.h |  1 +
 llvm/lib/Support/APFixedPoint.cpp|  6 ++
 5 files changed, 174 insertions(+)
 create mode 100644 clang/test/Preprocessor/fixed-point.c
 create mode 100644 clang/test/Preprocessor/no-fixed-point.c

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 877e205e2e9bfa..7a136fb6bdcdf9 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -768,6 +768,58 @@ void InitializeOpenCLFeatureTestMacros(const TargetInfo 
,
   Builder.defineMacro("__opencl_c_int64");
 }
 
+std::string ConstructFixedPointLiteral(llvm::APFixedPoint Val,
+   llvm::StringRef Suffix) {
+  if (Val.isSigned() && Val == llvm::APFixedPoint::getMin(Val.getSemantics())) 
{
+// When representing the min value of a signed fixed point type in source
+// code, we cannot simply write `-`. For example, the min
+// value of a `short _Fract` cannot be written as `-1.0hr`. This is because
+// the parser will read this (and really any negative numerical literal) as
+// a UnaryOperator that owns a FixedPointLiteral with a positive value
+// rather than just a FixedPointLiteral with a negative value. Compiling
+// `-1.0hr` results in an overflow to the maximal value of that fixed point
+// type. The correct way to represent a signed min value is to instead 
split
+// it into two halves, like `(-0.5hr-0.5hr)` which is what the standard
+// defines SFRACT_MIN as.
+std::string Literal;
+std::string HalfStr = ConstructFixedPointLiteral(Val.shr(1), Suffix);
+Literal.push_back('(');
+Literal += HalfStr;
+Literal += HalfStr;
+Literal.push_back(')');
+return Literal;
+  }
+
+  std::string Str(Val.toString());
+  Str += Suffix;
+  return Str;
+}
+
+void DefineFixedPointMacros(const TargetInfo , MacroBuilder ,
+llvm::StringRef TypeName, llvm::StringRef Suffix,
+unsigned Width, unsigned Scale, bool Signed) {
+  // Saturation doesn't affect the size or scale of a fixed point type, so we
+  // don't need it here.
+  llvm::FixedPointSemantics FXSema(Width, Scale, Signed, /*IsSaturated=*/false,
+   TI.doUnsignedFixedPointTypesHavePadding());
+  llvm::SmallString<32> MacroPrefix("__");
+  MacroPrefix += TypeName;
+  Builder.defineMacro(MacroPrefix + "_EPSILON__",
+  ConstructFixedPointLiteral(
+  llvm::APFixedPoint::getEpsilon(FXSema), Suffix));
+  Builder.defineMacro(MacroPrefix + "_FBIT__", Twine(Scale));
+  Builder.defineMacro(
+  MacroPrefix + "_MAX__",
+  ConstructFixedPointLiteral(llvm::APFixedPoint::getMax(FXSema), Suffix));
+
+  // N1169 doesn't specify MIN macros for unsigned types since they're all just
+  // zero.
+  if (Signed)
+Builder.defineMacro(
+MacroPrefix + "_MIN__",
+ConstructFixedPointLiteral(llvm::APFixedPoint::getMin(FXSema), 
Suffix));
+}
+
 static void InitializePredefinedMacros(const TargetInfo ,
const LangOptions ,
const FrontendOptions ,
@@ -1097,6 +1149,47 @@ static void InitializePredefinedMacros(const TargetInfo 
,
  TI.getTypeWidth(TI.getIntMaxType()) &&
  "uintmax_t and intmax_t have different widths?");
 
+  if (LangOpts.FixedPoint) {
+// Each unsigned type has the same width as their signed type.
+DefineFixedPointMacros(TI, Builder, "SFRACT", "hr", 
TI.getShortFractWidth(),
+   TI.getShortFractScale(), /*Signed=*/true);
+DefineFixedPointMacros(TI, Builder, "USFRACT", "uhr",
+   TI.getShortFractWidth(),
+   TI.getUnsignedShortFractScale(), /*Signed=*/false);
+DefineFixedPointMacros(TI, Builder, "FRACT", "r", TI.getFractWidth(),
+   TI.getFractScale(), /*Signed=*/true);
+DefineFixedPointMacros(TI, Builder, "UFRACT", "ur", TI.getFractWidth(),
+   TI.getUnsignedFractScale(), /*Signed=*/false);
+

[clang] [-Wunsafe-buffer-usage] Fixits for array decayed to pointer (PR #80347)

2024-02-08 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 86cd2fbdfe67d70a7fe061ed5d3a644f50f070f5 
b7471ab0ec3e7d20e971ed61dea727b55c944d5a -- 
clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-array-assign-to-ptr.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-array-inits-ptr.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-array.cpp 
clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
clang/lib/Analysis/UnsafeBufferUsage.cpp 
clang/lib/Sema/AnalysisBasedWarnings.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-access.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 32fae49577..c25ab18e2a 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -776,8 +776,8 @@ private:
 public:
   PtrToPtrAssignmentGadget(const MatchFinder::MatchResult )
   : FixableGadget(Kind::PtrToPtrAssignment),
-PtrLHS(Result.Nodes.getNodeAs(PointerAssignLHSTag)),
-PtrRHS(Result.Nodes.getNodeAs(PointerAssignRHSTag)) {}
+PtrLHS(Result.Nodes.getNodeAs(PointerAssignLHSTag)),
+PtrRHS(Result.Nodes.getNodeAs(PointerAssignRHSTag)) {}
 
   static bool classof(const Gadget *G) {
 return G->getKind() == Kind::PtrToPtrAssignment;
@@ -824,27 +824,28 @@ class CArrayToPtrAssignmentGadget : public FixableGadget {
 private:
   static constexpr const char *const PointerAssignLHSTag = "ptrLHS";
   static constexpr const char *const PointerAssignRHSTag = "ptrRHS";
-  const DeclRefExpr * PtrLHS; // the LHS pointer expression in `PA`
-  const DeclRefExpr * PtrRHS; // the RHS pointer expression in `PA`
+  const DeclRefExpr *PtrLHS; // the LHS pointer expression in `PA`
+  const DeclRefExpr *PtrRHS; // the RHS pointer expression in `PA`
 
 public:
   CArrayToPtrAssignmentGadget(const MatchFinder::MatchResult )
   : FixableGadget(Kind::CArrayToPtrAssignment),
-PtrLHS(Result.Nodes.getNodeAs(PointerAssignLHSTag)),
-PtrRHS(Result.Nodes.getNodeAs(PointerAssignRHSTag)) {}
+PtrLHS(Result.Nodes.getNodeAs(PointerAssignLHSTag)),
+PtrRHS(Result.Nodes.getNodeAs(PointerAssignRHSTag)) {}
 
   static bool classof(const Gadget *G) {
 return G->getKind() == Kind::CArrayToPtrAssignment;
   }
 
   static Matcher matcher() {
-auto PtrAssignExpr = binaryOperator(allOf(hasOperatorName("="),
-  
hasRHS(ignoringParenImpCasts(declRefExpr(hasType(hasCanonicalType(constantArrayType())),
-   toSupportedVariable()).
-   bind(PointerAssignRHSTag))),
-   hasLHS(declRefExpr(hasPointerType(),
-  toSupportedVariable()).
-  bind(PointerAssignLHSTag;
+auto PtrAssignExpr = binaryOperator(
+allOf(hasOperatorName("="),
+  hasRHS(ignoringParenImpCasts(
+  declRefExpr(hasType(hasCanonicalType(constantArrayType())),
+  toSupportedVariable())
+  .bind(PointerAssignRHSTag))),
+  hasLHS(declRefExpr(hasPointerType(), toSupportedVariable())
+ .bind(PointerAssignLHSTag;
 
 return stmt(isInUnspecifiedUntypedContext(PtrAssignExpr));
   }
@@ -1511,7 +1512,8 @@ PtrToPtrAssignmentGadget::getFixits(const FixitStrategy 
) const {
 }
 
 /// \returns fixit that adds .data() call after \DRE.
-static inline std::optional createDataFixit(const ASTContext& Ctx, 
const DeclRefExpr * DRE);
+static inline std::optional createDataFixit(const ASTContext ,
+   const DeclRefExpr *DRE);
 
 std::optional
 CArrayToPtrAssignmentGadget::getFixits(const FixitStrategy ) const {
@@ -1520,27 +1522,30 @@ CArrayToPtrAssignmentGadget::getFixits(const 
FixitStrategy ) const {
   switch (S.lookup(LeftVD)) {
   case FixitStrategy::Kind::Span: {
 switch (S.lookup(RightVD)) {
-  case FixitStrategy::Kind::Array:
-  case FixitStrategy::Kind::Vector:
-  case FixitStrategy::Kind::Wontfix:
-return FixItList{};
-  default: break;
+case FixitStrategy::Kind::Array:
+case FixitStrategy::Kind::Vector:
+case FixitStrategy::Kind::Wontfix:
+  return FixItList{};
+default:
+  break;
 }
 break;
   }
   case FixitStrategy::Kind::Wontfix: {
 switch (S.lookup(RightVD)) {
-  case FixitStrategy::Kind::Wontfix:
-

[clang] Disable FTZ/DAZ when compiling shared libraries by default. (PR #80475)

2024-02-08 Thread Andy Kaylor via cfe-commits

andykaylor wrote:

I just created https://github.com/llvm/llvm-project/issues/81204 to describe 
the linking versus compiling problem.

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


[clang] [clang][fmv] Drop .ifunc from target_version's entrypoint's mangling (PR #81194)

2024-02-08 Thread via cfe-commits


@@ -4393,7 +4394,7 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // a separate resolver).
   std::string ResolverName = MangledName;
   if (getTarget().supportsIFunc()) {
-if (!FD->isTargetClonesMultiVersion())
+if (!FD->isTargetClonesMultiVersion() && 
!FD->isTargetVersionMultiVersion())

elizabethandrews wrote:

I didn't realize there were multiple attributes still using this mangling. A 
switch would make this code better but I'm ok either way. 

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread Farzon Lotfi via cfe-commits


@@ -4518,6 +4518,12 @@ def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void*(unsigned char)";
 }
 
+def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_dot"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "void(...)";

farzonl wrote:

Thats a place holder `clang\lib\Sema\SemaExpr.cpp` has these 
`hasCustomTypechecking` checks  that call `CheckBuiltinFunctionCall` in 
`clang\lib\Sema\SemaChecking.cpp` I want to do custom type checking but that 
piece was dragging the pr and I wanted to get some feedback. Since it isn't 
ready yet so I pulled it from the pr and disabled code gen for the bad cases as 
a stop gap

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


[clang] Disable FTZ/DAZ when compiling shared libraries by default. (PR #80475)

2024-02-08 Thread Andy Kaylor via cfe-commits

andykaylor wrote:

> > I don't see why the current denormal-fp-math setting behavior is a blocking 
> > issue for this change
> 
> Because this PR as-is causes us to start parsing the "-shared" flag for 
> compilation actions in order to determine which denormal-fp-math setting to 
> use. Users should not pass that to compile actions, and if they do, it should 
> result in a `-Wunused-command-line-argument` diagnostic, NOT a behavior 
> change.

We're already parsing -nostartfiles and -nostdlib to determine the default 
setting. I don't see how looking at -shared makes it any worse.

I would agree that this whole model is broken. If I use -ffast-math to create a 
bunch of object files (including the one containing main()) and then I link 
without that option, crtfastmath.o doesn't get linked, even though we used 
"denorm-fp-math"="preserveSign" on every function.

I think we're in agreement that this needs to be fixed for x86-based targets. 
We just need to agree on how to do it. I think 
https://github.com/llvm/llvm-project/issues/57589 is a pretty egregious 
problem, and I'd like to see it fixed without delay, but given that it requires 
setting -ffast-math on your link line maybe it can wait for a proper fix.

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


[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-08 Thread Alexey Bataev via cfe-commits


@@ -0,0 +1,140 @@
+//===- StmtOpenACC.h - Classes for OpenACC directives  --*- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+/// \file
+/// This file defines OpenACC AST classes for statement-level contructs.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_AST_STMTOPENACC_H
+#define LLVM_CLANG_AST_STMTOPENACC_H
+
+#include "clang/AST/Stmt.h"
+#include "clang/Basic/OpenACCKinds.h"
+#include "clang/Basic/SourceLocation.h"
+
+namespace clang {
+/// This is the base class for an OpenACC statement-level construct, other
+/// construct types are expected to inherit from this.
+class OpenACCConstructStmt : public Stmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  /// The directive kind. Each implementation of this interface should handle
+  /// specific kinds.
+  OpenACCDirectiveKind Kind = OpenACCDirectiveKind::Invalid;
+  /// The location of the directive statement, from the '#' to the last token 
of
+  /// the directive.
+  SourceRange Range;
+
+  // TODO OPENACC: Clauses should probably be collected in this class.
+
+protected:
+  OpenACCConstructStmt(StmtClass SC, OpenACCDirectiveKind K,
+   SourceLocation Start, SourceLocation End)
+  : Stmt(SC), Kind(K), Range(Start, End) {}
+
+public:
+  OpenACCDirectiveKind getDirectiveKind() const { return Kind; }
+
+  static bool classof(const Stmt *S) {
+return S->getStmtClass() >= firstOpenACCConstructStmtConstant &&
+   S->getStmtClass() <= lastOpenACCConstructStmtConstant;
+  }
+
+  SourceLocation getBeginLoc() const { return Range.getBegin(); }
+  SourceLocation getEndLoc() const { return Range.getEnd(); }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+
+/// This is a base class for any OpenACC statement-level constructs that have 
an
+/// associated statement. This class is not intended to be instantiated, but is
+/// a convenient place to hold the associated statement.
+class OpenACCAssociatedStmtConstruct : public OpenACCConstructStmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  template  friend class RecursiveASTVisitor;
+  Stmt *AssociatedStmt = nullptr;
+
+protected:
+  OpenACCAssociatedStmtConstruct(StmtClass SC, OpenACCDirectiveKind K,
+ SourceLocation Start, SourceLocation End)
+  : OpenACCConstructStmt(SC, K, Start, End) {}
+
+  void setAssociatedStmt(Stmt *S) { AssociatedStmt = S; }
+  Stmt *getAssociatedStmt() { return AssociatedStmt; }
+  const Stmt *getAssociatedStmt() const {
+return const_cast(this)
+->getAssociatedStmt();
+  }
+
+public:
+  child_range children() {
+if (getAssociatedStmt())
+  return child_range(,  + 1);
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+/// This class represents a compute construct, representing a 'Kind' of
+/// `parallel', 'serial', or 'kernel'. These constructs are associated with a
+/// 'structured block', defined as:
+///
+///  in C or C++, an executable statement, possibly compound, with a single
+///  entry at the top and a single exit at the bottom
+///
+/// At the moment there is no real motivation to have a different AST node for
+/// those three, as they are semantically identical, and have only minor
+/// differences in the permitted list of clauses, which can be differentiated 
by
+/// the 'Kind'.
+class OpenACCComputeConstruct : public OpenACCAssociatedStmtConstruct {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  OpenACCComputeConstruct()
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
+   OpenACCDirectiveKind::Invalid,
+   SourceLocation{}, SourceLocation{}) {}
+
+  OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start,
+  SourceLocation End)
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass, K, Start,
+   End) {
+assert((K == OpenACCDirectiveKind::Parallel ||
+K == OpenACCDirectiveKind::Serial ||
+K == OpenACCDirectiveKind::Kernels) &&
+   "Only parallel, serial, and kernels constructs should be "
+   "represented by this type");
+  }
+
+public:
+  static bool classof(const Stmt *T) {
+return T->getStmtClass() == OpenACCComputeConstructClass;
+  }
+
+  static OpenACCComputeConstruct *CreateEmpty(const ASTContext , 

[clang] [llvm] [LinkerWrapper] Allow 'all' as a generic bundled architecture (PR #81193)

2024-02-08 Thread Joseph Huber via cfe-commits

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


[clang] 42230e2 - [LinkerWrapper] Allow 'all' as a generic bundled architecture (#81193)

2024-02-08 Thread via cfe-commits

Author: Joseph Huber
Date: 2024-02-08T17:17:21-06:00
New Revision: 42230e213e11a0cf9cdbdcd49225eb0d325ef007

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

LOG: [LinkerWrapper] Allow 'all' as a generic bundled architecture (#81193)

Summary:
Currently, the linker wrapper sorts input files into different link
jobs according to their architectures. Here we assume each architecture
is a unique and incompatible link job unless they are specifically
marked compatible. This patch simply adds an `all` target to represent
an architecture that should be linked against every single other
architecture.

This will be useful for modelling generic IR such as the ROCm device
libraries or the NVPTX libdevice.

Added: 


Modified: 
clang/test/Driver/linker-wrapper.c
llvm/lib/Object/OffloadBinary.cpp

Removed: 




diff  --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index 010001b83d7c2d..647629a5969bdc 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -172,6 +172,22 @@ __attribute__((visibility("protected"), used)) int x;
 // AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx90a:xnack+ -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o
 // AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx90a:xnack- -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o
 
+// RUN: clang-offload-packager -o %t-lib.out \
+// RUN:   --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=all
+// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o 
-fembed-offload-object=%t-lib.out
+// RUN: llvm-ar rcs %t.a %t.o
+// RUN: clang-offload-packager -o %t1.out \
+// RUN:   
--image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx90a
+// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t1.o 
-fembed-offload-object=%t1.out
+// RUN: clang-offload-packager -o %t2.out \
+// RUN:   
--image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908
+// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t2.o 
-fembed-offload-object=%t2.out
+// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
+// RUN:   --linker-path=/usr/bin/ld -- %t1.o %t2.o %t.a -o a.out 2>&1 | 
FileCheck %s --check-prefix=ARCH-ALL
+
+// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 
-O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o
+// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a 
-O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o
+
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu \
 // RUN:   --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu

diff  --git a/llvm/lib/Object/OffloadBinary.cpp 
b/llvm/lib/Object/OffloadBinary.cpp
index 22d604b125c583..58b9b39e0d2721 100644
--- a/llvm/lib/Object/OffloadBinary.cpp
+++ b/llvm/lib/Object/OffloadBinary.cpp
@@ -355,6 +355,10 @@ bool object::areTargetsCompatible(const 
OffloadFile::TargetID ,
   if (LHS.first != RHS.first)
 return false;
 
+  // If the architecture is "all" we assume it is always compatible.
+  if (LHS.second.equals("all") || RHS.second.equals("all"))
+return true;
+
   // Only The AMDGPU target requires additional checks.
   llvm::Triple T(LHS.first);
   if (!T.isAMDGPU())



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


[clang] [clang][fmv] Drop .ifunc from target_version's entrypoint's mangling (PR #81194)

2024-02-08 Thread Jon Roelofs via cfe-commits


@@ -4393,7 +4394,7 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // a separate resolver).
   std::string ResolverName = MangledName;
   if (getTarget().supportsIFunc()) {
-if (!FD->isTargetClonesMultiVersion())
+if (!FD->isTargetClonesMultiVersion() && 
!FD->isTargetVersionMultiVersion())

jroelofs wrote:

`target` and the two cpu-specific ones. I'll change it to a switch.

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


[clang] [clang][fmv] Drop .ifunc from target_version's entrypoint's mangling (PR #81194)

2024-02-08 Thread via cfe-commits


@@ -4393,7 +4394,7 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // a separate resolver).
   std::string ResolverName = MangledName;
   if (getTarget().supportsIFunc()) {
-if (!FD->isTargetClonesMultiVersion())
+if (!FD->isTargetClonesMultiVersion() && 
!FD->isTargetVersionMultiVersion())

elizabethandrews wrote:

What attributes use this mangling now? Does it make sense changing this guard 
to do this mangling only for those attributes instead? As in `if (FD->isXYZ)` 

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


[clang] Disable FTZ/DAZ when compiling shared libraries by default. (PR #80475)

2024-02-08 Thread Andy Kaylor via cfe-commits

andykaylor wrote:

> > I'd like to see this change land, but with the "-mdaz-ftz" option removed 
> > (because I don't think it's useful). That would fix the critical problem of 
> > fast-math infecting shared libraries with the ftz setting, and we could 
> > straighten out the other problems, which are relatively minor, afterwards.
> 
> There is, without this change, no way to control whether or not 
> `crtfastmath.o` is linked independent of all of the other fast-math options. 
> The `-mdaz-ftz` option would at least add a flag to explicitly control the 
> parameter (for the people who care), and we can then have discussions about 
> different ways to effect setting DAZ/FTZ bits or what options imply 
> `-mdaz-ftz` in future PRs. That alone makes it a worthy addition IMHO; the 
> compatibility with gcc is another nice feature.

You can always link crtfastmath.o directly, of course. Ultimately, I don't 
think the compiler should ever be adding the crtfastmath.o file. I would prefer 
to insert code directly into the entry function as @arsenm indicated the AMDGPU 
backend does for kernels. That would then be controlled by the 
-fdenormal-fp-math option or something more explicitly linked to the entry 
function.

I don't want to add -mdaz-ftz because once we do we're kind of stuck with it. 
If you don't add it here, we'd continue the current behavior of linking with 
crtfastmath.o normally but we'd stop infecting shared libraries with it.

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


[clang] [Clang] CGCoroutine: Skip moving parameters if the allocation decision is false (PR #81195)

2024-02-08 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/81195

>From fe55a632883d801a4688d787323be243d031df5b Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Wed, 7 Feb 2024 16:05:42 -0800
Subject: [PATCH] Skip moving parameters if the allocation decision is false

---
 clang/lib/CodeGen/CGCoroutine.cpp| 120 ++-
 clang/test/CodeGenCoroutines/coro-gro.cpp|   6 +-
 clang/test/CodeGenCoroutines/coro-params.cpp |  48 +---
 3 files changed, 130 insertions(+), 44 deletions(-)

diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 888d30bfb3e1d6..b2933650367c12 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -389,25 +389,12 @@ namespace {
 ParamReferenceReplacerRAII(CodeGenFunction::DeclMapTy )
 : LocalDeclMap(LocalDeclMap) {}
 
-void addCopy(DeclStmt const *PM) {
-  // Figure out what param it refers to.
-
-  assert(PM->isSingleDecl());
-  VarDecl const*VD = static_cast(PM->getSingleDecl());
-  Expr const *InitExpr = VD->getInit();
-  GetParamRef Visitor;
-  Visitor.Visit(const_cast(InitExpr));
-  assert(Visitor.Expr);
-  DeclRefExpr *DREOrig = Visitor.Expr;
-  auto *PD = DREOrig->getDecl();
-
-  auto it = LocalDeclMap.find(PD);
-  assert(it != LocalDeclMap.end() && "parameter is not found");
-  SavedLocals.insert({ PD, it->second });
-
-  auto copyIt = LocalDeclMap.find(VD);
-  assert(copyIt != LocalDeclMap.end() && "parameter copy is not found");
-  it->second = copyIt->getSecond();
+void substAddress(ValueDecl *D, Address Addr) {
+  auto it = LocalDeclMap.find(D);
+  assert(it != LocalDeclMap.end() && "original decl is not found");
+  SavedLocals.insert({D, it->second});
+
+  it->second = Addr;
 }
 
 ~ParamReferenceReplacerRAII() {
@@ -629,6 +616,63 @@ struct GetReturnObjectManager {
 Builder.CreateStore(Builder.getTrue(), GroActiveFlag);
   }
 };
+
+static ValueDecl *getOriginalParamDeclForParamMove(VarDecl const *VD) {
+  Expr const *InitExpr = VD->getInit();
+  GetParamRef Visitor;
+  Visitor.Visit(const_cast(InitExpr));
+  assert(Visitor.Expr);
+  return Visitor.Expr->getDecl();
+}
+
+struct ParamMoveManager {
+  ParamMoveManager(CodeGenFunction ,
+   llvm::ArrayRef ParamMoves)
+  : CGF(CGF), ParamMovesVarDecls() {
+ParamMovesVarDecls.reserve(ParamMoves.size());
+for (auto *S : ParamMoves) {
+  auto *PMStmt = cast(S);
+  assert(PMStmt->isSingleDecl());
+  auto *ParamMoveVD = static_cast(PMStmt->getSingleDecl());
+  ParamMovesVarDecls.push_back(ParamMoveVD);
+}
+  }
+
+  // Because we wrap param moves in the coro.alloc block. It's not always
+  // necessary to run the corresponding cleanups in the branches.
+  // We would need to know when to (conditionally) clean them up.
+  void EmitMovesWithCleanup(Address PMCleanupActiveFlag) {
+// Create parameter copies. We do it before creating a promise, since an
+// evolution of coroutine TS may allow promise constructor to observe
+// parameter copies.
+for (auto *VD : ParamMovesVarDecls) {
+  auto Emission = CGF.EmitAutoVarAlloca(*VD);
+  CGF.EmitAutoVarInit(Emission);
+  auto OldTop = CGF.EHStack.stable_begin();
+  CGF.EmitAutoVarCleanups(Emission);
+  auto Top = CGF.EHStack.stable_begin();
+
+  for (auto I = CGF.EHStack.find(Top), E = CGF.EHStack.find(OldTop); I != 
E;
+   I++) {
+if (auto *Cleanup = dyn_cast(&*I)) {
+  assert(!Cleanup->hasActiveFlag() &&
+ "cleanup already has active flag?");
+  Cleanup->setActiveFlag(PMCleanupActiveFlag);
+  Cleanup->setTestFlagInEHCleanup();
+  Cleanup->setTestFlagInNormalCleanup();
+}
+  }
+}
+  }
+
+  llvm::ArrayRef GetParamMovesVarDecls() {
+return ParamMovesVarDecls;
+  }
+
+private:
+  CodeGenFunction 
+  SmallVector ParamMovesVarDecls;
+};
 } // namespace
 
 static void emitBodyAndFallthrough(CodeGenFunction ,
@@ -648,6 +692,8 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt ) {
   auto *EntryBB = Builder.GetInsertBlock();
   auto *AllocBB = createBasicBlock("coro.alloc");
   auto *InitBB = createBasicBlock("coro.init");
+  auto *ParamMoveBB = createBasicBlock("coro.param.move");
+  auto *AfterParamMoveBB = createBasicBlock("coro.after.param.move");
   auto *FinalBB = createBasicBlock("coro.final");
   auto *RetBB = createBasicBlock("coro.ret");
 
@@ -664,6 +710,9 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt ) {
   auto *CoroAlloc = Builder.CreateCall(
   CGM.getIntrinsic(llvm::Intrinsic::coro_alloc), {CoroId});
 
+  auto PMCleanupActiveFlag = CreateTempAlloca(
+  Builder.getInt1Ty(), CharUnits::One(), "param.move.cleanup.active");
+  Builder.CreateStore(CoroAlloc, PMCleanupActiveFlag);
   Builder.CreateCondBr(CoroAlloc, AllocBB, InitBB);
 
   

[clang] [llvm] [PGO] Add ability to mark cold functions as optsize/minsize/optnone (PR #69030)

2024-02-08 Thread David Li via cfe-commits

david-xl wrote:

> > Good example. This pass should be run post-inline. @aeubanks, any reason we 
> > want to run it early in the pipeline?
> 
> We want the main function simplification pipeline to see these function 
> attributes because some optimizations trigger or don't trigger depending on 
> the presence of the attributes. Modifying function attributes is typically 
> done in CGSCC/module passes since doing so can affect what callers of those 
> functions see (in effect changing other functions), which shouldn't happen in 
> function passes. I suppose it's possible to add this as a CGSCC pass that 
> runs after inlining and before the function simplification pipeline, but this 
> is more of a one time thing and CGSCC passes can revisit functions. So this 
> pass makes the most sense as a module pass, but we can't insert a module pass 
> between inlining and the function simplification pipeline.
> 
> Can/does the inliner ignore these size attributes when it has call-site 
> profile information?

Looking at the current change, this new pass is actually after the sample 
loader (including sample loader inlining) pass,  so wenlei@'s concern should be 
addressed.

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


[clang] [NFC] Refactor fast-math handling for clang driver (PR #81173)

2024-02-08 Thread Andy Kaylor via cfe-commits

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


[clang] Disable FTZ/DAZ when compiling shared libraries by default. (PR #80475)

2024-02-08 Thread Joshua Cranmer via cfe-commits

jcranmer-intel wrote:

> I'd like to see this change land, but with the "-mdaz-ftz" option removed 
> (because I don't think it's useful). That would fix the critical problem of 
> fast-math infecting shared libraries with the ftz setting, and we could 
> straighten out the other problems, which are relatively minor, afterwards.

There is, without this change, no way to control whether or not `crtfastmath.o` 
is linked independent of all of the other fast-math options. The `-mdaz-ftz` 
option would at least add a flag to explicitly control the parameter (for the 
people who care), and we can then have discussions about different ways to 
effect setting DAZ/FTZ bits or what options imply `-mdaz-ftz` in future PRs. 
That alone makes it a worthy addition IMHO; the compatibility with gcc is 
another nice feature.

> I'm suggesting that we modify Clang so that -ffast-math doesn't affect 
> denormal-fp-math, by (as I mentioned before) removing the overload 
> [Linux::getDefaultDenormalModeForType](https://github.com/llvm/llvm-project/blob/d4c5acac99e83ffa12d2d720c9e502a181cbd7ea/clang/lib/Driver/ToolChains/Linux.cpp#L838).
>  This makes Clang for Linux X86 and X86-64 work the same as every other 
> OS/CPU combo.

That sounds to me ultimately like it should be a separate PR, although you're 
suggesting that should happen first?

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


[clang] [NFC] Refactor fast-math handling for clang driver (PR #81173)

2024-02-08 Thread Andy Kaylor via cfe-commits


@@ -2842,9 +2862,8 @@ static void RenderFloatingPointOptions(const ToolChain 
, const Driver ,
 << Args.MakeArgString("-ffp-model=" + FPModel)
 << Args.MakeArgString("-ffp-model=" + Val);
   if (Val.equals("fast")) {
-optID = options::OPT_ffast_math;
 FPModel = Val;
-FPContract = "fast";
+applyFastMath();

andykaylor wrote:

I just re-read you comment, and I think I see the confusion now. The previous 
code was not easy to follow. We were changing the value of optID here, so when 
we finished with this switch statement execution would continue on to the 
switch statement below where the "whole pile of flags" was being set by the 
OPT_ffast_math handler. Now I'm not changing the value of optID here and 
instead calling the lambda to set the pile of flags. In a future revision I'd 
like to add a parameter to the lambda to indicate that I want slightly less 
aggressive fast math settings.

I started out with a change that chained all the OPT_ffast_math, 
OPT_fno_fast_math, OPT_funsafe_math_optimizations, and 
OPT_fno_unsafe_math_optimizations into a pair of nested lambdas with a 
parameter for positive and negative versions, but that got way too convoluted 
to handle all the variations needed to make it NFC. I think that pointed to 
some things we're doing wrong, but I'll address those separately to keep the 
history clean. This seemed like a manageable place to start.

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


[clang] [clang][fmv] Drop .ifunc from target_version's entrypoint's mangling (PR #81194)

2024-02-08 Thread Jon Roelofs via cfe-commits

https://github.com/jroelofs updated 
https://github.com/llvm/llvm-project/pull/81194

>From 92aef5a078583f69cede47374e2b97de865c5c5d Mon Sep 17 00:00:00 2001
From: Jon Roelofs 
Date: Thu, 8 Feb 2024 13:56:50 -0800
Subject: [PATCH 1/3] [clang][fmv] Drop .ifunc from target_version's
 entrypoint's mangling

Fixes: https://github.com/llvm/llvm-project/issues/81043
---
 clang/include/clang/AST/Decl.h|   4 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/CodeGen/CodeGenModule.cpp   |   4 +-
 clang/test/CodeGen/attr-target-version.c  | 129 +-
 clang/test/CodeGenCXX/attr-target-version.cpp |  87 ++--
 5 files changed, 123 insertions(+), 105 deletions(-)

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index f26fb5ad5f1331..42fdf2b56dc278 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2619,6 +2619,10 @@ class FunctionDecl : public DeclaratorDecl,
   /// the target-clones functionality.
   bool isTargetClonesMultiVersion() const;
 
+  /// True if this function is a multiversioned dispatch function as a part of
+  /// the target-version functionality.
+  bool isTargetVersionMultiVersion() const;
+
   /// \brief Get the associated-constraints of this function declaration.
   /// Currently, this will either be a vector of size 1 containing the
   /// trailing-requires-clause or an empty vector.
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 26fdfa040796ed..40e2903265bf3c 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3541,6 +3541,10 @@ bool FunctionDecl::isTargetClonesMultiVersion() const {
   return isMultiVersion() && hasAttr();
 }
 
+bool FunctionDecl::isTargetVersionMultiVersion() const {
+  return isMultiVersion() && hasAttr();
+}
+
 void
 FunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) {
   redeclarable_base::setPreviousDecl(PrevDecl);
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 36b63d78b06f83..364553e2a6f0f7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4212,7 +4212,7 @@ void CodeGenModule::emitMultiVersionFunctions() {
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
-  if (FD->isTargetClonesMultiVersion()) {
+  if (FD->isTargetClonesMultiVersion() || 
FD->isTargetVersionMultiVersion()) {
 const CGFunctionInfo  = getTypes().arrangeGlobalDeclaration(GD);
 llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
@@ -4393,7 +4393,7 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // a separate resolver).
   std::string ResolverName = MangledName;
   if (getTarget().supportsIFunc()) {
-if (!FD->isTargetClonesMultiVersion())
+if (!FD->isTargetClonesMultiVersion() && 
!FD->isTargetVersionMultiVersion())
   ResolverName += ".ifunc";
   } else if (FD->isTargetMultiVersion()) {
 ResolverName += ".resolver";
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 2a96697e4291b9..c27d48f3ecf681 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -90,13 +90,20 @@ int hoo(void) {
 
 //.
 // CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
-// CHECK: @fmv.ifunc = weak_odr ifunc i32 (), ptr @fmv.resolver
-// CHECK: @fmv_one.ifunc = weak_odr ifunc i32 (), ptr @fmv_one.resolver
-// CHECK: @fmv_two.ifunc = weak_odr ifunc i32 (), ptr @fmv_two.resolver
-// CHECK: @fmv_e.ifunc = weak_odr ifunc i32 (), ptr @fmv_e.resolver
-// CHECK: @fmv_c.ifunc = weak_odr ifunc void (), ptr @fmv_c.resolver
-// CHECK: @fmv_inline.ifunc = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
-// CHECK: @fmv_d.ifunc = internal ifunc i32 (), ptr @fmv_d.resolver
+// CHECK: @fmv.ifunc = weak_odr alias i32 (), ptr @fmv
+// CHECK: @fmv_one.ifunc = weak_odr alias i32 (), ptr @fmv_one
+// CHECK: @fmv_two.ifunc = weak_odr alias i32 (), ptr @fmv_two
+// CHECK: @fmv_e.ifunc = weak_odr alias i32 (), ptr @fmv_e
+// CHECK: @fmv_inline.ifunc = weak_odr alias i32 (), ptr @fmv_inline
+// CHECK: @fmv_d.ifunc = internal alias i32 (), ptr @fmv_d
+// CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
+// CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
+// CHECK: @fmv_one = weak_odr ifunc i32 (), ptr @fmv_one.resolver
+// CHECK: @fmv_two = weak_odr ifunc i32 (), ptr @fmv_two.resolver
+// CHECK: @fmv_e = weak_odr ifunc i32 (), ptr @fmv_e.resolver
+// CHECK: @fmv_inline = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
+// CHECK: @fmv_d = internal ifunc i32 (), ptr @fmv_d.resolver
+// CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 //.
 // CHECK: Function Attrs: noinline nounwind optnone
 

[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread David Peixotto via cfe-commits


@@ -144,6 +144,92 @@ double3 cos(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
 double4 cos(double4);
 
+//===--===//
+// dot product builtins
+//===--===//
+#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half, half);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half2, half2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half3, half3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half4, half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t, int16_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t2, int16_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t3, int16_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t4, int16_t4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t, uint16_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t2, uint16_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t3, uint16_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t4, uint16_t4);
+#endif
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float, float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float2, float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float3, float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float4, float4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double, double);

dmpots wrote:

But dxc does actually accept the double overload for the scalar case only. It 
generates a double multiply in the scalar case so there is no problem with the 
non-existent double overload of the dxil op.

In the vector case it generates a validation error because it tries to use the 
double overload of the dot dxil op.

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread David Peixotto via cfe-commits


@@ -144,6 +144,92 @@ double3 cos(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
 double4 cos(double4);
 
+//===--===//
+// dot product builtins
+//===--===//
+#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half, half);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half2, half2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half3, half3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half4, half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t, int16_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t2, int16_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t3, int16_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t4, int16_t4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t, uint16_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t2, uint16_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t3, uint16_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t4, uint16_t4);
+#endif
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float, float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float2, float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float3, float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float4, float4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double, double);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double2, double2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double3, double3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double4, double4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int dot(int, int);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int dot(int2, int2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int dot(int3, int3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int dot(int4, int4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint dot(uint, uint);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint dot(uint2, uint2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint dot(uint3, uint3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint dot(uint4, uint4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int64_t dot(int64_t, int64_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int64_t dot(int64_t2, int64_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int64_t dot(int64_t3, int64_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int64_t dot(int64_t4, int64_t4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint64_t dot(uint64_t, uint64_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint64_t dot(uint64_t2, uint64_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint64_t dot(uint64_t3, uint64_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint64_t dot(uint64_t4, uint64_t4);

dmpots wrote:

It looks like dxc accepts the 64-bit overload and generates a dxil op

https://godbolt.org/z/8Gf6xExhc

` %IMad = call i64 @dx.op.tertiary.i64(i32 48, i64 %14, i64 %9, i64 %16)`

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread Chris B via cfe-commits


@@ -144,6 +144,92 @@ double3 cos(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
 double4 cos(double4);
 
+//===--===//
+// dot product builtins
+//===--===//
+#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half, half);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half2, half2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half3, half3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half4, half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t, int16_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t2, int16_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t3, int16_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t4, int16_t4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t, uint16_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t2, uint16_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t3, uint16_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t4, uint16_t4);
+#endif
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float, float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float2, float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float3, float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float4, float4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double, double);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double2, double2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double3, double3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double4, double4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int dot(int, int);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int dot(int2, int2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int dot(int3, int3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int dot(int4, int4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint dot(uint, uint);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint dot(uint2, uint2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint dot(uint3, uint3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint dot(uint4, uint4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int64_t dot(int64_t, int64_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int64_t dot(int64_t2, int64_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int64_t dot(int64_t3, int64_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int64_t dot(int64_t4, int64_t4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint64_t dot(uint64_t, uint64_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint64_t dot(uint64_t2, uint64_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint64_t dot(uint64_t3, uint64_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint64_t dot(uint64_t4, uint64_t4);

llvm-beanz wrote:

Same as with double, we shouldn't have 64-bit integer types here since DXIL 
doesn't support them.

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread Chris B via cfe-commits


@@ -144,6 +144,92 @@ double3 cos(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
 double4 cos(double4);
 
+//===--===//
+// dot product builtins
+//===--===//
+#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half, half);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half2, half2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half3, half3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half4, half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t, int16_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t2, int16_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t3, int16_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t4, int16_t4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t, uint16_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t2, uint16_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t3, uint16_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t4, uint16_t4);
+#endif
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float, float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float2, float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float3, float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float4, float4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double, double);

llvm-beanz wrote:

I think we should remove the double overloads. Since the DXIL op is only half 
and float, we should only surface half and float variants. That allows us to 
correctly warn on implicit conversion rather than having the conversion happen 
magically during code generation.

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread Chris B via cfe-commits


@@ -4518,6 +4518,12 @@ def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void*(unsigned char)";
 }
 
+def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_dot"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];

llvm-beanz wrote:

We should add type checking for this builtin in SemaChecking.cpp so that the 
builtin can't be directly called with invalid argument types.

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread Chris B via cfe-commits


@@ -19,4 +19,9 @@ def int_dx_flattened_thread_id_in_group : 
Intrinsic<[llvm_i32_ty], [], [IntrNoMe
 
 def int_dx_create_handle : ClangBuiltin<"__builtin_hlsl_create_handle">,
 Intrinsic<[ llvm_ptr_ty ], [llvm_i8_ty], [IntrWillReturn]>;
-}
+
+def int_dx_dot : 
+Intrinsic<[LLVMVectorElementType<0>], 
+[llvm_anyvector_ty, LLVMScalarOrSameVectorWidth<0, 
LLVMVectorElementType<0>>],
+[IntrNoMem, IntrWillReturn, Commutative] >;
+}

llvm-beanz wrote:

Be sure to set your editor to add a newline to the end of files.

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread Chris B via cfe-commits


@@ -17895,6 +17898,52 @@ llvm::Value 
*CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned ICEArguments,
   return Arg;
 }
 
+Value *CodeGenFunction::EmitDXILBuiltinExpr(unsigned BuiltinID,
+const CallExpr *E) {
+  switch (BuiltinID) {
+  case Builtin::BI__builtin_hlsl_dot: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+Value *Op1 = EmitScalarExpr(E->getArg(1));
+llvm::Type *T0 = Op0->getType();
+llvm::Type *T1 = Op1->getType();
+if (!T0->isVectorTy() && !T1->isVectorTy()) {
+  if (T0->isFloatingPointTy()) {
+return Builder.CreateFMul(Op0, Op1, "dx.dot");
+  }
+
+  if (T0->isIntegerTy()) {
+return Builder.CreateMul(Op0, Op1, "dx.dot");
+  }
+  ErrorUnsupported(
+  E,
+  "Dot product on a scalar is only supported on integers and floats.");
+}
+
+if (T0->isVectorTy() && T1->isVectorTy()) {
+
+  if (T0->getScalarType() != T1->getScalarType()) {
+ErrorUnsupported(E,

llvm-beanz wrote:

We should also catch this in SemaChecking and not need an error here.

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread Chris B via cfe-commits


@@ -19,4 +19,9 @@ def int_dx_flattened_thread_id_in_group : 
Intrinsic<[llvm_i32_ty], [], [IntrNoMe
 
 def int_dx_create_handle : ClangBuiltin<"__builtin_hlsl_create_handle">,
 Intrinsic<[ llvm_ptr_ty ], [llvm_i8_ty], [IntrWillReturn]>;
-}
+
+def int_dx_dot : 
+Intrinsic<[LLVMVectorElementType<0>], 
+[llvm_anyvector_ty, LLVMScalarOrSameVectorWidth<0, 
LLVMVectorElementType<0>>],
+[IntrNoMem, IntrWillReturn, Commutative] >;

llvm-beanz wrote:

This intrinsic should probably only support 16 and 32-bit types because those 
are the only types we can map to DXIL.

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread Chris B via cfe-commits


@@ -17895,6 +17898,52 @@ llvm::Value 
*CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned ICEArguments,
   return Arg;
 }
 
+Value *CodeGenFunction::EmitDXILBuiltinExpr(unsigned BuiltinID,
+const CallExpr *E) {
+  switch (BuiltinID) {
+  case Builtin::BI__builtin_hlsl_dot: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+Value *Op1 = EmitScalarExpr(E->getArg(1));
+llvm::Type *T0 = Op0->getType();
+llvm::Type *T1 = Op1->getType();
+if (!T0->isVectorTy() && !T1->isVectorTy()) {
+  if (T0->isFloatingPointTy()) {
+return Builder.CreateFMul(Op0, Op1, "dx.dot");
+  }
+
+  if (T0->isIntegerTy()) {
+return Builder.CreateMul(Op0, Op1, "dx.dot");
+  }
+  ErrorUnsupported(

llvm-beanz wrote:

If we have checking in SemaChecking for this, this error should be unreachable 
so it could be an assert instead.

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread Chris B via cfe-commits

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread Chris B via cfe-commits

https://github.com/llvm-beanz commented:

Super excited to see this coming along.

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


[clang] Consider aggregate bases when checking if an InitListExpr is constant (PR #80519)

2024-02-08 Thread Reid Kleckner via cfe-commits

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


[clang] [Clang] CGCoroutine: Skip moving parameters if the allocation decision is false (PR #81195)

2024-02-08 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/81195

>From c976747972ffb2e38874eb1f572d110479b109fc Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Wed, 7 Feb 2024 16:05:42 -0800
Subject: [PATCH] Skip moving parameters if the allocation decision is false

---
 clang/lib/CodeGen/CGCoroutine.cpp| 120 ++-
 clang/test/CodeGenCoroutines/coro-gro.cpp|   6 +-
 clang/test/CodeGenCoroutines/coro-params.cpp |  49 +---
 3 files changed, 131 insertions(+), 44 deletions(-)

diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 888d30bfb3e1d..b2933650367c1 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -389,25 +389,12 @@ namespace {
 ParamReferenceReplacerRAII(CodeGenFunction::DeclMapTy )
 : LocalDeclMap(LocalDeclMap) {}
 
-void addCopy(DeclStmt const *PM) {
-  // Figure out what param it refers to.
-
-  assert(PM->isSingleDecl());
-  VarDecl const*VD = static_cast(PM->getSingleDecl());
-  Expr const *InitExpr = VD->getInit();
-  GetParamRef Visitor;
-  Visitor.Visit(const_cast(InitExpr));
-  assert(Visitor.Expr);
-  DeclRefExpr *DREOrig = Visitor.Expr;
-  auto *PD = DREOrig->getDecl();
-
-  auto it = LocalDeclMap.find(PD);
-  assert(it != LocalDeclMap.end() && "parameter is not found");
-  SavedLocals.insert({ PD, it->second });
-
-  auto copyIt = LocalDeclMap.find(VD);
-  assert(copyIt != LocalDeclMap.end() && "parameter copy is not found");
-  it->second = copyIt->getSecond();
+void substAddress(ValueDecl *D, Address Addr) {
+  auto it = LocalDeclMap.find(D);
+  assert(it != LocalDeclMap.end() && "original decl is not found");
+  SavedLocals.insert({D, it->second});
+
+  it->second = Addr;
 }
 
 ~ParamReferenceReplacerRAII() {
@@ -629,6 +616,63 @@ struct GetReturnObjectManager {
 Builder.CreateStore(Builder.getTrue(), GroActiveFlag);
   }
 };
+
+static ValueDecl *getOriginalParamDeclForParamMove(VarDecl const *VD) {
+  Expr const *InitExpr = VD->getInit();
+  GetParamRef Visitor;
+  Visitor.Visit(const_cast(InitExpr));
+  assert(Visitor.Expr);
+  return Visitor.Expr->getDecl();
+}
+
+struct ParamMoveManager {
+  ParamMoveManager(CodeGenFunction ,
+   llvm::ArrayRef ParamMoves)
+  : CGF(CGF), ParamMovesVarDecls() {
+ParamMovesVarDecls.reserve(ParamMoves.size());
+for (auto *S : ParamMoves) {
+  auto *PMStmt = cast(S);
+  assert(PMStmt->isSingleDecl());
+  auto *ParamMoveVD = static_cast(PMStmt->getSingleDecl());
+  ParamMovesVarDecls.push_back(ParamMoveVD);
+}
+  }
+
+  // Because we wrap param moves in the coro.alloc block. It's not always
+  // necessary to run the corresponding cleanups in the branches.
+  // We would need to know when to (conditionally) clean them up.
+  void EmitMovesWithCleanup(Address PMCleanupActiveFlag) {
+// Create parameter copies. We do it before creating a promise, since an
+// evolution of coroutine TS may allow promise constructor to observe
+// parameter copies.
+for (auto *VD : ParamMovesVarDecls) {
+  auto Emission = CGF.EmitAutoVarAlloca(*VD);
+  CGF.EmitAutoVarInit(Emission);
+  auto OldTop = CGF.EHStack.stable_begin();
+  CGF.EmitAutoVarCleanups(Emission);
+  auto Top = CGF.EHStack.stable_begin();
+
+  for (auto I = CGF.EHStack.find(Top), E = CGF.EHStack.find(OldTop); I != 
E;
+   I++) {
+if (auto *Cleanup = dyn_cast(&*I)) {
+  assert(!Cleanup->hasActiveFlag() &&
+ "cleanup already has active flag?");
+  Cleanup->setActiveFlag(PMCleanupActiveFlag);
+  Cleanup->setTestFlagInEHCleanup();
+  Cleanup->setTestFlagInNormalCleanup();
+}
+  }
+}
+  }
+
+  llvm::ArrayRef GetParamMovesVarDecls() {
+return ParamMovesVarDecls;
+  }
+
+private:
+  CodeGenFunction 
+  SmallVector ParamMovesVarDecls;
+};
 } // namespace
 
 static void emitBodyAndFallthrough(CodeGenFunction ,
@@ -648,6 +692,8 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt ) {
   auto *EntryBB = Builder.GetInsertBlock();
   auto *AllocBB = createBasicBlock("coro.alloc");
   auto *InitBB = createBasicBlock("coro.init");
+  auto *ParamMoveBB = createBasicBlock("coro.param.move");
+  auto *AfterParamMoveBB = createBasicBlock("coro.after.param.move");
   auto *FinalBB = createBasicBlock("coro.final");
   auto *RetBB = createBasicBlock("coro.ret");
 
@@ -664,6 +710,9 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt ) {
   auto *CoroAlloc = Builder.CreateCall(
   CGM.getIntrinsic(llvm::Intrinsic::coro_alloc), {CoroId});
 
+  auto PMCleanupActiveFlag = CreateTempAlloca(
+  Builder.getInt1Ty(), CharUnits::One(), "param.move.cleanup.active");
+  Builder.CreateStore(CoroAlloc, PMCleanupActiveFlag);
   Builder.CreateCondBr(CoroAlloc, AllocBB, InitBB);
 
   

[clang] [clang][fmv] Drop .ifunc from target_version's entrypoint's mangling (PR #81194)

2024-02-08 Thread Jon Roelofs via cfe-commits

https://github.com/jroelofs updated 
https://github.com/llvm/llvm-project/pull/81194

>From 92aef5a078583f69cede47374e2b97de865c5c5d Mon Sep 17 00:00:00 2001
From: Jon Roelofs 
Date: Thu, 8 Feb 2024 13:56:50 -0800
Subject: [PATCH 1/2] [clang][fmv] Drop .ifunc from target_version's
 entrypoint's mangling

Fixes: https://github.com/llvm/llvm-project/issues/81043
---
 clang/include/clang/AST/Decl.h|   4 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/CodeGen/CodeGenModule.cpp   |   4 +-
 clang/test/CodeGen/attr-target-version.c  | 129 +-
 clang/test/CodeGenCXX/attr-target-version.cpp |  87 ++--
 5 files changed, 123 insertions(+), 105 deletions(-)

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index f26fb5ad5f1331..42fdf2b56dc278 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2619,6 +2619,10 @@ class FunctionDecl : public DeclaratorDecl,
   /// the target-clones functionality.
   bool isTargetClonesMultiVersion() const;
 
+  /// True if this function is a multiversioned dispatch function as a part of
+  /// the target-version functionality.
+  bool isTargetVersionMultiVersion() const;
+
   /// \brief Get the associated-constraints of this function declaration.
   /// Currently, this will either be a vector of size 1 containing the
   /// trailing-requires-clause or an empty vector.
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 26fdfa040796ed..40e2903265bf3c 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3541,6 +3541,10 @@ bool FunctionDecl::isTargetClonesMultiVersion() const {
   return isMultiVersion() && hasAttr();
 }
 
+bool FunctionDecl::isTargetVersionMultiVersion() const {
+  return isMultiVersion() && hasAttr();
+}
+
 void
 FunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) {
   redeclarable_base::setPreviousDecl(PrevDecl);
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 36b63d78b06f83..364553e2a6f0f7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4212,7 +4212,7 @@ void CodeGenModule::emitMultiVersionFunctions() {
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
-  if (FD->isTargetClonesMultiVersion()) {
+  if (FD->isTargetClonesMultiVersion() || 
FD->isTargetVersionMultiVersion()) {
 const CGFunctionInfo  = getTypes().arrangeGlobalDeclaration(GD);
 llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
@@ -4393,7 +4393,7 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // a separate resolver).
   std::string ResolverName = MangledName;
   if (getTarget().supportsIFunc()) {
-if (!FD->isTargetClonesMultiVersion())
+if (!FD->isTargetClonesMultiVersion() && 
!FD->isTargetVersionMultiVersion())
   ResolverName += ".ifunc";
   } else if (FD->isTargetMultiVersion()) {
 ResolverName += ".resolver";
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 2a96697e4291b9..c27d48f3ecf681 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -90,13 +90,20 @@ int hoo(void) {
 
 //.
 // CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
-// CHECK: @fmv.ifunc = weak_odr ifunc i32 (), ptr @fmv.resolver
-// CHECK: @fmv_one.ifunc = weak_odr ifunc i32 (), ptr @fmv_one.resolver
-// CHECK: @fmv_two.ifunc = weak_odr ifunc i32 (), ptr @fmv_two.resolver
-// CHECK: @fmv_e.ifunc = weak_odr ifunc i32 (), ptr @fmv_e.resolver
-// CHECK: @fmv_c.ifunc = weak_odr ifunc void (), ptr @fmv_c.resolver
-// CHECK: @fmv_inline.ifunc = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
-// CHECK: @fmv_d.ifunc = internal ifunc i32 (), ptr @fmv_d.resolver
+// CHECK: @fmv.ifunc = weak_odr alias i32 (), ptr @fmv
+// CHECK: @fmv_one.ifunc = weak_odr alias i32 (), ptr @fmv_one
+// CHECK: @fmv_two.ifunc = weak_odr alias i32 (), ptr @fmv_two
+// CHECK: @fmv_e.ifunc = weak_odr alias i32 (), ptr @fmv_e
+// CHECK: @fmv_inline.ifunc = weak_odr alias i32 (), ptr @fmv_inline
+// CHECK: @fmv_d.ifunc = internal alias i32 (), ptr @fmv_d
+// CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
+// CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
+// CHECK: @fmv_one = weak_odr ifunc i32 (), ptr @fmv_one.resolver
+// CHECK: @fmv_two = weak_odr ifunc i32 (), ptr @fmv_two.resolver
+// CHECK: @fmv_e = weak_odr ifunc i32 (), ptr @fmv_e.resolver
+// CHECK: @fmv_inline = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
+// CHECK: @fmv_d = internal ifunc i32 (), ptr @fmv_d.resolver
+// CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 //.
 // CHECK: Function Attrs: noinline nounwind optnone
 

[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread David Peixotto via cfe-commits

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread Xiang Li via cfe-commits

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread Xiang Li via cfe-commits

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


[clang] Consider aggregate bases when checking if an InitListExpr is constant (PR #80519)

2024-02-08 Thread Reid Kleckner via cfe-commits

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread Xiang Li via cfe-commits


@@ -4518,6 +4518,12 @@ def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void*(unsigned char)";
 }
 
+def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_dot"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "void(...)";

python3kgae wrote:

The return type should not be void.

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


[clang] Consider aggregate bases when checking if an InitListExpr is constant (PR #80519)

2024-02-08 Thread Reid Kleckner via cfe-commits

https://github.com/rnk commented:

Thanks! I added notes.

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


[clang] [Clang] CGCoroutine: Skip moving parameters if the allocation decision is false (PR #81195)

2024-02-08 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 created 
https://github.com/llvm/llvm-project/pull/81195

There's a 
[comment](https://github.com/llvm/llvm-project/blob/0572dabb71147fdc156d90a3ecd036d1652c2006/clang/lib/CodeGen/CGCoroutine.cpp#L728-L730)
 left in the coroutine codegen that reads
```
TODO: if(CoroParam(...)) need to surround ctor and dtor for the copy, so that 
llvm can elide it if the copy is not needed.
```
Reading from this it appears to me that we can just generate a check around the 
parameter moves and the corresponding cleanups with the boolean 
`@llvm.coro.alloc` gives us. 

>From 6099b56f3477f3e82dd98086db52f181b12ce0d3 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Wed, 7 Feb 2024 16:05:42 -0800
Subject: [PATCH] Skip moving parameters if the allocation decision is false

---
 clang/lib/CodeGen/CGCoroutine.cpp| 117 ++-
 clang/test/CodeGenCoroutines/coro-gro.cpp|   6 +-
 clang/test/CodeGenCoroutines/coro-params.cpp |  49 +---
 3 files changed, 128 insertions(+), 44 deletions(-)

diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 888d30bfb3e1d6..fdcd498a2cd981 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -389,25 +389,12 @@ namespace {
 ParamReferenceReplacerRAII(CodeGenFunction::DeclMapTy )
 : LocalDeclMap(LocalDeclMap) {}
 
-void addCopy(DeclStmt const *PM) {
-  // Figure out what param it refers to.
-
-  assert(PM->isSingleDecl());
-  VarDecl const*VD = static_cast(PM->getSingleDecl());
-  Expr const *InitExpr = VD->getInit();
-  GetParamRef Visitor;
-  Visitor.Visit(const_cast(InitExpr));
-  assert(Visitor.Expr);
-  DeclRefExpr *DREOrig = Visitor.Expr;
-  auto *PD = DREOrig->getDecl();
-
-  auto it = LocalDeclMap.find(PD);
-  assert(it != LocalDeclMap.end() && "parameter is not found");
-  SavedLocals.insert({ PD, it->second });
-
-  auto copyIt = LocalDeclMap.find(VD);
-  assert(copyIt != LocalDeclMap.end() && "parameter copy is not found");
-  it->second = copyIt->getSecond();
+void substAddress(ValueDecl *D, Address Addr) {
+  auto it = LocalDeclMap.find(D);
+  assert(it != LocalDeclMap.end() && "original decl is not found");
+  SavedLocals.insert({D, it->second});
+
+  it->second = Addr;
 }
 
 ~ParamReferenceReplacerRAII() {
@@ -629,6 +616,60 @@ struct GetReturnObjectManager {
 Builder.CreateStore(Builder.getTrue(), GroActiveFlag);
   }
 };
+
+static ValueDecl *getOriginalParamDeclForParamMove(VarDecl const *VD) {
+  Expr const *InitExpr = VD->getInit();
+  GetParamRef Visitor;
+  Visitor.Visit(const_cast(InitExpr));
+  assert(Visitor.Expr);
+  return Visitor.Expr->getDecl();
+}
+
+struct ParamMoveManager {
+  ParamMoveManager(CodeGenFunction ,
+   llvm::ArrayRef ParamMoves)
+  : CGF(CGF), ParamMovesVarDecls() {
+ParamMovesVarDecls.reserve(ParamMoves.size());
+for (auto *S : ParamMoves) {
+  auto *PMStmt = cast(S);
+  assert(PMStmt->isSingleDecl());
+  auto *ParamMoveVD = static_cast(PMStmt->getSingleDecl());
+  ParamMovesVarDecls.push_back(ParamMoveVD);
+}
+  }
+
+  void EmitMovesWithCleanup(Address PMCleanupActiveFlag) {
+// Create parameter copies. We do it before creating a promise, since an
+// evolution of coroutine TS may allow promise constructor to observe
+// parameter copies.
+for (auto *VD : ParamMovesVarDecls) {
+  auto Emission = CGF.EmitAutoVarAlloca(*VD);
+  CGF.EmitAutoVarInit(Emission);
+  auto OldTop = CGF.EHStack.stable_begin();
+  CGF.EmitAutoVarCleanups(Emission);
+  auto Top = CGF.EHStack.stable_begin();
+
+  for (auto I = CGF.EHStack.find(Top), E = CGF.EHStack.find(OldTop); I != 
E;
+   I++) {
+if (auto *Cleanup = dyn_cast(&*I)) {
+  assert(!Cleanup->hasActiveFlag() &&
+ "cleanup already has active flag?");
+  Cleanup->setActiveFlag(PMCleanupActiveFlag);
+  Cleanup->setTestFlagInEHCleanup();
+  Cleanup->setTestFlagInNormalCleanup();
+}
+  }
+}
+  }
+
+  llvm::ArrayRef GetParamMovesVarDecls() {
+return ParamMovesVarDecls;
+  }
+
+private:
+  CodeGenFunction 
+  SmallVector ParamMovesVarDecls;
+};
 } // namespace
 
 static void emitBodyAndFallthrough(CodeGenFunction ,
@@ -648,6 +689,8 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt ) {
   auto *EntryBB = Builder.GetInsertBlock();
   auto *AllocBB = createBasicBlock("coro.alloc");
   auto *InitBB = createBasicBlock("coro.init");
+  auto *ParamMoveBB = createBasicBlock("coro.param.move");
+  auto *AfterParamMoveBB = createBasicBlock("coro.after.param.move");
   auto *FinalBB = createBasicBlock("coro.final");
   auto *RetBB = createBasicBlock("coro.ret");
 
@@ -664,6 +707,9 @@ void CodeGenFunction::EmitCoroutineBody(const 
CoroutineBodyStmt ) {
   auto *CoroAlloc = Builder.CreateCall(
   

[clang] [clang][fmv] Drop .ifunc from target_version's entrypoint's mangling (PR #81194)

2024-02-08 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff ff8c865838b46d0202963b816fbed50aaf96a7f4 
92aef5a078583f69cede47374e2b97de865c5c5d -- clang/include/clang/AST/Decl.h 
clang/lib/AST/Decl.cpp clang/lib/CodeGen/CodeGenModule.cpp 
clang/test/CodeGen/attr-target-version.c 
clang/test/CodeGenCXX/attr-target-version.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 364553e2a6..872bd630ca 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4212,7 +4212,8 @@ void CodeGenModule::emitMultiVersionFunctions() {
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
-  if (FD->isTargetClonesMultiVersion() || 
FD->isTargetVersionMultiVersion()) {
+  if (FD->isTargetClonesMultiVersion() ||
+  FD->isTargetVersionMultiVersion()) {
 const CGFunctionInfo  = getTypes().arrangeGlobalDeclaration(GD);
 llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(

``




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


[clang] [clang][fmv] Drop .ifunc from target_version's entrypoint's mangling (PR #81194)

2024-02-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jon Roelofs (jroelofs)


Changes

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

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


5 Files Affected:

- (modified) clang/include/clang/AST/Decl.h (+4) 
- (modified) clang/lib/AST/Decl.cpp (+4) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2-2) 
- (modified) clang/test/CodeGen/attr-target-version.c (+68-61) 
- (modified) clang/test/CodeGenCXX/attr-target-version.cpp (+45-42) 


``diff
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index f26fb5ad5f1331..42fdf2b56dc278 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2619,6 +2619,10 @@ class FunctionDecl : public DeclaratorDecl,
   /// the target-clones functionality.
   bool isTargetClonesMultiVersion() const;
 
+  /// True if this function is a multiversioned dispatch function as a part of
+  /// the target-version functionality.
+  bool isTargetVersionMultiVersion() const;
+
   /// \brief Get the associated-constraints of this function declaration.
   /// Currently, this will either be a vector of size 1 containing the
   /// trailing-requires-clause or an empty vector.
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 26fdfa040796ed..40e2903265bf3c 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3541,6 +3541,10 @@ bool FunctionDecl::isTargetClonesMultiVersion() const {
   return isMultiVersion() && hasAttr();
 }
 
+bool FunctionDecl::isTargetVersionMultiVersion() const {
+  return isMultiVersion() && hasAttr();
+}
+
 void
 FunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) {
   redeclarable_base::setPreviousDecl(PrevDecl);
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 36b63d78b06f83..364553e2a6f0f7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4212,7 +4212,7 @@ void CodeGenModule::emitMultiVersionFunctions() {
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
-  if (FD->isTargetClonesMultiVersion()) {
+  if (FD->isTargetClonesMultiVersion() || 
FD->isTargetVersionMultiVersion()) {
 const CGFunctionInfo  = getTypes().arrangeGlobalDeclaration(GD);
 llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
@@ -4393,7 +4393,7 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // a separate resolver).
   std::string ResolverName = MangledName;
   if (getTarget().supportsIFunc()) {
-if (!FD->isTargetClonesMultiVersion())
+if (!FD->isTargetClonesMultiVersion() && 
!FD->isTargetVersionMultiVersion())
   ResolverName += ".ifunc";
   } else if (FD->isTargetMultiVersion()) {
 ResolverName += ".resolver";
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 2a96697e4291b9..c27d48f3ecf681 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -90,13 +90,20 @@ int hoo(void) {
 
 //.
 // CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
-// CHECK: @fmv.ifunc = weak_odr ifunc i32 (), ptr @fmv.resolver
-// CHECK: @fmv_one.ifunc = weak_odr ifunc i32 (), ptr @fmv_one.resolver
-// CHECK: @fmv_two.ifunc = weak_odr ifunc i32 (), ptr @fmv_two.resolver
-// CHECK: @fmv_e.ifunc = weak_odr ifunc i32 (), ptr @fmv_e.resolver
-// CHECK: @fmv_c.ifunc = weak_odr ifunc void (), ptr @fmv_c.resolver
-// CHECK: @fmv_inline.ifunc = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
-// CHECK: @fmv_d.ifunc = internal ifunc i32 (), ptr @fmv_d.resolver
+// CHECK: @fmv.ifunc = weak_odr alias i32 (), ptr @fmv
+// CHECK: @fmv_one.ifunc = weak_odr alias i32 (), ptr @fmv_one
+// CHECK: @fmv_two.ifunc = weak_odr alias i32 (), ptr @fmv_two
+// CHECK: @fmv_e.ifunc = weak_odr alias i32 (), ptr @fmv_e
+// CHECK: @fmv_inline.ifunc = weak_odr alias i32 (), ptr @fmv_inline
+// CHECK: @fmv_d.ifunc = internal alias i32 (), ptr @fmv_d
+// CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
+// CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
+// CHECK: @fmv_one = weak_odr ifunc i32 (), ptr @fmv_one.resolver
+// CHECK: @fmv_two = weak_odr ifunc i32 (), ptr @fmv_two.resolver
+// CHECK: @fmv_e = weak_odr ifunc i32 (), ptr @fmv_e.resolver
+// CHECK: @fmv_inline = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
+// CHECK: @fmv_d = internal ifunc i32 (), ptr @fmv_d.resolver
+// CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 //.
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@fmv._MrngMflagmMfp16fml
@@ -105,6 +112,32 @@ int hoo(void) {
 // CHECK-NEXT:ret i32 1
 //
 //
+// CHECK: Function Attrs: noinline nounwind optnone
+// 

[clang] [clang][fmv] Drop .ifunc from target_version's entrypoint's mangling (PR #81194)

2024-02-08 Thread Jon Roelofs via cfe-commits

https://github.com/jroelofs created 
https://github.com/llvm/llvm-project/pull/81194

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

>From 92aef5a078583f69cede47374e2b97de865c5c5d Mon Sep 17 00:00:00 2001
From: Jon Roelofs 
Date: Thu, 8 Feb 2024 13:56:50 -0800
Subject: [PATCH] [clang][fmv] Drop .ifunc from target_version's entrypoint's
 mangling

Fixes: https://github.com/llvm/llvm-project/issues/81043
---
 clang/include/clang/AST/Decl.h|   4 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/CodeGen/CodeGenModule.cpp   |   4 +-
 clang/test/CodeGen/attr-target-version.c  | 129 +-
 clang/test/CodeGenCXX/attr-target-version.cpp |  87 ++--
 5 files changed, 123 insertions(+), 105 deletions(-)

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index f26fb5ad5f133..42fdf2b56dc27 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2619,6 +2619,10 @@ class FunctionDecl : public DeclaratorDecl,
   /// the target-clones functionality.
   bool isTargetClonesMultiVersion() const;
 
+  /// True if this function is a multiversioned dispatch function as a part of
+  /// the target-version functionality.
+  bool isTargetVersionMultiVersion() const;
+
   /// \brief Get the associated-constraints of this function declaration.
   /// Currently, this will either be a vector of size 1 containing the
   /// trailing-requires-clause or an empty vector.
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 26fdfa040796e..40e2903265bf3 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3541,6 +3541,10 @@ bool FunctionDecl::isTargetClonesMultiVersion() const {
   return isMultiVersion() && hasAttr();
 }
 
+bool FunctionDecl::isTargetVersionMultiVersion() const {
+  return isMultiVersion() && hasAttr();
+}
+
 void
 FunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) {
   redeclarable_base::setPreviousDecl(PrevDecl);
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 36b63d78b06f8..364553e2a6f0f 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4212,7 +4212,7 @@ void CodeGenModule::emitMultiVersionFunctions() {
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
-  if (FD->isTargetClonesMultiVersion()) {
+  if (FD->isTargetClonesMultiVersion() || 
FD->isTargetVersionMultiVersion()) {
 const CGFunctionInfo  = getTypes().arrangeGlobalDeclaration(GD);
 llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
@@ -4393,7 +4393,7 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   // a separate resolver).
   std::string ResolverName = MangledName;
   if (getTarget().supportsIFunc()) {
-if (!FD->isTargetClonesMultiVersion())
+if (!FD->isTargetClonesMultiVersion() && 
!FD->isTargetVersionMultiVersion())
   ResolverName += ".ifunc";
   } else if (FD->isTargetMultiVersion()) {
 ResolverName += ".resolver";
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 2a96697e4291b..c27d48f3ecf68 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -90,13 +90,20 @@ int hoo(void) {
 
 //.
 // CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
-// CHECK: @fmv.ifunc = weak_odr ifunc i32 (), ptr @fmv.resolver
-// CHECK: @fmv_one.ifunc = weak_odr ifunc i32 (), ptr @fmv_one.resolver
-// CHECK: @fmv_two.ifunc = weak_odr ifunc i32 (), ptr @fmv_two.resolver
-// CHECK: @fmv_e.ifunc = weak_odr ifunc i32 (), ptr @fmv_e.resolver
-// CHECK: @fmv_c.ifunc = weak_odr ifunc void (), ptr @fmv_c.resolver
-// CHECK: @fmv_inline.ifunc = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
-// CHECK: @fmv_d.ifunc = internal ifunc i32 (), ptr @fmv_d.resolver
+// CHECK: @fmv.ifunc = weak_odr alias i32 (), ptr @fmv
+// CHECK: @fmv_one.ifunc = weak_odr alias i32 (), ptr @fmv_one
+// CHECK: @fmv_two.ifunc = weak_odr alias i32 (), ptr @fmv_two
+// CHECK: @fmv_e.ifunc = weak_odr alias i32 (), ptr @fmv_e
+// CHECK: @fmv_inline.ifunc = weak_odr alias i32 (), ptr @fmv_inline
+// CHECK: @fmv_d.ifunc = internal alias i32 (), ptr @fmv_d
+// CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
+// CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
+// CHECK: @fmv_one = weak_odr ifunc i32 (), ptr @fmv_one.resolver
+// CHECK: @fmv_two = weak_odr ifunc i32 (), ptr @fmv_two.resolver
+// CHECK: @fmv_e = weak_odr ifunc i32 (), ptr @fmv_e.resolver
+// CHECK: @fmv_inline = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
+// CHECK: @fmv_d = internal ifunc i32 (), ptr @fmv_d.resolver
+// CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 //.
 // 

[clang] [clang][sema] Fix -Wunused-function on target_version'd file-scope Fn's (PR #81167)

2024-02-08 Thread Argyrios Kyrtzidis via cfe-commits

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


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


[clang] [llvm] [LinkerWrapper] Allow 'all' as a generic bundled architecture (PR #81193)

2024-02-08 Thread Artem Belevich via cfe-commits

https://github.com/Artem-B approved this pull request.


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


[clang] [llvm] [LinkerWrapper] Allow 'all' as a generic bundled architecture (PR #81193)

2024-02-08 Thread Artem Belevich via cfe-commits

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


[clang] [llvm] [RFC][AMDGPU] Use `bf16` instead of `i16` for bfloat (PR #80908)

2024-02-08 Thread Shilei Tian via cfe-commits


@@ -4181,13 +4181,20 @@ bool SIInstrInfo::isInlineConstant(const MachineOperand 
,
   case AMDGPU::OPERAND_REG_INLINE_C_V2INT16:
   case AMDGPU::OPERAND_REG_INLINE_AC_V2INT16:
 return AMDGPU::isInlinableLiteralV2I16(Imm);
+  case AMDGPU::OPERAND_REG_IMM_V2BF16:

shiltian wrote:

Yeah, I made some mistakes here. Will take care of them.

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


[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-08 Thread David Peixotto via cfe-commits


@@ -144,6 +144,92 @@ double3 cos(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
 double4 cos(double4);
 
+//===--===//
+// dot product builtins
+//===--===//
+#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half, half);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half2, half2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half3, half3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+half dot(half4, half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t, int16_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t2, int16_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t3, int16_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+int16_t dot(int16_t4, int16_t4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t, uint16_t);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t2, uint16_t2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t3, uint16_t3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+uint16_t dot(uint16_t4, uint16_t4);
+#endif
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float, float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float2, float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float3, float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+float dot(float4, float4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
+double dot(double, double);

dmpots wrote:

I think the double case deserves some discussion about whether this is valid 
hlsl or not. Currently dxc will only accept the `dot(double, double)` overload 
because it happens to lower that to a scalar multiply.

The vector overloads are not supported because there is no double overload of 
the final dxil `dot` intrinsic.


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


  1   2   3   4   5   >