[libc] [flang] [llvm] [libcxx] [clang] [compiler-rt] [clang-tools-extra] [libc++] Implement LWG3940: std::expected::value() also needs E to be copy constructible (PR #71819)

2024-01-05 Thread via cfe-commits

PragmaTwice wrote:

The CI finally passed now : )

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


[libc] [flang] [llvm] [libcxx] [clang] [compiler-rt] [clang-tools-extra] [libc++] Implement LWG3940: std::expected::value() also needs E to be copy constructible (PR #71819)

2024-01-05 Thread via cfe-commits


@@ -0,0 +1,49 @@
+//===--===//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// constexpr void value() const &;
+// Mandates: is_copy_constructible_v is true.
+
+// constexpr void value() &&;
+// Mandates: is_copy_constructible_v is true and is_move_constructible_v 
is true.
+
+#include 
+
+#include "MoveOnly.h"
+
+struct CopyOnly {
+  CopyOnly()= default;
+  CopyOnly(const CopyOnly&) = default;
+  CopyOnly(CopyOnly&&)  = delete;
+};
+
+void test() {
+  // MoveOnly type as error_type
+  std::expected e(std::unexpect, 5);
+
+  e.value(); // expected-note {{in instantiation of member function 
'std::expected::value' requested here}}
+  // expected-error@*:* {{static assertion failed due to requirement 
'is_copy_constructible_v'}}
+
+  std::move(e)
+  .value(); // expected-note {{in instantiation of member function 
'std::expected::value' requested here}}
+  // expected-error@*:* {{static assertion failed due to requirement 
'is_copy_constructible_v': error_type has to be both copy 
constructible and move constructible}}
+
+  // CopyOnly type as error_type
+  std::expected e2(std::unexpect);
+
+  e2.value();
+
+  std::move(e2)
+  .value(); // expected-note {{in instantiation of member function 
'std::expected::value' requested here}}
+  // expected-error@*:* {{static assertion failed due to requirement 
'is_move_constructible_v': error_type has to be both copy 
constructible and move constructible}}
+
+  // expected-error@*:* {{call to deleted constructor of 'MoveOnly'}}
+  // expected-error@*:* {{call to deleted constructor of 'CopyOnly'}}
+  // expected-error@*:* {{call to deleted constructor of 'CopyOnly'}}

PragmaTwice wrote:

Fixed : )

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


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

2024-01-05 Thread Gedare Bloom via cfe-commits

gedare wrote:

> > @owenca this waits for re-review
> 
> Can you rebase the patch?

done

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


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

2024-01-05 Thread Gedare Bloom via cfe-commits

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

>From 65e3a69e30810683ba76d9a233a9c408fd121120 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Thu, 9 Nov 2023 09:30:24 -0700
Subject: [PATCH 1/7] Revert "Revert "[clang-format] Fix align consecutive
 declarations over function pointers""

This reverts commit 7bc1031c474ebb2216a5432273dafe4d1490fbce.
---
 clang/lib/Format/WhitespaceManager.cpp |  2 +-
 clang/unittests/Format/FormatTest.cpp  | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 3bc6915b8df0a7..4bf4699756f77d 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -979,7 +979,7 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
   AlignTokens(
   Style,
   [](Change const ) {
-if (C.Tok->is(TT_FunctionDeclarationName))
+if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen))
   return true;
 if (C.Tok->isNot(TT_StartOfName))
   return false;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 881993ede17c3d..5eef94332e21dd 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2050,6 +2050,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"const unsigned int *d;\n"
"Const unsigned int \n"
"const unsigned int \n"
+   "int*f1(int *a, int , int &);\n"
+   "double *(*f2)(int *a, double &);\n"
"const unsigned&\n"
"Const unsigned  h;",
Style);
@@ -2095,6 +2097,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"const unsigned int* d;\n"
"Const unsigned int& e;\n"
"const unsigned int& f;\n"
+   "int*f1(int* a, int& b, int&& c);\n"
+   "double* (*f2)(int* a, double&& b);\n"
"const unsigned&&g;\n"
"Const unsigned  h;",
Style);
@@ -2120,6 +2124,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"const unsigned int *d;\n"
"Const unsigned int& e;\n"
"const unsigned int& f;\n"
+   "int*f1(int *a, int& b, int&& c);\n"
+   "double *(*f2)(int *a, double&& b);\n"
"const unsigned  g;\n"
"Const unsigned  h;",
Style);
@@ -2160,6 +2166,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"const unsigned int*  d;\n"
"Const unsigned int & e;\n"
"const unsigned int & f;\n"
+   "int* f1(int* a, int & b, int && c);\n"
+   "double*  (*f2)(int* a, double && b);\n"
"const unsigned &&g;\n"
"Const unsigned   h;",
Style);
@@ -2185,6 +2193,8 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"const unsigned int * d;\n"
"Const unsigned int  \n"
"const unsigned int  \n"
+   "int *f1(int * a, int , int &);\n"
+   "double * (*f2)(int * a, double &);\n"
"const unsigned &\n"
"Const unsigned   h;",
Style);

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

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

Fixes #68079.
---
 clang/lib/Format/WhitespaceManager.cpp | 3 +++
 clang/unittests/Format/FormatTest.cpp  | 9 +
 2 files changed, 12 insertions(+)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 4bf4699756f77d..d210d4cfb0c6a6 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -979,6 +979,9 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
   AlignTokens(
   Style,
   [](Change const ) {
+for 

[clang] [Driver] Add the --gcc-triple option (PR #73214)

2024-01-05 Thread Fangrui Song via cfe-commits

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

Looks great!

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


[clang] [compiler-rt] [clang-tools-extra] [libcxx] [flang] [llvm] [libc] [libc++] Implement LWG3940: std::expected::value() also needs E to be copy constructible (PR #71819)

2024-01-05 Thread via cfe-commits

https://github.com/PragmaTwice updated 
https://github.com/llvm/llvm-project/pull/71819

>From 3e4b73d2aeac411a83dda5cd63eb0572499db467 Mon Sep 17 00:00:00 2001
From: PragmaTwice 
Date: Fri, 10 Nov 2023 00:50:24 +0900
Subject: [PATCH 1/8] [libc++] Implement LWG3940 (std::expected::value() also needs E to be copy constructible)

---
 libcxx/docs/Status/Cxx2cIssues.csv|  2 +-
 libcxx/include/__expected/expected.h  |  3 +++
 .../observers/value.lwg3940.compile.fail.cpp  | 27 +++
 .../expected.void/observers/value.pass.cpp| 11 
 4 files changed, 31 insertions(+), 12 deletions(-)
 create mode 100644 
libcxx/test/std/utilities/expected/expected.void/observers/value.lwg3940.compile.fail.cpp

diff --git a/libcxx/docs/Status/Cxx2cIssues.csv 
b/libcxx/docs/Status/Cxx2cIssues.csv
index a928b69ea10c48..099a19d02888f4 100644
--- a/libcxx/docs/Status/Cxx2cIssues.csv
+++ b/libcxx/docs/Status/Cxx2cIssues.csv
@@ -15,7 +15,7 @@
 "`3927 `__","Unclear preconditions for 
``operator[]`` for sequence containers","Varna June 2023","|Nothing To 
Do|","",""
 "`3935 `__","``template constexpr complex& 
operator=(const complex&)`` has no specification","Varna June 
2023","|Complete|","3.4",""
 "`3938 `__","Cannot use ``std::expected`` monadic 
ops with move-only ``error_type``","Varna June 2023","|Complete|","18.0",""
-"`3940 `__","``std::expected::value()`` 
also needs ``E`` to be copy constructible","Varna June 2023","","",""
+"`3940 `__","``std::expected::value()`` 
also needs ``E`` to be copy constructible","Varna June 
2023","|Complete|","18.0",""
 "","","","","",""
 "`3343 `__","Ordering of calls to ``unlock()`` and 
``notify_all()`` in Effects element of ``notify_all_at_thread_exit()`` should 
be reversed","Not Yet Adopted","|Complete|","16.0",""
 "`3892 `__","Incorrect formatting of nested ranges 
and tuples","Not Yet Adopted","|Complete|","17.0","|format|"
diff --git a/libcxx/include/__expected/expected.h 
b/libcxx/include/__expected/expected.h
index bf16c8f720d268..c6441f1651b085 100644
--- a/libcxx/include/__expected/expected.h
+++ b/libcxx/include/__expected/expected.h
@@ -1187,12 +1187,15 @@ class expected<_Tp, _Err> {
   }
 
   _LIBCPP_HIDE_FROM_ABI constexpr void value() const& {
+static_assert(is_copy_constructible_v<_Err>, "error_type has to be copy 
constructible");
 if (!__has_val_) {
   std::__throw_bad_expected_access<_Err>(__union_.__unex_);
 }
   }
 
   _LIBCPP_HIDE_FROM_ABI constexpr void value() && {
+static_assert(is_copy_constructible_v<_Err> && 
is_move_constructible_v<_Err>,
+  "error_type has to be both copy constructible and move 
constructible");
 if (!__has_val_) {
   std::__throw_bad_expected_access<_Err>(std::move(__union_.__unex_));
 }
diff --git 
a/libcxx/test/std/utilities/expected/expected.void/observers/value.lwg3940.compile.fail.cpp
 
b/libcxx/test/std/utilities/expected/expected.void/observers/value.lwg3940.compile.fail.cpp
new file mode 100644
index 00..37c06e629e9443
--- /dev/null
+++ 
b/libcxx/test/std/utilities/expected/expected.void/observers/value.lwg3940.compile.fail.cpp
@@ -0,0 +1,27 @@
+//===--===//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// constexpr void value() &&;
+// Mandates: is_copy_constructible_v is true and is_move_constructible_v 
is true.
+
+#include 
+
+#include "MoveOnly.h"
+
+void test() {
+  // MoveOnly
+  std::expected e(std::unexpect, 5);
+
+  // COMPILE FAIL: MoveOnly is not copy constructible
+  std::move(e).value();
+}
+
+int main(int, char**) {
+  test();
+}
diff --git 
a/libcxx/test/std/utilities/expected/expected.void/observers/value.pass.cpp 
b/libcxx/test/std/utilities/expected/expected.void/observers/value.pass.cpp
index 0f02db19c7b75e..a24d67c57e19b5 100644
--- a/libcxx/test/std/utilities/expected/expected.void/observers/value.pass.cpp
+++ b/libcxx/test/std/utilities/expected/expected.void/observers/value.pass.cpp
@@ -65,17 +65,6 @@ void testException() {
 }
   }
 
-  // MoveOnly
-  {
-std::expected e(std::unexpect, 5);
-try {
-  std::move(e).value();
-  assert(false);
-} catch (const std::bad_expected_access& ex) {
-  assert(ex.error() == 5);
-}
-  }
-
 #endif // TEST_HAS_NO_EXCEPTIONS
 }
 

>From 2d1c43fa98b3a97f31509e98c3abdd7fe8f62626 Mon Sep 17 00:00:00 2001
From: PragmaTwice 
Date: Fri, 10 Nov 2023 19:29:30 +0900
Subject: [PATCH 2/8] [libcxx] format test


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-05 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

This should have a release note and I think this is a potentially breaking 
change since folks using `Wextra` may get this diagnostic now.

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-05 Thread Abhin P Jose via cfe-commits

https://github.com/Abhinkop updated 
https://github.com/llvm/llvm-project/pull/77178

>From d147292312ea05eb6b4a28940faffe54093c900e Mon Sep 17 00:00:00 2001
From: Abhin Parekadan Jose 
Date: Sat, 6 Jan 2024 05:09:36 +0100
Subject: [PATCH] [clang] move -Wcast-function-type under -Wextra

---
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../Sema/warn-cast-function-type-strict.c |  2 +-
 clang/test/Sema/warn-cast-function-type.c |  1 +
 .../warn-extra-cast-function-type-strict.c| 42 +++
 .../warn-cast-function-type-strict.cpp|  1 +
 .../test/SemaCXX/warn-cast-function-type.cpp  |  1 +
 6 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/warn-extra-cast-function-type-strict.c

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..d3e57de8ac7a58 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1026,6 +1026,7 @@ def Extra : DiagGroup<"extra", [
 EmptyInitStatement,
 StringConcatation,
 FUseLdPath,
+CastFunctionType,
   ]>;
 
 def Most : DiagGroup<"most", [
diff --git a/clang/test/Sema/warn-cast-function-type-strict.c 
b/clang/test/Sema/warn-cast-function-type-strict.c
index 5233680796e972..68b49bb0d05d06 100644
--- a/clang/test/Sema/warn-cast-function-type-strict.c
+++ b/clang/test/Sema/warn-cast-function-type-strict.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type-strict -verify
-
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-ignored-qualifiers -verify
 
 int t(int array[static 12]);
 int u(int i);
diff --git a/clang/test/Sema/warn-cast-function-type.c 
b/clang/test/Sema/warn-cast-function-type.c
index d7ddcdb73725c0..09d169026b1c86 100644
--- a/clang/test/Sema/warn-cast-function-type.c
+++ b/clang/test/Sema/warn-cast-function-type.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type 
-Wno-cast-function-type-strict -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-cast-function-type-strict 
-verify
 
 int x(long);
 
diff --git a/clang/test/Sema/warn-extra-cast-function-type-strict.c 
b/clang/test/Sema/warn-extra-cast-function-type-strict.c
new file mode 100644
index 00..ef8853616ba832
--- /dev/null
+++ b/clang/test/Sema/warn-extra-cast-function-type-strict.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)();
+typedef void (f4)();
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+typedef int (f8)(int *);
+typedef int (f9)(const int);
+typedef int (f10)(int);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+f8 *h;
+f9 *i;
+f10 *j;
+
+void foo(void) {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
+  c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)()') converts to incompatible function type}} */
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
+  e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 
'void (*)(void)') converts to incompatible function type}} */
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 
'int (*)(long, int)') converts to incompatible function type}} */
+  g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 
'int (*)(long, ...)') converts to incompatible function type}} */
+  h = (f8 *)t;
+  i = (f9 *)u;
+  j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 
*' (aka 'int (*)(int)') converts to incompatible function type}} */
+}
diff --git a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp 
b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
index f7ee55f84ac280..b3164afde5a0ca 100644
--- a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type-strict 
-verify
+// RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wextra -verify
 
 int x(long);
 
diff --git a/clang/test/SemaCXX/warn-cast-function-type.cpp 
b/clang/test/SemaCXX/warn-cast-function-type.cpp
index c613aaea1e33f2..db2ee030fcbfc9 100644
--- a/clang/test/SemaCXX/warn-cast-function-type.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only 

[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-05 Thread Abhin P Jose via cfe-commits

Abhinkop wrote:

@nickdesaulniers 

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Abhin P Jose (Abhinkop)


Changes

This patch is for github issue 
https://github.com/llvm/llvm-project/issues/76872. 

The -Wcast-fuction-type-strict has been moved under dignstic group -Wextra.
Edited the test cases for -Wcast-fuction-type-strict and -Wcast-fuction-type in 
Sema an SemaCXX.

Added a new test case which include a functionality that was already in the 
-Wextra group, i.e -Wignored-qualifiers with -Wcast-fuction-type-strict.


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


6 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+1) 
- (modified) clang/test/Sema/warn-cast-function-type-strict.c (+1-1) 
- (modified) clang/test/Sema/warn-cast-function-type.c (+1) 
- (added) clang/test/Sema/warn-extra-cast-function-type-strict.c (+42) 
- (modified) clang/test/SemaCXX/warn-cast-function-type-strict.cpp (+1) 
- (modified) clang/test/SemaCXX/warn-cast-function-type.cpp (+1) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..d3e57de8ac7a58 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1026,6 +1026,7 @@ def Extra : DiagGroup<"extra", [
 EmptyInitStatement,
 StringConcatation,
 FUseLdPath,
+CastFunctionType,
   ]>;
 
 def Most : DiagGroup<"most", [
diff --git a/clang/test/Sema/warn-cast-function-type-strict.c 
b/clang/test/Sema/warn-cast-function-type-strict.c
index 5233680796e972..68b49bb0d05d06 100644
--- a/clang/test/Sema/warn-cast-function-type-strict.c
+++ b/clang/test/Sema/warn-cast-function-type-strict.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type-strict -verify
-
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-ignored-qualifiers -verify
 
 int t(int array[static 12]);
 int u(int i);
diff --git a/clang/test/Sema/warn-cast-function-type.c 
b/clang/test/Sema/warn-cast-function-type.c
index d7ddcdb73725c0..09d169026b1c86 100644
--- a/clang/test/Sema/warn-cast-function-type.c
+++ b/clang/test/Sema/warn-cast-function-type.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type 
-Wno-cast-function-type-strict -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-cast-function-type-strict 
-verify
 
 int x(long);
 
diff --git a/clang/test/Sema/warn-extra-cast-function-type-strict.c 
b/clang/test/Sema/warn-extra-cast-function-type-strict.c
new file mode 100644
index 00..ef8853616ba832
--- /dev/null
+++ b/clang/test/Sema/warn-extra-cast-function-type-strict.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)();
+typedef void (f4)();
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+typedef int (f8)(int *);
+typedef int (f9)(const int);
+typedef int (f10)(int);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+f8 *h;
+f9 *i;
+f10 *j;
+
+void foo(void) {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
+  c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)()') converts to incompatible function type}} */
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
+  e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 
'void (*)(void)') converts to incompatible function type}} */
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 
'int (*)(long, int)') converts to incompatible function type}} */
+  g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 
'int (*)(long, ...)') converts to incompatible function type}} */
+  h = (f8 *)t;
+  i = (f9 *)u;
+  j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 
*' (aka 'int (*)(int)') converts to incompatible function type}} */
+}
diff --git a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp 
b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
index f7ee55f84ac280..b3164afde5a0ca 100644
--- a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type-strict 
-verify
+// RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wextra -verify
 
 int x(long);
 
diff --git a/clang/test/SemaCXX/warn-cast-function-type.cpp 

[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-05 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/77178
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-05 Thread Abhin P Jose via cfe-commits

https://github.com/Abhinkop created 
https://github.com/llvm/llvm-project/pull/77178

This patch is for github issue 
https://github.com/llvm/llvm-project/issues/76872. 

The -Wcast-fuction-type-strict has been moved under dignstic group -Wextra.
Edited the test cases for -Wcast-fuction-type-strict and -Wcast-fuction-type in 
Sema an SemaCXX.

Added a new test case which include a functionality that was already in the 
-Wextra group, i.e -Wignored-qualifiers with -Wcast-fuction-type-strict.


>From adeed20dea0bb8ef6dedfd2df675ee724597355d Mon Sep 17 00:00:00 2001
From: Abhin Parekadan Jose 
Date: Sat, 6 Jan 2024 05:09:36 +0100
Subject: [PATCH] [clang] move -Wcast-function-type under -Wextra

---
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../Sema/warn-cast-function-type-strict.c |  2 +-
 clang/test/Sema/warn-cast-function-type.c |  1 +
 .../warn-extra-cast-function-type-strict.c| 42 +++
 .../warn-cast-function-type-strict.cpp|  1 +
 .../test/SemaCXX/warn-cast-function-type.cpp  |  1 +
 6 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/warn-extra-cast-function-type-strict.c

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..d3e57de8ac7a58 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1026,6 +1026,7 @@ def Extra : DiagGroup<"extra", [
 EmptyInitStatement,
 StringConcatation,
 FUseLdPath,
+CastFunctionType,
   ]>;
 
 def Most : DiagGroup<"most", [
diff --git a/clang/test/Sema/warn-cast-function-type-strict.c 
b/clang/test/Sema/warn-cast-function-type-strict.c
index 5233680796e972..68b49bb0d05d06 100644
--- a/clang/test/Sema/warn-cast-function-type-strict.c
+++ b/clang/test/Sema/warn-cast-function-type-strict.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type-strict -verify
-
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-ignored-qualifiers -verify
 
 int t(int array[static 12]);
 int u(int i);
diff --git a/clang/test/Sema/warn-cast-function-type.c 
b/clang/test/Sema/warn-cast-function-type.c
index d7ddcdb73725c0..09d169026b1c86 100644
--- a/clang/test/Sema/warn-cast-function-type.c
+++ b/clang/test/Sema/warn-cast-function-type.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type 
-Wno-cast-function-type-strict -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -Wno-cast-function-type-strict 
-verify
 
 int x(long);
 
diff --git a/clang/test/Sema/warn-extra-cast-function-type-strict.c 
b/clang/test/Sema/warn-extra-cast-function-type-strict.c
new file mode 100644
index 00..ef8853616ba832
--- /dev/null
+++ b/clang/test/Sema/warn-extra-cast-function-type-strict.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)();
+typedef void (f4)();
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+typedef int (f8)(int *);
+typedef int (f9)(const int);
+typedef int (f10)(int);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+f8 *h;
+f9 *i;
+f10 *j;
+
+void foo(void) {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
+  c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)()') converts to incompatible function type}} */
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
+  e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 
'void (*)(void)') converts to incompatible function type}} */
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 
'int (*)(long, int)') converts to incompatible function type}} */
+  g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 
'int (*)(long, ...)') converts to incompatible function type}} */
+  h = (f8 *)t;
+  i = (f9 *)u;
+  j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 
*' (aka 'int (*)(int)') converts to incompatible function type}} */
+}
diff --git a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp 
b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
index f7ee55f84ac280..b3164afde5a0ca 100644
--- a/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
+++ b/clang/test/SemaCXX/warn-cast-function-type-strict.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type -verify
 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -Wcast-function-type-strict 
-verify
+// 

[clang-tools-extra] [libcxx] [libc] [clang] [mlir] [llvm] [compiler-rt] [flang] [openmp] [libunwind] [X86][ISel] Don't select MOV/ADD64ri32 for tglobaltlsaddr under large code models (PR #77175)

2024-01-05 Thread Nicholas Mosier via cfe-commits

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


[compiler-rt] [libcxx] [mlir] [libc] [flang] [llvm] [clang] [openmp] [clang-tools-extra] [libunwind] [X86][ISel] Don't select MOV/ADD64ri32 for tglobaltlsaddr under large code models (PR #77175)

2024-01-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Nicholas Mosier (nmosier)


Changes

This patch fixes a bug (GitHub issue #77128) that caused the compiler 
to emit 32-bit (rather than 64-bit) relocations for TLS offsets under a 
medium/large code model for x86-64 targets, resulting in link-time errors.

The root cause of the bug is an X86 instruction selection pattern that errantly 
matches tglobaltlsaddr SDNodes to target MOV64ri32/ADD64ri32 SDNodes during the 
Select phase of instruction selection, regardless of the code model.

This patch adds the requirement `Requires[NearData]` to both X86 
selection patterns, ensuring that they only match when the code model is not 
large. It also adds a new test (llvm/test/CodeGen/X86/tls-largecode.ll) to 
ensure the patterns are not matched for medium/large code models.

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


2 Files Affected:

- (modified) llvm/lib/Target/X86/X86InstrCompiler.td (+2-2) 
- (added) llvm/test/CodeGen/X86/tls-codemodels.ll (+36) 


``diff
diff --git a/llvm/lib/Target/X86/X86InstrCompiler.td 
b/llvm/lib/Target/X86/X86InstrCompiler.td
index c77c77ee4a3eeb..67fb593e391d34 100644
--- a/llvm/lib/Target/X86/X86InstrCompiler.td
+++ b/llvm/lib/Target/X86/X86InstrCompiler.td
@@ -1267,10 +1267,10 @@ def : Pat<(i64 (X86RecoverFrameAlloc mcsym:$dst)), 
(MOV64ri mcsym:$dst)>;
 // tls has some funny stuff here...
 // This corresponds to movabs $foo@tpoff, %rax
 def : Pat<(i64 (X86Wrapper tglobaltlsaddr :$dst)),
-  (MOV64ri32 tglobaltlsaddr :$dst)>;
+  (MOV64ri32 tglobaltlsaddr :$dst)>, Requires<[NearData]>;
 // This corresponds to add $foo@tpoff, %rax
 def : Pat<(add GR64:$src1, (X86Wrapper tglobaltlsaddr :$dst)),
-  (ADD64ri32 GR64:$src1, tglobaltlsaddr :$dst)>;
+  (ADD64ri32 GR64:$src1, tglobaltlsaddr :$dst)>, Requires<[NearData]>;
 
 
 // Direct PC relative function call for small code model. 32-bit displacement
diff --git a/llvm/test/CodeGen/X86/tls-codemodels.ll 
b/llvm/test/CodeGen/X86/tls-codemodels.ll
new file mode 100644
index 00..644e07300f3928
--- /dev/null
+++ b/llvm/test/CodeGen/X86/tls-codemodels.ll
@@ -0,0 +1,36 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -code-model=small | 
FileCheck %s --check-prefix=CHECK-SMALL
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -code-model=kernel | 
FileCheck %s --check-prefix=CHECK-KERNEL
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -code-model=medium | 
FileCheck %s --check-prefix=CHECK-MEDIUM
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -code-model=large | 
FileCheck %s --check-prefix=CHECK-LARGE
+
+@x = dso_local thread_local global i32 0, align 4
+
+define dso_local void @test() local_unnamed_addr {
+; CHECK-SMALL-LABEL: test:
+; CHECK-SMALL:   # %bb.0: # %entry
+; CHECK-SMALL-NEXT:movl $0, %fs:x@TPOFF
+; CHECK-SMALL-NEXT:retq
+;
+; CHECK-KERNEL-LABEL: test:
+; CHECK-KERNEL:   # %bb.0: # %entry
+; CHECK-KERNEL-NEXT:movl $0, %fs:x@TPOFF
+; CHECK-KERNEL-NEXT:retq
+;
+; CHECK-MEDIUM-LABEL: test:
+; CHECK-MEDIUM:   # %bb.0: # %entry
+; CHECK-MEDIUM-NEXT:movl $0, %fs:x@TPOFF
+; CHECK-MEDIUM-NEXT:retq
+;
+; CHECK-LARGE-LABEL: test:
+; CHECK-LARGE:   # %bb.0: # %entry
+; CHECK-LARGE-NEXT:movabsq $x@TPOFF, %rax
+; CHECK-LARGE-NEXT:movl $0, %fs:(%rax)
+; CHECK-LARGE-NEXT:retq
+entry:
+  %0 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @x)
+  store i32 0, ptr %0, align 4
+  ret void
+}
+
+declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull)

``




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


[compiler-rt] [libcxx] [mlir] [libc] [flang] [llvm] [clang] [openmp] [clang-tools-extra] [libunwind] [X86][ISel] Don't select MOV/ADD64ri32 for tglobaltlsaddr under large code models (PR #77175)

2024-01-05 Thread Nicholas Mosier via cfe-commits

https://github.com/nmosier updated 
https://github.com/llvm/llvm-project/pull/77175

>From b6351e796868be27075518fb51830bf79c60cdf6 Mon Sep 17 00:00:00 2001
From: Nicholas Mosier 
Date: Sat, 6 Jan 2024 03:36:03 +
Subject: [PATCH] [X86][ISel] Select MOV/ADD64ri32 for tglobaltlsaddr only
 under small code models

This patch fixes a bug (GitHub issue #77128) that caused the compiler
to emit 32-bit (rather than 64-bit) relocations for TLS offsets under a
medium/large code model for x86-64 targets, resulting in link-time errors.

The root cause of the bug is an X86 instruction selection pattern that
errantly matches tglobaltlsaddr SDNodes to target MOV64ri32/ADD64ri32 SDNodes
during the Select phase of instruction selection, regardless of the code
model.

This patch adds the requirement `Requires<[NearData]>` to both X86 selection
patterns, ensuring that they only match when the code model is 
tiny/small/kernel.
It also adds a new test (llvm/test/CodeGen/X86/tls-largecode.ll) to ensure the 
patterns are not matched for medium/large code models.
---
 llvm/lib/Target/X86/X86InstrCompiler.td |  4 +--
 llvm/test/CodeGen/X86/tls-codemodels.ll | 36 +
 2 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/CodeGen/X86/tls-codemodels.ll

diff --git a/llvm/lib/Target/X86/X86InstrCompiler.td 
b/llvm/lib/Target/X86/X86InstrCompiler.td
index c77c77ee4a3eeb..67fb593e391d34 100644
--- a/llvm/lib/Target/X86/X86InstrCompiler.td
+++ b/llvm/lib/Target/X86/X86InstrCompiler.td
@@ -1267,10 +1267,10 @@ def : Pat<(i64 (X86RecoverFrameAlloc mcsym:$dst)), 
(MOV64ri mcsym:$dst)>;
 // tls has some funny stuff here...
 // This corresponds to movabs $foo@tpoff, %rax
 def : Pat<(i64 (X86Wrapper tglobaltlsaddr :$dst)),
-  (MOV64ri32 tglobaltlsaddr :$dst)>;
+  (MOV64ri32 tglobaltlsaddr :$dst)>, Requires<[NearData]>;
 // This corresponds to add $foo@tpoff, %rax
 def : Pat<(add GR64:$src1, (X86Wrapper tglobaltlsaddr :$dst)),
-  (ADD64ri32 GR64:$src1, tglobaltlsaddr :$dst)>;
+  (ADD64ri32 GR64:$src1, tglobaltlsaddr :$dst)>, Requires<[NearData]>;
 
 
 // Direct PC relative function call for small code model. 32-bit displacement
diff --git a/llvm/test/CodeGen/X86/tls-codemodels.ll 
b/llvm/test/CodeGen/X86/tls-codemodels.ll
new file mode 100644
index 00..644e07300f3928
--- /dev/null
+++ b/llvm/test/CodeGen/X86/tls-codemodels.ll
@@ -0,0 +1,36 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -code-model=small | 
FileCheck %s --check-prefix=CHECK-SMALL
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -code-model=kernel | 
FileCheck %s --check-prefix=CHECK-KERNEL
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -code-model=medium | 
FileCheck %s --check-prefix=CHECK-MEDIUM
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -code-model=large | 
FileCheck %s --check-prefix=CHECK-LARGE
+
+@x = dso_local thread_local global i32 0, align 4
+
+define dso_local void @test() local_unnamed_addr {
+; CHECK-SMALL-LABEL: test:
+; CHECK-SMALL:   # %bb.0: # %entry
+; CHECK-SMALL-NEXT:movl $0, %fs:x@TPOFF
+; CHECK-SMALL-NEXT:retq
+;
+; CHECK-KERNEL-LABEL: test:
+; CHECK-KERNEL:   # %bb.0: # %entry
+; CHECK-KERNEL-NEXT:movl $0, %fs:x@TPOFF
+; CHECK-KERNEL-NEXT:retq
+;
+; CHECK-MEDIUM-LABEL: test:
+; CHECK-MEDIUM:   # %bb.0: # %entry
+; CHECK-MEDIUM-NEXT:movl $0, %fs:x@TPOFF
+; CHECK-MEDIUM-NEXT:retq
+;
+; CHECK-LARGE-LABEL: test:
+; CHECK-LARGE:   # %bb.0: # %entry
+; CHECK-LARGE-NEXT:movabsq $x@TPOFF, %rax
+; CHECK-LARGE-NEXT:movl $0, %fs:(%rax)
+; CHECK-LARGE-NEXT:retq
+entry:
+  %0 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @x)
+  store i32 0, ptr %0, align 4
+  ret void
+}
+
+declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull)

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


[clang-tools-extra] [libcxx] [libc] [clang] [mlir] [llvm] [compiler-rt] [flang] [openmp] [libunwind] [X86][ISel] Don't select MOV/ADD64ri32 for tglobaltlsaddr under large code models (PR #77175)

2024-01-05 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/77175
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-05 Thread Owen Pan via cfe-commits

owenca wrote:

> @owenca this waits for re-review

Can you rebase the patch?

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


[clang] [clang][lex] Fix non-portability diagnostics with absolute path (PR #74782)

2024-01-05 Thread Jeremy Wong via cfe-commits

jrmwng wrote:

> @jrmwng PR #76985 (landed in 
> [853b133](https://github.com/llvm/llvm-project/commit/853b13342a131e06d61293ec6e840642054c6c85))
>  seems to have resolved this issue for me. Can you confirm that on your end?

Yes, your fix is effective  

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


[llvm] [libcxx] [clang-tools-extra] [libc++] Implement LWG3940: std::expected::value() also needs E to be copy constructible (PR #71819)

2024-01-05 Thread via cfe-commits


@@ -0,0 +1,49 @@
+//===--===//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// constexpr void value() const &;
+// Mandates: is_copy_constructible_v is true.
+
+// constexpr void value() &&;
+// Mandates: is_copy_constructible_v is true and is_move_constructible_v 
is true.
+
+#include 
+
+#include "MoveOnly.h"
+
+struct CopyOnly {
+  CopyOnly()= default;
+  CopyOnly(const CopyOnly&) = default;
+  CopyOnly(CopyOnly&&)  = delete;
+};
+
+void test() {
+  // MoveOnly type as error_type
+  std::expected e(std::unexpect, 5);
+
+  e.value(); // expected-note {{in instantiation of member function 
'std::expected::value' requested here}}
+  // expected-error@*:* {{static assertion failed due to requirement 
'is_copy_constructible_v'}}
+
+  std::move(e)
+  .value(); // expected-note {{in instantiation of member function 
'std::expected::value' requested here}}
+  // expected-error@*:* {{static assertion failed due to requirement 
'is_copy_constructible_v': error_type has to be both copy 
constructible and move constructible}}
+
+  // CopyOnly type as error_type
+  std::expected e2(std::unexpect);
+
+  e2.value();
+
+  std::move(e2)
+  .value(); // expected-note {{in instantiation of member function 
'std::expected::value' requested here}}
+  // expected-error@*:* {{static assertion failed due to requirement 
'is_move_constructible_v': error_type has to be both copy 
constructible and move constructible}}
+
+  // expected-error@*:* {{call to deleted constructor of 'MoveOnly'}}
+  // expected-error@*:* {{call to deleted constructor of 'CopyOnly'}}
+  // expected-error@*:* {{call to deleted constructor of 'CopyOnly'}}

PragmaTwice wrote:

Ahhh I see. Thank you!

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


[llvm] [libcxx] [clang-tools-extra] [libc++] Implement LWG3940: std::expected::value() also needs E to be copy constructible (PR #71819)

2024-01-05 Thread via cfe-commits

https://github.com/PragmaTwice updated 
https://github.com/llvm/llvm-project/pull/71819

>From 3e4b73d2aeac411a83dda5cd63eb0572499db467 Mon Sep 17 00:00:00 2001
From: PragmaTwice 
Date: Fri, 10 Nov 2023 00:50:24 +0900
Subject: [PATCH 1/8] [libc++] Implement LWG3940 (std::expected::value() also needs E to be copy constructible)

---
 libcxx/docs/Status/Cxx2cIssues.csv|  2 +-
 libcxx/include/__expected/expected.h  |  3 +++
 .../observers/value.lwg3940.compile.fail.cpp  | 27 +++
 .../expected.void/observers/value.pass.cpp| 11 
 4 files changed, 31 insertions(+), 12 deletions(-)
 create mode 100644 
libcxx/test/std/utilities/expected/expected.void/observers/value.lwg3940.compile.fail.cpp

diff --git a/libcxx/docs/Status/Cxx2cIssues.csv 
b/libcxx/docs/Status/Cxx2cIssues.csv
index a928b69ea10c48..099a19d02888f4 100644
--- a/libcxx/docs/Status/Cxx2cIssues.csv
+++ b/libcxx/docs/Status/Cxx2cIssues.csv
@@ -15,7 +15,7 @@
 "`3927 `__","Unclear preconditions for 
``operator[]`` for sequence containers","Varna June 2023","|Nothing To 
Do|","",""
 "`3935 `__","``template constexpr complex& 
operator=(const complex&)`` has no specification","Varna June 
2023","|Complete|","3.4",""
 "`3938 `__","Cannot use ``std::expected`` monadic 
ops with move-only ``error_type``","Varna June 2023","|Complete|","18.0",""
-"`3940 `__","``std::expected::value()`` 
also needs ``E`` to be copy constructible","Varna June 2023","","",""
+"`3940 `__","``std::expected::value()`` 
also needs ``E`` to be copy constructible","Varna June 
2023","|Complete|","18.0",""
 "","","","","",""
 "`3343 `__","Ordering of calls to ``unlock()`` and 
``notify_all()`` in Effects element of ``notify_all_at_thread_exit()`` should 
be reversed","Not Yet Adopted","|Complete|","16.0",""
 "`3892 `__","Incorrect formatting of nested ranges 
and tuples","Not Yet Adopted","|Complete|","17.0","|format|"
diff --git a/libcxx/include/__expected/expected.h 
b/libcxx/include/__expected/expected.h
index bf16c8f720d268..c6441f1651b085 100644
--- a/libcxx/include/__expected/expected.h
+++ b/libcxx/include/__expected/expected.h
@@ -1187,12 +1187,15 @@ class expected<_Tp, _Err> {
   }
 
   _LIBCPP_HIDE_FROM_ABI constexpr void value() const& {
+static_assert(is_copy_constructible_v<_Err>, "error_type has to be copy 
constructible");
 if (!__has_val_) {
   std::__throw_bad_expected_access<_Err>(__union_.__unex_);
 }
   }
 
   _LIBCPP_HIDE_FROM_ABI constexpr void value() && {
+static_assert(is_copy_constructible_v<_Err> && 
is_move_constructible_v<_Err>,
+  "error_type has to be both copy constructible and move 
constructible");
 if (!__has_val_) {
   std::__throw_bad_expected_access<_Err>(std::move(__union_.__unex_));
 }
diff --git 
a/libcxx/test/std/utilities/expected/expected.void/observers/value.lwg3940.compile.fail.cpp
 
b/libcxx/test/std/utilities/expected/expected.void/observers/value.lwg3940.compile.fail.cpp
new file mode 100644
index 00..37c06e629e9443
--- /dev/null
+++ 
b/libcxx/test/std/utilities/expected/expected.void/observers/value.lwg3940.compile.fail.cpp
@@ -0,0 +1,27 @@
+//===--===//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// constexpr void value() &&;
+// Mandates: is_copy_constructible_v is true and is_move_constructible_v 
is true.
+
+#include 
+
+#include "MoveOnly.h"
+
+void test() {
+  // MoveOnly
+  std::expected e(std::unexpect, 5);
+
+  // COMPILE FAIL: MoveOnly is not copy constructible
+  std::move(e).value();
+}
+
+int main(int, char**) {
+  test();
+}
diff --git 
a/libcxx/test/std/utilities/expected/expected.void/observers/value.pass.cpp 
b/libcxx/test/std/utilities/expected/expected.void/observers/value.pass.cpp
index 0f02db19c7b75e..a24d67c57e19b5 100644
--- a/libcxx/test/std/utilities/expected/expected.void/observers/value.pass.cpp
+++ b/libcxx/test/std/utilities/expected/expected.void/observers/value.pass.cpp
@@ -65,17 +65,6 @@ void testException() {
 }
   }
 
-  // MoveOnly
-  {
-std::expected e(std::unexpect, 5);
-try {
-  std::move(e).value();
-  assert(false);
-} catch (const std::bad_expected_access& ex) {
-  assert(ex.error() == 5);
-}
-  }
-
 #endif // TEST_HAS_NO_EXCEPTIONS
 }
 

>From 2d1c43fa98b3a97f31509e98c3abdd7fe8f62626 Mon Sep 17 00:00:00 2001
From: PragmaTwice 
Date: Fri, 10 Nov 2023 19:29:30 +0900
Subject: [PATCH 2/8] [libcxx] format test


[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)

2024-01-05 Thread Qizhi Hu via cfe-commits


@@ -53,18 +53,76 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) {
  FuncTemplate->getTemplateParameters()->getDepth();
 }
 
+AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) {
+  const auto  = Node.getNameAsString();
+
+  return Builder->removeBindings(
+  [this, Name](const ast_matchers::internal::BoundNodesMap ) {
+const auto  = Nodes.getNode(this->BindingID);
+if (const auto *ND = BN.get()) {
+  if (!isa(ND))
+return true;
+  return ND->getName() != Name;
+}
+return true;
+  });
+}
+
+AST_MATCHER_P(LambdaCapture, hasCaptureKind, LambdaCaptureKind, Kind) {
+  return Node.getCaptureKind() == Kind;
+}
+
+AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) {
+  return Node.getCaptureDefault() == Kind;
+}
+
+AST_MATCHER(LambdaExpr, hasCaptureToParm) {
+  auto RefToParm = capturesVar(varDecl(hasSameNameAsBoundNode("param")));
+  auto HasRefToParm = hasAnyCapture(RefToParm);
+
+  auto CaptureInRef =
+  allOf(hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByRef),
+unless(HasRefToParm));
+  auto CaptureInCopy = allOf(
+  hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByCopy), HasRefToParm);
+  auto CaptureByRefExplicit = hasAnyCapture(
+  allOf(hasCaptureKind(LambdaCaptureKind::LCK_ByRef), RefToParm));
+
+  auto Captured =
+  lambdaExpr(anyOf(CaptureInRef, CaptureInCopy, CaptureByRefExplicit));
+  if (Captured.matches(Node, Finder, Builder))
+return true;
+
+  return false;
+}
+
+AST_MATCHER(CallExpr, forCallableNode) {

jcsxky wrote:

Use original matchers instead.

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


[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)

2024-01-05 Thread Qizhi Hu via cfe-commits


@@ -53,18 +53,76 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) {
  FuncTemplate->getTemplateParameters()->getDepth();
 }
 
+AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) {
+  const auto  = Node.getNameAsString();
+
+  return Builder->removeBindings(
+  [this, Name](const ast_matchers::internal::BoundNodesMap ) {
+const auto  = Nodes.getNode(this->BindingID);

jcsxky wrote:

Add explicit type instead of `auto`.

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


[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)

2024-01-05 Thread Qizhi Hu via cfe-commits


@@ -147,4 +147,24 @@ class AClass {
   T data;
 };
 
+template 
+void lambda_value_reference(T&& t) {
+  [&]() { T other = std::forward(t); };
+}
+
+template
+void lambda_value_reference_capture_list_ref_1(T&& t) {
+[=, ] { T other = std::forward(t); };
+}
+
+template
+void lambda_value_reference_capture_list_ref_2(T&& t) {
+[] { T other = std::forward(t); };
+}
+
+template
+void lambda_value_reference_capture_list(T&& t) {
+[t = std::forward(t)] { t(); };
+}
+

jcsxky wrote:

Fixed.

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


[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)

2024-01-05 Thread Qizhi Hu via cfe-commits


@@ -53,18 +53,76 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) {
  FuncTemplate->getTemplateParameters()->getDepth();
 }
 
+AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) {
+  const auto  = Node.getNameAsString();

jcsxky wrote:

Add release notes and fix code as your suggestion.

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


[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)

2024-01-05 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/77056

>From 0f1e72b143d360c1f005f4bd63a378c5277d4480 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 3 Jan 2024 09:44:26 +0800
Subject: [PATCH] [clang-tidy] fix false positive in
 cppcoreguidelines-missing-std-forward

---
 .../MissingStdForwardCheck.cpp| 60 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../cppcoreguidelines/missing-std-forward.cpp | 31 +-
 3 files changed, 91 insertions(+), 5 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index 0b85ea19735eef..370de12999aceb 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -53,16 +53,72 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) {
  FuncTemplate->getTemplateParameters()->getDepth();
 }
 
+AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) {
+  IdentifierInfo *II = Node.getIdentifier();
+  if (nullptr == II)
+return false;
+  StringRef Name = II->getName();
+
+  return Builder->removeBindings(
+  [this, Name](const ast_matchers::internal::BoundNodesMap ) {
+const DynTypedNode  = Nodes.getNode(this->BindingID);
+if (const auto *ND = BN.get()) {
+  if (!isa(ND))
+return true;
+  return ND->getName() != Name;
+}
+return true;
+  });
+}
+
+AST_MATCHER_P(LambdaCapture, hasCaptureKind, LambdaCaptureKind, Kind) {
+  return Node.getCaptureKind() == Kind;
+}
+
+AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) {
+  return Node.getCaptureDefault() == Kind;
+}
+
 } // namespace
 
 void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) {
+  auto RefToParmImplicit = allOf(
+  equalsBoundNode("var"), hasInitializer(ignoringParenImpCasts(
+  declRefExpr(to(equalsBoundNode("param"));
+  auto RefToParm = capturesVar(
+  varDecl(anyOf(hasSameNameAsBoundNode("param"), RefToParmImplicit)));
+  auto HasRefToParm = hasAnyCapture(RefToParm);
+
+  auto CaptureInRef =
+  allOf(hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByRef),
+unless(hasAnyCapture(
+capturesVar(varDecl(hasSameNameAsBoundNode("param"));
+  auto CaptureInCopy = allOf(
+  hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByCopy), HasRefToParm);
+  auto CaptureByRefExplicit = hasAnyCapture(
+  allOf(hasCaptureKind(LambdaCaptureKind::LCK_ByRef), RefToParm));
+
+  auto CapturedInBody =
+  lambdaExpr(anyOf(CaptureInRef, CaptureInCopy, CaptureByRefExplicit));
+  auto CapturedInCaptureList = hasAnyCapture(capturesVar(
+  
varDecl(hasInitializer(ignoringParenImpCasts(equalsBoundNode("call"));
+
+  auto CapturedInLambda = hasDeclContext(cxxRecordDecl(
+  isLambda(),
+  hasParent(lambdaExpr(forCallable(equalsBoundNode("func")),
+   anyOf(CapturedInCaptureList, CapturedInBody);
+
   auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode("param")));
 
   auto ForwardCallMatcher = callExpr(
-  forCallable(equalsBoundNode("func")), argumentCountIs(1),
+  callExpr().bind("call"), argumentCountIs(1),
+  hasArgument(
+  0, declRefExpr(to(
+ varDecl(optionally(equalsBoundNode("param"))).bind("var",
+  forCallable(anyOf(equalsBoundNode("func"), CapturedInLambda)),
   callee(unresolvedLookupExpr(hasAnyDeclaration(
   namedDecl(hasUnderlyingDecl(hasName("::std::forward")),
-  hasArgument(0, declRefExpr(to(equalsBoundNode("param"))).bind("ref")),
+
   unless(anyOf(hasAncestor(typeLoc()),
hasAncestor(expr(hasUnevaluatedContext());
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 4d25e2ebe85f5f..b55599cac3dd06 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -295,6 +295,11 @@ Changes in existing checks
   coroutine functions and increase issue detection for cases involving type
   aliases with references.
 
+- Improved :doc:`cppcoreguidelines-missing-std-forward
+  ` check to
+  provide fixes of false positive that forwarded in capture list and body of
+  lambda.
+
 - Improved :doc:`cppcoreguidelines-narrowing-conversions
   ` check by
   extending the `IgnoreConversionFromTypes` option to include types without a
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
index b9720db272e406..443f338ba2046a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
+++ 

[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)

2024-01-05 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/77056

>From 4b8438f448010d8a805549d8c0fa902266c643e0 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 3 Jan 2024 09:44:26 +0800
Subject: [PATCH] [clang-tidy] fix false positive in
 cppcoreguidelines-missing-std-forward

---
 .../MissingStdForwardCheck.cpp| 60 ++-
 .../cppcoreguidelines/missing-std-forward.cpp | 31 +-
 2 files changed, 86 insertions(+), 5 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index 0b85ea19735eef..370de12999aceb 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -53,16 +53,72 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) {
  FuncTemplate->getTemplateParameters()->getDepth();
 }
 
+AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) {
+  IdentifierInfo *II = Node.getIdentifier();
+  if (nullptr == II)
+return false;
+  StringRef Name = II->getName();
+
+  return Builder->removeBindings(
+  [this, Name](const ast_matchers::internal::BoundNodesMap ) {
+const DynTypedNode  = Nodes.getNode(this->BindingID);
+if (const auto *ND = BN.get()) {
+  if (!isa(ND))
+return true;
+  return ND->getName() != Name;
+}
+return true;
+  });
+}
+
+AST_MATCHER_P(LambdaCapture, hasCaptureKind, LambdaCaptureKind, Kind) {
+  return Node.getCaptureKind() == Kind;
+}
+
+AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) {
+  return Node.getCaptureDefault() == Kind;
+}
+
 } // namespace
 
 void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) {
+  auto RefToParmImplicit = allOf(
+  equalsBoundNode("var"), hasInitializer(ignoringParenImpCasts(
+  declRefExpr(to(equalsBoundNode("param"));
+  auto RefToParm = capturesVar(
+  varDecl(anyOf(hasSameNameAsBoundNode("param"), RefToParmImplicit)));
+  auto HasRefToParm = hasAnyCapture(RefToParm);
+
+  auto CaptureInRef =
+  allOf(hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByRef),
+unless(hasAnyCapture(
+capturesVar(varDecl(hasSameNameAsBoundNode("param"));
+  auto CaptureInCopy = allOf(
+  hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByCopy), HasRefToParm);
+  auto CaptureByRefExplicit = hasAnyCapture(
+  allOf(hasCaptureKind(LambdaCaptureKind::LCK_ByRef), RefToParm));
+
+  auto CapturedInBody =
+  lambdaExpr(anyOf(CaptureInRef, CaptureInCopy, CaptureByRefExplicit));
+  auto CapturedInCaptureList = hasAnyCapture(capturesVar(
+  
varDecl(hasInitializer(ignoringParenImpCasts(equalsBoundNode("call"));
+
+  auto CapturedInLambda = hasDeclContext(cxxRecordDecl(
+  isLambda(),
+  hasParent(lambdaExpr(forCallable(equalsBoundNode("func")),
+   anyOf(CapturedInCaptureList, CapturedInBody);
+
   auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode("param")));
 
   auto ForwardCallMatcher = callExpr(
-  forCallable(equalsBoundNode("func")), argumentCountIs(1),
+  callExpr().bind("call"), argumentCountIs(1),
+  hasArgument(
+  0, declRefExpr(to(
+ varDecl(optionally(equalsBoundNode("param"))).bind("var",
+  forCallable(anyOf(equalsBoundNode("func"), CapturedInLambda)),
   callee(unresolvedLookupExpr(hasAnyDeclaration(
   namedDecl(hasUnderlyingDecl(hasName("::std::forward")),
-  hasArgument(0, declRefExpr(to(equalsBoundNode("param"))).bind("ref")),
+
   unless(anyOf(hasAncestor(typeLoc()),
hasAncestor(expr(hasUnevaluatedContext());
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
index b9720db272e406..443f338ba2046a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
@@ -90,9 +90,9 @@ void lambda_value_capture(T&& t) {
 }
 
 template 
-void lambda_value_reference(T&& t) {
-  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: forwarding reference parameter 
't' is never forwarded inside the function body 
[cppcoreguidelines-missing-std-forward]
-  [&]() { T other = std::forward(t); };
+void lambda_value_capture_copy(T&& t) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: forwarding reference parameter 
't' is never forwarded inside the function body 
[cppcoreguidelines-missing-std-forward]
+  [&,t]() { T other = std::forward(t); };
 }
 
 } // namespace positive_cases
@@ -147,4 +147,29 @@ class AClass {
   T data;
 };
 
+template 
+void lambda_value_reference(T&& 

[compiler-rt] [mlir] [llvm] [flang] [libcxx] [clang-tools-extra] [clang] [NFC][sanitizer] Add consts to SkipInternalFrames (PR #77162)

2024-01-05 Thread Vitaly Buka via cfe-commits

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


[compiler-rt] [mlir] [llvm] [flang] [libcxx] [clang-tools-extra] [clang] [NFC][sanitizer] Add consts to SkipInternalFrames (PR #77162)

2024-01-05 Thread Vitaly Buka via cfe-commits

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


[clang] [clang-tools-extra] [libcxx] [mlir] [compiler-rt] [llvm] [NFC][sanitizer] Move SymbolizedStackHolder into sanitizer_common (PR #77152)

2024-01-05 Thread Vitaly Buka via cfe-commits

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


[lldb] [llvm] [libc] [mlir] [clang] [NFC][ObjectSizeOffset] Use classes instead of std::pair (PR #76882)

2024-01-05 Thread Bill Wendling via cfe-commits

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


[lldb] [llvm] [libc] [mlir] [clang] [NFC][ObjectSizeOffset] Use classes instead of std::pair (PR #76882)

2024-01-05 Thread Bill Wendling via cfe-commits


@@ -187,80 +187,132 @@ Value *lowerObjectSizeCall(
 const TargetLibraryInfo *TLI, AAResults *AA, bool MustSucceed,
 SmallVectorImpl *InsertedInstructions = nullptr);
 
-using SizeOffsetType = std::pair;
+/// SizeOffsetType - A base template class for the object size visitors. Used
+/// here as a self-documenting way to handle the values rather than using a
+/// \p std::pair.
+template  class SizeOffsetType {
+public:
+  T Size;
+  T Offset;
+
+  SizeOffsetType() = default;
+  SizeOffsetType(T Size, T Offset) : Size(Size), Offset(Offset) {}
+
+  bool anyKnown() const { return C::known(Size) || C::known(Offset); }
+  bool bothKnown() const { return C::known(Size) && C::known(Offset); }
+
+  bool operator==(const SizeOffsetType ) const {
+return Size == RHS.Size && Offset == RHS.Offset;
+  }
+  bool operator!=(const SizeOffsetType ) const {
+return !(*this == RHS);
+  }
+};
+
+/// SizeOffsetAPInt - Used by \p ObjectSizeOffsetVisitor, which works with
+/// \p APInts.
+class SizeOffsetAPInt : public SizeOffsetType {
+  friend class SizeOffsetType;
+  static bool known(APInt V) { return V.getBitWidth() > 1; }
+
+public:
+  SizeOffsetAPInt() = default;
+  SizeOffsetAPInt(APInt Size, APInt Offset) : SizeOffsetType(Size, Offset) {}
+
+  bool knownSize() const { return SizeOffsetAPInt::known(Size); }
+  bool knownOffset() const { return SizeOffsetAPInt::known(Offset); }

bwendling wrote:

Ah yes! Done. :-)

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


[lldb] [llvm] [libc] [mlir] [clang] [NFC][ObjectSizeOffset] Use classes instead of std::pair (PR #76882)

2024-01-05 Thread Bill Wendling via cfe-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/76882

>From ca7a96a40952fe94b916dacc52f07aa90bbdb1e7 Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Wed, 3 Jan 2024 13:22:37 -0800
Subject: [PATCH 1/9] [builtin_object_size] Use classes instead of std::pair
 (NFC)

The use of std::pair makes the values it holds opaque. Using classes
improves this while keeping the POD aspect of a std::pair. As a nice
addition, the "known" functions held inappropriately in the Visitor
classes can now properly reside in the value classes. :-)
---
 llvm/include/llvm/Analysis/MemoryBuiltins.h   | 192 +++
 llvm/lib/Analysis/MemoryBuiltins.cpp  | 314 +-
 .../Transforms/IPO/AttributorAttributes.cpp   |   8 +-
 .../Instrumentation/AddressSanitizer.cpp  |  12 +-
 .../Instrumentation/BoundsChecking.cpp|   8 +-
 5 files changed, 299 insertions(+), 235 deletions(-)

diff --git a/llvm/include/llvm/Analysis/MemoryBuiltins.h 
b/llvm/include/llvm/Analysis/MemoryBuiltins.h
index 827b5081b2ce75..56faa32fb0b226 100644
--- a/llvm/include/llvm/Analysis/MemoryBuiltins.h
+++ b/llvm/include/llvm/Analysis/MemoryBuiltins.h
@@ -187,80 +187,146 @@ Value *lowerObjectSizeCall(
 const TargetLibraryInfo *TLI, AAResults *AA, bool MustSucceed,
 SmallVectorImpl *InsertedInstructions = nullptr);
 
-using SizeOffsetType = std::pair;
+/// SizeOffsetType - A base template class for the object size visitors. Used
+/// here as a self-documenting way to handle the values rather than using a
+/// \p std::pair.
+template  struct SizeOffsetType {
+  T Size;
+  T Offset;
+
+  bool knownSize() const;
+  bool knownOffset() const;
+  bool anyKnown() const;
+  bool bothKnown() const;
+};
+
+/// SizeOffsetType - Used by \p ObjectSizeOffsetVisitor, which works
+/// with \p APInts.
+template <> struct SizeOffsetType {
+  APInt Size;
+  APInt Offset;
+
+  SizeOffsetType() = default;
+  SizeOffsetType(APInt Size, APInt Offset) : Size(Size), Offset(Offset) {}
+
+  bool knownSize() const { return Size.getBitWidth() > 1; }
+  bool knownOffset() const { return Offset.getBitWidth() > 1; }
+  bool anyKnown() const { return knownSize() || knownOffset(); }
+  bool bothKnown() const { return knownSize() && knownOffset(); }
+
+  bool operator==(const SizeOffsetType ) {
+return Size == RHS.Size && Offset == RHS.Offset;
+  }
+  bool operator!=(const SizeOffsetType ) { return !(*this == RHS); }
+};
+using SizeOffsetAPInt = SizeOffsetType;
 
 /// Evaluate the size and offset of an object pointed to by a Value*
 /// statically. Fails if size or offset are not known at compile time.
 class ObjectSizeOffsetVisitor
-  : public InstVisitor {
+: public InstVisitor {
   const DataLayout 
   const TargetLibraryInfo *TLI;
   ObjectSizeOpts Options;
   unsigned IntTyBits;
   APInt Zero;
-  SmallDenseMap SeenInsts;
+  SmallDenseMap SeenInsts;
   unsigned InstructionsVisited;
 
   APInt align(APInt Size, MaybeAlign Align);
 
-  SizeOffsetType unknown() {
-return std::make_pair(APInt(), APInt());
-  }
+  static SizeOffsetAPInt unknown;
 
 public:
   ObjectSizeOffsetVisitor(const DataLayout , const TargetLibraryInfo *TLI,
   LLVMContext , ObjectSizeOpts Options = {});
 
-  SizeOffsetType compute(Value *V);
-
-  static bool knownSize(const SizeOffsetType ) {
-return SizeOffset.first.getBitWidth() > 1;
-  }
-
-  static bool knownOffset(const SizeOffsetType ) {
-return SizeOffset.second.getBitWidth() > 1;
-  }
-
-  static bool bothKnown(const SizeOffsetType ) {
-return knownSize(SizeOffset) && knownOffset(SizeOffset);
-  }
+  SizeOffsetAPInt compute(Value *V);
 
   // These are "private", except they can't actually be made private. Only
   // compute() should be used by external users.
-  SizeOffsetType visitAllocaInst(AllocaInst );
-  SizeOffsetType visitArgument(Argument );
-  SizeOffsetType visitCallBase(CallBase );
-  SizeOffsetType visitConstantPointerNull(ConstantPointerNull&);
-  SizeOffsetType visitExtractElementInst(ExtractElementInst );
-  SizeOffsetType visitExtractValueInst(ExtractValueInst );
-  SizeOffsetType visitGlobalAlias(GlobalAlias );
-  SizeOffsetType visitGlobalVariable(GlobalVariable );
-  SizeOffsetType visitIntToPtrInst(IntToPtrInst&);
-  SizeOffsetType visitLoadInst(LoadInst );
-  SizeOffsetType visitPHINode(PHINode&);
-  SizeOffsetType visitSelectInst(SelectInst );
-  SizeOffsetType visitUndefValue(UndefValue&);
-  SizeOffsetType visitInstruction(Instruction );
+  SizeOffsetAPInt visitAllocaInst(AllocaInst );
+  SizeOffsetAPInt visitArgument(Argument );
+  SizeOffsetAPInt visitCallBase(CallBase );
+  SizeOffsetAPInt visitConstantPointerNull(ConstantPointerNull &);
+  SizeOffsetAPInt visitExtractElementInst(ExtractElementInst );
+  SizeOffsetAPInt visitExtractValueInst(ExtractValueInst );
+  SizeOffsetAPInt visitGlobalAlias(GlobalAlias );
+  SizeOffsetAPInt visitGlobalVariable(GlobalVariable );
+  SizeOffsetAPInt visitIntToPtrInst(IntToPtrInst &);

[mlir] [llvm] [compiler-rt] [clang-tools-extra] [libcxx] [clang] [NFC][sanitizer] Move SymbolizedStackHolder into sanitizer_common (PR #77152)

2024-01-05 Thread Kirill Stoimenov via cfe-commits

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


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


[clang] [llvm] [llvm] Add support for building on illumos (PR #74930)

2024-01-05 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> illumos has an older version of the Solaris linker that does not support the 
> GNU version script compat nor version scripts and does not support 
> -Bsymbolic-functions. Treat illumos linker separately.

Are they aware of the issue and is there a tracking feature request/issue? It 
seems that this patch adds code to hard code the implementation properties 
which may become stale.

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


[clang] [llvm] [llvm] Add support for building on illumos (PR #74930)

2024-01-05 Thread Fangrui Song via cfe-commits


@@ -241,6 +241,11 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
   set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
   set(LLVM_LINKER_IS_GNULD YES CACHE INTERNAL "")
   message(STATUS "Linker detection: GNU ld")
+elseif("${stderr}" MATCHES "(illumos)" OR
+   "${stdout}" MATCHES "(illumos)")
+  set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
+  set(LLVM_LINKER_IS_SOLARISLD_ILLUMOS YES CACHE INTERNAL "")

MaskRay wrote:

If illumos uses an old Solaris ld, it seems that the similarity outnumbers the 
discrepancy and we should set `LLVM_LINKER_IS_SOLARISLD` to yes as well.

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


[clang] [compiler-rt] [llvm] [mlir] [clang-tools-extra] [libcxx] [ubsan] Drop terminal "in " from reports without functions (PR #77163)

2024-01-05 Thread Vitaly Buka via cfe-commits

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


[clang-tools-extra] [compiler-rt] [mlir] [llvm] [libcxx] [clang] [NFC][sanitizer] Move SymbolizedStackHolder into sanitizer_common (PR #77152)

2024-01-05 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/77152

>From 484721a2c62b33385bf8cfec2f00450c2079a2a2 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Fri, 5 Jan 2024 14:31:51 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
 =?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 .../lib/sanitizer_common/sanitizer_common.h   |  3 +++
 .../sanitizer_symbolizer_report.cpp   | 20 +++
 compiler-rt/lib/tsan/rtl/tsan_report.cpp  | 18 +++--
 3 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h 
b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index 6b327a4aa16f0b..7d9d61de8b6175 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -32,6 +32,7 @@ struct AddressInfo;
 struct BufferedStackTrace;
 struct SignalContext;
 struct StackTrace;
+struct SymbolizedStack;
 
 // Constants.
 const uptr kWordSize = SANITIZER_WORDSIZE / 8;
@@ -393,6 +394,8 @@ void ReportErrorSummary(const char *error_type, const 
AddressInfo ,
 // Same as above, but obtains AddressInfo by symbolizing top stack trace frame.
 void ReportErrorSummary(const char *error_type, const StackTrace *trace,
 const char *alt_tool_name = nullptr);
+// Skips frames which we consider internal and not usefull to the users.
+SymbolizedStack *SkipInternalFrames(SymbolizedStack *frames);
 
 void ReportMmapWriteExec(int prot, int mflags);
 
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
index 3e4417ae3f57e5..ec60dd3e0d6620 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
@@ -28,6 +28,26 @@
 namespace __sanitizer {
 
 #if !SANITIZER_GO
+
+static bool FrameIsInternal(const SymbolizedStack *frame) {
+  if (!frame)
+return true;
+  const char *file = frame->info.file;
+  const char *module = frame->info.module;
+  if (file && (internal_strstr(file, "/compiler-rt/lib/")))
+return true;
+  if (module && (internal_strstr(module, "libclang_rt.")))
+return true;
+  return false;
+}
+
+SymbolizedStack *SkipInternalFrames(SymbolizedStack *frames) {
+  for (SymbolizedStack *f = frames; f; f = f->next)
+if (!FrameIsInternal(f))
+  return f;
+  return nullptr;
+}
+
 void ReportErrorSummary(const char *error_type, const AddressInfo ,
 const char *alt_tool_name) {
   if (!common_flags()->print_summary) return;
diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cpp 
b/compiler-rt/lib/tsan/rtl/tsan_report.cpp
index 167e4be4fc0e26..b1cee7ac8cbf83 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_report.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_report.cpp
@@ -273,22 +273,10 @@ static ReportStack *ChooseSummaryStack(const ReportDesc 
*rep) {
   return 0;
 }
 
-static bool FrameIsInternal(const SymbolizedStack *frame) {
-  if (frame == 0)
-return false;
-  const char *file = frame->info.file;
-  const char *module = frame->info.module;
-  if (file != 0 && (internal_strstr(file, "/compiler-rt/lib/")))
-return true;
-  if (module != 0 && (internal_strstr(module, "libclang_rt.")))
-return true;
-  return false;
-}
-
 static SymbolizedStack *SkipTsanInternalFrames(SymbolizedStack *frames) {
-  while (FrameIsInternal(frames) && frames->next)
-frames = frames->next;
-  return frames;
+  if (SymbolizedStack *f = SkipInternalFrames(frames))
+return f;
+  return frames;  // Fallback to the top frame.
 }
 
 void PrintReport(const ReportDesc *rep) {

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


[clang] [-Wunsafe-buffer-usage] Add a new warning for uses of std::span two-parameter constructors (PR #77148)

2024-01-05 Thread Ziqing Luo via cfe-commits

https://github.com/ziqingluo-90 updated 
https://github.com/llvm/llvm-project/pull/77148

>From 4714b0c03897ab61322e3a16288994ccb01dbfac Mon Sep 17 00:00:00 2001
From: ziqingluo-90 
Date: Fri, 5 Jan 2024 13:39:39 -0800
Subject: [PATCH 1/2] [-Wunsafe-buffer-usage] Add a new warning for use of
 two-parameter std::span constructors

Constructing `std::span` objects with the two parameter constructors
could introduce mismatched bounds information, which defeats the
purpose of using `std::span`.  Therefore, we warn every use of such
constructors.

We also plan to incrementally teach `-Wunsafe-buffer-usage` about benign
usages of those constructors.

rdar://115817781
---
 .../Analysis/Analyses/UnsafeBufferUsage.h |   8 +-
 .../Analyses/UnsafeBufferUsageGadgets.def |   8 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/lib/Analysis/UnsafeBufferUsage.cpp  |  46 +++
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |  16 ++-
 ...ffer-usage-in-container-span-construct.cpp | 118 ++
 ...e-buffer-usage-warning-data-invocation.cpp |   2 +-
 7 files changed, 197 insertions(+), 4 deletions(-)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp

diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index b28f2c6b99c50e..aca1ad998822c5 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -16,6 +16,7 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/Stmt.h"
+#include "clang/Basic/SourceLocation.h"
 #include "llvm/Support/Debug.h"
 
 namespace clang {
@@ -98,9 +99,14 @@ class UnsafeBufferUsageHandler {
 #endif
 
 public:
-  /// Returns a reference to the `Preprocessor`:
+  /// \return true iff buffer safety is opt-out at `Loc`; false otherwise.
   virtual bool isSafeBufferOptOut(const SourceLocation ) const = 0;
 
+  /// \return true iff unsafe uses in containers should NOT be reported at
+  /// `Loc`; false otherwise.
+  virtual bool
+  ignoreUnsafeBufferInContainer(const SourceLocation ) const = 0;
+
   virtual std::string
   getUnsafeBufferUsageAttributeTextAt(SourceLocation Loc,
   StringRef WSSuffix = "") const = 0;
diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
index c9766168836510..07f805ebb11013 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
@@ -18,6 +18,12 @@
 #define WARNING_GADGET(name) GADGET(name)
 #endif
 
+/// A `WARNING_GADGET` subset, where the code pattern of each gadget
+/// corresponds uses of a (possibly hardened) contatiner (e.g., `std::span`).
+#ifndef WARNING_CONTAINER_GADGET
+#define WARNING_CONTAINER_GADGET(name) WARNING_GADGET(name)
+#endif
+
 /// Safe gadgets correspond to code patterns that aren't unsafe but need to be
 /// properly recognized in order to emit correct warnings and fixes over unsafe
 /// gadgets.
@@ -31,6 +37,7 @@ WARNING_GADGET(ArraySubscript)
 WARNING_GADGET(PointerArithmetic)
 WARNING_GADGET(UnsafeBufferUsageAttr)
 WARNING_GADGET(DataInvocation)
+WARNING_CONTAINER_GADGET(SpanTwoParamConstructor) // Uses of `std::span(arg0, 
arg1)`
 FIXABLE_GADGET(ULCArraySubscript)  // `DRE[any]` in an Unspecified 
Lvalue Context
 FIXABLE_GADGET(DerefSimplePtrArithFixable)
 FIXABLE_GADGET(PointerDereference)
@@ -43,4 +50,5 @@ FIXABLE_GADGET(PointerInit)
 
 #undef FIXABLE_GADGET
 #undef WARNING_GADGET
+#undef WARNING_CONTAINER_GADGET
 #undef GADGET
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e54f969c19039d..940de9629d7986 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12075,6 +12075,9 @@ def note_unsafe_buffer_variable_fixit_together : Note<
   "%select{|, and change %2 to safe types to make function %4 bounds-safe}3">;
 def note_safe_buffer_usage_suggestions_disabled : Note<
   "pass -fsafe-buffer-usage-suggestions to receive code hardening 
suggestions">;
+def warn_unsafe_buffer_usage_in_container : Warning<
+  "%select{the two-parameter std::span construction is unsafe as it can 
introduce mismatch between buffer size and the bound information}0">,
+  InGroup, DefaultIgnore;
 #ifndef NDEBUG
 // Not a user-facing diagnostic. Useful for debugging false negatives in
 // -fsafe-buffer-usage-suggestions (i.e. lack of -Wunsafe-buffer-usage fixits).
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 724c4304a07242..3b6d69cac1afd8 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -232,6 +232,11 @@ AST_MATCHER_P(Stmt, notInSafeBufferOptOut, const 

[libc] [libunwind] [compiler-rt] [llvm] [libcxx] [clang] [NFC][tsan] Move SkipInternalFrames into sanitizer_common (PR #77146)

2024-01-05 Thread Vitaly Buka via cfe-commits

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


[llvm] [compiler-rt] [libunwind] [libc] [libcxx] [clang] [NFC][tsan] Move SkipInternalFrames into sanitizer_common (PR #77146)

2024-01-05 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/77146

>From 250c84b0b0278e4f03aace2bfc03943543ed5f23 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Fri, 5 Jan 2024 14:06:44 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
 =?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/lib/tsan/rtl/tsan_report.cpp | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cpp 
b/compiler-rt/lib/tsan/rtl/tsan_report.cpp
index 35cb6710a54fa4..c6b764bd891752 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_report.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_report.cpp
@@ -274,25 +274,22 @@ static ReportStack *ChooseSummaryStack(const ReportDesc 
*rep) {
 }
 
 static bool FrameIsInternal(const SymbolizedStack *frame) {
-  if (frame == 0)
-return false;
+  if (!frame)
+return true;
   const char *file = frame->info.file;
   const char *module = frame->info.module;
-  if (file != 0 &&
-  (internal_strstr(file, "tsan_interceptors_posix.cpp") ||
-   internal_strstr(file, "tsan_interceptors_memintrinsics.cpp") ||
-   internal_strstr(file, "sanitizer_common_interceptors.inc") ||
-   internal_strstr(file, "tsan_interface_")))
+  if (file && (internal_strstr(file, "/compiler-rt/lib/")))
 return true;
-  if (module != 0 && (internal_strstr(module, "libclang_rt.tsan_")))
+  if (module && (internal_strstr(module, "libclang_rt.")))
 return true;
   return false;
 }
 
 static SymbolizedStack *SkipTsanInternalFrames(SymbolizedStack *frames) {
-  while (FrameIsInternal(frames) && frames->next)
-frames = frames->next;
-  return frames;
+  for (SymbolizedStack *f = frames; f; f = f->next)
+if (!FrameIsInternal(f))
+  return f;
+  return frames;  // Fallback to the top frame.
 }
 
 void PrintReport(const ReportDesc *rep) {

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


[clang] [clang] Add per-global code model attribute (PR #72078)

2024-01-05 Thread via cfe-commits

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


[clang] 4df5662 - [clang] Add per-global code model attribute (#72078)

2024-01-05 Thread via cfe-commits

Author: hev
Date: 2024-01-06T08:51:59+08:00
New Revision: 4df566290751403f470fea3b27aa148ab1ddf144

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

LOG: [clang] Add per-global code model attribute (#72078)

This patch adds a per-global code model attribute, which can override
the target's code model to access global variables.

Currently, the code model attribute is only supported on LoongArch. This
patch also maps GCC's code model names to LLVM's, which allows for
better compatibility between the two compilers.


Suggested-by: Arthur Eubanks 
Link:
https://discourse.llvm.org/t/how-to-best-implement-code-model-overriding-for-certain-values/71816
Link:
https://discourse.llvm.org/t/rfc-add-per-global-code-model-attribute/74944

-

Signed-off-by: WANG Rui 

Added: 
clang/test/CodeGen/LoongArch/attributes.cpp
clang/test/Sema/attr-model.cpp

Modified: 
clang/include/clang/AST/Attr.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 1b831c9511e272..8e9b7ad8b46826 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -25,6 +25,7 @@
 #include "clang/Basic/Sanitizers.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/Frontend/HLSL/HLSLResource.h"
+#include "llvm/Support/CodeGen.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/Support/raw_ostream.h"

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fda62aaae22c78..d5eabaad488965 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -143,6 +143,11 @@ def ExternalGlobalVar : SubsetSubjectisLocalExternDecl()}],
  "external global variables">;
 
+def NonTLSGlobalVar : SubsetSubjecthasGlobalStorage() &&
+   S->getTLSKind() == 0}],
+ "non-TLS global variables">;
+
 def InlineFunction : SubsetSubjectisInlineSpecified()}], "inline functions">;
 
@@ -431,6 +436,7 @@ def TargetAArch64 : TargetArch<["aarch64", "aarch64_be", 
"aarch64_32"]>;
 def TargetAnyArm : TargetArch;
 def TargetAVR : TargetArch<["avr"]>;
 def TargetBPF : TargetArch<["bpfel", "bpfeb"]>;
+def TargetLoongArch : TargetArch<["loongarch32", "loongarch64"]>;
 def TargetMips32 : TargetArch<["mips", "mipsel"]>;
 def TargetAnyMips : TargetArch<["mips", "mipsel", "mips64", "mips64el"]>;
 def TargetMSP430 : TargetArch<["msp430"]>;
@@ -2738,6 +2744,15 @@ def PragmaClangTextSection : InheritableAttr {
   let Documentation = [InternalOnly];
 }
 
+def CodeModel : InheritableAttr, TargetSpecificAttr {
+  let Spellings = [GCC<"model">];
+  let Args = [EnumArgument<"Model", "llvm::CodeModel::Model",
+  ["normal", "medium", "extreme"], ["Small", "Medium", "Large"],
+  /*opt=*/0, /*fake=*/0, /*isExternalType=*/1>];
+  let Subjects = SubjectList<[NonTLSGlobalVar], ErrorDiag>;
+  let Documentation = [CodeModelDocs];
+}
+
 def Sentinel : InheritableAttr {
   let Spellings = [GCC<"sentinel">];
   let Args = [DefaultIntArgument<"Sentinel", 0>,

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index cd3dcf2ccf4411..5416a0cbdd0757 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -57,6 +57,15 @@ global variable or function should be in after translation.
   let Heading = "section, __declspec(allocate)";
 }
 
+def CodeModelDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+The ``model`` attribute allows overriding the translation unit's
+code model (specified by ``-mcmodel``) for a specific global variable.
+  }];
+  let Heading = "model";
+}
+
 def UsedDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e54f969c19039d..d150e08d5f5ea8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3415,6 +3415,8 @@ def warn_objc_redundant_literal_use : Warning<
 def err_attr_tlsmodel_arg : Error<"tls_model must be \"global-dynamic\", "
   "\"local-dynamic\", \"initial-exec\" or \"local-exec\"">;
 
+def err_attr_codemodel_arg : Error<"code model '%0' is not supported on this 
target">;
+
 def err_aix_attr_unsupported_tls_model : Error<"TLS model '%0' is not yet 
supported on AIX">;
 
 def err_tls_var_aligned_over_maximum : Error<

diff  --git 

[clang] [-Wunsafe-buffer-usage] Add a new warning for uses of std::span two-parameter constructors (PR #77148)

2024-01-05 Thread Ziqing Luo via cfe-commits

https://github.com/ziqingluo-90 updated 
https://github.com/llvm/llvm-project/pull/77148

>From fb93d83d65ef1c52857b4471ccda2e82447d45dc Mon Sep 17 00:00:00 2001
From: ziqingluo-90 
Date: Fri, 5 Jan 2024 13:39:39 -0800
Subject: [PATCH 1/2] [-Wunsafe-buffer-usage] Add a new warning for use of
 two-parameter std::span constructors

Constructing `std::span` objects with the two parameter constructors
could introduce mismatched bounds information, which defeats the
purpose of using `std::span`.  Therefore, we warn every use of such
constructors.

We also plan to incrementally teach `-Wunsafe-buffer-usage` about benign
usages of those constructors.

rdar://115817781
---
 .../Analysis/Analyses/UnsafeBufferUsage.h |   8 +-
 .../Analyses/UnsafeBufferUsageGadgets.def |   8 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/lib/Analysis/UnsafeBufferUsage.cpp  |  46 +++
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |  15 ++-
 ...ffer-usage-in-container-span-construct.cpp | 118 ++
 ...e-buffer-usage-warning-data-invocation.cpp |   2 +-
 7 files changed, 197 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp

diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index b28f2c6b99c50e..aca1ad998822c5 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -16,6 +16,7 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/Stmt.h"
+#include "clang/Basic/SourceLocation.h"
 #include "llvm/Support/Debug.h"
 
 namespace clang {
@@ -98,9 +99,14 @@ class UnsafeBufferUsageHandler {
 #endif
 
 public:
-  /// Returns a reference to the `Preprocessor`:
+  /// \return true iff buffer safety is opt-out at `Loc`; false otherwise.
   virtual bool isSafeBufferOptOut(const SourceLocation ) const = 0;
 
+  /// \return true iff unsafe uses in containers should NOT be reported at
+  /// `Loc`; false otherwise.
+  virtual bool
+  ignoreUnsafeBufferInContainer(const SourceLocation ) const = 0;
+
   virtual std::string
   getUnsafeBufferUsageAttributeTextAt(SourceLocation Loc,
   StringRef WSSuffix = "") const = 0;
diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
index c9766168836510..07f805ebb11013 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
@@ -18,6 +18,12 @@
 #define WARNING_GADGET(name) GADGET(name)
 #endif
 
+/// A `WARNING_GADGET` subset, where the code pattern of each gadget
+/// corresponds uses of a (possibly hardened) contatiner (e.g., `std::span`).
+#ifndef WARNING_CONTAINER_GADGET
+#define WARNING_CONTAINER_GADGET(name) WARNING_GADGET(name)
+#endif
+
 /// Safe gadgets correspond to code patterns that aren't unsafe but need to be
 /// properly recognized in order to emit correct warnings and fixes over unsafe
 /// gadgets.
@@ -31,6 +37,7 @@ WARNING_GADGET(ArraySubscript)
 WARNING_GADGET(PointerArithmetic)
 WARNING_GADGET(UnsafeBufferUsageAttr)
 WARNING_GADGET(DataInvocation)
+WARNING_CONTAINER_GADGET(SpanTwoParamConstructor) // Uses of `std::span(arg0, 
arg1)`
 FIXABLE_GADGET(ULCArraySubscript)  // `DRE[any]` in an Unspecified 
Lvalue Context
 FIXABLE_GADGET(DerefSimplePtrArithFixable)
 FIXABLE_GADGET(PointerDereference)
@@ -43,4 +50,5 @@ FIXABLE_GADGET(PointerInit)
 
 #undef FIXABLE_GADGET
 #undef WARNING_GADGET
+#undef WARNING_CONTAINER_GADGET
 #undef GADGET
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e54f969c19039d..940de9629d7986 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12075,6 +12075,9 @@ def note_unsafe_buffer_variable_fixit_together : Note<
   "%select{|, and change %2 to safe types to make function %4 bounds-safe}3">;
 def note_safe_buffer_usage_suggestions_disabled : Note<
   "pass -fsafe-buffer-usage-suggestions to receive code hardening 
suggestions">;
+def warn_unsafe_buffer_usage_in_container : Warning<
+  "%select{the two-parameter std::span construction is unsafe as it can 
introduce mismatch between buffer size and the bound information}0">,
+  InGroup, DefaultIgnore;
 #ifndef NDEBUG
 // Not a user-facing diagnostic. Useful for debugging false negatives in
 // -fsafe-buffer-usage-suggestions (i.e. lack of -Wunsafe-buffer-usage fixits).
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 724c4304a07242..3b6d69cac1afd8 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -232,6 +232,11 @@ AST_MATCHER_P(Stmt, notInSafeBufferOptOut, const 

[lldb] [flang] [compiler-rt] [libcxxabi] [llvm] [clang] [polly] [libcxx] [libc] [mlir] [clang-tools-extra] [lld] Make clang report invalid target versions. (PR #75373)

2024-01-05 Thread Fangrui Song via cfe-commits


@@ -5,13 +5,13 @@
 // RUN: %clang -O3 -target aarch64-linux-eabi -mno-fix-cortex-a53-835769 %s -S 
-o- 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO --check-prefix=CHECK %s
 
-// RUN: %clang -O3 -target aarch64-android-eabi %s -S -o- \
+// RUN: %clang -O3 -target aarch64-linux-androideabi %s -S -o- \

MaskRay wrote:

while here, replace deprecated `-target ` with `--target=`

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


[clang-tools-extra] [libcxx] [compiler-rt] [flang] [libc] [lldb] [llvm] [polly] [mlir] [lld] [clang] [libcxxabi] Make clang report invalid target versions. (PR #75373)

2024-01-05 Thread Fangrui Song via cfe-commits


@@ -786,4 +786,7 @@ def warn_android_unversioned_fallback : Warning<
   " directories will not be used in Clang 19. Provide a versioned directory"
   " for the target version or lower instead.">,
   InGroup>;
+
+def err_android_version_invalid : Error<
+  "Version %0 in triple %1-%2-%3-%4 is invalid.">;

MaskRay wrote:

See https://llvm.org/docs/CodingStandards.html#error-and-warning-messages

We can keep just `%1` and remove 2/3/4 by using `TC.getTripleString()` in the 
call site.

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


[clang] [mlir] [clang-tools-extra] [llvm] [mlir][spirv] Fix spirv dialect to support Specialization constants as GlobalVar initializer (PR #75660)

2024-01-05 Thread Lei Zhang via cfe-commits

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


[mlir] [clang] [clang-tools-extra] [llvm] [mlir][spirv] Fix spirv dialect to support Specialization constants as GlobalVar initializer (PR #75660)

2024-01-05 Thread Lei Zhang via cfe-commits

antiagainst wrote:

Thanks for the contribution! Sorry about the delay in reviews. I do have some 
style-ish comments but given this has been a while I just went ahead fixed them 
and will land this path directly. Thanks again! 

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


[clang] [mlir] [llvm] [clang-tools-extra] [mlir][spirv] Fix spirv dialect to support Specialization constants as GlobalVar initializer (PR #75660)

2024-01-05 Thread Lei Zhang via cfe-commits

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


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


[clang] [llvm] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2024-01-05 Thread Paul Kirth via cfe-commits

ilovepi wrote:

The title should probably be changed to something like:

`[RISCV] Add Zicfiss support to the shadow call stack implementation`

The current title doesn't make much sense to me, but maybe I've misunderstood 
the intent?

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


[llvm] [libc] [libcxx] [clang] [compiler-rt] [libunwind] [NFC][tsan] Move SkipInternalFrames into sanitizer_common (PR #77146)

2024-01-05 Thread Vitaly Buka via cfe-commits

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


[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

2024-01-05 Thread Owen Pan via cfe-commits


@@ -2499,6 +2499,15 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
 }
 
+TEST_F(TokenAnnotatorTest, StreamOperator) {
+  auto Tokens = annotate("\"foo\\n\" << aux << \"foo\\n\" << \"foo\";");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_FALSE(Tokens[1]->MustBreakBefore);
+  EXPECT_FALSE(Tokens[3]->MustBreakBefore);
+  // Only break between string literals if the former ends with \n.
+  EXPECT_TRUE(Tokens[5]->MustBreakBefore);
+}
+

owenca wrote:

I understand, but `TokenAnnotatorTest` is mainly for testing token types and 
has never been used for checking `MustBreakBefore` and other similar token 
attributes. @HazardyKnusperkeks @rymiel @mydeveloperday what do you think?

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


[llvm] [clang] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2024-01-05 Thread Paul Kirth via cfe-commits


@@ -57,11 +57,14 @@ compiled application or the operating system. Integrating 
the runtime into
 the operating system should be preferred since otherwise all thread creation
 and destruction would need to be intercepted by the application.
 
-The instrumentation makes use of the platform register ``x18`` on AArch64 and
-``x3`` (``gp``) on RISC-V. For simplicity we will refer to this as the
-``SCSReg``. On some platforms, ``SCSReg`` is reserved, and on others, it is
-designated as a scratch register.  This generally means that any code that may
-run on the same thread as code compiled with ShadowCallStack must either target
+The instrumentation makes use of the platform register ``x18`` on AArch64,
+``x3`` (``gp``) on RISC-V with software shadow stack and ``ssp`` on RISC-V with
+hardware shadow stack, which needs `Zicfiss`_ and 
``-mno-forced-sw-shadow-stack``
+(default option). ``-mforced-sw-shadow-stack`` make risc-v backend generate
+software shadow stack with `Zicfiss`_ when shadow stack enabled.

ilovepi wrote:

```suggestion
hardware shadow stack, which needs `Zicfiss`_. Note that with ``Zicfiss``_ the 
RISC-V backend will default to the hardware based shadow call stack. Users can 
force the RISC-V backend to generate the software shadow call stack with 
``Zicfiss``_ by passing ``-mforced-sw-shadow-stack``. 
```
Maybe this is easier to follow? Might also make sense to outline when 
`-mforced-sw-shadow-stack` is expected to work somewhere, e.g., it has no 
effect w/o `Zicfiss``.  TBH, in that case, the driver should probably issue an 
error, since its incompatible w/o the feature, but I'm not sure if we can do 
that check in the frontend or not.

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


[llvm] [clang] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2024-01-05 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi commented:

Should the driver issue an error when using `-mforced-sw-shadow-stack` w/o 
`Zicfiss`? As mentioned in-line, I'm not sure we can do that check, but it 
feels like it should be incompatible.

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


[clang] [llvm] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2024-01-05 Thread Paul Kirth via cfe-commits

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


[clang] [llvm] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2024-01-05 Thread Paul Kirth via cfe-commits


@@ -151,9 +155,10 @@ Usage
 
 To enable ShadowCallStack, just pass the ``-fsanitize=shadow-call-stack`` flag
 to both compile and link command lines. On aarch64, you also need to pass
-``-ffixed-x18`` unless your target already reserves ``x18``. On RISC-V, ``x3``
-(``gp``) is always reserved. It is, however, important to disable GP relaxation
-in the linker. This can be done with the ``--no-relax-gp`` flag in GNU ld.
+``-ffixed-x18`` unless your target already reserves ``x18``. On RISC-V with 
software
+shadow stack, ``x3`` (``gp``) is always reserved. It is, however, important to
+disable GP relaxation in the linker. This can be done with the 
``--no-relax-gp``
+flag in GNU ld.

ilovepi wrote:

We reserve `gp` even w/o SCS. The `--no-relax-gp`  advice does only apply to 
the software SCS.

Maybe something along these lines?

```suggestion
``-ffixed-x18`` unless your target already reserves ``x18``. No additional 
flags need to be passed on RISC-V because the software based shadow stack uses 
``x3`` (``gp``), which is always reserved, and the hardware based shadow call 
stack uses a dedicated register, ``ssp``.
However, it is important to disable GP relaxation in the linker when using the 
software based shadow call stack on RISC-V. 
This can be done with the ``--no-relax-gp`` flag in GNU ld, and is off by 
default in LLD.
```

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


[clang] [mlir] [llvm] [clang-tools-extra] [mlir][spirv] Fix spirv dialect to support Specialization constants as GlobalVar initializer (PR #75660)

2024-01-05 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst updated 
https://github.com/llvm/llvm-project/pull/75660

>From fd8c637f2b146ffce657307841f84a4123e351af Mon Sep 17 00:00:00 2001
From: Dimple Prajapati 
Date: Wed, 13 Dec 2023 22:33:23 +
Subject: [PATCH 1/6] [mlir][spirv] Fix spirv dialect to support Specialization
 constants in GlobalVar initializer

Changes include:
- spirv serialization and deserialization needs handling in cases when 
GlobalVariableOp
  initializer is defined using spirv SpecConstant or 
SpecConstantComposite op, currently
  even though it allows SpecConst, it only looked up in for 
GlobalVariable Map to find
  initializer symbol reference, change is fixing this and extending the 
support to
  SpecConstantComposite as an initializer.
- Adds tests to make sure GlobalVariable can be initialzed using 
specialized constants.
---
 mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp|  5 ++--
 .../SPIRV/Deserialization/Deserializer.cpp| 19 ++-
 .../SPIRV/Serialization/SerializeOps.cpp  | 22 -
 mlir/test/Dialect/SPIRV/IR/structure-ops.mlir | 15 +++-
 mlir/test/Target/SPIRV/global-variable.mlir   | 24 +++
 5 files changed, 70 insertions(+), 15 deletions(-)

diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp 
b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
index 2a1d083308282a..66f1d6b2e12206 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
@@ -1163,9 +1163,10 @@ LogicalResult spirv::GlobalVariableOp::verify() {
 // constants and other variables is supported. They could be normal
 // constants in the module scope as well.
 if (!initOp ||
-!isa(initOp)) {
+!isa(initOp)) {
   return emitOpError("initializer must be result of a "
- "spirv.SpecConstant or spirv.GlobalVariable op");
+ "spirv.SpecConstant or spirv.GlobalVariable or "
+ "spirv.SpecConstantCompositeOp op");
 }
   }
 
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp 
b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index 89e2e7ad52fa7d..ccea690a7c3ded 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -637,14 +637,21 @@ 
spirv::Deserializer::processGlobalVariable(ArrayRef operands) {
 
   // Initializer.
   FlatSymbolRefAttr initializer = nullptr;
+  
   if (wordIndex < operands.size()) {
-auto initializerOp = getGlobalVariable(operands[wordIndex]);
-if (!initializerOp) {
-  return emitError(unknownLoc, "unknown  ")
- << operands[wordIndex] << "used as initializer";
-}
+Operation *op = nullptr;
+
+if((op = getGlobalVariable(operands[wordIndex])))
+  initializer = 
SymbolRefAttr::get((dyn_cast(op)).getOperation());
+else if ((op  = getSpecConstant(operands[wordIndex])))
+  initializer = 
SymbolRefAttr::get((dyn_cast(op)).getOperation());
+else if((op = getSpecConstantComposite(operands[wordIndex])))
+  initializer = 
SymbolRefAttr::get((dyn_cast(op)).getOperation());
+else
+  return emitError(unknownLoc,
+"Unknown op used as initializer");
+
 wordIndex++;
-initializer = SymbolRefAttr::get(initializerOp.getOperation());
   }
   if (wordIndex != operands.size()) {
 return emitError(unknownLoc,
diff --git a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp 
b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
index 44538c38a41b83..bd1fc7a84fbd6a 100644
--- a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
+++ b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
@@ -383,12 +383,22 @@ 
Serializer::processGlobalVariableOp(spirv::GlobalVariableOp varOp) {
   operands.push_back(static_cast(varOp.storageClass()));
 
   // Encode initialization.
-  if (auto initializer = varOp.getInitializer()) {
-auto initializerID = getVariableID(*initializer);
-if (!initializerID) {
-  return emitError(varOp.getLoc(),
-   "invalid usage of undefined variable as initializer");
-}
+  if (auto initializerName = varOp.getInitializer()) {
+
+uint32_t initializerID = 0;
+auto init = varOp->getAttrOfType("initializer");
+Operation *initOp = 
SymbolTable::lookupNearestSymbolFrom(varOp->getParentOp(), init.getAttr());
+
+// Check if initializer is GlobalVariable or 
SpecConstant/SpecConstantComposite
+if(isa(initOp))
+  initializerID = getVariableID(*initializerName);
+else
+  initializerID = getSpecConstID(*initializerName);
+
+if (!initializerID)
+return emitError(varOp.getLoc(),
+  "invalid usage of undefined variable as initializer");
+   
 operands.push_back(initializerID);
 elidedAttrs.push_back("initializer");
   }
diff --git a/mlir/test/Dialect/SPIRV/IR/structure-ops.mlir 

[clang] [llvm] [SpecialCaseList] Use glob by default (PR #74809)

2024-01-05 Thread Ellis Hoag via cfe-commits

ellishg wrote:

> This caused some ignorelist changes, e.g.
> 
> 
> 
> `src:*third_party/vulkan_memory_allocator/include/vk_mem_alloc.h`
> 
> 
> 
> didn't work anymore and the opt-out made it work again. Still investigating 
> why.

Not sure if it's the reason, but the `.` in `vk_mem_alloc.h` matches any 
character for regex, but only the literal for glob (use `?` for this). I think 
everything else is the same. 

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


[clang] [llvm] [SpecialCaseList] Use glob by default (PR #74809)

2024-01-05 Thread Arthur Eubanks via cfe-commits

aeubanks wrote:

This caused some ignorelist changes, e.g.

`src:*third_party/vulkan_memory_allocator/include/vk_mem_alloc.h`

didn't work anymore and the opt-out made it work again. Still investigating why.

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


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-05 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

I think I would like some more eyes on this, I don't know if it is obvious to 
me what it means to reallocate a volatile object. 

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


[clang-tools-extra] [clang-tidy] Add check `readability-avoid-return-with-void-value` (PR #76249)

2024-01-05 Thread Danny Mösch via cfe-commits

SimplyDanny wrote:

Thank you, @PiotrZSL, for the reviews and helpful suggestions!

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


[clang-tools-extra] [clang-tidy] Add check `readability-avoid-return-with-void-value` (PR #76249)

2024-01-05 Thread Danny Mösch via cfe-commits

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


[clang-tools-extra] a89141f - [clang-tidy] Add check `readability-avoid-return-with-void-value` (#76249)

2024-01-05 Thread via cfe-commits

Author: Danny Mösch
Date: 2024-01-06T00:14:08+01:00
New Revision: a89141f733cef817c586bb6da0ea69a5a323874e

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

LOG: [clang-tidy] Add check `readability-avoid-return-with-void-value` (#76249)

Added: 
clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.h

clang-tools-extra/docs/clang-tidy/checks/readability/avoid-return-with-void-value.rst

clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp

Modified: 
clang-tools-extra/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
new file mode 100644
index 00..e3400f614fa564
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
@@ -0,0 +1,57 @@
+//===--- AvoidReturnWithVoidValueCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "AvoidReturnWithVoidValueCheck.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static constexpr auto IgnoreMacrosName = "IgnoreMacros";
+static constexpr auto IgnoreMacrosDefault = true;
+
+static constexpr auto StrictModeName = "StrictMode";
+static constexpr auto StrictModeDefault = true;
+
+AvoidReturnWithVoidValueCheck::AvoidReturnWithVoidValueCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreMacros(
+  Options.getLocalOrGlobal(IgnoreMacrosName, IgnoreMacrosDefault)),
+  StrictMode(Options.getLocalOrGlobal(StrictModeName, StrictModeDefault)) 
{}
+
+void AvoidReturnWithVoidValueCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  returnStmt(
+  hasReturnValue(allOf(hasType(voidType()), unless(initListExpr(,
+  optionally(hasParent(compoundStmt().bind("compound_parent"
+  .bind("void_return"),
+  this);
+}
+
+void AvoidReturnWithVoidValueCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
+  if (IgnoreMacros && VoidReturn->getBeginLoc().isMacroID())
+return;
+  if (!StrictMode && !Result.Nodes.getNodeAs("compound_parent"))
+return;
+  diag(VoidReturn->getBeginLoc(), "return statement within a void function "
+  "should not have a specified return value");
+}
+
+void AvoidReturnWithVoidValueCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, IgnoreMacrosName, IgnoreMacros);
+  Options.store(Opts, StrictModeName, StrictMode);
+}
+
+} // namespace clang::tidy::readability

diff  --git 
a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.h 
b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.h
new file mode 100644
index 00..f8148db43cd952
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.h
@@ -0,0 +1,44 @@
+//===--- AvoidReturnWithVoidValueCheck.h - clang-tidy ---*- 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
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDRETURNWITHVOIDVALUECHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDRETURNWITHVOIDVALUECHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::readability {
+
+/// Finds return statements with `void` values used within functions with 
`void`
+/// result types.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/readability/avoid-return-with-void-value.html
+class AvoidReturnWithVoidValueCheck : public ClangTidyCheck {
+public:
+  AvoidReturnWithVoidValueCheck(StringRef Name, ClangTidyContext *Context);
+
+  void 

[clang] [clang][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72235)

2024-01-05 Thread Michael Buch via cfe-commits

Michael137 wrote:

Proposed fix: https://github.com/llvm/llvm-project/pull/77155

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


[libcxx] [llvm] [clang] [compiler-rt] [libc] [libunwind] [tsan] Fallback to top frame (PR #77145)

2024-01-05 Thread Vitaly Buka via cfe-commits

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


[libcxx] [llvm] [clang] [compiler-rt] [libc] [libunwind] [tsan] Fallback to top frame (PR #77145)

2024-01-05 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/77145

>From d3a38ee314802fca37849ae33fa7d445369f0956 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Fri, 5 Jan 2024 14:06:41 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
 =?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/lib/tsan/rtl/tsan_report.cpp | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cpp 
b/compiler-rt/lib/tsan/rtl/tsan_report.cpp
index 35cb6710a54fa4..cdcc20b9758f48 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_report.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_report.cpp
@@ -274,17 +274,13 @@ static ReportStack *ChooseSummaryStack(const ReportDesc 
*rep) {
 }
 
 static bool FrameIsInternal(const SymbolizedStack *frame) {
-  if (frame == 0)
+  if (!frame)
 return false;
   const char *file = frame->info.file;
   const char *module = frame->info.module;
-  if (file != 0 &&
-  (internal_strstr(file, "tsan_interceptors_posix.cpp") ||
-   internal_strstr(file, "tsan_interceptors_memintrinsics.cpp") ||
-   internal_strstr(file, "sanitizer_common_interceptors.inc") ||
-   internal_strstr(file, "tsan_interface_")))
+  if (file && (internal_strstr(file, "/compiler-rt/lib/")))
 return true;
-  if (module != 0 && (internal_strstr(module, "libclang_rt.tsan_")))
+  if (module && (internal_strstr(module, "libclang_rt.")))
 return true;
   return false;
 }

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


[libc] [openmp] [llvm] [flang] [libcxx] [clang] [compiler-rt] [clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2024-01-05 Thread via cfe-commits

EugeneZelenko wrote:

You need to do interactive rebase:

```
git fetch --prune # get latest main and remove local copies deleted branch 
git rebase origin/main # rebase from main
git rebase -i origin/main # interactive rebase, just use fixup command
git rebase --force origin  # push updated branch
```

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


[libcxx] [libunwind] [libc] [llvm] [compiler-rt] [clang] [tsan] Fallback to top frame (PR #77145)

2024-01-05 Thread Vitaly Buka via cfe-commits

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


[clang] [CLANG] Add warning when comparing to INF or NAN in fast math mode. (PR #76873)

2024-01-05 Thread Andy Kaylor via cfe-commits


@@ -13846,6 +13880,37 @@ Sema::CheckReturnValExpr(Expr *RetValExp, QualType 
lhsType,
 CheckPPCMMAType(RetValExp->getType(), ReturnLoc);
 }
 
+/// Diagnose comparison to NAN or INFINITY in fast math modes.
+/// The comparison to NaN or INFINITY is always false in
+/// fast modes: float evaluation will not result in inf or nan.
+void Sema::CheckInfNaNFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS,

andykaylor wrote:

Oh, sorry. I must have copied the "+ " when I checked it. It just looked longer 
than the surrounding text.

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


[libcxx] [libunwind] [libc] [llvm] [compiler-rt] [clang] [NFC][tsan] `ptr != 0` to implicit check (PR #77144)

2024-01-05 Thread Vitaly Buka via cfe-commits

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


[mlir] [openmp] [lld] [libc] [llvm] [libcxx] [flang] [clang] [lldb] [compiler-rt] [clang-tools-extra] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-05 Thread via cfe-commits

zeroomega wrote:

Hi, this change breaks libcxx test on Windows due to unable to find "unistd.h" 
file (which doesn't exist on msvc based environment).

Failed test message and failed commandline: 

```

Failed Tests (8):
  llvm-libc++-static-clangcl.cfg.in :: 
std/input.output/file.streams/fstreams/filebuf.members/native_handle.pass.cpp
  llvm-libc++-static-clangcl.cfg.in :: 
std/input.output/file.streams/fstreams/filebuf/types.pass.cpp
  llvm-libc++-static-clangcl.cfg.in :: 
std/input.output/file.streams/fstreams/fstream.members/native_handle.pass.cpp
  llvm-libc++-static-clangcl.cfg.in :: 
std/input.output/file.streams/fstreams/fstream/types.pass.cpp
  llvm-libc++-static-clangcl.cfg.in :: 
std/input.output/file.streams/fstreams/ifstream.members/native_handle.pass.cpp
  llvm-libc++-static-clangcl.cfg.in :: 
std/input.output/file.streams/fstreams/ifstream/types.pass.cpp
  llvm-libc++-static-clangcl.cfg.in :: 
std/input.output/file.streams/fstreams/ofstream.members/native_handle.pass.cpp
  llvm-libc++-static-clangcl.cfg.in :: 
std/input.output/file.streams/fstreams/ofstream/types.pass.cpp
```

```
Exit Code: 1

Command Output (stdout):
--
# COMPILED WITH
C:/b/s/w/ir/x/w/llvm_build/./bin/clang-cl.exe 
C:\b\s\w\ir\x\w\llvm-llvm-project\libcxx\test\std\input.output\file.streams\fstreams\filebuf.members\native_handle.pass.cpp
 --driver-mode=g++ --target=x86_64-pc-windows-msvc -fms-runtime-lib=static 
-nostdinc++ -I C:/b/s/w/ir/x/w/llvm_build/include/c++/v1 -I 
C:/b/s/w/ir/x/w/llvm_build/include/x86_64-pc-windows-msvc/c++/v1 -I 
C:/b/s/w/ir/x/w/llvm-llvm-project/libcxx/test/support -D_CRT_SECURE_NO_WARNINGS 
-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX 
-std=c++26 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef 
-Wunused-template -Wno-unused-command-line-argument -Wno-attributes 
-Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment 
-Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor 
-Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare 
-Wunused-variable -Wunused-parameter -Wunreachable-code 
-Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions 
-Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete 
-Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 
-D_LIBCPP_ENABLE_EXPERIMENTAL 
-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety 
-Wuser-defined-warnings  -llibc++experimental -nostdlib -L 
C:/b/s/w/ir/x/w/llvm_build/./lib/x86_64-pc-windows-msvc -llibc++ -llibcpmt -o 
C:\b\s\w\ir\x\w\llvm_build\runtimes\runtimes-x86_64-pc-windows-msvc-bins\test\std\input.output\file.streams\fstreams\filebuf.members\Output\native_handle.pass.cpp.dir\t.tmp.exe
# executed command: C:/b/s/w/ir/x/w/llvm_build/./bin/clang-cl.exe 
'C:\b\s\w\ir\x\w\llvm-llvm-project\libcxx\test\std\input.output\file.streams\fstreams\filebuf.members\native_handle.pass.cpp'
 --driver-mode=g++ --target=x86_64-pc-windows-msvc -fms-runtime-lib=static 
-nostdinc++ -I C:/b/s/w/ir/x/w/llvm_build/include/c++/v1 -I 
C:/b/s/w/ir/x/w/llvm_build/include/x86_64-pc-windows-msvc/c++/v1 -I 
C:/b/s/w/ir/x/w/llvm-llvm-project/libcxx/test/support -D_CRT_SECURE_NO_WARNINGS 
-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX 
-std=c++26 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef 
-Wunused-template -Wno-unused-command-line-argument -Wno-attributes 
-Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment 
-Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor 
-Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare 
-Wunused-variable -Wunused-parameter -Wunreachable-code 
-Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions 
-Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete 
-Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 
-D_LIBCPP_ENABLE_EXPERIMENTAL 
-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety 
-Wuser-defined-warnings -llibc++experimental -nostdlib -L 
C:/b/s/w/ir/x/w/llvm_build/./lib/x86_64-pc-windows-msvc -llibc++ -llibcpmt -o 
'C:\b\s\w\ir\x\w\llvm_build\runtimes\runtimes-x86_64-pc-windows-msvc-bins\test\std\input.output\file.streams\fstreams\filebuf.members\Output\native_handle.pass.cpp.dir\t.tmp.exe'
# .---command stderr
# | In file included from 
C:\b\s\w\ir\x\w\llvm-llvm-project\libcxx\test\std\input.output\file.streams\fstreams\filebuf.members\native_handle.pass.cpp:24:
# | In file included from 
C:\b\s\w\ir\x\w\llvm-llvm-project\libcxx\test\std\input.output\file.streams\fstreams\filebuf.members\../native_handle_test_helpers.h:33:
# | 
C:/b/s/w/ir/x/w/llvm-llvm-project/libcxx/test/support\check_assertion.h:22:10: 
fatal error: 'unistd.h' file not found
# |22 | #include 
# |   |  ^~
# | 1 error generated.
# `-
# error: command failed with exit 

[libcxx] [libunwind] [libc] [llvm] [compiler-rt] [clang] [NFC][tsan] `ptr != 0` to implicit check (PR #77144)

2024-01-05 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/77144

>From 878c38dba9d819b79b8db8b3044078839f5a4e55 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Fri, 5 Jan 2024 14:06:37 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
 =?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/lib/tsan/rtl/tsan_report.cpp | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cpp 
b/compiler-rt/lib/tsan/rtl/tsan_report.cpp
index 35cb6710a54fa4..167e4be4fc0e26 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_report.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_report.cpp
@@ -278,13 +278,9 @@ static bool FrameIsInternal(const SymbolizedStack *frame) {
 return false;
   const char *file = frame->info.file;
   const char *module = frame->info.module;
-  if (file != 0 &&
-  (internal_strstr(file, "tsan_interceptors_posix.cpp") ||
-   internal_strstr(file, "tsan_interceptors_memintrinsics.cpp") ||
-   internal_strstr(file, "sanitizer_common_interceptors.inc") ||
-   internal_strstr(file, "tsan_interface_")))
+  if (file != 0 && (internal_strstr(file, "/compiler-rt/lib/")))
 return true;
-  if (module != 0 && (internal_strstr(module, "libclang_rt.tsan_")))
+  if (module != 0 && (internal_strstr(module, "libclang_rt.")))
 return true;
   return false;
 }

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


[clang] [-Wunsafe-buffer-usage] Add a new warning for uses of std::span two-parameter constructors (PR #77148)

2024-01-05 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 d7b4debf98fd740f821bda717de7b807e26ae95a 
54d75df6c413a5b273a059426b00def7437ab525 -- 
clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp 
clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
clang/lib/Analysis/UnsafeBufferUsage.cpp 
clang/lib/Sema/AnalysisBasedWarnings.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index 0d0a2e2b5b..aca1ad9988 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -102,8 +102,8 @@ public:
   /// \return true iff buffer safety is opt-out at `Loc`; false otherwise.
   virtual bool isSafeBufferOptOut(const SourceLocation ) const = 0;
 
-  /// \return true iff unsafe uses in containers should NOT be reported at 
`Loc`;
-  /// false otherwise.
+  /// \return true iff unsafe uses in containers should NOT be reported at
+  /// `Loc`; false otherwise.
   virtual bool
   ignoreUnsafeBufferInContainer(const SourceLocation ) const = 0;
 
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp 
b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 9d1bc9876c..36466d1806 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -26,7 +26,6 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
-#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
 #include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h"
 #include "clang/Analysis/Analyses/CalledOnceCheck.h"
@@ -2258,7 +2257,9 @@ public:
 MsgParam = 1;
   }
 } else if (const auto *CtorExpr = dyn_cast(Operation)) {
-  S.Diag(CtorExpr->getLocation(), 
diag::warn_unsafe_buffer_usage_in_container) << 0;
+  S.Diag(CtorExpr->getLocation(),
+ diag::warn_unsafe_buffer_usage_in_container)
+  << 0;
 } else {
   if (isa(Operation)) {
 // note_unsafe_buffer_operation doesn't have this mode yet.

``




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


[clang] [-Wunsafe-buffer-usage] Add a new warning for uses of std::span two-parameter constructors (PR #77148)

2024-01-05 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Author: Ziqing Luo (ziqingluo-90)


Changes

The PR contains two commits:
1. adding a new waring under a sub-group of `-Wunsafe-buffer-usage`
2. teach the analyzer to be quiet on some benign cases

---

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


6 Files Affected:

- (modified) clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h (+7-1) 
- (modified) clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
(+8) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+3) 
- (modified) clang/lib/Analysis/UnsafeBufferUsage.cpp (+117) 
- (modified) clang/lib/Sema/AnalysisBasedWarnings.cpp (+12-1) 
- (added) 
clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp 
(+136) 


``diff
diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index b28f2c6b99c50e..0d0a2e2b5bc998 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -16,6 +16,7 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/Stmt.h"
+#include "clang/Basic/SourceLocation.h"
 #include "llvm/Support/Debug.h"
 
 namespace clang {
@@ -98,9 +99,14 @@ class UnsafeBufferUsageHandler {
 #endif
 
 public:
-  /// Returns a reference to the `Preprocessor`:
+  /// \return true iff buffer safety is opt-out at `Loc`; false otherwise.
   virtual bool isSafeBufferOptOut(const SourceLocation ) const = 0;
 
+  /// \return true iff unsafe uses in containers should NOT be reported at 
`Loc`;
+  /// false otherwise.
+  virtual bool
+  ignoreUnsafeBufferInContainer(const SourceLocation ) const = 0;
+
   virtual std::string
   getUnsafeBufferUsageAttributeTextAt(SourceLocation Loc,
   StringRef WSSuffix = "") const = 0;
diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
index c9766168836510..07f805ebb11013 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
@@ -18,6 +18,12 @@
 #define WARNING_GADGET(name) GADGET(name)
 #endif
 
+/// A `WARNING_GADGET` subset, where the code pattern of each gadget
+/// corresponds uses of a (possibly hardened) contatiner (e.g., `std::span`).
+#ifndef WARNING_CONTAINER_GADGET
+#define WARNING_CONTAINER_GADGET(name) WARNING_GADGET(name)
+#endif
+
 /// Safe gadgets correspond to code patterns that aren't unsafe but need to be
 /// properly recognized in order to emit correct warnings and fixes over unsafe
 /// gadgets.
@@ -31,6 +37,7 @@ WARNING_GADGET(ArraySubscript)
 WARNING_GADGET(PointerArithmetic)
 WARNING_GADGET(UnsafeBufferUsageAttr)
 WARNING_GADGET(DataInvocation)
+WARNING_CONTAINER_GADGET(SpanTwoParamConstructor) // Uses of `std::span(arg0, 
arg1)`
 FIXABLE_GADGET(ULCArraySubscript)  // `DRE[any]` in an Unspecified 
Lvalue Context
 FIXABLE_GADGET(DerefSimplePtrArithFixable)
 FIXABLE_GADGET(PointerDereference)
@@ -43,4 +50,5 @@ FIXABLE_GADGET(PointerInit)
 
 #undef FIXABLE_GADGET
 #undef WARNING_GADGET
+#undef WARNING_CONTAINER_GADGET
 #undef GADGET
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e54f969c19039d..940de9629d7986 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12075,6 +12075,9 @@ def note_unsafe_buffer_variable_fixit_together : Note<
   "%select{|, and change %2 to safe types to make function %4 bounds-safe}3">;
 def note_safe_buffer_usage_suggestions_disabled : Note<
   "pass -fsafe-buffer-usage-suggestions to receive code hardening 
suggestions">;
+def warn_unsafe_buffer_usage_in_container : Warning<
+  "%select{the two-parameter std::span construction is unsafe as it can 
introduce mismatch between buffer size and the bound information}0">,
+  InGroup, DefaultIgnore;
 #ifndef NDEBUG
 // Not a user-facing diagnostic. Useful for debugging false negatives in
 // -fsafe-buffer-usage-suggestions (i.e. lack of -Wunsafe-buffer-usage fixits).
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 724c4304a07242..55f522c8988625 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -232,6 +232,11 @@ AST_MATCHER_P(Stmt, notInSafeBufferOptOut, const 
UnsafeBufferUsageHandler *,
   return !Handler->isSafeBufferOptOut(Node.getBeginLoc());
 }
 
+AST_MATCHER_P(Stmt, ignoreUnsafeBufferInContainer,
+  const UnsafeBufferUsageHandler *, Handler) {
+  return Handler->ignoreUnsafeBufferInContainer(Node.getBeginLoc());
+}
+
 AST_MATCHER_P(CastExpr, castSubExpr, internal::Matcher, 

[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

2024-01-05 Thread Owen Pan via cfe-commits


@@ -5151,6 +5151,14 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
,
 return true;
   if (Left.IsUnterminatedLiteral)
 return true;
+  // FIXME: Breaking after newlines seems useful in general. Turn this into an
+  // option and recognize more cases like endl etc, and break independent of
+  // what comes after operator lessless.
+  if (Right.is(tok::lessless) && Right.Next &&
+  Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) &&
+  Left.TokenText.ends_with("\\n\"")) {

owenca wrote:

We can also handle `\n` and `endl` now. For example:
```suggestion
  Right.Next->is(tok::string_literal) &&
  ((Left.is(tok::string_literal) && Left.TokenText.ends_with("\\n\"")) ||
   Left.TokenText == "'\\n'" || Left.TokenText == "endl")) {
```

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


[clang] [-Wunsafe-buffer-usage] Add a new warning for uses of std::span two-parameter constructors (PR #77148)

2024-01-05 Thread Ziqing Luo via cfe-commits

https://github.com/ziqingluo-90 created 
https://github.com/llvm/llvm-project/pull/77148

The PR contains two commits:
1. adding a new waring under a sub-group of `-Wunsafe-buffer-usage`
2. teach the analyzer to be quiet on some benign cases

>From 475d918fb0b5991be7ce559ef6ef7f20c6b231e5 Mon Sep 17 00:00:00 2001
From: ziqingluo-90 
Date: Fri, 5 Jan 2024 13:39:39 -0800
Subject: [PATCH 1/2] [-Wunsafe-buffer-usage] Add a new warning for use of
 two-parameter std::span constructors

Constructing `std::span` objects with the two parameter constructors
could introduce mismatched bounds information, which defeats the
purpose of using `std::span`.  Therefore, we warn every use of such
constructors.

We also plan to incrementally teach `-Wunsafe-buffer-usage` about benign
usages of those constructors.

rdar://115817781
---
 .../Analysis/Analyses/UnsafeBufferUsage.h |   8 +-
 .../Analyses/UnsafeBufferUsageGadgets.def |   8 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/lib/Analysis/UnsafeBufferUsage.cpp  |  46 +++
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |  13 +-
 ...ffer-usage-in-container-span-construct.cpp | 118 ++
 6 files changed, 194 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-in-container-span-construct.cpp

diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index b28f2c6b99c50e..0d0a2e2b5bc998 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -16,6 +16,7 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/Stmt.h"
+#include "clang/Basic/SourceLocation.h"
 #include "llvm/Support/Debug.h"
 
 namespace clang {
@@ -98,9 +99,14 @@ class UnsafeBufferUsageHandler {
 #endif
 
 public:
-  /// Returns a reference to the `Preprocessor`:
+  /// \return true iff buffer safety is opt-out at `Loc`; false otherwise.
   virtual bool isSafeBufferOptOut(const SourceLocation ) const = 0;
 
+  /// \return true iff unsafe uses in containers should NOT be reported at 
`Loc`;
+  /// false otherwise.
+  virtual bool
+  ignoreUnsafeBufferInContainer(const SourceLocation ) const = 0;
+
   virtual std::string
   getUnsafeBufferUsageAttributeTextAt(SourceLocation Loc,
   StringRef WSSuffix = "") const = 0;
diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
index c9766168836510..07f805ebb11013 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
@@ -18,6 +18,12 @@
 #define WARNING_GADGET(name) GADGET(name)
 #endif
 
+/// A `WARNING_GADGET` subset, where the code pattern of each gadget
+/// corresponds uses of a (possibly hardened) contatiner (e.g., `std::span`).
+#ifndef WARNING_CONTAINER_GADGET
+#define WARNING_CONTAINER_GADGET(name) WARNING_GADGET(name)
+#endif
+
 /// Safe gadgets correspond to code patterns that aren't unsafe but need to be
 /// properly recognized in order to emit correct warnings and fixes over unsafe
 /// gadgets.
@@ -31,6 +37,7 @@ WARNING_GADGET(ArraySubscript)
 WARNING_GADGET(PointerArithmetic)
 WARNING_GADGET(UnsafeBufferUsageAttr)
 WARNING_GADGET(DataInvocation)
+WARNING_CONTAINER_GADGET(SpanTwoParamConstructor) // Uses of `std::span(arg0, 
arg1)`
 FIXABLE_GADGET(ULCArraySubscript)  // `DRE[any]` in an Unspecified 
Lvalue Context
 FIXABLE_GADGET(DerefSimplePtrArithFixable)
 FIXABLE_GADGET(PointerDereference)
@@ -43,4 +50,5 @@ FIXABLE_GADGET(PointerInit)
 
 #undef FIXABLE_GADGET
 #undef WARNING_GADGET
+#undef WARNING_CONTAINER_GADGET
 #undef GADGET
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e54f969c19039d..940de9629d7986 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12075,6 +12075,9 @@ def note_unsafe_buffer_variable_fixit_together : Note<
   "%select{|, and change %2 to safe types to make function %4 bounds-safe}3">;
 def note_safe_buffer_usage_suggestions_disabled : Note<
   "pass -fsafe-buffer-usage-suggestions to receive code hardening 
suggestions">;
+def warn_unsafe_buffer_usage_in_container : Warning<
+  "%select{the two-parameter std::span construction is unsafe as it can 
introduce mismatch between buffer size and the bound information}0">,
+  InGroup, DefaultIgnore;
 #ifndef NDEBUG
 // Not a user-facing diagnostic. Useful for debugging false negatives in
 // -fsafe-buffer-usage-suggestions (i.e. lack of -Wunsafe-buffer-usage fixits).
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 724c4304a07242..3b6d69cac1afd8 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ 

[llvm] [clang] [Clang] Update Unicode version to 15.1 (PR #77147)

2024-01-05 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 f22dc88759a53d4224c17d3833a359ef5674b4ea 
83314b0226f0585c3f689c8fdf556e45dbec207c -- clang/lib/Lex/UnicodeCharSets.h 
clang/test/Lexer/unicode.c llvm/lib/Support/Unicode.cpp 
llvm/lib/Support/UnicodeCaseFold.cpp 
llvm/lib/Support/UnicodeNameToCodepoint.cpp 
llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp 
llvm/unittests/Support/UnicodeTest.cpp 
llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/unittests/Support/UnicodeTest.cpp 
b/llvm/unittests/Support/UnicodeTest.cpp
index 66ff11d30f..35d4f1bc81 100644
--- a/llvm/unittests/Support/UnicodeTest.cpp
+++ b/llvm/unittests/Support/UnicodeTest.cpp
@@ -147,7 +147,6 @@ TEST(Unicode, nameToCodepointStrict) {
   EXPECT_EQ(0x31350u, map("CJK UNIFIED IDEOGRAPH-31350")); // Unicode 15.0
   EXPECT_EQ(0x2EBF0u, map("CJK UNIFIED IDEOGRAPH-2EBF0")); // Unicode 15.1
 
-
   EXPECT_EQ(0xAC00u, map("HANGUL SYLLABLE GA"));
   EXPECT_EQ(0xAC14u, map("HANGUL SYLLABLE GASS"));
   EXPECT_EQ(0xAC2Bu, map("HANGUL SYLLABLE GAELH"));
@@ -170,7 +169,8 @@ TEST(Unicode, nameToCodepointStrict) {
   "ABOVE WITH ALEF MAKSURA ISOLATED FORM"));
   EXPECT_EQ(0x11F04u, map("KAWI LETTER A")); // Unicode 15.0
   EXPECT_EQ(0x1FA77u, map("PINK HEART")); // Unicode 15.0
-  EXPECT_EQ(0x2FFFu, map("IDEOGRAPHIC DESCRIPTION CHARACTER ROTATION")); // 
Unicode 15.1
+  EXPECT_EQ(0x2FFFu,
+map("IDEOGRAPHIC DESCRIPTION CHARACTER ROTATION")); // Unicode 15.1
 
   // Aliases
   EXPECT_EQ(0xu, map("NULL"));

``




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


[flang] [compiler-rt] [llvm] [lldb] [clang-tools-extra] [libunwind] [clang] [libcxx] [libc] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,71 @@
+// -*- 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
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/as_const.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+namespace __ranges_iota {
+struct __iota_fn {
+private:
+  // Private helper function
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> 
__iota_impl(_Out __first, _Sent __last, _Tp __value) {
+while (__first != __last) {
+  *__first = std::as_const(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), std::move(__value)};
+  }

cjdb wrote:

Please move this into the iterator-based `operator()` and have the range-based 
one call that. As it's currently implemented, additional and unnecessary moves 
need to happen, and we also incur some debug overhead that I'd rather avoid.

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


[llvm] [clang] [Clang] Update Unicode version to 15.1 (PR #77147)

2024-01-05 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-llvm-support

Author: cor3ntin (cor3ntin)


Changes

This update all of our Unicode tables to Unicode 15.1. This is a minor version 
so only a relatively small numbers of characters are added, mainly ideographs

https://www.unicode.org/versions/Unicode15.1.0/#Appendices_nb

---

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


9 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Lex/UnicodeCharSets.h (+68-66) 
- (modified) clang/test/Lexer/unicode.c (+4-3) 
- (modified) llvm/lib/Support/Unicode.cpp (+171-171) 
- (modified) llvm/lib/Support/UnicodeCaseFold.cpp (+11-2) 
- (modified) llvm/lib/Support/UnicodeNameToCodepoint.cpp (+2-1) 
- (modified) llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp 
(+19816-19812) 
- (modified) llvm/unittests/Support/UnicodeTest.cpp (+3) 
- (modified) llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp (+3-3) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9b6e00b231216b..1a0fad1d9de8d4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -238,6 +238,8 @@ Non-comprehensive list of changes in this release
 
 * Added ``#pragma clang fp reciprocal``.
 
+* The version of Unicode used by Clang (primarily to parse identifiers) has 
been updated to 15.1.
+
 New Compiler Flags
 --
 
diff --git a/clang/lib/Lex/UnicodeCharSets.h b/clang/lib/Lex/UnicodeCharSets.h
index 5316d2540b76ce..9fee964562fe74 100644
--- a/clang/lib/Lex/UnicodeCharSets.h
+++ b/clang/lib/Lex/UnicodeCharSets.h
@@ -10,7 +10,7 @@
 
 #include "llvm/Support/UnicodeCharRanges.h"
 
-// Unicode 15.0 XID_Start
+// Unicode 15.1 XID_Start
 static const llvm::sys::UnicodeCharRange XIDStartRanges[] = {
 {0x0041, 0x005A},   {0x0061, 0x007A},   {0x00AA, 0x00AA},
 {0x00B5, 0x00B5},   {0x00BA, 0x00BA},   {0x00C0, 0x00D6},
@@ -233,9 +233,10 @@ static const llvm::sys::UnicodeCharRange XIDStartRanges[] 
= {
 {0x1EE8B, 0x1EE9B}, {0x1EEA1, 0x1EEA3}, {0x1EEA5, 0x1EEA9},
 {0x1EEAB, 0x1EEBB}, {0x2, 0x2A6DF}, {0x2A700, 0x2B739},
 {0x2B740, 0x2B81D}, {0x2B820, 0x2CEA1}, {0x2CEB0, 0x2EBE0},
-{0x2F800, 0x2FA1D}, {0x3, 0x3134A}, {0x31350, 0x323AF}};
+{0x2EBF0, 0x2EE5D}, {0x2F800, 0x2FA1D}, {0x3, 0x3134A},
+{0x31350, 0x323AF}};
 
-// Unicode 15.0 XID_Continue, excluding XID_Start
+// Unicode 15.1 XID_Continue, excluding XID_Start
 // The Unicode Property XID_Continue is a super set of XID_Start.
 // To save Space, the table below only contains the codepoints
 // that are not also in XID_Start.
@@ -302,69 +303,70 @@ static const llvm::sys::UnicodeCharRange 
XIDContinueRanges[] = {
 {0x203F, 0x2040},   {0x2054, 0x2054},   {0x20D0, 0x20DC},
 {0x20E1, 0x20E1},   {0x20E5, 0x20F0},   {0x2CEF, 0x2CF1},
 {0x2D7F, 0x2D7F},   {0x2DE0, 0x2DFF},   {0x302A, 0x302F},
-{0x3099, 0x309A},   {0xA620, 0xA629},   {0xA66F, 0xA66F},
-{0xA674, 0xA67D},   {0xA69E, 0xA69F},   {0xA6F0, 0xA6F1},
-{0xA802, 0xA802},   {0xA806, 0xA806},   {0xA80B, 0xA80B},
-{0xA823, 0xA827},   {0xA82C, 0xA82C},   {0xA880, 0xA881},
-{0xA8B4, 0xA8C5},   {0xA8D0, 0xA8D9},   {0xA8E0, 0xA8F1},
-{0xA8FF, 0xA909},   {0xA926, 0xA92D},   {0xA947, 0xA953},
-{0xA980, 0xA983},   {0xA9B3, 0xA9C0},   {0xA9D0, 0xA9D9},
-{0xA9E5, 0xA9E5},   {0xA9F0, 0xA9F9},   {0xAA29, 0xAA36},
-{0xAA43, 0xAA43},   {0xAA4C, 0xAA4D},   {0xAA50, 0xAA59},
-{0xAA7B, 0xAA7D},   {0xAAB0, 0xAAB0},   {0xAAB2, 0xAAB4},
-{0xAAB7, 0xAAB8},   {0xAABE, 0xAABF},   {0xAAC1, 0xAAC1},
-{0xAAEB, 0xAAEF},   {0xAAF5, 0xAAF6},   {0xABE3, 0xABEA},
-{0xABEC, 0xABED},   {0xABF0, 0xABF9},   {0xFB1E, 0xFB1E},
-{0xFE00, 0xFE0F},   {0xFE20, 0xFE2F},   {0xFE33, 0xFE34},
-{0xFE4D, 0xFE4F},   {0xFF10, 0xFF19},   {0xFF3F, 0xFF3F},
-{0xFF9E, 0xFF9F},   {0x101FD, 0x101FD}, {0x102E0, 0x102E0},
-{0x10376, 0x1037A}, {0x104A0, 0x104A9}, {0x10A01, 0x10A03},
-{0x10A05, 0x10A06}, {0x10A0C, 0x10A0F}, {0x10A38, 0x10A3A},
-{0x10A3F, 0x10A3F}, {0x10AE5, 0x10AE6}, {0x10D24, 0x10D27},
-{0x10D30, 0x10D39}, {0x10EAB, 0x10EAC}, {0x10EFD, 0x10EFF},
-{0x10F46, 0x10F50}, {0x10F82, 0x10F85}, {0x11000, 0x11002},
-{0x11038, 0x11046}, {0x11066, 0x11070}, {0x11073, 0x11074},
-{0x1107F, 0x11082}, {0x110B0, 0x110BA}, {0x110C2, 0x110C2},
-{0x110F0, 0x110F9}, {0x11100, 0x11102}, {0x11127, 0x11134},
-{0x11136, 0x1113F}, {0x11145, 0x11146}, {0x11173, 0x11173},
-{0x11180, 0x11182}, {0x111B3, 0x111C0}, {0x111C9, 0x111CC},
-{0x111CE, 0x111D9}, {0x1122C, 0x11237}, {0x1123E, 0x1123E},
-{0x11241, 0x11241}, {0x112DF, 0x112EA}, {0x112F0, 0x112F9},
-{0x11300, 0x11303}, {0x1133B, 0x1133C}, {0x1133E, 0x11344},
-{0x11347, 0x11348}, {0x1134B, 0x1134D}, {0x11357, 0x11357},
-{0x11362, 0x11363}, {0x11366, 0x1136C}, {0x11370, 0x11374},
-{0x11435, 0x11446}, 

[libcxx] [flang] [libunwind] [libc] [llvm] [lldb] [clang-tools-extra] [compiler-rt] [clang] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -1161,9 +1185,11 @@ struct Proxy {
 return lhs.data == rhs.data;
   }
 
-  friend constexpr auto operator<=>(const Proxy&, const Proxy&)
-requires (std::three_way_comparable && !std::is_reference_v)
-  = default;
+  friend constexpr auto operator<=>(const Proxy& lhs, const Proxy& rhs)
+requires(std::three_way_comparable && !std::is_reference_v)
+  {
+return lhs.data <=> rhs.data;
+  };

cjdb wrote:

What is the intention of this change?

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


[clang-tools-extra] [libc] [llvm] [libunwind] [flang] [lldb] [libcxx] [clang] [compiler-rt] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -1172,6 +1198,22 @@ struct Proxy {
 requires std::three_way_comparable_with, std::decay_t> {
 return lhs.data <=> rhs.data;
   }
+
+  // Needed to allow certain types to be weakly_incremental
+  constexpr Proxy& operator++()
+requires(HasPreIncrementOp)
+  {
+++data;
+return *this;
+  }
+
+  constexpr Proxy operator++(int)
+requires(HasPostIncrementOp)
+  {
+Proxy tmp = *this;
+operator++();
+return tmp;
+  }

cjdb wrote:

Please use `std::weakly_incrementable` and `std::incrementable`. You'll also 
need to support `void operator++(int)` for when a type is weakly 
incremenetable, but not incrementable.

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


[llvm] [compiler-rt] [libcxx] [lldb] [libunwind] [flang] [libc] [clang-tools-extra] [clang] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits

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


[libcxx] [compiler-rt] [clang-tools-extra] [libc] [clang] [flang] [lldb] [llvm] [libunwind] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,171 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// Testing std::ranges::iota
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+#include 
+#include 
+#include 
+#include 
+#include  // TODO RM
+
+#include "test_macros.h"
+#include "test_iterators.h"
+#include "almost_satisfies_types.h"
+
+//
+// Testing constraints
+//
+
+// Concepts to check different overloads of std::ranges::iota
+template 
+concept HasIotaIter = requires(Iter&& iter, Sent&& sent, Value&& val) {
+  std::ranges::iota(std::forward(iter), std::forward(sent), 
std::forward(val));
+};
+
+template 
+concept HasIotaRange =
+requires(Range&& range, Value&& val) { 
std::ranges::iota(std::forward(range), std::forward(val)); };
+
+// Test constraints of the iterator/sentinel overload
+// ==
+static_assert(HasIotaIter);
+
+// !input_or_output_iterator
+static_assert(!HasIotaIter);
+
+// !sentinel_for
+static_assert(!HasIotaIter);
+static_assert(!HasIotaIter);
+
+// !weakly_incrementable
+static_assert(!HasIotaIter);
+
+// !indirectly writable 
+static_assert(!HasIotaIter);
+
+// Test constraints for the range overload
+// ===
+static_assert(HasIotaRange, int>);
+
+// !weakly_incrementable
+static_assert(!HasIotaRange, 
WeaklyIncrementableNotMovable>);
+
+// !ranges::output_range
+static_assert(!HasIotaRange, 
OutputIteratorNotIndirectlyWritable>);
+
+//
+// Testing results
+//
+
+struct DangerousCopyAssign {
+  int val;
+  using difference_type = int;
+
+  constexpr explicit DangerousCopyAssign(int v) : val(v) {}
+
+  // Needed in postfix
+  constexpr DangerousCopyAssign(DangerousCopyAssign const& other) { this->val 
= other.val; }
+
+  // mischievious copy assignment that we won't use if the
+  // std::as_const inside ranges::iota isn't working, this should perturb the
+  // results
+  constexpr DangerousCopyAssign& operator=(DangerousCopyAssign& a) {
+++a.val;
+this->val = a.val;
+return *this;
+  }
+
+  // safe copy assignment std::as_const inside ranges::iota should ensure this
+  // overload gets called
+  constexpr DangerousCopyAssign& operator=(DangerousCopyAssign const& a) {
+this->val = a.val;
+return *this;
+  }
+
+  constexpr bool operator==(DangerousCopyAssign const& rhs) { return this->val 
== rhs.val; }
+
+  // prefix
+  constexpr DangerousCopyAssign& operator++() {
+++(this->val);
+return *this;
+  }
+
+  // postfix
+  constexpr DangerousCopyAssign operator++(int) {
+auto tmp = *this;
+++this->val;
+return tmp;
+  }
+};
+
+template 
+constexpr void test_result(std::array input, T starting_value, 
std::array const expected) {
+  { // (iterator, sentinel) overload
+auto in_begin = Iter(input.data());
+auto in_end   = Sent(Iter(input.data() + input.size()));
+std::same_as> decltype(auto) result 
=
+std::ranges::iota(std::move(in_begin), std::move(in_end), 
starting_value);
+assert(result.out == in_end);
+if constexpr (expected.size() > 0) {
+  assert(result.value == expected.back() + 1);
+} else {
+  assert(result.value == starting_value);
+}

cjdb wrote:

Please avoid using logic in test cases.

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


[flang] [libcxx] [libc] [clang-tools-extra] [llvm] [libunwind] [lldb] [clang] [compiler-rt] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,71 @@
+// -*- 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
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/as_const.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+namespace __ranges_iota {
+struct __iota_fn {
+private:
+  // Private helper function
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> 
__iota_impl(_Out __first, _Sent __last, _Tp __value) {
+while (__first != __last) {
+  *__first = std::as_const(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), std::move(__value)};
+  }
+
+public:
+  // Public facing interfaces
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> 
operator()(_Out __first, _Sent __last, _Tp __value) {
+return __iota_impl(std::move(__first), std::move(__last), 
std::move(__value));
+  }
+
+  template  _Range>
+  _LIBCPP_HIDE_FROM_ABI static constexpr 
iota_result, _Tp>
+  operator()(_Range&& __r, _Tp __value) {
+return __iota_impl(ranges::begin(__r), ranges::end(__r), 
std::move(__value));
+  }
+};
+} // namespace __ranges_iota
+
+inline namespace __cpo {

cjdb wrote:

Similar to the `__iota` namespace, this is likely going to be removed. Please 
track the discussion in #76542.

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


[clang-tools-extra] [flang] [libunwind] [libc] [llvm] [lldb] [libcxx] [compiler-rt] [clang] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -1149,9 +1171,11 @@ struct Proxy {
   // Calling swap(Proxy{}, Proxy{}) would fail (pass prvalues)
 
   // Compare operators are defined for the convenience of the tests
-  friend constexpr bool operator==(const Proxy&, const Proxy&)
-requires (std::equality_comparable && !std::is_reference_v)
-  = default;
+  friend constexpr bool operator==(const Proxy& lhs, const Proxy& rhs)
+requires(std::equality_comparable && !std::is_reference_v)
+  {
+return lhs.data == rhs.data;
+  };

cjdb wrote:

What is the intention of this change?

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


[libunwind] [clang] [clang-tools-extra] [llvm] [flang] [compiler-rt] [libcxx] [libc] [lldb] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,71 @@
+// -*- 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
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/as_const.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+namespace __ranges_iota {

cjdb wrote:

This namespace isn't necessary, and I'm working on a patch to remove the ones 
that are already checked in. Since this patch is happening concurrently, would 
you mind removing this namespace here?

Alternatively, you can track #76543 and hold off removing this until that lands 
in main.

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


[libunwind] [lldb] [flang] [libc] [llvm] [clang-tools-extra] [clang] [libcxx] [compiler-rt] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -1083,6 +1083,27 @@ rvalue_iterator(T*) -> rvalue_iterator;
 
 static_assert(std::random_access_iterator>);
 
+// The ProxyDiffTBase allows us to conditionally specify 
Proxy::difference_type
+// which we need in certain situations. For example when we want
+// std::weakly_incrementable> to be true.
+template 
+struct ProxyDiffTBase {};
+
+template 
+  requires requires { std::iter_difference_t{}; }
+struct ProxyDiffTBase {
+  using difference_type = std::iter_difference_t;
+};
+
+// These concepts allow us to conditionally add the pre-/postfix operators
+// when T also supports those member functions. Like ProxyDiffTBase, this
+// is necessary when we want std::weakly_incrementable> to be true.
+template 
+concept HasPreIncrementOp = requires(T const& obj) { ++obj; };
+
+template 
+concept HasPostIncrementOp = requires(T const& obj) { obj++; };
+

cjdb wrote:

These may be better off in a local header, since they're very 
`ranges::iota`-specific.

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


[flang] [clang] [lldb] [libcxx] [libc] [libunwind] [llvm] [clang-tools-extra] [compiler-rt] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,171 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// Testing std::ranges::iota
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+#include 
+#include 
+#include 
+#include 
+#include  // TODO RM
+
+#include "test_macros.h"
+#include "test_iterators.h"
+#include "almost_satisfies_types.h"
+
+//
+// Testing constraints
+//
+
+// Concepts to check different overloads of std::ranges::iota
+template 
+concept HasIotaIter = requires(Iter&& iter, Sent&& sent, Value&& val) {
+  std::ranges::iota(std::forward(iter), std::forward(sent), 
std::forward(val));
+};
+
+template 
+concept HasIotaRange =
+requires(Range&& range, Value&& val) { 
std::ranges::iota(std::forward(range), std::forward(val)); };
+
+// Test constraints of the iterator/sentinel overload
+// ==
+static_assert(HasIotaIter);
+
+// !input_or_output_iterator
+static_assert(!HasIotaIter);
+
+// !sentinel_for
+static_assert(!HasIotaIter);
+static_assert(!HasIotaIter);
+
+// !weakly_incrementable
+static_assert(!HasIotaIter);
+
+// !indirectly writable 
+static_assert(!HasIotaIter);
+
+// Test constraints for the range overload
+// ===
+static_assert(HasIotaRange, int>);
+
+// !weakly_incrementable
+static_assert(!HasIotaRange, 
WeaklyIncrementableNotMovable>);
+
+// !ranges::output_range
+static_assert(!HasIotaRange, 
OutputIteratorNotIndirectlyWritable>);
+
+//
+// Testing results
+//
+
+struct DangerousCopyAssign {
+  int val;
+  using difference_type = int;
+
+  constexpr explicit DangerousCopyAssign(int v) : val(v) {}
+
+  // Needed in postfix
+  constexpr DangerousCopyAssign(DangerousCopyAssign const& other) { this->val 
= other.val; }
+
+  // mischievious copy assignment that we won't use if the
+  // std::as_const inside ranges::iota isn't working, this should perturb the
+  // results
+  constexpr DangerousCopyAssign& operator=(DangerousCopyAssign& a) {
+++a.val;
+this->val = a.val;
+return *this;
+  }
+
+  // safe copy assignment std::as_const inside ranges::iota should ensure this
+  // overload gets called
+  constexpr DangerousCopyAssign& operator=(DangerousCopyAssign const& a) {
+this->val = a.val;
+return *this;
+  }
+
+  constexpr bool operator==(DangerousCopyAssign const& rhs) { return this->val 
== rhs.val; }
+
+  // prefix
+  constexpr DangerousCopyAssign& operator++() {
+++(this->val);
+return *this;
+  }
+
+  // postfix
+  constexpr DangerousCopyAssign operator++(int) {
+auto tmp = *this;
+++this->val;
+return tmp;
+  }
+};
+
+template 
+constexpr void test_result(std::array input, T starting_value, 
std::array const expected) {
+  { // (iterator, sentinel) overload
+auto in_begin = Iter(input.data());
+auto in_end   = Sent(Iter(input.data() + input.size()));
+std::same_as> decltype(auto) result 
=
+std::ranges::iota(std::move(in_begin), std::move(in_end), 
starting_value);
+assert(result.out == in_end);
+if constexpr (expected.size() > 0) {
+  assert(result.value == expected.back() + 1);
+} else {
+  assert(result.value == starting_value);
+}
+assert(std::ranges::equal(input, expected));
+  }
+
+  // The range overload adds the additional constraint that it must be an 
outputrange
+  // so skip this for the input iterators we test
+  if constexpr (!std::is_same_v> &&
+!std::is_same_v>) { // (range) 
overload
+auto in_begin = Iter(input.data());
+auto in_end   = Sent(Iter(input.data() + input.size()));
+auto range= std::ranges::subrange(std::move(in_begin), 
std::move(in_end));
+
+std::same_as> decltype(auto) result 
=
+std::ranges::iota(range, starting_value);
+assert(result.out == in_end);
+assert(result.value == starting_value + N);
+assert(std::ranges::equal(input, expected));
+  }

cjdb wrote:

Please move this conditional logic into a separate test case.

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


[clang] [lldb] [llvm] [compiler-rt] [libcxx] [libc] [clang-tools-extra] [flang] [libunwind] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits

https://github.com/cjdb requested changes to this pull request.

Thanks for working on this, it's an important algorithm to have. I've left some 
comments, but would like to see this merged by the end of January.

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


[clang-tools-extra] [clang-tidy] Add check `readability-avoid-return-with-void-value` (PR #76249)

2024-01-05 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/76249

From 16b877e782951293a67a819441a3910f19bc24ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Fri, 22 Dec 2023 17:09:59 +0100
Subject: [PATCH 01/16] [clang-tidy] Add check
 readability-return-expression-in-void-function

---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../readability/ReadabilityTidyModule.cpp |  3 ++
 .../ReturnExpressionInVoidFunctionCheck.cpp   | 31 +++
 .../ReturnExpressionInVoidFunctionCheck.h | 30 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  7 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../return-expression-in-void-function.rst| 30 ++
 .../return-expression-in-void-function.cpp| 23 ++
 8 files changed, 126 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/return-expression-in-void-function.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/return-expression-in-void-function.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a4617..7d0399ed901267 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangTidyReadabilityModule
   RedundantStringCStrCheck.cpp
   RedundantStringInitCheck.cpp
   ReferenceToConstructedTemporaryCheck.cpp
+  ReturnExpressionInVoidFunctionCheck.cpp
   SimplifyBooleanExprCheck.cpp
   SimplifySubscriptExprCheck.cpp
   StaticAccessedThroughInstanceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e641432060..2a9134071b9a72 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -45,6 +45,7 @@
 #include "RedundantStringCStrCheck.h"
 #include "RedundantStringInitCheck.h"
 #include "ReferenceToConstructedTemporaryCheck.h"
+#include "ReturnExpressionInVoidFunctionCheck.h"
 #include "SimplifyBooleanExprCheck.h"
 #include "SimplifySubscriptExprCheck.h"
 #include "StaticAccessedThroughInstanceCheck.h"
@@ -119,6 +120,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-redundant-preprocessor");
 CheckFactories.registerCheck(
 "readability-reference-to-constructed-temporary");
+CheckFactories.registerCheck(
+"readability-return-expression-in-void-function");
 CheckFactories.registerCheck(
 "readability-simplify-subscript-expr");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
new file mode 100644
index 00..2308d0782ae1c3
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
@@ -0,0 +1,31 @@
+//===--- ReturnExpressionInVoidFunctionCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ReturnExpressionInVoidFunctionCheck.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void ReturnExpressionInVoidFunctionCheck::registerMatchers(
+MatchFinder *Finder) {
+  Finder->addMatcher(
+  returnStmt(hasReturnValue(hasType(voidType(.bind("void_return"),
+  this);
+}
+
+void ReturnExpressionInVoidFunctionCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
+  diag(VoidReturn->getBeginLoc(), "return statements should not return void");
+}
+
+} // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
new file mode 100644
index 00..e28f9cebd2620e
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
@@ -0,0 +1,30 @@
+//===--- ReturnExpressionInVoidFunctionCheck.h - clang-tidy -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with 

[clang] [CLANG] Add warning when comparing to INF or NAN in fast math mode. (PR #76873)

2024-01-05 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

> Expanding the scope a bit, it would also be useful to have warnings for 
> constant NaN or Inf values passed as arguments or used in binary operations.

Added that.

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


[clang] [CLANG] Add warning when comparing to INF or NAN in fast math mode. (PR #76873)

2024-01-05 Thread Zahira Ammarguellat via cfe-commits


@@ -13044,9 +13044,12 @@ static QualType checkArithmeticOrEnumeralCompare(Sema 
, ExprResult ,
   if (Type->isAnyComplexType() && BinaryOperator::isRelationalOp(Opc))
 return S.InvalidOperands(Loc, LHS, RHS);
 
-  // Check for comparisons of floating point operands using != and ==.
-  if (Type->hasFloatingRepresentation())
+  if (Type->hasFloatingRepresentation()) {
+// Check for comparisons to NAN or INFINITY in fast math mode.
+S.CheckInfNaNFloatComparison(Loc, LHS.get(), RHS.get(), Opc);

zahiraam wrote:

Done.

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


[clang] [CLANG] Add warning when comparing to INF or NAN in fast math mode. (PR #76873)

2024-01-05 Thread Zahira Ammarguellat via cfe-commits


@@ -13846,6 +13880,37 @@ Sema::CheckReturnValExpr(Expr *RetValExp, QualType 
lhsType,
 CheckPPCMMAType(RetValExp->getType(), ReturnLoc);
 }
 
+/// Diagnose comparison to NAN or INFINITY in fast math modes.
+/// The comparison to NaN or INFINITY is always false in
+/// fast modes: float evaluation will not result in inf or nan.
+void Sema::CheckInfNaNFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS,
+  BinaryOperatorKind Opcode) {
+  Expr *LeftExprSansParen = LHS->IgnoreParenImpCasts();
+  Expr *RightExprSansParen = RHS->IgnoreParenImpCasts();
+
+  FPOptions FPO = LHS->getFPFeaturesInEffect(getLangOpts());
+  bool NoHonorNaNs = FPO.getNoHonorNaNs();
+  bool NoHonorInfs = FPO.getNoHonorInfs();
+  llvm::APFloat Value(0.0);
+  bool IsConstant;
+  IsConstant = !LHS->isValueDependent() &&

zahiraam wrote:

Done.

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


[clang] [CLANG] Add warning when comparing to INF or NAN in fast math mode. (PR #76873)

2024-01-05 Thread Zahira Ammarguellat via cfe-commits


@@ -13846,6 +13880,37 @@ Sema::CheckReturnValExpr(Expr *RetValExp, QualType 
lhsType,
 CheckPPCMMAType(RetValExp->getType(), ReturnLoc);
 }
 
+/// Diagnose comparison to NAN or INFINITY in fast math modes.
+/// The comparison to NaN or INFINITY is always false in
+/// fast modes: float evaluation will not result in inf or nan.
+void Sema::CheckInfNaNFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS,

zahiraam wrote:

It's 79 chars long.

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


[clang] [CLANG] Add warning when comparing to INF or NAN in fast math mode. (PR #76873)

2024-01-05 Thread Zahira Ammarguellat via cfe-commits


@@ -2267,6 +2273,16 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   case Builtin::BI__builtin_signbit:
   case Builtin::BI__builtin_signbitf:
   case Builtin::BI__builtin_signbitl:
+FPO = TheCall->getFPFeaturesInEffect(getLangOpts());

zahiraam wrote:

Done.

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


[clang] [libcxx] [flang] [llvm] [compiler-rt] [clang-tools-extra] [openmp] [libc] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2024-01-05 Thread via cfe-commits

pizzud wrote:

Not sure how to squash properly; I tried rebasing but all the commits on the 
main branch snuck in to the history and I'm quite new to git. If it would be 
preferred I can store this off as a patch and open up a new PR. Sorry for all 
the hassle with the merges!

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


[clang] [clang][Driver] Don't warn when -nostdinc and -nostdinc++ are both specified (PR #77130)

2024-01-05 Thread Jonathon Penix via cfe-commits

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


[clang] f1d75d0 - [clang][Driver] Don't warn when -nostdinc and -nostdinc++ are both specified (#77130)

2024-01-05 Thread via cfe-commits

Author: Jonathon Penix
Date: 2024-01-05T13:55:50-08:00
New Revision: f1d75d08adb9841dd9cebad63b76d4823ec2bdac

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

LOG: [clang][Driver] Don't warn when -nostdinc and -nostdinc++ are both 
specified (#77130)

When -nostdinc and -nostdinc++ are both specified and the Baremetal
toolchain is used, an unused command line argument warning for
-nostdinc++ is produced. This doesn't seem particularly meaningful as
-nostdinc++ would have been claimed/used had the check in
AddClangCXXStdlibIncludeArgs not short-circuited. So, just claim all
arguments in this check.

I believe this is consistent with what was done for the GNU toolchain
(see 6fe7de90b9e4e466a5c2baadafd5f72d3203651d), so hopefully this is
appropriate here as well.

Added: 


Modified: 
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/test/Driver/nostdincxx.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 42c8336e626c7b..391c47f88bde2b 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -293,9 +293,8 @@ void BareMetal::addClangTargetOptions(const ArgList 
,
 
 void BareMetal::AddClangCXXStdlibIncludeArgs(const ArgList ,
  ArgStringList ) const {
-  if (DriverArgs.hasArg(options::OPT_nostdinc) ||
-  DriverArgs.hasArg(options::OPT_nostdlibinc) ||
-  DriverArgs.hasArg(options::OPT_nostdincxx))
+  if (DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdlibinc,
+options::OPT_nostdincxx))
 return;
 
   const Driver  = getDriver();

diff  --git a/clang/test/Driver/nostdincxx.cpp 
b/clang/test/Driver/nostdincxx.cpp
index ef5702a19c037f..94d74f230eb16c 100644
--- a/clang/test/Driver/nostdincxx.cpp
+++ b/clang/test/Driver/nostdincxx.cpp
@@ -2,6 +2,7 @@
 // RUN: not %clangxx -nostdinc++ %s 2>&1 | FileCheck %s
 // RUN: not %clangxx -nostdlibinc %s 2>&1 | FileCheck %s
 // RUN: not %clangxx --target=x86_64-unknown-unknown-gnu -fsyntax-only 
-nostdinc -nostdinc++ %s 2>&1 | FileCheck /dev/null 
--implicit-check-not=-Wunused-command-line-argument
+// RUN: not %clangxx --target=riscv64-unknown-elf -fsyntax-only -nostdinc 
-nostdinc++ %s 2>&1 | FileCheck /dev/null 
--implicit-check-not=-Wunused-command-line-argument
 // CHECK: 'vector' file not found
 #include 
 



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


[libcxx] [flang] [compiler-rt] [llvm] [openmp] [clang] [libc] [clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2024-01-05 Thread via cfe-commits


@@ -0,0 +1,157 @@
+//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "::std::shared_ptr"))) {}
+
+void MoveSharedPointerContentsCheck::registerMatchers(MatchFinder *Finder) {
+  auto isStdMove = callee(functionDecl(hasName("::std::move")));
+
+  // Resolved type, direct move.
+  Finder->addMatcher(
+  callExpr(isStdMove, hasArgument(0, cxxOperatorCallExpr(
+ hasOverloadedOperatorName("*"),
+ callee(cxxMethodDecl(ofClass(
+ 
matchers::matchesAnyListedName(
+ 
SharedPointerClasses)))
+  .bind("call"),
+  this);
+
+  // Resolved type, move out of get().
+  Finder->addMatcher(
+  callExpr(
+  isStdMove,
+  hasArgument(
+  0, unaryOperator(
+ hasOperatorName("*"),
+ hasUnaryOperand(cxxMemberCallExpr(callee(cxxMethodDecl(
+ hasName("get"), 
ofClass(matchers::matchesAnyListedName(
+ SharedPointerClasses)
+  .bind("get_call"),
+  this);
+
+  auto isStdMoveUnresolved = callee(unresolvedLookupExpr(
+  
hasAnyDeclaration(namedDecl(hasUnderlyingDecl(hasName("::std::move"));
+
+  // Unresolved type, direct move.
+  Finder->addMatcher(
+  callExpr(
+  isStdMoveUnresolved,
+  hasArgument(0, unaryOperator(hasOperatorName("*"),
+   hasUnaryOperand(declRefExpr(hasType(
+   
qualType().bind("unresolved_p")))
+  .bind("unresolved_call"),
+  this);
+  // Annoyingly, the declRefExpr in the unresolved-move-of-get() case
+  // is of  rather than shared_ptr, so we have to
+  // just fetch the variable. This does leave a gap where a temporary
+  // shared_ptr wouldn't be caught, but moving out of a temporary
+  // shared pointer is a truly wild thing to do so it should be okay.
+
+  // Unresolved type, move out of get().
+  Finder->addMatcher(
+  callExpr(isStdMoveUnresolved,
+   hasArgument(
+   0, unaryOperator(hasOperatorName("*"),
+hasDescendant(cxxDependentScopeMemberExpr(
+hasMemberName("get"))),
+hasDescendant(declRefExpr(to(
+
varDecl().bind("unresolved_get_p")))
+  .bind("unresolved_get_call"),
+  this);
+}
+
+bool MoveSharedPointerContentsCheck::isSharedPointerClass(
+const VarDecl *VD) const {
+  if (VD == nullptr) {
+return false;
+  }
+
+  const QualType QT = VD->getType();
+  return isSharedPointerClass();
+}
+
+bool MoveSharedPointerContentsCheck::isSharedPointerClass(
+const QualType *QT) const {
+  if (QT == nullptr) {
+return false;
+  }
+  // We want the qualified name without template parameters,
+  // const/volatile, or reference/pointer qualifiers so we can look
+  // it up in SharedPointerClasses. This is a bit messy, but gets us
+  // to the underlying type without template parameters (eg
+  // std::shared_ptr) or const/volatile qualifiers even in the face of
+  // typedefs.
+
+  bool found = false;
+  auto *Template = llvm::dyn_cast(

pizzud wrote:

Okay, this time it made it.

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


[clang] [CLANG] Add warning when comparing to INF or NAN in fast math mode. (PR #76873)

2024-01-05 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam updated 
https://github.com/llvm/llvm-project/pull/76873

>From 7dbaf037b6b2196cee7c0c837e0a89ce3c2556ed Mon Sep 17 00:00:00 2001
From: Ammarguellat 
Date: Wed, 3 Jan 2024 14:37:17 -0800
Subject: [PATCH 1/2] [CLANG] Add warning when comparing to INF or NAN in fast
 math mode.

---
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/Sema/SemaChecking.cpp   |  65 +++
 clang/lib/Sema/SemaExpr.cpp   |   7 +-
 clang/test/Sema/warn-fp-fast-compare.cpp  | 171 ++
 5 files changed, 248 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Sema/warn-fp-fast-compare.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e54f969c19039d..1b75ae8f678b68 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6771,6 +6771,9 @@ def warn_pointer_sub_null_ptr : Warning<
 def warn_floatingpoint_eq : Warning<
   "comparing floating point with == or != is unsafe">,
   InGroup>, DefaultIgnore;
+def warn_fast_floatingpoint_eq : Warning<
+  "explicit comparison with %0 in fast floating point mode">,
+  InGroup;
 
 def err_setting_eval_method_used_in_unsafe_context : Error <
   "%select{'#pragma clang fp eval_method'|option 'ffp-eval-method'}0 cannot be 
used with "
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5e3b57ea33220b..6125e7ebb6b48a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13998,6 +13998,8 @@ class Sema final {
 SourceRange range,
 llvm::SmallBitVector );
 
+  void CheckInfNaNFunction(const CallExpr *Call, const FunctionDecl *FDecl);
+
   void CheckAbsoluteValueFunction(const CallExpr *Call,
   const FunctionDecl *FDecl);
 
@@ -14024,6 +14026,8 @@ class Sema final {
 public:
   void CheckFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS,
 BinaryOperatorKind Opcode);
+  void CheckInfNaNFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS,
+  BinaryOperatorKind Opcode);
 
 private:
   void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3168d38dd66c36..2e9f61f40b795b 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2169,6 +2169,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 ICEArguments &= ~(1 << ArgNo);
   }
 
+  FPOptions FPO;
   switch (BuiltinID) {
   case Builtin::BI__builtin___CFStringMakeConstantString:
 // CFStringMakeConstantString is currently not implemented for GOFF (i.e.,
@@ -2245,6 +2246,11 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   case Builtin::BI__builtin_islessequal:
   case Builtin::BI__builtin_islessgreater:
   case Builtin::BI__builtin_isunordered:
+if (BuiltinID == Builtin::BI__builtin_isunordered) {
+  if (TheCall->getFPFeaturesInEffect(getLangOpts()).getNoHonorNaNs())
+Diag(TheCall->getBeginLoc(), diag::warn_fast_floatingpoint_eq)
+<< "NaN" << TheCall->getSourceRange();
+}
 if (SemaBuiltinUnorderedCompare(TheCall))
   return ExprError();
 break;
@@ -2267,6 +2273,16 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   case Builtin::BI__builtin_signbit:
   case Builtin::BI__builtin_signbitf:
   case Builtin::BI__builtin_signbitl:
+FPO = TheCall->getFPFeaturesInEffect(getLangOpts());
+if (FPO.getNoHonorInfs() && (BuiltinID == Builtin::BI__builtin_isfinite ||
+ BuiltinID == Builtin::BI__builtin_isinf ||
+ BuiltinID == Builtin::BI__builtin_isinf_sign))
+  Diag(TheCall->getBeginLoc(), diag::warn_fast_floatingpoint_eq)
+  << "infinity" << TheCall->getSourceRange();
+if (FPO.getNoHonorNaNs() && (BuiltinID == Builtin::BI__builtin_isnan ||
+ BuiltinID == 
Builtin::BI__builtin_isunordered))
+  Diag(TheCall->getBeginLoc(), diag::warn_fast_floatingpoint_eq)
+  << "NaN" << TheCall->getSourceRange();
 if (SemaBuiltinFPClassification(TheCall, 1))
   return ExprError();
 break;
@@ -7621,6 +7637,7 @@ bool Sema::CheckFunctionCall(FunctionDecl *FDecl, 
CallExpr *TheCall,
 
   CheckAbsoluteValueFunction(TheCall, FDecl);
   CheckMaxUnsignedZero(TheCall, FDecl);
+  CheckInfNaNFunction(TheCall, FDecl);
 
   if (getLangOpts().ObjC)
 DiagnoseCStringFormatDirectiveInCFAPI(*this, FDecl, Args, NumArgs);
@@ -12878,6 +12895,23 @@ static bool IsStdFunction(const FunctionDecl *FDecl,
   return true;
 }
 
+void Sema::CheckInfNaNFunction(const CallExpr *Call,
+   

[clang] [libcxx] [flang] [llvm] [compiler-rt] [clang-tools-extra] [openmp] [libc] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2024-01-05 Thread via cfe-commits

https://github.com/pizzud updated 
https://github.com/llvm/llvm-project/pull/67467

>From 6d5d35e1273f595e8a0382053d5183cbce7a9d8a Mon Sep 17 00:00:00 2001
From: David Pizzuto 
Date: Tue, 26 Sep 2023 10:45:42 -0700
Subject: [PATCH 1/6] [clang-tidy] Add bugprone-move-shared-pointer-contents
 check.

This check detects moves of the contents of a shared pointer rather than the
pointer itself. Other code with a reference to the shared pointer is probably
not expecting the move.

The set of shared pointer classes is configurable via options to allow 
individual
projects to cover additional types.
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  2 +
 .../MoveSharedPointerContentsCheck.cpp| 60 
 .../bugprone/MoveSharedPointerContentsCheck.h | 37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../bugprone/move-shared-pointer-contents.rst | 17 +
 .../docs/clang-tidy/checks/list.rst   |  2 +
 .../bugprone/move-shared-pointer-contents.cpp | 68 +++
 8 files changed, 195 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/move-shared-pointer-contents.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/move-shared-pointer-contents.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index a67a91eedd1048..7f4a504f9930f1 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "MisplacedPointerArithmeticInAllocCheck.h"
 #include "MisplacedWideningCastCheck.h"
 #include "MoveForwardingReferenceCheck.h"
+#include "MoveSharedPointerContentsCheck.h"
 #include "MultiLevelImplicitPointerConversionCheck.h"
 #include "MultipleNewInOneExpressionCheck.h"
 #include "MultipleStatementMacroCheck.h"
@@ -125,6 +126,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(
 "bugprone-incorrect-enable-if");
+CheckFactories.registerCheck(
+"bugprone-move-shared-pointer-contents");
 CheckFactories.registerCheck(
 "bugprone-switch-missing-default-case");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 3c768021feb150..c017f0c0cc5202 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -23,6 +23,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  MoveSharedPointerContentsCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
   IncDecInConditionsCheck.cpp
   IncorrectRoundingsCheck.cpp
@@ -35,6 +36,7 @@ add_clang_library(clangTidyBugproneModule
   MisplacedPointerArithmeticInAllocCheck.cpp
   MisplacedWideningCastCheck.cpp
   MoveForwardingReferenceCheck.cpp
+  MoveSharedPointerContentsCheck.cpp
   MultiLevelImplicitPointerConversionCheck.cpp
   MultipleNewInOneExpressionCheck.cpp
   MultipleStatementMacroCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
new file mode 100644
index 00..b4a393b7f2f200
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp
@@ -0,0 +1,60 @@
+//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "std::shared_ptr"))) {}
+
+MoveSharedPointerContentsCheck::~MoveSharedPointerContentsCheck() = default;
+
+bool MoveSharedPointerContentsCheck::isLanguageVersionSupported(
+const LangOptions ) const {
+  return 

  1   2   3   4   5   >