[clang] [clang] Report erroneous floating point results in _Complex math (PR #90588)

2024-05-24 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/90588

>From 4bcba4c08be471e8cf6fb52842f9a73e3c45639d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 30 Apr 2024 12:25:20 +0200
Subject: [PATCH] [clang] Report erroneous floating point results in _Complex
 math

Use handleFloatFloatBinOp to properly diagnose NaN results and divisions
by zero.
---
 clang/lib/AST/ExprConstant.cpp | 27 +---
 clang/test/SemaCXX/complex-folding.cpp | 61 ++
 2 files changed, 55 insertions(+), 33 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e1..86fb396fabe2d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15209,11 +15209,21 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
   APFloat &ResI = Result.getComplexFloatImag();
   if (LHSReal) {
 assert(!RHSReal && "Cannot have two real operands for a complex op!");
-ResR = A * C;
-ResI = A * D;
+ResR = A;
+ResI = A;
+// ResR = A * C;
+// ResI = A * D;
+if (!handleFloatFloatBinOp(Info, E, ResR, BO_Mul, C) ||
+!handleFloatFloatBinOp(Info, E, ResI, BO_Mul, D))
+  return false;
   } else if (RHSReal) {
-ResR = C * A;
-ResI = C * B;
+// ResR = C * A;
+// ResI = C * B;
+ResR = C;
+ResI = C;
+if (!handleFloatFloatBinOp(Info, E, ResR, BO_Mul, A) ||
+!handleFloatFloatBinOp(Info, E, ResI, BO_Mul, B))
+  return false;
   } else {
 // In the fully general case, we need to handle NaNs and infinities
 // robustly.
@@ -15289,8 +15299,13 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
   APFloat &ResR = Result.getComplexFloatReal();
   APFloat &ResI = Result.getComplexFloatImag();
   if (RHSReal) {
-ResR = A / C;
-ResI = B / C;
+ResR = A;
+ResI = B;
+// ResR = A / C;
+// ResI = B / C;
+if (!handleFloatFloatBinOp(Info, E, ResR, BO_Div, C) ||
+!handleFloatFloatBinOp(Info, E, ResI, BO_Div, C))
+  return false;
   } else {
 if (LHSReal) {
   // No real optimizations we can do here, stub out with zero.
diff --git a/clang/test/SemaCXX/complex-folding.cpp 
b/clang/test/SemaCXX/complex-folding.cpp
index 054f159e9ce0d..7bfd36f156ea6 100644
--- a/clang/test/SemaCXX/complex-folding.cpp
+++ b/clang/test/SemaCXX/complex-folding.cpp
@@ -59,41 +59,48 @@ static_assert((1.25 / (0.25 - 0.75j)) == (0.5 + 1.5j));
 
 // Test that infinities are preserved, don't turn into NaNs, and do form zeros
 // when the divisor.
+constexpr _Complex float InfC = {1.0, __builtin_inf()};
+constexpr _Complex float InfInf = __builtin_inf() + InfC;
+static_assert(__real__(InfInf) == __builtin_inf());
+static_assert(__imag__(InfInf) == __builtin_inf());
+static_assert(__builtin_isnan(__real__(InfInf * InfInf)));
+static_assert(__builtin_isinf_sign(__imag__(InfInf * InfInf)) == 1);
+
 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * 1.0)) 
== 1);
-static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) * 
1.0)) == 1);
+static_assert(__builtin_isinf_sign(__imag__((1.0 + InfC) * 1.0)) == 1);
 static_assert(__builtin_isinf_sign(__real__(1.0 * (__builtin_inf() + 1.0j))) 
== 1);
-static_assert(__builtin_isinf_sign(__imag__(1.0 * (1.0 + __builtin_inf() * 
1.0j))) == 1);
-
+static_assert(__builtin_isinf_sign(__imag__(1.0 * (1.0 + InfC))) == 1);
 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * (1.0 + 
1.0j))) == 1);
 static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) * (__builtin_inf() + 
1.0j))) == 1);
 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * 
(__builtin_inf() + 1.0j))) == 1);
-
-static_assert(__builtin_isinf_sign(__real__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + 1.0j))) == -1);
-static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + 1.0j))) == 1);
-static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) * (1.0 + 
__builtin_inf() * 1.0j))) == -1);
-static_assert(__builtin_isinf_sign(__imag__((1.0 + 1.0j) * (1.0 + 
__builtin_inf() * 1.0j))) == 1);
-
-static_assert(__builtin_isinf_sign(__real__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + __builtin_inf() * 1.0j))) == -1);
-static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + __builtin_inf() 
* 1.0j) * (__builtin_inf() + __builtin_inf() * 1.0j))) == -1);
-
+static_assert(__builtin_isinf_sign(__real__((1.0 + InfC) * (1.0 + 1.0j))) == 
-1);
+static_assert(__builtin_isinf_sign(__imag__((1.0 + InfC) * (1.0 + 1.0j))) == 
1);
+static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) * (1.0 + InfC))) == 
-1);
+static_assert(__builtin_isinf_sign(__imag__((1.0 + 1.0j) * (1.0 + InfC))) == 
1);
+static_assert(__builtin_isinf_sign(__rea

[clang] [clang] Report erroneous floating point results in _Complex math (PR #90588)

2024-05-24 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/90588

>From 4d121c1cdca78378a3200353071c9ff460e0fcbc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 30 Apr 2024 12:25:20 +0200
Subject: [PATCH] [clang][Interp] Report erroneous floating point results in
 _Complex math

Use handleFloatFloatBinOp to properly diagnose NaN results and divisions
by zero.
---
 clang/lib/AST/ExprConstant.cpp | 27 +---
 clang/test/SemaCXX/complex-folding.cpp | 61 ++
 2 files changed, 55 insertions(+), 33 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e1..86fb396fabe2d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15209,11 +15209,21 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
   APFloat &ResI = Result.getComplexFloatImag();
   if (LHSReal) {
 assert(!RHSReal && "Cannot have two real operands for a complex op!");
-ResR = A * C;
-ResI = A * D;
+ResR = A;
+ResI = A;
+// ResR = A * C;
+// ResI = A * D;
+if (!handleFloatFloatBinOp(Info, E, ResR, BO_Mul, C) ||
+!handleFloatFloatBinOp(Info, E, ResI, BO_Mul, D))
+  return false;
   } else if (RHSReal) {
-ResR = C * A;
-ResI = C * B;
+// ResR = C * A;
+// ResI = C * B;
+ResR = C;
+ResI = C;
+if (!handleFloatFloatBinOp(Info, E, ResR, BO_Mul, A) ||
+!handleFloatFloatBinOp(Info, E, ResI, BO_Mul, B))
+  return false;
   } else {
 // In the fully general case, we need to handle NaNs and infinities
 // robustly.
@@ -15289,8 +15299,13 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
   APFloat &ResR = Result.getComplexFloatReal();
   APFloat &ResI = Result.getComplexFloatImag();
   if (RHSReal) {
-ResR = A / C;
-ResI = B / C;
+ResR = A;
+ResI = B;
+// ResR = A / C;
+// ResI = B / C;
+if (!handleFloatFloatBinOp(Info, E, ResR, BO_Div, C) ||
+!handleFloatFloatBinOp(Info, E, ResI, BO_Div, C))
+  return false;
   } else {
 if (LHSReal) {
   // No real optimizations we can do here, stub out with zero.
diff --git a/clang/test/SemaCXX/complex-folding.cpp 
b/clang/test/SemaCXX/complex-folding.cpp
index 054f159e9ce0d..7bfd36f156ea6 100644
--- a/clang/test/SemaCXX/complex-folding.cpp
+++ b/clang/test/SemaCXX/complex-folding.cpp
@@ -59,41 +59,48 @@ static_assert((1.25 / (0.25 - 0.75j)) == (0.5 + 1.5j));
 
 // Test that infinities are preserved, don't turn into NaNs, and do form zeros
 // when the divisor.
+constexpr _Complex float InfC = {1.0, __builtin_inf()};
+constexpr _Complex float InfInf = __builtin_inf() + InfC;
+static_assert(__real__(InfInf) == __builtin_inf());
+static_assert(__imag__(InfInf) == __builtin_inf());
+static_assert(__builtin_isnan(__real__(InfInf * InfInf)));
+static_assert(__builtin_isinf_sign(__imag__(InfInf * InfInf)) == 1);
+
 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * 1.0)) 
== 1);
-static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) * 
1.0)) == 1);
+static_assert(__builtin_isinf_sign(__imag__((1.0 + InfC) * 1.0)) == 1);
 static_assert(__builtin_isinf_sign(__real__(1.0 * (__builtin_inf() + 1.0j))) 
== 1);
-static_assert(__builtin_isinf_sign(__imag__(1.0 * (1.0 + __builtin_inf() * 
1.0j))) == 1);
-
+static_assert(__builtin_isinf_sign(__imag__(1.0 * (1.0 + InfC))) == 1);
 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * (1.0 + 
1.0j))) == 1);
 static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) * (__builtin_inf() + 
1.0j))) == 1);
 static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + 1.0j) * 
(__builtin_inf() + 1.0j))) == 1);
-
-static_assert(__builtin_isinf_sign(__real__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + 1.0j))) == -1);
-static_assert(__builtin_isinf_sign(__imag__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + 1.0j))) == 1);
-static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) * (1.0 + 
__builtin_inf() * 1.0j))) == -1);
-static_assert(__builtin_isinf_sign(__imag__((1.0 + 1.0j) * (1.0 + 
__builtin_inf() * 1.0j))) == 1);
-
-static_assert(__builtin_isinf_sign(__real__((1.0 + __builtin_inf() * 1.0j) * 
(1.0 + __builtin_inf() * 1.0j))) == -1);
-static_assert(__builtin_isinf_sign(__real__((__builtin_inf() + __builtin_inf() 
* 1.0j) * (__builtin_inf() + __builtin_inf() * 1.0j))) == -1);
-
+static_assert(__builtin_isinf_sign(__real__((1.0 + InfC) * (1.0 + 1.0j))) == 
-1);
+static_assert(__builtin_isinf_sign(__imag__((1.0 + InfC) * (1.0 + 1.0j))) == 
1);
+static_assert(__builtin_isinf_sign(__real__((1.0 + 1.0j) * (1.0 + InfC))) == 
-1);
+static_assert(__builtin_isinf_sign(__imag__((1.0 + 1.0j) * (1.0 + InfC))) == 
1);
+static_assert(__builtin_isinf_si

[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)

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

gedare wrote:

> It seems that you used 5 different assembly snippets and repeated each 3-6 
> times. Instead, we can have something like the following:
> 
> ```
> asm{Snippet 1};
> 
> __asm(Snippet 2);
> 
> __asm__(Snippet 3);
> 
> asm volatile (Snippet 4);
> 
> __asm volatile (Snippet 5);
> ```
> 
> Also, no space between `tok::asm` (i.e. `asm`, `__asm`, or `__asm__`) and `(`.

done, thanks for the clarification

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


[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)

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


@@ -1488,12 +1488,247 @@ TEST_F(TokenAnnotatorTest, 
RequiresDoesNotChangeParsingOfTheRest) {
 
 TEST_F(TokenAnnotatorTest, UnderstandsAsm) {
   auto Tokens = annotate("__asm{\n"
- "a:\n"
- "};");
-  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+ "\"a\":\n"
+ ": x\n"
+ ":};");

gedare wrote:

AFAIK it's not valid, unless `a` is a CPP string.

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


[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)

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

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

>From b4a8c06b79ec10ed2f53a7410bd847ecfa9e8450 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Fri, 17 May 2024 17:18:59 -0600
Subject: [PATCH 1/5] [clang-format]: Annotate colons found in inline assembly

Short-circuit the parsing of tok::colon to label colons found
within lines starting with asm as InlineASMColon.

Fixes #92616.
---
 clang/lib/Format/TokenAnnotator.cpp   |  2 ++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 20 ---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 7c4c76a91f2c5..a83f937336565 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1358,6 +1358,8 @@ class AnnotatingParser {
   Line.First->startsSequence(tok::kw_export, Keywords.kw_module) ||
   Line.First->startsSequence(tok::kw_export, Keywords.kw_import)) {
 Tok->setType(TT_ModulePartitionColon);
+  } else if (Line.First->is(tok::kw_asm)) {
+Tok->setType(TT_InlineASMColon);
   } else if (Contexts.back().ColonIsDictLiteral || Style.isProto()) {
 Tok->setType(TT_DictLiteral);
 if (Style.Language == FormatStyle::LK_TextProto) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index aadfa6dc0165c..0f5f3936e0181 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1489,11 +1489,25 @@ TEST_F(TokenAnnotatorTest, 
RequiresDoesNotChangeParsingOfTheRest) {
 TEST_F(TokenAnnotatorTest, UnderstandsAsm) {
   auto Tokens = annotate("__asm{\n"
  "a:\n"
- "};");
-  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+ ": x\n"
+ ":};");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown);
   EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace);
-  EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_InlineASMBrace);
+  EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace);
+
+  Tokens = annotate("__asm__ volatile (\n"
+"a:\n"
+": x\n"
+":);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsObjCBlock) {

>From 835425caa996d63f726bf89599b49ac2ad7fa3fb Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Thu, 23 May 2024 08:37:50 -0600
Subject: [PATCH 2/5] TokenAnnotator: remove redundant TT_InlineASMColon and
 add more tests

---
 clang/lib/Format/TokenAnnotator.cpp   |  9 +--
 clang/unittests/Format/TokenAnnotatorTest.cpp | 69 ++-
 2 files changed, 70 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index a83f937336565..bbf791c44d775 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1428,12 +1428,9 @@ class AnnotatingParser {
 // the colon are passed as macro arguments.
 Tok->setType(TT_ObjCMethodExpr);
   } else if (Contexts.back().ContextKind == tok::l_paren &&
- !Line.InPragmaDirective) {
-if (Style.isTableGen() && Contexts.back().IsTableGenDAGArg) {
-  Tok->setType(TT_TableGenDAGArgListColon);
-  break;
-}
-Tok->setType(TT_InlineASMColon);
+ !Line.InPragmaDirective && Style.isTableGen() &&
+ Contexts.back().IsTableGenDAGArg) {
+Tok->setType(TT_TableGenDAGArgListColon);
   }
   break;
 case tok::pipe:
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 0f5f3936e0181..f5e819f8719a6 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1488,7 +1488,7 @@ TEST_F(TokenAnnotatorTest, 
RequiresDoesNotChangeParsingOfTheRest) {
 
 TEST_F(TokenAnnotatorTest, UnderstandsAsm) {
   auto Tokens = annotate("__asm{\n"
- "a:\n"
+ "\"a\":\n"
  ": x\n"
  ":};");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
@@ -1500,7 +1500,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsAsm) {
   EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace);
 
   Tokens = annotate("__asm__ volatile (\n"
-"a:\n"
+"\"a\":\n"

[clang] 7d29718 - [CMake] Update CMake cache file for the Win-to-Arm cross toolchains. NFC. (#93363)

2024-05-24 Thread via cfe-commits

Author: Vladimir Vereschaka
Date: 2024-05-24T22:04:54-07:00
New Revision: 7d29718ff601c62f8c89be71e582358bfc18dd70

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

LOG: [CMake] Update CMake cache file for the Win-to-Arm cross toolchains. NFC. 
(#93363)

* allow configuration for the target specific compiler flags.
* allow lld linker for all linker outputs: shared, module and exe.
* allow configuration of libc++ ABI version.
* set MSVC runtime library to MultiThreadedDLL/MultiThreadedDebugDLL on
Windows build hosts.
* install UCRT libraries on Windows build hosts

Added: 


Modified: 
clang/cmake/caches/CrossWinToARMLinux.cmake

Removed: 




diff  --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index 736a54ece550c..62e87c6c62f85 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -89,6 +89,13 @@ endif()
 
 message(STATUS "Toolchain target to build: ${LLVM_TARGETS_TO_BUILD}")
 
+# Allow to override libc++ ABI version. Use 2 by default.
+if (NOT DEFINED LIBCXX_ABI_VERSION)
+  set(LIBCXX_ABI_VERSION 2)
+endif()
+
+message(STATUS "Toolchain's Libc++ ABI version: ${LIBCXX_ABI_VERSION}")
+
 if (NOT DEFINED CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
 endif()
@@ -109,8 +116,15 @@ set(CLANG_DEFAULT_OBJCOPY   "llvm-objcopy" 
CACHE STRING "")
 set(CLANG_DEFAULT_RTLIB "compiler-rt" CACHE STRING "")
 set(CLANG_DEFAULT_UNWINDLIB "libunwind" CACHE STRING "")
 
-if(WIN32)
-  set(CMAKE_MSVC_RUNTIME_LIBRARY"MultiThreaded" CACHE STRING "")
+if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY AND WIN32)
+  #Note: Always specify MT DLL for the LLDB build configurations on Windows 
host.
+  if (CMAKE_BUILD_TYPE STREQUAL "Debug")
+set(CMAKE_MSVC_RUNTIME_LIBRARY"MultiThreadedDebugDLL" CACHE 
STRING "")
+  else()
+set(CMAKE_MSVC_RUNTIME_LIBRARY"MultiThreadedDLL" CACHE STRING 
"")
+  endif()
+  # Grab all ucrt/vcruntime related DLLs into the binary installation folder.
+  set(CMAKE_INSTALL_UCRT_LIBRARIES  ON CACHE BOOL "")
 endif()
 
 # Set up RPATH for the target runtime/builtin libraries.
@@ -127,6 +141,15 @@ set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_INSTALL_RPATH
 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_BUILD_WITH_INSTALL_RPATH 
   ON  CACHE BOOL "")
 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_LLVM_CMAKE_DIR 
   "${LLVM_PROJECT_DIR}/llvm/cmake/modules" CACHE PATH "")
 
+if (DEFINED TOOLCHAIN_TARGET_COMPILER_FLAGS)
+  foreach(lang C;CXX;ASM)
+set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${lang}_FLAGS 
"${TOOLCHAIN_TARGET_COMPILER_FLAGS}" CACHE STRING "")
+  endforeach()
+endif()
+foreach(type SHARED;MODULE;EXE)
+  set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${type}_LINKER_FLAGS
"-fuse-ld=lld" CACHE STRING "")
+endforeach()
+
 set(LLVM_RUNTIME_TARGETS"${TOOLCHAIN_TARGET_TRIPLE}" CACHE 
STRING "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR  ON CACHE BOOL "")
 
@@ -137,6 +160,15 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_SYSROOT
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_INSTALL_RPATH
   "${RUNTIMES_INSTALL_RPATH}"  CACHE STRING "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_BUILD_WITH_INSTALL_RPATH 
   ON  CACHE BOOL "")
 
+if (DEFINED TOOLCHAIN_TARGET_COMPILER_FLAGS)
+  foreach(lang C;CXX;ASM)
+set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${lang}_FLAGS 
"${TOOLCHAIN_TARGET_COMPILER_FLAGS}" CACHE STRING "")
+  endforeach()
+endif()
+foreach(type SHARED;MODULE;EXE)
+  set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${type}_LINKER_FLAGS
"-fuse-ld=lld" CACHE STRING "")
+endforeach()
+
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_BUILTINS 
   ON CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_SANITIZERS   
   OFF CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_XRAY 
   OFF CACHE BOOL "")
@@ -164,7 +196,7 @@ 
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED
 
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_USE_COMPILER_RT 
   ON CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_SHARED   
   OFF CACHE BOOL "")
-set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION 
   2 CACHE STRING "")
+set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION 
   ${LIBCXX_ABI_VERSION} CACHE STRING "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI 
   "libcxxabi" CACHE STRING "")#!!!
 set(RUNTIMES_${TOOLCHAIN_TARGET_

[clang] [CMake] Update CMake cache file for the Win-to-Arm cross toolchains. NFC. (PR #93363)

2024-05-24 Thread Vladimir Vereschaka via cfe-commits

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


[clang] [clang][Interp] Member Pointers (PR #91303)

2024-05-24 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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 5c40db1da3a5ee1ed27b2ed874353dd80b294c15 
19bb75633bf6875cecd0d6ec72e4d756c4b39174 -- 
clang/lib/AST/Interp/MemberPointer.cpp clang/lib/AST/Interp/MemberPointer.h 
clang/test/AST/Interp/memberpointers.cpp 
clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/Context.cpp 
clang/lib/AST/Interp/Context.h clang/lib/AST/Interp/Descriptor.cpp 
clang/lib/AST/Interp/Disasm.cpp clang/lib/AST/Interp/Interp.cpp 
clang/lib/AST/Interp/Interp.h clang/lib/AST/Interp/InterpFrame.cpp 
clang/lib/AST/Interp/InterpStack.cpp clang/lib/AST/Interp/InterpStack.h 
clang/lib/AST/Interp/Pointer.cpp clang/lib/AST/Interp/Pointer.h 
clang/lib/AST/Interp/PrimType.cpp clang/lib/AST/Interp/PrimType.h 
clang/test/AST/Interp/eval-order.cpp clang/test/AST/Interp/literals.cpp 
clang/test/CodeGenCXX/mangle-ms-templates-memptrs.cpp 
clang/test/CodeGenCXX/pointers-to-data-members.cpp 
clang/test/SemaCXX/attr-weak.cpp 
clang/test/SemaCXX/nullptr_in_arithmetic_ops.cpp 
clang/unittests/AST/Interp/toAPValue.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 53e6b4cfc4..25c600efc2 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3349,7 +3349,7 @@ bool ByteCodeExprGen::VisitCallExpr(const 
CallExpr *E) {
   if (!this->emitGetMemberPtrBase(E))
 return false;
 } else if (!this->visit(MC->getImplicitObjectArgument())) {
-return false;
+  return false;
 }
   }
 
diff --git a/clang/lib/AST/Interp/MemberPointer.h 
b/clang/lib/AST/Interp/MemberPointer.h
index d5299e0ff1..2eca911fc8 100644
--- a/clang/lib/AST/Interp/MemberPointer.h
+++ b/clang/lib/AST/Interp/MemberPointer.h
@@ -34,7 +34,8 @@ public:
   MemberPointer(uint32_t Address, const Descriptor *D) {
 // This should be impossible to hit, at least I've been unable
 // to write a test for it.
-assert(false && "This constructor shouldn't be reachable for 
MemberPointers");
+assert(false &&
+   "This constructor shouldn't be reachable for MemberPointers");
   }
 
   MemberPointer(const Decl *D) : Dcl(D) {
@@ -43,7 +44,9 @@ public:
   }
 
   uint64_t getIntegerRepresentation() const {
-assert(false && "getIntegerRepresentation() shouldn't be reachable for 
MemberPointers");
+assert(
+false &&
+"getIntegerRepresentation() shouldn't be reachable for 
MemberPointers");
 return 17;
   }
 

``




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


[clang] [clang][Interp] Member Pointers (PR #91303)

2024-05-24 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/91303

>From df90df17e949e264f0b0f6816cd6bd138e159271 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 10 Apr 2024 16:42:36 +0200
Subject: [PATCH 1/2] Memberpointers

---
 clang/lib/AST/CMakeLists.txt  |   1 +
 clang/lib/AST/Interp/ByteCodeExprGen.cpp  | 103 +-
 clang/lib/AST/Interp/Context.cpp  |  15 +-
 clang/lib/AST/Interp/Context.h|   2 +
 clang/lib/AST/Interp/Descriptor.cpp   |   1 +
 clang/lib/AST/Interp/Disasm.cpp   |   3 +
 clang/lib/AST/Interp/Interp.cpp   |  30 ++-
 clang/lib/AST/Interp/Interp.h |  99 ++
 clang/lib/AST/Interp/InterpFrame.cpp  |   1 +
 clang/lib/AST/Interp/InterpStack.cpp  |   1 +
 clang/lib/AST/Interp/InterpStack.h|   3 +
 clang/lib/AST/Interp/MemberPointer.cpp|  73 +++
 clang/lib/AST/Interp/MemberPointer.h  | 112 +++
 clang/lib/AST/Interp/Opcodes.td   |  18 +-
 clang/lib/AST/Interp/Pointer.cpp  |   1 +
 clang/lib/AST/Interp/Pointer.h|   1 +
 clang/lib/AST/Interp/PrimType.cpp |   1 +
 clang/lib/AST/Interp/PrimType.h   |   8 +-
 clang/test/AST/Interp/eval-order.cpp  |   4 +-
 clang/test/AST/Interp/literals.cpp|   7 +-
 clang/test/AST/Interp/memberpointers.cpp  | 184 ++
 .../mangle-ms-templates-memptrs.cpp   |   2 +-
 .../CodeGenCXX/pointers-to-data-members.cpp   |   2 +-
 clang/test/SemaCXX/attr-weak.cpp  |   1 +
 .../SemaCXX/nullptr_in_arithmetic_ops.cpp |   2 +-
 clang/unittests/AST/Interp/toAPValue.cpp  |  46 +
 26 files changed, 692 insertions(+), 29 deletions(-)
 create mode 100644 clang/lib/AST/Interp/MemberPointer.cpp
 create mode 100644 clang/lib/AST/Interp/MemberPointer.h
 create mode 100644 clang/test/AST/Interp/memberpointers.cpp

diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index 3faefb54f599f..a5d3dacfc1a84 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -87,6 +87,7 @@ add_clang_library(clangAST
   Interp/Record.cpp
   Interp/Source.cpp
   Interp/State.cpp
+  Interp/MemberPointer.cpp
   Interp/InterpShared.cpp
   ItaniumCXXABI.cpp
   ItaniumMangle.cpp
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 6607727b5246f..5f8b94c3a0f94 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -100,6 +100,35 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
 return this->emitMemcpy(CE);
   }
 
+  case CK_DerivedToBaseMemberPointer: {
+assert(classifyPrim(CE->getType()) == PT_MemberPtr);
+assert(classifyPrim(SubExpr->getType()) == PT_MemberPtr);
+const auto *FromMP = SubExpr->getType()->getAs();
+const auto *ToMP = CE->getType()->getAs();
+
+unsigned DerivedOffset = collectBaseOffset(QualType(ToMP->getClass(), 0),
+   QualType(FromMP->getClass(), 
0));
+
+if (!this->visit(SubExpr))
+  return false;
+
+return this->emitGetMemberPtrBasePop(DerivedOffset, CE);
+  }
+
+  case CK_BaseToDerivedMemberPointer: {
+assert(classifyPrim(CE) == PT_MemberPtr);
+assert(classifyPrim(SubExpr) == PT_MemberPtr);
+const auto *FromMP = SubExpr->getType()->getAs();
+const auto *ToMP = CE->getType()->getAs();
+
+unsigned DerivedOffset = collectBaseOffset(QualType(FromMP->getClass(), 0),
+   QualType(ToMP->getClass(), 0));
+
+if (!this->visit(SubExpr))
+  return false;
+return this->emitGetMemberPtrBasePop(-DerivedOffset, CE);
+  }
+
   case CK_UncheckedDerivedToBase:
   case CK_DerivedToBase: {
 if (!this->visit(SubExpr))
@@ -187,7 +216,8 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 return this->emitCastFloatingIntegral(*ToT, CE);
   }
 
-  case CK_NullToPointer: {
+  case CK_NullToPointer:
+  case CK_NullToMemberPointer: {
 if (DiscardResult)
   return true;
 
@@ -326,7 +356,8 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 return this->emitCast(*FromT, *ToT, CE);
   }
 
-  case CK_PointerToBoolean: {
+  case CK_PointerToBoolean:
+  case CK_MemberPointerToBoolean: {
 PrimType PtrT = classifyPrim(SubExpr->getType());
 
 // Just emit p != nullptr for this.
@@ -534,8 +565,23 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   BO->isComparisonOp())
 return this->emitComplexComparison(LHS, RHS, BO);
 
-  if (BO->isPtrMemOp())
-return this->visit(RHS);
+  if (BO->isPtrMemOp()) {
+if (!this->visit(LHS))
+  return false;
+
+if (!this->visit(RHS))
+  return false;
+
+if (!this->emitToMemberPtr(BO))
+  return false;

[clang] [clang][Interp] Member Pointers (PR #91303)

2024-05-24 Thread Timm Baeder via cfe-commits


@@ -3123,10 +3172,28 @@ bool ByteCodeExprGen::VisitCallExpr(const 
CallExpr *E) {
 }
   }
 
+  std::optional CalleeOffset;
   // Add the (optional, implicit) This pointer.
   if (const auto *MC = dyn_cast(E)) {
-if (!this->visit(MC->getImplicitObjectArgument()))
-  return false;
+if (!FuncDecl && classifyPrim(E->getCallee()) == PT_MemberPtr) {
+  // If we end up creating a CallPtr op for this, we need the base of the
+  // member pointer as the instance pointer, and later extract the function
+  // decl as the function pointer.
+  const Expr *Callee = E->getCallee();
+  CalleeOffset =
+  this->allocateLocalPrimitive(Callee, PT_MemberPtr, true, false);
+  if (!this->visit(Callee))
+return false;
+  if (!this->emitSetLocal(PT_MemberPtr, *CalleeOffset, E))
+return false;
+  if (!this->emitGetLocal(PT_MemberPtr, *CalleeOffset, E))

tbaederr wrote:

We could also `dup()` the value before the `SetLocal` - but the `SetLocal` will 
remove it from the stack, so we have to get the value somehow again.

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


[clang] [clang][Interp] Member Pointers (PR #91303)

2024-05-24 Thread Timm Baeder via cfe-commits


@@ -0,0 +1,112 @@
+//===- MemberPointer.h --*- 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_AST_INTERP_MEMBER_POINTER_H
+#define LLVM_CLANG_AST_INTERP_MEMBER_POINTER_H
+
+#include "Pointer.h"
+#include 
+
+namespace clang {
+class ASTContext;
+namespace interp {
+
+class Context;
+class FunctionPointer;
+
+class MemberPointer final {
+private:
+  Pointer Base;
+  const Decl *Dcl = nullptr;
+  int32_t PtrOffset = 0;
+
+  MemberPointer(Pointer Base, const Decl *Dcl, int32_t PtrOffset)
+  : Base(Base), Dcl(Dcl), PtrOffset(PtrOffset) {}
+
+public:
+  MemberPointer() = default;
+  MemberPointer(Pointer Base, const Decl *Dcl) : Base(Base), Dcl(Dcl) {}
+  MemberPointer(uint32_t Address, const Descriptor *D) {
+// This should be impossible to hit, at least I've been unable
+// to write a test for it.
+  }
+
+  MemberPointer(const Decl *D) : Dcl(D) {
+assert(isa(D) || isa(D) ||
+   isa(D));

tbaederr wrote:

I made that change at least a few times locally, but it doesn't work:
```
/home/tbaeder/code/llvm-project/clang/lib/AST/Interp/MemberPointer.h:40:27: 
error: too many arguments provided to function-like macro invocation
   40 | assert(isa(D));
  |   ^
/usr/include/assert.h:99:11: note: macro 'assert' defined here
   99 | #  define assert(expr)  
\
  |   ^

```

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


[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)

2024-05-24 Thread Hirofumi Nakamura via cfe-commits


@@ -1426,12 +1428,9 @@ class AnnotatingParser {
 // the colon are passed as macro arguments.
 Tok->setType(TT_ObjCMethodExpr);
   } else if (Contexts.back().ContextKind == tok::l_paren &&
- !Line.InPragmaDirective) {
-if (Style.isTableGen() && Contexts.back().IsTableGenDAGArg) {
-  Tok->setType(TT_TableGenDAGArgListColon);
-  break;
-}
-Tok->setType(TT_InlineASMColon);
+ !Line.InPragmaDirective && Style.isTableGen() &&
+ Contexts.back().IsTableGenDAGArg) {
+Tok->setType(TT_TableGenDAGArgListColon);

hnakamura5 wrote:

No objection. This seems redundant. Thank you for removing.

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


[clang] [clang-format] Add option to remove leading blank lines (PR #91221)

2024-05-24 Thread via cfe-commits

https://github.com/sstwcw updated 
https://github.com/llvm/llvm-project/pull/91221

>From 72e15ffb87eff94d51af69c0f804084ab7abe474 Mon Sep 17 00:00:00 2001
From: sstwcw 
Date: Mon, 6 May 2024 14:34:08 +
Subject: [PATCH 1/2] [clang-format] Add option to remove leading blank lines

---
 clang/docs/ClangFormatStyleOptions.rst  | 5 +
 clang/include/clang/Format/Format.h | 5 +
 clang/lib/Format/ContinuationIndenter.cpp   | 3 +++
 clang/lib/Format/Format.cpp | 2 ++
 clang/lib/Format/UnwrappedLineFormatter.cpp | 4 +++-
 clang/unittests/Format/ConfigParseTest.cpp  | 1 +
 clang/unittests/Format/FormatTest.cpp   | 7 +++
 7 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index ce9035a2770ee..c81de131f050c 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4406,6 +4406,11 @@ the configuration (without a prefix: ``Auto``).
 **KeepEmptyLinesAtEOF** (``Boolean``) :versionbadge:`clang-format 17` :ref:`¶ 
`
   Keep empty lines (up to ``MaxEmptyLinesToKeep``) at end of file.
 
+.. _KeepEmptyLinesAtStart:
+
+**KeepEmptyLinesAtStart** (``Boolean``) :versionbadge:`clang-format 19` 
:ref:`¶ `
+  Keep empty lines (up to ``MaxEmptyLinesToKeep``) at start of file.
+
 .. _KeepEmptyLinesAtTheStartOfBlocks:
 
 **KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) :versionbadge:`clang-format 
3.7` :ref:`¶ `
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 8ebdc86b98329..9a7837b1bac2d 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3061,6 +3061,10 @@ struct FormatStyle {
   /// \version 17
   bool KeepEmptyLinesAtEOF;
 
+  /// Keep empty lines (up to ``MaxEmptyLinesToKeep``) at start of file.
+  /// \version 19
+  bool KeepEmptyLinesAtStart;
+
   /// If true, the empty line at the start of blocks is kept.
   /// \code
   ///true:  false:
@@ -4994,6 +4998,7 @@ struct FormatStyle {
JavaScriptQuotes == R.JavaScriptQuotes &&
JavaScriptWrapImports == R.JavaScriptWrapImports &&
KeepEmptyLinesAtEOF == R.KeepEmptyLinesAtEOF &&
+   KeepEmptyLinesAtStart == R.KeepEmptyLinesAtStart &&
KeepEmptyLinesAtTheStartOfBlocks ==
R.KeepEmptyLinesAtTheStartOfBlocks &&
Language == R.Language &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index ad0e2c3c620c3..33dca7b08f998 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -208,6 +208,9 @@ RawStringFormatStyleManager::RawStringFormatStyleManager(
   LanguageStyle = PredefinedStyle;
 }
 LanguageStyle->ColumnLimit = CodeStyle.ColumnLimit;
+// This way the first line of the string does not have to follow the code
+// before the string.
+LanguageStyle->KeepEmptyLinesAtStart = true;
 for (StringRef Delimiter : RawStringFormat.Delimiters)
   DelimiterStyle.insert({Delimiter, *LanguageStyle});
 for (StringRef EnclosingFunction : RawStringFormat.EnclosingFunctions)
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c8d8ec3afbd99..31ffbf46cdd08 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1003,6 +1003,7 @@ template <> struct MappingTraits {
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
 IO.mapOptional("KeepEmptyLinesAtEOF", Style.KeepEmptyLinesAtEOF);
+IO.mapOptional("KeepEmptyLinesAtStart", Style.KeepEmptyLinesAtStart);
 IO.mapOptional("LambdaBodyIndentation", Style.LambdaBodyIndentation);
 IO.mapOptional("LineEnding", Style.LineEnding);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
@@ -1513,6 +1514,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave;
   LLVMStyle.JavaScriptWrapImports = true;
   LLVMStyle.KeepEmptyLinesAtEOF = false;
+  LLVMStyle.KeepEmptyLinesAtStart = true;
   LLVMStyle.KeepEmptyLinesAtTheStartOfBlocks = true;
   LLVMStyle.LambdaBodyIndentation = FormatStyle::LBI_Signature;
   LLVMStyle.Language = Language;
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 4ae54e56331bd..b8485ae2b9197 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1473,8 +1473,10 @@ static auto computeNewlines(const AnnotatedLine &Line,
 Newlines = std::min(Newlines, 1u);
   if (Newlines == 0 && !RootToken.IsFirst)
 Newlines = 1;
-  if (RootToken.IsFirst && !RootToken.HasUnescapedNewline)
+  if (RootToken.IsFirst &&
+  (!Style.KeepEmptyLinesAtStart || !RootToken.HasUnescapedNewline)) {
 Newlines = 0;
+  }
 
   // Remove em

[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2024-05-24 Thread Max Winkler via cfe-commits

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


[clang] 778dbcb - [clang] Add /Zc:__STDC__ flag to clang-cl (#68690)

2024-05-24 Thread via cfe-commits

Author: Reagan
Date: 2024-05-24T23:48:13-04:00
New Revision: 778dbcbbb5c4e462231e812ab463b586555b6a0a

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

LOG: [clang] Add /Zc:__STDC__ flag to clang-cl (#68690)

This commit adds the /Zc:\_\_STDC\_\_ argument from MSVC, which defines
\_\_STDC_\_.
This means, alongside stronger feature parity with MSVC, that things
that rely on \_\_STDC\_\_, such as autoconf, can work.
Link to MSVC documentation of this flag:
https://learn.microsoft.com/en-us/cpp/build/reference/zc-stdc?view=msvc-170

Added: 
clang/test/Driver/ms-define-stdc.c
clang/test/Preprocessor/stdc-ms-extension.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/InitPreprocessor.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e40b236c914d9..d023f53754cb3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -342,6 +342,10 @@ New Compiler Flags
   ``__attribute__((section(...)))``. This enables linker GC to collect unused
   symbols without having to use a per-symbol section.
 
+- ``-fms-define-stdc`` and its clang-cl counterpart ``/Zc:__STDC__``.
+  Matches MSVC behaviour by defining ``__STDC__`` to ``1`` when
+  MSVC compatibility mode is used. It has no effect for C++ code.
+
 Deprecated Compiler Flags
 -
 

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 09eb92d6f10d2..4061451b2150a 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -300,6 +300,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations 
/ deallocations with
 
 LANGOPT(OpenACC   , 1, 0, "OpenACC Enabled")
 
+LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with 
'-fms-compatibility'")
 LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
 LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
 LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are 
unavailable")

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9a5bffce20460..de2f245fb29f8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2981,6 +2981,10 @@ def fms_compatibility : Flag<["-"], 
"fms-compatibility">, Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Enable full Microsoft Visual C++ compatibility">,
   MarshallingInfoFlag>;
+def fms_define_stdc : Flag<["-"], "fms-define-stdc">, Group,
+  Visibility<[ClangOption, CC1Option, CLOption]>,
+  HelpText<"Define '__STDC__' to '1' in MSVC Compatibility mode">,
+  MarshallingInfoFlag>;
 def fms_extensions : Flag<["-"], "fms-extensions">, Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Accept some non-standard constructs supported by the Microsoft 
compiler">,
@@ -8306,6 +8310,9 @@ def _SLASH_vd : CLJoined<"vd">, HelpText<"Control 
vtordisp placement">,
   Alias;
 def _SLASH_X : CLFlag<"X">,
   HelpText<"Do not add %INCLUDE% to include search path">, Alias;
+def _SLASH_Zc___STDC__ : CLFlag<"Zc:__STDC__">,
+  HelpText<"Define __STDC__">,
+  Alias;
 def _SLASH_Zc_sizedDealloc : CLFlag<"Zc:sizedDealloc">,
   HelpText<"Enable C++14 sized global deallocation functions">,
   Alias;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index adb1b2ff566cb..97e451cfe2acb 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7026,8 +7026,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   options::OPT_fms_compatibility, options::OPT_fno_ms_compatibility,
   (IsWindowsMSVC && Args.hasFlag(options::OPT_fms_extensions,
  options::OPT_fno_ms_extensions, true)));
-  if (IsMSVCCompat)
+  if (IsMSVCCompat) {
 CmdArgs.push_back("-fms-compatibility");
+if (!types::isCXX(Input.getType()) &&
+Args.hasArg(options::OPT_fms_define_stdc))
+  CmdArgs.push_back("-fms-define-stdc");
+  }
 
   if (Triple.isWindowsMSVCEnvironment() && !D.IsCLMode() &&
   Args.hasArg(options::OPT_fms_runtime_lib_EQ))

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 68760e3e0..e8c8a5175f8f4 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -432,7 +432,8 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo &TI,
   //  [C++] Whether __STDC__ is predefined and if so, what its value is,
   //  are implementation-defi

[clang] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes without a virtual destructor. (PR #92837)

2024-05-24 Thread Ryosuke Niwa via cfe-commits


@@ -11,16 +11,134 @@
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SetVector.h"
 #include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
+
+class DerefAnalysisVisitor
+: public ConstStmtVisitor {
+  // Returns true if any of child statements return true.
+  bool VisitChildren(const Stmt *S) {
+for (const Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+
+  bool VisitBody(const Stmt *Body) {
+if (!Body)
+  return false;
+
+auto [It, IsNew] = VisitedBody.insert(Body);
+if (!IsNew) // This body is recursive

rniwa wrote:

Yeah. We could keep the visitor around for the duration of the checker & cache 
the results. Will address that in a follow up.

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


[clang] [compiler-rt] [llvm] [openmp] [PGO][Offload] Profile profraw generation for GPU instrumentation #76587 (PR #93365)

2024-05-24 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 d63764718c93a40d25cf4ae62b6ea6cb8eda6435 
67f3009173d815295f36e2b37e85add1347e3bf9 -- 
offload/DeviceRTL/include/Profiling.h offload/DeviceRTL/src/Profiling.cpp 
offload/test/offloading/pgo1.c clang/lib/CodeGen/CodeGenPGO.cpp 
compiler-rt/lib/profile/InstrProfiling.h 
compiler-rt/lib/profile/InstrProfilingFile.c 
llvm/include/llvm/ProfileData/InstrProf.h llvm/lib/ProfileData/InstrProf.cpp 
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp 
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp 
offload/plugins-nextgen/common/include/GlobalHandler.h 
offload/plugins-nextgen/common/src/GlobalHandler.cpp 
offload/plugins-nextgen/common/src/PluginInterface.cpp
``





View the diff from clang-format here.


``diff
diff --git a/offload/plugins-nextgen/common/include/GlobalHandler.h 
b/offload/plugins-nextgen/common/include/GlobalHandler.h
index 017d7e994f..1d7b9f80f9 100644
--- a/offload/plugins-nextgen/common/include/GlobalHandler.h
+++ b/offload/plugins-nextgen/common/include/GlobalHandler.h
@@ -64,12 +64,10 @@ struct __llvm_profile_data {
 };
 
 extern "C" {
-extern int __attribute__((weak))
-__llvm_write_custom_profile(const char *Target,
-const __llvm_profile_data *DataBegin,
-const __llvm_profile_data *DataEnd,
-const char *CountersBegin, const char *CountersEnd,
-const char *NamesBegin, const char *NamesEnd);
+extern int __attribute__((weak)) __llvm_write_custom_profile(
+const char *Target, const __llvm_profile_data *DataBegin,
+const __llvm_profile_data *DataEnd, const char *CountersBegin,
+const char *CountersEnd, const char *NamesBegin, const char *NamesEnd);
 }
 
 /// PGO profiling data extracted from a GPU device

``




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


[clang] [compiler-rt] [llvm] [openmp] [PGO][Offload] Profile profraw generation for GPU instrumentation #76587 (PR #93365)

2024-05-24 Thread Ethan Luis McDonough via cfe-commits

https://github.com/EthanLuisMcDonough created 
https://github.com/llvm/llvm-project/pull/93365

This pull request is the second part of an ongoing effort to extends PGO 
instrumentation to GPU device code and depends on #76587. This PR makes the 
following changes:

- Introduces `__llvm_write_custom_profile` to PGO compiler-rt library. This is 
an external function that can be used to write profiles with custom data to 
target-specific files.
- Adds `__llvm_write_custom_profile` as weak symbol to libomptarget so that it 
can write the collected data to a profraw file.

>From 530eb982b9770190377bb0bd09c5cb715f34d484 Mon Sep 17 00:00:00 2001
From: Ethan Luis McDonough 
Date: Fri, 15 Dec 2023 20:38:38 -0600
Subject: [PATCH 01/27] Add profiling functions to libomptarget

---
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |  3 +++
 openmp/libomptarget/DeviceRTL/CMakeLists.txt  |  2 ++
 .../DeviceRTL/include/Profiling.h | 21 +++
 .../libomptarget/DeviceRTL/src/Profiling.cpp  | 19 +
 4 files changed, 45 insertions(+)
 create mode 100644 openmp/libomptarget/DeviceRTL/include/Profiling.h
 create mode 100644 openmp/libomptarget/DeviceRTL/src/Profiling.cpp

diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def 
b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
index d22d2a8e948b0..1d887d5cb5812 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -503,6 +503,9 @@ __OMP_RTL(__kmpc_barrier_simple_generic, false, Void, 
IdentPtr, Int32)
 __OMP_RTL(__kmpc_warp_active_thread_mask, false, Int64,)
 __OMP_RTL(__kmpc_syncwarp, false, Void, Int64)
 
+__OMP_RTL(__llvm_profile_register_function, false, Void, VoidPtr)
+__OMP_RTL(__llvm_profile_register_names_function, false, Void, VoidPtr, Int64)
+
 __OMP_RTL(__last, false, Void, )
 
 #undef __OMP_RTL
diff --git a/openmp/libomptarget/DeviceRTL/CMakeLists.txt 
b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
index 1ce3e1e40a80a..55ee15d068c67 100644
--- a/openmp/libomptarget/DeviceRTL/CMakeLists.txt
+++ b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
@@ -89,6 +89,7 @@ set(include_files
   ${include_directory}/Interface.h
   ${include_directory}/LibC.h
   ${include_directory}/Mapping.h
+  ${include_directory}/Profiling.h
   ${include_directory}/State.h
   ${include_directory}/Synchronization.h
   ${include_directory}/Types.h
@@ -104,6 +105,7 @@ set(src_files
   ${source_directory}/Mapping.cpp
   ${source_directory}/Misc.cpp
   ${source_directory}/Parallelism.cpp
+  ${source_directory}/Profiling.cpp
   ${source_directory}/Reduction.cpp
   ${source_directory}/State.cpp
   ${source_directory}/Synchronization.cpp
diff --git a/openmp/libomptarget/DeviceRTL/include/Profiling.h 
b/openmp/libomptarget/DeviceRTL/include/Profiling.h
new file mode 100644
index 0..68c7744cd6075
--- /dev/null
+++ b/openmp/libomptarget/DeviceRTL/include/Profiling.h
@@ -0,0 +1,21 @@
+//=== Profiling.h - OpenMP interface -- 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 OMPTARGET_DEVICERTL_PROFILING_H
+#define OMPTARGET_DEVICERTL_PROFILING_H
+
+extern "C" {
+
+void __llvm_profile_register_function(void *ptr);
+void __llvm_profile_register_names_function(void *ptr, long int i);
+}
+
+#endif
diff --git a/openmp/libomptarget/DeviceRTL/src/Profiling.cpp 
b/openmp/libomptarget/DeviceRTL/src/Profiling.cpp
new file mode 100644
index 0..799477f5e47d2
--- /dev/null
+++ b/openmp/libomptarget/DeviceRTL/src/Profiling.cpp
@@ -0,0 +1,19 @@
+//===--- Profiling.cpp  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
+//
+//===--===//
+
+#include "Profiling.h"
+
+#pragma omp begin declare target device_type(nohost)
+
+extern "C" {
+
+void __llvm_profile_register_function(void *ptr) {}
+void __llvm_profile_register_names_function(void *ptr, long int i) {}
+}
+
+#pragma omp end declare target

>From fb067d4ffe604fd68cf90b705db1942bce49dbb1 Mon Sep 17 00:00:00 2001
From: Ethan Luis McDonough 
Date: Sat, 16 Dec 2023 01:18:41 -0600
Subject: [PATCH 02/27] Fix PGO instrumentation for GPU targets

---
 clang/lib/CodeGen/CodeGenPGO.cpp  | 10 --
 .../lib/Transforms/Instrumentation/InstrProfiling.cpp | 11 ---
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang

[clang] [analyzer] Fix a test issue in mingw configurations (PR #92737)

2024-05-24 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.


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


[clang] [clang-format] Don't always break before << between string literals (PR #92214)

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


@@ -10539,6 +10539,17 @@ TEST_F(FormatTest, KeepStringLabelValuePairsOnALine) {
   "  bbb);");
 }
 
+TEST_F(FormatTest, WrapBeforeInsertionOperatorbetweenStringLiterals) {
+  verifyFormat("QStringList() << \"foo\" << \"bar\";");

owenca wrote:

No, because the single-argument version of `verifyFormat` is a more stringent 
test than `verifyNoChange` as the former also tests the input with all optional 
whitespace characters between tokens removed.

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


[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)

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


@@ -1488,12 +1488,247 @@ TEST_F(TokenAnnotatorTest, 
RequiresDoesNotChangeParsingOfTheRest) {
 
 TEST_F(TokenAnnotatorTest, UnderstandsAsm) {
   auto Tokens = annotate("__asm{\n"
- "a:\n"
- "};");
-  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+ "\"a\":\n"
+ ": x\n"
+ ":};");

owenca wrote:

Is the unquoted `a:` in assembly code invalid? If not, please add your test 
instead of editing the existing one.

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


[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)

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


@@ -1488,12 +1488,247 @@ TEST_F(TokenAnnotatorTest, 
RequiresDoesNotChangeParsingOfTheRest) {
 
 TEST_F(TokenAnnotatorTest, UnderstandsAsm) {
   auto Tokens = annotate("__asm{\n"
- "a:\n"
- "};");
-  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+ "\"a\":\n"
+ ": x\n"
+ ":};");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown);
+  EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace);
+  EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace);
+
+  Tokens = annotate("asm{\n"
+"\"a\":\n"
+": x\n"
+":};");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown);
   EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace);
-  EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_InlineASMBrace);
+  EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace);
+
+  Tokens = annotate("__asm__{\n"
+"\"a\":\n"
+": x\n"
+":};");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown);
+  EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace);
+  EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace);
+
+  Tokens = annotate("__asm (\n"
+"\"a\":\n"
+": x\n"
+":);");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown);
+  EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon);
+
+  Tokens = annotate("asm (\n"
+"\"a\":\n"
+": x\n"
+":);");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown);
+  EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon);
+
+  Tokens = annotate("__asm__ (\n"
+"\"a\":\n"
+": x\n"
+":);");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown);
+  EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon);
+
+  Tokens = annotate("__asm volatile (\n"
+"\"a_label:\"\n"
+":\n"
+": x\n"
+":);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon);
+
+  Tokens = annotate("asm volatile (\n"
+"\"a_label:\"\n"
+":\n"
+": x\n"
+":);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon);
+
+  Tokens = annotate("__asm__ volatile (\n"
+"\"a_label:\"\n"
+":\n"
+": x\n"
+":);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon);
+
+  Tokens = annotate("__asm (\n"
+"\"a_label:\"\n"
+": x\n"
+":\n"
+": y);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown);
+  EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon);
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon);
+
+  Tokens = annotate("asm (\n"
+"\"a_label:\"\n"
+": x\n"
+":\n"
+ 

[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)

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

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


[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)

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

https://github.com/owenca commented:

It seems that you used 5 different assembly snippets and repeated each 3-6 
times. Instead, we can have something like the following:
```
asm{Snippet 1};

__asm(Snippet 2);

__asm__(Snippet 3);

asm volatile (Snippet 4);

__asm volatile (Snippet 5);
```
Also, no space between `tok::asm` (i.e. `asm`, `__asm`, or `__asm__`) and `(`.

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


[clang] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes without a virtual destructor. (PR #92837)

2024-05-24 Thread Artem Dergachev via cfe-commits

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


[clang] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes without a virtual destructor. (PR #92837)

2024-05-24 Thread Artem Dergachev via cfe-commits


@@ -11,16 +11,134 @@
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SetVector.h"
 #include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
+
+class DerefAnalysisVisitor
+: public ConstStmtVisitor {
+  // Returns true if any of child statements return true.
+  bool VisitChildren(const Stmt *S) {
+for (const Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+
+  bool VisitBody(const Stmt *Body) {
+if (!Body)
+  return false;
+
+auto [It, IsNew] = VisitedBody.insert(Body);
+if (!IsNew) // This body is recursive

haoNoQ wrote:

Oh ok it's a one-shot visitor that scans one function and dies. But if it is 
instantiated again to scan another function that calls a previously visited 
function, it'll re-scan it from scratch.

So like, this probably ensures termination but there's also probably room for 
major optimizations there. We don't really have strict performance 
requirements, esp. for project-specific checks, but at a glance this could 
matter on some TUs, so it may be a good idea to keep an eye on performance.

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


[clang] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes without a virtual destructor. (PR #92837)

2024-05-24 Thread Artem Dergachev via cfe-commits


@@ -11,16 +11,118 @@
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SetVector.h"
 #include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
+
+class DerefFuncDeleteExprVisitor
+: public ConstStmtVisitor {
+  // Returns true if any of child statements return true.
+  bool VisitChildren(const Stmt *S) {
+for (const Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+
+  bool VisitBody(const Stmt *Body) {
+if (!Body)
+  return false;
+
+auto [It, IsNew] = VisitedBody.insert(Body);
+if (!IsNew) // This body is recursive
+  return false;
+
+return Visit(Body);
+  }
+
+public:
+  DerefFuncDeleteExprVisitor(const TemplateArgumentList &ArgList,
+ const CXXRecordDecl *ClassDecl)
+  : ArgList(&ArgList), ClassDecl(ClassDecl) {}
+
+  DerefFuncDeleteExprVisitor(const CXXRecordDecl *ClassDecl)
+  : ClassDecl(ClassDecl) {}
+
+  std::optional HasSpecializedDelete(CXXMethodDecl *Decl) {
+if (auto *Body = Decl->getBody())
+  return VisitBody(Body);
+if (auto *Tmpl = Decl->getTemplateInstantiationPattern())
+  return std::nullopt; // Indeterminate. There was no concrete instance.
+return false;
+  }
+
+  bool VisitCallExpr(const CallExpr *CE) {
+const Decl *D = CE->getCalleeDecl();
+if (D && D->hasBody())
+  return VisitBody(D->getBody());
+return false;
+  }
+
+  bool VisitCXXDeleteExpr(const CXXDeleteExpr *E) {
+auto *Arg = E->getArgument();
+while (Arg) {
+  if (auto *Paren = dyn_cast(Arg))
+Arg = Paren->getSubExpr();
+  else if (auto *Cast = dyn_cast(Arg)) {
+Arg = Cast->getSubExpr();
+auto CastType = Cast->getType();
+if (auto *PtrType = dyn_cast(CastType)) {
+  auto PointeeType = PtrType->getPointeeType();
+  while (auto *ET = dyn_cast(PointeeType)) {
+if (ET->isSugared())
+  PointeeType = ET->desugar();
+  }
+  if (auto *ParmType = dyn_cast(PointeeType)) {
+if (ArgList) {
+  auto ParmIndex = ParmType->getIndex();
+  auto Type = ArgList->get(ParmIndex).getAsType();
+  if (auto *RD = dyn_cast(Type)) {

haoNoQ wrote:

`Type->getAsCXXRecordDecl() == ClassDecl` is a bit shorter, and you probably 
don't even need to null-check, because `ClassDecl` is never null anyway.

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


[clang] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes without a virtual destructor. (PR #92837)

2024-05-24 Thread Artem Dergachev via cfe-commits

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

LGTM now!

I have one style comment but that's it, everything looks good.

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


[clang] [webkit.RefCntblBaseVirtualDtor] Allow CRTP classes without a virtual destructor. (PR #92837)

2024-05-24 Thread Artem Dergachev via cfe-commits

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


[clang] [llvm] [WIP] Expand variadic functions in IR (PR #89007)

2024-05-24 Thread Jon Chesterfield via cfe-commits


@@ -115,7 +115,13 @@ void AMDGPUABIInfo::computeInfo(CGFunctionInfo &FI) const {
 
 Address AMDGPUABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
  QualType Ty) const {
-  llvm_unreachable("AMDGPU does not support varargs");
+  const bool IsIndirect = false;
+  const bool AllowHigherAlign = true;
+  // Would rather not naturally align values
+  // Splitting {char, short} into two separate arguments makes that difficult.

JonChesterfield wrote:

^structs < 8 bytes are packed into integers, but structs larger than that are 
spread across multiple parameters in a discarding-padding sense. Better testing 
revealed that one byte aligning things does not work out robustly, have had to 
take a different strategy to make all the cases work. However that does mean 
everything is 4 byte aligned now.

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


[clang] [llvm] [AMDGPU] Implement variadic functions by IR lowering (PR #93362)

2024-05-24 Thread Jon Chesterfield via cfe-commits


@@ -197,12 +206,20 @@ ABIArgInfo 
AMDGPUABIInfo::classifyKernelArgumentType(QualType Ty) const {
   return ABIArgInfo::getDirect(LTy, 0, nullptr, false);
 }
 
-ABIArgInfo AMDGPUABIInfo::classifyArgumentType(QualType Ty,
+ABIArgInfo AMDGPUABIInfo::classifyArgumentType(QualType Ty, bool Variadic,
unsigned &NumRegsLeft) const {

JonChesterfield wrote:

This was subtle. Structs that aren't packed into integers and passed in 
registers fall through to default handling which sets CanBeFlattened, saying 
that it's OK to spread the struct across multiple arguments. This is then very 
difficult to reassemble robustly using the va_arg(x, type) interface - one 
needs to compute how type is likely to have been spread out across part of the 
call frame.

Noting that these values aren't being usefully passed in registers anyway, the 
`if (Variadic) {}` sets up call instructions that pass values by value (not 
byval) and declares that every value shall be exactly four byte aligned 
(including doubles, as that's something Matt suggested for amdgpu some time 
ago). This means the frame setup implementation and the case analysis for 
testing are very straightforward.

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


[clang] [llvm] [AMDGPU] Implement variadic functions by IR lowering (PR #93362)

2024-05-24 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 560c2fd3d427a5e2dc2361abde1142f3fda40253 
6d00264803682d44cb68a8be6a6ad605ea439bd6 -- clang/test/CodeGen/voidptr-vaarg.c 
clang/test/CodeGenCXX/inline-then-fold-variadics.cpp 
llvm/include/llvm/Transforms/IPO/ExpandVariadics.h 
llvm/lib/Transforms/IPO/ExpandVariadics.cpp 
clang/lib/CodeGen/Targets/AMDGPU.cpp llvm/include/llvm/InitializePasses.h 
llvm/lib/Passes/PassBuilder.cpp llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Transforms/IPO/ExpandVariadics.cpp 
b/llvm/lib/Transforms/IPO/ExpandVariadics.cpp
index 65b53d2f49..cc97d3e27e 100644
--- a/llvm/lib/Transforms/IPO/ExpandVariadics.cpp
+++ b/llvm/lib/Transforms/IPO/ExpandVariadics.cpp
@@ -116,7 +116,7 @@ public:
   // initialized contiguous memory region.
   // Return the value to pass as the va_list argument
   virtual Value *initializeVaList(LLVMContext &Ctx, IRBuilder<> &Builder,
-  AllocaInst * VaList, Value * Buffer) = 0;
+  AllocaInst *VaList, Value *Buffer) = 0;
 
   struct VAArgSlotInfo {
 Align Align;   // With respect to the call frame

``




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


[clang] [llvm] [WIP] Expand variadic functions in IR (PR #89007)

2024-05-24 Thread Jon Chesterfield via cfe-commits

JonChesterfield wrote:

I think the comments here are fed into 
https://github.com/llvm/llvm-project/pull/93362 successfully, will go through 
the list again to check.

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


[clang] [llvm] [IPO] Optimise variadic functions (PR #92850)

2024-05-24 Thread Jon Chesterfield via cfe-commits

JonChesterfield wrote:

Dropping this in favour of 
[93362](https://github.com/llvm/llvm-project/pull/93362) on risk assessment 
grounds.

This commit enabled ad hoc testing from wasm, x64, and aarch64. However if it's 
buggy, it'll show up on those targets, which should make the code owners 
reluctant to land it.

Going with pure amdgpu first is not great from the perspective of finding 
errors in this pass - since va_arg is currently a fatal_error, existing 
software on amdgpu doesn't tend to use variadic functions - but it does 
completely derisk the initial commit.

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


[clang] [llvm] [IPO] Optimise variadic functions (PR #92850)

2024-05-24 Thread Jon Chesterfield via cfe-commits

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


[clang] [CMake] Update CMake cache file for the Win-to-Arm cross toolchains. NFC. (PR #93363)

2024-05-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vladimir Vereschaka (vvereschaka)


Changes

* allow configuration for the target specific compiler flags.
* allow lld linker for all linker outputs: shared, module and exe.
* allow configuration of libc++ ABI version.
* set MSVC runtime library to MultiThreadedDLL/MultiThreadedDebugDLL on Windows 
build hosts.
* install UCRT libraries on Windows build hosts

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


1 Files Affected:

- (modified) clang/cmake/caches/CrossWinToARMLinux.cmake (+35-3) 


``diff
diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index 736a54ece550c..62e87c6c62f85 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -89,6 +89,13 @@ endif()
 
 message(STATUS "Toolchain target to build: ${LLVM_TARGETS_TO_BUILD}")
 
+# Allow to override libc++ ABI version. Use 2 by default.
+if (NOT DEFINED LIBCXX_ABI_VERSION)
+  set(LIBCXX_ABI_VERSION 2)
+endif()
+
+message(STATUS "Toolchain's Libc++ ABI version: ${LIBCXX_ABI_VERSION}")
+
 if (NOT DEFINED CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
 endif()
@@ -109,8 +116,15 @@ set(CLANG_DEFAULT_OBJCOPY   "llvm-objcopy" 
CACHE STRING "")
 set(CLANG_DEFAULT_RTLIB "compiler-rt" CACHE STRING "")
 set(CLANG_DEFAULT_UNWINDLIB "libunwind" CACHE STRING "")
 
-if(WIN32)
-  set(CMAKE_MSVC_RUNTIME_LIBRARY"MultiThreaded" CACHE STRING "")
+if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY AND WIN32)
+  #Note: Always specify MT DLL for the LLDB build configurations on Windows 
host.
+  if (CMAKE_BUILD_TYPE STREQUAL "Debug")
+set(CMAKE_MSVC_RUNTIME_LIBRARY"MultiThreadedDebugDLL" CACHE 
STRING "")
+  else()
+set(CMAKE_MSVC_RUNTIME_LIBRARY"MultiThreadedDLL" CACHE STRING 
"")
+  endif()
+  # Grab all ucrt/vcruntime related DLLs into the binary installation folder.
+  set(CMAKE_INSTALL_UCRT_LIBRARIES  ON CACHE BOOL "")
 endif()
 
 # Set up RPATH for the target runtime/builtin libraries.
@@ -127,6 +141,15 @@ set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_INSTALL_RPATH
 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_BUILD_WITH_INSTALL_RPATH 
   ON  CACHE BOOL "")
 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_LLVM_CMAKE_DIR 
   "${LLVM_PROJECT_DIR}/llvm/cmake/modules" CACHE PATH "")
 
+if (DEFINED TOOLCHAIN_TARGET_COMPILER_FLAGS)
+  foreach(lang C;CXX;ASM)
+set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${lang}_FLAGS 
"${TOOLCHAIN_TARGET_COMPILER_FLAGS}" CACHE STRING "")
+  endforeach()
+endif()
+foreach(type SHARED;MODULE;EXE)
+  set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${type}_LINKER_FLAGS
"-fuse-ld=lld" CACHE STRING "")
+endforeach()
+
 set(LLVM_RUNTIME_TARGETS"${TOOLCHAIN_TARGET_TRIPLE}" CACHE 
STRING "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR  ON CACHE BOOL "")
 
@@ -137,6 +160,15 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_SYSROOT
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_INSTALL_RPATH
   "${RUNTIMES_INSTALL_RPATH}"  CACHE STRING "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_BUILD_WITH_INSTALL_RPATH 
   ON  CACHE BOOL "")
 
+if (DEFINED TOOLCHAIN_TARGET_COMPILER_FLAGS)
+  foreach(lang C;CXX;ASM)
+set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${lang}_FLAGS 
"${TOOLCHAIN_TARGET_COMPILER_FLAGS}" CACHE STRING "")
+  endforeach()
+endif()
+foreach(type SHARED;MODULE;EXE)
+  set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${type}_LINKER_FLAGS
"-fuse-ld=lld" CACHE STRING "")
+endforeach()
+
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_BUILTINS 
   ON CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_SANITIZERS   
   OFF CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_XRAY 
   OFF CACHE BOOL "")
@@ -164,7 +196,7 @@ 
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED
 
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_USE_COMPILER_RT 
   ON CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_SHARED   
   OFF CACHE BOOL "")
-set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION 
   2 CACHE STRING "")
+set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION 
   ${LIBCXX_ABI_VERSION} CACHE STRING "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI 
   "libcxxabi" CACHE STRING "")#!!!
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS   
   ON CACHE BOOL "")
 

``




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

[clang] [CMake] Update CMake cache file for the Win-to-Arm cross toolchains. NFC. (PR #93363)

2024-05-24 Thread Vladimir Vereschaka via cfe-commits

https://github.com/vvereschaka created 
https://github.com/llvm/llvm-project/pull/93363

* allow configuration for the target specific compiler flags.
* allow lld linker for all linker outputs: shared, module and exe.
* allow configuration of libc++ ABI version.
* set MSVC runtime library to MultiThreadedDLL/MultiThreadedDebugDLL on Windows 
build hosts.
* install UCRT libraries on Windows build hosts

>From 8a6e41d0f27885d67e9b81f2afd7a9897485e85d Mon Sep 17 00:00:00 2001
From: Vladimir Vereschaka 
Date: Fri, 24 May 2024 18:34:53 -0700
Subject: [PATCH] [CMake] Update CMake cache file for the Win-to-Arm cross
 toolchains. NFC.

* allow configuration for the target specific compiler flags.
* allow lld linker for all linker outputs: shared, module and exe.
* allow configuration of libc++ ABI version.
* set MSVC runtime library to MultiThreadedDLL/MultiThreadedDebugDLL on Windows 
build hosts.
* install UCRT libraries on Windows build hosts
---
 clang/cmake/caches/CrossWinToARMLinux.cmake | 38 +++--
 1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index 736a54ece550c..62e87c6c62f85 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -89,6 +89,13 @@ endif()
 
 message(STATUS "Toolchain target to build: ${LLVM_TARGETS_TO_BUILD}")
 
+# Allow to override libc++ ABI version. Use 2 by default.
+if (NOT DEFINED LIBCXX_ABI_VERSION)
+  set(LIBCXX_ABI_VERSION 2)
+endif()
+
+message(STATUS "Toolchain's Libc++ ABI version: ${LIBCXX_ABI_VERSION}")
+
 if (NOT DEFINED CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
 endif()
@@ -109,8 +116,15 @@ set(CLANG_DEFAULT_OBJCOPY   "llvm-objcopy" 
CACHE STRING "")
 set(CLANG_DEFAULT_RTLIB "compiler-rt" CACHE STRING "")
 set(CLANG_DEFAULT_UNWINDLIB "libunwind" CACHE STRING "")
 
-if(WIN32)
-  set(CMAKE_MSVC_RUNTIME_LIBRARY"MultiThreaded" CACHE STRING "")
+if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY AND WIN32)
+  #Note: Always specify MT DLL for the LLDB build configurations on Windows 
host.
+  if (CMAKE_BUILD_TYPE STREQUAL "Debug")
+set(CMAKE_MSVC_RUNTIME_LIBRARY"MultiThreadedDebugDLL" CACHE 
STRING "")
+  else()
+set(CMAKE_MSVC_RUNTIME_LIBRARY"MultiThreadedDLL" CACHE STRING 
"")
+  endif()
+  # Grab all ucrt/vcruntime related DLLs into the binary installation folder.
+  set(CMAKE_INSTALL_UCRT_LIBRARIES  ON CACHE BOOL "")
 endif()
 
 # Set up RPATH for the target runtime/builtin libraries.
@@ -127,6 +141,15 @@ set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_INSTALL_RPATH
 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_BUILD_WITH_INSTALL_RPATH 
   ON  CACHE BOOL "")
 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_LLVM_CMAKE_DIR 
   "${LLVM_PROJECT_DIR}/llvm/cmake/modules" CACHE PATH "")
 
+if (DEFINED TOOLCHAIN_TARGET_COMPILER_FLAGS)
+  foreach(lang C;CXX;ASM)
+set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${lang}_FLAGS 
"${TOOLCHAIN_TARGET_COMPILER_FLAGS}" CACHE STRING "")
+  endforeach()
+endif()
+foreach(type SHARED;MODULE;EXE)
+  set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${type}_LINKER_FLAGS
"-fuse-ld=lld" CACHE STRING "")
+endforeach()
+
 set(LLVM_RUNTIME_TARGETS"${TOOLCHAIN_TARGET_TRIPLE}" CACHE 
STRING "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR  ON CACHE BOOL "")
 
@@ -137,6 +160,15 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_SYSROOT
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_INSTALL_RPATH
   "${RUNTIMES_INSTALL_RPATH}"  CACHE STRING "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_BUILD_WITH_INSTALL_RPATH 
   ON  CACHE BOOL "")
 
+if (DEFINED TOOLCHAIN_TARGET_COMPILER_FLAGS)
+  foreach(lang C;CXX;ASM)
+set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${lang}_FLAGS 
"${TOOLCHAIN_TARGET_COMPILER_FLAGS}" CACHE STRING "")
+  endforeach()
+endif()
+foreach(type SHARED;MODULE;EXE)
+  set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${type}_LINKER_FLAGS
"-fuse-ld=lld" CACHE STRING "")
+endforeach()
+
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_BUILTINS 
   ON CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_SANITIZERS   
   OFF CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_XRAY 
   OFF CACHE BOOL "")
@@ -164,7 +196,7 @@ 
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED
 
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_USE_COMPILER_RT 
   ON CACHE BOOL "")
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_SHARED   
   OFF CACHE BOOL "")
-set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION 
   2 CACHE STRING "")
+set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION 
 

[clang] [analyzer] Allow recursive functions to be trivial. (PR #91876)

2024-05-24 Thread Ryosuke Niwa via cfe-commits

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


[clang] 1c90de5 - [analyzer] Allow recursive functions to be trivial. (#91876)

2024-05-24 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2024-05-24T17:48:36-07:00
New Revision: 1c90de5fe3d9f3d4048ba7e4aba2fd1613843f34

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

LOG: [analyzer] Allow recursive functions to be trivial. (#91876)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 5c797d5233089..49bbff1942167 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -271,6 +271,43 @@ class TrivialFunctionAnalysisVisitor
 
   TrivialFunctionAnalysisVisitor(CacheTy &Cache) : Cache(Cache) {}
 
+  bool IsFunctionTrivial(const Decl *D) {
+auto CacheIt = Cache.find(D);
+if (CacheIt != Cache.end())
+  return CacheIt->second;
+
+// Treat a recursive function call to be trivial until proven otherwise.
+auto [RecursiveIt, IsNew] = RecursiveFn.insert(std::make_pair(D, true));
+if (!IsNew)
+  return RecursiveIt->second;
+
+bool Result = [&]() {
+  if (auto *CtorDecl = dyn_cast(D)) {
+for (auto *CtorInit : CtorDecl->inits()) {
+  if (!Visit(CtorInit->getInit()))
+return false;
+}
+  }
+  const Stmt *Body = D->getBody();
+  if (!Body)
+return false;
+  return Visit(Body);
+}();
+
+if (!Result) {
+  // D and its mutually recursive callers are all non-trivial.
+  for (auto &It : RecursiveFn)
+It.second = false;
+}
+RecursiveIt = RecursiveFn.find(D);
+assert(RecursiveIt != RecursiveFn.end());
+Result = RecursiveIt->second;
+RecursiveFn.erase(RecursiveIt);
+Cache[D] = Result;
+
+return Result;
+  }
+
   bool VisitStmt(const Stmt *S) {
 // All statements are non-trivial unless overriden later.
 // Don't even recurse into children by default.
@@ -368,7 +405,7 @@ class TrivialFunctionAnalysisVisitor
 Name == "bitwise_cast" || Name.find("__builtin") == 0)
   return true;
 
-return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
+return IsFunctionTrivial(Callee);
   }
 
   bool
@@ -403,7 +440,7 @@ class TrivialFunctionAnalysisVisitor
   return true;
 
 // Recursively descend into the callee to confirm that it's trivial as 
well.
-return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
+return IsFunctionTrivial(Callee);
   }
 
   bool VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *OCE) {
@@ -413,7 +450,7 @@ class TrivialFunctionAnalysisVisitor
 if (!Callee)
   return false;
 // Recursively descend into the callee to confirm that it's trivial as 
well.
-return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
+return IsFunctionTrivial(Callee);
   }
 
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) {
@@ -439,7 +476,7 @@ class TrivialFunctionAnalysisVisitor
 }
 
 // Recursively descend into the callee to confirm that it's trivial.
-return TrivialFunctionAnalysis::isTrivialImpl(CE->getConstructor(), Cache);
+return IsFunctionTrivial(CE->getConstructor());
   }
 
   bool VisitCXXNewExpr(const CXXNewExpr *NE) { return VisitChildren(NE); }
@@ -513,36 +550,13 @@ class TrivialFunctionAnalysisVisitor
 
 private:
   CacheTy &Cache;
+  CacheTy RecursiveFn;
 };
 
 bool TrivialFunctionAnalysis::isTrivialImpl(
 const Decl *D, TrivialFunctionAnalysis::CacheTy &Cache) {
-  // If the function isn't in the cache, conservatively assume that
-  // it's not trivial until analysis completes. This makes every recursive
-  // function non-trivial. This also guarantees that each function
-  // will be scanned at most once.
-  auto [It, IsNew] = Cache.insert(std::make_pair(D, false));
-  if (!IsNew)
-return It->second;
-
   TrivialFunctionAnalysisVisitor V(Cache);
-
-  if (auto *CtorDecl = dyn_cast(D)) {
-for (auto *CtorInit : CtorDecl->inits()) {
-  if (!V.Visit(CtorInit->getInit()))
-return false;
-}
-  }
-
-  const Stmt *Body = D->getBody();
-  if (!Body)
-return false;
-
-  bool Result = V.Visit(Body);
-  if (Result)
-Cache[D] = true;
-
-  return Result;
+  return V.IsFunctionTrivial(D);
 }
 
 bool TrivialFunctionAnalysis::isTrivialImpl(

diff  --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 96986631726fe..a98c6eb9c84d9 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -231,6 +231,18 @@ class RefCounted {
   void method();
  

[clang] [analyzer] Allow recursive functions to be trivial. (PR #91876)

2024-05-24 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

Thanks for the review!

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


[clang] [llvm] [WebAssembly] Implement all f16x8 binary instructions. (PR #93360)

2024-05-24 Thread Brendan Dahl via cfe-commits

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


[clang] [llvm] [WebAssembly] Implement all f16x8 binary instructions. (PR #93360)

2024-05-24 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-webassembly

@llvm/pr-subscribers-clang

Author: Brendan Dahl (brendandahl)


Changes

This reuses most of the code that was created for f32x4 and f64x2 binary 
instructions and tries to follow how they were implemented.

add/sub/mul/div - use regular LL instructions
min/max - use the minimum/maximum intrinsic, and also have builtins pmin/pmax - 
use the wasm.pmax/pmin intrinsics and also have builtins

Specified at:
https://github.com/WebAssembly/half-precision/blob/29a9b9462c9285d4ccc1a5dc39214ddfd1892658/proposals/half-precision/Overview.md

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


7 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsWebAssembly.def (+4) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+4) 
- (modified) clang/test/CodeGen/builtins-wasm.c (+24) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (+5) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td (+28-9) 
- (modified) llvm/test/CodeGen/WebAssembly/half-precision.ll (+68) 
- (modified) llvm/test/MC/WebAssembly/simd-encodings.s (+24) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index fd8c1b480d6da..4e48ff48b60f5 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -135,6 +135,10 @@ TARGET_BUILTIN(__builtin_wasm_min_f64x2, "V2dV2dV2d", 
"nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_max_f64x2, "V2dV2dV2d", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_pmin_f64x2, "V2dV2dV2d", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_pmax_f64x2, "V2dV2dV2d", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_min_f16x8, "V8hV8hV8h", "nc", "half-precision")
+TARGET_BUILTIN(__builtin_wasm_max_f16x8, "V8hV8hV8h", "nc", "half-precision")
+TARGET_BUILTIN(__builtin_wasm_pmin_f16x8, "V8hV8hV8h", "nc", "half-precision")
+TARGET_BUILTIN(__builtin_wasm_pmax_f16x8, "V8hV8hV8h", "nc", "half-precision")
 
 TARGET_BUILTIN(__builtin_wasm_ceil_f32x4, "V4fV4f", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_floor_f32x4, "V4fV4f", "nc", "simd128")
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 0549afa12e430..f8be7182b5267 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20779,6 +20779,7 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
   }
   case WebAssembly::BI__builtin_wasm_min_f32:
   case WebAssembly::BI__builtin_wasm_min_f64:
+  case WebAssembly::BI__builtin_wasm_min_f16x8:
   case WebAssembly::BI__builtin_wasm_min_f32x4:
   case WebAssembly::BI__builtin_wasm_min_f64x2: {
 Value *LHS = EmitScalarExpr(E->getArg(0));
@@ -20789,6 +20790,7 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
   }
   case WebAssembly::BI__builtin_wasm_max_f32:
   case WebAssembly::BI__builtin_wasm_max_f64:
+  case WebAssembly::BI__builtin_wasm_max_f16x8:
   case WebAssembly::BI__builtin_wasm_max_f32x4:
   case WebAssembly::BI__builtin_wasm_max_f64x2: {
 Value *LHS = EmitScalarExpr(E->getArg(0));
@@ -20797,6 +20799,7 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 CGM.getIntrinsic(Intrinsic::maximum, ConvertType(E->getType()));
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_pmin_f16x8:
   case WebAssembly::BI__builtin_wasm_pmin_f32x4:
   case WebAssembly::BI__builtin_wasm_pmin_f64x2: {
 Value *LHS = EmitScalarExpr(E->getArg(0));
@@ -20805,6 +20808,7 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 CGM.getIntrinsic(Intrinsic::wasm_pmin, ConvertType(E->getType()));
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_pmax_f16x8:
   case WebAssembly::BI__builtin_wasm_pmax_f32x4:
   case WebAssembly::BI__builtin_wasm_pmax_f64x2: {
 Value *LHS = EmitScalarExpr(E->getArg(0));
diff --git a/clang/test/CodeGen/builtins-wasm.c 
b/clang/test/CodeGen/builtins-wasm.c
index 93a6ab06081c9..d6ee4f68700dc 100644
--- a/clang/test/CodeGen/builtins-wasm.c
+++ b/clang/test/CodeGen/builtins-wasm.c
@@ -825,6 +825,30 @@ float extract_lane_f16x8(f16x8 a, int i) {
   // WEBASSEMBLY-NEXT: ret float %0
   return __builtin_wasm_extract_lane_f16x8(a, i);
 }
+
+f16x8 min_f16x8(f16x8 a, f16x8 b) {
+  // WEBASSEMBLY:  %0 = tail call <8 x half> @llvm.minimum.v8f16(<8 x half> 
%a, <8 x half> %b)
+  // WEBASSEMBLY-NEXT: ret <8 x half> %0
+  return __builtin_wasm_min_f16x8(a, b);
+}
+
+f16x8 max_f16x8(f16x8 a, f16x8 b) {
+  // WEBASSEMBLY:  %0 = tail call <8 x half> @llvm.maximum.v8f16(<8 x half> 
%a, <8 x half> %b)
+  // WEBASSEMBLY-NEXT: ret <8 x half> %0
+  return __builtin_wasm_max_f16x8(a, b);
+}
+
+f16x8 pmin_f16x8(f16x8 a, f16x8 b) {
+  // WEBASSEMBLY:  %0 = tail call <8 x half> @llvm.wasm.pmin.v8f16(<8 x half> 
%a, <8 x half> %b)
+  // WEBAS

[clang] [llvm] [WebAssembly] Implement all f16x8 binary instructions. (PR #93360)

2024-05-24 Thread Brendan Dahl via cfe-commits

https://github.com/brendandahl created 
https://github.com/llvm/llvm-project/pull/93360

This reuses most of the code that was created for f32x4 and f64x2 binary 
instructions and tries to follow how they were implemented.

add/sub/mul/div - use regular LL instructions
min/max - use the minimum/maximum intrinsic, and also have builtins pmin/pmax - 
use the wasm.pmax/pmin intrinsics and also have builtins

Specified at:
https://github.com/WebAssembly/half-precision/blob/29a9b9462c9285d4ccc1a5dc39214ddfd1892658/proposals/half-precision/Overview.md

>From c33801afebb6720bc4b51fb4064b59529c40d298 Mon Sep 17 00:00:00 2001
From: Brendan Dahl 
Date: Thu, 23 May 2024 23:38:51 +
Subject: [PATCH] [WebAssembly] Implement all f16x8 binary instructions.

This reuses most of the code that was created for f32x4 and f64x2 binary
instructions and tries to follow how they were implemented.

add/sub/mul/div - use regular LL instructions
min/max - use the minimum/maximum intrinsic, and also have builtins
pmin/pmax - use the wasm.pmax/pmin intrinsics and also have builtins

Specified at:
https://github.com/WebAssembly/half-precision/blob/29a9b9462c9285d4ccc1a5dc39214ddfd1892658/proposals/half-precision/Overview.md
---
 .../clang/Basic/BuiltinsWebAssembly.def   |  4 ++
 clang/lib/CodeGen/CGBuiltin.cpp   |  4 ++
 clang/test/CodeGen/builtins-wasm.c| 24 +++
 .../WebAssembly/WebAssemblyISelLowering.cpp   |  5 ++
 .../WebAssembly/WebAssemblyInstrSIMD.td   | 37 +++---
 .../CodeGen/WebAssembly/half-precision.ll | 68 +++
 llvm/test/MC/WebAssembly/simd-encodings.s | 24 +++
 7 files changed, 157 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index fd8c1b480d6da..4e48ff48b60f5 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -135,6 +135,10 @@ TARGET_BUILTIN(__builtin_wasm_min_f64x2, "V2dV2dV2d", 
"nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_max_f64x2, "V2dV2dV2d", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_pmin_f64x2, "V2dV2dV2d", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_pmax_f64x2, "V2dV2dV2d", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_min_f16x8, "V8hV8hV8h", "nc", "half-precision")
+TARGET_BUILTIN(__builtin_wasm_max_f16x8, "V8hV8hV8h", "nc", "half-precision")
+TARGET_BUILTIN(__builtin_wasm_pmin_f16x8, "V8hV8hV8h", "nc", "half-precision")
+TARGET_BUILTIN(__builtin_wasm_pmax_f16x8, "V8hV8hV8h", "nc", "half-precision")
 
 TARGET_BUILTIN(__builtin_wasm_ceil_f32x4, "V4fV4f", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_floor_f32x4, "V4fV4f", "nc", "simd128")
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 0549afa12e430..f8be7182b5267 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20779,6 +20779,7 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
   }
   case WebAssembly::BI__builtin_wasm_min_f32:
   case WebAssembly::BI__builtin_wasm_min_f64:
+  case WebAssembly::BI__builtin_wasm_min_f16x8:
   case WebAssembly::BI__builtin_wasm_min_f32x4:
   case WebAssembly::BI__builtin_wasm_min_f64x2: {
 Value *LHS = EmitScalarExpr(E->getArg(0));
@@ -20789,6 +20790,7 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
   }
   case WebAssembly::BI__builtin_wasm_max_f32:
   case WebAssembly::BI__builtin_wasm_max_f64:
+  case WebAssembly::BI__builtin_wasm_max_f16x8:
   case WebAssembly::BI__builtin_wasm_max_f32x4:
   case WebAssembly::BI__builtin_wasm_max_f64x2: {
 Value *LHS = EmitScalarExpr(E->getArg(0));
@@ -20797,6 +20799,7 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 CGM.getIntrinsic(Intrinsic::maximum, ConvertType(E->getType()));
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_pmin_f16x8:
   case WebAssembly::BI__builtin_wasm_pmin_f32x4:
   case WebAssembly::BI__builtin_wasm_pmin_f64x2: {
 Value *LHS = EmitScalarExpr(E->getArg(0));
@@ -20805,6 +20808,7 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 CGM.getIntrinsic(Intrinsic::wasm_pmin, ConvertType(E->getType()));
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_pmax_f16x8:
   case WebAssembly::BI__builtin_wasm_pmax_f32x4:
   case WebAssembly::BI__builtin_wasm_pmax_f64x2: {
 Value *LHS = EmitScalarExpr(E->getArg(0));
diff --git a/clang/test/CodeGen/builtins-wasm.c 
b/clang/test/CodeGen/builtins-wasm.c
index 93a6ab06081c9..d6ee4f68700dc 100644
--- a/clang/test/CodeGen/builtins-wasm.c
+++ b/clang/test/CodeGen/builtins-wasm.c
@@ -825,6 +825,30 @@ float extract_lane_f16x8(f16x8 a, int i) {
   // WEBASSEMBLY-NEXT: ret float %0
   return __builtin_wasm_extract_lane_f16x8(a, i);
 }
+
+f16x8 min_f16x8(f16x8 a, f16x8 b) {
+  // WEBASSEMBLY:  %

[clang] [analyzer] Allow recursive functions to be trivial. (PR #91876)

2024-05-24 Thread Artem Dergachev via cfe-commits

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

Ok LGTM then!

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


[clang] [clang] In Sema use new parentEvaluationContext function (PR #93338)

2024-05-24 Thread Oleksandr T. via cfe-commits


@@ -17693,12 +17691,13 @@ void Sema::PopExpressionEvaluationContext() {
 
   // Append the collected materialized temporaries into previous context before
   // exit if the previous also is a lifetime extending context.
-  auto &PrevRecord = ExprEvalContexts[ExprEvalContexts.size() - 2];
+  auto &PrevRecord = parentEvaluationContext();
   if (getLangOpts().CPlusPlus23 && Rec.InLifetimeExtendingContext &&
   PrevRecord.InLifetimeExtendingContext &&
   !Rec.ForRangeLifetimeExtendTemps.empty()) {
-PrevRecord.ForRangeLifetimeExtendTemps.append(
-Rec.ForRangeLifetimeExtendTemps);
+const_cast &>(

a-tarasyuk wrote:

I'm uncertain about using `const_cast` in this case. While `EvaluationContext` 
contains properties that can be changed, `parentEvaluationContext` is declared 
as `const`. Maybe `const` shouldn't be used in this case, or we could create a 
new helper to return `ForRangeLifetimeExtendTemps` for parent eval context, or 
avoid applying `parentEvaluationContext` in this case. What do you think 
@Endilll, @Fznamznon?

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


[libcxx] [libcxxabi] [libunwind] [llvm] [runtimes] Correctly apply libdir subdir for multilib (PR #93354)

2024-05-24 Thread Petr Hosek via cfe-commits

https://github.com/petrhosek updated 
https://github.com/llvm/llvm-project/pull/93354

>From b7b4e6bf186e798d23d24a506461741e12ac79da Mon Sep 17 00:00:00 2001
From: Petr Hosek 
Date: Fri, 24 May 2024 23:15:19 +
Subject: [PATCH 1/2] [runtimes] Correctly apply libdir subdir for multilib

We weren't applying applying the libdir subdir to header directories
but this is necessary for corretness when building e.g. ASan variant.
This change also updates path construction logic accross all runtimes
and ensures they're consistent.
---
 libcxx/CMakeLists.txt  | 17 +
 libcxxabi/CMakeLists.txt   | 13 +++--
 libunwind/CMakeLists.txt   | 13 +++--
 llvm-libgcc/CMakeLists.txt | 13 +++--
 4 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index f34cb178e076e..9e0dc159565b1 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -432,18 +432,19 @@ set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output 
name for the shared lib
 set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static 
libc++ runtime library.")
 
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
-  set(LIBCXX_LIBRARY_DIR 
${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
+  set(TARGET_DIR ${LLVM_DEFAULT_TARGET_TRIPLE})
+  if(LIBCXX_LIBDIR_SUBDIR)
+string(APPEND TARGET_DIR /${LIBCXX_LIBDIR_SUBDIR})
+  endif()
+  set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${TARGET_DIR})
   set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
   set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1")
-  set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR 
"${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
-  set(LIBCXX_INSTALL_LIBRARY_DIR 
lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
+  set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR 
"${LLVM_BINARY_DIR}/include/${TARGET_DIR}/c++/v1")
+  set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${TARGET_DIR} CACHE 
STRING
   "Path where built libc++ libraries should be installed.")
-  set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR 
"${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE STRING
+  set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR 
"${CMAKE_INSTALL_INCLUDEDIR}/${TARGET_DIR}/c++/v1" CACHE STRING
   "Path where target-specific libc++ headers should be installed.")
-  if(LIBCXX_LIBDIR_SUBDIR)
-string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
-string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
-  endif()
+  unset(TARGET_DIR)
 else()
   if(LLVM_LIBRARY_OUTPUT_INTDIR)
 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index da998d2221dc4..a799407d04e61 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -182,14 +182,15 @@ set(LIBCXXABI_INSTALL_RUNTIME_DIR 
"${CMAKE_INSTALL_BINDIR}" CACHE STRING
 "Path where built libc++abi runtime libraries should be installed.")
 
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+  set(TARGET_DIR ${LLVM_DEFAULT_TARGET_TRIPLE})
+  if(LIBCXXABI_LIBDIR_SUBDIR)
+string(APPEND TARGET_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
+  endif()
   set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
-  set(LIBCXXABI_LIBRARY_DIR 
${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
-  set(LIBCXXABI_INSTALL_LIBRARY_DIR 
lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
+  set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${TARGET_DIR})
+  set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${TARGET_DIR} 
CACHE STRING
   "Path where built libc++abi libraries should be installed.")
-  if(LIBCXX_LIBDIR_SUBDIR)
-string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
-string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
-  endif()
+  unset(TARGET_DIR)
 else()
   if(LLVM_LIBRARY_OUTPUT_INTDIR)
 set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 806d5a783ec39..24acb3fd40d0d 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -129,13 +129,14 @@ set(LIBUNWIND_SHARED_OUTPUT_NAME "unwind" CACHE STRING 
"Output name for the shar
 set(LIBUNWIND_STATIC_OUTPUT_NAME "unwind" CACHE STRING "Output name for the 
static libunwind runtime library.")
 
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
-  set(LIBUNWIND_LIBRARY_DIR 
${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
-  set(LIBUNWIND_INSTALL_LIBRARY_DIR 
lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
-  "Path where built libunwind libraries should be installed.")
-  if(LIBCXX_LIBDIR_SUBDIR)
-string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
-string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
+  set(TARGET_DIR ${LLVM_DEFAULT_TARGET_TRIPLE})
+  if(LIBUNWIND_LIBDIR_SUBDIR)
+ 

[libcxx] [libcxxabi] [libunwind] [llvm] [runtimes] Correctly apply libdir subdir for multilib (PR #93354)

2024-05-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Petr Hosek (petrhosek)


Changes

We weren't applying applying the libdir subdir to header directories but this 
is necessary for corretness when building e.g. ASan variant. This change also 
updates path construction logic accross all runtimes and ensures they're 
consistent.

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


4 Files Affected:

- (modified) libcxx/CMakeLists.txt (+9-8) 
- (modified) libcxxabi/CMakeLists.txt (+7-6) 
- (modified) libunwind/CMakeLists.txt (+7-6) 
- (modified) llvm-libgcc/CMakeLists.txt (+7-6) 


``diff
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index f34cb178e076e..9e0dc159565b1 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -432,18 +432,19 @@ set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output 
name for the shared lib
 set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static 
libc++ runtime library.")
 
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
-  set(LIBCXX_LIBRARY_DIR 
${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
+  set(TARGET_DIR ${LLVM_DEFAULT_TARGET_TRIPLE})
+  if(LIBCXX_LIBDIR_SUBDIR)
+string(APPEND TARGET_DIR /${LIBCXX_LIBDIR_SUBDIR})
+  endif()
+  set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${TARGET_DIR})
   set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
   set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1")
-  set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR 
"${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
-  set(LIBCXX_INSTALL_LIBRARY_DIR 
lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
+  set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR 
"${LLVM_BINARY_DIR}/include/${TARGET_DIR}/c++/v1")
+  set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${TARGET_DIR} CACHE 
STRING
   "Path where built libc++ libraries should be installed.")
-  set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR 
"${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE STRING
+  set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR 
"${CMAKE_INSTALL_INCLUDEDIR}/${TARGET_DIR}/c++/v1" CACHE STRING
   "Path where target-specific libc++ headers should be installed.")
-  if(LIBCXX_LIBDIR_SUBDIR)
-string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
-string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
-  endif()
+  unset(TARGET_DIR)
 else()
   if(LLVM_LIBRARY_OUTPUT_INTDIR)
 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index da998d2221dc4..a799407d04e61 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -182,14 +182,15 @@ set(LIBCXXABI_INSTALL_RUNTIME_DIR 
"${CMAKE_INSTALL_BINDIR}" CACHE STRING
 "Path where built libc++abi runtime libraries should be installed.")
 
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+  set(TARGET_DIR ${LLVM_DEFAULT_TARGET_TRIPLE})
+  if(LIBCXXABI_LIBDIR_SUBDIR)
+string(APPEND TARGET_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
+  endif()
   set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
-  set(LIBCXXABI_LIBRARY_DIR 
${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
-  set(LIBCXXABI_INSTALL_LIBRARY_DIR 
lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
+  set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${TARGET_DIR})
+  set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${TARGET_DIR} 
CACHE STRING
   "Path where built libc++abi libraries should be installed.")
-  if(LIBCXX_LIBDIR_SUBDIR)
-string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
-string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
-  endif()
+  unset(TARGET_DIR)
 else()
   if(LLVM_LIBRARY_OUTPUT_INTDIR)
 set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 806d5a783ec39..24acb3fd40d0d 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -129,13 +129,14 @@ set(LIBUNWIND_SHARED_OUTPUT_NAME "unwind" CACHE STRING 
"Output name for the shar
 set(LIBUNWIND_STATIC_OUTPUT_NAME "unwind" CACHE STRING "Output name for the 
static libunwind runtime library.")
 
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
-  set(LIBUNWIND_LIBRARY_DIR 
${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
-  set(LIBUNWIND_INSTALL_LIBRARY_DIR 
lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
-  "Path where built libunwind libraries should be installed.")
-  if(LIBCXX_LIBDIR_SUBDIR)
-string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
-string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
+  set(TARGET_DIR ${LLVM_DEFAULT_TARGET_TRIPLE})
+  if(LIBUNWIND_LIBDIR_SUBDIR)
+string(APPEND TARGET_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
   endif()
+  set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${TARGET_DIR})
+  set(LIBUNWIN

[libcxx] [libcxxabi] [libunwind] [llvm] [runtimes] Correctly apply libdir subdir for multilib (PR #93354)

2024-05-24 Thread Petr Hosek via cfe-commits

https://github.com/petrhosek created 
https://github.com/llvm/llvm-project/pull/93354

We weren't applying applying the libdir subdir to header directories but this 
is necessary for corretness when building e.g. ASan variant. This change also 
updates path construction logic accross all runtimes and ensures they're 
consistent.

>From b7b4e6bf186e798d23d24a506461741e12ac79da Mon Sep 17 00:00:00 2001
From: Petr Hosek 
Date: Fri, 24 May 2024 23:15:19 +
Subject: [PATCH] [runtimes] Correctly apply libdir subdir for multilib

We weren't applying applying the libdir subdir to header directories
but this is necessary for corretness when building e.g. ASan variant.
This change also updates path construction logic accross all runtimes
and ensures they're consistent.
---
 libcxx/CMakeLists.txt  | 17 +
 libcxxabi/CMakeLists.txt   | 13 +++--
 libunwind/CMakeLists.txt   | 13 +++--
 llvm-libgcc/CMakeLists.txt | 13 +++--
 4 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index f34cb178e076e..9e0dc159565b1 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -432,18 +432,19 @@ set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output 
name for the shared lib
 set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static 
libc++ runtime library.")
 
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
-  set(LIBCXX_LIBRARY_DIR 
${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
+  set(TARGET_DIR ${LLVM_DEFAULT_TARGET_TRIPLE})
+  if(LIBCXX_LIBDIR_SUBDIR)
+string(APPEND TARGET_DIR /${LIBCXX_LIBDIR_SUBDIR})
+  endif()
+  set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${TARGET_DIR})
   set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
   set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1")
-  set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR 
"${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
-  set(LIBCXX_INSTALL_LIBRARY_DIR 
lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
+  set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR 
"${LLVM_BINARY_DIR}/include/${TARGET_DIR}/c++/v1")
+  set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${TARGET_DIR} CACHE 
STRING
   "Path where built libc++ libraries should be installed.")
-  set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR 
"${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE STRING
+  set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR 
"${CMAKE_INSTALL_INCLUDEDIR}/${TARGET_DIR}/c++/v1" CACHE STRING
   "Path where target-specific libc++ headers should be installed.")
-  if(LIBCXX_LIBDIR_SUBDIR)
-string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
-string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
-  endif()
+  unset(TARGET_DIR)
 else()
   if(LLVM_LIBRARY_OUTPUT_INTDIR)
 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index da998d2221dc4..a799407d04e61 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -182,14 +182,15 @@ set(LIBCXXABI_INSTALL_RUNTIME_DIR 
"${CMAKE_INSTALL_BINDIR}" CACHE STRING
 "Path where built libc++abi runtime libraries should be installed.")
 
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+  set(TARGET_DIR ${LLVM_DEFAULT_TARGET_TRIPLE})
+  if(LIBCXXABI_LIBDIR_SUBDIR)
+string(APPEND TARGET_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
+  endif()
   set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
-  set(LIBCXXABI_LIBRARY_DIR 
${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
-  set(LIBCXXABI_INSTALL_LIBRARY_DIR 
lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
+  set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${TARGET_DIR})
+  set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${TARGET_DIR} 
CACHE STRING
   "Path where built libc++abi libraries should be installed.")
-  if(LIBCXX_LIBDIR_SUBDIR)
-string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
-string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
-  endif()
+  unset(TARGET_DIR)
 else()
   if(LLVM_LIBRARY_OUTPUT_INTDIR)
 set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 806d5a783ec39..24acb3fd40d0d 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -129,13 +129,14 @@ set(LIBUNWIND_SHARED_OUTPUT_NAME "unwind" CACHE STRING 
"Output name for the shar
 set(LIBUNWIND_STATIC_OUTPUT_NAME "unwind" CACHE STRING "Output name for the 
static libunwind runtime library.")
 
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
-  set(LIBUNWIND_LIBRARY_DIR 
${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
-  set(LIBUNWIND_INSTALL_LIBRARY_DIR 
lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
-  "Path where built libunwind libraries should be installed.")
-  if(LIBCXX_LIBD

[clang] [clang][Driver] Fix enabling strict alising by default when the environment is MSVC (PR #91689)

2024-05-24 Thread Max Winkler via cfe-commits

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


[clang] d637647 - [clang][Driver] Fix enabling strict alising by default when the environment is MSVC (#91689)

2024-05-24 Thread via cfe-commits

Author: Max Winkler
Date: 2024-05-24T19:12:38-04:00
New Revision: d63764718c93a40d25cf4ae62b6ea6cb8eda6435

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

LOG: [clang][Driver] Fix enabling strict alising by default when the 
environment is MSVC (#91689)

>From looking at the rest of code and from my own understanding, the
driver mode is supposed to be independent of MSVC compatibility when the
target triple is `*-windows-msvc`.
Therefore strict aliasing should be disabled by default when the target
triple is `*-windows-msvc` so code assuming MSVC behaves as expected
when compiled with Clang.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/Ofast.c
clang/test/Driver/clang_f_opts.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fd7f3ee13d9ac..e40b236c914d9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -878,6 +878,10 @@ Windows Support
   including STL headers will no longer slow down compile times since 
``intrin.h``
   is not included from MSVC STL.
 
+- When the target triple is `*-windows-msvc` strict aliasing is now disabled 
by default
+  to ensure compatibility with msvc. Previously strict aliasing was only 
disabled if the
+  driver mode was cl.
+
 LoongArch Support
 ^
 

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 15cf58f9d3339..adb1b2ff566cb 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5681,11 +5681,10 @@ void Clang::ConstructJob(Compilation &C, const 
JobAction &JA,
   // enabled.  This alias option is being used to simplify the hasFlag logic.
   OptSpecifier StrictAliasingAliasOption =
   OFastEnabled ? options::OPT_Ofast : options::OPT_fstrict_aliasing;
-  // We turn strict aliasing off by default if we're in CL mode, since MSVC
+  // We turn strict aliasing off by default if we're Windows MSVC since MSVC
   // doesn't do any TBAA.
-  bool TBAAOnByDefault = !D.IsCLMode();
   if (!Args.hasFlag(options::OPT_fstrict_aliasing, StrictAliasingAliasOption,
-options::OPT_fno_strict_aliasing, TBAAOnByDefault))
+options::OPT_fno_strict_aliasing, !IsWindowsMSVC))
 CmdArgs.push_back("-relaxed-aliasing");
   if (!Args.hasFlag(options::OPT_fstruct_path_tbaa,
 options::OPT_fno_struct_path_tbaa, true))

diff  --git a/clang/test/Driver/Ofast.c b/clang/test/Driver/Ofast.c
index 1f9fc78ec1ef8..8b7f2217eca2f 100644
--- a/clang/test/Driver/Ofast.c
+++ b/clang/test/Driver/Ofast.c
@@ -3,7 +3,9 @@
 // RUN: %clang -fno-fast-math -Ofast -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST %s
 // RUN: %clang -fno-strict-aliasing -Ofast -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST %s
 // RUN: %clang -fno-vectorize -Ofast -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST %s
-// RUN: %clang -Ofast -O2 -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST-O2 %s
+// RUN: %clang -Ofast -O2 -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST-O2 \
+// RUN:  %if target={{.*-windows-msvc.*}} %{ 
--check-prefix=CHECK-OFAST-O2-ALIASING-MSVC %} \
+// RUN:  %else %{ --check-prefix=CHECK-OFAST-O2-ALIASING %} %s
 // RUN: %clang -Ofast -fno-fast-math -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST-NO-FAST-MATH %s
 // RUN: %clang -Ofast -fno-strict-aliasing -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST-NO-STRICT-ALIASING %s
 // RUN: %clang -Ofast -fno-vectorize -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST-NO-VECTORIZE %s
@@ -15,7 +17,8 @@
 // CHECK-OFAST: -vectorize-loops
 
 // CHECK-OFAST-O2: -cc1
-// CHECK-OFAST-O2-NOT: -relaxed-aliasing
+// CHECK-OFAST-O2-ALIASING-NOT: -relaxed-aliasing
+// CHECK-OFAST-O2-ALIASING-MSVC: -relaxed-aliasing
 // CHECK-OFAST-O2-NOT: -ffast-math
 // CHECK-OFAST-O2-NOT: -Ofast
 // CHECK-OFAST-O2: -vectorize-loops

diff  --git a/clang/test/Driver/clang_f_opts.c 
b/clang/test/Driver/clang_f_opts.c
index 472d0725a7934..d69cd199ac61d 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -623,3 +623,9 @@
 // RUN: %clang -### --target=aarch64-windows-msvc -fno-ms-volatile %s 2>&1 | 
FileCheck -check-prefix=CHECK-NO-MS-VOLATILE %s
 // CHECK-MS-VOLATILE: -fms-volatile
 // CHECK-NO-MS-VOLATILE-NOT: -fms-volatile
+
+// RUN: %clang -### --target=x86_64-pc-windows-msvc %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-STRICT-ALIASING %s
+// RUN: %clang -### --target=x86_64-pc-windows-msvc -fstrict-aliasing %s 2>&1 
| FileCheck -check-prefix=CHECK-STRICT-ALIASING %s
+// RUN: %clang -### --target=x86_64-pc-windows-msvc -fno-strict-aliasing %s 
2>&1 | FileCheck -check-prefix=CHECK-NO-STRICT-ALIASING %s
+// CHECK

[clang] [Clang] Throw error when calling atomic with pointer to zero size object (PR #91057)

2024-05-24 Thread Hendrik Hübner via cfe-commits

https://github.com/HendrikHuebner updated 
https://github.com/llvm/llvm-project/pull/91057

From 487ec3df346924f71b66e5753c844c97991e Mon Sep 17 00:00:00 2001
From: hhuebner 
Date: Sat, 4 May 2024 13:49:38 +0200
Subject: [PATCH 1/2] [Clang] Throw error when calling atomic with pointer to
 zero size object

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++-
 clang/lib/Sema/SemaChecking.cpp   | 17 +++---
 clang/test/Sema/atomic-ops.c  | 32 +++
 3 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6c4d92790afc5..4aab1d86fc5ec 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8808,8 +8808,10 @@ def err_builtin_fn_use : Error<"builtin functions must 
be directly called">;
 
 def warn_call_wrong_number_of_arguments : Warning<
   "too %select{few|many}0 arguments in call to %1">;
+
 def err_atomic_builtin_must_be_pointer : Error<
-  "address argument to atomic builtin must be a pointer (%0 invalid)">;
+  "address argument to atomic builtin must be a pointer %select{|to a 
non-zero-sized object }1(%0 invalid)">;
+
 def err_atomic_builtin_must_be_pointer_intptr : Error<
   "address argument to atomic builtin must be a pointer to integer or pointer"
   " (%0 invalid)">;
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3179d542b1f92..22ed9776f5995 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3820,7 +3820,7 @@ bool Sema::CheckARMBuiltinExclusiveCall(unsigned 
BuiltinID, CallExpr *TheCall,
   const PointerType *pointerType = PointerArg->getType()->getAs();
   if (!pointerType) {
 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_must_be_pointer)
-<< PointerArg->getType() << PointerArg->getSourceRange();
+<< PointerArg->getType() << 0 << PointerArg->getSourceRange();
 return true;
   }
 
@@ -3854,7 +3854,7 @@ bool Sema::CheckARMBuiltinExclusiveCall(unsigned 
BuiltinID, CallExpr *TheCall,
   if (!ValType->isIntegerType() && !ValType->isAnyPointerType() &&
   !ValType->isBlockPointerType() && !ValType->isFloatingType()) {
 Diag(DRE->getBeginLoc(), 
diag::err_atomic_builtin_must_be_pointer_intfltptr)
-<< PointerArg->getType() << PointerArg->getSourceRange();
+<< PointerArg->getType() << 0 << PointerArg->getSourceRange();
 return true;
   }
 
@@ -8526,7 +8526,7 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, 
SourceRange ExprRange,
   const PointerType *pointerType = Ptr->getType()->getAs();
   if (!pointerType) {
 Diag(ExprRange.getBegin(), diag::err_atomic_builtin_must_be_pointer)
-<< Ptr->getType() << Ptr->getSourceRange();
+<< Ptr->getType() << 0 << Ptr->getSourceRange();
 return ExprError();
   }
 
@@ -8555,6 +8555,13 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, 
SourceRange ExprRange,
 }
   }
 
+  // Pointer to object of size zero is not allowed.
+  if (Context.getTypeInfoInChars(AtomTy).Width.isZero()) {
+Diag(ExprRange.getBegin(), diag::err_atomic_builtin_must_be_pointer)
+<< Ptr->getType() << 1 << Ptr->getSourceRange();
+return ExprError();
+  }
+
   // For an arithmetic operation, the implied arithmetic must be well-formed.
   if (Form == Arithmetic) {
 // GCC does not enforce these rules for GNU atomics, but we do to help 
catch
@@ -8946,7 +8953,7 @@ ExprResult Sema::BuiltinAtomicOverloaded(ExprResult 
TheCallResult) {
   const PointerType *pointerType = FirstArg->getType()->getAs();
   if (!pointerType) {
 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_must_be_pointer)
-<< FirstArg->getType() << FirstArg->getSourceRange();
+<< FirstArg->getType() << 0 << FirstArg->getSourceRange();
 return ExprError();
   }
 
@@ -8954,7 +8961,7 @@ ExprResult Sema::BuiltinAtomicOverloaded(ExprResult 
TheCallResult) {
   if (!ValType->isIntegerType() && !ValType->isAnyPointerType() &&
   !ValType->isBlockPointerType()) {
 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_must_be_pointer_intptr)
-<< FirstArg->getType() << FirstArg->getSourceRange();
+<< FirstArg->getType() << 0 << FirstArg->getSourceRange();
 return ExprError();
   }
 
diff --git a/clang/test/Sema/atomic-ops.c b/clang/test/Sema/atomic-ops.c
index 1d36667d6cf40..2024b81ce6aec 100644
--- a/clang/test/Sema/atomic-ops.c
+++ b/clang/test/Sema/atomic-ops.c
@@ -639,6 +639,38 @@ void memory_checks(_Atomic(int) *Ap, int *p, int val) {
   (void)__atomic_compare_exchange_n(p, p, val, 0, memory_order_seq_cst, -1); 
// expected-warning {{memory order argument to atomic operation is invalid}}
 }
 
+struct Z {
+  char z[];
+};
+
+void zeroSizeArgError(struct Z *a, struct Z *b, struct Z *c) {
+  __atomic_exchange(b, b, c, memory_order_relaxed); // expected-error 
{{address argument

[clang] [Bounds-Safety] Add sized_by, counted_by_or_null & sized_by_or_null (PR #93231)

2024-05-24 Thread Dan Liew via cfe-commits


@@ -8641,22 +8641,33 @@ enum class CountedByInvalidPointeeTypeKind {
   VALID,
 };
 
-static bool CheckCountedByAttrOnField(
-Sema &S, FieldDecl *FD, Expr *E,
-llvm::SmallVectorImpl &Decls) {
+static bool
+CheckCountedByAttrOnField(Sema &S, FieldDecl *FD, Expr *E,
+  llvm::SmallVectorImpl &Decls,
+  bool CountInBytes, bool OrNull) {
   // Check the context the attribute is used in
 
+  unsigned Kind = CountInBytes;
+  if (OrNull)
+Kind += 2;
+
   if (FD->getParent()->isUnion()) {
 S.Diag(FD->getBeginLoc(), diag::err_counted_by_attr_in_union)
-<< FD->getSourceRange();
+<< Kind << FD->getSourceRange();
 return true;
   }
 
   const auto FieldTy = FD->getType();
+  if (FieldTy->isArrayType() && (CountInBytes || OrNull)) {
+S.Diag(FD->getBeginLoc(),
+   diag::err_counted_by_attr_not_on_ptr_or_flexible_array_member)

delcypher wrote:

> > The diagnostic name is a little misleading here because CountInBytes 
> > suggested __sized_by but the diagnostic name has counted_by in its name
> 
> I kept it because it's the same family of attributes. Do you have a 
> suggestion for a name that would imply that it's not just for `counted_by`, 
> but more specific than `bounds_attribute`?

We use `CountAttributedType` to represent both `counted_by` and `sized_by`  so 
how about `err_count_attr_...` as the diagnostic prefix? I don't have strong 
opinions on exactly what the name should be.

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


[clang] [Bounds-Safety] Add sized_by, counted_by_or_null & sized_by_or_null (PR #93231)

2024-05-24 Thread Dan Liew via cfe-commits


@@ -8641,22 +8641,33 @@ enum class CountedByInvalidPointeeTypeKind {
   VALID,
 };
 
-static bool CheckCountedByAttrOnField(
-Sema &S, FieldDecl *FD, Expr *E,
-llvm::SmallVectorImpl &Decls) {
+static bool
+CheckCountedByAttrOnField(Sema &S, FieldDecl *FD, Expr *E,
+  llvm::SmallVectorImpl &Decls,
+  bool CountInBytes, bool OrNull) {
   // Check the context the attribute is used in
 
+  unsigned Kind = CountInBytes;
+  if (OrNull)
+Kind += 2;
+
   if (FD->getParent()->isUnion()) {
 S.Diag(FD->getBeginLoc(), diag::err_counted_by_attr_in_union)
-<< FD->getSourceRange();
+<< Kind << FD->getSourceRange();
 return true;
   }
 
   const auto FieldTy = FD->getType();
+  if (FieldTy->isArrayType() && (CountInBytes || OrNull)) {
+S.Diag(FD->getBeginLoc(),
+   diag::err_counted_by_attr_not_on_ptr_or_flexible_array_member)

delcypher wrote:

> > The OrNull case probably deserves its own special diagnostic because in 
> > that case the diagnostic should explain that they cannot use the attribute 
> > on arrays and that they need to use __counted_by instead.
> 
> That is also true for `CountInBytes`. But I agree that it would be good for 
> the diagnostic to suggest `counted_by`.

Hmm looking at it more closely for the 
`err_counted_by_attr_not_on_ptr_or_flexible_array_member` means the diagnostic 
output for

```
struct Test {
  int count;
  int fma[] __counted_by_or_null(count)
}
```

would look something like

```
counted_by_or_null only applies to pointers
```

i.e. mentioning flexible array members is dropped (I initially thought it 
wasn't). So actually I guess this is fine. Suggesting the right attribute would 
be an extra bonus.  If you don't want to do it now file an issue (tagged with 
clang:bounds-safety).

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


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

2024-05-24 Thread David Blaikie via cfe-commits

dwblaikie wrote:

> I think the comment about `s/members/methods/` is still outstanding - I agree 
> that methods is more descriptive than members.

Yeah, seems I'm outvoted here. I'm a bit of a pedant for the C++ standard 
language, which doesn't talk about "methods", only "member functions". But 
anyway, since you're likeyl the first folks to use this, I've made that change 
toward "methods".

> I'm +1 on having this be non-default; adding it to SCE tuning is also not 
> necessary (or desired) for now, because this is more aggressive than our 
> private option (we keep entries for member functions that are called), and 
> we're still working out whether we can/should adopt this instead.

Yeah, no plans to make this the default any time soon - will start with it 
entirely off by default, and figured you Sony folks can see if it can be your 
default in the future - save you carrying the downstream patches, gives you 
some hope other folks might adopt the same strategy (& folks considering 
adopting it would have some reassurance that other people are living with 
it/interested in caring for it already)


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


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

2024-05-24 Thread David Blaikie via cfe-commits


@@ -4260,6 +4260,13 @@ defm strict_dwarf : BoolOption<"g", "strict-dwarf",
   "the specified version, avoiding features from later versions.">,
   NegFlag, BothFlags<[], [ClangOption, CLOption, DXCOption]>>,
   Group;
+defm omit_unreferenced_members : BoolOption<"g", "omit-unreferenced-members",
+  CodeGenOpts<"DebugOmitUnreferencedMembers">, DefaultFalse,
+  PosFlag,
+  NegFlag, BothFlags<[], [ClangOption, CLOption, DXCOption]>>,
+  Group;

dwblaikie wrote:

Wasn't able to get this to avoid the `renderDebugOptions` code - even other 
uses of marshalling (and it looks like BoolOption, and even BoolGOption, have 
some marshalling details in their implementation - so maybe they're getting the 
same functionality as MarshallingInfoFlag already?) seem to still have to 
handle/repeat the flag from the driver to the frontend.

Oh, and now that I'm checking compatible flags in the driver (disabling this 
feature if -fstandalone-debug or -fdebug-types-section are enabled) then 
there's probably no avoiding having some code there anyway.

Switching to BoolGOption does make it a bit tidier, though.

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


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

2024-05-24 Thread David Blaikie via cfe-commits


@@ -2755,7 +2755,7 @@ CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
 
   // Collect data fields (including static variables and any initializers).
   CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
-  if (CXXDecl)
+  if (CXXDecl && !CGM.getCodeGenOpts().DebugOmitUnreferencedMembers)

dwblaikie wrote:

Added that at the driver level - and similarly for type units (since they use 
an mllvm flag, clang frontend/codegen doesn't actually know if type units are 
enabled). (though this doesn't work out /that/ badly for type units, in some 
sense - the type units are still consistent, they just consistently contain no 
member functions (in the same way that even without the flag, for things like 
member function template instantiations we never put them in the member list, 
so they never end up in type units - only attached as declarations to the 
skeleton type DIE in the CU))

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


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

2024-05-24 Thread David Blaikie via cfe-commits


@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -gomit-unreferenced-members %s 
-emit-llvm -o - | FileCheck %s

dwblaikie wrote:

Done

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


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

2024-05-24 Thread David Blaikie via cfe-commits

https://github.com/dwblaikie updated 
https://github.com/llvm/llvm-project/pull/87018

>From 6834c245205d1e38a615e97217dada3cd941ed03 Mon Sep 17 00:00:00 2001
From: David Blaikie 
Date: Fri, 2 Jun 2023 15:04:14 +
Subject: [PATCH 1/3] [DebugInfo] Add flag to only emit referenced member
 functions

Complete C++ type information can be quite expensive - and there's
limited value in representing every member function, even those that
can't be called (we don't do similarly for every non-member function
anyway). So add a flag to opt out of this behavior for experimenting
with this more terse behavior.

I think Sony already does this by default, so perhaps with a change to
the defaults, Sony can migrate to this rather than a downstream patch.

This breaks current debuggers in some expected ways - but those
breakages are visible without this feature too. Consider member function
template instantiations - they can't be consistently enumerated in every
translation unit:

a.h:
```
struct t1 {
  template 
  static int f1() {
return i;
  }
};
namespace ns {
template 
int f1() {
  return i;
}
}  // namespace ns
```
a.cpp:
```
void f1() {
  t1::f1<0>();
  ns::f1<0>();
}
```
b.cpp:
```
void f1();
int main() {
  f1();
  t1::f1<1>();
  ns::f1<1>();
}
```
```
(gdb) p ns::f1<0>()
$1 = 0
(gdb) p ns::f1<1>()
$2 = 1
(gdb) p t1::f1<0>()
Couldn't find method t1::f1<0>
(gdb) p t1::f1<1>()
$3 = 1
(gdb) s
f1 () at a.cpp:3
3 t1::f1<0>();
(gdb) p t1::f1<0>()
$4 = 0
(gdb) p t1::f1<1>()
Couldn't find method t1::f1<1>
(gdb)
```

(other similar non-canonical features are implicit special members
(copy/move ctor/assignment operator, default ctor) and nested types (eg:
pimpl idiom, where the nested type is declared-but-not-defined in one
TU, and defined in another TU))

lldb can't parse the template expressions above, so I'm not sure how to
test it there, but I'd guess it has similar problems. (
https://stackoverflow.com/questions/64602475/how-to-print-value-returned-by-template-member-function-in-gdb-lldb-debugging
so... I guess that's just totally not supported in lldb, how
unfortunate. And implicit special members are instantiated implicitly by
lldb, so missing those doesn't tickle the same issue)

Some very rudimentary numbers for a clang debug build:
.debug_info section size:
-g: 476MiB
-g -fdebug-types-section: 357MiB
-g -gomit-unreferenced-members: 340MiB

Though it also means a major reduction in .debug_str size,
-fdebug-types-section doesn't reduce string usage (so the first two
examples have the same .debug_str size, 247MiB), down to 175MiB.

So for total clang binary size (I don't have a quick "debug section size
reduction" on-hand): 1.45 (no type units) GiB -> 1.34 -> 1.22, so it
saves about 120MiB of binary size.

Also open to any riffing on the flag name for sure.

@probinson - would this be an accurate upstreaming of your internal 
handling/would you use this functionality? If it wouldn't be useful to you, 
it's maybe not worth adding upstream yet - not sure we'll use it at Google, but 
if it was useful to you folks and meant other folks could test with it it 
seemed maybe useful.

Original Differential Revision: https://reviews.llvm.org/D152017
---
 clang/include/clang/Basic/DebugOptions.def   |  2 ++
 clang/include/clang/Driver/Options.td|  7 +++
 clang/lib/CodeGen/CGDebugInfo.cpp|  2 +-
 clang/lib/Driver/ToolChains/Clang.cpp|  6 ++
 .../test/CodeGenCXX/debug-info-incomplete-types.cpp  | 12 
 clang/test/Driver/debug-options.c|  6 ++
 6 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/debug-info-incomplete-types.cpp

diff --git a/clang/include/clang/Basic/DebugOptions.def 
b/clang/include/clang/Basic/DebugOptions.def
index 7cd3edf08a17e..fe2adaa20f4e3 100644
--- a/clang/include/clang/Basic/DebugOptions.def
+++ b/clang/include/clang/Basic/DebugOptions.def
@@ -68,6 +68,8 @@ BENIGN_DEBUGOPT(NoInlineLineTables, 1, 0) ///< Whether debug 
info should contain
   ///< inline line tables.
 
 DEBUGOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF info.
+DEBUGOPT(DebugOmitUnreferencedMembers, 1, 0) ///< Omit unreferenced member
+///< functions in type debug info.
 
 /// Control the Assignment Tracking debug info feature.
 BENIGN_ENUM_DEBUGOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2,
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 29066ea14280c..4000403a1991d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4260,6 +4260,13 @@ defm strict_dwarf : BoolOption<"g", "strict-dwarf",
   "the specified version, avoiding features from later versions.">,
   NegFlag, BothFlags<[], [ClangOption, CLOption, DXCOption]>>,
   Group;
+defm omit_unreferenced_members : BoolOption<"g

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-05-24 Thread Justin Stitt via cfe-commits

https://github.com/JustinStitt updated 
https://github.com/llvm/llvm-project/pull/86618

>From 1df2f520f6a8ab0e45b80f7a1d680d34f8ab37c9 Mon Sep 17 00:00:00 2001
From: Justin Stitt 
Date: Tue, 5 Mar 2024 03:14:49 +
Subject: [PATCH] implement wraps attribute

Signed-off-by: Justin Stitt 
---
 clang/docs/ReleaseNotes.rst   | 10 +++
 clang/include/clang/AST/Expr.h|  3 +
 clang/include/clang/AST/Type.h|  2 +
 clang/include/clang/Basic/Attr.td |  7 ++
 clang/include/clang/Basic/AttrDocs.td | 69 +++
 clang/include/clang/Basic/DiagnosticGroups.td |  6 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 ++
 clang/lib/AST/Expr.cpp|  9 +++
 clang/lib/AST/ExprConstant.cpp|  4 +-
 clang/lib/AST/Type.cpp|  4 ++
 clang/lib/AST/TypePrinter.cpp |  3 +
 clang/lib/CodeGen/CGExprScalar.cpp| 47 +
 clang/lib/Sema/Sema.cpp   |  3 +
 clang/lib/Sema/SemaChecking.cpp   | 33 -
 clang/lib/Sema/SemaDeclAttr.cpp   |  8 ++-
 clang/lib/Sema/SemaType.cpp   | 15 
 clang/test/CodeGen/integer-overflow.c | 66 ++
 clang/test/CodeGen/unsigned-overflow.c| 63 ++---
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/Sema/attr-wraps.c  | 43 
 20 files changed, 377 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/Sema/attr-wraps.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba4637d98197f..a1fc18523936f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -407,6 +407,16 @@ Attribute Changes in Clang
   (`OpenCL-C to Vulkan SPIR-V compiler `_) to 
identify functions coming from libclc
   (`OpenCL-C builtin library `_).
 
+- Introduced ``__attribute((wraps))__`` which can be added to type or variable
+  declarations. Using an attributed type or variable in an arithmetic
+  expression will define the overflow behavior for that expression as having
+  two's complement wrap-around. These expressions cannot trigger integer
+  overflow warnings or sanitizer warnings. They also cannot be optimized away
+  by some eager UB optimizations.
+
+  This attribute is only valid for C, as there are built-in language
+  alternatives for other languages.
+
 Improvements to Clang's diagnostics
 ---
 - Clang now applies syntax highlighting to the code snippets it
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index f2bf667636dc9..48968cbbbaf7e 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -4061,6 +4061,9 @@ class BinaryOperator : public Expr {
 return getFPFeaturesInEffect(LO).getAllowFEnvAccess();
   }
 
+  /// Does one of the subexpressions have the wraps attribute?
+  bool hasWrappingOperand(const ASTContext &Ctx) const;
+
 protected:
   BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc,
  QualType ResTy, ExprValueKind VK, ExprObjectKind OK,
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index da3834f19ca04..641f943205891 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1441,6 +1441,8 @@ class QualType {
 return getQualifiers().hasStrongOrWeakObjCLifetime();
   }
 
+  bool hasWrapsAttr() const;
+
   // true when Type is objc's weak and weak is enabled but ARC isn't.
   bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const;
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 7008bea483c87..922dcba29a8de 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4595,3 +4595,10 @@ def ClspvLibclcBuiltin: InheritableAttr {
   let Documentation = [ClspvLibclcBuiltinDoc];
   let SimpleHandler = 1;
 }
+
+def Wraps : DeclOrTypeAttr {
+  let Spellings = [Clang<"wraps">];
+  let Subjects = SubjectList<[Var, TypedefName, Field]>;
+  let Documentation = [WrapsDocs];
+  let LangOpts = [COnly];
+}
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 54197d588eb45..dc050e616d63a 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8106,3 +8106,72 @@ Attribute used by `clspv`_ (OpenCL-C to Vulkan SPIR-V 
compiler) to identify func
 .. _`libclc`: https://libclc.llvm.org
 }];
 }
+
+def WrapsDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+This attribute can be used with type or variable declarations to denote that
+arithmetic containing these marked components have defined overflow behavior.
+Specifically, the behavior is defined as being consistent with two's complement
+wrap-around. For the purposes of s

[clang] [compiler-rt] [llvm] [IRPGO] [Draft] Import vtable definitions in ThinTLO and use more efficient vtable comparison sequence with cost-benefit analysis (PR #69141)

2024-05-24 Thread Mingming Liu via cfe-commits

minglotus-6 wrote:

Close this stale patch and won't merge conflicts in this one.

Working on https://github.com/llvm/llvm-project/pull/81442 now.

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


[clang] [compiler-rt] [llvm] [IRPGO] [Draft] Import vtable definitions in ThinTLO and use more efficient vtable comparison sequence with cost-benefit analysis (PR #69141)

2024-05-24 Thread Mingming Liu via cfe-commits

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


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-05-24 Thread Alexandre Ganea via cfe-commits

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


[clang] 90e33e2 - [clang-scan-deps] Expand response files before the argument adjuster (#89950)

2024-05-24 Thread via cfe-commits

Author: Alexandre Ganea
Date: 2024-05-24T17:20:08-04:00
New Revision: 90e33e20a594b8a404af1df93b629137cb605a21

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

LOG: [clang-scan-deps] Expand response files before the argument adjuster 
(#89950)

Previously, since response (.rsp) files weren't expanded at the very
beginning of clang-scan-deps, we only parsed the command-line as
provided in the Clang .cdb file. Unfortunately, when using Unreal
Engine, arguments are always generated in a .rsp file (ie.
`/path/to/clang-cl.exe @/path/to/filename_args.rsp`).

After this patch, `/Fo` can be parsed and added to the final
command-line. Without this option, the make targets that are emitted are
made up from the input file name alone. We have some cases where the
same input in the project generates several output files, so we end up
with duplicate make targets in the scan-deps emitted dependency file.

Added: 
clang/test/ClangScanDeps/response-file-clang-cl.c

Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-options.c
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 18de8781e894a..15cf58f9d3339 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1030,7 +1030,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const 
JobAction &JA,
 
   // If user provided -o, that is the dependency target, except
   // when we are only generating a dependency file.
-  Arg *OutputOpt = Args.getLastArg(options::OPT_o);
+  Arg *OutputOpt = Args.getLastArg(options::OPT_o, options::OPT__SLASH_Fo);
   if (OutputOpt && Output.getType() != types::TY_Dependencies) {
 DepTarget = OutputOpt->getValue();
   } else {

diff  --git a/clang/test/ClangScanDeps/response-file-clang-cl.c 
b/clang/test/ClangScanDeps/response-file-clang-cl.c
new file mode 100644
index 0..b543231f4bb1b
--- /dev/null
+++ b/clang/test/ClangScanDeps/response-file-clang-cl.c
@@ -0,0 +1,56 @@
+// Check that the scanner can adjust arguments by reading .rsp files in 
advance.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// First run the tests with a .cdb
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: sed -e "s|DIR|%/t|g" %t/args_nested.template > %t/args_nested.rsp
+
+// RUN: cp %t/args_compilation.rsp %t/args.rsp
+// RUN: clang-scan-deps --compilation-database %t/cdb.json > %t/deps.json
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s
+
+// RUN: cp %t/args_preprocess.rsp %t/args.rsp
+// RUN: clang-scan-deps --compilation-database %t/cdb.json > %t/deps.json
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s
+
+
+// Now run the tests again with a in-place compilation database
+// RUN: cd %t
+
+// RUN: cp args_compilation.rsp args.rsp
+// RUN: clang-scan-deps -o deps.json -- %clang_cl @args.rsp
+// RUN: cat deps.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s
+
+// RUN: cp args_preprocess.rsp args.rsp
+// RUN: clang-scan-deps -o deps.json -- %clang_cl @args.rsp
+// RUN: cat deps.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s
+
+// Here we ensure that we got a qualified .obj with its full path, since 
that's what we're passing with /Fo
+// CHECK: [[PREFIX]]/tu.obj:
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.cpp",
+  "directory": "DIR",
+  "command": "clang-cl @DIR/args.rsp"
+}]
+
+//--- args_compilation.rsp
+@args_nested.rsp
+/c
+
+//--- args_preprocess.rsp
+@args_nested.rsp
+/E
+
+//--- args_nested.template
+/I include
+tu.cpp
+/FoDIR/tu.obj
+
+//--- include/header.h
+
+//--- tu.cpp
+#include "header.h"

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 75f49deca0653..733f243d3c69b 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -740,9 +740,10 @@
 // NOCLANG-SAME: "-vectorize-slp"
 // NOCLANG-NOT: "--dependent-lib=msvcrt"
 
-// RUN: %clang_cl -O2 -MD /clang:-fno-slp-vectorize /clang:-MD /clang:-MF 
/clang:my_dependency_file.dep -### -- %s 2>&1 | FileCheck -check-prefix=CLANG %s
+// RUN: %clang_cl -O2 -MD /clang:-fno-slp-vectorize /clang:-MD /clang:-MF 
/clang:my_dependency_file.dep /c /Fo%/t/cl-options.obj -### -- %s 2>&1 | 
FileCheck -DPREFIX=%/t -check-prefix=CLANG %s
 // CLANG: "--dependent-lib=msvcrt"
 // CLANG-SAME: "-dependency-file" "my_dependency_file.dep"
+// CLANG-SAME: "-MT" "[[PREFIX]]/cl-options.obj"
 // CLANG-NOT: "--dependent-lib=libcmt"
 // CLANG-NOT: "-vectorize-slp"
 

diff  --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index f42af7e330e17..036e57c8d213b 100644
--- a/clang/tools/

[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

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

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

>From 16ec4c725d86020831541a64bada8f4629a0972c Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Fri, 24 May 2024 19:15:54 +0300
Subject: [PATCH 01/17] [clang][ci] Move libc++ testing into the main PR
 pipeline

---
 .ci/generate-buildkite-pipeline-premerge | 31 ++-
 .ci/monolithic-linux.sh  | 65 
 2 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/.ci/generate-buildkite-pipeline-premerge 
b/.ci/generate-buildkite-pipeline-premerge
index e1c66ac18e7ac..d563fa6a01120 100755
--- a/.ci/generate-buildkite-pipeline-premerge
+++ b/.ci/generate-buildkite-pipeline-premerge
@@ -85,6 +85,22 @@ function compute-projects-to-test() {
   done
 }
 
+function compute-runtimes-to-test() {
+  projects=${@}
+  for project in ${projects}; do
+echo "${project}"
+case ${project} in
+clang)
+  for p in libcxx libcxxabi libunwind; do
+echo $p
+  done
+*)
+  # Nothing to do
+;;
+esac
+  done
+}
+
 function add-dependencies() {
   projects=${@}
   for project in ${projects}; do
@@ -178,6 +194,15 @@ function check-targets() {
 cross-project-tests)
   echo "check-cross-project"
 ;;
+libcxx)
+  echo "check-cxx"
+;;
+libcxxabi)
+  echo "check-cxxabi"
+;;
+libunwind)
+  echo "check-unwind"
+;;
 lldb)
   echo "check-all" # TODO: check-lldb may not include all the LLDB tests?
 ;;
@@ -231,6 +256,10 @@ linux_projects_to_test=$(exclude-linux 
$(compute-projects-to-test ${modified_pro
 linux_check_targets=$(check-targets ${linux_projects_to_test} | sort | uniq)
 linux_projects=$(add-dependencies ${linux_projects_to_test} | sort | uniq)
 
+linux_runtimes_to_test=$(compute-runtimes-to-test ${linux_projects_to_test})
+linux_runtime_check_targets=$(check-targets ${linux_runtimes_to_test} | sort | 
uniq)
+linux_runtimes=$(${linux_runtimes_to_test} | sort | uniq)
+
 windows_projects_to_test=$(exclude-windows $(compute-projects-to-test 
${modified_projects}))
 windows_check_targets=$(check-targets ${windows_projects_to_test} | sort | 
uniq)
 windows_projects=$(add-dependencies ${windows_projects_to_test} | sort | uniq)
@@ -255,7 +284,7 @@ if [[ "${linux_projects}" != "" ]]; then
 CC: 'clang'
 CXX: 'clang++'
   commands:
-  - './.ci/monolithic-linux.sh "$(echo ${linux_projects} | tr ' ' ';')" 
"$(echo ${linux_check_targets})"'
+  - './.ci/monolithic-linux.sh "$(echo ${linux_projects} | tr ' ' ';')" 
"$(echo ${linux_check_targets})" "$(echo ${linux_runtimes} | tr ' ' ';')" 
"$(echo ${linux_runtime_check_targets})"'
 EOF
 fi
 
diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index b00a4b984a1d2..bbd90f7d496b1 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -54,3 +54,68 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
 echo "--- ninja"
 # Targets are not escaped as they are passed as separate arguments.
 ninja -C "${BUILD_DIR}" -k 0 ${targets}
+
+runtimes="${3}"
+runtime_targets="${4}"
+
+# Compiling runtimes with just-built Clang and running their tests
+# as an additional testing for Clang.
+if [[ "${runtimes}" != "" ]]; then
+  if [[ "${runtime_targets}" == "" ]]; then
+echo "Runtimes to build are specified, but targets are not."
+  fi
+
+  RUNTIMES_BUILD_DIR="${MONOREPO_ROOT}/build-runtimes"
+  INSTALL_DIR="${RUNTIMES_BUILD_DIR}/install"
+  mkdir -p ${RUNTIMES_BUILD_DIR}
+
+  echo "--- cmake runtimes C++03"
+
+  cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
+  -DCMAKE_C_COMPILER="${BUILD_DIR}/bin/clang" \
+  -DCMAKE_CXX_COMPILER="${BUILD_DIR}/bin/clang++" \
+  -DLLVM_ENABLE_RUNTIMES="${runtimes}" \
+  -DLIBCXX_CXX_ABI=libcxxabi \
+  -DCMAKE_BUILD_TYPE=RelWithDebInfo \
+  -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
+  -DLIBCXX_TEST_PARAMS="std=c++03" \
+  -DLIBCXXABI_TEST_PARAMS="std=c++03"
+
+  echo "--- ninja runtimes C++03"
+
+  ninja -vC "${RUNTIMES_BUILD_DIR}" ${runtime_targets}
+
+  echo "--- cmake runtimes C++26"
+
+  rm -rf "${RUNTIMES_BUILD_DIR}"
+  cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
+  -DCMAKE_C_COMPILER="${BUILD_DIR}/bin/clang" \
+  -DCMAKE_CXX_COMPILER="${BUILD_DIR}/bin/clang++" \
+  -DLLVM_ENABLE_RUNTIMES="${runtimes}" \
+  -DLIBCXX_CXX_ABI=libcxxabi \
+  -DCMAKE_BUILD_TYPE=RelWithDebInfo \
+  -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
+  -DLIBCXX_TEST_PARAMS="std=c++26" \
+  -DLIBCXXABI_TEST_PARAMS="std=c++26"
+
+  echo "--- ninja runtimes C++26"
+
+  ninja -vC "${RUNTIMES_BUILD_DIR}" ${runtime_targets}
+
+  echo "--- cmake runtimes clang modules"
+
+  rm -rf "${RUNTIMES_BUILD_DIR}"
+  cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
+  -DCMAKE_C_COMPILER="${BUILD_DIR}/bin/clang" \
+  -DCMAKE_CXX_COMPILER="${BUILD_DIR}/bin/clang++" \
+  -DLLVM_ENABLE_RUNTIMES="${runtim

[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

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


@@ -54,3 +54,68 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
 echo "--- ninja"
 # Targets are not escaped as they are passed as separate arguments.
 ninja -C "${BUILD_DIR}" -k 0 ${targets}
+

Endilll wrote:

> 1. It's not parallelized anymore

Performance that we get from parallelization only helps when there's low amount 
of PRs to test to begin with (so we have idle agents). This is not the case we 
need to focus on at the moment

> 2. If one job fails, you don't get signal from whether the other jobs would 
> fail too

Sure, but I consider it minor. Nothing stop us from iterating on this later.

> 3. The reporting on Github is going to be confusing because everything will 
> be under the same job

Entirety of the reporting for Clang PRs has been single 
`buildkite/github-pull-requests` entry, and even with the very recent change 
that enabled per-job reporting, libc++ jobs haven't been reported. So this 
patch doesn't regress anything for Clang contributors. We still have the 
primary piece of information whether the CI passed or not. Again, we can 
iterate on this later.

> 4. This doesn't scale if we want to add more testing to be done against the 
> just-built Clang

Additional Clang testing has scaling problems either way, because as I 
mentioned earlier, splitting jobs only helps when there are free agents to 
begin with.

> Instead, I would suggest changing generate-buildkite-pipeline so that it adds 
> additional steps to the pipeline when we're testing Clang. These steps can 
> communicate via artifacts uploading/downloading like they used to.

If you're willing to do the work in a reasonable time (remember we're reducing 
CI pressure here), you can take over this PR or I can abandon it. I personally 
had enough of bash scripting to iterate on this immediately.

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


[clang] [clang-tools-extra] [llvm] [BOLT][NFC] Added double escape characters (PR #93348)

2024-05-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Sayhaan Siddiqui (sayhaan)


Changes

Added double escape characters to lines that describe a test.

>From [T187348734](https://www.internalfb.com/intern/tasks/?t=187348734)

---

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


222 Files Affected:

- (modified) bolt/lib/Passes/ReorderFunctions.cpp (+139-156) 
- (modified) bolt/test/X86/addr32.s (+1-1) 
- (modified) bolt/test/X86/asm-dump.c (+1-1) 
- (modified) bolt/test/X86/asm-func-debug.test (+7-7) 
- (modified) bolt/test/X86/avx512-trap.test (+5-5) 
- (modified) bolt/test/X86/bb-with-two-tail-calls.s (+2-2) 
- (modified) bolt/test/X86/block-reordering.test (+2-3) 
- (modified) bolt/test/X86/bolt-address-translation-internal-call.test (+5-5) 
- (modified) bolt/test/X86/bolt-address-translation.test (+6-6) 
- (modified) bolt/test/X86/branch-data.test (+3-3) 
- (modified) bolt/test/X86/broken_dynsym.test (+3-3) 
- (modified) bolt/test/X86/bug-reorder-bb-jrcxz.s (+8-8) 
- (modified) bolt/test/X86/call-zero.s (+1-1) 
- (modified) bolt/test/X86/cfi-expr-rewrite.s (+2-2) 
- (modified) bolt/test/X86/cfi-instrs-count.s (+11-11) 
- (modified) bolt/test/X86/cfi-instrs-reordered.s (+2-2) 
- (modified) bolt/test/X86/ctc-and-unreachable.test (+2-2) 
- (modified) bolt/test/X86/debug-fission-single.s (+1-1) 
- (modified) bolt/test/X86/double-jump.test (+1-1) 
- (modified) bolt/test/X86/dwarf-handle-visit-loclist-error.s (+1-1) 
- (modified) bolt/test/X86/dwarf-test-df-logging.test (+1-1) 
- (modified) bolt/test/X86/dwarf3-lowpc-highpc-convert.s (+1-1) 
- (modified) bolt/test/X86/dwarf4-df-dualcu-loclist.test (+1-1) 
- (modified) bolt/test/X86/dwarf4-df-dualcu.test (+2-2) 
- (modified) bolt/test/X86/dwarf4-ftypes-dwo-input-dwp-output.test (+2-2) 
- (modified) bolt/test/X86/dwarf4-ftypes-dwp-input-dwo-output.test (+2-2) 
- (modified) bolt/test/X86/dwarf4-ftypes-dwp-input-dwp-output.test (+2-2) 
- (modified) bolt/test/X86/dwarf4-size-0-inlined_subroutine.s (+2-2) 
- (modified) bolt/test/X86/dwarf4-split-dwarf-no-address.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-addr-section-reuse.s (+2-2) 
- (modified) bolt/test/X86/dwarf5-call-pc-function-null-check.test (+2-2) 
- (modified) bolt/test/X86/dwarf5-call-pc.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-cu-no-debug-addr.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-debug-info-dwarf4-debug-line.s (+1-1) 
- (modified) bolt/test/X86/dwarf5-debug-line.s (+1-1) 
- (modified) bolt/test/X86/dwarf5-debug-loclists.s (+1-1) 
- (modified) bolt/test/X86/dwarf5-df-dualcu-loclist.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-df-dualcu.test (+2-2) 
- (modified) bolt/test/X86/dwarf5-df-mono-dualcu.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-dwarf4-monolithic.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-ftypes-dwp-input-dwo-output.test (+2-2) 
- (modified) bolt/test/X86/dwarf5-label-low-pc.s (+1-1) 
- (modified) bolt/test/X86/dwarf5-locaddrx.test (+2-2) 
- (modified) bolt/test/X86/dwarf5-locexpr-addrx.s (+2-2) 
- (modified) bolt/test/X86/dwarf5-loclist-offset-form.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-lowpc-highpc-convert.s (+2-2) 
- (modified) bolt/test/X86/dwarf5-multiple-dw-op-addrx-locexpr.s (+1-1) 
- (modified) bolt/test/X86/dwarf5-rangeoffset-to-rangeindex.s (+1-1) 
- (modified) bolt/test/X86/dwarf5-return-pc-form-addr.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-return-pc.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-shared-str-offset-base.s (+2-2) 
- (modified) bolt/test/X86/dwarf5-split-dwarf4-monolithic.test (+3-3) 
- (modified) bolt/test/X86/dwarf5-two-loclists.test (+2-2) 
- (modified) bolt/test/X86/dwarf5-two-rnglists.test (+2-2) 
- (modified) bolt/test/X86/dynrelocs.s (+23-23) 
- (modified) bolt/test/X86/exceptions-args.test (+2-2) 
- (modified) bolt/test/X86/fallthrough-to-noop.test (+7-7) 
- (modified) bolt/test/X86/false-jump-table.s (+2-2) 
- (modified) bolt/test/X86/fragment-lite-reverse.s (+1-1) 
- (modified) bolt/test/X86/fragment-lite.s (+1-1) 
- (modified) bolt/test/X86/fragmented-symbols.s (+2-2) 
- (modified) bolt/test/X86/frame-opt-lea.s (+3-3) 
- (modified) bolt/test/X86/function-order-lite.s (+2-2) 
- (modified) bolt/test/X86/high_pc_udata.s (+2-2) 
- (modified) bolt/test/X86/icp-inline.s (+2-2) 
- (modified) bolt/test/X86/indirect-goto.test (+2-2) 
- (modified) bolt/test/X86/inlined-function-mixed.test (+2-2) 
- (modified) bolt/test/X86/insert-addr-rnglists_base.s (+2-2) 
- (modified) bolt/test/X86/insert-debug-info-entry.test (+1-1) 
- (modified) bolt/test/X86/internal-call-instrument-so.s (+1-1) 
- (modified) bolt/test/X86/internal-call-instrument.s (+1-1) 
- (modified) bolt/test/X86/interprocedural-ref-entry-point.s (+2-2) 
- (modified) bolt/test/X86/is-strip.s (+1-1) 
- (modified) bolt/test/X86/issue20.s (+3-3) 
- (modified) bolt/test/X86/issue20.test (+3-3) 
- (modified) bolt/test/X86/issue26.s (+3-3) 
- (modified) bolt/test/X86/issue26.test (+1-

[clang] [clang-tools-extra] [llvm] [BOLT][NFC] Added double escape characters (PR #93348)

2024-05-24 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang-modules

Author: Sayhaan Siddiqui (sayhaan)


Changes

Added double escape characters to lines that describe a test.

>From [T187348734](https://www.internalfb.com/intern/tasks/?t=187348734)

---

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


222 Files Affected:

- (modified) bolt/lib/Passes/ReorderFunctions.cpp (+139-156) 
- (modified) bolt/test/X86/addr32.s (+1-1) 
- (modified) bolt/test/X86/asm-dump.c (+1-1) 
- (modified) bolt/test/X86/asm-func-debug.test (+7-7) 
- (modified) bolt/test/X86/avx512-trap.test (+5-5) 
- (modified) bolt/test/X86/bb-with-two-tail-calls.s (+2-2) 
- (modified) bolt/test/X86/block-reordering.test (+2-3) 
- (modified) bolt/test/X86/bolt-address-translation-internal-call.test (+5-5) 
- (modified) bolt/test/X86/bolt-address-translation.test (+6-6) 
- (modified) bolt/test/X86/branch-data.test (+3-3) 
- (modified) bolt/test/X86/broken_dynsym.test (+3-3) 
- (modified) bolt/test/X86/bug-reorder-bb-jrcxz.s (+8-8) 
- (modified) bolt/test/X86/call-zero.s (+1-1) 
- (modified) bolt/test/X86/cfi-expr-rewrite.s (+2-2) 
- (modified) bolt/test/X86/cfi-instrs-count.s (+11-11) 
- (modified) bolt/test/X86/cfi-instrs-reordered.s (+2-2) 
- (modified) bolt/test/X86/ctc-and-unreachable.test (+2-2) 
- (modified) bolt/test/X86/debug-fission-single.s (+1-1) 
- (modified) bolt/test/X86/double-jump.test (+1-1) 
- (modified) bolt/test/X86/dwarf-handle-visit-loclist-error.s (+1-1) 
- (modified) bolt/test/X86/dwarf-test-df-logging.test (+1-1) 
- (modified) bolt/test/X86/dwarf3-lowpc-highpc-convert.s (+1-1) 
- (modified) bolt/test/X86/dwarf4-df-dualcu-loclist.test (+1-1) 
- (modified) bolt/test/X86/dwarf4-df-dualcu.test (+2-2) 
- (modified) bolt/test/X86/dwarf4-ftypes-dwo-input-dwp-output.test (+2-2) 
- (modified) bolt/test/X86/dwarf4-ftypes-dwp-input-dwo-output.test (+2-2) 
- (modified) bolt/test/X86/dwarf4-ftypes-dwp-input-dwp-output.test (+2-2) 
- (modified) bolt/test/X86/dwarf4-size-0-inlined_subroutine.s (+2-2) 
- (modified) bolt/test/X86/dwarf4-split-dwarf-no-address.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-addr-section-reuse.s (+2-2) 
- (modified) bolt/test/X86/dwarf5-call-pc-function-null-check.test (+2-2) 
- (modified) bolt/test/X86/dwarf5-call-pc.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-cu-no-debug-addr.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-debug-info-dwarf4-debug-line.s (+1-1) 
- (modified) bolt/test/X86/dwarf5-debug-line.s (+1-1) 
- (modified) bolt/test/X86/dwarf5-debug-loclists.s (+1-1) 
- (modified) bolt/test/X86/dwarf5-df-dualcu-loclist.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-df-dualcu.test (+2-2) 
- (modified) bolt/test/X86/dwarf5-df-mono-dualcu.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-dwarf4-monolithic.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-ftypes-dwp-input-dwo-output.test (+2-2) 
- (modified) bolt/test/X86/dwarf5-label-low-pc.s (+1-1) 
- (modified) bolt/test/X86/dwarf5-locaddrx.test (+2-2) 
- (modified) bolt/test/X86/dwarf5-locexpr-addrx.s (+2-2) 
- (modified) bolt/test/X86/dwarf5-loclist-offset-form.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-lowpc-highpc-convert.s (+2-2) 
- (modified) bolt/test/X86/dwarf5-multiple-dw-op-addrx-locexpr.s (+1-1) 
- (modified) bolt/test/X86/dwarf5-rangeoffset-to-rangeindex.s (+1-1) 
- (modified) bolt/test/X86/dwarf5-return-pc-form-addr.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-return-pc.test (+1-1) 
- (modified) bolt/test/X86/dwarf5-shared-str-offset-base.s (+2-2) 
- (modified) bolt/test/X86/dwarf5-split-dwarf4-monolithic.test (+3-3) 
- (modified) bolt/test/X86/dwarf5-two-loclists.test (+2-2) 
- (modified) bolt/test/X86/dwarf5-two-rnglists.test (+2-2) 
- (modified) bolt/test/X86/dynrelocs.s (+23-23) 
- (modified) bolt/test/X86/exceptions-args.test (+2-2) 
- (modified) bolt/test/X86/fallthrough-to-noop.test (+7-7) 
- (modified) bolt/test/X86/false-jump-table.s (+2-2) 
- (modified) bolt/test/X86/fragment-lite-reverse.s (+1-1) 
- (modified) bolt/test/X86/fragment-lite.s (+1-1) 
- (modified) bolt/test/X86/fragmented-symbols.s (+2-2) 
- (modified) bolt/test/X86/frame-opt-lea.s (+3-3) 
- (modified) bolt/test/X86/function-order-lite.s (+2-2) 
- (modified) bolt/test/X86/high_pc_udata.s (+2-2) 
- (modified) bolt/test/X86/icp-inline.s (+2-2) 
- (modified) bolt/test/X86/indirect-goto.test (+2-2) 
- (modified) bolt/test/X86/inlined-function-mixed.test (+2-2) 
- (modified) bolt/test/X86/insert-addr-rnglists_base.s (+2-2) 
- (modified) bolt/test/X86/insert-debug-info-entry.test (+1-1) 
- (modified) bolt/test/X86/internal-call-instrument-so.s (+1-1) 
- (modified) bolt/test/X86/internal-call-instrument.s (+1-1) 
- (modified) bolt/test/X86/interprocedural-ref-entry-point.s (+2-2) 
- (modified) bolt/test/X86/is-strip.s (+1-1) 
- (modified) bolt/test/X86/issue20.s (+3-3) 
- (modified) bolt/test/X86/issue20.test (+3-3) 
- (modified) bolt/test/X86/issue26.s (+3-3) 
- (modified) b

[clang] [Bounds-Safety] Add sized_by, counted_by_or_null & sized_by_or_null (PR #93231)

2024-05-24 Thread Henrik G. Olsson via cfe-commits


@@ -8641,22 +8641,33 @@ enum class CountedByInvalidPointeeTypeKind {
   VALID,
 };
 
-static bool CheckCountedByAttrOnField(
-Sema &S, FieldDecl *FD, Expr *E,
-llvm::SmallVectorImpl &Decls) {
+static bool
+CheckCountedByAttrOnField(Sema &S, FieldDecl *FD, Expr *E,
+  llvm::SmallVectorImpl &Decls,
+  bool CountInBytes, bool OrNull) {
   // Check the context the attribute is used in
 
+  unsigned Kind = CountInBytes;
+  if (OrNull)
+Kind += 2;
+
   if (FD->getParent()->isUnion()) {
 S.Diag(FD->getBeginLoc(), diag::err_counted_by_attr_in_union)
-<< FD->getSourceRange();
+<< Kind << FD->getSourceRange();
 return true;
   }
 
   const auto FieldTy = FD->getType();
+  if (FieldTy->isArrayType() && (CountInBytes || OrNull)) {
+S.Diag(FD->getBeginLoc(),
+   diag::err_counted_by_attr_not_on_ptr_or_flexible_array_member)

hnrklssn wrote:

>The diagnostic name is a little misleading here because CountInBytes suggested 
>__sized_by but the diagnostic name has counted_by in its name

I kept it because it's the same family of attributes. Do you have a suggestion 
for a name that would imply that it's not just for `counted_by`, but more 
specific than `bounds_attribute`?

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


[clang] [HLSL] Default and Relaxed Availability Diagnostics (PR #92704)

2024-05-24 Thread Helena Kotas via cfe-commits


@@ -0,0 +1,108 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library \
+// RUN: -fsyntax-only -Wno-error=hlsl-availability -verify %s
+
+__attribute__((availability(shadermodel, introduced = 6.5)))
+float fx(float);  // #fx
+
+__attribute__((availability(shadermodel, introduced = 5.0, environment = 
pixel)))
+__attribute__((availability(shadermodel, introduced = 6.5, environment = 
compute)))
+float fy(float); // #fy
+
+__attribute__((availability(shadermodel, introduced = 5.0, environment = 
pixel)))
+__attribute__((availability(shadermodel, introduced = 6.5, environment = 
mesh)))
+float fz(float); // #fz
+
+float also_alive(float f) {
+  // expected-warning@#also_alive_fx_call {{'fx' is only available on Shader 
Model 6.5 or newer}}
+  // expected-note@#fx {{'fx' has been marked as being introduced in Shader 
Model 6.5 here, but the deployment target is Shader Model 6.0}}
+  float A = fx(f); // #also_alive_fx_call
+  
+  // expected-warning@#also_alive_fy_call {{'fy' is only available in compute 
shader environment on Shader Model 6.5 or newer}}
+  // expected-note@#fy {{'fy' has been marked as being introduced in Shader 
Model 6.5 in compute shader environment here, but the deployment target is 
Shader Model 6.0 compute shader environment}}
+  float B = fy(f); // #also_alive_fy_call
+
+  // expected-warning@#also_alive_fz_call {{'fz' is unavailable}}
+  // expected-note@#fz {{'fz' has been marked as being introduced in Shader 
Model 6.5 in mesh shader environment here, but the deployment target is Shader 
Model 6.0 compute shader environment}}
+  float C = fz(f); // #also_alive_fz_call
+
+  return 0;
+}
+
+float alive(float f) {
+  // expected-warning@#alive_fx_call {{'fx' is only available on Shader Model 
6.5 or newer}}
+  // expected-note@#fx {{'fx' has been marked as being introduced in Shader 
Model 6.5 here, but the deployment target is Shader Model 6.0}}
+  float A = fx(f); // #alive_fx_call
+
+  // expected-warning@#alive_fy_call {{'fy' is only available in compute 
shader environment on Shader Model 6.5 or newer}}
+  // expected-note@#fy {{'fy' has been marked as being introduced in Shader 
Model 6.5 in compute shader environment here, but the deployment target is 
Shader Model 6.0 compute shader environment}}
+  float B = fy(f); // #alive_fy_call
+
+  // expected-warning@#alive_fz_call {{'fz' is unavailable}}
+  // expected-note@#fz {{'fz' has been marked as being introduced in Shader 
Model 6.5 in mesh shader environment here, but the deployment target is Shader 
Model 6.0 compute shader environment}}
+  float C = fz(f); // #alive_fz_call
+
+  return also_alive(f);
+}
+
+float also_dead(float f) {
+  // unreachable code - no errors expected
+  float A = fx(f);
+  float B = fy(f);
+  float C = fz(f);
+  return 0;
+}
+
+float dead(float f) {
+  // unreachable code - no errors expected
+  float A = fx(f);
+  float B = fy(f);
+  float C = fz(f);
+  return also_dead(f);
+}
+
+template
+T aliveTemp(T f) {
+  // expected-warning@#aliveTemp_fx_call {{'fx' is only available on Shader 
Model 6.5 or newer}}
+  // expected-note@#fx {{'fx' has been marked as being introduced in Shader 
Model 6.5 here, but the deployment target is Shader Model 6.0}}
+  float A = fx(f); // #aliveTemp_fx_call
+  // expected-warning@#aliveTemp_fy_call {{'fy' is only available in compute 
shader environment on Shader Model 6.5 or newer}}
+  // expected-note@#fy {{'fy' has been marked as being introduced in Shader 
Model 6.5 in compute shader environment here, but the deployment target is 
Shader Model 6.0 compute shader environment}}
+  float B = fy(f); // #aliveTemp_fy_call
+  // expected-warning@#aliveTemp_fz_call {{'fz' is unavailable}}
+  // expected-note@#fz {{'fz' has been marked as being introduced in Shader 
Model 6.5 in mesh shader environment here, but the deployment target is Shader 
Model 6.0 compute shader environment}}
+  float C = fz(f); // #aliveTemp_fz_call
+  return 0;
+}
+
+class MyClass
+{
+  float F;
+  float makeF() {
+// expected-warning@#MyClass_makeF_fx_call {{'fx' is only available on 
Shader Model 6.5 or newer}}
+// expected-note@#fx {{'fx' has been marked as being introduced in Shader 
Model 6.5 here, but the deployment target is Shader Model 6.0}}
+float A = fx(F); // #MyClass_makeF_fx_call
+// expected-warning@#MyClass_makeF_fy_call {{'fy' is only available in 
compute shader environment on Shader Model 6.5 or newer}}
+// expected-note@#fy {{'fy' has been marked as being introduced in Shader 
Model 6.5 in compute shader environment here, but the deployment target is 
Shader Model 6.0 compute shader environment}}
+float B = fy(F); // #MyClass_makeF_fy_call
+// expected-warning@#MyClass_makeF_fz_call {{'fz' is unavailable}}
+// expected-note@#fz {{'fz' has been marked as being introduced in Shader 
Model 6.5 in mesh shader environment here, but the deployment target is Shader 
Model 6.0 compute shader environment}}
+float C = fz(F); // #

[clang] [Bounds-Safety] Add sized_by, counted_by_or_null & sized_by_or_null (PR #93231)

2024-05-24 Thread Henrik G. Olsson via cfe-commits


@@ -8641,22 +8641,33 @@ enum class CountedByInvalidPointeeTypeKind {
   VALID,
 };
 
-static bool CheckCountedByAttrOnField(
-Sema &S, FieldDecl *FD, Expr *E,
-llvm::SmallVectorImpl &Decls) {
+static bool
+CheckCountedByAttrOnField(Sema &S, FieldDecl *FD, Expr *E,
+  llvm::SmallVectorImpl &Decls,
+  bool CountInBytes, bool OrNull) {
   // Check the context the attribute is used in
 
+  unsigned Kind = CountInBytes;
+  if (OrNull)
+Kind += 2;
+
   if (FD->getParent()->isUnion()) {
 S.Diag(FD->getBeginLoc(), diag::err_counted_by_attr_in_union)
-<< FD->getSourceRange();
+<< Kind << FD->getSourceRange();
 return true;
   }
 
   const auto FieldTy = FD->getType();
+  if (FieldTy->isArrayType() && (CountInBytes || OrNull)) {
+S.Diag(FD->getBeginLoc(),
+   diag::err_counted_by_attr_not_on_ptr_or_flexible_array_member)

hnrklssn wrote:

> The OrNull case probably deserves its own special diagnostic because in that 
> case the diagnostic should explain that they cannot use the attribute on 
> arrays and that they need to use __counted_by instead.

That is also true for `CountInBytes`. But I agree that it would be good for the 
diagnostic to suggest `counted_by`.

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


[clang] [Bounds-Safety] Add sized_by, counted_by_or_null & sized_by_or_null (PR #93231)

2024-05-24 Thread Henrik G. Olsson via cfe-commits


@@ -425,6 +425,12 @@ Attribute Changes in Clang
size_t count;
  };
 
+- The attributes ``sized_by``, ``counted_by_or_null`` and ``sized_by_or_null```
+  have been added as variants on ``counted_by``, each with slightly different 
semantics.
+  ``sized_by`` takes a byte size parameter instead of an element count, 
allowing pointees
+  with unknown size. The ``counted_by_or_null`` and ``sized_by_or_null`` 
variants are equivalent
+  to their base variants, except the pointer can be null regardless of 
count/size value.

hnrklssn wrote:

Hmm yeah there's nothing preventing you from assigning null I guess, but I 
don't believe `__bdos` CG has any support for returning 0 when the pointer is 
null.

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


[clang] [Bounds-Safety] Add sized_by, counted_by_or_null & sized_by_or_null (PR #93231)

2024-05-24 Thread Henrik G. Olsson via cfe-commits


@@ -8697,9 +8708,10 @@ static bool CheckCountedByAttrOnField(
 InvalidTypeKind = CountedByInvalidPointeeTypeKind::FLEXIBLE_ARRAY_MEMBER;
   }
 
-  if (InvalidTypeKind != CountedByInvalidPointeeTypeKind::VALID) {
+  if (InvalidTypeKind != CountedByInvalidPointeeTypeKind::VALID &&
+  !CountInBytes) {

hnrklssn wrote:

I think that is a reasonable restriction to add in `-fbounds-safety`, but for 
simply saying "this is the size", is it really an issue? It's also feasible to 
allow the attribute, but not allow indexing into an unsized type. That would 
make it possible to cast to `char * sized_by(sz)` and retain the size bounds 
before indexing into it.

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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

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


@@ -54,3 +54,68 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
 echo "--- ninja"
 # Targets are not escaped as they are passed as separate arguments.
 ninja -C "${BUILD_DIR}" -k 0 ${targets}
+
+runtimes="${3}"
+runtime_targets="${4}"
+
+# Compiling runtimes with just-built Clang and running their tests
+# as an additional testing for Clang.
+if [[ "${runtimes}" != "" ]]; then
+  if [[ "${runtime_targets}" == "" ]]; then
+echo "Runtimes to build are specified, but targets are not."
+  fi
+
+  RUNTIMES_BUILD_DIR="${MONOREPO_ROOT}/build-runtimes"
+  INSTALL_DIR="${RUNTIMES_BUILD_DIR}/install"
+  mkdir -p ${RUNTIMES_BUILD_DIR}
+
+  echo "--- cmake runtimes C++03"
+
+  cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
+  -DCMAKE_C_COMPILER="${BUILD_DIR}/bin/clang" \
+  -DCMAKE_CXX_COMPILER="${BUILD_DIR}/bin/clang++" \
+  -DLLVM_ENABLE_RUNTIMES="${runtimes}" \
+  -DLIBCXX_CXX_ABI=libcxxabi \
+  -DCMAKE_BUILD_TYPE=RelWithDebInfo \
+  -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
+  -DLIBCXX_TEST_PARAMS="std=c++03" \
+  -DLIBCXXABI_TEST_PARAMS="std=c++03"

Endilll wrote:

Fixed.

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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

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


@@ -54,3 +54,68 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
 echo "--- ninja"
 # Targets are not escaped as they are passed as separate arguments.
 ninja -C "${BUILD_DIR}" -k 0 ${targets}
+
+runtimes="${3}"
+runtime_targets="${4}"
+
+# Compiling runtimes with just-built Clang and running their tests
+# as an additional testing for Clang.
+if [[ "${runtimes}" != "" ]]; then
+  if [[ "${runtime_targets}" == "" ]]; then
+echo "Runtimes to build are specified, but targets are not."
+  fi
+
+  RUNTIMES_BUILD_DIR="${MONOREPO_ROOT}/build-runtimes"
+  INSTALL_DIR="${RUNTIMES_BUILD_DIR}/install"
+  mkdir -p ${RUNTIMES_BUILD_DIR}
+
+  echo "--- cmake runtimes C++03"
+
+  cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
+  -DCMAKE_C_COMPILER="${BUILD_DIR}/bin/clang" \
+  -DCMAKE_CXX_COMPILER="${BUILD_DIR}/bin/clang++" \

Endilll wrote:

Thank you! This should be fixed now.

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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

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

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

>From 16ec4c725d86020831541a64bada8f4629a0972c Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Fri, 24 May 2024 19:15:54 +0300
Subject: [PATCH 01/16] [clang][ci] Move libc++ testing into the main PR
 pipeline

---
 .ci/generate-buildkite-pipeline-premerge | 31 ++-
 .ci/monolithic-linux.sh  | 65 
 2 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/.ci/generate-buildkite-pipeline-premerge 
b/.ci/generate-buildkite-pipeline-premerge
index e1c66ac18e7ac..d563fa6a01120 100755
--- a/.ci/generate-buildkite-pipeline-premerge
+++ b/.ci/generate-buildkite-pipeline-premerge
@@ -85,6 +85,22 @@ function compute-projects-to-test() {
   done
 }
 
+function compute-runtimes-to-test() {
+  projects=${@}
+  for project in ${projects}; do
+echo "${project}"
+case ${project} in
+clang)
+  for p in libcxx libcxxabi libunwind; do
+echo $p
+  done
+*)
+  # Nothing to do
+;;
+esac
+  done
+}
+
 function add-dependencies() {
   projects=${@}
   for project in ${projects}; do
@@ -178,6 +194,15 @@ function check-targets() {
 cross-project-tests)
   echo "check-cross-project"
 ;;
+libcxx)
+  echo "check-cxx"
+;;
+libcxxabi)
+  echo "check-cxxabi"
+;;
+libunwind)
+  echo "check-unwind"
+;;
 lldb)
   echo "check-all" # TODO: check-lldb may not include all the LLDB tests?
 ;;
@@ -231,6 +256,10 @@ linux_projects_to_test=$(exclude-linux 
$(compute-projects-to-test ${modified_pro
 linux_check_targets=$(check-targets ${linux_projects_to_test} | sort | uniq)
 linux_projects=$(add-dependencies ${linux_projects_to_test} | sort | uniq)
 
+linux_runtimes_to_test=$(compute-runtimes-to-test ${linux_projects_to_test})
+linux_runtime_check_targets=$(check-targets ${linux_runtimes_to_test} | sort | 
uniq)
+linux_runtimes=$(${linux_runtimes_to_test} | sort | uniq)
+
 windows_projects_to_test=$(exclude-windows $(compute-projects-to-test 
${modified_projects}))
 windows_check_targets=$(check-targets ${windows_projects_to_test} | sort | 
uniq)
 windows_projects=$(add-dependencies ${windows_projects_to_test} | sort | uniq)
@@ -255,7 +284,7 @@ if [[ "${linux_projects}" != "" ]]; then
 CC: 'clang'
 CXX: 'clang++'
   commands:
-  - './.ci/monolithic-linux.sh "$(echo ${linux_projects} | tr ' ' ';')" 
"$(echo ${linux_check_targets})"'
+  - './.ci/monolithic-linux.sh "$(echo ${linux_projects} | tr ' ' ';')" 
"$(echo ${linux_check_targets})" "$(echo ${linux_runtimes} | tr ' ' ';')" 
"$(echo ${linux_runtime_check_targets})"'
 EOF
 fi
 
diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index b00a4b984a1d2..bbd90f7d496b1 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -54,3 +54,68 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
 echo "--- ninja"
 # Targets are not escaped as they are passed as separate arguments.
 ninja -C "${BUILD_DIR}" -k 0 ${targets}
+
+runtimes="${3}"
+runtime_targets="${4}"
+
+# Compiling runtimes with just-built Clang and running their tests
+# as an additional testing for Clang.
+if [[ "${runtimes}" != "" ]]; then
+  if [[ "${runtime_targets}" == "" ]]; then
+echo "Runtimes to build are specified, but targets are not."
+  fi
+
+  RUNTIMES_BUILD_DIR="${MONOREPO_ROOT}/build-runtimes"
+  INSTALL_DIR="${RUNTIMES_BUILD_DIR}/install"
+  mkdir -p ${RUNTIMES_BUILD_DIR}
+
+  echo "--- cmake runtimes C++03"
+
+  cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
+  -DCMAKE_C_COMPILER="${BUILD_DIR}/bin/clang" \
+  -DCMAKE_CXX_COMPILER="${BUILD_DIR}/bin/clang++" \
+  -DLLVM_ENABLE_RUNTIMES="${runtimes}" \
+  -DLIBCXX_CXX_ABI=libcxxabi \
+  -DCMAKE_BUILD_TYPE=RelWithDebInfo \
+  -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
+  -DLIBCXX_TEST_PARAMS="std=c++03" \
+  -DLIBCXXABI_TEST_PARAMS="std=c++03"
+
+  echo "--- ninja runtimes C++03"
+
+  ninja -vC "${RUNTIMES_BUILD_DIR}" ${runtime_targets}
+
+  echo "--- cmake runtimes C++26"
+
+  rm -rf "${RUNTIMES_BUILD_DIR}"
+  cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
+  -DCMAKE_C_COMPILER="${BUILD_DIR}/bin/clang" \
+  -DCMAKE_CXX_COMPILER="${BUILD_DIR}/bin/clang++" \
+  -DLLVM_ENABLE_RUNTIMES="${runtimes}" \
+  -DLIBCXX_CXX_ABI=libcxxabi \
+  -DCMAKE_BUILD_TYPE=RelWithDebInfo \
+  -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
+  -DLIBCXX_TEST_PARAMS="std=c++26" \
+  -DLIBCXXABI_TEST_PARAMS="std=c++26"
+
+  echo "--- ninja runtimes C++26"
+
+  ninja -vC "${RUNTIMES_BUILD_DIR}" ${runtime_targets}
+
+  echo "--- cmake runtimes clang modules"
+
+  rm -rf "${RUNTIMES_BUILD_DIR}"
+  cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
+  -DCMAKE_C_COMPILER="${BUILD_DIR}/bin/clang" \
+  -DCMAKE_CXX_COMPILER="${BUILD_DIR}/bin/clang++" \
+  -DLLVM_ENABLE_RUNTIMES="${runtim

[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-05-24 Thread Louis Dionne via cfe-commits


@@ -54,3 +54,68 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
 echo "--- ninja"
 # Targets are not escaped as they are passed as separate arguments.
 ninja -C "${BUILD_DIR}" -k 0 ${targets}
+
+runtimes="${3}"
+runtime_targets="${4}"
+
+# Compiling runtimes with just-built Clang and running their tests
+# as an additional testing for Clang.
+if [[ "${runtimes}" != "" ]]; then
+  if [[ "${runtime_targets}" == "" ]]; then
+echo "Runtimes to build are specified, but targets are not."
+  fi
+
+  RUNTIMES_BUILD_DIR="${MONOREPO_ROOT}/build-runtimes"
+  INSTALL_DIR="${RUNTIMES_BUILD_DIR}/install"
+  mkdir -p ${RUNTIMES_BUILD_DIR}
+
+  echo "--- cmake runtimes C++03"
+
+  cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
+  -DCMAKE_C_COMPILER="${BUILD_DIR}/bin/clang" \
+  -DCMAKE_CXX_COMPILER="${BUILD_DIR}/bin/clang++" \

ldionne wrote:

We should install Clang in a directory above, and then use 
`/bin/clang++` here. That way stuff like the compiler-rt headers 
would be installed properly.

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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-05-24 Thread Louis Dionne via cfe-commits


@@ -54,3 +54,68 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
 echo "--- ninja"
 # Targets are not escaped as they are passed as separate arguments.
 ninja -C "${BUILD_DIR}" -k 0 ${targets}
+
+runtimes="${3}"
+runtime_targets="${4}"
+
+# Compiling runtimes with just-built Clang and running their tests
+# as an additional testing for Clang.
+if [[ "${runtimes}" != "" ]]; then
+  if [[ "${runtime_targets}" == "" ]]; then
+echo "Runtimes to build are specified, but targets are not."
+  fi
+
+  RUNTIMES_BUILD_DIR="${MONOREPO_ROOT}/build-runtimes"
+  INSTALL_DIR="${RUNTIMES_BUILD_DIR}/install"
+  mkdir -p ${RUNTIMES_BUILD_DIR}
+
+  echo "--- cmake runtimes C++03"
+
+  cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
+  -DCMAKE_C_COMPILER="${BUILD_DIR}/bin/clang" \
+  -DCMAKE_CXX_COMPILER="${BUILD_DIR}/bin/clang++" \
+  -DLLVM_ENABLE_RUNTIMES="${runtimes}" \
+  -DLIBCXX_CXX_ABI=libcxxabi \
+  -DCMAKE_BUILD_TYPE=RelWithDebInfo \
+  -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
+  -DLIBCXX_TEST_PARAMS="std=c++03" \
+  -DLIBCXXABI_TEST_PARAMS="std=c++03"

ldionne wrote:

```suggestion
  -D LIBCXX_CXX_ABI=libcxxabi \
  -D CMAKE_BUILD_TYPE=RelWithDebInfo \
  -D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
  -D LIBCXX_TEST_PARAMS="std=c++03" \
  -D LIBCXXABI_TEST_PARAMS="std=c++03"
```

etc.. for consistency with above.

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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-05-24 Thread Louis Dionne via cfe-commits

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


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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-05-24 Thread Louis Dionne via cfe-commits


@@ -54,3 +54,68 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
 echo "--- ninja"
 # Targets are not escaped as they are passed as separate arguments.
 ninja -C "${BUILD_DIR}" -k 0 ${targets}
+

ldionne wrote:

I don't think it makes sense to serialize all these different jobs and put them 
in the same script. Doing this has several downsides:
1. It's not parallelized anymore
2. If one job fails, you don't get signal from whether the other jobs would 
fail too
3. The reporting on Github is going to be confusing because everything will be 
under the same job
4. This doesn't scale if we want to add more testing to be done against the 
just-built Clang

Instead, I would suggest changing `generate-buildkite-pipeline` so that it adds 
additional steps to the pipeline when we're testing Clang. These steps can 
communicate via artifacts uploading/downloading like they used to.

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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-05-24 Thread Louis Dionne via cfe-commits

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


[clang] [clang] In Sema use new parentEvaluationContext function (PR #93338)

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

https://github.com/Endilll commented:

`Sema.h` changes look good.

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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-05-24 Thread Louis Dionne via cfe-commits

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


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

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


@@ -1030,6 +1036,12 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   Phase != ThinOrFullLTOPhase::ThinLTOPostLink)
 MPM.addPass(SampleProfileProbePass(TM));
 
+  // Instrument function entry and exit before all inlining.
+  if (!isLTOPostLink(Phase)) {
+MPM.addPass(createModuleToFunctionPassAdaptor(

aeubanks wrote:

actually is it possible to add this into `EarlyFPM` below? it's nice to have 
fewer module->function adaptors. (e.g. in `EarlyFPM` we run all the function 
passes on a single function before moving to the next one which is nice for 
memory locality)

sorry for suggesting this so late, since it'll require updating all the 
pipeline tests... but first check that none of the other tests fail

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


[clang] [clang] In Sema use new parentEvaluationContext function (PR #93338)

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

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


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

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


@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -debug-info-kind=standalone 
-emit-llvm -o - %s -finstrument-functions | FileCheck %s

aeubanks wrote:

this should also not be testing the pass and should have -disable-llvm-passes

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


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

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

https://github.com/aeubanks commented:

looks pretty good, can you update the commit title to something like 
`[EntryExitInstrumenter] Move passes out of clang into LLVM default pipelines`

I've added test coverage for mcount-aix in 
3ec57a7ed60a19c5e3e18655e19c997a469d10ec, can you merge that in?

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


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

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

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


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

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


@@ -1,25 +1,13 @@
 // RUN: %clang_cc1 -pg -triple powerpc-ibm-aix7.2.0.0 -emit-llvm %s -o - | 
FileCheck %s

aeubanks wrote:

also -disable-llvm-passes here

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


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

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

bolshakov-a wrote:

Ok, got it. Thanks!

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


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

2024-05-24 Thread Eli Friedman via cfe-commits

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


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

2024-05-24 Thread via cfe-commits

Author: Andrey Ali Khan Bolshakov
Date: 2024-05-24T13:04:18-07:00
New Revision: 6be1a1535ef4ea30f301586e4960bebbfccfe851

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

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

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

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

A test case with subobject-referring NTTP added.

Added: 


Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/test/CoverageMapping/templates.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 05de50e3f1216..6ce2d32dd292e 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2271,7 +2271,8 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
-Visit(OVE->getSourceExpr());
+if (OVE->isUnique())
+  Visit(OVE->getSourceExpr());
   }
 };
 

diff  --git a/clang/test/CoverageMapping/templates.cpp 
b/clang/test/CoverageMapping/templates.cpp
index 143e566a33cb8..7e7f2208f1145 100644
--- a/clang/test/CoverageMapping/templates.cpp
+++ b/clang/test/CoverageMapping/templates.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
 
 template
 void unused(T x) {
@@ -30,5 +30,6 @@ namespace structural_value_crash {
 
   void test() {
 tpl_fn();
+tpl_fn<&arr[1]>();
   }
 }



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


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

2024-05-24 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

(In the future, please leave a note on the pull request when you push an 
update; as far as 
I can tell, GitHub doesn't generate a notification when you force-push to the 
branch.)

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


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

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

bolshakov-a wrote:

@efriedma-quic ping.

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


[clang] [clang] Macro for constant rounding mode (PR #92699)

2024-05-24 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM, but maybe wait a few days to merge in case someone else has comments.

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


[clang] [clang] fix(93284): In Sema use new parentEvaluationContext function (PR #93338)

2024-05-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #93284

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


2 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+2-3) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+7-8) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5247379181808..1214a262076e0 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6289,10 +6289,9 @@ class Sema final : public SemaBase {
   /// flag from previous context.
   void keepInLifetimeExtendingContext() {
 if (ExprEvalContexts.size() > 2 &&
-ExprEvalContexts[ExprEvalContexts.size() - 2]
-.InLifetimeExtendingContext) {
+parentEvaluationContext().InLifetimeExtendingContext) {
   auto &LastRecord = ExprEvalContexts.back();
-  auto &PrevRecord = ExprEvalContexts[ExprEvalContexts.size() - 2];
+  auto &PrevRecord = parentEvaluationContext();
   LastRecord.InLifetimeExtendingContext =
   PrevRecord.InLifetimeExtendingContext;
 }
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ff9c5ead36dcf..0236db1f37b1a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17223,8 +17223,7 @@ ExprResult Sema::TransformToPotentiallyEvaluated(Expr 
*E) {
 TypeSourceInfo *Sema::TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo) {
   assert(isUnevaluatedContext() &&
  "Should only transform unevaluated expressions");
-  ExprEvalContexts.back().Context =
-  ExprEvalContexts[ExprEvalContexts.size() - 2].Context;
+  ExprEvalContexts.back().Context = parentEvaluationContext().Context;
   if (isUnevaluatedContext())
 return TInfo;
   return TransformToPE(*this).TransformType(TInfo);
@@ -17241,14 +17240,13 @@ Sema::PushExpressionEvaluationContext(
   // discarded statements or immediate context are themselves
   // a discarded statement or an immediate context, respectively.
   ExprEvalContexts.back().InDiscardedStatement =
-  ExprEvalContexts[ExprEvalContexts.size() - 2]
-  .isDiscardedStatementContext();
+  parentEvaluationContext().isDiscardedStatementContext();
 
   // C++23 [expr.const]/p15
   // An expression or conversion is in an immediate function context if [...]
   // it is a subexpression of a manifestly constant-evaluated expression or
   // conversion.
-  const auto &Prev = ExprEvalContexts[ExprEvalContexts.size() - 2];
+  const auto &Prev = parentEvaluationContext();
   ExprEvalContexts.back().InImmediateFunctionContext =
   Prev.isImmediateFunctionContext() || Prev.isConstantEvaluated();
 
@@ -17693,12 +17691,13 @@ void Sema::PopExpressionEvaluationContext() {
 
   // Append the collected materialized temporaries into previous context before
   // exit if the previous also is a lifetime extending context.
-  auto &PrevRecord = ExprEvalContexts[ExprEvalContexts.size() - 2];
+  auto &PrevRecord = parentEvaluationContext();
   if (getLangOpts().CPlusPlus23 && Rec.InLifetimeExtendingContext &&
   PrevRecord.InLifetimeExtendingContext &&
   !Rec.ForRangeLifetimeExtendTemps.empty()) {
-PrevRecord.ForRangeLifetimeExtendTemps.append(
-Rec.ForRangeLifetimeExtendTemps);
+const_cast &>(
+PrevRecord.ForRangeLifetimeExtendTemps)
+.append(Rec.ForRangeLifetimeExtendTemps);
   }
 
   WarnOnPendingNoDerefs(Rec);

``




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


[clang] [clang] fix(93284): In Sema use new parentEvaluationContext function (PR #93338)

2024-05-24 Thread Oleksandr T. via cfe-commits

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

Fixes #93284

>From 43050fe6f93436b43b4aa336013a91eed1d6d23a Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 24 May 2024 22:46:53 +0300
Subject: [PATCH] fix(93284): replace direct access to ExprEvalContexts with
 parentEvaluationContext

---
 clang/include/clang/Sema/Sema.h |  5 ++---
 clang/lib/Sema/SemaExpr.cpp | 15 +++
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5247379181808..1214a262076e0 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6289,10 +6289,9 @@ class Sema final : public SemaBase {
   /// flag from previous context.
   void keepInLifetimeExtendingContext() {
 if (ExprEvalContexts.size() > 2 &&
-ExprEvalContexts[ExprEvalContexts.size() - 2]
-.InLifetimeExtendingContext) {
+parentEvaluationContext().InLifetimeExtendingContext) {
   auto &LastRecord = ExprEvalContexts.back();
-  auto &PrevRecord = ExprEvalContexts[ExprEvalContexts.size() - 2];
+  auto &PrevRecord = parentEvaluationContext();
   LastRecord.InLifetimeExtendingContext =
   PrevRecord.InLifetimeExtendingContext;
 }
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ff9c5ead36dcf..0236db1f37b1a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17223,8 +17223,7 @@ ExprResult Sema::TransformToPotentiallyEvaluated(Expr 
*E) {
 TypeSourceInfo *Sema::TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo) {
   assert(isUnevaluatedContext() &&
  "Should only transform unevaluated expressions");
-  ExprEvalContexts.back().Context =
-  ExprEvalContexts[ExprEvalContexts.size() - 2].Context;
+  ExprEvalContexts.back().Context = parentEvaluationContext().Context;
   if (isUnevaluatedContext())
 return TInfo;
   return TransformToPE(*this).TransformType(TInfo);
@@ -17241,14 +17240,13 @@ Sema::PushExpressionEvaluationContext(
   // discarded statements or immediate context are themselves
   // a discarded statement or an immediate context, respectively.
   ExprEvalContexts.back().InDiscardedStatement =
-  ExprEvalContexts[ExprEvalContexts.size() - 2]
-  .isDiscardedStatementContext();
+  parentEvaluationContext().isDiscardedStatementContext();
 
   // C++23 [expr.const]/p15
   // An expression or conversion is in an immediate function context if [...]
   // it is a subexpression of a manifestly constant-evaluated expression or
   // conversion.
-  const auto &Prev = ExprEvalContexts[ExprEvalContexts.size() - 2];
+  const auto &Prev = parentEvaluationContext();
   ExprEvalContexts.back().InImmediateFunctionContext =
   Prev.isImmediateFunctionContext() || Prev.isConstantEvaluated();
 
@@ -17693,12 +17691,13 @@ void Sema::PopExpressionEvaluationContext() {
 
   // Append the collected materialized temporaries into previous context before
   // exit if the previous also is a lifetime extending context.
-  auto &PrevRecord = ExprEvalContexts[ExprEvalContexts.size() - 2];
+  auto &PrevRecord = parentEvaluationContext();
   if (getLangOpts().CPlusPlus23 && Rec.InLifetimeExtendingContext &&
   PrevRecord.InLifetimeExtendingContext &&
   !Rec.ForRangeLifetimeExtendTemps.empty()) {
-PrevRecord.ForRangeLifetimeExtendTemps.append(
-Rec.ForRangeLifetimeExtendTemps);
+const_cast &>(
+PrevRecord.ForRangeLifetimeExtendTemps)
+.append(Rec.ForRangeLifetimeExtendTemps);
   }
 
   WarnOnPendingNoDerefs(Rec);

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


[clang] [HLSL] Change default linkage of HLSL functions to internal (PR #93336)

2024-05-24 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 3c3e71d929457daf4be425a35920cc53ed875fab 
bc226afcdd8c358f730c1243a11f7bbb17b8b209 -- clang/lib/CodeGen/CGHLSLRuntime.cpp 
clang/lib/CodeGen/CGHLSLRuntime.h clang/lib/CodeGen/CodeGenFunction.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 0f18c55ada..8e5123daf2 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -354,7 +354,7 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> 
&B,
 }
 
 void CGHLSLRuntime::emitFunctionProlog(const FunctionDecl *FD,
-  llvm::Function *Fn) {
+   llvm::Function *Fn) {
   if (!FD || !Fn)
 return;
 

``




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


[clang] [HLSL] Default and Relaxed Availability Diagnostics (PR #92704)

2024-05-24 Thread Damyan Pepper via cfe-commits


@@ -290,3 +294,295 @@ void SemaHLSL::DiagnoseAttrStageMismatch(
   << A << HLSLShaderAttr::ConvertShaderTypeToStr(Stage)
   << (AllowedStages.size() != 1) << join(StageStrings, ", ");
 }
+
+namespace {
+
+/// This class implements HLSL availability diagnostics for default
+/// and relaxed mode
+///
+/// The goal of this diagnostic is to emit an error or warning when an
+/// unavailable API is found in a code that is reachable from the shader
+/// entry function or from an exported function (when compiling shader
+/// library).
+///
+/// This is done by traversing the AST of all shader entry point functions
+/// and of all exported functions, and any functions that are refrenced
+/// from this AST. In other words, any function that are reachable from
+/// the entry points.
+class DiagnoseHLSLAvailability
+: public RecursiveASTVisitor {
+
+  Sema &SemaRef;
+
+  // Stack of functions to be scaned
+  llvm::SmallVector DeclsToScan;
+
+  // List of functions that were already scanned and in which environment.
+  //
+  // Maps FunctionDecl to a unsigned number that represents a set of shader
+  // environments the function has been scanned for.
+  // Since HLSLShaderAttr::ShaderType enum is generated from Attr.td and is
+  // defined without any assigned values, it is guaranteed to be numbered
+  // sequentially from 0 up and we can use it to 'index' individual bits
+  // in the set.
+  // The N'th bit in the set will be set if the function has been scanned
+  // in shader environment whose ShaderType integer value equals N.
+  // For example, if a function has been scanned in compute and pixel stage
+  // environment, the value will be 0x21 (11 binary) because
+  // (int)HLSLShaderAttr::ShaderType::Pixel == 1 and
+  // (int)HLSLShaderAttr::ShaderType::Compute == 5.
+  llvm::DenseMap ScannedDecls;
+
+  // Do not access these directly, use the get/set methods below to make
+  // sure the values are in sync
+  llvm::Triple::EnvironmentType CurrentShaderEnvironment;
+  unsigned CurrentShaderStageBit;

damyanp wrote:

As it's a contiguous block of EnvironmentTypes it'd be possible to do this 
without the switch, but I think that this is more a style issue than anything.  
I tend to go to lengths to avoid storing redundant data, but can see that it 
doesn't have to be done that way.

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


[clang] [HLSL] Default and Relaxed Availability Diagnostics (PR #92704)

2024-05-24 Thread Helena Kotas via cfe-commits


@@ -0,0 +1,98 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute \
+// RUN: -fsyntax-only -verify %s
+
+__attribute__((availability(shadermodel, introduced = 6.5)))
+float fx(float);  // #fx
+
+__attribute__((availability(shadermodel, introduced = 5.0, environment = 
pixel)))
+__attribute__((availability(shadermodel, introduced = 6.5, environment = 
compute)))
+float fy(float); // #fy
+
+__attribute__((availability(shadermodel, introduced = 5.0, environment = 
pixel)))
+__attribute__((availability(shadermodel, introduced = 6.5, environment = 
mesh)))
+float fz(float); // #fz
+
+float also_alive(float f) {
+  // expected-error@#also_alive_fx_call {{'fx' is only available on Shader 
Model 6.5 or newer}}
+  // expected-note@#fx {{'fx' has been marked as being introduced in Shader 
Model 6.5 here, but the deployment target is Shader Model 6.0}}
+  float A = fx(f); // #also_alive_fx_call
+  // expected-error@#also_alive_fy_call {{'fy' is only available in compute 
shader environment on Shader Model 6.5 or newer}}
+  // expected-note@#fy {{'fy' has been marked as being introduced in Shader 
Model 6.5 in compute shader environment here, but the deployment target is 
Shader Model 6.0 compute shader environment}}
+  float B = fy(f); // #also_alive_fy_call
+  // expected-error@#also_alive_fz_call {{'fz' is unavailable}}
+  // expected-note@#fz {{'fz' has been marked as being introduced in Shader 
Model 6.5 in mesh shader environment here, but the deployment target is Shader 
Model 6.0 compute shader environment}}
+  float C = fz(f); // #also_alive_fz_call
+  return 0;
+}
+
+float alive(float f) {
+  // expected-error@#alive_fx_call {{'fx' is only available on Shader Model 
6.5 or newer}}
+  // expected-note@#fx {{'fx' has been marked as being introduced in Shader 
Model 6.5 here, but the deployment target is Shader Model 6.0}}
+  float A = fx(f); // #alive_fx_call
+  // expected-error@#alive_fy_call {{'fy' is only available in compute shader 
environment on Shader Model 6.5 or newer}}
+  // expected-note@#fy {{'fy' has been marked as being introduced in Shader 
Model 6.5 in compute shader environment here, but the deployment target is 
Shader Model 6.0 compute shader environment}}
+  float B = fy(f); // #alive_fy_call
+  // expected-error@#alive_fz_call {{'fz' is unavailable}}
+  // expected-note@#fz {{'fz' has been marked as being introduced in Shader 
Model 6.5 in mesh shader environment here, but the deployment target is Shader 
Model 6.0 compute shader environment}}
+  float C = fz(f); // #alive_fz_call
+
+  return also_alive(f);
+}
+
+float also_dead(float f) {
+  // unreachable code - no errors expected
+  float A = fx(f);
+  float B = fy(f);
+  float C = fz(f);
+  return 0;
+}
+
+float dead(float f) {
+  // unreachable code - no errors expected
+  float A = fx(f);
+  float B = fy(f);
+  float C = fz(f);
+
+  return also_dead(f);
+}
+
+template
+T aliveTemp(T f) {

hekota wrote:

I'll add them here.

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


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-05-24 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea updated 
https://github.com/llvm/llvm-project/pull/89950

>From 13c411018e491fc2be4f4118a56f9b8cf2e5b76f Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 17 Apr 2024 16:28:21 -0400
Subject: [PATCH 1/5] [clang-scan-deps] Expand response files before the
 argument ajuster

Previously, since response (.rsp) files weren't expanded, we only parsed
the command-line as provided in the Clang CDB file. Unfortunately, when
using Unreal Engine, arguments are always generated in a .rsp file.

After this patch, /Fo can be parsed and added to the final command-line.
Without this option, the make targets that are emitted are made up from the
input file name alone. We have some cases where the same input in the project
generates several output files, so we end up with duplicate make targets
in the scan-deps emitted dependency file.
---
 clang/tools/clang-scan-deps/ClangScanDeps.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index f42af7e330e17..7b7f10c4be742 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -792,10 +792,15 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
 
   llvm::cl::PrintOptionValues();
 
+  // Expand response files in advance, so that we can "see" all the arguments
+  // when adjusting below.
+  auto ResponseExpander = expandResponseFiles(std::move(Compilations),
+  llvm::vfs::getRealFileSystem());
+
   // The command options are rewritten to run Clang in preprocessor only mode.
   auto AdjustingCompilations =
   std::make_unique(
-  std::move(Compilations));
+  std::move(ResponseExpander));
   ResourceDirectoryCache ResourceDirCache;
 
   AdjustingCompilations->appendArgumentsAdjuster(

>From d6122c7fe41fb1642560985abafb9444f3e6 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 24 Apr 2024 13:52:55 -0400
Subject: [PATCH 2/5] Add test

---
 .../ClangScanDeps/response-file-clang-cl.c| 32 +++
 1 file changed, 32 insertions(+)
 create mode 100644 clang/test/ClangScanDeps/response-file-clang-cl.c

diff --git a/clang/test/ClangScanDeps/response-file-clang-cl.c 
b/clang/test/ClangScanDeps/response-file-clang-cl.c
new file mode 100644
index 0..78e3d15deb167
--- /dev/null
+++ b/clang/test/ClangScanDeps/response-file-clang-cl.c
@@ -0,0 +1,32 @@
+// Check that the scanner can adjust arguments by reading .rsp files in 
advance.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: echo /Fo%t/tu.obj >> %t/args_nested.rsp
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json > %t/deps.json
+
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s
+
+// Here we ensure that we got a qualified .obj with its full path, since 
that's what we're passing with /Fo
+// CHECK: [[PREFIX]]/tu.obj:
+
+//--- cdb.json.template
+[{
+  "file": "DIR/t.cpp",
+  "directory": "DIR",
+  "command": "clang-cl @DIR/args.rsp"
+}]
+
+//--- args.rsp
+@args_nested.rsp
+/c tu.cpp
+
+//--- args_nested.rsp
+/I include
+
+//--- include/header.h
+
+//--- tu.cpp
+#include "header.h"

>From d74e133dc023d24e66b853940a1b4bb799c0a491 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 24 Apr 2024 17:02:17 -0400
Subject: [PATCH 3/5] Handle /Fo in the Clang driver as well.

---
 clang/lib/Driver/ToolChains/Clang.cpp | 2 +-
 clang/test/ClangScanDeps/response-file-clang-cl.c | 6 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 18de8781e894a..15cf58f9d3339 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1030,7 +1030,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const 
JobAction &JA,
 
   // If user provided -o, that is the dependency target, except
   // when we are only generating a dependency file.
-  Arg *OutputOpt = Args.getLastArg(options::OPT_o);
+  Arg *OutputOpt = Args.getLastArg(options::OPT_o, options::OPT__SLASH_Fo);
   if (OutputOpt && Output.getType() != types::TY_Dependencies) {
 DepTarget = OutputOpt->getValue();
   } else {
diff --git a/clang/test/ClangScanDeps/response-file-clang-cl.c 
b/clang/test/ClangScanDeps/response-file-clang-cl.c
index 78e3d15deb167..77cecfff0b9ca 100644
--- a/clang/test/ClangScanDeps/response-file-clang-cl.c
+++ b/clang/test/ClangScanDeps/response-file-clang-cl.c
@@ -5,8 +5,12 @@
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
 // RUN: echo /Fo%t/tu.obj >> %t/args_nested.rsp
 
+// RUN: echo /c >> %t/args_nested.rsp
 // RUN: clang-scan-deps -compilation-database %t/cdb.json > %t/deps.json
+// RUN: cat %t/deps.json | sed 's:\?:/:

  1   2   3   4   >