[PATCH] D151300: [clang][Diagnostics][NFC] Remove unnecessary StringRef

2023-05-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: clang, cjdb, aaron.ballman.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Seems unnecessary to create a `StringRef` here just so we can drop the trailing 
null bytes. We can do that with the `std::string` we create anyway.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151300

Files:
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/Misc/diag-null-bytes-in-line.cpp


Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1203,14 +1203,12 @@
 if (size_t(LineEnd - LineStart) > MaxLineLengthToPrint)
   return;
 
-// Trim trailing null-bytes.
-StringRef Line(LineStart, LineEnd - LineStart);
-while (!Line.empty() && Line.back() == '\0' &&
-   (LineNo != CaretLineNo || Line.size() > CaretColNo))
-  Line = Line.drop_back();
-
 // Copy the line of code into an std::string for ease of manipulation.
-std::string SourceLine(Line.begin(), Line.end());
+std::string SourceLine(LineStart, LineEnd);
+// Remove trailing null bytes.
+while (!SourceLine.empty() && SourceLine.back() == '\0' &&
+   (LineNo != CaretLineNo || SourceLine.size() > CaretColNo))
+  SourceLine.pop_back();
 
 // Build the byte to column map.
 const SourceColumnMap sourceColMap(SourceLine, DiagOpts->TabStop);


Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1203,14 +1203,12 @@
 if (size_t(LineEnd - LineStart) > MaxLineLengthToPrint)
   return;
 
-// Trim trailing null-bytes.
-StringRef Line(LineStart, LineEnd - LineStart);
-while (!Line.empty() && Line.back() == '\0' &&
-   (LineNo != CaretLineNo || Line.size() > CaretColNo))
-  Line = Line.drop_back();
-
 // Copy the line of code into an std::string for ease of manipulation.
-std::string SourceLine(Line.begin(), Line.end());
+std::string SourceLine(LineStart, LineEnd);
+// Remove trailing null bytes.
+while (!SourceLine.empty() && SourceLine.back() == '\0' &&
+   (LineNo != CaretLineNo || SourceLine.size() > CaretColNo))
+  SourceLine.pop_back();
 
 // Build the byte to column map.
 const SourceColumnMap sourceColMap(SourceLine, DiagOpts->TabStop);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151300: [clang][Diagnostics][NFC] Remove unnecessary StringRef

2023-05-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 525031.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151300/new/

https://reviews.llvm.org/D151300

Files:
  clang/lib/Frontend/TextDiagnostic.cpp


Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1203,14 +1203,12 @@
 if (size_t(LineEnd - LineStart) > MaxLineLengthToPrint)
   return;
 
-// Trim trailing null-bytes.
-StringRef Line(LineStart, LineEnd - LineStart);
-while (!Line.empty() && Line.back() == '\0' &&
-   (LineNo != CaretLineNo || Line.size() > CaretColNo))
-  Line = Line.drop_back();
-
 // Copy the line of code into an std::string for ease of manipulation.
-std::string SourceLine(Line.begin(), Line.end());
+std::string SourceLine(LineStart, LineEnd);
+// Remove trailing null bytes.
+while (!SourceLine.empty() && SourceLine.back() == '\0' &&
+   (LineNo != CaretLineNo || SourceLine.size() > CaretColNo))
+  SourceLine.pop_back();
 
 // Build the byte to column map.
 const SourceColumnMap sourceColMap(SourceLine, DiagOpts->TabStop);


Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1203,14 +1203,12 @@
 if (size_t(LineEnd - LineStart) > MaxLineLengthToPrint)
   return;
 
-// Trim trailing null-bytes.
-StringRef Line(LineStart, LineEnd - LineStart);
-while (!Line.empty() && Line.back() == '\0' &&
-   (LineNo != CaretLineNo || Line.size() > CaretColNo))
-  Line = Line.drop_back();
-
 // Copy the line of code into an std::string for ease of manipulation.
-std::string SourceLine(Line.begin(), Line.end());
+std::string SourceLine(LineStart, LineEnd);
+// Remove trailing null bytes.
+while (!SourceLine.empty() && SourceLine.back() == '\0' &&
+   (LineNo != CaretLineNo || SourceLine.size() > CaretColNo))
+  SourceLine.pop_back();
 
 // Build the byte to column map.
 const SourceColumnMap sourceColMap(SourceLine, DiagOpts->TabStop);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151301: [clang][Diagnostics] Print empty lines in multiline snippets

2023-05-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: clang, cjdb, aaron.ballman.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We should preserve empty lines in output snippets.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151301

Files:
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/Misc/diag-style.cpp


Index: clang/test/Misc/diag-style.cpp
===
--- /dev/null
+++ clang/test/Misc/diag-style.cpp
@@ -0,0 +1,12 @@
+// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s
+
+/// empty lines in multi-line diagnostic snippets are preserved.
+static_assert(false &&
+
+  true, "");
+// CHECK: static assertion failed
+// CHECK-NEXT: {{^}}4 | static_assert(false &&{{$}}
+// CHECK-NEXT: {{^}}  |   ^~~~{{$}}
+// CHECK-NEXT: {{^}}5 | {{$}}
+// CHECK-NEXT: {{^}}6 |   true, "");{{$}}
+// CHECK-NEXT: {{^}}  |   {{$}}
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1280,9 +1280,6 @@
 void TextDiagnostic::emitSnippet(StringRef SourceLine,
  unsigned MaxLineNoDisplayWidth,
  unsigned LineNo) {
-  if (SourceLine.empty())
-return;
-
   // Emit line number.
   if (MaxLineNoDisplayWidth > 0) {
 unsigned LineNoDisplayWidth = getNumDisplayWidth(LineNo);


Index: clang/test/Misc/diag-style.cpp
===
--- /dev/null
+++ clang/test/Misc/diag-style.cpp
@@ -0,0 +1,12 @@
+// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s
+
+/// empty lines in multi-line diagnostic snippets are preserved.
+static_assert(false &&
+
+  true, "");
+// CHECK: static assertion failed
+// CHECK-NEXT: {{^}}4 | static_assert(false &&{{$}}
+// CHECK-NEXT: {{^}}  |   ^~~~{{$}}
+// CHECK-NEXT: {{^}}5 | {{$}}
+// CHECK-NEXT: {{^}}6 |   true, "");{{$}}
+// CHECK-NEXT: {{^}}  |   {{$}}
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1280,9 +1280,6 @@
 void TextDiagnostic::emitSnippet(StringRef SourceLine,
  unsigned MaxLineNoDisplayWidth,
  unsigned LineNo) {
-  if (SourceLine.empty())
-return;
-
   // Emit line number.
   if (MaxLineNoDisplayWidth > 0) {
 unsigned LineNoDisplayWidth = getNumDisplayWidth(LineNo);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-05-24 Thread wanglei via Phabricator via cfe-commits
wangleiat added a comment.

In D151298#4367163 , @xry111 wrote:

> Blocking this as it's a deliberate decision made in D132285 
> .
>
> Is there any imperative reason we must really pass the empty struct?  The C++ 
> standard only treats struct {} as size 1 for the semantics of pointer 
> comparison.  While there is no pointers to registers, ignoring it in the 
> register calling convention will make no harm.
>
> And AFAIK it will be an undefined behavior attempting to (mis)use the padding 
> space of/after the empty struct to pass any information.



In D151298#4367163 , @xry111 wrote:

> Blocking this as it's a deliberate decision made in D132285 
> .
>
> Is there any imperative reason we must really pass the empty struct?  The C++ 
> standard only treats struct {} as size 1 for the semantics of pointer 
> comparison.  While there is no pointers to registers, ignoring it in the 
> register calling convention will make no harm.
>
> And AFAIK it will be an undefined behavior attempting to (mis)use the padding 
> space of/after the empty struct to pass any information.

Our current modifications are closer to the description of `Itanium C++ ABI`, 
and we try to keep it consistent with the description of the calling convention 
under `reasonable premise`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151298/new/

https://reviews.llvm.org/D151298

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


[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-05-24 Thread Xi Ruoyao via Phabricator via cfe-commits
xry111 added a comment.

In D151298#4367215 , @wangleiat wrote:

> In D151298#4367163 , @xry111 wrote:
>
>> Blocking this as it's a deliberate decision made in D132285 
>> .
>>
>> Is there any imperative reason we must really pass the empty struct?  The 
>> C++ standard only treats struct {} as size 1 for the semantics of pointer 
>> comparison.  While there is no pointers to registers, ignoring it in the 
>> register calling convention will make no harm.
>>
>> And AFAIK it will be an undefined behavior attempting to (mis)use the 
>> padding space of/after the empty struct to pass any information.
>
> Our current modifications are closer to the description of `Itanium C++ ABI`, 
> and we try to keep it consistent with the description of the calling 
> convention under `reasonable premise`.

Hmm, could you provide a link to the section saying this in the Itanium C++ ABI?

I see it has some words about passing or returning an empty class, but there 
seems no words about passing a class containing an empty class.

And for our own psABI, it's easier to simply reword it (making it similar to 
the RISC-V psABI about passing args with FPRs) instead of modifying both Clang 
and GCC (causing the code of Clang and GCC more nasty, and both compilers 
slower, and we'll need to add a -Wpsabi warning at least in GCC too).  And it 
already needs a reword considering empty arrays and zero-width bit-fields 
anyway.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151298/new/

https://reviews.llvm.org/D151298

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


[PATCH] D151301: [clang][Diagnostics] Print empty lines in multiline snippets

2023-05-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/Misc/diag-style.cpp:10
+// CHECK-NEXT: {{^}}  |   ^~~~{{$}}
+// CHECK-NEXT: {{^}}5 | {{$}}
+// CHECK-NEXT: {{^}}6 |   true, "");{{$}}

Questionable whether the space after the `|` is expected.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151301/new/

https://reviews.llvm.org/D151301

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


[clang] 1c9a800 - Recommit [C++20] [Modules] Serialize the evaluated constant values for VarDecl

2023-05-24 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-05-24T15:45:16+08:00
New Revision: 1c9a8004ed88c9a5e42e5b247cb489456559b845

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

LOG: Recommit [C++20] [Modules] Serialize the evaluated constant values for 
VarDecl

Close https://github.com/llvm/llvm-project/issues/62796.

Previously, we didn't serialize the evaluated result for VarDecl. This
caused the compilation of template metaprogramming become slower than
expect. This patch fixes the issue.

This is a recommit tested with asan built clang.

Added: 
clang/test/Modules/pr62796.cppm
clang/unittests/Serialization/VarDeclConstantInitTest.cpp

Modified: 
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/unittests/Serialization/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 5ce7007d8acef..fb8677769d09b 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1659,6 +1659,13 @@ void ASTDeclReader::ReadVarDeclInit(VarDecl *VD) {
 EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
 Eval->HasConstantInitialization = (Val & 2) != 0;
 Eval->HasConstantDestruction = (Val & 4) != 0;
+Eval->WasEvaluated = (Val & 8) != 0;
+if (Eval->WasEvaluated) {
+  Eval->Evaluated = Record.readAPValue();
+  if (Eval->Evaluated.needsCleanup())
+Reader.getContext().addDestruction(&Eval->Evaluated);
+}
+
 // Store the offset of the initializer. Don't deserialize it yet: it might
 // not be needed, and might refer back to the variable, for example if it
 // contains a lambda.

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 749aaa4cd6e19..4efc27b3d2434 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5987,13 +5987,20 @@ void ASTRecordWriter::AddVarDeclInit(const VarDecl *VD) 
{
 return;
   }
 
-  unsigned Val = 1;
+  uint64_t Val = 1;
   if (EvaluatedStmt *ES = VD->getEvaluatedStmt()) {
 Val |= (ES->HasConstantInitialization ? 2 : 0);
 Val |= (ES->HasConstantDestruction ? 4 : 0);
-// FIXME: Also emit the constant initializer value.
+APValue *Evaluated = VD->getEvaluatedValue();
+// If the evaluted result is constant, emit it.
+if (Evaluated && (Evaluated->isInt() || Evaluated->isFloat()))
+  Val |= 8;
   }
   push_back(Val);
+  if (Val & 8) {
+AddAPValue(*VD->getEvaluatedValue());
+  }
+
   writeStmtRef(Init);
 }
 

diff  --git a/clang/test/Modules/pr62796.cppm b/clang/test/Modules/pr62796.cppm
new file mode 100644
index 0..f96e54bc6aded
--- /dev/null
+++ b/clang/test/Modules/pr62796.cppm
@@ -0,0 +1,51 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Cache.cppm -o 
%t/Cache.pcm
+// RUN: %clang_cc1 -std=c++20 %t/Use.cpp 
-fmodule-file=Fibonacci.Cache=%t/Cache.pcm \
+// RUN: -fsyntax-only -verify
+
+//--- Cache.cppm
+export module Fibonacci.Cache;
+
+export namespace Fibonacci
+{
+   constexpr unsigned long Recursive(unsigned long n)
+   {
+   if (n == 0)
+   return 0;
+   if (n == 1)
+   return 1;
+   return Recursive(n - 2) + Recursive(n - 1);
+   }
+
+   template
+   struct Number{};
+
+   struct DefaultStrategy
+   {
+   constexpr unsigned long operator()(unsigned long n, auto... 
other) const
+   {
+   return (n + ... + other);
+   }
+   };
+
+constexpr unsigned long Compute(Number<10ul>, auto strategy)
+   {
+   return strategy(Recursive(10ul));
+   }
+
+   template
+   constexpr unsigned long Cache = Compute(Number{}, Strategy{});
+
+template constexpr unsigned long Cache<10ul>;
+}
+
+//--- Use.cpp
+// expected-no-diagnostics
+import Fibonacci.Cache;
+
+constexpr bool value = Fibonacci::Cache<10ul> == 55;
+
+static_assert(value == true, "");

diff  --git a/clang/unittests/Serialization/CMakeLists.txt 
b/clang/unittests/Serialization/CMakeLists.txt
index cfb4089167aad..88aca2e135200 100644
--- a/clang/unittests/Serialization/CMakeLists.txt
+++ b/clang/unittests/Serialization/CMakeLists.txt
@@ -8,6 +8,7 @@ add_clang_unittest(SerializationTests
   InMemoryModuleCacheTest.cpp
   ModuleCacheTest.cpp
   SourceLocationEncodingTest.cpp
+  VarDeclConstantInitTest.cpp
   )
 
 clang_target_link_libraries(SerializationTests
@@ -18,4 +19,5 @@ clang_target_link_libraries(SerializationTests
   clangLex
   clangSema
   clangSerialization
+  clangTooling
   )

diff  --git a/clang/uni

[PATCH] D151303: [clangd] Fix add-using tweak on declrefs with template arguments

2023-05-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: VitaNuo.
Herald added a subscriber: arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151303

Files:
  clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
  clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
@@ -498,6 +498,30 @@
   switch(one::two::ee{}) { case ee_one:break; }
 }
 )cpp"},
+  {R"cpp(
+#include "test.hpp"
+void foo() {
+  one::f^unc_temp();
+})cpp",
+   R"cpp(
+#include "test.hpp"
+using one::func_temp;
+
+void foo() {
+  func_temp();
+})cpp"},
+  {R"cpp(
+#include "test.hpp"
+void foo() {
+  one::va^r_temp;
+})cpp",
+   R"cpp(
+#include "test.hpp"
+using one::var_temp;
+
+void foo() {
+  var_temp;
+})cpp"},
   };
   llvm::StringMap EditedFiles;
   for (const auto &Case : Cases) {
@@ -515,6 +539,8 @@
 }
 using uu = two::cc;
 template struct vec {};
+template  void func_temp();
+template  T var_temp();
 })cpp";
 // Typo correction is disabled in msvc-compatibility mode.
 ExtraArgs.push_back("-fno-ms-compatibility");
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -288,11 +288,18 @@
   if (Node == nullptr)
 return false;
 
+  // Closed range for the fully qualified name as spelled in source code.
   SourceRange SpelledNameRange;
   if (auto *D = Node->ASTNode.get()) {
 if (D->getDecl()->getIdentifier()) {
   QualifierToRemove = D->getQualifierLoc();
+  // Use the name range rather than expr, as the latter can contain 
template
+  // arguments in the range.
   SpelledNameRange = D->getSourceRange();
+  // Remove the template arguments from the name, as they shouldn't be
+  // spelled in the using declaration.
+  if (auto AngleLoc = D->getLAngleLoc(); AngleLoc.isValid())
+SpelledNameRange.setEnd(AngleLoc.getLocWithOffset(-1));
   MustInsertAfterLoc = D->getDecl()->getBeginLoc();
 }
   } else if (auto *T = Node->ASTNode.get()) {


Index: clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
@@ -498,6 +498,30 @@
   switch(one::two::ee{}) { case ee_one:break; }
 }
 )cpp"},
+  {R"cpp(
+#include "test.hpp"
+void foo() {
+  one::f^unc_temp();
+})cpp",
+   R"cpp(
+#include "test.hpp"
+using one::func_temp;
+
+void foo() {
+  func_temp();
+})cpp"},
+  {R"cpp(
+#include "test.hpp"
+void foo() {
+  one::va^r_temp;
+})cpp",
+   R"cpp(
+#include "test.hpp"
+using one::var_temp;
+
+void foo() {
+  var_temp;
+})cpp"},
   };
   llvm::StringMap EditedFiles;
   for (const auto &Case : Cases) {
@@ -515,6 +539,8 @@
 }
 using uu = two::cc;
 template struct vec {};
+template  void func_temp();
+template  T var_temp();
 })cpp";
 // Typo correction is disabled in msvc-compatibility mode.
 ExtraArgs.push_back("-fno-ms-compatibility");
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -288,11 +288,18 @@
   if (Node == nullptr)
 return false;
 
+  // Closed range for the fully qualified name as spelled in source code.
   SourceRange SpelledNameRange;
   if (auto *D = Node->ASTNode.get()) {
 if (D->getDecl()->getIdentifier()) {
   QualifierToRemove = D->getQualifierLoc();
+  // Use the name range rather than expr, as the latter can contain template
+  // arguments in the range.
   SpelledNameRange = D->getSourceRange();
+  // Remove the template arguments from the name, as they shouldn't be
+  // spelled in the using declaration.
+  if (auto AngleLoc = D->getLAngleLoc(); AngleLoc.isValid())
+SpelledNameRange.setEnd(AngleLoc.getLocWithOffset(-1));
   MustInsertAfterLoc = D->getDecl()->getBeginLoc();
 }
   } else if (auto *T = Node->ASTNode.get()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151303: [clangd] Fix add-using tweak on declrefs with template arguments

2023-05-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG51df1a9ac96f: [clangd] Fix add-using tweak on declrefs with 
template arguments (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151303/new/

https://reviews.llvm.org/D151303

Files:
  clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
  clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
@@ -498,6 +498,30 @@
   switch(one::two::ee{}) { case ee_one:break; }
 }
 )cpp"},
+  {R"cpp(
+#include "test.hpp"
+void foo() {
+  one::f^unc_temp();
+})cpp",
+   R"cpp(
+#include "test.hpp"
+using one::func_temp;
+
+void foo() {
+  func_temp();
+})cpp"},
+  {R"cpp(
+#include "test.hpp"
+void foo() {
+  one::va^r_temp;
+})cpp",
+   R"cpp(
+#include "test.hpp"
+using one::var_temp;
+
+void foo() {
+  var_temp;
+})cpp"},
   };
   llvm::StringMap EditedFiles;
   for (const auto &Case : Cases) {
@@ -515,6 +539,8 @@
 }
 using uu = two::cc;
 template struct vec {};
+template  void func_temp();
+template  T var_temp();
 })cpp";
 // Typo correction is disabled in msvc-compatibility mode.
 ExtraArgs.push_back("-fno-ms-compatibility");
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -288,11 +288,18 @@
   if (Node == nullptr)
 return false;
 
+  // Closed range for the fully qualified name as spelled in source code.
   SourceRange SpelledNameRange;
   if (auto *D = Node->ASTNode.get()) {
 if (D->getDecl()->getIdentifier()) {
   QualifierToRemove = D->getQualifierLoc();
+  // Use the name range rather than expr, as the latter can contain 
template
+  // arguments in the range.
   SpelledNameRange = D->getSourceRange();
+  // Remove the template arguments from the name, as they shouldn't be
+  // spelled in the using declaration.
+  if (auto AngleLoc = D->getLAngleLoc(); AngleLoc.isValid())
+SpelledNameRange.setEnd(AngleLoc.getLocWithOffset(-1));
   MustInsertAfterLoc = D->getDecl()->getBeginLoc();
 }
   } else if (auto *T = Node->ASTNode.get()) {


Index: clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
@@ -498,6 +498,30 @@
   switch(one::two::ee{}) { case ee_one:break; }
 }
 )cpp"},
+  {R"cpp(
+#include "test.hpp"
+void foo() {
+  one::f^unc_temp();
+})cpp",
+   R"cpp(
+#include "test.hpp"
+using one::func_temp;
+
+void foo() {
+  func_temp();
+})cpp"},
+  {R"cpp(
+#include "test.hpp"
+void foo() {
+  one::va^r_temp;
+})cpp",
+   R"cpp(
+#include "test.hpp"
+using one::var_temp;
+
+void foo() {
+  var_temp;
+})cpp"},
   };
   llvm::StringMap EditedFiles;
   for (const auto &Case : Cases) {
@@ -515,6 +539,8 @@
 }
 using uu = two::cc;
 template struct vec {};
+template  void func_temp();
+template  T var_temp();
 })cpp";
 // Typo correction is disabled in msvc-compatibility mode.
 ExtraArgs.push_back("-fno-ms-compatibility");
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -288,11 +288,18 @@
   if (Node == nullptr)
 return false;
 
+  // Closed range for the fully qualified name as spelled in source code.
   SourceRange SpelledNameRange;
   if (auto *D = Node->ASTNode.get()) {
 if (D->getDecl()->getIdentifier()) {
   QualifierToRemove = D->getQualifierLoc();
+  // Use the name range rather than expr, as the latter can contain template
+  // arguments in the range.
   SpelledNameRange = D->getSourceRange();
+  // Remove the template arguments from the name, as they shouldn't be
+  // spelled in the using declaration.
+  if (auto AngleLoc = D->getLAngleLoc(); AngleLoc.isValid())
+SpelledNameRange.setEnd(AngleLoc.getLocWithOffset(-1));
   MustInsertAfterLoc = D->getDecl()->getBeginLoc();
 }
   } else if (auto *T = Node->ASTNode.get()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 51df1a9 - [clangd] Fix add-using tweak on declrefs with template arguments

2023-05-24 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-05-24T09:56:53+02:00
New Revision: 51df1a9ac96f0cf588e97d3174d5c16ed9577b96

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

LOG: [clangd] Fix add-using tweak on declrefs with template arguments

Differential Revision: https://reviews.llvm.org/D151303

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
index 5ca45f94ea9f0..ca96da34e0920 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -288,11 +288,18 @@ bool AddUsing::prepare(const Selection &Inputs) {
   if (Node == nullptr)
 return false;
 
+  // Closed range for the fully qualified name as spelled in source code.
   SourceRange SpelledNameRange;
   if (auto *D = Node->ASTNode.get()) {
 if (D->getDecl()->getIdentifier()) {
   QualifierToRemove = D->getQualifierLoc();
+  // Use the name range rather than expr, as the latter can contain 
template
+  // arguments in the range.
   SpelledNameRange = D->getSourceRange();
+  // Remove the template arguments from the name, as they shouldn't be
+  // spelled in the using declaration.
+  if (auto AngleLoc = D->getLAngleLoc(); AngleLoc.isValid())
+SpelledNameRange.setEnd(AngleLoc.getLocWithOffset(-1));
   MustInsertAfterLoc = D->getDecl()->getBeginLoc();
 }
   } else if (auto *T = Node->ASTNode.get()) {

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
index f3a479a9a240f..da76ecad14554 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
@@ -498,6 +498,30 @@ void foo() {
   switch(one::two::ee{}) { case ee_one:break; }
 }
 )cpp"},
+  {R"cpp(
+#include "test.hpp"
+void foo() {
+  one::f^unc_temp();
+})cpp",
+   R"cpp(
+#include "test.hpp"
+using one::func_temp;
+
+void foo() {
+  func_temp();
+})cpp"},
+  {R"cpp(
+#include "test.hpp"
+void foo() {
+  one::va^r_temp;
+})cpp",
+   R"cpp(
+#include "test.hpp"
+using one::var_temp;
+
+void foo() {
+  var_temp;
+})cpp"},
   };
   llvm::StringMap EditedFiles;
   for (const auto &Case : Cases) {
@@ -515,6 +539,8 @@ class cc {
 }
 using uu = two::cc;
 template struct vec {};
+template  void func_temp();
+template  T var_temp();
 })cpp";
 // Typo correction is disabled in msvc-compatibility mode.
 ExtraArgs.push_back("-fno-ms-compatibility");



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


[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-05-24 Thread wanglei via Phabricator via cfe-commits
wangleiat added a comment.

In D151298#4367225 , @xry111 wrote:

> In D151298#4367215 , @wangleiat 
> wrote:
>
>> In D151298#4367163 , @xry111 wrote:
>>
>>> Blocking this as it's a deliberate decision made in D132285 
>>> .
>>>
>>> Is there any imperative reason we must really pass the empty struct?  The 
>>> C++ standard only treats struct {} as size 1 for the semantics of pointer 
>>> comparison.  While there is no pointers to registers, ignoring it in the 
>>> register calling convention will make no harm.
>>>
>>> And AFAIK it will be an undefined behavior attempting to (mis)use the 
>>> padding space of/after the empty struct to pass any information.
>>
>> Our current modifications are closer to the description of `Itanium C++ 
>> ABI`, and we try to keep it consistent with the description of the calling 
>> convention under `reasonable premise`.
>
> Hmm, could you provide a link to the section saying this in the Itanium C++ 
> ABI?

http://itanium-cxx-abi.github.io/cxx-abi/abi.html#empty-parameters
http://itanium-cxx-abi.github.io/cxx-abi/abi.html#emptty-return-values

> I see it has some words about passing or returning an empty class, but there 
> seems no words about passing a class containing an empty class.

It's possible that my understanding is incorrect. There is indeed no place to 
see how an empty class is passed, just like there is no documentation on how to 
pass `class A { class B { char c;};};`.

> And for our own psABI, it's easier to simply reword it (making it similar to 
> the RISC-V psABI about passing args with FPRs) instead of modifying both 
> Clang and GCC (causing the code of Clang and GCC more nasty, and both 
> compilers slower, and we'll need to add a -Wpsabi warning at least in GCC 
> too).  And it already needs a reword considering empty arrays and zero-width 
> bit-fields anyway.

I'm sorry, I couldn't quite understand what you meant.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151298/new/

https://reviews.llvm.org/D151298

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


[PATCH] D151301: [clang][Diagnostics] Print empty lines in multiline snippets

2023-05-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 525050.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151301/new/

https://reviews.llvm.org/D151301

Files:
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/Misc/diag-style.cpp


Index: clang/test/Misc/diag-style.cpp
===
--- /dev/null
+++ clang/test/Misc/diag-style.cpp
@@ -0,0 +1,12 @@
+// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s
+
+/// empty lines in multi-line diagnostic snippets are preserved.
+static_assert(false &&
+
+  true, "");
+// CHECK: static assertion failed
+// CHECK-NEXT: {{^}}4 | static_assert(false &&{{$}}
+// CHECK-NEXT: {{^}}  |   ^~~~{{$}}
+// CHECK-NEXT: {{^}}5 | {{$}}
+// CHECK-NEXT: {{^}}6 |   true, "");{{$}}
+// CHECK-NEXT: {{^}}  |   {{$}}
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1243,7 +1243,7 @@
 // to produce easily machine parsable output.  Add a space before the
 // source line and the caret to make it trivial to tell the main diagnostic
 // line from what the user is intended to see.
-if (DiagOpts->ShowSourceRanges) {
+if (DiagOpts->ShowSourceRanges && !SourceLine.empty()) {
   SourceLine = ' ' + SourceLine;
   CaretLine = ' ' + CaretLine;
 }
@@ -1280,9 +1280,6 @@
 void TextDiagnostic::emitSnippet(StringRef SourceLine,
  unsigned MaxLineNoDisplayWidth,
  unsigned LineNo) {
-  if (SourceLine.empty())
-return;
-
   // Emit line number.
   if (MaxLineNoDisplayWidth > 0) {
 unsigned LineNoDisplayWidth = getNumDisplayWidth(LineNo);


Index: clang/test/Misc/diag-style.cpp
===
--- /dev/null
+++ clang/test/Misc/diag-style.cpp
@@ -0,0 +1,12 @@
+// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s
+
+/// empty lines in multi-line diagnostic snippets are preserved.
+static_assert(false &&
+
+  true, "");
+// CHECK: static assertion failed
+// CHECK-NEXT: {{^}}4 | static_assert(false &&{{$}}
+// CHECK-NEXT: {{^}}  |   ^~~~{{$}}
+// CHECK-NEXT: {{^}}5 | {{$}}
+// CHECK-NEXT: {{^}}6 |   true, "");{{$}}
+// CHECK-NEXT: {{^}}  |   {{$}}
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1243,7 +1243,7 @@
 // to produce easily machine parsable output.  Add a space before the
 // source line and the caret to make it trivial to tell the main diagnostic
 // line from what the user is intended to see.
-if (DiagOpts->ShowSourceRanges) {
+if (DiagOpts->ShowSourceRanges && !SourceLine.empty()) {
   SourceLine = ' ' + SourceLine;
   CaretLine = ' ' + CaretLine;
 }
@@ -1280,9 +1280,6 @@
 void TextDiagnostic::emitSnippet(StringRef SourceLine,
  unsigned MaxLineNoDisplayWidth,
  unsigned LineNo) {
-  if (SourceLine.empty())
-return;
-
   // Emit line number.
   if (MaxLineNoDisplayWidth > 0) {
 unsigned LineNoDisplayWidth = getNumDisplayWidth(LineNo);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c3c0774 - [Clang][C++20] Error out if parameter types of a defaulted comparion operator are not all the same.

2023-05-24 Thread Jens Massberg via cfe-commits

Author: Jens Massberg
Date: 2023-05-24T10:02:58+02:00
New Revision: c3c0774b1d6ef524de3a25e1f13828d2f9861aad

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

LOG: [Clang][C++20] Error out if parameter types of a defaulted comparion 
operator are not all the same.

This fixes #62880

Differential Revision: https://reviews.llvm.org/D151200

Added: 


Modified: 
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.compare.default/p1.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e2a1de9ee5be2..cbe4229b05d00 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -8626,8 +8626,7 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, 
FunctionDecl *FD,
   const ParmVarDecl *KnownParm = nullptr;
   for (const ParmVarDecl *Param : FD->parameters()) {
 QualType ParmTy = Param->getType();
-if (ParmTy->isDependentType())
-  continue;
+
 if (!KnownParm) {
   auto CTy = ParmTy;
   // Is it `T const &`?

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
index eadb5718780a3..e469e31e1f696 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -27,6 +27,16 @@ struct A {
 bool operator==(const A&) const = default; // expected-error {{comparison 
operator template cannot be defaulted}}
 };
 
+template struct D {
+  C i;
+  friend bool operator==(const D&, D) = default; // expected-error {{must have 
the same type}}
+  friend bool operator>(D, const D&) = default; // expected-error {{must have 
the same type}}
+  friend bool operator<(const D&, const D&) = default;
+  friend bool operator<=(D, D) = default;
+
+  bool operator!=(D) const = default; // expected-error {{invalid parameter 
type for defaulted equality comparison operator}}
+};
+
 template struct Dependent {
   using U = typename T::type;
   bool operator==(U) const = default; // expected-error {{found 'U'}}



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


[PATCH] D151200: [Clang][C++20] Error out if parameter types of a defaulted comparison operator aren't as expected.

2023-05-24 Thread Jens Massberg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc3c0774b1d6e: [Clang][C++20] Error out if parameter types of 
a defaulted comparion operator… (authored by massberg).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151200/new/

https://reviews.llvm.org/D151200

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p1.cpp


Index: clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -27,6 +27,16 @@
 bool operator==(const A&) const = default; // expected-error {{comparison 
operator template cannot be defaulted}}
 };
 
+template struct D {
+  C i;
+  friend bool operator==(const D&, D) = default; // expected-error {{must have 
the same type}}
+  friend bool operator>(D, const D&) = default; // expected-error {{must have 
the same type}}
+  friend bool operator<(const D&, const D&) = default;
+  friend bool operator<=(D, D) = default;
+
+  bool operator!=(D) const = default; // expected-error {{invalid parameter 
type for defaulted equality comparison operator}}
+};
+
 template struct Dependent {
   using U = typename T::type;
   bool operator==(U) const = default; // expected-error {{found 'U'}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -8626,8 +8626,7 @@
   const ParmVarDecl *KnownParm = nullptr;
   for (const ParmVarDecl *Param : FD->parameters()) {
 QualType ParmTy = Param->getType();
-if (ParmTy->isDependentType())
-  continue;
+
 if (!KnownParm) {
   auto CTy = ParmTy;
   // Is it `T const &`?


Index: clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -27,6 +27,16 @@
 bool operator==(const A&) const = default; // expected-error {{comparison operator template cannot be defaulted}}
 };
 
+template struct D {
+  C i;
+  friend bool operator==(const D&, D) = default; // expected-error {{must have the same type}}
+  friend bool operator>(D, const D&) = default; // expected-error {{must have the same type}}
+  friend bool operator<(const D&, const D&) = default;
+  friend bool operator<=(D, D) = default;
+
+  bool operator!=(D) const = default; // expected-error {{invalid parameter type for defaulted equality comparison operator}}
+};
+
 template struct Dependent {
   using U = typename T::type;
   bool operator==(U) const = default; // expected-error {{found 'U'}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -8626,8 +8626,7 @@
   const ParmVarDecl *KnownParm = nullptr;
   for (const ParmVarDecl *Param : FD->parameters()) {
 QualType ParmTy = Param->getType();
-if (ParmTy->isDependentType())
-  continue;
+
 if (!KnownParm) {
   auto CTy = ParmTy;
   // Is it `T const &`?
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151301: [clang][Diagnostics] Print empty lines in multiline snippets

2023-05-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/Frontend/TextDiagnostic.cpp:1246
 // line from what the user is intended to see.
-if (DiagOpts->ShowSourceRanges) {
+if (DiagOpts->ShowSourceRanges && !SourceLine.empty()) {
   SourceLine = ' ' + SourceLine;

This is a special case (and probably unneeded?), but otherwise we get 2 empty 
lines for an empty source line when we print source range info.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151301/new/

https://reviews.llvm.org/D151301

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


[PATCH] D151094: [clang] Implement P2564 "consteval must propagate up"

2023-05-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 525054.
cor3ntin added a comment.

Revert unrelated change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151094/new/

https://reviews.llvm.org/D151094

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/VTableBuilder.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/ScopeInfo.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -363,7 +363,7 @@
 
   consteval needs to propagate up
   https://wg21.link/P2564R3";>P2564R3 (DR)
-  No
+  Clang 17
 
 
   Lifetime extension in range-based for loops
Index: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -0,0 +1,152 @@
+// RUN: %clang_cc1 -std=c++2a -emit-llvm-only -Wno-unused-value %s -verify
+// RUN: %clang_cc1 -std=c++2b -emit-llvm-only -Wno-unused-value %s -verify
+
+consteval int id(int i) { return i; }
+constexpr char id(char c) { return c; }
+
+template 
+constexpr int f(T t) { // expected-note {{declared here}}
+return t + id(t);  // expected-note 2{{'f' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
+}
+
+namespace examples {
+
+auto a = &f; // ok, f is not an immediate function
+auto b = &f;  // expected-error {{cannot take address of immediate function 'f' outside of an immediate invocation}}
+
+static_assert(f(3) == 6); // ok
+
+template 
+constexpr int g(T t) {// g is not an immediate function
+return t + id(42);// because id(42) is already a constant
+}
+
+template 
+constexpr bool is_not(T t, F f) {
+return not f(t);
+}
+
+consteval bool is_even(int i) { return i % 2 == 0; }
+
+static_assert(is_not(5, is_even));
+
+int x = 0; // expected-note {{declared here}}
+
+template 
+constexpr T h(T t = id(x)) { // expected-note {{read of non-const variable 'x' is not allowed in a constant expression}} \
+ // expected-note {{'hh' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
+return t;
+}
+
+template 
+constexpr T hh() {   // hh is an immediate function
+return h();
+}
+
+int i = hh(); // expected-error {{call to immediate function 'examples::hh' is not a constant expression}} \
+   // expected-note {{in call to 'hh()'}}
+
+struct A {
+  int x;
+  int y = id(x);
+};
+
+template 
+constexpr int k(int) {
+  return A(42).y;
+}
+
+}
+
+namespace nested {
+
+template 
+constexpr int fdupe(T t) {
+return id(t);
+}
+
+struct a {
+  constexpr a(int) { }
+};
+
+a aa(fdupe((f(7;
+
+template 
+constexpr int foo(T t); // expected-note {{declared here}}
+
+a bb(f(foo(7))); // expected-error{{call to immediate function 'f' is not a constant expression}} \
+   // expected-note{{undefined function 'foo' cannot be used in a constant expression}}
+
+}
+
+namespace e2{
+template 
+constexpr int f(T t);
+auto a = &f;
+auto b = &f;
+}
+
+namespace forward_declare_constexpr{
+template 
+constexpr int f(T t);
+
+auto a = &f;
+auto b = &f;
+
+template 
+constexpr int f(T t) {
+return id(0);
+}
+}
+
+namespace forward_declare_consteval{
+template 
+constexpr int f(T t);  // expected-note {{'f' defined here}}
+
+auto a = &f;
+auto b = &f; // expected-error {{immediate function 'f' used before it is defined}} \
+  // expected-note {{in instantiation of function template specialization}}
+
+template 
+constexpr int f(T t) {
+return id(t); // expected-note {{'f' is an immediate function because its body contains a call to a consteval function 'id' and

[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-05-24 Thread Xi Ruoyao via Phabricator via cfe-commits
xry111 added a comment.

In D151298#4367349 , @wangleiat wrote:

> In D151298#4367225 , @xry111 wrote:
>
>> In D151298#4367215 , @wangleiat 
>> wrote:
>>
>>> In D151298#4367163 , @xry111 
>>> wrote:
>>>
 Blocking this as it's a deliberate decision made in D132285 
 .

 Is there any imperative reason we must really pass the empty struct?  The 
 C++ standard only treats struct {} as size 1 for the semantics of pointer 
 comparison.  While there is no pointers to registers, ignoring it in the 
 register calling convention will make no harm.

 And AFAIK it will be an undefined behavior attempting to (mis)use the 
 padding space of/after the empty struct to pass any information.
>>>
>>> Our current modifications are closer to the description of `Itanium C++ 
>>> ABI`, and we try to keep it consistent with the description of the calling 
>>> convention under `reasonable premise`.
>>
>> Hmm, could you provide a link to the section saying this in the Itanium C++ 
>> ABI?
>
> http://itanium-cxx-abi.github.io/cxx-abi/abi.html#empty-parameters
> http://itanium-cxx-abi.github.io/cxx-abi/abi.html#emptty-return-values
>
>> I see it has some words about passing or returning an empty class, but there 
>> seems no words about passing a class containing an empty class.
>
> It's possible that my understanding is incorrect. There is indeed no place to 
> see how an empty class is passed, just like there is no documentation on how 
> to pass `class A { class B { char c;};};`.

I think the paragraph means:

  class Empty {};
  int test(Empty empty, int a);

Then we should put `a` into `a1`, not `a0`.  And we are indeed doing so.

>> And for our own psABI, it's easier to simply reword it (making it similar to 
>> the RISC-V psABI about passing args with FPRs) instead of modifying both 
>> Clang and GCC (causing the code of Clang and GCC more nasty, and both 
>> compilers slower, and we'll need to add a -Wpsabi warning at least in GCC 
>> too).  And it already needs a reword considering empty arrays and zero-width 
>> bit-fields anyway.
>
> I'm sorry, I couldn't quite understand what you meant.

I mean now GCC and Clang have the same behavior, so it's easier to just 
document the behavior in our psABI doc instead of making both Clang and GCC 
rigidly following the interpretation of psABI (which is currently unclear about 
zero-sized fields now) anyway.

And the current behavior of GCC and Clang treating a class containing two 
floating-point members and some empty fields is same as RISC-V, so it's highly 
unlikely we are violating the C++ standard or IA64 C++ ABI (or the entire 
RISC-V ecosystem would be violating them).  The only issue is our psABI is 
unclear about empty fields, and the easiest way to solve the issue is revising 
the psABI (maybe, just "borrowing" some paragraphs from RISC-V psABI if there 
is no copyright issue).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151298/new/

https://reviews.llvm.org/D151298

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


[PATCH] D151307: [Clang][SVE2.1] Add svwhile (predicate-as-counter) builtins

2023-05-24 Thread Caroline via Phabricator via cfe-commits
CarolineConcatto created this revision.
Herald added subscribers: kristof.beyls, tschuett.
Herald added a project: All.
CarolineConcatto requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As described in: https://github.com/ARM-software/acle/pull/257

Patch by : David Sherwood 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151307

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_while_pn.c
  clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp

Index: clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
===
--- clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
+++ clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
@@ -49,6 +49,74 @@
   svpsel_lane_c64(svptrue_c64(), svptrue_b64(), 0, 2);  // expected-error {{argument value 2 is outside the valid range [0, 1]}}
 }
 
+svcount_t test_svwhile_pn(int64_t op1, int64_t op2) {
+  svwhilege_c8(op1, op2, 6);  // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilege_c16(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilege_c32(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilege_c64(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilegt_c8(op1, op2, 6);  // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilegt_c16(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilegt_c32(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilegt_c64(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilehi_c8(op1, op2, 6);  // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilehi_c16(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilehi_c32(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilehi_c64(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilehs_c8(op1, op2, 6);  // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilehs_c16(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilehs_c32(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilehs_c64(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilele_c8(op1, op2, 6);  // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilele_c16(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilele_c32(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilele_c64(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilelo_c8(op1, op2, 6);  // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilelo_c16(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilelo_c32(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilelo_c64(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilels_c8(op1, op2, 6);  // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilels_c16(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilels_c32(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilels_c64(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilelt_c8(op1, op2, 6);  // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilelt_c16(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilelt_c32(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+  svwhilelt_c64(op1, op2, 6); // expected-error {{argument value 6 is outside the valid range [2, 4]}}
+
+  svwhilege_c8(op1, op2, 3);  // expected-error {{argument should be a multiple of 2}}
+  svwhilege_c16(op1, op2, 3); // expected-error {{argument should be a multiple of 2}}
+  svwhilege_c32(op1, op2, 3); // expected-error {{argument should be a multiple of 2}}
+  svwhilege_c64(op1, op2, 3); // expected-error {{argument should be a multiple of 2}}
+  svwhilegt_c8(op1, op2, 3);  // expected-error {{argument should be a multiple of 2}}
+  svwhilegt_c16(op1, op2, 3); // expected-error {{argument should be a multiple of 2}}
+  svwhilegt_c32(op1, op2, 3); // expected-error {{argument should be a 

[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-05-24 Thread wanglei via Phabricator via cfe-commits
wangleiat added a comment.

> I think the paragraph means:
>
>   class Empty {};
>   int test(Empty empty, int a);
>
> Then we should put `a` into `a1`, not `a0`.  And we are indeed doing so.

yes. with this patch, `a` will be passed with `a1` register.

> I mean now GCC and Clang have the same behavior, so it's easier to just 
> document the behavior in our psABI doc instead of making both Clang and GCC 
> rigidly following the interpretation of psABI (which is currently unclear 
> about zero-sized fields now) anyway.
>
> And the current behavior of GCC and Clang treating a class containing two 
> floating-point members and some empty fields is same as RISC-V, so it's 
> highly unlikely we are violating the C++ standard or IA64 C++ ABI (or the 
> entire RISC-V ecosystem would be violating them).  The only issue is our 
> psABI is unclear about empty fields, and the easiest way to solve the issue 
> is revising the psABI (maybe, just "borrowing" some paragraphs from RISC-V 
> psABI if there is no copyright issue).

If we want to ignore empty structures, it is not enough to only modify psABI, 
because the current implementations of gcc and clang do not ignore empty 
structures in all cases. For example:

  struct { struct{}; int i; }; // in this case, the empty struct is not ignored.
  struct { struct{}; float f; }; // ignored.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151298/new/

https://reviews.llvm.org/D151298

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


[PATCH] D151308: -fsanitize=function: fix alignment fault on Arm targets.

2023-05-24 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham created this revision.
simon_tatham added reviewers: peter.smith, MaskRay, dmgreen.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
simon_tatham requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Function pointers are checked by loading a prefix structure from just
before the function's entry point. However, on Arm, the function
pointer is not always exactly equal to the address of the entry point,
because Thumb function pointers have the low bit set to tell the BX
instruction to enter them in Thumb state. So the generated code loads
from an odd address and suffers an alignment fault.

Fixed by clearing the low bit of the function pointer before
subtracting 8.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151308

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/ubsan-function.cpp


Index: clang/test/CodeGen/ubsan-function.cpp
===
--- clang/test/CodeGen/ubsan-function.cpp
+++ clang/test/CodeGen/ubsan-function.cpp
@@ -1,11 +1,15 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64_be-linux-gnu -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s
+// RUN: %clang_cc1 -triple arm-none-eabi -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s 
--check-prefixes=CHECK,ARM
 
 // CHECK: define{{.*}} void @_Z3funv() #0 !func_sanitize ![[FUNCSAN:.*]] {
 void fun() {}
 
 // CHECK-LABEL: define{{.*}} void @_Z6callerPFvvE(ptr noundef %f)
+// ARM:   ptrtoint ptr {{.*}} to i32, !nosanitize !5
+// ARM:   and i32 {{.*}}, -2, !nosanitize !5
+// ARM:   inttoptr i32 {{.*}} to ptr, !nosanitize !5
 // CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 0, !nosanitize
 // CHECK: load i32, ptr {{.*}}, align {{.*}}, !nosanitize
 // CHECK: icmp eq i32 {{.*}}, -1056584962, !nosanitize
@@ -16,7 +20,7 @@
 // CHECK: icmp eq i32 {{.*}}, -1522505972, !nosanitize
 // CHECK: br i1 {{.*}}, label %[[LABEL3:.*]], label %[[LABEL2:[^,]*]], 
{{.*}}!nosanitize
 // CHECK: [[LABEL2]]:
-// CHECK: call void @__ubsan_handle_function_type_mismatch_abort(ptr @[[#]], 
i64 %[[#]]) #[[#]], !nosanitize
+// CHECK: call void @__ubsan_handle_function_type_mismatch_abort(ptr @[[#]], 
{{i64|i32}} %[[#]]) #[[#]], !nosanitize
 // CHECK-NEXT: unreachable, !nosanitize
 // CHECK-EMPTY:
 // CHECK-NEXT: [[LABEL3]]:
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -5364,8 +5364,26 @@
 
   llvm::Value *CalleePtr = Callee.getFunctionPointer();
 
+  // On 32-bit Arm, the low bit of a function pointer indicates whether
+  // it's using the Arm or Thumb instruction set. The actual first
+  // instruction lives at the same address either way, so we must clear
+  // that low bit before using the function address to find the prefix
+  // structure.
+  //
+  // This applies to both Arm and Thumb target triples, because
+  // either one could be used in an interworking context where it
+  // might be passed function pointers of both types.
+  llvm::Value *AlignedCalleePtr;
+  if (CGM.getTriple().isARM() || CGM.getTriple().isThumb()) {
+  llvm::Value *CalleeAddress = Builder.CreatePtrToInt(CalleePtr, 
IntPtrTy);
+  llvm::Value *AlignedCalleeAddress = Builder.CreateAnd(CalleeAddress, 
llvm::ConstantInt::get(IntPtrTy, -2));
+  AlignedCalleePtr = Builder.CreateIntToPtr(AlignedCalleeAddress, 
CalleePtr->getType());
+  } else {
+  AlignedCalleePtr = CalleePtr;
+  }
+
   llvm::Value *CalleePrefixStruct = Builder.CreateBitCast(
-  CalleePtr, llvm::PointerType::getUnqual(PrefixStructTy));
+  AlignedCalleePtr, llvm::PointerType::getUnqual(PrefixStructTy));
   llvm::Value *CalleeSigPtr =
   Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, -1, 
0);
   llvm::Value *CalleeSig =


Index: clang/test/CodeGen/ubsan-function.cpp
===
--- clang/test/CodeGen/ubsan-function.cpp
+++ clang/test/CodeGen/ubsan-function.cpp
@@ -1,11 +1,15 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64_be-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s
+// RUN: %clang_cc1 -triple arm-none-eabi -emit-llvm -o - %s -fsanitize=function -fno-sanitize-

[PATCH] D151308: -fsanitize=function: fix alignment fault on Arm targets.

2023-05-24 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham added a comment.

I think this began going wrong as a result of D148573 
, which enabled `-fsanitize=function` on all 
targets, where previously it hadn't been running on Arm at all. But I'd rather 
make it work than turn it off again!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151308/new/

https://reviews.llvm.org/D151308

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


[PATCH] D151308: -fsanitize=function: fix alignment fault on Arm targets.

2023-05-24 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham updated this revision to Diff 525065.
simon_tatham added a comment.

(oops, forgot to clang-format)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151308/new/

https://reviews.llvm.org/D151308

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/ubsan-function.cpp


Index: clang/test/CodeGen/ubsan-function.cpp
===
--- clang/test/CodeGen/ubsan-function.cpp
+++ clang/test/CodeGen/ubsan-function.cpp
@@ -1,11 +1,15 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64_be-linux-gnu -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s
+// RUN: %clang_cc1 -triple arm-none-eabi -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s 
--check-prefixes=CHECK,ARM
 
 // CHECK: define{{.*}} void @_Z3funv() #0 !func_sanitize ![[FUNCSAN:.*]] {
 void fun() {}
 
 // CHECK-LABEL: define{{.*}} void @_Z6callerPFvvE(ptr noundef %f)
+// ARM:   ptrtoint ptr {{.*}} to i32, !nosanitize !5
+// ARM:   and i32 {{.*}}, -2, !nosanitize !5
+// ARM:   inttoptr i32 {{.*}} to ptr, !nosanitize !5
 // CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 0, !nosanitize
 // CHECK: load i32, ptr {{.*}}, align {{.*}}, !nosanitize
 // CHECK: icmp eq i32 {{.*}}, -1056584962, !nosanitize
@@ -16,7 +20,7 @@
 // CHECK: icmp eq i32 {{.*}}, -1522505972, !nosanitize
 // CHECK: br i1 {{.*}}, label %[[LABEL3:.*]], label %[[LABEL2:[^,]*]], 
{{.*}}!nosanitize
 // CHECK: [[LABEL2]]:
-// CHECK: call void @__ubsan_handle_function_type_mismatch_abort(ptr @[[#]], 
i64 %[[#]]) #[[#]], !nosanitize
+// CHECK: call void @__ubsan_handle_function_type_mismatch_abort(ptr @[[#]], 
{{i64|i32}} %[[#]]) #[[#]], !nosanitize
 // CHECK-NEXT: unreachable, !nosanitize
 // CHECK-EMPTY:
 // CHECK-NEXT: [[LABEL3]]:
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -5364,8 +5364,26 @@
 
   llvm::Value *CalleePtr = Callee.getFunctionPointer();
 
+  // On 32-bit Arm, the low bit of a function pointer indicates whether
+  // it's using the Arm or Thumb instruction set. The actual first
+  // instruction lives at the same address either way, so we must clear
+  // that low bit before using the function address to find the prefix
+  // structure.
+  //
+  // This applies to both Arm and Thumb target triples, because
+  // either one could be used in an interworking context where it
+  // might be passed function pointers of both types.
+  llvm::Value *AlignedCalleePtr;
+  if (CGM.getTriple().isARM() || CGM.getTriple().isThumb()) {
+  llvm::Value *CalleeAddress = Builder.CreatePtrToInt(CalleePtr, 
IntPtrTy);
+  llvm::Value *AlignedCalleeAddress = Builder.CreateAnd(CalleeAddress, 
llvm::ConstantInt::get(IntPtrTy, -2));
+  AlignedCalleePtr = Builder.CreateIntToPtr(AlignedCalleeAddress, 
CalleePtr->getType());
+  } else {
+  AlignedCalleePtr = CalleePtr;
+  }
+
   llvm::Value *CalleePrefixStruct = Builder.CreateBitCast(
-  CalleePtr, llvm::PointerType::getUnqual(PrefixStructTy));
+  AlignedCalleePtr, llvm::PointerType::getUnqual(PrefixStructTy));
   llvm::Value *CalleeSigPtr =
   Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, -1, 
0);
   llvm::Value *CalleeSig =


Index: clang/test/CodeGen/ubsan-function.cpp
===
--- clang/test/CodeGen/ubsan-function.cpp
+++ clang/test/CodeGen/ubsan-function.cpp
@@ -1,11 +1,15 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64_be-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s
+// RUN: %clang_cc1 -triple arm-none-eabi -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s --check-prefixes=CHECK,ARM
 
 // CHECK: define{{.*}} void @_Z3funv() #0 !func_sanitize ![[FUNCSAN:.*]] {
 void fun() {}
 
 // CHECK-LABEL: define{{.*}} void @_Z6callerPFvvE(ptr noundef %f)
+// ARM:   ptrtoint ptr {{.*}} to i32, !nosanitize !5
+// ARM:   and i32 {{.*}}, -2, !nosanitize !5
+// ARM:   inttoptr i32 {{.*}} to ptr, !nosanitize !5
 // CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 0, !nosanitize
 // CHECK: load i32, ptr {{.*}}, align {{.*}}, !nosanitize
 // CHECK: icmp eq i32 {{.*}}, -1056584962, !nosanitize
@@ -16,7 +20,7 @

[PATCH] D150843: [clang][Diagnostics] Refactor printableTextForNextCharacter

2023-05-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Frontend/TextDiagnostic.cpp:124-128
+  if (CharSize == 1 && llvm::isLegalUTF8Sequence(Begin, End) &&
+  llvm::sys::locale::isPrint(*Begin)) {
+++(*I);
+return std::make_pair(SmallString<16>(Begin, End), true);
+  }

tbaeder wrote:
> cor3ntin wrote:
> > this could be simplified : the common case for ascii could be just looking 
> > at `isPrint(*Begin);` (which implies  CharSize == 1 and  
> > llvm::isLegalUTF8Sequence(Begin, End))
> > So you could do it before computing CharSize
> This is not true in my testing fwiw.
```
const unsigned char *Begin = SourceLine.bytes_begin() + *I;

  // Fast path for the common ASCII case.
  if (*Begin < 0x80 && llvm::sys::locale::isPrint(*Begin)) {
++(*I);
return std::make_pair(SmallString<16>(Begin, Begin + 1), true);
  }
```
seems to work fine locally. Note that I'm not sure `*Begin` is always valid - 
it seems to be, but we might want an assert to check that SourceLine is not 
empty. 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150843/new/

https://reviews.llvm.org/D150843

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


[PATCH] D151145: Add disabled unittest reproducing TextProto formatting issue.

2023-05-24 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

Thank you! That's a bug in the raw string format manager.
This code effectively first looks for a matching top-level style, and if that's 
not found, then it tries to derive one via the RawFormat's BasedOnStyle:
https://github.com/llvm/llvm-project/blob/main/clang/lib/Format/ContinuationIndenter.cpp#L191-L201

This doesn't match the documentation of the BasedOnStyle field, which indicates 
that, if specified, it should take precedence:
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Format/Format.h#L3219-L3222

@Icantjuddle would you like to update this patch to fix the issue and enable 
your newly added tests?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151145/new/

https://reviews.llvm.org/D151145

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


[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-05-24 Thread Xi Ruoyao via Phabricator via cfe-commits
xry111 added a comment.

In D151298#4367458 , @wangleiat wrote:

>> I think the paragraph means:
>>
>>   class Empty {};
>>   int test(Empty empty, int a);
>>
>> Then we should put `a` into `a1`, not `a0`.  And we are indeed doing so.
>
> yes. with this patch, `a` will be passed with `a1` register.
>
>> I mean now GCC and Clang have the same behavior, so it's easier to just 
>> document the behavior in our psABI doc instead of making both Clang and GCC 
>> rigidly following the interpretation of psABI (which is currently unclear 
>> about zero-sized fields now) anyway.
>>
>> And the current behavior of GCC and Clang treating a class containing two 
>> floating-point members and some empty fields is same as RISC-V, so it's 
>> highly unlikely we are violating the C++ standard or IA64 C++ ABI (or the 
>> entire RISC-V ecosystem would be violating them).  The only issue is our 
>> psABI is unclear about empty fields, and the easiest way to solve the issue 
>> is revising the psABI (maybe, just "borrowing" some paragraphs from RISC-V 
>> psABI if there is no copyright issue).
>
> If we want to ignore empty structures, it is not enough to only modify psABI, 
> because the current implementations of gcc and clang do not ignore empty 
> structures in all cases. For example:
>
>   struct { struct{}; int i; }; // in this case, the empty struct is not 
> ignored.
>   struct { struct{}; float f; }; // ignored.

This is the same behavior as RISC-V.  While attempting to pass a struct through 
FPRs, the empty field is ignored.  But if passing through FPR does not work and 
it's passed through GPRs, the empty fields are not ignored:

https://godbolt.org/z/T1PKoxbYM

> Whether to ignore empty structures or not can affect the testing of gdb. 
> @seehearfeel knows more details.

I guess we should be able to fix it for GDB because they must have fixed it for 
RISC-V already.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151298/new/

https://reviews.llvm.org/D151298

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


[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-05-24 Thread Xi Ruoyao via Phabricator via cfe-commits
xry111 added a comment.

In D151298#4367496 , @xry111 wrote:

> In D151298#4367458 , @wangleiat 
> wrote:
>
>>> I think the paragraph means:
>>>
>>>   class Empty {};
>>>   int test(Empty empty, int a);
>>>
>>> Then we should put `a` into `a1`, not `a0`.  And we are indeed doing so.
>>
>> yes. with this patch, `a` will be passed with `a1` register.
>>
>>> I mean now GCC and Clang have the same behavior, so it's easier to just 
>>> document the behavior in our psABI doc instead of making both Clang and GCC 
>>> rigidly following the interpretation of psABI (which is currently unclear 
>>> about zero-sized fields now) anyway.
>>>
>>> And the current behavior of GCC and Clang treating a class containing two 
>>> floating-point members and some empty fields is same as RISC-V, so it's 
>>> highly unlikely we are violating the C++ standard or IA64 C++ ABI (or the 
>>> entire RISC-V ecosystem would be violating them).  The only issue is our 
>>> psABI is unclear about empty fields, and the easiest way to solve the issue 
>>> is revising the psABI (maybe, just "borrowing" some paragraphs from RISC-V 
>>> psABI if there is no copyright issue).
>>
>> If we want to ignore empty structures, it is not enough to only modify 
>> psABI, because the current implementations of gcc and clang do not ignore 
>> empty structures in all cases. For example:
>>
>>   struct { struct{}; int i; }; // in this case, the empty struct is not 
>> ignored.
>>   struct { struct{}; float f; }; // ignored.
>
> This is the same behavior as RISC-V.  While attempting to pass a struct 
> through FPRs, the empty field is ignored.  But if passing through FPR does 
> not work and it's passed through GPRs, the empty fields are not ignored:
>
> https://godbolt.org/z/T1PKoxbYM
>
>> Whether to ignore empty structures or not can affect the testing of gdb. 
>> @seehearfeel knows more details.
>
> I guess we should be able to fix it for GDB because they must have fixed it 
> for RISC-V already.

@seahearfeel: 
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9f0272f8548164b024ff9fd151686b2b904a5d59


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151298/new/

https://reviews.llvm.org/D151298

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


[PATCH] D150843: [clang][Diagnostics] Refactor printableTextForNextCharacter

2023-05-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/Frontend/TextDiagnostic.cpp:124-128
+  if (CharSize == 1 && llvm::isLegalUTF8Sequence(Begin, End) &&
+  llvm::sys::locale::isPrint(*Begin)) {
+++(*I);
+return std::make_pair(SmallString<16>(Begin, End), true);
+  }

cor3ntin wrote:
> tbaeder wrote:
> > cor3ntin wrote:
> > > this could be simplified : the common case for ascii could be just 
> > > looking at `isPrint(*Begin);` (which implies  CharSize == 1 and  
> > > llvm::isLegalUTF8Sequence(Begin, End))
> > > So you could do it before computing CharSize
> > This is not true in my testing fwiw.
> ```
> const unsigned char *Begin = SourceLine.bytes_begin() + *I;
> 
>   // Fast path for the common ASCII case.
>   if (*Begin < 0x80 && llvm::sys::locale::isPrint(*Begin)) {
> ++(*I);
> return std::make_pair(SmallString<16>(Begin, Begin + 1), true);
>   }
> ```
> seems to work fine locally. Note that I'm not sure `*Begin` is always valid - 
> it seems to be, but we might want an assert to check that SourceLine is not 
> empty. 
This function is only ever called in a `while (I < SourceLine.size())` loop. 
I've thought about refactoring this into a helper struct that keeps the index 
separate from the calling function to simplify callers.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150843/new/

https://reviews.llvm.org/D150843

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


[PATCH] D150843: [clang][Diagnostics] Refactor printableTextForNextCharacter

2023-05-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/Frontend/TextDiagnostic.cpp:124-128
+  if (CharSize == 1 && llvm::isLegalUTF8Sequence(Begin, End) &&
+  llvm::sys::locale::isPrint(*Begin)) {
+++(*I);
+return std::make_pair(SmallString<16>(Begin, End), true);
+  }

tbaeder wrote:
> cor3ntin wrote:
> > tbaeder wrote:
> > > cor3ntin wrote:
> > > > this could be simplified : the common case for ascii could be just 
> > > > looking at `isPrint(*Begin);` (which implies  CharSize == 1 and  
> > > > llvm::isLegalUTF8Sequence(Begin, End))
> > > > So you could do it before computing CharSize
> > > This is not true in my testing fwiw.
> > ```
> > const unsigned char *Begin = SourceLine.bytes_begin() + *I;
> > 
> >   // Fast path for the common ASCII case.
> >   if (*Begin < 0x80 && llvm::sys::locale::isPrint(*Begin)) {
> > ++(*I);
> > return std::make_pair(SmallString<16>(Begin, Begin + 1), true);
> >   }
> > ```
> > seems to work fine locally. Note that I'm not sure `*Begin` is always valid 
> > - it seems to be, but we might want an assert to check that SourceLine is 
> > not empty. 
> This function is only ever called in a `while (I < SourceLine.size())` loop. 
> I've thought about refactoring this into a helper struct that keeps the index 
> separate from the calling function to simplify callers.
Oh also, there are two asserts at the beginning of the function to ensure `I` 
is valid.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150843/new/

https://reviews.llvm.org/D150843

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


[PATCH] D151293: [clang][ExtractAPI] Refactor serializer to the CRTP

2023-05-24 Thread Daniel Grumberg via Phabricator via cfe-commits
dang requested changes to this revision.
dang added a comment.
This revision now requires changes to proceed.

Great start but there are still some rough edges to polish!




Comment at: clang/include/clang/ExtractAPI/Serialization/SerializerBase.h:19
 #include "clang/ExtractAPI/APIIgnoresList.h"
+#include "llvm/Support/JSON.h"
 #include "llvm/Support/raw_ostream.h"

This shouldn't be needed at this point.



Comment at: clang/include/clang/ExtractAPI/Serialization/SerializerBase.h:28-31
+struct APISetVisitorOption {
   /// Do not include unnecessary whitespaces to save space.
   bool Compact;
 };

This is very specific to SymbolGraphSerializer or at last to JSON.



Comment at: clang/include/clang/ExtractAPI/Serialization/SerializerBase.h:37
+  /// Traverse the API information to output to \p os.
+  void traverseAPISet(raw_ostream &os){};
+

This shouldn't be needed anymore.



Comment at: clang/include/clang/ExtractAPI/Serialization/SerializerBase.h:84
+for (const auto &Protocol : API.getObjCProtocols())
+  getDerived()->visitObjCContainerRecord(*Protocol.second);
+  }

This should visit some sort Protocol Records specifically. Likewise for 
interfaces.



Comment at: clang/include/clang/ExtractAPI/Serialization/SerializerBase.h:100
+  /// Visit a global variable record.
+  void visitGlobalVariableRecord(const GlobalVariableRecord &Record);
+

This should have a default implementation.



Comment at: clang/include/clang/ExtractAPI/Serialization/SerializerBase.h:138
 protected:
-  APISerializer(const APISet &API, const APIIgnoresList &IgnoresList,
-APISerializerOption Options = {})
+  APISetVisitor(const APISet &API, const APIIgnoresList &IgnoresList,
+APISetVisitorOption Options = {})

I think that `APIIgnoresList` Should be pushed down into the 
SymbolGraphSerializer.



Comment at: clang/include/clang/ExtractAPI/Serialization/SerializerBase.h:142
 
-  virtual ~APISerializer() = default;
+  virtual ~APISetVisitor() = default;
+  Derived *getDerived() { return static_cast(this); };

Don't need a virtual destructor anymore.



Comment at: 
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h:12
 ///
-/// Implement an APISerializer for the Symbol Graph format for ExtractAPI.
+/// Implement an APISetVisitor for the Symbol Graph format for ExtractAPI.
 /// See https://github.com/apple/swift-docc-symbolkit.





Comment at: 
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h:94
   /// Just serialize the currently recorded objects in Symbol Graph format.
-  Object serializeCurrentGraph();
+  Object visitCurrentGraph();
 

I think these should still be called serializeXXX as they aren't part of the 
visitation interface and are very specific to the symbol graph format.



Comment at: 
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h:129
   template 
-  void serializeMembers(const APIRecord &Record,
-const SmallVector> &Members);
+  void visitMembers(const APIRecord &Record,
+const SmallVector> &Members);

I think we shouldn't need to have this method. APISetVisitor should handle 
calling the relevant visitMethods for the members.



Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:221
 /// references, and the interface language name.
-Object serializeIdentifier(const APIRecord &Record, Language Lang) {
+Object visitIdentifier(const APIRecord &Record, Language Lang) {
   Object Identifier;

I think all these helper methods for serializing specific chunks of symbol 
graphs should still be names serialize


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151293/new/

https://reviews.llvm.org/D151293

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


[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-05-24 Thread wanglei via Phabricator via cfe-commits
wangleiat added a comment.

>>> If we want to ignore empty structures, it is not enough to only modify 
>>> psABI, because the current implementations of gcc and clang do not ignore 
>>> empty structures in all cases. For example:
>>>
>>>   struct { struct{}; int i; }; // in this case, the empty struct is not 
>>> ignored.
>>>   struct { struct{}; float f; }; // ignored.
>>
>> This is the same behavior as RISC-V.  While attempting to pass a struct 
>> through FPRs, the empty field is ignored.  But if passing through FPR does 
>> not work and it's passed through GPRs, the empty fields are not ignored:

Yes, but our psABI still differs from RISC-V in the description of parameter 
passing, and it would be better to have consistent behavior regardless of 
whether there are floating points or not.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151298/new/

https://reviews.llvm.org/D151298

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


[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-05-24 Thread Xi Ruoyao via Phabricator via cfe-commits
xry111 added a comment.

In D151298#4367620 , @wangleiat wrote:

 If we want to ignore empty structures, it is not enough to only modify 
 psABI, because the current implementations of gcc and clang do not ignore 
 empty structures in all cases. For example:

   struct { struct{}; int i; }; // in this case, the empty struct is not 
 ignored.
   struct { struct{}; float f; }; // ignored.
>>>
>>> This is the same behavior as RISC-V.  While attempting to pass a struct 
>>> through FPRs, the empty field is ignored.  But if passing through FPR does 
>>> not work and it's passed through GPRs, the empty fields are not ignored:
>
> Yes, but our psABI still differs from RISC-V in the description of parameter 
> passing, and it would be better to have consistent behavior regardless of 
> whether there are floating points or not.

But it's easier to just modify the text of the ABI doc, in order to avoid an 
ABI incompatibility between different GCC of Clang versions (as GCC and Clang 
are only C++ compilers supporting LoongArch now).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151298/new/

https://reviews.llvm.org/D151298

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


[PATCH] D149444: [ARM] Allow codegen for Armv6m eXecute-Only (XO) sections

2023-05-24 Thread Ties Stuij via Phabricator via cfe-commits
stuij updated this revision to Diff 525079.
stuij added a comment.

addressed review comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149444/new/

https://reviews.llvm.org/D149444

Files:
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/test/Driver/arm-execute-only.c
  llvm/lib/Target/ARM/ARMSubtarget.cpp


Index: llvm/lib/Target/ARM/ARMSubtarget.cpp
===
--- llvm/lib/Target/ARM/ARMSubtarget.cpp
+++ llvm/lib/Target/ARM/ARMSubtarget.cpp
@@ -187,10 +187,12 @@
   // Assert this for now to make the change obvious.
   assert(hasV6T2Ops() || !hasThumb2());
 
-  // Execute only support requires movt support
   if (genExecuteOnly()) {
-NoMovt = false;
-assert(hasV8MBaselineOps() && "Cannot generate execute-only code for this 
target");
+// Execute only support for >= v8-M Baseline requires movt support
+if (hasV8MBaselineOps())
+  NoMovt = false;
+if (!hasV6MOps())
+  llvm_unreachable("Cannot generate execute-only code for this target");
   }
 
   // Keep a pointer to static instruction cost data for the specified CPU.
Index: clang/test/Driver/arm-execute-only.c
===
--- clang/test/Driver/arm-execute-only.c
+++ clang/test/Driver/arm-execute-only.c
@@ -1,6 +1,11 @@
-// RUN: not %clang -c -target thumbv6m-eabi -mexecute-only %s 2>&1 | \
+// RUN: %clang -c -target thumbv6m-eabi -mexecute-only %s 2>&1 | \
+// RUN:   FileCheck -allow-empty --check-prefix CHECK-THIS %s
+// CHECK-THIS-NOT: warning:
+// CHECK-THIS-NOT: error:
+
+// RUN: not %clang -c -target thumbv6-eabi -mexecute-only %s 2>&1 |\
 // RUN:   FileCheck --check-prefix CHECK-EXECUTE-ONLY-NOT-SUPPORTED %s
-// CHECK-EXECUTE-ONLY-NOT-SUPPORTED: error: execute only is not supported for 
the thumbv6m sub-architecture
+// CHECK-EXECUTE-ONLY-NOT-SUPPORTED: error: execute only is not supported for 
the armv6 sub-architecture
 
 // RUN: not %clang -target armv8m.main-eabi -mexecute-only -mno-movt %s 2>&1 \
 // RUN:| FileCheck %s -check-prefix CHECK-EXECUTE-ONLY-NO-MOVT
@@ -11,7 +16,7 @@
 // CHECK-NO-EXECUTE-ONLY-ASM: warning: argument unused during compilation: 
'-mexecute-only'
 
 // -mpure-code flag for GCC compatibility
-// RUN: not %clang -c -target thumbv6m-eabi -mpure-code %s 2>&1 | \
+// RUN: not %clang -c -target armv6-eabi -mpure-code %s 2>&1 | \
 // RUN:   FileCheck --check-prefix CHECK-EXECUTE-ONLY-NOT-SUPPORTED %s
 
 // RUN: not %clang -target armv8m.main-eabi -mpure-code -mno-movt %s 2>&1 \
Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp
===
--- clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -790,7 +790,8 @@
 if (Arg *A = Args.getLastArg(options::OPT_mexecute_only, 
options::OPT_mno_execute_only)) {
   if (A->getOption().matches(options::OPT_mexecute_only)) {
 if (getARMSubArchVersionNumber(Triple) < 7 &&
-llvm::ARM::parseArch(Triple.getArchName()) != 
llvm::ARM::ArchKind::ARMV6T2)
+llvm::ARM::parseArch(Triple.getArchName()) != 
llvm::ARM::ArchKind::ARMV6T2 &&
+ llvm::ARM::parseArch(Triple.getArchName()) != 
llvm::ARM::ArchKind::ARMV6M)
   D.Diag(diag::err_target_unsupported_execute_only) << 
Triple.getArchName();
 else if (Arg *B = Args.getLastArg(options::OPT_mno_movt))
   D.Diag(diag::err_opt_not_valid_with_opt)


Index: llvm/lib/Target/ARM/ARMSubtarget.cpp
===
--- llvm/lib/Target/ARM/ARMSubtarget.cpp
+++ llvm/lib/Target/ARM/ARMSubtarget.cpp
@@ -187,10 +187,12 @@
   // Assert this for now to make the change obvious.
   assert(hasV6T2Ops() || !hasThumb2());
 
-  // Execute only support requires movt support
   if (genExecuteOnly()) {
-NoMovt = false;
-assert(hasV8MBaselineOps() && "Cannot generate execute-only code for this target");
+// Execute only support for >= v8-M Baseline requires movt support
+if (hasV8MBaselineOps())
+  NoMovt = false;
+if (!hasV6MOps())
+  llvm_unreachable("Cannot generate execute-only code for this target");
   }
 
   // Keep a pointer to static instruction cost data for the specified CPU.
Index: clang/test/Driver/arm-execute-only.c
===
--- clang/test/Driver/arm-execute-only.c
+++ clang/test/Driver/arm-execute-only.c
@@ -1,6 +1,11 @@
-// RUN: not %clang -c -target thumbv6m-eabi -mexecute-only %s 2>&1 | \
+// RUN: %clang -c -target thumbv6m-eabi -mexecute-only %s 2>&1 | \
+// RUN:   FileCheck -allow-empty --check-prefix CHECK-THIS %s
+// CHECK-THIS-NOT: warning:
+// CHECK-THIS-NOT: error:
+
+// RUN: not %clang -c -target thumbv6-eabi -mexecute-only %s 2>&1 |\
 // RUN:   FileCheck --check-prefix CHECK-EXECUTE-ONLY-NOT-SUPPORTED %s
-// CHECK-EXECUTE-ONLY-NOT-SUPPORTED: error:

[PATCH] D149444: [ARM] Allow codegen for Armv6m eXecute-Only (XO) sections

2023-05-24 Thread Ties Stuij via Phabricator via cfe-commits
stuij added inline comments.



Comment at: llvm/lib/Target/ARM/ARMSubtarget.cpp:194
+  NoMovt = false;
+assert(hasV6MOps() && "Cannot generate execute-only code for this target");
   }

tschuett wrote:
> What happens in release mode? At the top you now claim that ARMV6M is 
> supported. Could hasV6MOps() silently return false?
This should really be caught by the frontend, but yes, I'm not sure why we use 
assert so often in this kind of code instead of unreachable. Changed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149444/new/

https://reviews.llvm.org/D149444

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


[PATCH] D150427: [AMDGPU] Non hostcall printf support for HIP

2023-05-24 Thread Vikram Hegde via Phabricator via cfe-commits
vikramRH updated this revision to Diff 525082.
vikramRH added a comment.

Handled review comments and rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150427/new/

https://reviews.llvm.org/D150427

Files:
  clang/include/clang/Basic/TargetOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenHIP/printf_nonhostcall.cpp
  clang/test/Driver/hip-options.hip
  llvm/include/llvm/Transforms/Utils/AMDGPUEmitPrintf.h
  llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp

Index: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
===
--- llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
+++ llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
@@ -17,6 +17,9 @@
 #include "llvm/Transforms/Utils/AMDGPUEmitPrintf.h"
 #include "llvm/ADT/SparseBitVector.h"
 #include "llvm/Analysis/ValueTracking.h"
+#include "llvm/Support/DataExtractor.h"
+#include "llvm/Support/MD5.h"
+#include "llvm/Support/MathExtras.h"
 
 using namespace llvm;
 
@@ -179,11 +182,7 @@
 
 // Scan the format string to locate all specifiers, and mark the ones that
 // specify a string, i.e, the "%s" specifier with optional '*' characters.
-static void locateCStrings(SparseBitVector<8> &BV, Value *Fmt) {
-  StringRef Str;
-  if (!getConstantStringInfo(Fmt, Str) || Str.empty())
-return;
-
+static void locateCStrings(SparseBitVector<8> &BV, StringRef Str) {
   static const char ConvSpecifiers[] = "diouxXfFeEgGaAcspn";
   size_t SpecPos = 0;
   // Skip the first argument, the format string.
@@ -207,14 +206,298 @@
   }
 }
 
-Value *llvm::emitAMDGPUPrintfCall(IRBuilder<> &Builder,
-  ArrayRef Args) {
+// helper struct to package the string related data
+struct StringData {
+  std::string Str = "";
+  bool isConst = true;
+  Value *RealSize = nullptr;
+  Value *AlignedSize = nullptr;
+
+  StringData(std::string str, bool IC, Value *RS, Value *AS)
+  : Str(str), isConst(IC), RealSize(RS), AlignedSize(AS) {}
+};
+
+// Calculates frame size required for current printf expansion and allocates
+// space on printf buffer. Printf frame includes following contents
+// [ ControlDWord , format string/Hash , Arguments (each aligned to 8 byte) ]
+static Value *callBufferedPrintfStart(
+IRBuilder<> &Builder, ArrayRef &Args, Value *Fmt,
+bool isConstFmtStr, SparseBitVector<8> &SpecIsCString,
+SmallVectorImpl &StringContents, Value *&ArgSize) {
+  Value *NonConstStrLen = nullptr;
+
+  // First 4 bytes to be reserved for control dword
+  size_t BufSize = 4;
+  if (isConstFmtStr)
+// First 8 bytes of MD5 hash
+BufSize += 8;
+  else {
+auto LenWithNull = getStrlenWithNull(Builder, Fmt);
+
+// Align the computed length to next 8 byte boundary
+auto TempAdd = Builder.CreateAdd(
+LenWithNull, ConstantInt::get(LenWithNull->getType(), 7U));
+NonConstStrLen = Builder.CreateAnd(
+TempAdd, ConstantInt::get(LenWithNull->getType(), ~7U));
+
+StringContents.push_back(
+StringData("", false, LenWithNull, NonConstStrLen));
+  }
+
+  for (size_t i = 1; i < Args.size(); i++) {
+if (SpecIsCString.test(i)) {
+  StringRef ArgStr;
+  if (getConstantStringInfo(Args[i], ArgStr)) {
+auto alignedLen = alignTo(ArgStr.size() + 1, 8);
+StringContents.push_back(
+StringData((ArgStr.str() + '\0'), /*isConst*/ true,
+   /*RealSize*/ nullptr, /*AlignedSize*/ nullptr));
+BufSize += alignedLen;
+  } else {
+auto LenWithNull = getStrlenWithNull(Builder, Args[i]);
+
+// Align the computed length to next 8 byte boundary
+auto TempAdd = Builder.CreateAdd(
+LenWithNull, ConstantInt::get(LenWithNull->getType(), 7U));
+auto LenWithNullAligned = Builder.CreateAnd(
+TempAdd, ConstantInt::get(LenWithNull->getType(), ~7U));
+
+if (NonConstStrLen) {
+  auto Val = Builder.CreateAdd(LenWithNullAligned, NonConstStrLen,
+   "cumulativeAdd");
+  NonConstStrLen = Val;
+} else
+  NonConstStrLen = LenWithNullAligned;
+
+StringContents.push_back(
+StringData("", false, LenWithNull, LenWithNullAligned));
+  }
+} else
+  // We end up expanding non string arguments to 8 bytes
+  BufSize += 8;
+  }
+
+  // calculate final size value to be passed to printf_alloc
+  Value *SizeToReserve = ConstantInt::get(Builder.getInt64Ty(), BufSize, false);
+  SmallVector Alloc_args;
+  if (NonConstStrLen)
+SizeToReserve = Builder.CreateAdd(NonConstStrLen, SizeToReserve);
+
+  ArgSize = Builder.CreateTrunc(SizeToReserve, Builder.getInt32Ty());
+  Alloc_args.push_back(ArgSize);
+
+  // call the printf_alloc function
+  AttributeList Attr = AttributeList::get(
+  Builder.getContext(), AttributeList::FunctionIndex, Attribut

[PATCH] D151308: -fsanitize=function: fix alignment fault on Arm targets.

2023-05-24 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham updated this revision to Diff 525084.
simon_tatham added a comment.

How embarrassing. _Really_ upload the clang-formatted version this time. Sorry 
for the noise.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151308/new/

https://reviews.llvm.org/D151308

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/ubsan-function.cpp


Index: clang/test/CodeGen/ubsan-function.cpp
===
--- clang/test/CodeGen/ubsan-function.cpp
+++ clang/test/CodeGen/ubsan-function.cpp
@@ -1,11 +1,15 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64_be-linux-gnu -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s
+// RUN: %clang_cc1 -triple arm-none-eabi -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s 
--check-prefixes=CHECK,ARM
 
 // CHECK: define{{.*}} void @_Z3funv() #0 !func_sanitize ![[FUNCSAN:.*]] {
 void fun() {}
 
 // CHECK-LABEL: define{{.*}} void @_Z6callerPFvvE(ptr noundef %f)
+// ARM:   ptrtoint ptr {{.*}} to i32, !nosanitize !5
+// ARM:   and i32 {{.*}}, -2, !nosanitize !5
+// ARM:   inttoptr i32 {{.*}} to ptr, !nosanitize !5
 // CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 0, !nosanitize
 // CHECK: load i32, ptr {{.*}}, align {{.*}}, !nosanitize
 // CHECK: icmp eq i32 {{.*}}, -1056584962, !nosanitize
@@ -16,7 +20,7 @@
 // CHECK: icmp eq i32 {{.*}}, -1522505972, !nosanitize
 // CHECK: br i1 {{.*}}, label %[[LABEL3:.*]], label %[[LABEL2:[^,]*]], 
{{.*}}!nosanitize
 // CHECK: [[LABEL2]]:
-// CHECK: call void @__ubsan_handle_function_type_mismatch_abort(ptr @[[#]], 
i64 %[[#]]) #[[#]], !nosanitize
+// CHECK: call void @__ubsan_handle_function_type_mismatch_abort(ptr @[[#]], 
{{i64|i32}} %[[#]]) #[[#]], !nosanitize
 // CHECK-NEXT: unreachable, !nosanitize
 // CHECK-EMPTY:
 // CHECK-NEXT: [[LABEL3]]:
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -5364,8 +5364,29 @@
 
   llvm::Value *CalleePtr = Callee.getFunctionPointer();
 
+  // On 32-bit Arm, the low bit of a function pointer indicates whether
+  // it's using the Arm or Thumb instruction set. The actual first
+  // instruction lives at the same address either way, so we must clear
+  // that low bit before using the function address to find the prefix
+  // structure.
+  //
+  // This applies to both Arm and Thumb target triples, because
+  // either one could be used in an interworking context where it
+  // might be passed function pointers of both types.
+  llvm::Value *AlignedCalleePtr;
+  if (CGM.getTriple().isARM() || CGM.getTriple().isThumb()) {
+llvm::Value *CalleeAddress =
+Builder.CreatePtrToInt(CalleePtr, IntPtrTy);
+llvm::Value *AlignedCalleeAddress = Builder.CreateAnd(
+CalleeAddress, llvm::ConstantInt::get(IntPtrTy, -2));
+AlignedCalleePtr =
+Builder.CreateIntToPtr(AlignedCalleeAddress, CalleePtr->getType());
+  } else {
+AlignedCalleePtr = CalleePtr;
+  }
+
   llvm::Value *CalleePrefixStruct = Builder.CreateBitCast(
-  CalleePtr, llvm::PointerType::getUnqual(PrefixStructTy));
+  AlignedCalleePtr, llvm::PointerType::getUnqual(PrefixStructTy));
   llvm::Value *CalleeSigPtr =
   Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, -1, 
0);
   llvm::Value *CalleeSig =


Index: clang/test/CodeGen/ubsan-function.cpp
===
--- clang/test/CodeGen/ubsan-function.cpp
+++ clang/test/CodeGen/ubsan-function.cpp
@@ -1,11 +1,15 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64_be-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s
+// RUN: %clang_cc1 -triple arm-none-eabi -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s --check-prefixes=CHECK,ARM
 
 // CHECK: define{{.*}} void @_Z3funv() #0 !func_sanitize ![[FUNCSAN:.*]] {
 void fun() {}
 
 // CHECK-LABEL: define{{.*}} void @_Z6callerPFvvE(ptr noundef %f)
+// ARM:   ptrtoint ptr {{.*}} to i32, !nosanitize !5
+// ARM:   and i32 {{.*}}, -2, !nosanitize !5
+// ARM:   inttoptr i32 {{.*}} to ptr, !nosanitize !5
 // CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 0, !nosanitize
 // CHECK: load i32, ptr {{.*}}, align

[PATCH] D151308: -fsanitize=function: fix alignment fault on Arm targets.

2023-05-24 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

This looks good to me. Will be worth waiting for a day to give the US time zone 
time to leave any comments.

I note that this is also broken in -fsanitize=kcfi [*] 
(https://reviews.llvm.org/D135411) although fixing that is a separate patch. 
Would you be able to raise a github issue to cover that?

As an end-to-end example for:

  typedef int Fptr(void);
  
  // pf could be Arm (bit 0 clear) or Thumb (bit 0 set)
  int f(Fptr* pf) {
return pf();
  }

This generates:

  f:
  .fnstart
  @ %bb.0:@ %entry
  push{r4, lr}
  mov r3, r0
  bic r0, r0, #1
  movwr2, #51966
  ldr r1, [r0, #-8]
  movtr2, #49413
  cmp r1, r2
  bne .LBB0_2
  @ %bb.1:@ %typecheck
  ldr r0, [r0, #-4]
  movwr1, #50598
  movtr1, #14001
  cmp r0, r1
  bne .LBB0_3
  .LBB0_2:@ %cont1
  pop.w   {r4, lr}
  bx  r3

Which gets the address of the signature and type correct, while preserving the 
thumb bit on the register used for the indirect branch.

-fsanitize=kcfi output is not correct for a Thumb destination:

  f:
  .fnstart
  // r0 will have thumb bit set if destination thumb
  ldr r1, [r0, #-4]
  movwr2, #50598
  movtr2, #14001
  cmp r1, r2
  bne .LBB0_2
  bx  r0
  .LBB0_2:
  .inst   0xe7ffdefe


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151308/new/

https://reviews.llvm.org/D151308

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


[PATCH] D150843: [clang][Diagnostics] Refactor printableTextForNextCharacter

2023-05-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 525094.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150843/new/

https://reviews.llvm.org/D150843

Files:
  clang/lib/Frontend/TextDiagnostic.cpp

Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -96,68 +96,74 @@
 /// \return pair(printable text, 'true' iff original text was printable)
 ///
 static std::pair, bool>
-printableTextForNextCharacter(StringRef SourceLine, size_t *i,
+printableTextForNextCharacter(StringRef SourceLine, size_t *I,
   unsigned TabStop) {
-  assert(i && "i must not be null");
-  assert(*i expandedTab;
-expandedTab.assign(NumSpaces, ' ');
-return std::make_pair(expandedTab, true);
+SmallString<16> ExpandedTab;
+ExpandedTab.assign(NumSpaces, ' ');
+return std::make_pair(ExpandedTab, true);
   }
 
-  unsigned char const *begin, *end;
-  begin = reinterpret_cast(&*(SourceLine.begin() + *i));
-  end = begin + (SourceLine.size() - *i);
-
-  if (llvm::isLegalUTF8Sequence(begin, end)) {
-llvm::UTF32 c;
-llvm::UTF32 *cptr = &c;
-unsigned char const *original_begin = begin;
-unsigned char const *cp_end =
-begin + llvm::getNumBytesForUTF8(SourceLine[*i]);
-
-llvm::ConversionResult res = llvm::ConvertUTF8toUTF32(
-&begin, cp_end, &cptr, cptr + 1, llvm::strictConversion);
-(void)res;
-assert(llvm::conversionOK == res);
-assert(0 < begin-original_begin
-   && "we must be further along in the string now");
-*i += begin-original_begin;
-
-if (!llvm::sys::locale::isPrint(c)) {
-  // If next character is valid UTF-8, but not printable
-  SmallString<16> expandedCP("");
-  while (c) {
-expandedCP.insert(expandedCP.begin()+3, llvm::hexdigit(c%16));
-c/=16;
-  }
-  while (expandedCP.size() < 8)
-expandedCP.insert(expandedCP.begin()+3, llvm::hexdigit(0));
-  return std::make_pair(expandedCP, false);
-}
-
-// If next character is valid UTF-8, and printable
-return std::make_pair(SmallString<16>(original_begin, cp_end), true);
+  const unsigned char *Begin = SourceLine.bytes_begin() + *I;
 
+  // Fast path for the common ASCII case.
+  if (*Begin < 0x80 && llvm::sys::locale::isPrint(*Begin)) {
+++(*I);
+return std::make_pair(SmallString<16>(Begin, Begin + 1), true);
+  }
+  unsigned CharSize = llvm::getNumBytesForUTF8(*Begin);
+  const unsigned char *End = Begin + CharSize;
+
+  // We now know that the next character is a multi-byte character.
+  // Convert it to UTF32 and check if it's printable.
+  if (End <= SourceLine.bytes_end() && llvm::isLegalUTF8Sequence(Begin, End)) {
+llvm::UTF32 C;
+llvm::UTF32 *CPtr = &C;
+
+// Begin and end before conversion.
+unsigned char const *OriginalBegin = Begin;
+llvm::ConversionResult Res = llvm::ConvertUTF8toUTF32(
+&Begin, End, &CPtr, CPtr + 1, llvm::strictConversion);
+(void)Res;
+assert(Res == llvm::conversionOK);
+assert(OriginalBegin < Begin);
+assert((Begin - OriginalBegin) == CharSize);
+
+(*I) += (Begin - OriginalBegin);
+
+// Valid, multi-byte, printable UTF8 character.
+if (llvm::sys::locale::isPrint(C))
+  return std::make_pair(SmallString<16>(OriginalBegin, End), true);
+
+// Valid but not printable.
+SmallString<16> Str("");
+while (C) {
+  Str.insert(Str.begin() + 3, llvm::hexdigit(C % 16));
+  C /= 16;
+}
+while (Str.size() < 8)
+  Str.insert(Str.begin() + 3, llvm::hexdigit(0));
+return std::make_pair(Str, false);
   }
 
-  // If next byte is not valid UTF-8 (and therefore not printable)
-  SmallString<16> expandedByte("");
-  unsigned char byte = SourceLine[*i];
-  expandedByte[1] = llvm::hexdigit(byte / 16);
-  expandedByte[2] = llvm::hexdigit(byte % 16);
-  ++(*i);
-  return std::make_pair(expandedByte, false);
+  // Otherwise, not printable since it's not valid UTF8.
+  SmallString<16> ExpandedByte("");
+  unsigned char Byte = SourceLine[*I];
+  ExpandedByte[1] = llvm::hexdigit(Byte / 16);
+  ExpandedByte[2] = llvm::hexdigit(Byte % 16);
+  ++(*I);
+  return std::make_pair(ExpandedByte, false);
 }
 
 static void expandTabs(std::string &SourceLine, unsigned TabStop) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151308: -fsanitize=function: fix alignment fault on Arm targets.

2023-05-24 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:5380-5381
+Builder.CreatePtrToInt(CalleePtr, IntPtrTy);
+llvm::Value *AlignedCalleeAddress = Builder.CreateAnd(
+CalleeAddress, llvm::ConstantInt::get(IntPtrTy, -2));
+AlignedCalleePtr =

I think this line could be more readable. I suggest defining Mask separately 
and using `~1` instead of `-2`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151308/new/

https://reviews.llvm.org/D151308

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


[PATCH] D150670: [WebAssembly] Disable generation of fshl/fshr for rotates

2023-05-24 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

In D150670#4352094 , @craig.topper 
wrote:

>> Preventing the simplification means adding target specific code in 
>> instcombine which seems even worse than adding it here given as @dschuff 
>> pointed out, there's precedent with x86.
>
> How harmful is it to avoid breaking rotate patterns even if the target 
> doesn't support rotate?

Hi Craig, I thought initially your question was for Nikita but it's apparently 
for me. I am sorry but I am not sure I understand your question. Could you 
please rephrase?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150670/new/

https://reviews.llvm.org/D150670

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


[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-05-24 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

FYI, in the matching GCC patch discussion 
 it was 
suggested that such a treatment wouldn't be necessary in principle.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151298/new/

https://reviews.llvm.org/D151298

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


[PATCH] D151315: [clangd] Add a switch to specify a default clangd configuration file

2023-05-24 Thread Thilo Vörtler via Phabricator via cfe-commits
voertler created this revision.
voertler added reviewers: dgoldman, kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
voertler requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This patch allows it to set a default configuration as discussed in issue 
https://github.com/clangd/clangd/issues/845 by adding a startup option 
--default-config.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151315

Files:
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -317,7 +317,6 @@
 RetiredFlag InlayHints("inlay-hints");
 RetiredFlag FoldingRanges("folding-ranges");
 
-
 opt LimitResults{
 "limit-results",
 cat(Features),
@@ -497,7 +496,8 @@
 desc(
 "Read user and project configuration from YAML files.\n"
 "Project config is from a .clangd file in the project directory.\n"
-"User config is from clangd/config.yaml in the following 
directories:\n"
+"User config is from clangd/config.yaml in the following directories 
\n"
+"(unless specified with --default-config):\n"
 "\tWindows: %USERPROFILE%\\AppData\\Local\n"
 "\tMac OS: ~/Library/Preferences/\n"
 "\tOthers: $XDG_CONFIG_HOME, usually ~/.config\n"
@@ -505,6 +505,15 @@
 init(true),
 };
 
+opt DefaultConfig{
+"default-config",
+cat(Misc),
+desc("Path to a default clangd configuration file. A clangd user and "
+ "project configuration has a higher priority (requires "
+ "--enable-config) "),
+init(""),
+};
+
 opt UseDirtyHeaders{"use-dirty-headers", cat(Misc),
   desc("Use files open in the editor when parsing "
"headers instead of reading from the disk"),
@@ -945,6 +954,21 @@
 } else {
   elog("Couldn't determine user config file, not loading");
 }
+if (DefaultConfig.getNumOccurrences()) {
+  llvm::SmallString<256> DefaultConfigPath;
+  if (auto Error = llvm::sys::fs::real_path(
+  DefaultConfig, DefaultConfigPath, /*expand_tilde=*/true)) {
+elog("Couldn't determine default config file {0}: {1} , not loading",
+ DefaultConfig, Error.message());
+  } else {
+vlog("Default config file is {0}", DefaultConfigPath);
+// Give lowest priority to default config 
+ProviderStack.insert(
+ProviderStack.begin(),
+config::Provider::fromYAMLFile(DefaultConfigPath, /*Directory=*/"",
+   TFS, /*Trusted=*/true));
+  }
+}
   }
   ProviderStack.push_back(std::make_unique());
   std::vector ProviderPointers;


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -317,7 +317,6 @@
 RetiredFlag InlayHints("inlay-hints");
 RetiredFlag FoldingRanges("folding-ranges");
 
-
 opt LimitResults{
 "limit-results",
 cat(Features),
@@ -497,7 +496,8 @@
 desc(
 "Read user and project configuration from YAML files.\n"
 "Project config is from a .clangd file in the project directory.\n"
-"User config is from clangd/config.yaml in the following directories:\n"
+"User config is from clangd/config.yaml in the following directories \n"
+"(unless specified with --default-config):\n"
 "\tWindows: %USERPROFILE%\\AppData\\Local\n"
 "\tMac OS: ~/Library/Preferences/\n"
 "\tOthers: $XDG_CONFIG_HOME, usually ~/.config\n"
@@ -505,6 +505,15 @@
 init(true),
 };
 
+opt DefaultConfig{
+"default-config",
+cat(Misc),
+desc("Path to a default clangd configuration file. A clangd user and "
+ "project configuration has a higher priority (requires "
+ "--enable-config) "),
+init(""),
+};
+
 opt UseDirtyHeaders{"use-dirty-headers", cat(Misc),
   desc("Use files open in the editor when parsing "
"headers instead of reading from the disk"),
@@ -945,6 +954,21 @@
 } else {
   elog("Couldn't determine user config file, not loading");
 }
+if (DefaultConfig.getNumOccurrences()) {
+  llvm::SmallString<256> DefaultConfigPath;
+  if (auto Error = llvm::sys::fs::real_path(
+  DefaultConfig, DefaultConfigPath, /*expand_tilde=*/true)) {
+elog("Couldn't determine default config file {0}: {1} , not loading",
+ DefaultConfig, Error.message());
+  } else {
+vlog("Default config file is {0}", DefaultConfigPath);
+// Give lowest priority to default config 
+ProviderStac

[PATCH] D151190: [clangd] Do not end inactiveRegions range at position 0 of line

2023-05-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/unittests/ClangdTests.cpp:1343
 #undef CMDMACRO
 $inactive3[[#ifdef CMDMACRO
   int inactiveInt2;

While this patch is an improvement, I wonder we should move it further.

Has been thinking about it more, we seem to have some inconsistent behavior on 
highlighting the `#if`, `#else`, `#endif` lines:

- in `$inactive1` case, the `#endif` is marked as inactive (IMO, the 
highlighting in the editor is confusing, it looks like we're missing a match 
`endif`, thus I prefer to mark it as active to correspond to the active `#if` 
branch);
- in `$inactive3` case, the line `#elif PREAMBLEMACRO > 0` is marked as 
inactive, this is inconsistent with `$inactive1` case;

I think it would be nice to have a consistent model. One approach is to always 
consider `#if`, `#elif`, `#endif`, `#endif` lines active (in the implementation 
side, this would mean we always use the line range [skipp_range.start.line+1, 
skipp_range.end.line - 1]).

What do you think about this?




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151190/new/

https://reviews.llvm.org/D151190

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


[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-05-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added reviewers: efriedma, rjmccall.
aaron.ballman added a comment.

Adding codegen code owners as reviewers.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151298/new/

https://reviews.llvm.org/D151298

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


[PATCH] D148094: [clang][CodeGen] Break up TargetInfo.cpp [8/8]

2023-05-24 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148094/new/

https://reviews.llvm.org/D148094

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


[PATCH] D151308: -fsanitize=function: fix alignment fault on Arm targets.

2023-05-24 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham updated this revision to Diff 525111.
simon_tatham added a comment.

Clarify mask construction as @michaelplatings suggested.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151308/new/

https://reviews.llvm.org/D151308

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/ubsan-function.cpp


Index: clang/test/CodeGen/ubsan-function.cpp
===
--- clang/test/CodeGen/ubsan-function.cpp
+++ clang/test/CodeGen/ubsan-function.cpp
@@ -1,11 +1,15 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64_be-linux-gnu -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s
+// RUN: %clang_cc1 -triple arm-none-eabi -emit-llvm -o - %s 
-fsanitize=function -fno-sanitize-recover=all | FileCheck %s 
--check-prefixes=CHECK,ARM
 
 // CHECK: define{{.*}} void @_Z3funv() #0 !func_sanitize ![[FUNCSAN:.*]] {
 void fun() {}
 
 // CHECK-LABEL: define{{.*}} void @_Z6callerPFvvE(ptr noundef %f)
+// ARM:   ptrtoint ptr {{.*}} to i32, !nosanitize !5
+// ARM:   and i32 {{.*}}, -2, !nosanitize !5
+// ARM:   inttoptr i32 {{.*}} to ptr, !nosanitize !5
 // CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 0, !nosanitize
 // CHECK: load i32, ptr {{.*}}, align {{.*}}, !nosanitize
 // CHECK: icmp eq i32 {{.*}}, -1056584962, !nosanitize
@@ -16,7 +20,7 @@
 // CHECK: icmp eq i32 {{.*}}, -1522505972, !nosanitize
 // CHECK: br i1 {{.*}}, label %[[LABEL3:.*]], label %[[LABEL2:[^,]*]], 
{{.*}}!nosanitize
 // CHECK: [[LABEL2]]:
-// CHECK: call void @__ubsan_handle_function_type_mismatch_abort(ptr @[[#]], 
i64 %[[#]]) #[[#]], !nosanitize
+// CHECK: call void @__ubsan_handle_function_type_mismatch_abort(ptr @[[#]], 
{{i64|i32}} %[[#]]) #[[#]], !nosanitize
 // CHECK-NEXT: unreachable, !nosanitize
 // CHECK-EMPTY:
 // CHECK-NEXT: [[LABEL3]]:
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -5364,8 +5364,30 @@
 
   llvm::Value *CalleePtr = Callee.getFunctionPointer();
 
+  // On 32-bit Arm, the low bit of a function pointer indicates whether
+  // it's using the Arm or Thumb instruction set. The actual first
+  // instruction lives at the same address either way, so we must clear
+  // that low bit before using the function address to find the prefix
+  // structure.
+  //
+  // This applies to both Arm and Thumb target triples, because
+  // either one could be used in an interworking context where it
+  // might be passed function pointers of both types.
+  llvm::Value *AlignedCalleePtr;
+  if (CGM.getTriple().isARM() || CGM.getTriple().isThumb()) {
+llvm::Value *CalleeAddress =
+Builder.CreatePtrToInt(CalleePtr, IntPtrTy);
+llvm::Value *Mask = llvm::ConstantInt::get(IntPtrTy, ~1);
+llvm::Value *AlignedCalleeAddress =
+Builder.CreateAnd(CalleeAddress, Mask);
+AlignedCalleePtr =
+Builder.CreateIntToPtr(AlignedCalleeAddress, CalleePtr->getType());
+  } else {
+AlignedCalleePtr = CalleePtr;
+  }
+
   llvm::Value *CalleePrefixStruct = Builder.CreateBitCast(
-  CalleePtr, llvm::PointerType::getUnqual(PrefixStructTy));
+  AlignedCalleePtr, llvm::PointerType::getUnqual(PrefixStructTy));
   llvm::Value *CalleeSigPtr =
   Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, -1, 
0);
   llvm::Value *CalleeSig =


Index: clang/test/CodeGen/ubsan-function.cpp
===
--- clang/test/CodeGen/ubsan-function.cpp
+++ clang/test/CodeGen/ubsan-function.cpp
@@ -1,11 +1,15 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64_be-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s
+// RUN: %clang_cc1 -triple arm-none-eabi -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s --check-prefixes=CHECK,ARM
 
 // CHECK: define{{.*}} void @_Z3funv() #0 !func_sanitize ![[FUNCSAN:.*]] {
 void fun() {}
 
 // CHECK-LABEL: define{{.*}} void @_Z6callerPFvvE(ptr noundef %f)
+// ARM:   ptrtoint ptr {{.*}} to i32, !nosanitize !5
+// ARM:   and i32 {{.*}}, -2, !nosanitize !5
+// ARM:   inttoptr i32 {{.*}} to ptr, !nosanitize !5
 // CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 0, !nosanitize
 // CHECK: load i32, ptr {{.*}}, align {{.

[PATCH] D151300: [clang][Diagnostics][NFC] Remove unnecessary StringRef

2023-05-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, but it's worth noting that `std::string::pop_back()` calls `erase()` and 
there's no guarantee that there's not an extra allocation involved as a result. 
However, I've not seen evidence that STLs actually do an allocation (looking at 
libc++ and MSVC STL, they don't appear to allocate), so I think this is fine.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151300/new/

https://reviews.llvm.org/D151300

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


[PATCH] D151300: [clang][Diagnostics][NFC] Remove unnecessary StringRef

2023-05-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

In D151300#4367884 , @aaron.ballman 
wrote:

> LGTM, but it's worth noting that `std::string::pop_back()` calls `erase()` 
> and there's no guarantee that there's not an extra allocation involved as a 
> result. However, I've not seen evidence that STLs actually do an allocation 
> (looking at libc++ and MSVC STL, they don't appear to allocate), so I think 
> this is fine.

Is the allocation only relevant for performance reasons or something else?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151300/new/

https://reviews.llvm.org/D151300

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


[PATCH] D151300: [clang][Diagnostics][NFC] Remove unnecessary StringRef

2023-05-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D151300#4367939 , @tbaeder wrote:

> In D151300#4367884 , @aaron.ballman 
> wrote:
>
>> LGTM, but it's worth noting that `std::string::pop_back()` calls `erase()` 
>> and there's no guarantee that there's not an extra allocation involved as a 
>> result. However, I've not seen evidence that STLs actually do an allocation 
>> (looking at libc++ and MSVC STL, they don't appear to allocate), so I think 
>> this is fine.
>
> Is the allocation only relevant for performance reasons or something else?

Performance was my only concern there.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151300/new/

https://reviews.llvm.org/D151300

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


[PATCH] D151300: [clang][Diagnostics][NFC] Remove unnecessary StringRef

2023-05-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

In D151300#4367943 , @aaron.ballman 
wrote:

> In D151300#4367939 , @tbaeder wrote:
>
>> In D151300#4367884 , 
>> @aaron.ballman wrote:
>>
>>> LGTM, but it's worth noting that `std::string::pop_back()` calls `erase()` 
>>> and there's no guarantee that there's not an extra allocation involved as a 
>>> result. However, I've not seen evidence that STLs actually do an allocation 
>>> (looking at libc++ and MSVC STL, they don't appear to allocate), so I think 
>>> this is fine.
>>
>> Is the allocation only relevant for performance reasons or something else?
>
> Performance was my only concern there.

Okay, good. I don't think that's too bad since the common line of code has 
exactly 0 trailing null bytes anyway.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151300/new/

https://reviews.llvm.org/D151300

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


[PATCH] D151320: [clang] Add `// expected-maybe-no-diagnostics` comment to VerifyDiagnosticConsumer

2023-05-24 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill created this revision.
Endill added reviewers: aaron.ballman, hfinkel, dblaikie.
Herald added a project: All.
Endill requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch introduces a `// expected-maybe-not-diagnostic` that silence 
warnings about missing `// expected-no-diagnostic`, but doesn't conflict with 
`// expected-error` directives.

I go into details in the Discourse thread 

 about why we need this, and why we need this in the form implemented.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151320

Files:
  clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
  clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
  clang/test/Frontend/verify-maybe-no-diagnostics.c

Index: clang/test/Frontend/verify-maybe-no-diagnostics.c
===
--- /dev/null
+++ clang/test/Frontend/verify-maybe-no-diagnostics.c
@@ -0,0 +1,106 @@
+// RUN: %clang_cc1 -DTEST_A1 -verify %s
+// RUN: %clang_cc1 -DTEST_B1 -verify %s
+// RUN: %clang_cc1 -DTEST_B2 -verify %s
+// RUN: %clang_cc1 -DTEST_C1 -verify %s
+// RUN: %clang_cc1 -DTEST_C2 -verify %s
+// RUN: not %clang_cc1 -DTEST_D1 -verify %s 2>&1 | FileCheck --check-prefix=D1-CHECK %s
+// RUN: not %clang_cc1 -DTEST_D2 -verify %s 2>&1 | FileCheck --check-prefix=D2-CHECK %s
+// RUN: not %clang_cc1 -DTEST_D3 -verify %s 2>&1 | FileCheck --check-prefix=D3-CHECK %s
+// RUN: not %clang_cc1 -DTEST_D4 -verify %s 2>&1 | FileCheck --check-prefix=D4-CHECK %s
+// RUN: not %clang_cc1 -DTEST_D5 -verify %s 2>&1 | FileCheck --check-prefix=D5-CHECK %s
+// RUN: not %clang_cc1 -DTEST_D6 -verify %s 2>&1 | FileCheck --check-prefix=D6-CHECK %s
+
+#ifdef TEST_A1
+// expected-maybe-no-diagnostics
+#endif
+
+#ifdef TEST_B1
+// expected-maybe-no-diagnostics
+// expected-no-diagnostics
+#endif
+
+#ifdef TEST_B2
+// expected-no-diagnostics
+// expected-maybe-no-diagnostics
+#endif
+
+#ifdef TEST_C1
+// expected-maybe-no-diagnostics
+#error test_c1
+// expected-error@-1 {{test_c1}}
+#endif
+
+#ifdef TEST_C2
+#error test_c2
+// expected-error@-1 {{test_c2}}
+// expected-maybe-no-diagnostics
+#endif
+
+#ifdef TEST_D1
+// expected-maybe-no-diagnostics
+#error test_d1
+// expected-error@-1 {{test_d1}}
+// expected-no-diagnostics
+
+//  D1-CHECK: error: 'error' diagnostics seen but not expected:
+// D1-CHECK-NEXT:   {{.*}} 'expected-no-diagnostics' directive cannot follow other expected directives
+// D1-CHECK-NEXT: 1 error generated.
+#endif
+
+#ifdef TEST_D2
+// expected-maybe-no-diagnostics
+// expected-no-diagnostics
+#error test_d2
+// expected-error@-1 {{test_d2}}
+
+//  D2-CHECK: error: 'error' diagnostics seen but not expected:
+// D2-CHECK-NEXT:   {{test_d2}}
+// D2-CHECK-NEXT:   {{.*}} expected directive cannot follow 'expected-no-diagnostics' directive
+// D2-CHECK-NEXT: 2 errors generated.
+#endif
+
+#ifdef TEST_D3
+// expected-no-diagnostics
+// expected-maybe-no-diagnostics
+#error test_d3
+// expected-error@-1 {{test_d3}}
+
+//  D3-CHECK: error: 'error' diagnostics seen but not expected:
+// D3-CHECK-NEXT:   {{test_d3}}
+// D3-CHECK-NEXT:   {{.*}} expected directive cannot follow 'expected-no-diagnostics' directive
+// D3-CHECK-NEXT: 2 errors generated.
+#endif
+
+#ifdef TEST_D4
+// expected-no-diagnostics
+#error test_d4
+// expected-error@-1 {{test_d4}}
+// expected-maybe-no-diagnostics
+
+//  D4-CHECK: error: 'error' diagnostics seen but not expected:
+// D4-CHECK-NEXT:   {{test_d4}}
+// D4-CHECK-NEXT:   {{.*}} expected directive cannot follow 'expected-no-diagnostics' directive
+// D4-CHECK-NEXT: 2 errors generated.
+#endif
+
+#ifdef TEST_D5
+#error test_d5
+// expected-error@-1 {{test_d5}}
+// expected-no-diagnostics
+// expected-maybe-no-diagnostics
+
+//  D5-CHECK: error: 'error' diagnostics seen but not expected:
+// D5-CHECK-NEXT:   {{.*}} 'expected-no-diagnostics' directive cannot follow other expected directives
+// D5-CHECK-NEXT: 1 error generated.
+#endif
+
+#ifdef TEST_D6
+#error test_d6
+// expected-error@-1 {{test_d6}}
+// expected-maybe-no-diagnostics
+// expected-no-diagnostics
+
+//  D6-CHECK: error: 'error' diagnostics seen but not expected:
+// D6-CHECK-NEXT:   {{.*}} 'expected-no-diagnostics' directive cannot follow other expected directives
+// D6-CHECK-NEXT: 1 error generated.
+#endif
Index: clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
===
--- clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -462,7 +462,11 @@
   D.DL = ED ? &ED->Remarks : nullptr;
 else if (DToken.endswith(DType="-note"))
   D.DL = ED ? &ED->Notes : nullptr;
-else if (DToken.endswith(DType="-no-diagnostics")) {
+else if (DToken.endswith(DType="-maybe-no-diagnostics")) {
+  if (Status == Verify

[PATCH] D151321: [clangd] Dont run raw-lexer for OOB source locations

2023-05-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added a subscriber: arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

We can get stale source locations from preamble, make sure we don't
access those locations without checking first.

Fixes https://github.com/clangd/clangd/issues/1636.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151321

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp


Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -829,6 +829,37 @@
 auto AST = createPatchedAST(Code.code(), NewCode.code());
 EXPECT_THAT(*AST->getDiagnostics(), IsEmpty());
   }
+  {
+Annotations Code(R"(
+#ifndef FOO
+#define FOO
+void foo();
+#endif)");
+// This code will emit a diagnostic for unterminated #ifndef (as stale
+// preamble has the conditional but main file doesn't terminate it).
+// We shouldn't emit any diagnotiscs (and shouldn't crash).
+Annotations NewCode("");
+auto AST = createPatchedAST(Code.code(), NewCode.code());
+EXPECT_THAT(*AST->getDiagnostics(), IsEmpty());
+  }
+  {
+Annotations Code(R"(
+#ifndef FOO
+#define FOO
+void foo();
+#endif)");
+// This code will emit a diagnostic for unterminated #ifndef (as stale
+// preamble has the conditional but main file doesn't terminate it).
+// We shouldn't emit any diagnotiscs (and shouldn't crash).
+// FIXME: Patch/ignore diagnostics in such cases.
+Annotations NewCode(R"(
+i[[nt]] xyz;
+)");
+auto AST = createPatchedAST(Code.code(), NewCode.code());
+EXPECT_THAT(
+*AST->getDiagnostics(),
+ElementsAre(Diag(NewCode.range(), "pp_unterminated_conditional")));
+  }
 }
 
 MATCHER_P2(Mark, Range, Text, "") {
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -96,7 +96,8 @@
 
 // Clang diags have a location (shown as ^) and 0 or more ranges ().
 // LSP needs a single range.
-Range diagnosticRange(const clang::Diagnostic &D, const LangOptions &L) {
+std::optional diagnosticRange(const clang::Diagnostic &D,
+ const LangOptions &L) {
   auto &M = D.getSourceManager();
   auto PatchedRange = [&M](CharSourceRange &R) {
 R.setBegin(translatePreamblePatchLocation(R.getBegin(), M));
@@ -115,13 +116,18 @@
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, PatchedRange(R));
   }
+  // Source locations from stale preambles might become OOB.
+  // FIXME: These diagnostics might point to wrong locations even when they're
+  // not OOB.
+  auto [FID, Offset] = M.getDecomposedLoc(Loc);
+  if (Offset > M.getBufferData(FID).size())
+return std::nullopt;
   // If the token at the location is not a comment, we use the token.
   // If we can't get the token at the location, fall back to using the location
   auto R = CharSourceRange::getCharRange(Loc);
   Token Tok;
-  if (!Lexer::getRawToken(Loc, Tok, M, L, true) && Tok.isNot(tok::comment)) {
+  if (!Lexer::getRawToken(Loc, Tok, M, L, true) && Tok.isNot(tok::comment))
 R = CharSourceRange::getTokenRange(Tok.getLocation(), Tok.getEndLoc());
-  }
   return halfOpenToRange(M, PatchedRange(R));
 }
 
@@ -697,7 +703,10 @@
 SourceLocation PatchLoc =
 translatePreamblePatchLocation(Info.getLocation(), SM);
 D.InsideMainFile = isInsideMainFile(PatchLoc, SM);
-D.Range = diagnosticRange(Info, *LangOpts);
+if (auto DRange = diagnosticRange(Info, *LangOpts))
+  D.Range = *DRange;
+else
+  D.Severity = DiagnosticsEngine::Ignored;
 auto FID = SM.getFileID(Info.getLocation());
 if (const auto FE = SM.getFileEntryRefForID(FID)) {
   D.File = FE->getName().str();


Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -829,6 +829,37 @@
 auto AST = createPatchedAST(Code.code(), NewCode.code());
 EXPECT_THAT(*AST->getDiagnostics(), IsEmpty());
   }
+  {
+Annotations Code(R"(
+#ifndef FOO
+#define FOO
+void foo();
+#endif)");
+// This code will emit a diagnostic for unterminated #ifndef (as stale
+// preamble has the conditional but main file doesn't terminate it).
+// We shouldn't emit any diagnotiscs (and shouldn't crash).
+Annotations NewCode("");
+auto AST = createPatchedAST(Code.code(), NewCode.code());
+EXPECT_THAT(*AST->getDiagnost

[PATCH] D150913: [Clang][Bfloat16] Upgrade __bf16 to arithmetic type, change mangling, and extend excess precision support.

2023-05-24 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:852
 ``double`` when passed to ``printf``, so the programmer must explicitly cast 
it to
 ``double`` before using it with an ``%f`` or similar specifier.
 

rjmccall wrote:
> Suggested rework:
> 
> ```
> Clang supports three half-precision (16-bit) floating point types: ``__fp16``,
> ``_Float16`` and ``__bf16``.  These types are supported in all language
> modes, but not on all targets:
> 
> - ``__fp16`` is supported on every target.
> 
> - ``_Float16`` is currently supported on the following targets:
>   * 32-bit ARM (natively on some architecture versions)
>   * 64-bit ARM (AArch64) (natively on ARMv8.2a and above)
>   * AMDGPU (natively)
>   * SPIR (natively)
>   * X86 (if SSE2 is available; natively if AVX512-FP16 is also available)
> 
> - ``__bf16`` is currently supported on the following targets:
>   * 32-bit ARM
>   * 64-bit ARM (AArch64)
>   * X86 (when SSE2 is available)
> 
> (For X86, SSE2 is available on 64-bit and all recent 32-bit processors.)
> 
> ``__fp16`` and ``_Float16`` both use the binary16 format from IEEE
> 754-2008, which provides a 5-bit exponent and an 11-bit significand
> (counting the implicit leading 1).  ``__bf16`` uses the `bfloat16
> `_ format,
> which provides an 8-bit exponent and an 8-bit significand; this is the same
> exponent range as `float`, just with greatly reduced precision.
> 
> ``_Float16`` and ``__bf16`` follow the usual rules for arithmetic
> floating-point types.  Most importantly, this means that arithmetic operations
> on operands of these types are formally performed in the type and produce
> values of the type.  ``__fp16`` does not follow those rules: most operations
> immediately promote operands of type ``__fp16`` to ``float``, and so
> arithmetic operations are defined to be performed in ``float`` and so result 
> in
> a value of type ``float`` (unless further promoted because of other operands).
> See below for more information on the exact specifications of these types.
> 
> Only some of the supported processors for ``__fp16`` and ``__bf16`` offer
> native hardware support for arithmetic in their corresponding formats.
> The exact conditions are described in the lists above.  When compiling for a
> processor without native support, Clang will perform the arithmetic in
> ``float``, inserting extensions and truncations as necessary.  This can be
> done in a way that exactly emulates the behavior of hardware support for
> arithmetic, but it can require many extra operations.  By default, Clang takes
> advantage of the C standard's allowances for excess precision in intermediate
> operands in order to eliminate intermediate truncations within statements.
> This is generally much faster but can generate different results from strict
> operation-by-operation emulation.
> 
> The use of excess precision can be independently controlled for these two
> types with the ``-ffloat16-excess-precision=`` and
> ``-fbfloat16-excess-precision=`` options.  Valid values include:
> - ``none`` (meaning to perform strict operation-by-operation emulation)
> - ``standard`` (meaning that excess precision is permitted under the rules
>   described in the standard, i.e. never across explicit casts or statements)
> - ``fast`` (meaning that excess precision is permitted whenever the
>   optimizer sees an opportunity to avoid truncations; currently this has no
>   effect beyond ``standard``)
> 
> The ``_Float16`` type is an interchange floating type specified in
>  ISO/IEC TS 18661-3:2015 ("Floating-point extensions for C").  It will
> be supported on more targets as they define ABIs for it.
> 
> The ``__bf16`` type is a non-standard extension, but it generally follows
> the rules for arithmetic interchange floating types from ISO/IEC TS
> 18661-3:2015.  In previous versions of Clang, it was a storage-only type
> that forbade arithmetic operations.  It will be supported on more targets
> as they define ABIs for it.
> 
> The ``__fp16`` type was originally an ARM extension and is specified
> by the `ARM C Language Extensions 
> `_.
> Clang uses the ``binary16`` format from IEEE 754-2008 for ``__fp16``,
> not the ARM alternative format.  Operators that expect arithmetic operands
> immediately promote ``__fp16`` operands to ``float``.
> 
> It is recommended that portable code use ``_Float16`` instead of ``__fp16``,
> as it has been defined by the C standards committee and has behavior that is
> more familiar to most programmers.
> 
> Because ``__fp16`` operands are always immediately promoted to ``float``, the
> common real type of ``__fp16`` and ``_Float16`` for the purposes of the usual
> arithmetic conversions is ``float``.
> 
> A literal can be given ``_Float16`` type using the suffix ``f16``. For 
> example,
> ``3.14f16``.
> 
> Because default argument promotion on

[clang] 456d072 - Reland: [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables

2023-05-24 Thread Takuya Shimizu via cfe-commits

Author: Takuya Shimizu
Date: 2023-05-24T21:31:25+09:00
New Revision: 456d072405d29ac731ad22fa1ec198b9f8265c4e

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

LOG: Reland: [clang][AST] Print name instead of type when diagnosing 
uninitialized subobject in constexpr variables

This patch improves the diagnostic on uninitialized subobjects in constexpr 
variables by modifying the diagnostic message to display the subobject's name 
instead of its type.

Fixes https://github.com/llvm/llvm-project/issues/58601
Differential Revision: https://reviews.llvm.org/D146358

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/Interp/Interp.cpp
clang/test/AST/Interp/cxx20.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a124617fac8bb..0c369a7f45057 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -296,7 +296,9 @@ Improvements to Clang's diagnostics
   Clang ABI >= 15.
   (`#62353: `_,
   fallout from the non-POD packing ABI fix in LLVM 15).
-
+- Clang constexpr evaluator now prints subobject's name instead of its type in 
notes
+  when a constexpr variable has uninitialized subobjects after its constructor 
call.
+  (`#58601 `_)
 
 Bug Fixes in This Version
 -

diff  --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index c283ee842e730..eb13467317963 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -65,7 +65,7 @@ def note_consteval_address_accessible : Note<
   "%select{pointer|reference}0 to a consteval declaration "
   "is not a constant expression">;
 def note_constexpr_uninitialized : Note<
-  "%select{|sub}0object of type %1 is not initialized">;
+  "subobject %0 is not initialized">;
 def note_constexpr_static_local : Note<
   "control flows through the definition of a %select{static|thread_local}0 
variable">;
 def note_constexpr_subobject_declared_here : Note<

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d88f9535c1a4b..1f1ce2a18bd4a 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2119,7 +2119,7 @@ static bool 
CheckEvaluationResult(CheckEvaluationResultKind CERK,
   EvalInfo &Info, SourceLocation DiagLoc,
   QualType Type, const APValue &Value,
   ConstantExprKind Kind,
-  SourceLocation SubobjectLoc,
+  const FieldDecl *SubobjectDecl,
   CheckedTemporaries &CheckedTemps);
 
 /// Check that this reference or pointer core constant expression is a valid
@@ -2266,8 +2266,8 @@ static bool CheckLValueConstantExpression(EvalInfo &Info, 
SourceLocation Loc,
   APValue *V = MTE->getOrCreateValue(false);
   assert(V && "evasluation result refers to uninitialised temporary");
   if (!CheckEvaluationResult(CheckEvaluationResultKind::ConstantExpression,
- Info, MTE->getExprLoc(), TempType, *V,
- Kind, SourceLocation(), CheckedTemps))
+ Info, MTE->getExprLoc(), TempType, *V, Kind,
+ /*SubobjectDecl=*/nullptr, CheckedTemps))
 return false;
 }
   }
@@ -2350,13 +2350,13 @@ static bool 
CheckEvaluationResult(CheckEvaluationResultKind CERK,
   EvalInfo &Info, SourceLocation DiagLoc,
   QualType Type, const APValue &Value,
   ConstantExprKind Kind,
-  SourceLocation SubobjectLoc,
+  const FieldDecl *SubobjectDecl,
   CheckedTemporaries &CheckedTemps) {
   if (!Value.hasValue()) {
-Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized)
-  << true << Type;
-if (SubobjectLoc.isValid())
-  Info.Note(SubobjectLoc, diag::note_constexpr_subobject_declared_here);
+assert(SubobjectDecl && "SubobjectDecl shall be non-null");
+Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized) << SubobjectDecl;
+Info.Note(SubobjectDecl->getLocation(),
+  diag::note_constexpr_subobject_declared_here);

[clang] 29dc47a - [clang][Sema] `-Wshadow` warns about shadowings by static local variables

2023-05-24 Thread Takuya Shimizu via cfe-commits

Author: Takuya Shimizu
Date: 2023-05-24T21:31:25+09:00
New Revision: 29dc47a9eeeb2e080170109e3e2fb3cd5aad58d2

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

LOG: [clang][Sema] `-Wshadow` warns about shadowings by static local variables

This patch makes `-Wshadow` warn about the shadowings by static local variables.

Fixes https://github.com/llvm/llvm-project/issues/62850
Differential Revision: https://reviews.llvm.org/D151214

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/warn-shadow.c
clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
clang/test/SemaCXX/warn-shadow.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c369a7f45057..92fe909e5e8a6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -299,6 +299,8 @@ Improvements to Clang's diagnostics
 - Clang constexpr evaluator now prints subobject's name instead of its type in 
notes
   when a constexpr variable has uninitialized subobjects after its constructor 
call.
   (`#58601 `_)
+- Clang's `-Wshadow` warning now warns about shadowings by static local 
variables
+  (`#62850: `_).
 
 Bug Fixes in This Version
 -

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 859224780befa..aac57196012aa 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8150,7 +8150,7 @@ NamedDecl *Sema::getShadowedDeclaration(const VarDecl *D,
 return nullptr;
 
   // Don't diagnose declarations at file scope.
-  if (D->hasGlobalStorage())
+  if (D->hasGlobalStorage() && !D->isStaticLocal())
 return nullptr;
 
   NamedDecl *ShadowedDecl = R.getFoundDecl();

diff  --git a/clang/test/Sema/warn-shadow.c b/clang/test/Sema/warn-shadow.c
index b4b0620395cf7..212ca8803b6fb 100644
--- a/clang/test/Sema/warn-shadow.c
+++ b/clang/test/Sema/warn-shadow.c
@@ -1,18 +1,24 @@
 // RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wshadow %s
 
-int i;  // expected-note 3 {{previous declaration is here}}
+int i;  // expected-note 4 {{previous declaration is here}}
+static int s;   // expected-note 2 {{previous declaration is here}}
 
 void foo(void) {
   int pass1;
   int i;// expected-warning {{declaration shadows a variable in the 
global scope}} \
 // expected-note {{previous declaration is here}}
+  int s;// expected-warning {{declaration shadows a variable in the 
global scope}} \
+// expected-note {{previous declaration is here}}
   {
 int pass2;
 int i;  // expected-warning {{declaration shadows a local variable}} \
 // expected-note {{previous declaration is here}}
+int s;  // expected-warning {{declaration shadows a local variable}} \
+// expected-note {{previous declaration is here}}
 {
   int pass3;
   int i;// expected-warning {{declaration shadows a local variable}}
+  int s;// expected-warning {{declaration shadows a local variable}}
 }
   }
 
@@ -71,3 +77,25 @@ struct PR24718_4 {
 PR24718_3 // Does not shadow a type.
   };
 };
+
+void static_locals() {
+  static int i; // expected-warning {{declaration shadows a variable in the 
global scope}}
+// expected-note@-1 {{previous definition is here}}
+// expected-note@-2 {{previous declaration is here}}
+  int i;// expected-error {{non-static declaration of 'i' follows 
static declaration}}
+  static int foo; // expected-note {{previous declaration is here}}
+  static int hoge; // expected-note {{previous declaration is here}}
+  int s; // expected-warning {{declaration shadows a variable in the global 
scope}}
+  {
+static int foo; // expected-warning {{declaration shadows a local 
variable}}
+// expected-note@-1 {{previous declaration is here}}
+static int i; // expected-warning {{declaration shadows a local variable}}
+  // expected-note@-1 {{previous declaration is here}}
+int hoge; // expected-warning {{declaration shadows a local variable}}
+{
+  static int foo; // expected-warning {{declaration shadows a local 
variable}}
+  int i; // expected-warning {{declaration shadows a local variable}}
+  extern int hoge;
+}
+  }
+}

diff  --git a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp 
b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
index e5d4c69dcee06..bda6a65c02168 100644
--- a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -14,11 +14,15 @@ void foo(int param) { // expected-note 1+ {{p

[PATCH] D146358: [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables

2023-05-24 Thread Takuya Shimizu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG456d072405d2: Reland: [clang][AST] Print name instead of 
type when diagnosing uninitialized… (authored by hazohelet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146358/new/

https://reviews.llvm.org/D146358

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/Interp.cpp
  clang/test/AST/Interp/cxx20.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
  clang/test/SemaCXX/constant-expression-cxx2a.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp

Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -761,7 +761,7 @@
 };
 
 S s1; // expected-error {{call to consteval function 'NamespaceScopeConsteval::S::S' is not a constant expression}} \
- expected-note {{subobject of type 'int' is not initialized}}
+ expected-note {{subobject 'Val' is not initialized}}
 
 template 
 struct T {
@@ -770,7 +770,7 @@
 };
 
 T t; // expected-error {{call to consteval function 'NamespaceScopeConsteval::T::T' is not a constant expression}} \
- expected-note {{subobject of type 'int' is not initialized}}
+ expected-note {{subobject 'Val' is not initialized}}
 
 } // namespace NamespaceScopeConsteval
 
Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -409,12 +409,12 @@
 b.a.x = 2;
 return b;
   }
-  constexpr B uninit = return_uninit(); // expected-error {{constant expression}} expected-note {{subobject of type 'int' is not initialized}}
+  constexpr B uninit = return_uninit(); // expected-error {{constant expression}} expected-note {{subobject 'y' is not initialized}}
   static_assert(return_uninit().a.x == 2);
   constexpr A return_uninit_struct() {
 B b = {.b = 1};
 b.a.x = 2;
-return b.a; // expected-note {{in call to 'A(b.a)'}} expected-note {{subobject of type 'int' is not initialized}}
+return b.a; // expected-note {{in call to 'A(b.a)'}} expected-note {{subobject 'y' is not initialized}}
   }
   // Note that this is rejected even though return_uninit() is accepted, and
   // return_uninit() copies the same stuff wrapped in a union.
@@ -558,7 +558,7 @@
 }
   };
   constinit X x1(true);
-  constinit X x2(false); // expected-error {{constant initializer}} expected-note {{constinit}} expected-note {{subobject of type 'int' is not initialized}}
+  constinit X x2(false); // expected-error {{constant initializer}} expected-note {{constinit}} expected-note {{subobject 'n' is not initialized}}
 
   struct Y {
 struct Z { int n; }; // expected-note {{here}}
@@ -577,7 +577,7 @@
   };
   // FIXME: This is working around clang not implementing DR2026. With that
   // fixed, we should be able to test this without the injected copy.
-  constexpr Y copy(Y y) { return y; } // expected-note {{in call to 'Y(y)'}} expected-note {{subobject of type 'int' is not initialized}}
+  constexpr Y copy(Y y) { return y; } // expected-note {{in call to 'Y(y)'}} expected-note {{subobject 'n' is not initialized}}
   constexpr Y y1 = copy(Y());
   static_assert(y1.z1.n == 1 && y1.z2.n == 2 && y1.z3.n == 3);
 
Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
+++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
@@ -360,7 +360,7 @@
   // The constructor is still 'constexpr' here, but the result is not intended
   // to be a constant expression. The standard is not clear on how this should
   // work.
-  constexpr V v; // expected-error {{constant expression}} expected-note {{subobject of type 'int' is not initialized}}
+  constexpr V v; // expected-error {{constant expression}} expected-note {{subobject 'y' is not initialized}}
 
   constexpr int k = V().x; // FIXME: ok?
 }
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -143,9 +143,9 @@
 constexpr A() {}
   };
   constexpr A a; // expected-error {{must be initialized by a constant expression}} \
- // expected-note {{subobject of type 'int' is not initialized}} \
+ // expected-note {{subobject 'a' is not initialized}} \
  // ref-error {{must be initialized by a constant expression}} \
- // ref-note {{subobject of type 'int' is not initialized}}
+ // ref-note {{subobject '

[PATCH] D151214: [clang][Sema] `-Wshadow` warns about shadowings by static local variables

2023-05-24 Thread Takuya Shimizu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG29dc47a9eeeb: [clang][Sema] `-Wshadow` warns about 
shadowings by static local variables (authored by hazohelet).

Changed prior to commit:
  https://reviews.llvm.org/D151214?vs=524709&id=525126#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151214/new/

https://reviews.llvm.org/D151214

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/warn-shadow.c
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
  clang/test/SemaCXX/warn-shadow.cpp

Index: clang/test/SemaCXX/warn-shadow.cpp
===
--- clang/test/SemaCXX/warn-shadow.cpp
+++ clang/test/SemaCXX/warn-shadow.cpp
@@ -2,6 +2,7 @@
 
 namespace {
   int i; // expected-note {{previous declaration is here}}
+  static int s; // expected-note {{previous declaration is here}}
 }
 
 namespace one {
@@ -31,6 +32,7 @@
 void foo() {
   int i; // expected-warning {{declaration shadows a variable in namespace '(anonymous)'}}
   int j; // expected-warning {{declaration shadows a variable in namespace 'one::two'}}
+  static int s; // expected-warning {{declaration shadows a variable in namespace '(anonymous)'}}
   int m;
   int mm;
   int mmm;
@@ -40,7 +42,7 @@
   static int data; // expected-note 1 {{previous declaration}}
   // expected-note@+1 1 {{previous declaration}}
   int field;
-  int f1, f2, f3, f4; // expected-note 8 {{previous declaration is here}}
+  int f1, f2, f3, f4; // expected-note 9 {{previous declaration is here}}
 
   typedef int a1; // expected-note 2 {{previous declaration}}
   using a2=int; // expected-note 2 {{previous declaration}}
@@ -66,6 +68,7 @@
 char *a2; // no warning
 char *jj; // no warning
 char *jjj; // no warning
+static char *f1; // expected-warning {{declaration shadows a field of 'A'}}
   }
 
   void test2() {
@@ -305,4 +308,4 @@
   }
 }
 
-}; // namespace structured_binding_tests
\ No newline at end of file
+}; // namespace structured_binding_tests
Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -14,11 +14,15 @@
 auto f2 = [&] { int var = 2; };  // no warning
 auto f3 = [=] (int param) { ; }; // no warning
 auto f4 = [&] (int param) { ; }; // no warning
+auto f5 = [=] { static int var = 1; };  // no warning
+auto f6 = [&] { static int var = 2; };  // no warning
 #else
 auto f1 = [=] { int var = 1; };  // expected-warning {{declaration shadows a local variable}}
 auto f2 = [&] { int var = 2; };  // expected-warning {{declaration shadows a local variable}}
 auto f3 = [=] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
 auto f4 = [&] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
+auto f5 = [=] { static int var = 1; };  // expected-warning {{declaration shadows a local variable}}
+auto f6 = [&] { static int var = 2; };  // expected-warning {{declaration shadows a local variable}}
 #endif
   }
 
@@ -67,11 +71,15 @@
 auto f2 = [] (int param) { ; }; // no warning
 auto f3 = [param] () { int var = 1; }; // no warning
 auto f4 = [var] (int param) { ; }; // no warning
+auto f5 = [param] () { static int var = 1; }; // no warning
+auto f6 = [] { static int var = 1; }; // no warning
 #else
 auto f1 = [] { int var = 1; }; // expected-warning {{declaration shadows a local variable}}
 auto f2 = [] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
 auto f3 = [param] () { int var = 1; }; // expected-warning {{declaration shadows a local variable}}
 auto f4 = [var] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
+auto f5 = [param] () { static int var = 1; }; // expected-warning {{declaration shadows a local variable}}
+auto f6 = [] { static int var = 1; }; // expected-warning {{declaration shadows a local variable}}
 #endif
   };
 
@@ -127,6 +135,11 @@
   int param = 0; // expected-warning {{declaration shadows a local variable}}
 };
   };
+  auto l7 = [&] {
+auto f1 = [param] { // expected-note {{variable 'param' is explicitly captured here}}
+  static int param = 0; // expected-warning {{declaration shadows a local variable}}
+};
+  };
 
   // Generic lambda arguments should work.
 #ifdef AVOID
Index: clang/test/Sema/warn-shadow.c
===
--- clang/test/Sema/warn-shadow.c
+++ clang/test/Sema/warn-shadow.c
@@ -1,18 +1,24 @@
 // RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wshadow %s
 
-int i;  // expected-note 3 {{previous declaration is here}}
+int i;  // expected-note 4 {{previous declaration is here}}
+static int s;  

[PATCH] D150528: [Clang][Attribute] Improve the AST/diagnoses fidelity of alignas and _Alignas

2023-05-24 Thread Yurong via Phabricator via cfe-commits
yronglin added a comment.

In D150528#4365688 , @aaron.ballman 
wrote:

> In general, I think this is looking pretty good, thank you! I'll leave it to 
> @erichkeane to do the final sign-off as attributes code owner since this is 
> making a fair number of changes in that area.

Thanks for your review @aaron.ballman ! BTW, I have two questions:

1. Should we print the cached alignment value when dump AST?
2. The AlignedAttr::getAlignment has a bit redundant with GetAlignOfType(in 
ExprConstant.cpp ), should we merge these?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150528/new/

https://reviews.llvm.org/D150528

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


[PATCH] D151308: -fsanitize=function: fix alignment fault on Arm targets.

2023-05-24 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings accepted this revision.
michaelplatings added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151308/new/

https://reviews.llvm.org/D151308

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


[PATCH] D151286: [clang][Diagnostics][NFC] Don't create oversized CaretLine

2023-05-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151286/new/

https://reviews.llvm.org/D151286

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


[PATCH] D151280: [NFC][CLANG] Fix static code analyzer concerns

2023-05-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane requested changes to this revision.
erichkeane added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1343
 const ConstantArrayType *CAT = CGM.getContext().getAsConstantArrayType(T);
+assert(CAT && "unexpected type for array initializer");
 

The assert message doesn't make sense here?  This isn't an initializer for an 
array?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151280/new/

https://reviews.llvm.org/D151280

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


[PATCH] D151092: [clang-tidy]performance-no-automatic-move: fix false negative on `const T&&` ctors.

2023-05-24 Thread Clement Courbet via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9182c679dde7: [clang-tidy]performance-no-automatic-move: fix 
false negative on `const T&&`… (authored by courbet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151092/new/

https://reviews.llvm.org/D151092

Files:
  clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
@@ -7,30 +7,42 @@
   virtual ~Obj();
 };
 
-template 
-struct StatusOr {
-  StatusOr(const T &);
-  StatusOr(T &&);
-};
-
 struct NonTemplate {
   NonTemplate(const Obj &);
   NonTemplate(Obj &&);
 };
 
+template  struct TemplateCtorPair {
+  TemplateCtorPair(const T &);
+  TemplateCtorPair(T &&value);
+};
+
+template  struct UrefCtor {
+  template  UrefCtor(U &&value);
+};
+
 template 
 T Make();
 
-StatusOr PositiveStatusOrConstValue() {
+NonTemplate PositiveNonTemplate() {
   const Obj obj = Make();
-  return obj;
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents automatic move [performance-no-automatic-move]
+  return obj; // selects `NonTemplate(const Obj&)`
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents
+  // automatic move [performance-no-automatic-move]
 }
 
-NonTemplate PositiveNonTemplateConstValue() {
+TemplateCtorPair PositiveTemplateCtorPair() {
   const Obj obj = Make();
-  return obj;
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents automatic move [performance-no-automatic-move]
+  return obj; // selects `TemplateCtorPair(const T&)`
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents
+  // automatic move [performance-no-automatic-move]
+}
+
+UrefCtor PositiveUrefCtor() {
+  const Obj obj = Make();
+  return obj; // selects `UrefCtor(const T&&)`
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents
+  // automatic move [performance-no-automatic-move]
 }
 
 Obj PositiveCantNrvo(bool b) {
@@ -51,22 +63,18 @@
 }
 
 // FIXME: Ideally we would warn here too.
-StatusOr PositiveStatusOrLifetimeExtension() {
+UrefCtor PositiveUrefCtorLifetimeExtension() {
   const Obj &obj = Make();
   return obj;
 }
 
 // Negatives.
 
-StatusOr Temporary() {
-  return Make();
-}
+UrefCtor Temporary() { return Make(); }
 
-StatusOr ConstTemporary() {
-  return Make();
-}
+UrefCtor ConstTemporary() { return Make(); }
 
-StatusOr ConvertingMoveConstructor() {
+UrefCtor ConvertingMoveConstructor() {
   Obj obj = Make();
   return obj;
 }
@@ -85,21 +93,19 @@
   return obj2;
 }
 
-StatusOr Ref() {
+UrefCtor Ref() {
   Obj &obj = Make();
   return obj;
 }
 
-StatusOr ConstRef() {
+UrefCtor ConstRef() {
   const Obj &obj = Make();
   return obj;
 }
 
 const Obj global;
 
-StatusOr Global() {
-  return global;
-}
+UrefCtor Global() { return global; }
 
 struct FromConstRefOnly {
   FromConstRefOnly(const Obj &);
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -387,6 +387,10 @@
   ` when warning would be
   emitted for a const local variable to which NRVO is applied.
 
+- Improved :doc:`performance-no-automatic-move
+  `: warn on ``const &&``
+  constructors.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
@@ -48,15 +48,23 @@
   hasParameter(0, hasType(rValueReferenceType(
   pointee(type(equalsBoundNode("SrcT")));
 
+  // A matcher for `DstT::DstT(const Src&&)`, which typically comes from an
+  // instantiation of `template  DstT::DstT(U&&)`.
+  const auto ConstRefRefCtor = cxxConstructorDecl(
+  parameterCountIs(1),
+  hasParameter(0,
+   hasType(rValueReferenceType(pointee(isConstQualified());
+
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   returnStmt(hasReturnValue(
-   ignoringElidableConstructorCall(ignoringParenImpCasts(
-   cxxConstructExpr(
-   hasDeclaration(LValueRefCtor),
-   hasArgument(0, ignoringParenImpCasts(declRefExpr(
-  to(NonNrvoConstLocalVariable)

[clang-tools-extra] 9182c67 - [clang-tidy]performance-no-automatic-move: fix false negative on `const T&&` ctors.

2023-05-24 Thread Clement Courbet via cfe-commits

Author: Clement Courbet
Date: 2023-05-24T15:05:39+02:00
New Revision: 9182c679dde7cb6480e66b9231a53d43ad03908b

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

LOG: [clang-tidy]performance-no-automatic-move: fix false negative on `const 
T&&` ctors.

We were only handling `const T&`/`T&&` ctor pairs, and we were missing 
uref-based ctors.

Differential Revision: https://reviews.llvm.org/D151092

Added: 


Modified: 
clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
index 42bf8ff831868..7022e9d784fa7 100644
--- a/clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp
@@ -48,15 +48,23 @@ void NoAutomaticMoveCheck::registerMatchers(MatchFinder 
*Finder) {
   hasParameter(0, hasType(rValueReferenceType(
   pointee(type(equalsBoundNode("SrcT")));
 
+  // A matcher for `DstT::DstT(const Src&&)`, which typically comes from an
+  // instantiation of `template  DstT::DstT(U&&)`.
+  const auto ConstRefRefCtor = cxxConstructorDecl(
+  parameterCountIs(1),
+  hasParameter(0,
+   hasType(rValueReferenceType(pointee(isConstQualified());
+
   Finder->addMatcher(
-  traverse(TK_AsIs,
-   returnStmt(hasReturnValue(
-   ignoringElidableConstructorCall(ignoringParenImpCasts(
-   cxxConstructExpr(
-   hasDeclaration(LValueRefCtor),
-   hasArgument(0, ignoringParenImpCasts(declRefExpr(
-  to(NonNrvoConstLocalVariable)
-   .bind("ctor_call")),
+  traverse(
+  TK_AsIs,
+  returnStmt(hasReturnValue(
+  ignoringElidableConstructorCall(ignoringParenImpCasts(
+  cxxConstructExpr(
+  hasDeclaration(anyOf(LValueRefCtor, ConstRefRefCtor)),
+  hasArgument(0, ignoringParenImpCasts(declRefExpr(
+ to(NonNrvoConstLocalVariable)
+  .bind("ctor_call")),
   this);
 }
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7fe2b97de8643..d1fd47542bd51 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -387,6 +387,10 @@ Changes in existing checks
   ` when warning would be
   emitted for a const local variable to which NRVO is applied.
 
+- Improved :doc:`performance-no-automatic-move
+  `: warn on 
``const &&``
+  constructors.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
index d365f7de8b7c1..1ef7d16e38393 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance/no-automatic-move.cpp
@@ -7,30 +7,42 @@ struct Obj {
   virtual ~Obj();
 };
 
-template 
-struct StatusOr {
-  StatusOr(const T &);
-  StatusOr(T &&);
-};
-
 struct NonTemplate {
   NonTemplate(const Obj &);
   NonTemplate(Obj &&);
 };
 
+template  struct TemplateCtorPair {
+  TemplateCtorPair(const T &);
+  TemplateCtorPair(T &&value);
+};
+
+template  struct UrefCtor {
+  template  UrefCtor(U &&value);
+};
+
 template 
 T Make();
 
-StatusOr PositiveStatusOrConstValue() {
+NonTemplate PositiveNonTemplate() {
   const Obj obj = Make();
-  return obj;
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents 
automatic move [performance-no-automatic-move]
+  return obj; // selects `NonTemplate(const Obj&)`
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents
+  // automatic move [performance-no-automatic-move]
 }
 
-NonTemplate PositiveNonTemplateConstValue() {
+TemplateCtorPair PositiveTemplateCtorPair() {
   const Obj obj = Make();
-  return obj;
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents 
automatic move [performance-no-automatic-move]
+  return obj; // selects `TemplateCtorPair(const T&)`
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: constness of 'obj' prevents
+  // automatic move [performance-no-automatic-move]
+}
+
+UrefCtor PositiveUrefCtor() {
+  const Obj obj = Make();
+  return obj; // selects `UrefCtor(const T&&)`
+  // CHECK-MESSAGES: :

[PATCH] D151301: [clang][Diagnostics] Print empty lines in multiline snippets

2023-05-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: clang/test/Misc/diag-style.cpp:10
+// CHECK-NEXT: {{^}}  |   ^~~~{{$}}
+// CHECK-NEXT: {{^}}5 | {{$}}
+// CHECK-NEXT: {{^}}6 |   true, "");{{$}}

tbaeder wrote:
> Questionable whether the space after the `|` is expected.
I don't have a good intuition for whether it is expected or not, but I think 
it's defensible.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151301/new/

https://reviews.llvm.org/D151301

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


[PATCH] D151325: [analyzer] Differentiate lifetime extended temporaries

2023-05-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
tomasz-kaminski-sonarsource requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch introduces a new `CXXLifetimeExtendedObjectRegion` as a 
representation
of the memory for the temporary object that is lifetime extended by the 
reference
to which they are bound.

This separation provides an ability to detect the use of dangling pointers
(either binding or dereference) in a robust manner.
For example, the `ref` is conditionally dangling in the following example:

  template
  T const& select(bool cond, T const& t, T const& u) { return cond ? t : u; }
  
  int const& le = Composite{}.x;
  auto&& ref = select(cond, le, 10);

Before the change, regardless of the value of `cond`, the `select()` call would
have returned a `temp_object` region.
With the proposed change we would produce a (non-dangling) 
`lifetime_extended_object`
region with lifetime bound to `le` or a `temp_object` region for the dangling 
case.

We believe that such separation is desired, as such lifetime extended 
temporaries
are closer to the variables. For example, they may have a static storage 
duration
(this patch removes a static temporary region, which was an abomination).
We also think that alternative approaches are not viable.

While for some cases it may be possible to determine if the region is lifetime
extended by searching the parents of the initializer expr, this quickly becomes
complex in the presence of the conditions operators like this one:

  Composite cc;
  // Ternary produces prvalue 'int' which is extended, as branches differ in 
value category
  auto&& x = cond ? Composite{}.x : cc.x;
  
  // Ternary produces xvalue, and extends the Composite object
  auto&& y = cond ? Composite{}.x : std::move(cc).x;


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151325

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/Regions.def
  clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/lib/StaticAnalyzer/Core/Store.cpp
  clang/test/Analysis/lifetime-extended-regions.cpp
  clang/test/Analysis/stack-addr-ps.cpp

Index: clang/test/Analysis/stack-addr-ps.cpp
===
--- clang/test/Analysis/stack-addr-ps.cpp
+++ clang/test/Analysis/stack-addr-ps.cpp
@@ -30,13 +30,13 @@
 
 const int &get_reference2() {
   const int &x = get_value(); // expected-note {{binding reference variable 'x' here}}
-  return x; // expected-warning{{Address of stack memory associated with temporary object of type 'int' returned}} expected-warning {{returning reference to local temporary}}
+  return x; // expected-warning{{Address of stack memory associated with temporary object of type 'int' lifetime extended by local variable 'x' returned to caller}} expected-warning {{returning reference to local temporary}} 
 }
 
 const int &get_reference3() {
   const int &x1 = get_value(); // expected-note {{binding reference variable 'x1' here}}
   const int &x2 = x1; // expected-note {{binding reference variable 'x2' here}}
-  return x2; // expected-warning{{Address of stack memory associated with temporary object of type 'int' returned}} expected-warning {{returning reference to local temporary}}
+  return x2; // expected-warning{{Address of stack memory associated with temporary object of type 'int' lifetime extended by local variable 'x1' returned to caller}} expected-warning {{returning reference to local temporary}}
 }
 
 int global_var;
@@ -60,7 +60,7 @@
 const int *f4() {
   const int &x1 = get_value(); // expected-note {{binding reference variable 'x1' here}}
   const int &x2 = x1; // expected-note {{binding reference variable 'x2' here}}
-  return &x2; // expected-warning{{Address of stack memory associated with temporary object of type 'int' returned}} expected-warning {{returning address of local temporary}}
+  return &x2; // expected-warning{{Address of stack memory associated with temporary object of type 'int' lifetime extended by local variable 'x1' returned to caller}} expected-warning {{returning address of local temporary}}
 }
 
 struct S {
Index: clang/test/Analysis/lifetime-extended-regions.cpp
===
--- /dev/null
+++ clang/test/Analysis/lifetime-extended-regions.cpp
@@ -0,0 +1,170 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core\
+// RUN:-analyzer-checker=debug.ExprInspection\
+// RUN:-Wno-dangl

[PATCH] D150528: [Clang][Attribute] Improve the AST/diagnoses fidelity of alignas and _Alignas

2023-05-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D150528#4368023 , @yronglin wrote:

> In D150528#4365688 , @aaron.ballman 
> wrote:
>
>> In general, I think this is looking pretty good, thank you! I'll leave it to 
>> @erichkeane to do the final sign-off as attributes code owner since this is 
>> making a fair number of changes in that area.
>
> Thanks for your review @aaron.ballman ! BTW, I have two questions:
>
> 1. Should we print the cached alignment value when dump AST?

I think it would be nice to dump that as well, but not critical.

> 2. The AlignedAttr::getAlignment has a bit redundant with GetAlignOfType(in 
> ExprConstant.cpp ), should we merge these?

It would be good to unify them, but that can be done in a follow-up as it's a 
bit orthogonal.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150528/new/

https://reviews.llvm.org/D150528

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


[PATCH] D151092: [clang-tidy]performance-no-automatic-move: fix false negative on `const T&&` ctors.

2023-05-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

The release note references documentation that doesn't exist, so Sphinx is 
failing: https://lab.llvm.org/buildbot/#/builders/115/builds/46942


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151092/new/

https://reviews.llvm.org/D151092

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


[clang-tools-extra] 62dc3ba - [clang-tidy]Fix rG9182c679dde7cb6480e66b9231a53d43ad03908b

2023-05-24 Thread Clement Courbet via cfe-commits

Author: Clement Courbet
Date: 2023-05-24T15:19:00+02:00
New Revision: 62dc3ba8442fa3f7003d46d2838307452a0391f4

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

LOG: [clang-tidy]Fix rG9182c679dde7cb6480e66b9231a53d43ad03908b

Fix bad link to documentation.

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index d1fd47542bd5..8365340921e6 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -384,7 +384,7 @@ Changes in existing checks
   with attributes and to support nested inline namespace introduced in c++20.
 
 - Fixed a false positive in :doc:`performance-no-automatic-move
-  ` when warning would be
+  ` when warning 
would be
   emitted for a const local variable to which NRVO is applied.
 
 - Improved :doc:`performance-no-automatic-move



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


[PATCH] D150646: [clang][X86] Add __cpuidex function to cpuid.h

2023-05-24 Thread Ron Lieberman via Phabricator via cfe-commits
ronlieb added a comment.

seeing this issue in our downstream builders: 
[2023-05-24T11:46:07.333Z] 
/opt/rocm-5.6.0-12074/llvm/lib/clang/17.0.0/include/cpuid.h:333:22: error: 
static declaration of '__cpuidex' follows non-static declaration

[2023-05-24T11:46:07.333Z] static __inline void __cpuidex (int __cpu_info[4], 
int __leaf, int __subleaf)

[2023-05-24T11:46:07.333Z]  ^


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150646/new/

https://reviews.llvm.org/D150646

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


[PATCH] D151092: [clang-tidy]performance-no-automatic-move: fix false negative on `const T&&` ctors.

2023-05-24 Thread Clement Courbet via Phabricator via cfe-commits
courbet added a comment.

In D151092#4368151 , @aaron.ballman 
wrote:

> The release note references documentation that doesn't exist, so Sphinx is 
> failing: https://lab.llvm.org/buildbot/#/builders/115/builds/46942

Sorry, fixed in rG62dc3ba8442f 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151092/new/

https://reviews.llvm.org/D151092

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


[PATCH] D151092: [clang-tidy]performance-no-automatic-move: fix false negative on `const T&&` ctors.

2023-05-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D151092#4368225 , @courbet wrote:

> In D151092#4368151 , @aaron.ballman 
> wrote:
>
>> The release note references documentation that doesn't exist, so Sphinx is 
>> failing: https://lab.llvm.org/buildbot/#/builders/115/builds/46942
>
> Sorry, fixed in rG62dc3ba8442f 
> 

Thanks! In retrospect, I should have fixed that myself rather than mention it 
here, sorry for that. :-D


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151092/new/

https://reviews.llvm.org/D151092

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


[PATCH] D150953: [Clang][SVE2.1] Add clang support for prototypes using svcount_t

2023-05-24 Thread Caroline via Phabricator via cfe-commits
CarolineConcatto updated this revision to Diff 525146.
CarolineConcatto marked an inline comment as done.
CarolineConcatto edited the summary of this revision.
CarolineConcatto added a comment.

-Address review's comments about Q target type.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150953/new/

https://reviews.llvm.org/D150953

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/arm_sve.td
  clang/lib/AST/ASTContext.cpp
  clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_ptrue.c
  clang/utils/TableGen/SveEmitter.cpp

Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -66,7 +66,8 @@
 class SVEType {
   TypeSpec TS;
   bool Float, Signed, Immediate, Void, Constant, Pointer, BFloat;
-  bool DefaultType, IsScalable, Predicate, PredicatePattern, PrefetchOp;
+  bool DefaultType, IsScalable, Predicate, PredicatePattern, PrefetchOp,
+  Svcount;
   unsigned Bitwidth, ElementBitwidth, NumVectors;
 
 public:
@@ -76,7 +77,8 @@
   : TS(TS), Float(false), Signed(true), Immediate(false), Void(false),
 Constant(false), Pointer(false), BFloat(false), DefaultType(false),
 IsScalable(true), Predicate(false), PredicatePattern(false),
-PrefetchOp(false), Bitwidth(128), ElementBitwidth(~0U), NumVectors(1) {
+PrefetchOp(false), Svcount(false), Bitwidth(128), ElementBitwidth(~0U),
+NumVectors(1) {
 if (!TS.empty())
   applyTypespec();
 applyModifier(CharMod);
@@ -95,13 +97,16 @@
   bool isFloat() const { return Float && !BFloat; }
   bool isBFloat() const { return BFloat && !Float; }
   bool isFloatingPoint() const { return Float || BFloat; }
-  bool isInteger() const { return !isFloatingPoint() && !Predicate; }
+  bool isInteger() const {
+return !isFloatingPoint() && !Predicate && !Svcount;
+  }
   bool isScalarPredicate() const {
 return !isFloatingPoint() && Predicate && NumVectors == 0;
   }
   bool isPredicateVector() const { return Predicate; }
   bool isPredicatePattern() const { return PredicatePattern; }
   bool isPrefetchOp() const { return PrefetchOp; }
+  bool isSvcount() const { return Svcount; }
   bool isConstant() const { return Constant; }
   unsigned getElementSizeInBits() const { return ElementBitwidth; }
   unsigned getNumVectors() const { return NumVectors; }
@@ -203,6 +208,9 @@
   /// ClassS, so will add type suffixes such as _u32/_s32.
   std::string getMangledName() const { return mangleName(ClassS); }
 
+  /// As above, but mangles the LLVM name instead.
+  std::string getMangledLLVMName() const { return mangleLLVMName(); }
+
   /// Returns true if the intrinsic is overloaded, in that it should also generate
   /// a short form without the type-specifiers, e.g. 'svld1(..)' instead of
   /// 'svld1_u32(..)'.
@@ -233,6 +241,7 @@
 private:
   std::string getMergeSuffix() const { return MergeSuffix; }
   std::string mangleName(ClassKind LocalCK) const;
+  std::string mangleLLVMName() const;
   std::string replaceTemplatedArgs(std::string Name, TypeSpec TS,
std::string Proto) const;
 };
@@ -366,6 +375,9 @@
   if (isScalarPredicate())
 return "b";
 
+  if (isSvcount())
+return "Qa";
+
   if (isVoidPointer())
 S += "v";
   else if (!isFloatingPoint())
@@ -429,13 +441,15 @@
   if (Void)
 S += "void";
   else {
-if (isScalableVector())
+if (isScalableVector() || isSvcount())
   S += "sv";
 if (!Signed && !isFloatingPoint())
   S += "u";
 
 if (Float)
   S += "float";
+else if (isSvcount())
+  S += "count";
 else if (isScalarPredicate() || isPredicateVector())
   S += "bool";
 else if (isBFloat())
@@ -443,7 +457,7 @@
 else
   S += "int";
 
-if (!isScalarPredicate() && !isPredicateVector())
+if (!isScalarPredicate() && !isPredicateVector() && !isSvcount())
   S += utostr(ElementBitwidth);
 if (!isScalableVector() && isVector())
   S += "x" + utostr(getNumElements());
@@ -461,8 +475,15 @@
   return S;
 }
 void SVEType::applyTypespec() {
-  for (char I : TS) {
-switch (I) {
+  for (size_t I = 0; I < TS.size(); I++) {
+switch (TS[I]) {
+case 'Q':
+  if (TS[I + 1] == 'a') {
+Svcount = true;
+I++;
+  } else
+llvm_unreachable("Unknow Modifier");
+  break;
 case 'P':
   Predicate = true;
   break;
@@ -554,6 +575,7 @@
 Float = false;
 BFloat = false;
 Predicate = true;
+Svcount = false;
 Bitwidth = 16;
 ElementBitwidth = 1;
 break;
@@ -593,18 +615,21 @@
 break;
   case 'u':
 Predicate = false;
+Svcount = false;
 Signed = false;
 Float = false;
 BFloat = false;
 break;
   case 'x':
 Predicate = false;
+Svcount = false;
 Signed = true;
 Float = false;
 BFloat = false;
 b

[clang-tools-extra] 32ffc55 - [clang-tidy] Really fix rG9182c679dde7

2023-05-24 Thread Clement Courbet via cfe-commits

Author: Clement Courbet
Date: 2023-05-24T15:21:50+02:00
New Revision: 32ffc1feda4cf3eeec5740af5c5f386e584c

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

LOG: [clang-tidy] Really fix  rG9182c679dde7

Correct link is clang-tidy/checks/performance/no-automatic-move

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 8365340921e6..980be4869ead 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -384,11 +384,11 @@ Changes in existing checks
   with attributes and to support nested inline namespace introduced in c++20.
 
 - Fixed a false positive in :doc:`performance-no-automatic-move
-  ` when warning 
would be
+  ` when warning would be
   emitted for a const local variable to which NRVO is applied.
 
 - Improved :doc:`performance-no-automatic-move
-  `: warn on 
``const &&``
+  `: warn on ``const &&``
   constructors.
 
 Removed checks



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


[PATCH] D151325: [analyzer] Differentiate lifetime extended temporaries

2023-05-24 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Please leave a link in the summary to the RFC to discuss.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151325/new/

https://reviews.llvm.org/D151325

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


[PATCH] D150670: [WebAssembly] Disable generation of fshl/fshr for rotates

2023-05-24 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

In D150670#4352163 , @nikic wrote:

> 1. Say that we prefer preserving rotates over "simplifying" funnel shifts 
> (ending up with the rot2 pattern). Basically by skipping the optimization at 
> https://github.com/llvm/llvm-project/blob/7f54b38e28b3b66195de672848f2b5366d0d51e3/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L927-L931
>  if both fsh operands are the same. Assuming this doesn't cause test 
> regressions, I think this would be acceptable to do. From a backend 
> perspective, even for targets that have a native funnel shift (aarch64, x86), 
> the difference between the rot1/rot2 patterns looks pretty neutral.

I am surprised this option is viable for example. This was my initial thought 
to avoid the rotate, but I assumed adding something like :

  if (!getTarget().getTriple().isWasm()) {
APInt DemandedMaskLHS(DemandedMask.lshr(ShiftAmt));
APInt DemandedMaskRHS(DemandedMask.shl(BitWidth - ShiftAmt));
if (SimplifyDemandedBits(I, 0, DemandedMaskLHS, LHSKnown, Depth + 1) ||
SimplifyDemandedBits(I, 1, DemandedMaskRHS, RHSKnown, Depth + 1))
  return I;
  }

would not be well received. Also, I cannot find precedent for doing this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150670/new/

https://reviews.llvm.org/D150670

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


[PATCH] D150670: [WebAssembly] Disable generation of fshl/fshr for rotates

2023-05-24 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

In D150670#4368238 , @pmatos wrote:

> In D150670#4352163 , @nikic wrote:
>
>> 1. Say that we prefer preserving rotates over "simplifying" funnel shifts 
>> (ending up with the rot2 pattern). Basically by skipping the optimization at 
>> https://github.com/llvm/llvm-project/blob/7f54b38e28b3b66195de672848f2b5366d0d51e3/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L927-L931
>>  if both fsh operands are the same. Assuming this doesn't cause test 
>> regressions, I think this would be acceptable to do. From a backend 
>> perspective, even for targets that have a native funnel shift (aarch64, 
>> x86), the difference between the rot1/rot2 patterns looks pretty neutral.

OK, I just re-read your comment above and I am starting to assume that what you 
mean is skipping the optimization for all targets if the funnel shift is a 
rotate (i.e. same first two operands). Is this correct?

> I am surprised this option is viable for example. This was my initial thought 
> to avoid the rotate, but I assumed adding something like :
>
>   if (!getTarget().getTriple().isWasm()) {
> APInt DemandedMaskLHS(DemandedMask.lshr(ShiftAmt));
> APInt DemandedMaskRHS(DemandedMask.shl(BitWidth - ShiftAmt));
> if (SimplifyDemandedBits(I, 0, DemandedMaskLHS, LHSKnown, Depth + 1) ||
> SimplifyDemandedBits(I, 1, DemandedMaskRHS, RHSKnown, Depth + 1))
>   return I;
>   }
>
> would not be well received. Also, I cannot find precedent for doing this.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150670/new/

https://reviews.llvm.org/D150670

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


[PATCH] D150670: [WebAssembly] Disable generation of fshl/fshr for rotates

2023-05-24 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D150670#4368241 , @pmatos wrote:

> In D150670#4368238 , @pmatos wrote:
>
>> In D150670#4352163 , @nikic wrote:
>>
>>> 1. Say that we prefer preserving rotates over "simplifying" funnel shifts 
>>> (ending up with the rot2 pattern). Basically by skipping the optimization 
>>> at 
>>> https://github.com/llvm/llvm-project/blob/7f54b38e28b3b66195de672848f2b5366d0d51e3/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L927-L931
>>>  if both fsh operands are the same. Assuming this doesn't cause test 
>>> regressions, I think this would be acceptable to do. From a backend 
>>> perspective, even for targets that have a native funnel shift (aarch64, 
>>> x86), the difference between the rot1/rot2 patterns looks pretty neutral.
>
> OK, I just re-read your comment above and I am starting to assume that what 
> you mean is skipping the optimization for all targets if the funnel shift is 
> a rotate (i.e. same first two operands). Is this correct?

That's right.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150670/new/

https://reviews.llvm.org/D150670

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


[clang] cde1390 - [clang][Sema] Fix a crash when instantiating a non-type template argument in a dependent scope.

2023-05-24 Thread via cfe-commits

Author: Sheng
Date: 2023-05-24T21:46:31+08:00
New Revision: cde139016a4eb2d71950e135f9c037987ecdb7cf

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

LOG: [clang][Sema] Fix a crash when instantiating a non-type template argument 
in a dependent scope.

The type alias template is not diagnosed when instantiating an expected 
non-type template argument in a dependent scope, causing ICE.

Besides that, the diagnostic message has been updated to account for the fact 
that the function template  is not the only non-type template.

Fixes #62533

Reviewed By: #clang-language-wg, erichkeane

Differential Revision: https://reviews.llvm.org/D151062

Added: 
clang/test/SemaCXX/PR62533.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/ms-sizeof-missing-typename.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 92fe909e5e8a6..38a1347368c4c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -437,7 +437,8 @@ Bug Fixes in This Version
   ``__builtin_dynamic_object_size`` on structs containing flexible array
   members.
   (`#62789 `_).
-
+- Fix a crash when instantiating a non-type template argument in a dependent 
scope.
+  (`#62533 `_).
 Bug Fixes to Compiler Builtins
 ^^
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d21cb62cd0423..0cbc2fc8c8949 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5490,10 +5490,10 @@ def note_template_kw_refers_to_non_template : Note<
 def err_template_kw_refers_to_dependent_non_template : Error<
   "%0%select{| following the 'template' keyword}1 "
   "cannot refer to a dependent template">;
-def err_template_kw_refers_to_class_template : Error<
-  "'%0%1' instantiated to a class template, not a function template">;
-def note_referenced_class_template : Note<
-  "class template declared here">;
+def err_template_kw_refers_to_type_template : Error<
+  "'%0%1' is expected to be a non-type template, but instantiated to a 
%select{class|type alias}2 template">;
+def note_referenced_type_template : Note<
+  "%select{class|type alias}0 template declared here">;
 def err_template_kw_missing : Error<
   "missing 'template' keyword prior to dependent template name '%0%1'">;
 def ext_template_outside_of_template : ExtWarn<

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 7a545214596ba..063ddb418c431 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -5001,13 +5001,20 @@ Sema::BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
 return ExprError();
   }
 
-  if (ClassTemplateDecl *Temp = R.getAsSingle()) {
-Diag(NameInfo.getLoc(), diag::err_template_kw_refers_to_class_template)
-  << SS.getScopeRep()
-  << NameInfo.getName().getAsString() << SS.getRange();
-Diag(Temp->getLocation(), diag::note_referenced_class_template);
+  auto DiagnoseTypeTemplateDecl = [&](TemplateDecl *Temp,
+  bool isTypeAliasTemplateDecl) {
+Diag(NameInfo.getLoc(), diag::err_template_kw_refers_to_type_template)
+<< SS.getScopeRep() << NameInfo.getName().getAsString() << 
SS.getRange()
+<< isTypeAliasTemplateDecl;
+Diag(Temp->getLocation(), diag::note_referenced_type_template) << 0;
 return ExprError();
-  }
+  };
+
+  if (ClassTemplateDecl *Temp = R.getAsSingle())
+return DiagnoseTypeTemplateDecl(Temp, false);
+
+  if (TypeAliasTemplateDecl *Temp = R.getAsSingle())
+return DiagnoseTypeTemplateDecl(Temp, true);
 
   return BuildTemplateIdExpr(SS, TemplateKWLoc, R, /*ADL*/ false, 
TemplateArgs);
 }

diff  --git a/clang/test/SemaCXX/PR62533.cpp b/clang/test/SemaCXX/PR62533.cpp
new file mode 100644
index 0..920ea54d4b00e
--- /dev/null
+++ b/clang/test/SemaCXX/PR62533.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template
+struct test {
+  template using fun_
diff  = char; // expected-note 2{{class template declared here}}
+};
+
+template
+decltype(T::template fun_
diff ) foo1() {}
+// expected-note@-1 {{candidate template ignored: substitution failure [with T 
= test, V = int]: 'test::fun_
diff ' is expected to be a non-type template, but instantiated to a type alias 
template}}
+
+template
+void foo2() {
+  // expected-error@+1 {{test::fun_
diff ' is expected to be a non-type template, but instantiated to a type alias 
template}}
+  int a = test::template

[PATCH] D151062: [clang][Sema] Fix a crash when instantiating a non-type template argument in a dependent scope.

2023-05-24 Thread Sheng via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcde139016a4e: [clang][Sema] Fix a crash when instantiating a 
non-type template argument in a… (authored by 0x59616e).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D151062?vs=525157&id=525160#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151062/new/

https://reviews.llvm.org/D151062

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaCXX/PR62533.cpp
  clang/test/SemaTemplate/ms-sizeof-missing-typename.cpp

Index: clang/test/SemaTemplate/ms-sizeof-missing-typename.cpp
===
--- clang/test/SemaTemplate/ms-sizeof-missing-typename.cpp
+++ clang/test/SemaTemplate/ms-sizeof-missing-typename.cpp
@@ -50,7 +50,7 @@
 }
 
 namespace ambiguous_missing_parens {
-// expected-error@+1 {{'Q::U' instantiated to a class template, not a function template}}
+// expected-error@+1 {{'Q::U' is expected to be a non-type template, but instantiated to a class template}}
 template  void f() { int a = sizeof T::template U<0> + 4; }
 struct Q {
   // expected-note@+1 {{class template declared here}}
Index: clang/test/SemaCXX/PR62533.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR62533.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template
+struct test {
+  template using fun_diff = char; // expected-note 2{{class template declared here}}
+};
+
+template
+decltype(T::template fun_diff) foo1() {}
+// expected-note@-1 {{candidate template ignored: substitution failure [with T = test, V = int]: 'test::fun_diff' is expected to be a non-type template, but instantiated to a type alias template}}
+
+template
+void foo2() {
+  // expected-error@+1 {{test::fun_diff' is expected to be a non-type template, but instantiated to a type alias template}}
+  int a = test::template fun_diff;
+}
+
+template
+struct has_fun_diff {
+  using type = double;
+};
+
+template
+struct has_fun_diff {
+  // expected-error@+1 {{'test::fun_diff' is expected to be a non-type template, but instantiated to a type alias template}}
+  using type = decltype(T::template fun_diff);
+};
+
+void bar() {
+  foo1, int>(); // expected-error {{no matching function for call to 'foo1'}}
+  foo2(); // expected-note {{in instantiation of function template specialization}}
+  has_fun_diff, int>::type a; // expected-note {{in instantiation of template class}}
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5001,13 +5001,20 @@
 return ExprError();
   }
 
-  if (ClassTemplateDecl *Temp = R.getAsSingle()) {
-Diag(NameInfo.getLoc(), diag::err_template_kw_refers_to_class_template)
-  << SS.getScopeRep()
-  << NameInfo.getName().getAsString() << SS.getRange();
-Diag(Temp->getLocation(), diag::note_referenced_class_template);
+  auto DiagnoseTypeTemplateDecl = [&](TemplateDecl *Temp,
+  bool isTypeAliasTemplateDecl) {
+Diag(NameInfo.getLoc(), diag::err_template_kw_refers_to_type_template)
+<< SS.getScopeRep() << NameInfo.getName().getAsString() << SS.getRange()
+<< isTypeAliasTemplateDecl;
+Diag(Temp->getLocation(), diag::note_referenced_type_template) << 0;
 return ExprError();
-  }
+  };
+
+  if (ClassTemplateDecl *Temp = R.getAsSingle())
+return DiagnoseTypeTemplateDecl(Temp, false);
+
+  if (TypeAliasTemplateDecl *Temp = R.getAsSingle())
+return DiagnoseTypeTemplateDecl(Temp, true);
 
   return BuildTemplateIdExpr(SS, TemplateKWLoc, R, /*ADL*/ false, TemplateArgs);
 }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5490,10 +5490,10 @@
 def err_template_kw_refers_to_dependent_non_template : Error<
   "%0%select{| following the 'template' keyword}1 "
   "cannot refer to a dependent template">;
-def err_template_kw_refers_to_class_template : Error<
-  "'%0%1' instantiated to a class template, not a function template">;
-def note_referenced_class_template : Note<
-  "class template declared here">;
+def err_template_kw_refers_to_type_template : Error<
+  "'%0%1' is expected to be a non-type template, but instantiated to a %select{class|type alias}2 template">;
+def note_referenced_type_template : Note<
+  "%select{class|type alias}0 template declared here">;
 def err_template_kw_missing : Error<
   "missing 'template' keyword prior to dependent template name '%0%1'">;
 def ext_

[clang] 77908ef - [clang][NFC] Add a blank line in ReleaseNotes.rst

2023-05-24 Thread via cfe-commits

Author: Sheng
Date: 2023-05-24T22:02:41+08:00
New Revision: 77908efab4391e7d401480c6cec307a5c45f1cce

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

LOG: [clang][NFC] Add a blank line in ReleaseNotes.rst

A buildbot has failed on the absence of the blank line at the end of the bullet 
list.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 38a1347368c4..53bc6b6c0027 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -439,6 +439,7 @@ Bug Fixes in This Version
   (`#62789 `_).
 - Fix a crash when instantiating a non-type template argument in a dependent 
scope.
   (`#62533 `_).
+
 Bug Fixes to Compiler Builtins
 ^^
 



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


[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-24 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:241-242
   Builder.defineMacro("__ARM_FEATURE_QRDMX", "1");
-  Builder.defineMacro("__ARM_FEATURE_ATOMICS", "1");
-  Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
 }

aaron.ballman wrote:
> john.brawn wrote:
> > aaron.ballman wrote:
> > > john.brawn wrote:
> > > > aaron.ballman wrote:
> > > > > Hmm, is this correct?
> > > > > 
> > > > > `__ARM_FEATURE_ATOMICS` is defined in one other place, but it's 
> > > > > conditionally defined: 
> > > > > https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/AArch64.cpp#L475
> > > > > 
> > > > > and `__ARM_FEATURE_CRC32` is defined in two places, both conditional: 
> > > > > https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/AArch64.cpp#L422
> > > > >  and 
> > > > > https://github.com/llvm/llvm-project/blob/11926e6149d2a68ecb0652b248efe6890c163846/clang/lib/Basic/Targets/ARM.cpp#L747
> > > > > 
> > > > > 
> > > > AArch64TargetInfo::setArchFeatures sets HasCRC and HasLSE to true for 
> > > > >= 8.1. This does mean that if you do `-march=armv8.1-a+nocrc` then the 
> > > > current behaviour is that __ARM_FEATURE_CRC32 is defined but the 
> > > > behaviour with this patch is that it's not defined, but the new 
> > > > behaviour is correct as we shouldn't be defining it in that case.
> > > Ah, okay! I think it's worth adding a test case for that scenario to show 
> > > we've made a bugfix here, not just an NFC change.
> > Actually I went and double-checked and I'm wrong, 
> > `-march=armv8.N+nowhatever` doesn't cause __ARM_FEATURE_WHATEVER to be 
> > undefined. Which seems wrong, but it's beyond the scope of this patch.
> Yeah, that does seem wrong. Agreed it's not in scope for this patch, but if 
> you would file an issue in GitHub so we don't lose track of it, that'd be 
> appreciated.
https://github.com/llvm/llvm-project/issues/62919



Comment at: clang/test/Preprocessor/predefined-macros-no-warnings.c:5
+// warnings suppressed by default.
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arc
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple xcore

aaron.ballman wrote:
> So the expectation is that any warnings that are emitted would be upgraded to 
> an error and the test would be flagged as a failure because %clang_cc1 would 
> return nonzero in that case?
> 
> (I was thrown for a loop by not using `-verify` and `// 
> expected-no-diagnostics`)
> 
> Pretty sure `-Eonly` is equivalent (it runs the preprocessor without emitting 
> output, so no extra overhead from piping to /dev/null).
Yes the intent is for the test to fail on any warning. Using `-Werror` and not 
`-verify` means that on failure you get which macro caused the error:
```
Exit Code: 1

Command Output (stderr):
--
:351:9: error: redefining builtin macro 
[-Werror,-Wbuiltin-macro-redefined]
#define __LITTLE_ENDIAN__ 1
^
1 error generated.

--
```
whereas `-verify` just outputs
```
Exit Code: 1

Command Output (stderr):
--
error: 'error' diagnostics seen but not expected:
  Line 351: redefining builtin macro
1 error generated.

--
```

Using `-Eonly` makes sense, I'll do that.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150966/new/

https://reviews.llvm.org/D150966

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


[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-24 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 525165.
john.brawn added a comment.

Use -Eonly in test.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150966/new/

https://reviews.llvm.org/D150966

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/CSKY.cpp
  clang/lib/Basic/Targets/Hexagon.cpp
  clang/lib/Basic/Targets/Le64.cpp
  clang/lib/Basic/Targets/MSP430.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/VE.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/init-ve.c
  clang/test/Preprocessor/predefined-macros-no-warnings.c

Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- /dev/null
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -0,0 +1,199 @@
+// Check that the predefined macros don't contain anything that causes a
+// warning, which needs -Wsystem-headers to detect as the predefined macros
+// are in the  file which is treated as a system header and so has
+// warnings suppressed by default.
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arc
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple xcore
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple hexagon
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple hexagon-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple lanai
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_32-darwin
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-darwin
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-cloudabi
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-fuchsia
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-linux-openhos
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-openbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-win32-gnu
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-win32-msvc
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-fuchsia
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-darwin
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-cloudabi
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-fuchsia
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-linux-openhos
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-liteos
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-openbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-rtems
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-nacl
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-cygnus
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-gnu
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-itanium
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-msvc
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-openbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-rtems
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple avr
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple bpfeb
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple bpfel
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple msp430
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple mips
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple mips-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-header

[PATCH] D151337: ARM: default to arm_aapcscc (or VFP) for embedded MachO targets.

2023-05-24 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover created this revision.
Herald added subscribers: kristof.beyls, mcrosier.
Herald added a project: All.
t.p.northover requested review of this revision.
Herald added a project: clang.

These were always intended to be AAPCS targets and LLVM does treat the usual C 
calling convention that way, but some refactoring over time seems to have lost 
that so now they get lots of extra `arm_aapcscc` decoration that's not needed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151337

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/arm-macho-embedded.c
  clang/test/CodeGen/atomic-arm.c


Index: clang/test/CodeGen/atomic-arm.c
===
--- clang/test/CodeGen/atomic-arm.c
+++ clang/test/CodeGen/atomic-arm.c
@@ -22,7 +22,7 @@
 
 int lock_free_1() {
   // CHECK-LABEL: @lock_free_1
-  // CHECK-V6M:   [[RES:%.*]] = call arm_aapcscc zeroext i1 
@__atomic_is_lock_free(i32 noundef 1, ptr noundef null)
+  // CHECK-V6M:   [[RES:%.*]] = call zeroext i1 @__atomic_is_lock_free(i32 
noundef 1, ptr noundef null)
   // CHECK-V6M:   [[RES32:%.*]] = zext i1 [[RES]] to i32
   // CHECK-V6M:   ret i32 [[RES32]]
 
@@ -33,7 +33,7 @@
 
 int lock_free_4() {
   // CHECK-LABEL: @lock_free_4
-  // CHECK-V6M:   [[RES:%.*]] = call arm_aapcscc zeroext i1 
@__atomic_is_lock_free(i32 noundef 4, ptr noundef null)
+  // CHECK-V6M:   [[RES:%.*]] = call zeroext i1 @__atomic_is_lock_free(i32 
noundef 4, ptr noundef null)
   // CHECK-V6M:   [[RES32:%.*]] = zext i1 [[RES]] to i32
   // CHECK-V6M:   ret i32 [[RES32]]
 
@@ -44,11 +44,11 @@
 
 int lock_free_8() {
   // CHECK-LABEL: @lock_free_8
-  // CHECK-V6M:   [[RES:%.*]] = call arm_aapcscc zeroext i1 
@__atomic_is_lock_free(i32 noundef 8, ptr noundef null)
+  // CHECK-V6M:   [[RES:%.*]] = call zeroext i1 @__atomic_is_lock_free(i32 
noundef 8, ptr noundef null)
   // CHECK-V6M:   [[RES32:%.*]] = zext i1 [[RES]] to i32
   // CHECK-V6M:   ret i32 [[RES32]]
 
-  // CHECK-V7M:   [[RES:%.*]] = call arm_aapcscc zeroext i1 
@__atomic_is_lock_free(i32 noundef 8, ptr noundef null)
+  // CHECK-V7M:   [[RES:%.*]] = call zeroext i1 @__atomic_is_lock_free(i32 
noundef 8, ptr noundef null)
   // CHECK-V7M:   [[RES32:%.*]] = zext i1 [[RES]] to i32
   // CHECK-V7M:   ret i32 [[RES32]]
 
Index: clang/test/CodeGen/arm-macho-embedded.c
===
--- /dev/null
+++ clang/test/CodeGen/arm-macho-embedded.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple thumbv7m-apple-unknown-macho %s -emit-llvm -o - | 
FileCheck %s
+
+// N.b. the default (C) calling convention for embedded MachO is AAPCS so we
+// don't want Clang generating arm_aapcscc or arm_aapcs_vfpcc for basic
+// functions.
+
+// CHECK: define void @func()
+void func() {
+}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -6532,9 +6532,12 @@
 /// Return the default calling convention that LLVM will use.
 llvm::CallingConv::ID ARMABIInfo::getLLVMDefaultCC() const {
   // The default calling convention that LLVM will infer.
-  if (isEABIHF() || getTarget().getTriple().isWatchABI())
+  const llvm::Triple &TT = getTarget().getTriple();
+  if (isEABIHF() || TT.isWatchABI() ||
+  (TT.isOSBinFormatMachO() &&
+   TT.getSubArch() == llvm::Triple::ARMSubArch_v7em))
 return llvm::CallingConv::ARM_AAPCS_VFP;
-  else if (isEABI())
+  else if (isEABI() || (TT.isOSBinFormatMachO() && !TT.isOSDarwin()))
 return llvm::CallingConv::ARM_AAPCS;
   else
 return llvm::CallingConv::ARM_APCS;


Index: clang/test/CodeGen/atomic-arm.c
===
--- clang/test/CodeGen/atomic-arm.c
+++ clang/test/CodeGen/atomic-arm.c
@@ -22,7 +22,7 @@
 
 int lock_free_1() {
   // CHECK-LABEL: @lock_free_1
-  // CHECK-V6M:   [[RES:%.*]] = call arm_aapcscc zeroext i1 @__atomic_is_lock_free(i32 noundef 1, ptr noundef null)
+  // CHECK-V6M:   [[RES:%.*]] = call zeroext i1 @__atomic_is_lock_free(i32 noundef 1, ptr noundef null)
   // CHECK-V6M:   [[RES32:%.*]] = zext i1 [[RES]] to i32
   // CHECK-V6M:   ret i32 [[RES32]]
 
@@ -33,7 +33,7 @@
 
 int lock_free_4() {
   // CHECK-LABEL: @lock_free_4
-  // CHECK-V6M:   [[RES:%.*]] = call arm_aapcscc zeroext i1 @__atomic_is_lock_free(i32 noundef 4, ptr noundef null)
+  // CHECK-V6M:   [[RES:%.*]] = call zeroext i1 @__atomic_is_lock_free(i32 noundef 4, ptr noundef null)
   // CHECK-V6M:   [[RES32:%.*]] = zext i1 [[RES]] to i32
   // CHECK-V6M:   ret i32 [[RES32]]
 
@@ -44,11 +44,11 @@
 
 int lock_free_8() {
   // CHECK-LABEL: @lock_free_8
-  // CHECK-V6M:   [[RES:%.*]] = call arm_aapcscc zeroext i1 @__atomic_is_lock_free(i32 noundef 8, ptr noundef null)
+  // CHECK-V6M:   [[RES:%.*]] = call zeroext i1 @__atomic_is_lock_free(i32 noundef 8, ptr noundef null)
   // CHECK-V6M:   [[RES32:%.*]] = zext i1 [[RES]] to i3

[PATCH] D148216: Add support for annotations in UpdateTestChecks (NFC)

2023-05-24 Thread Henrik G Olsson via Phabricator via cfe-commits
hnrklssn updated this revision to Diff 525174.
hnrklssn added a comment.
Herald added a subscriber: ormris.

Overhauled how update_cc_tests.py checks globals

It now:

- no longer matches the literal names, like update_test_checks.py does unless 
--preserve-names (which doesn't seem to see much use, at least not upstream, so 
did not add option to update_cc_tests.py) is set
- (along with update_test_checks.py) now adds checks for any definitions of 
globals referenced in the IR (by default, can still check all globals using 
"--check-globals all")
- (along with update_test_checks.py) can also be configured to emit checks for 
any definitions of globals referenced by other globals referenced in the IR, 
using "--check-globals transitive"
- (along with update_test_checks.py) filters out unstable metadata output, so 
that literal directory names and git hashes are not matched against


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148216/new/

https://reviews.llvm.org/D148216

Files:
  clang/test/utils/update_cc_test_checks/Inputs/annotations.c
  clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected
  clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected
  
clang/test/utils/update_cc_test_checks/Inputs/explicit-template-instantiation.cpp.expected
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
  
clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.expected
  
clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.no-generated.expected
  
clang/test/utils/update_cc_test_checks/Inputs/global-hex-value-regex.c.expected
  clang/test/utils/update_cc_test_checks/Inputs/global-value-regex.c.expected
  clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c.funcsig.expected
  
clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c.funcsig.v2.expected
  clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c.v2.expected
  
clang/test/utils/update_cc_test_checks/Inputs/replace-value-regex-across-runs.c.expected
  
clang/test/utils/update_cc_test_checks/Inputs/resolve-tmp-conflict.cpp.expected
  clang/test/utils/update_cc_test_checks/annotations.test
  clang/test/utils/update_cc_test_checks/check-globals.test
  clang/test/utils/update_cc_test_checks/generated-funcs.test
  clang/test/utils/update_cc_test_checks/global-hex-value-regex.test
  clang/test/utils/update_cc_test_checks/global-value-regex.test
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.funcattrs.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.plain.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.globals.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.globals.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.globals.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.globals.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/pre-process.ll.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.plain.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.globals.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.noglobals.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/various_ir_values.ll.funcsig.transitiveglobals.expected
  llvm/test/tools/UpdateTestChecks/update_test_checks/generated_funcs.test
  
llvm/test/tools/UpdateTestChecks/update_test_checks/generated_funcs_prefix_reuse.test
  llvm/test/tools/UpdateTestChecks/update_test_checks/various_ir_values.test
  llvm/utils/UpdateTestChecks/common.py
  llvm/utils/update_cc_test_checks.py
  llvm/utils/update_test_checks.py

Index: llvm/utils/update_test_checks.py
===
--- llvm/utils/update_test_checks.py
+++ llvm/utils/update_test_checks.py
@@ -59,7 +59,7 @@
   help='Remove attribute annotations (#0) from the end of check line')
   parser.add_argument('--check-attributes', action='store_true',
 

[PATCH] D151339: [OpenCL] Add cl_ext_image_raw10_raw12 extension

2023-05-24 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
Herald added subscribers: Naghasan, ldrumm, yaxunl.
Herald added a project: All.
svenvh requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add the defines for the `cl_ext_image_raw10_raw12` extension.

Draft extension specification is at 
https://github.com/KhronosGroup/OpenCL-Docs/pull/919


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151339

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/test/Headers/opencl-c-header.cl


Index: clang/test/Headers/opencl-c-header.cl
===
--- clang/test/Headers/opencl-c-header.cl
+++ clang/test/Headers/opencl-c-header.cl
@@ -187,6 +187,9 @@
 #if __opencl_c_ext_fp64_local_atomic_min_max != 1
 #error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_min_max"
 #endif
+#if __opencl_c_ext_image_raw10_raw12 != 1
+#error "Incorrectly defined __opencl_c_ext_image_raw10_raw12"
+#endif
 
 #else
 
@@ -271,6 +274,9 @@
 #ifdef __opencl_c_ext_fp64_local_atomic_min_max
 #error "Incorrectly __opencl_c_ext_fp64_local_atomic_min_max defined"
 #endif
+#ifdef __opencl_c_ext_image_raw10_raw12
+#error "Incorrectly __opencl_c_ext_image_raw10_raw12 defined"
+#endif
 
 #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -45,6 +45,7 @@
 #define __opencl_c_ext_fp32_local_atomic_add 1
 #define __opencl_c_ext_fp32_global_atomic_min_max 1
 #define __opencl_c_ext_fp32_local_atomic_min_max 1
+#define __opencl_c_ext_image_raw10_raw12 1
 
 #endif // defined(__SPIR__) || defined(__SPIRV__)
 #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
@@ -474,6 +475,10 @@
 #define CLK_HALF_FLOAT0x10DD
 #define CLK_FLOAT 0x10DE
 #define CLK_UNORM_INT24   0x10DF
+#ifdef __opencl_c_ext_image_raw10_raw12
+#define CLK_UNSIGNED_INT_RAW10_EXT 0x10E3
+#define CLK_UNSIGNED_INT_RAW12_EXT 0x10E4
+#endif // __opencl_c_ext_image_raw10_raw12
 
 // Channel order, numbering must be aligned with cl_channel_order in cl.h
 //


Index: clang/test/Headers/opencl-c-header.cl
===
--- clang/test/Headers/opencl-c-header.cl
+++ clang/test/Headers/opencl-c-header.cl
@@ -187,6 +187,9 @@
 #if __opencl_c_ext_fp64_local_atomic_min_max != 1
 #error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_min_max"
 #endif
+#if __opencl_c_ext_image_raw10_raw12 != 1
+#error "Incorrectly defined __opencl_c_ext_image_raw10_raw12"
+#endif
 
 #else
 
@@ -271,6 +274,9 @@
 #ifdef __opencl_c_ext_fp64_local_atomic_min_max
 #error "Incorrectly __opencl_c_ext_fp64_local_atomic_min_max defined"
 #endif
+#ifdef __opencl_c_ext_image_raw10_raw12
+#error "Incorrectly __opencl_c_ext_image_raw10_raw12 defined"
+#endif
 
 #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -45,6 +45,7 @@
 #define __opencl_c_ext_fp32_local_atomic_add 1
 #define __opencl_c_ext_fp32_global_atomic_min_max 1
 #define __opencl_c_ext_fp32_local_atomic_min_max 1
+#define __opencl_c_ext_image_raw10_raw12 1
 
 #endif // defined(__SPIR__) || defined(__SPIRV__)
 #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
@@ -474,6 +475,10 @@
 #define CLK_HALF_FLOAT0x10DD
 #define CLK_FLOAT 0x10DE
 #define CLK_UNORM_INT24   0x10DF
+#ifdef __opencl_c_ext_image_raw10_raw12
+#define CLK_UNSIGNED_INT_RAW10_EXT 0x10E3
+#define CLK_UNSIGNED_INT_RAW12_EXT 0x10E4
+#endif // __opencl_c_ext_image_raw10_raw12
 
 // Channel order, numbering must be aligned with cl_channel_order in cl.h
 //
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148216: Add support for annotations in UpdateTestChecks (NFC)

2023-05-24 Thread Henrik G Olsson via Phabricator via cfe-commits
hnrklssn added inline comments.



Comment at: 
clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected:12
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[X]], align 4
+// CHECK-NEXT:ret i32 [[TMP1]]
+//

nikic wrote:
> nikic wrote:
> > hnrklssn wrote:
> > > hnrklssn wrote:
> > > > nikic wrote:
> > > > > hnrklssn wrote:
> > > > > > delcypher wrote:
> > > > > > > @hnrklssn I just noticed we don't have a `CHECK` for what `META2` 
> > > > > > > actually refers to. Should we?
> > > > > > > 
> > > > > > > Not something that has to be fixed in this patch, more just an 
> > > > > > > observation.
> > > > > > Indeed this is true for metadata in general, presumably because the 
> > > > > > RHS often refer to things like other metadata identifiers. In the 
> > > > > > case of annotations they seem to always refer to simple strings 
> > > > > > however, so it would be feasible to do a straight match without 
> > > > > > having to do recursive matching or complex regexes to determine 
> > > > > > which part of the metadata to match against.
> > > > > > 
> > > > > > In many cases with metadata attached to IR nodes, multiple nodes 
> > > > > > refer to the same metadata node, so at least you verify that they 
> > > > > > still are consistent. But I agree that verifying the content would 
> > > > > > be a great future addition.
> > > > > You need to pass `--check-globals` to check the actual metadata.
> > > > When I add that to this test case it adds
> > > > 
> > > > ```
> > > > //.
> > > > // CHECK: attributes #0 = { noinline nounwind optnone 
> > > > "min-legal-vector-width"="0" "no-trapping-math"="true" 
> > > > "stack-protector-buffer-size"="8" 
> > > > "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
> > > > //.
> > > > // CHECK: !0 = !{i32 1, !"wchar_size", i32 4}
> > > > // CHECK: !1 = !{!"clang version 17.0.0 
> > > > (g...@github.com:llvm/llvm-project.git 
> > > > 684914f47cf59e9ab6d8b0f73c58ca6272ea28d4)"}
> > > > // CHECK: !2 = !{!"auto-init"}
> > > > //.
> > > > ```
> > > > 
> > > > So it seems to just be doing a simple literal matching on all metadata, 
> > > > regardless of whether we captured that metadata in any filecheck 
> > > > variable. And it still doesn't use the META2 variable to match the 
> > > > definition. Am I missing something? If we use the literal metadata 
> > > > names instead of variable matching for the definitions, there isn't 
> > > > much point in doing variable matching for the metadata uses either, 
> > > > since the test still very much relies on the metadata numbering being 
> > > > stable.
> > > @nikic Do you have more information to add about how metadata definition 
> > > matchers can be generated without hardcoding everything (which is kind of 
> > > the opposite of what this patch is trying to do), or in general if you're 
> > > happy with the state of the PR?
> > This works fine with update_test_checks, so it must be some bug in 
> > update_cc_test_checks in particular. From a quick look, I suspect it's 
> > because 
> > https://github.com/llvm/llvm-project/blob/3d05ab6d3e24e76ff53b8d7d623c436b4be5b809/llvm/utils/update_cc_test_checks.py#L447
> >  hardcodes a True value, while update_test_checks makes this dependent on 
> > `--preserve-names`, which is disabled by default there.
> Or maybe just test this with update_test_checks? This change is valuable for 
> that script as well, and it doesn't have this extra issue.
I couldn't find any uses of 
`--preserve-names` in the entire repo (not even in tests for 
update_test_checks), so I went ahead and changed update_cc_test_checks to pass 
True instead.

While at it I added 2 new options to match some, but not necessarily all, 
globals. I set the least verbose one (other than "none") as the default, 
emitting checks for the definitions of all globals that we emit matches for in 
the IR. Do you agree that this is reasonable?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148216/new/

https://reviews.llvm.org/D148216

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


[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-05-24 Thread Xi Ruoyao via Phabricator via cfe-commits
xry111 added a comment.

If you are really determined to do this, then OK.  I'm in a very bad
mood and I don't want to spend my mental strength on debating (esp. on a
corner case unlikely to affect "real" code) anymore.

But remember to add a entry in GCC 14 changes.html, and test this thing:

struct Empty {};

struct Something : Empty
{

  double a, b;

};

If we are not careful enough we may introduce a ABI mismatch between -
std=c++14 and -std=c++17 here.  See https://gcc.gnu.org/PR94383.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151298/new/

https://reviews.llvm.org/D151298

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


[PATCH] D146809: [clang-repl] Implement Value pretty printing

2023-05-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I didn't have the chance to complete my review (this is a pretty massive 
change), but here are some in-progress comments.




Comment at: clang/include/clang/Interpreter/Interpreter.h:105
 
+  Parser &getParser() const;
+

const mismatch here -- should be an overload set where the const member 
function returns a const reference and the non-const member function returns 
the non-const reference. (This is true in general, I see we've got other such 
functions that are const-qualified but returning non-const references.)

(Not critical to fix, but would be a nice follow-up NFC to correct these sorts 
of things; retro-fitting const correctness is hard, so we should strive for 
const correct by default for new code whenever possible.)



Comment at: clang/lib/Headers/__clang_interpreter_runtime_printvalue.h:1-3
+//===--- __clang_interpreter_runtime_printvalue.h - Incremental Compiation and
+// Execution---*- C++
+//-*-===//

er, not certain the best way to repair this, but wrapping the comment isn't it. 
Maybe drop the "Incremental Compilation and Execution" bit?



Comment at: clang/lib/Headers/__clang_interpreter_runtime_printvalue.h:28
+
+// We should include it somewhere instead of duplicating it...
+#if __has_attribute(visibility) && 
\





Comment at: clang/lib/Headers/__clang_interpreter_runtime_printvalue.h:33
+#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
+#define REPL_EXTERNAL_VISIBILITY __attribute__((visibility("default")))
+#else

You should use reserved identifiers where possible so as not to conflict with 
user-defined macros.



Comment at: clang/lib/Headers/__clang_interpreter_runtime_printvalue.h:50
+// Below overloads are all defined in the library itself.
+REPL_EXTERNAL_VISIBILITY std::string PrintValueRuntime(const void *Ptr);
+

I wonder if it makes some degree of sense to use macros to declare these, so 
that it's easier to see there's a consistent pattern and which types are 
supported. e.g.,
```
#define __DECL_PRINT_VALUE_RUNTIME(type) __REPL_EXTERNAL_VISIBILITY std::string 
PrintValueRuntime(const type *__Ptr)

__DECL_PRINT_VALUE_RUNTIME(void);
__DECL_PRINT_VALUE_RUNTIME(void *);
__DECL_PRINT_VALUE_RUNTIME(bool);
...

#undef __DECL_PRINT_VALUE_RUNTIME
```
I also wonder: should this header have a C interface so it can be used from a C 
context, or is the repl context in which this is included only ever C++?



Comment at: clang/lib/Headers/__clang_interpreter_runtime_printvalue.h:92
+
+namespace repl_runtime_detail {
+





Comment at: clang/lib/Headers/__clang_interpreter_runtime_printvalue.h:96
+// standards.
+template  struct repl_make_void { typedef void type; };
+

(and so forth in this header -- basically, every identifier should be in the 
reserved namespace unless it's the public API being exposed.)



Comment at: clang/lib/Interpreter/Interpreter.cpp:434
+
+llvm::Expected Interpreter::CompileDecl(Decl *D) {
+  assert(D && "The Decl being compiled can't be null");

Any way to make this take a `const Decl *` instead?



Comment at: clang/lib/Interpreter/InterpreterUtils.cpp:108
+  const DeclContext *DC = D->getDeclContext();
+  if (const NamespaceDecl *NS = dyn_cast(DC)) {
+while (NS && NS->isInline()) {





Comment at: clang/lib/Interpreter/InterpreterUtils.cpp:111
+  // Ignore inline namespace;
+  NS = dyn_cast_or_null(NS->getDeclContext());
+}





Comment at: clang/lib/Interpreter/InterpreterUtils.cpp:117-122
+  if (const auto *TD = dyn_cast(DC)) {
+return CreateNestedNameSpecifier(Ctx, TD, FullyQualify);
+  }
+  if (const TypedefNameDecl *TDD = dyn_cast(DC)) {
+return CreateNestedNameSpecifier(Ctx, TDD, FullyQualify);
+  }





Comment at: clang/lib/Interpreter/InterpreterUtils.cpp:133-136
+  const NamedDecl *Outer =
+  llvm::dyn_cast_or_null(D->getDeclContext());
+  const NamespaceDecl *OuterNs =
+  llvm::dyn_cast_or_null(D->getDeclContext());





Comment at: clang/lib/Interpreter/InterpreterUtils.cpp:139-140
+
+if (const CXXRecordDecl *CXXD =
+llvm::dyn_cast(D->getDeclContext())) {
+





Comment at: clang/lib/Interpreter/InterpreterUtils.cpp:157-158
+  D = *(clTempl->spec_begin());
+  Outer = llvm::dyn_cast(D);
+  OuterNs = llvm::dyn_cast(D);
+}





Comment at: clang/lib/Interpreter/InterpreterUtils.cpp:163-168
+if (OuterNs) {
+  return CreateNestedNameSpecifier(Ctx, OuterNs);
+}
+if (const auto *TD = llvm::dyn_cast(Ou

[PATCH] D148216: Add support for annotations in UpdateTestChecks (NFC)

2023-05-24 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: 
clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected:12
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[X]], align 4
+// CHECK-NEXT:ret i32 [[TMP1]]
+//

hnrklssn wrote:
> nikic wrote:
> > nikic wrote:
> > > hnrklssn wrote:
> > > > hnrklssn wrote:
> > > > > nikic wrote:
> > > > > > hnrklssn wrote:
> > > > > > > delcypher wrote:
> > > > > > > > @hnrklssn I just noticed we don't have a `CHECK` for what 
> > > > > > > > `META2` actually refers to. Should we?
> > > > > > > > 
> > > > > > > > Not something that has to be fixed in this patch, more just an 
> > > > > > > > observation.
> > > > > > > Indeed this is true for metadata in general, presumably because 
> > > > > > > the RHS often refer to things like other metadata identifiers. In 
> > > > > > > the case of annotations they seem to always refer to simple 
> > > > > > > strings however, so it would be feasible to do a straight match 
> > > > > > > without having to do recursive matching or complex regexes to 
> > > > > > > determine which part of the metadata to match against.
> > > > > > > 
> > > > > > > In many cases with metadata attached to IR nodes, multiple nodes 
> > > > > > > refer to the same metadata node, so at least you verify that they 
> > > > > > > still are consistent. But I agree that verifying the content 
> > > > > > > would be a great future addition.
> > > > > > You need to pass `--check-globals` to check the actual metadata.
> > > > > When I add that to this test case it adds
> > > > > 
> > > > > ```
> > > > > //.
> > > > > // CHECK: attributes #0 = { noinline nounwind optnone 
> > > > > "min-legal-vector-width"="0" "no-trapping-math"="true" 
> > > > > "stack-protector-buffer-size"="8" 
> > > > > "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
> > > > > //.
> > > > > // CHECK: !0 = !{i32 1, !"wchar_size", i32 4}
> > > > > // CHECK: !1 = !{!"clang version 17.0.0 
> > > > > (g...@github.com:llvm/llvm-project.git 
> > > > > 684914f47cf59e9ab6d8b0f73c58ca6272ea28d4)"}
> > > > > // CHECK: !2 = !{!"auto-init"}
> > > > > //.
> > > > > ```
> > > > > 
> > > > > So it seems to just be doing a simple literal matching on all 
> > > > > metadata, regardless of whether we captured that metadata in any 
> > > > > filecheck variable. And it still doesn't use the META2 variable to 
> > > > > match the definition. Am I missing something? If we use the literal 
> > > > > metadata names instead of variable matching for the definitions, 
> > > > > there isn't much point in doing variable matching for the metadata 
> > > > > uses either, since the test still very much relies on the metadata 
> > > > > numbering being stable.
> > > > @nikic Do you have more information to add about how metadata 
> > > > definition matchers can be generated without hardcoding everything 
> > > > (which is kind of the opposite of what this patch is trying to do), or 
> > > > in general if you're happy with the state of the PR?
> > > This works fine with update_test_checks, so it must be some bug in 
> > > update_cc_test_checks in particular. From a quick look, I suspect it's 
> > > because 
> > > https://github.com/llvm/llvm-project/blob/3d05ab6d3e24e76ff53b8d7d623c436b4be5b809/llvm/utils/update_cc_test_checks.py#L447
> > >  hardcodes a True value, while update_test_checks makes this dependent on 
> > > `--preserve-names`, which is disabled by default there.
> > Or maybe just test this with update_test_checks? This change is valuable 
> > for that script as well, and it doesn't have this extra issue.
> I couldn't find any uses of 
> `--preserve-names` in the entire repo (not even in tests for 
> update_test_checks), so I went ahead and changed update_cc_test_checks to 
> pass True instead.
> 
> While at it I added 2 new options to match some, but not necessarily all, 
> globals. I set the least verbose one (other than "none") as the default, 
> emitting checks for the definitions of all globals that we emit matches for 
> in the IR. Do you agree that this is reasonable?
That sounds like a nice approach. My main question would be whether 
`--check-globals seen` is the right default: My gut feeling here is that this 
will introduce additional checks for attributes/metadata in tests that don't 
actually care about it, but I'm not particularly sure about that.

You might want to do some mass test regeneration and take a look over the diff 
to see how useful the changes would be.

If we do change the default, the default change likely need to be part of 
`--version 3` to avoid substantial test churn.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148216/new/

https://reviews.llvm.org/D148216

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


[PATCH] D151192: [clang-tidy] have bugprone-unchecked-optional-access check boost::optional usage

2023-05-24 Thread Giel van Schijndel via Phabricator via cfe-commits
muggenhor added a comment.

FYI: I've added a set of tests. But in the process discovered there's at least 
one assumption that doesn't hold for boost::optional. So I'll have to adjust 
the implementation for that. That's a bit more involved change, so will take 
some time.

(Specifically the assumption is that converting constructors/assignment 
operators are templates themselves: `assert(F.getTemplateSpecializationArgs() 
!= nullptr);` in `valueOrConversionHasValue`).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151192/new/

https://reviews.llvm.org/D151192

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


[PATCH] D151320: [clang] Add `// expected-maybe-no-diagnostics` comment to VerifyDiagnosticConsumer

2023-05-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

> This patch introduces a `// expected-maybe-not-diagnostic` that silence

typo in the summary, it introduces `// expected-maybe-no-diagnostics`

To save other reviewers some clicking around, the reason why this is being 
proposed is because we want to use the `split-file` utility to separate 
monolithic DR tests into individual test cases to keep them hermetic. We could 
require each individual test within the greater file to specify `// 
expected-no-diagnostics`, but that adds quite a bit of noise to the test file 
due to how often those comments need to repeat. The idea behind this patch is 
that we can use one `// expected-maybe-no-diagnostics` marking in a header file 
that is force included on the RUN lines for the file. This way, each split off 
file says "if you get no diagnostics, that's fine". In the case where the file 
legitimately has no diagnostics, we pass that test. But in the case where the 
file does expect diagnostics, we avoid the "expected no diagnostics, but got 
diagnostics" failure mode. This allows us to continue to group DRs by number 
instead of by whether they expect diagnostics or not.




Comment at: clang/include/clang/Frontend/VerifyDiagnosticConsumer.h:255
+HasOtherExpectedDirectives,
+HasExpectedMaybeNoDiagnostics
   };




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151320/new/

https://reviews.llvm.org/D151320

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


[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/test/Preprocessor/predefined-macros-no-warnings.c:5
+// warnings suppressed by default.
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple arc
+// RUN: %clang_cc1 %s -E -o /dev/null -Wsystem-headers -Werror -triple xcore

john.brawn wrote:
> aaron.ballman wrote:
> > So the expectation is that any warnings that are emitted would be upgraded 
> > to an error and the test would be flagged as a failure because %clang_cc1 
> > would return nonzero in that case?
> > 
> > (I was thrown for a loop by not using `-verify` and `// 
> > expected-no-diagnostics`)
> > 
> > Pretty sure `-Eonly` is equivalent (it runs the preprocessor without 
> > emitting output, so no extra overhead from piping to /dev/null).
> Yes the intent is for the test to fail on any warning. Using `-Werror` and 
> not `-verify` means that on failure you get which macro caused the error:
> ```
> Exit Code: 1
> 
> Command Output (stderr):
> --
> :351:9: error: redefining builtin macro 
> [-Werror,-Wbuiltin-macro-redefined]
> #define __LITTLE_ENDIAN__ 1
> ^
> 1 error generated.
> 
> --
> ```
> whereas `-verify` just outputs
> ```
> Exit Code: 1
> 
> Command Output (stderr):
> --
> error: 'error' diagnostics seen but not expected:
>   Line 351: redefining builtin macro
> 1 error generated.
> 
> --
> ```
> 
> Using `-Eonly` makes sense, I'll do that.
Oh, that's a handy failure mechanism, thank you for pointing that out!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150966/new/

https://reviews.llvm.org/D150966

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


[PATCH] D151342: [Clang] Correctly handle generic lambda used as default template argument.

2023-05-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adjust the template pparameter depth when parsing default
template arguments as they may introduce generic lambda whose parameters
are not substituted at the same depth.

Fixes #62611


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151342

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/SemaCXX/cxx2a-template-lambdas.cpp


Index: clang/test/SemaCXX/cxx2a-template-lambdas.cpp
===
--- clang/test/SemaCXX/cxx2a-template-lambdas.cpp
+++ clang/test/SemaCXX/cxx2a-template-lambdas.cpp
@@ -43,3 +43,30 @@
 }
 static_assert(outer() == 123);
 template int *outer(); // expected-note {{in instantiation}}
+
+
+namespace GH62611 {
+template 
+struct C {
+  static constexpr auto B = A;
+};
+
+int test() {
+  C<>::B(42);
+}
+
+namespace AutoParam
+{
+template 
+auto B = A;
+static_assert(B<>(42) == 42);
+}
+
+namespace TypeParam
+{
+template 
+auto B = T{};
+static_assert(B<>(42) == 42);
+}
+
+}
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -841,10 +841,17 @@
   // we introduce the type parameter into the local scope.
   SourceLocation EqualLoc;
   ParsedType DefaultArg;
-  if (TryConsumeToken(tok::equal, EqualLoc))
+  if (TryConsumeToken(tok::equal, EqualLoc)) {
+// The default argument may declare template parameters, notably
+// if it contains a generic lambda, so we need to increase
+// the template depth as these parameters would not be instantiated
+// at the current level.
+TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
+CurTemplateDepthTracker.addDepth(1);
 DefaultArg =
 ParseTypeName(/*Range=*/nullptr, DeclaratorContext::TemplateTypeArg)
 .get();
+  }
 
   NamedDecl *NewDecl = Actions.ActOnTypeParameter(getCurScope(),
   TypenameKeyword, EllipsisLoc,
@@ -1030,6 +1037,14 @@
   //   end of the template-parameter-list rather than a greater-than
   //   operator.
   GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
+
+  // The default argument may declare template parameters, notably
+  // if it contains a generic lambda, so we need to increase
+  // the template depth as these parameters would not be instantiated
+  // at the current level.
+  TemplateParameterDepthRAII CurTemplateDepthTracker(
+  TemplateParameterDepth);
+  CurTemplateDepthTracker.addDepth(1);
   EnterExpressionEvaluationContext ConstantEvaluated(
   Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
   DefaultArg =
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -485,6 +485,8 @@
   (`#114 `_)
 - Fix parsing of `auto(x)`, when it is surrounded by parentheses.
   (`#62494 `_)
+- Fix handling of generic lambda used as template arguments.
+  (`#62611 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/cxx2a-template-lambdas.cpp
===
--- clang/test/SemaCXX/cxx2a-template-lambdas.cpp
+++ clang/test/SemaCXX/cxx2a-template-lambdas.cpp
@@ -43,3 +43,30 @@
 }
 static_assert(outer() == 123);
 template int *outer(); // expected-note {{in instantiation}}
+
+
+namespace GH62611 {
+template 
+struct C {
+  static constexpr auto B = A;
+};
+
+int test() {
+  C<>::B(42);
+}
+
+namespace AutoParam
+{
+template 
+auto B = A;
+static_assert(B<>(42) == 42);
+}
+
+namespace TypeParam
+{
+template 
+auto B = T{};
+static_assert(B<>(42) == 42);
+}
+
+}
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -841,10 +841,17 @@
   // we introduce the type parameter into the local scope.
   SourceLocation EqualLoc;
   ParsedType DefaultArg;
-  if (TryConsumeToken(tok::equal, EqualLoc))
+  if (TryConsumeToken(tok::equal, EqualLoc)) {
+// The default argument may declare template parameters, notably
+// if it contains a generic lambda, so we need to increase
+// the template depth as these parameters would not be instantiated
+// at the current level.
+TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
+CurTemplateDepthTracker.addDepth(1);
 DefaultArg =
 ParseTypeName(/*Range=*/nullptr, De

[PATCH] D151344: Reland "[CMake] Bumps minimum version to 3.20.0.

2023-05-24 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Mordante added reviewers: glandium, hans, thakis.
Herald added subscribers: libc-commits, bviyer, ekilmer, Moerafaat, zero9178, 
Enna1, bzcheeseman, ayermolo, sdasgup3, wenzhicui, wrengr, cota, teijeong, 
rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, jvesely, Joonsoo, 
liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, rriddle, 
mehdi_amini, mstorsjo, whisperity.
Herald added a reviewer: bollu.
Herald added a reviewer: ldionne.
Herald added a reviewer: rafauler.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
Herald added a reviewer: NoQ.
Herald added projects: libc-project, Flang, All.
Mordante requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, libcxx-commits, openmp-commits, 
lldb-commits, Sanitizers, cfe-commits, jplehr, yota9, sstefan1, 
stephenneuendorffer, nicolasvasilache, jdoerfert.
Herald added projects: clang, Sanitizers, LLDB, libc++, OpenMP, libc++abi, 
libunwind, MLIR, LLVM.
Herald added a reviewer: libc++.
Herald added a reviewer: libc++abi.
Herald added a reviewer: libunwind.

This reverts commit d763c6e5e2d0a6b34097aa7dabca31e9aff9b0b6 
.

Adds the patch by @hans from
https://github.com/llvm/llvm-project/issues/62719


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151344

Files:
  bolt/runtime/CMakeLists.txt
  clang/CMakeLists.txt
  clang/tools/scan-build-py/tests/functional/exec/CMakeLists.txt
  cmake/Modules/CMakePolicy.cmake
  compiler-rt/CMakeLists.txt
  compiler-rt/lib/builtins/CMakeLists.txt
  compiler-rt/lib/crt/CMakeLists.txt
  flang/CMakeLists.txt
  flang/lib/Decimal/CMakeLists.txt
  flang/runtime/CMakeLists.txt
  libc/CMakeLists.txt
  libc/examples/hello_world/CMakeLists.txt
  libclc/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxxabi/CMakeLists.txt
  libunwind/CMakeLists.txt
  libunwind/src/CMakeLists.txt
  lld/CMakeLists.txt
  lldb/CMakeLists.txt
  lldb/tools/debugserver/CMakeLists.txt
  llvm-libgcc/CMakeLists.txt
  llvm/CMakeLists.txt
  llvm/docs/CMake.rst
  llvm/docs/GettingStarted.rst
  llvm/docs/ReleaseNotes.rst
  mlir/CMakeLists.txt
  mlir/examples/standalone/CMakeLists.txt
  openmp/CMakeLists.txt
  openmp/cmake/DetectTestCompiler/CMakeLists.txt
  openmp/docs/SupportAndFAQ.rst
  openmp/libompd/src/CMakeLists.txt
  openmp/libomptarget/plugins/remote/src/CMakeLists.txt
  openmp/runtime/src/CMakeLists.txt
  openmp/tools/Modules/FindOpenMPTarget.cmake
  openmp/tools/Modules/README.rst
  polly/CMakeLists.txt
  pstl/CMakeLists.txt
  runtimes/CMakeLists.txt

Index: runtimes/CMakeLists.txt
===
--- runtimes/CMakeLists.txt
+++ runtimes/CMakeLists.txt
@@ -1,16 +1,13 @@
 # This file handles building LLVM runtime sub-projects.
-cmake_minimum_required(VERSION 3.13.4)
-if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
-  message(WARNING
-"Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
-"minimum version of CMake required to build LLVM will become 3.20.0, and "
-"using an older CMake will become an error. Please upgrade your CMake to "
-"at least 3.20.0 now to avoid issues in the future!")
-endif()
-project(Runtimes C CXX ASM)
+cmake_minimum_required(VERSION 3.20.0)
 
 # Add path for custom and the LLVM build's modules to the CMake module path.
 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
+include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
+  NO_POLICY_SCOPE)
+
+project(Runtimes C CXX ASM)
+
 list(INSERT CMAKE_MODULE_PATH 0
   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
Index: pstl/CMakeLists.txt
===
--- pstl/CMakeLists.txt
+++ pstl/CMakeLists.txt
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 #
 #===--===##
-cmake_minimum_required(VERSION 3.13.4)
+cmake_minimum_required(VERSION 3.20.0)
 
 set(PARALLELSTL_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/pstl/internal/pstl_config.h")
 file(STRINGS "${PARALLELSTL_VERSION_FILE}" PARALLELSTL_VERSION_SOURCE REGEX "#define _PSTL_VERSION .*$")
Index: polly/CMakeLists.txt
===
--- polly/CMakeLists.txt
+++ polly/CMakeLists.txt
@@ -1,14 +1,7 @@
 # Check if this is a in tree build.
 if (NOT DEFINED LLVM_MAIN_SRC_DIR)
   project(Polly)
-  cmake_minimum_required(VERSION 3.13.4)
-  if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
-message(WARNING
-  "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
-  "minimum version of CMake required to build LLVM will become 3.20.0, and "
-  "using an older CMake will become an error. Please upgrade your CMake to "
-  "at least 3.20.0 now to avoid issues in the fu

[PATCH] D144509: [CMake] Bumps minimum version to 3.20.0.

2023-05-24 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

I've created D151344  @glandium @hans @thakis 
I really would appreciate when you can test the patch locally to avoid another 
revert round.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144509/new/

https://reviews.llvm.org/D144509

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


[PATCH] D151320: [clang] Add `// expected-maybe-no-diagnostics` comment to VerifyDiagnosticConsumer

2023-05-24 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill updated this revision to Diff 525216.
Endill added a comment.

Add missing comma after enum item


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151320/new/

https://reviews.llvm.org/D151320

Files:
  clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
  clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
  clang/test/Frontend/verify-maybe-no-diagnostics.c

Index: clang/test/Frontend/verify-maybe-no-diagnostics.c
===
--- /dev/null
+++ clang/test/Frontend/verify-maybe-no-diagnostics.c
@@ -0,0 +1,106 @@
+// RUN: %clang_cc1 -DTEST_A1 -verify %s
+// RUN: %clang_cc1 -DTEST_B1 -verify %s
+// RUN: %clang_cc1 -DTEST_B2 -verify %s
+// RUN: %clang_cc1 -DTEST_C1 -verify %s
+// RUN: %clang_cc1 -DTEST_C2 -verify %s
+// RUN: not %clang_cc1 -DTEST_D1 -verify %s 2>&1 | FileCheck --check-prefix=D1-CHECK %s
+// RUN: not %clang_cc1 -DTEST_D2 -verify %s 2>&1 | FileCheck --check-prefix=D2-CHECK %s
+// RUN: not %clang_cc1 -DTEST_D3 -verify %s 2>&1 | FileCheck --check-prefix=D3-CHECK %s
+// RUN: not %clang_cc1 -DTEST_D4 -verify %s 2>&1 | FileCheck --check-prefix=D4-CHECK %s
+// RUN: not %clang_cc1 -DTEST_D5 -verify %s 2>&1 | FileCheck --check-prefix=D5-CHECK %s
+// RUN: not %clang_cc1 -DTEST_D6 -verify %s 2>&1 | FileCheck --check-prefix=D6-CHECK %s
+
+#ifdef TEST_A1
+// expected-maybe-no-diagnostics
+#endif
+
+#ifdef TEST_B1
+// expected-maybe-no-diagnostics
+// expected-no-diagnostics
+#endif
+
+#ifdef TEST_B2
+// expected-no-diagnostics
+// expected-maybe-no-diagnostics
+#endif
+
+#ifdef TEST_C1
+// expected-maybe-no-diagnostics
+#error test_c1
+// expected-error@-1 {{test_c1}}
+#endif
+
+#ifdef TEST_C2
+#error test_c2
+// expected-error@-1 {{test_c2}}
+// expected-maybe-no-diagnostics
+#endif
+
+#ifdef TEST_D1
+// expected-maybe-no-diagnostics
+#error test_d1
+// expected-error@-1 {{test_d1}}
+// expected-no-diagnostics
+
+//  D1-CHECK: error: 'error' diagnostics seen but not expected:
+// D1-CHECK-NEXT:   {{.*}} 'expected-no-diagnostics' directive cannot follow other expected directives
+// D1-CHECK-NEXT: 1 error generated.
+#endif
+
+#ifdef TEST_D2
+// expected-maybe-no-diagnostics
+// expected-no-diagnostics
+#error test_d2
+// expected-error@-1 {{test_d2}}
+
+//  D2-CHECK: error: 'error' diagnostics seen but not expected:
+// D2-CHECK-NEXT:   {{test_d2}}
+// D2-CHECK-NEXT:   {{.*}} expected directive cannot follow 'expected-no-diagnostics' directive
+// D2-CHECK-NEXT: 2 errors generated.
+#endif
+
+#ifdef TEST_D3
+// expected-no-diagnostics
+// expected-maybe-no-diagnostics
+#error test_d3
+// expected-error@-1 {{test_d3}}
+
+//  D3-CHECK: error: 'error' diagnostics seen but not expected:
+// D3-CHECK-NEXT:   {{test_d3}}
+// D3-CHECK-NEXT:   {{.*}} expected directive cannot follow 'expected-no-diagnostics' directive
+// D3-CHECK-NEXT: 2 errors generated.
+#endif
+
+#ifdef TEST_D4
+// expected-no-diagnostics
+#error test_d4
+// expected-error@-1 {{test_d4}}
+// expected-maybe-no-diagnostics
+
+//  D4-CHECK: error: 'error' diagnostics seen but not expected:
+// D4-CHECK-NEXT:   {{test_d4}}
+// D4-CHECK-NEXT:   {{.*}} expected directive cannot follow 'expected-no-diagnostics' directive
+// D4-CHECK-NEXT: 2 errors generated.
+#endif
+
+#ifdef TEST_D5
+#error test_d5
+// expected-error@-1 {{test_d5}}
+// expected-no-diagnostics
+// expected-maybe-no-diagnostics
+
+//  D5-CHECK: error: 'error' diagnostics seen but not expected:
+// D5-CHECK-NEXT:   {{.*}} 'expected-no-diagnostics' directive cannot follow other expected directives
+// D5-CHECK-NEXT: 1 error generated.
+#endif
+
+#ifdef TEST_D6
+#error test_d6
+// expected-error@-1 {{test_d6}}
+// expected-maybe-no-diagnostics
+// expected-no-diagnostics
+
+//  D6-CHECK: error: 'error' diagnostics seen but not expected:
+// D6-CHECK-NEXT:   {{.*}} 'expected-no-diagnostics' directive cannot follow other expected directives
+// D6-CHECK-NEXT: 1 error generated.
+#endif
Index: clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
===
--- clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -462,7 +462,11 @@
   D.DL = ED ? &ED->Remarks : nullptr;
 else if (DToken.endswith(DType="-note"))
   D.DL = ED ? &ED->Notes : nullptr;
-else if (DToken.endswith(DType="-no-diagnostics")) {
+else if (DToken.endswith(DType="-maybe-no-diagnostics")) {
+  if (Status == VerifyDiagnosticConsumer::HasNoDirectives)
+Status = VerifyDiagnosticConsumer::HasExpectedMaybeNoDiagnostics;
+  continue;
+} else if (DToken.endswith(DType="-no-diagnostics")) {
   NoDiag = true;
   if (D.RegexKind)
 continue;
Index: clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
===
--- clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
+++ clang/include/cl

[PATCH] D151320: [clang] Add `// expected-maybe-no-diagnostics` comment to VerifyDiagnosticConsumer

2023-05-24 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill marked an inline comment as done.
Endill added a comment.

Thank for for providing a nice explanation!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151320/new/

https://reviews.llvm.org/D151320

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


[clang] 78bf8a0 - [clang] Don't define predefined macros multiple times

2023-05-24 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-05-24T17:28:41+01:00
New Revision: 78bf8a0a2212c1826ce2a9c0f98c73e9b9b16367

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

LOG: [clang] Don't define predefined macros multiple times

Fix several instances of macros being defined multiple times
in several targets. Most of these are just simple duplication in a
TargetInfo or OSTargetInfo of things already defined in
InitializePredefinedMacros or InitializeStandardPredefinedMacros,
but there are a few that aren't:
 * AArch64 defines a couple of feature macros for armv8.1a that are
   handled generically by getTargetDefines.
 * CSKY needs to take care when CPUName and ArchName are the same.
 * Many os/target combinations result in __ELF__ being defined twice.
   Instead define __ELF__ just once in InitPreprocessor based on
   the Triple, which already knows what the object format is based
   on os and target.

These changes shouldn't change the final result of which macros are
defined, with the exception of the changes to __ELF__ where if you
explicitly specify the object type in the triple then this affects
if __ELF__ is defined, e.g. --target=i686-windows-elf results in it
being defined where it wasn't before, but this is more accurate as an
ELF file is in fact generated.

Differential Revision: https://reviews.llvm.org/D150966

Added: 
clang/test/Preprocessor/predefined-macros-no-warnings.c

Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/ARM.cpp
clang/lib/Basic/Targets/AVR.cpp
clang/lib/Basic/Targets/CSKY.cpp
clang/lib/Basic/Targets/Hexagon.cpp
clang/lib/Basic/Targets/Le64.cpp
clang/lib/Basic/Targets/MSP430.cpp
clang/lib/Basic/Targets/OSTargets.h
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/Basic/Targets/VE.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Preprocessor/init-ve.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 3840139d27434..ea9995fbe82ee 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -238,8 +238,6 @@ void AArch64TargetInfo::fillValidCPUList(
 void AArch64TargetInfo::getTargetDefinesARMV81A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_QRDMX", "1");
-  Builder.defineMacro("__ARM_FEATURE_ATOMICS", "1");
-  Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
 }
 
 void AArch64TargetInfo::getTargetDefinesARMV82A(const LangOptions &Opts,
@@ -335,16 +333,6 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   Builder.defineMacro("__aarch64__");
   // Inline assembly supports AArch64 flag outputs.
   Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
-  // For bare-metal.
-  if (getTriple().getOS() == llvm::Triple::UnknownOS &&
-  getTriple().isOSBinFormatELF())
-Builder.defineMacro("__ELF__");
-
-  // Target properties.
-  if (!getTriple().isOSWindows() && getTriple().isArch64Bit()) {
-Builder.defineMacro("_LP64");
-Builder.defineMacro("__LP64__");
-  }
 
   std::string CodeModel = getTargetOpts().CodeModel;
   if (CodeModel == "default")
@@ -1523,7 +1511,6 @@ void DarwinAArch64TargetInfo::getOSDefines(const 
LangOptions &Opts,
   else
 Builder.defineMacro("__ARM64_ARCH_8__");
   Builder.defineMacro("__ARM_NEON__");
-  Builder.defineMacro("__LITTLE_ENDIAN__");
   Builder.defineMacro("__REGISTER_PREFIX__", "");
   Builder.defineMacro("__arm64", "1");
   Builder.defineMacro("__arm64__", "1");

diff  --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 588357c83bfa8..6a57261c01789 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -711,10 +711,9 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   // For bare-metal none-eabi.
   if (getTriple().getOS() == llvm::Triple::UnknownOS &&
   (getTriple().getEnvironment() == llvm::Triple::EABI ||
-   getTriple().getEnvironment() == llvm::Triple::EABIHF)) {
-Builder.defineMacro("__ELF__");
-if (Opts.CPlusPlus)
-  Builder.defineMacro("_GNU_SOURCE");
+   getTriple().getEnvironment() == llvm::Triple::EABIHF) &&
+  Opts.CPlusPlus) {
+Builder.defineMacro("_GNU_SOURCE");
   }
 
   // Target properties.

diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index 5c75bae2d8121..85ca4bc30c461 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -450,7 +450,6 @@ void AVRTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   Builder.defineMacro("AVR");
   Builder.defineMacro("__AVR");
   Builder.defineMacro("__AVR__");
-  Builder.defineMacro("__ELF__");
 
   if (ABI == "avrtiny")
  

[PATCH] D150966: [clang] Don't define predefined macros multiple times

2023-05-24 Thread John Brawn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG78bf8a0a2212: [clang] Don't define predefined macros 
multiple times (authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150966/new/

https://reviews.llvm.org/D150966

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/CSKY.cpp
  clang/lib/Basic/Targets/Hexagon.cpp
  clang/lib/Basic/Targets/Le64.cpp
  clang/lib/Basic/Targets/MSP430.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/VE.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/init-ve.c
  clang/test/Preprocessor/predefined-macros-no-warnings.c

Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- /dev/null
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -0,0 +1,199 @@
+// Check that the predefined macros don't contain anything that causes a
+// warning, which needs -Wsystem-headers to detect as the predefined macros
+// are in the  file which is treated as a system header and so has
+// warnings suppressed by default.
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arc
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple xcore
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple hexagon
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple hexagon-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple lanai
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_32-darwin
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-darwin
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-cloudabi
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-fuchsia
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-linux-openhos
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-openbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-win32-gnu
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64-win32-msvc
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-fuchsia
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple aarch64_be-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-darwin
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-cloudabi
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-fuchsia
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-linux-openhos
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-liteos
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-openbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-rtems
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-nacl
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-cygnus
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-gnu
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-itanium
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple arm-win32-msvc
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-linux
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-freebsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-netbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-openbsd
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple armeb-rtems
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple avr
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple bpfeb
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple bpfel
+// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple msp430
+//

[PATCH] D150528: [Clang][Attribute] Improve the AST/diagnoses fidelity of alignas and _Alignas

2023-05-24 Thread Yurong via Phabricator via cfe-commits
yronglin updated this revision to Diff 525224.
yronglin added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150528/new/

https://reviews.llvm.org/D150528

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/AttrImpl.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/Sema/aix-attr-aligned-vector-warn.c
  clang/test/Sema/aix-attr-aligned-vector-warn.cpp
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/attr-cxx0x.cpp
  clang/test/SemaCXX/builtin-align-cxx.cpp
  clang/test/SemaCXX/cxx11-attr-print.cpp
  clang/test/SemaCXX/sizeless-1.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -508,6 +508,16 @@
   OS << "assert(!is" << getLowerName() << "Expr);\n";
   OS << "return " << getLowerName() << "Type;\n";
   OS << "  }";
+
+  OS << "  std::optional getCached" << getUpperName()
+ << "Value() const {\n";
+  OS << "return " << getLowerName() << "Cache;\n";
+  OS << "  }";
+
+  OS << "  void setCached" << getUpperName()
+ << "Value(unsigned AlignVal) {\n";
+  OS << "" << getLowerName() << "Cache = AlignVal;\n";
+  OS << "  }";
 }
 
 void writeAccessorDefinitions(raw_ostream &OS) const override {
@@ -530,21 +540,6 @@
   OS << "  return " << getLowerName()
  << "Type->getType()->containsErrors();\n";
   OS << "}\n";
-
-  // FIXME: Do not do the calculation here
-  // FIXME: Handle types correctly
-  // A null pointer means maximum alignment
-  OS << "unsigned " << getAttrName() << "Attr::get" << getUpperName()
- << "(ASTContext &Ctx) const {\n";
-  OS << "  assert(!is" << getUpperName() << "Dependent());\n";
-  OS << "  if (is" << getLowerName() << "Expr)\n";
-  OS << "return " << getLowerName() << "Expr ? " << getLowerName()
- << "Expr->EvaluateKnownConstInt(Ctx).getZExtValue()"
- << " * Ctx.getCharWidth() : "
- << "Ctx.getTargetDefaultAlignForAttributeAligned();\n";
-  OS << "  else\n";
-  OS << "return 0; // FIXME\n";
-  OS << "}\n";
 }
 
 void writeASTVisitorTraversal(raw_ostream &OS) const override {
@@ -601,7 +596,8 @@
   OS << "union {\n";
   OS << "Expr *" << getLowerName() << "Expr;\n";
   OS << "TypeSourceInfo *" << getLowerName() << "Type;\n";
-  OS << "};";
+  OS << "};\n";
+  OS << "std::optional " << getLowerName() << "Cache;\n";
 }
 
 void writePCHReadArgs(raw_ostream &OS) const override {
@@ -628,14 +624,21 @@
 }
 
 std::string getIsOmitted() const override {
-  return "!is" + getLowerName().str() + "Expr || !" + getLowerName().str()
- + "Expr";
+  return "!((is" + getLowerName().str() + "Expr && " +
+ getLowerName().str() + "Expr) || (!is" + getLowerName().str() +
+ "Expr && " + getLowerName().str() + "Type))";
 }
 
 void writeValue(raw_ostream &OS) const override {
   OS << "\";\n";
-  OS << "" << getLowerName()
+  OS << "if (is" << getLowerName() << "Expr && " << getLowerName()
+ << "Expr)";
+  OS << "  " << getLowerName()
  << "Expr->printPretty(OS, nullptr, Policy);\n";
+  OS << "if (!is" << getLowerName() << "Expr && " << getLowerName()
+ << "Type)";
+  OS << "  " << getLowerName()
+ << "Type->getType().print(OS, Policy);\n";
   OS << "OS << \"";
 }
 
Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -73,7 +73,7 @@
   svint8_t __attribute__((aligned(4))) aligned_int8_2; // expected-error {{'aligned' attribute cannot be applied to sizeless type 'svint8_t'}}
   svint8_t _Alignas(int) aligned_int8_3;   // expected-error {{'_Alignas' attribute cannot be applied to sizeless type 'svint8_t'}}
 
-  int _Alignas(svint8_t) aligned_int; // expected-error {{invalid application of 'alignof' to sizeless type 'svint8_t'}}
+  int _Alignas(svint8_t) aligned_int; // expected-error {{invalid application of '_Alignas' to sizeless type 'svint8_t'}}
 
   // Using pointers to sizeless data isn't wrong here, but because the
   // type is incomplete, it doesn't provide any alignment guarantees.
Index: clang/test/SemaCXX/cxx11-attr-print.cpp
===
--- clang/test/SemaCXX/cxx11-attr-print.cpp
+++ clang/test/SemaCXX/cxx11-

[PATCH] D150528: [Clang][Attribute] Improve the AST/diagnoses fidelity of alignas and _Alignas

2023-05-24 Thread Yurong via Phabricator via cfe-commits
yronglin marked 2 inline comments as done.
yronglin added a comment.

Thanks, maybe I can do these trivially change in separate patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150528/new/

https://reviews.llvm.org/D150528

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


  1   2   3   >