[clang] 4357571 - [Clang] Fix crash caused by line splicing in doc comment

2023-04-12 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-04-12T10:07:51+02:00
New Revision: 43575719d0c6d8cf5afedf39f6d89f69231aedc4

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

LOG: [Clang] Fix crash caused by line splicing in doc comment

Because the comment parser does not support slices,
we emit a warning for comments that do contain
a splice within their delimiter, and do not add them as
documentation comment.

Fixes #62054

Reviewed By: shafik, aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/RawCommentList.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/Sema.cpp
clang/test/Lexer/comment-escape.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7dff43ba30930..dd66c71122999 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -290,6 +290,8 @@ Bug Fixes in This Version
   (`#61142 `_)
 - Clang now better diagnose placeholder types constrained with a concept that 
is
   not a type concept.
+- Fix crash when a doc comment contains a line splicing.
+  (`#62054 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/include/clang/AST/RawCommentList.h 
b/clang/include/clang/AST/RawCommentList.h
index 1bb8d7ce40a90..a293e219e2502 100644
--- a/clang/include/clang/AST/RawCommentList.h
+++ b/clang/include/clang/AST/RawCommentList.h
@@ -115,6 +115,17 @@ class RawComment {
 return extractBriefText(Context);
   }
 
+  bool hasUnsupportedSplice(const SourceManager &SourceMgr) const {
+if (!isInvalid())
+  return false;
+StringRef Text = getRawText(SourceMgr);
+if (Text.size() < 6 || Text[0] != '/')
+  return false;
+if (Text[1] == '*')
+  return Text[Text.size() - 1] != '/' || Text[Text.size() - 2] != '*';
+return Text[1] != '/';
+  }
+
   /// Returns sanitized comment text, suitable for presentation in editor UIs.
   /// E.g. will transform:
   /// // This is a long multiline comment.

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 379554b1f..cd5930d385e69 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11377,6 +11377,8 @@ def err_coro_invalid_addr_of_label : Error<
 let CategoryName = "Documentation Issue" in {
 def warn_not_a_doxygen_trailing_member_comment : Warning<
   "not a Doxygen trailing comment">, InGroup, DefaultIgnore;
+def warn_splice_in_doxygen_comment : Warning<
+  "line splicing in Doxygen comments are not supported">, 
InGroup, DefaultIgnore;
 } // end of documentation issue category
 
 let CategoryName = "Nullability Issue" in {

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 89ac016f60e97..e1b309bd01938 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2390,7 +2390,7 @@ void Sema::ActOnComment(SourceRange Comment) {
   SourceMgr.isInSystemHeader(Comment.getBegin()))
 return;
   RawComment RC(SourceMgr, Comment, LangOpts.CommentOpts, false);
-  if (RC.isAlmostTrailingComment()) {
+  if (RC.isAlmostTrailingComment() || RC.hasUnsupportedSplice(SourceMgr)) {
 SourceRange MagicMarkerRange(Comment.getBegin(),
  Comment.getBegin().getLocWithOffset(3));
 StringRef MagicMarkerText;
@@ -2401,6 +2401,11 @@ void Sema::ActOnComment(SourceRange Comment) {
 case RawComment::RCK_OrdinaryC:
   MagicMarkerText = "/**<";
   break;
+case RawComment::RCK_Invalid:
+  // FIXME: are there other scenarios that could produce an invalid
+  // raw comment here?
+  Diag(Comment.getBegin(), diag::warn_splice_in_doxygen_comment);
+  return;
 default:
   llvm_unreachable("if this is an almost Doxygen comment, "
"it should be ordinary");

diff  --git a/clang/test/Lexer/comment-escape.c 
b/clang/test/Lexer/comment-escape.c
index 191e65441dd47..e9851caf2ce21 100644
--- a/clang/test/Lexer/comment-escape.c
+++ b/clang/test/Lexer/comment-escape.c
@@ -1,6 +1,38 @@
-// RUN: %clang -fsyntax-only %s 
+// RUN: %clang -fsyntax-only -Wdocumentation %s
 // rdar://6757323
 // foo \
 
 #define blork 32
 
+// GH62054
+
+/**<*\
+/
+//expected-warning@-2 {{escaped newline between}} \
+//expected-warning@-2 {{line splicing in Doxygen comments are not supported}}
+
+/**<*\ 
+/
+//expected-warning@-2 {{escaped newline between}} \
+//expected-warning@-2 {{backslash and newline separated by space}} \
+//expected-warning@-2 {{line splicing in Doxygen comments are not sup

[PATCH] D148029: [Clang] Fix crash caused by line splicing in doc comment

2023-04-12 Thread Corentin Jabot 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 rG43575719d0c6: [Clang] Fix crash caused by line splicing in 
doc comment (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148029

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/RawCommentList.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/Sema.cpp
  clang/test/Lexer/comment-escape.c

Index: clang/test/Lexer/comment-escape.c
===
--- clang/test/Lexer/comment-escape.c
+++ clang/test/Lexer/comment-escape.c
@@ -1,6 +1,38 @@
-// RUN: %clang -fsyntax-only %s 
+// RUN: %clang -fsyntax-only -Wdocumentation %s
 // rdar://6757323
 // foo \
 
 #define blork 32
 
+// GH62054
+
+/**<*\
+/
+//expected-warning@-2 {{escaped newline between}} \
+//expected-warning@-2 {{line splicing in Doxygen comments are not supported}}
+
+/**<*\	
+/
+//expected-warning@-2 {{escaped newline between}} \
+//expected-warning@-2 {{backslash and newline separated by space}} \
+//expected-warning@-2 {{line splicing in Doxygen comments are not supported}}
+
+
+/*<*\
+/
+//expected-warning@-2 {{escaped newline between}}  \
+//expected-warning@-2 {{line splicing in Doxygen comments are not supported}}
+
+/*<*\	
+/
+//expected-warning@-2 {{escaped newline between}} \
+//expected-warning@-2 {{backslash and newline separated by space}} \
+//expected-warning@-2 {{line splicing in Doxygen comments are not supported}}
+
+/\
+*<**/
+//expected-warning@-2 {{line splicing in Doxygen comments are not supported}}
+
+/\
+/<*
+//expected-warning@-2 {{line splicing in Doxygen comments are not supported}}
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -2390,7 +2390,7 @@
   SourceMgr.isInSystemHeader(Comment.getBegin()))
 return;
   RawComment RC(SourceMgr, Comment, LangOpts.CommentOpts, false);
-  if (RC.isAlmostTrailingComment()) {
+  if (RC.isAlmostTrailingComment() || RC.hasUnsupportedSplice(SourceMgr)) {
 SourceRange MagicMarkerRange(Comment.getBegin(),
  Comment.getBegin().getLocWithOffset(3));
 StringRef MagicMarkerText;
@@ -2401,6 +2401,11 @@
 case RawComment::RCK_OrdinaryC:
   MagicMarkerText = "/**<";
   break;
+case RawComment::RCK_Invalid:
+  // FIXME: are there other scenarios that could produce an invalid
+  // raw comment here?
+  Diag(Comment.getBegin(), diag::warn_splice_in_doxygen_comment);
+  return;
 default:
   llvm_unreachable("if this is an almost Doxygen comment, "
"it should be ordinary");
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11377,6 +11377,8 @@
 let CategoryName = "Documentation Issue" in {
 def warn_not_a_doxygen_trailing_member_comment : Warning<
   "not a Doxygen trailing comment">, InGroup, DefaultIgnore;
+def warn_splice_in_doxygen_comment : Warning<
+  "line splicing in Doxygen comments are not supported">, InGroup, DefaultIgnore;
 } // end of documentation issue category
 
 let CategoryName = "Nullability Issue" in {
Index: clang/include/clang/AST/RawCommentList.h
===
--- clang/include/clang/AST/RawCommentList.h
+++ clang/include/clang/AST/RawCommentList.h
@@ -115,6 +115,17 @@
 return extractBriefText(Context);
   }
 
+  bool hasUnsupportedSplice(const SourceManager &SourceMgr) const {
+if (!isInvalid())
+  return false;
+StringRef Text = getRawText(SourceMgr);
+if (Text.size() < 6 || Text[0] != '/')
+  return false;
+if (Text[1] == '*')
+  return Text[Text.size() - 1] != '/' || Text[Text.size() - 2] != '*';
+return Text[1] != '/';
+  }
+
   /// Returns sanitized comment text, suitable for presentation in editor UIs.
   /// E.g. will transform:
   /// // This is a long multiline comment.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -290,6 +290,8 @@
   (`#61142 `_)
 - Clang now better diagnose placeholder types constrained with a concept that is
   not a type concept.
+- Fix crash when a doc comment contains a line splicing.
+  (`#62054 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/l

[clang] ce1fb03 - [clang][analyzer] Improve bug reports of StdLibraryFunctionsChecker.

2023-04-12 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2023-04-12T10:24:55+02:00
New Revision: ce1fb03db8174ca63fedc6e3aebdd6fb2c4fcfdf

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

LOG: [clang][analyzer] Improve bug reports of StdLibraryFunctionsChecker.

Add an additional explanation of what is wrong if a constraint is
not satisfied, in some cases.
Additionally the bug report generation is changed to use raw_ostream.

Reviewed By: Szelethus, NoQ

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
clang/test/Analysis/std-c-library-functions-arg-constraints-tracking-notes.c
clang/test/Analysis/std-c-library-functions-arg-constraints.c
clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
clang/test/Analysis/stream-note.c
clang/test/Analysis/stream-stdlibraryfunctionargs.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 98f5540cef709..4e3ea0934b6f1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -102,21 +102,19 @@ class StdLibraryFunctionsChecker
   /// Special argument number for specifying the return value.
   static const ArgNo Ret;
 
-  using DescString = SmallString<96>;
-
-  /// Returns the string representation of an argument index.
+  /// Get a string representation of an argument index.
   /// E.g.: (1) -> '1st arg', (2) - > '2nd arg'
-  static SmallString<8> getArgDesc(ArgNo);
-  /// Append textual description of a numeric range [RMin,RMax] to the string
+  static void printArgDesc(ArgNo, llvm::raw_ostream &Out);
+  /// Append textual description of a numeric range [RMin,RMax] to
   /// \p Out.
   static void appendInsideRangeDesc(llvm::APSInt RMin, llvm::APSInt RMax,
 QualType ArgT, BasicValueFactory &BVF,
-DescString &Out);
-  /// Append textual description of a numeric range out of [RMin,RMax] to the
-  /// string \p Out.
+llvm::raw_ostream &Out);
+  /// Append textual description of a numeric range out of [RMin,RMax] to
+  /// \p Out.
   static void appendOutOfRangeDesc(llvm::APSInt RMin, llvm::APSInt RMax,
QualType ArgT, BasicValueFactory &BVF,
-   DescString &Out);
+   llvm::raw_ostream &Out);
 
   class ValueConstraint;
 
@@ -152,21 +150,25 @@ class StdLibraryFunctionsChecker
 
 /// Represents that in which context do we require a description of the
 /// constraint.
-enum class DescriptionKind {
-  /// The constraint is violated.
+enum DescriptionKind {
+  /// Describe a constraint that was violated.
+  /// Description should start with something like "should be".
   Violation,
-  /// We assume that the constraint is satisfied.
+  /// Describe a constraint that was assumed to be true.
   /// This can be used when a precondition is satisfied, or when a summary
   /// case is applied.
+  /// Description should start with something like "is".
   Assumption
 };
 
 /// Give a description that explains the constraint to the user. Used when
 /// a bug is reported or when the constraint is applied and displayed as a
-/// note.
-virtual std::string describe(DescriptionKind DK, const CallEvent &Call,
- ProgramStateRef State,
- const Summary &Summary) const {
+/// note. The description should not mention the argument (getArgNo).
+/// See StdLibraryFunctionsChecker::reportBug about how this function is
+/// used (this function is used not only there).
+virtual void describe(DescriptionKind DK, const CallEvent &Call,
+  ProgramStateRef State, const Summary &Summary,
+  llvm::raw_ostream &Out) const {
   // There are some descendant classes that are not used as argument
   // constraints, e.g. ComparisonConstraint. In that case we can safely
   // ignore the implementation of this function.
@@ -174,6 +176,31 @@ class StdLibraryFunctionsChecker
   "Description not implemented for summary case constraints");
 }
 
+/// Give a description that explains the actual argument value (where the
+/// current ValueConstraint applies to) to the user. This function should 
be
+/// calle

[PATCH] D144003: [clang][analyzer] Improve bug reports of StdLibraryFunctionsChecker.

2023-04-12 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGce1fb03db817: [clang][analyzer] Improve bug reports of 
StdLibraryFunctionsChecker. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144003

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-tracking-notes.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
  clang/test/Analysis/stream-note.c
  clang/test/Analysis/stream-stdlibraryfunctionargs.c

Index: clang/test/Analysis/stream-stdlibraryfunctionargs.c
===
--- clang/test/Analysis/stream-stdlibraryfunctionargs.c
+++ clang/test/Analysis/stream-stdlibraryfunctionargs.c
@@ -42,7 +42,7 @@
 
 void test_fread(void) {
   FILE *fp = tmpfile();
-  size_t ret = fread(buf, size, n, fp); // stdargs-warning{{The 4th argument to 'fread' should not be NULL}}
+  size_t ret = fread(buf, size, n, fp); // stdargs-warning{{The 4th argument to 'fread' is NULL but should not be NULL}}
   clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
   clang_analyzer_eval(ret <= n); // any-warning{{TRUE}}
   clang_analyzer_eval(ret == n); // any-warning{{TRUE}} any-warning{{FALSE}}
@@ -52,7 +52,7 @@
 
 void test_fwrite(void) {
   FILE *fp = tmpfile();
-  size_t ret = fwrite(buf, size, n, fp); // stdargs-warning{{The 4th argument to 'fwrite' should not be NULL}}
+  size_t ret = fwrite(buf, size, n, fp); // stdargs-warning{{The 4th argument to 'fwrite' is NULL but should not be NULL}}
   clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
   clang_analyzer_eval(ret <= n); // any-warning{{TRUE}}
   clang_analyzer_eval(ret == n); // any-warning{{TRUE}} any-warning{{FALSE}}
Index: clang/test/Analysis/stream-note.c
===
--- clang/test/Analysis/stream-note.c
+++ clang/test/Analysis/stream-note.c
@@ -88,8 +88,8 @@
 fclose(F);
 return;
   }
-  fclose(F); // stdargs-warning {{The 1st argument to 'fclose' should not be NULL}}
- // stdargs-note@-1 {{The 1st argument to 'fclose' should not be NULL}}
+  fclose(F); // stdargs-warning {{The 1st argument to 'fclose' is NULL but should not be NULL}}
+ // stdargs-note@-1 {{The 1st argument to 'fclose' is NULL but should not be NULL}}
 }
 
 void check_eof_notes_feof_after_feof(void) {
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
@@ -14,5 +14,5 @@
 
 void test_arg_constraint_on_fun_with_default_param() {
   __defaultparam(nullptr); // \
-  // expected-warning{{The 1st argument to '__defaultparam' should not be NULL}}
+  // expected-warning{{The 1st argument to '__defaultparam' is NULL but should not be NULL}}
 }
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -30,9 +30,9 @@
 
 void test_alnum_concrete(int v) {
   int ret = isalnum(256); // \
-  // report-warning{{The 1st argument to 'isalnum' should be an unsigned char value or EOF}} \
-  // bugpath-warning{{The 1st argument to 'isalnum' should be an unsigned char value or EOF}} \
-  // bugpath-note{{The 1st argument to 'isalnum' should be an unsigned char value or EOF}}
+  // report-warning{{The 1st argument to 'isalnum' is 256 but should be an unsigned char value or EOF}} \
+  // bugpath-warning{{The 1st argument to 'isalnum' is 256 but should be an unsigned char value or EOF}} \
+  // bugpath-note{{The 1st argument to 'isalnum' is 256 but should be an unsigned char value or EOF}}
   (void)ret;
 }
 
@@ -55,9 +55,9 @@
 // bugpath-note{{Taking true branch}}
 
 int ret = isalnum(x); // \
-// report-warning{{The 1st argument to 'isalnum' should be an unsigned char value or EOF}} \
-// bugpath-warning{{The 1st argument to 'isalnum' should be an unsigned char value or EOF}} \
-// bugpath-note{{The 1st argument to 'isalnum' should be an unsigned char value or EOF}}
+// report-warning{{The 1st argument to 'isalnum' is >= 256 but should be an unsigned char value or EOF}} \
+// bugpath-warning{{The 1st argument to 'isalnum' is >= 256 but should be an unsigned char value or EOF}} \
+// bugpath-note{{The 1st argument to 'isalnum' is >= 256 but should be an unsigned char va

[PATCH] D143467: [PowerPC] Add target feature requirement to builtins

2023-04-12 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added a comment.

In D143467#4258380 , @kamaub wrote:

> Sorry I should have requested changes before for this comment below, but I do 
> want these test moved to codegen and expanded, please let me know if anything 
> is unclear.
>
> In D143467#4241667 , @kamaub wrote:
>
>> Can you add a PowerPC codegen test case for `__attribute__((target(`? All of 
>> the updated test cases seem to only test `-target-feature`.
>> The only test case we have for `__attribute((target(` is a sema test 
>> `./clang/test/Sema/ppc-attr-target-inline.c`.
>>
>> Converting the deleted `clang/test/Sema/ppc-mma-builtins.c` and 
>> `clang/test/Sema/ppc-paired-vector-builtins.c` to a codegen test cases
>> like `clang/test/CodeGen/PowerPC/builtins-ppc-htm.c` using FileCheck seems 
>> like a nice solution since it would reintroduce the testing
>> for `+paired-vector-memops,-mma` situations, as well as a for 
>> `__attribute__((target("no-mma")))`

Hi, I updated the case to test builtins used in previous Sema tests when both 
no-mma and no-paired-vector-memops. There's limitation that such codegen error 
message only diagnose one function, so I wrapped them into a single function. 
Not sure if that's the full meaning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143467

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


[PATCH] D132819: [RISCV] Add MC support of RISCV zcmp Extension

2023-04-12 Thread Alex Bradbury via Phabricator via cfe-commits
asb added inline comments.



Comment at: clang/test/Preprocessor/riscv-target-features.c:51
 // CHECK-NOT: __riscv_zcf {{.*$}}
+// CHECK-NOT: __riscv_zcmp
 // CHECK-NOT: __riscv_h {{.*$}}

jrtc27 wrote:
> Does this really belong in an MC patch?
We typically do include this test change in the initial MC layer patch on the 
basis that the change becomes testable as soon as MC layer support is 
introduced (and indeed might be used for e.g. ifdefing inline assembler, so 
isn't really only useful in the presence of codegen/intrinsics support).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132819

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


[PATCH] D148034: [clang][driver] Disable GP relaxation with RISC-V ShadowCallStack

2023-04-12 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

Will `--[no-]relax-gp` make its way into a minor gcc point release or do we 
need to wait for the next major release?

In terms of this breaking GNU users - isn't it the case that without this 
option, they may get silently broken code when using the shadow call stack? 
Breaking loudly and early seems preferable, though of course it would be best 
if it's easily fixable by e.g. updating to a newer released binutils.

One slight tweak might be to avoid adding `--no-relax-gp` if linker relaxation 
is already disabled, though it's not going to matter once binutils gets support 
for --no-relax-gp.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148034

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


[PATCH] D148066: [RISCV] Add Smaia and Ssaia extensions support

2023-04-12 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

This extension doesn't appear to be ratified but you've listed it in the table 
of ratified extensions and treated it as a ratified extension in 
RISCVISAInfo.cpp. I know that given we don't do checking for CSR names the 
distinction feels a bit academic, but I don't think this is the best approach. 
For CSR only extensions like this my feeling is we should review a patch like 
this ahead of ratification, but not land until it's actually ratified. One of 
the main goals (from my perspective at least) for allowing not-yet-ratified 
extensions upstream was to allow collaboration on the implementation, but given 
the simplicity of CSR-only extensions I'm not sure the cost/benefit makes sense 
vs just waiting for ratification when we can be sure the assigned numbers won't 
change. I'd be open to counter arguments though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148066

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


[PATCH] D144638: [lit] Detect Inconsistent File Access Times

2023-04-12 Thread Sam Elliott via Phabricator via cfe-commits
lenary planned changes to this revision.
lenary added a comment.

To be clear: I've not yet addressed @jhenderson's comments above, yet, which 
may require changes to the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144638

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


[PATCH] D148101: [clang] Ensure that Attr::Create(Implicit) chooses a valid syntax

2023-04-12 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm created this revision.
rsandifo-arm added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
rsandifo-arm requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The purpose of this patch and follow-on patches is to ensure that
AttributeCommonInfos always have a syntax that is appropriate for
their kind (i.e. that it matches one of the entries in Attr.td).

The attribute-specific Create and CreateImplicit methods had four
overloads, based on their tail arguments:

(1) no extra arguments
(2) an AttributeCommonInfo
(3) a SourceRange
(4) a SourceRange, a syntax, and (where necessary) a spelling

When (4) had a spelling argument, it defaulted to
SpellingNotCalculated.

One disadvantage of this was that (1) and (3) zero-initialized
the syntax field of the AttributeCommonInfo, which corresponds
to AS_GNU.  But AS_GNU isn't always listed as a possibility
in Attr.td.

This patch therefore removes (1) and (3) and instead provides
the same functionality using default arguments on (4) (a bit
like the existing default argument for the spelling).
The default syntax is taken from the attribute's first valid
spelling.

Doing that raises the question: what should happen for attributes
like AlignNatural and CUDAInvalidTarget that are only ever created
implicitly, and so have no source-code manifestation at all?
The patch adds a new AS_Implicit "syntax" for that case.
The patch also removes the syntax argument for these attributes,
since the syntax must always be AS_Implicit.

For similar reasons, the patch removes the syntax argument if
there is exactly one valid spelling.

Doing this means that AttributeCommonInfo no longer needs the
single-argument constructors.  It is always given a syntax instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148101

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/unittests/AST/DeclTest.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2505,15 +2505,8 @@
   return &R == P.second;
 });
 
-enum class CreateKind {
-  WithAttributeCommonInfo,
-  WithSourceRange,
-  WithNoArgs,
-};
-
 // Emit CreateImplicit factory methods.
-auto emitCreate = [&](bool Implicit, bool DelayedArgsOnly,
-  bool emitFake, CreateKind Kind) {
+auto emitCreate = [&](bool Implicit, bool DelayedArgsOnly, bool emitFake) {
   if (Header)
 OS << "  static ";
   OS << R.getName() << "Attr *";
@@ -2537,10 +2530,7 @@
 OS << ", ";
 DelayedArgs->writeCtorParameters(OS);
   }
-  if (Kind == CreateKind::WithAttributeCommonInfo)
-OS << ", const AttributeCommonInfo &CommonInfo";
-  else if (Kind == CreateKind::WithSourceRange)
-OS << ", SourceRange R";
+  OS << ", const AttributeCommonInfo &CommonInfo";
   OS << ")";
   if (Header) {
 OS << ";\n";
@@ -2549,12 +2539,7 @@
 
   OS << " {\n";
   OS << "  auto *A = new (Ctx) " << R.getName();
-  if (Kind == CreateKind::WithAttributeCommonInfo)
-OS << "Attr(Ctx, CommonInfo";
-  else if (Kind == CreateKind::WithSourceRange)
-OS << "Attr(Ctx, AttributeCommonInfo{R}";
-  else if (Kind == CreateKind::WithNoArgs)
-OS << "Attr(Ctx, AttributeCommonInfo{SourceLocation{}}";
+  OS << "Attr(Ctx, CommonInfo";
 
   if (!DelayedArgsOnly) {
 for (auto const &ai : Args) {
@@ -2606,7 +2591,14 @@
 OS << ", ";
 DelayedArgs->writeCtorParameters(OS);
   }
-  OS << ", SourceRange Range, AttributeCommonInfo::Syntax Syntax";
+  OS << ", SourceRange Range";
+  if (Header)
+OS << " = {}";
+  if (Spellings.size() > 1) {
+OS << ", AttributeCommonInfo::Syntax Syntax";
+if (Header)
+  OS << " = AttributeCommonInfo::AS_" << Spellings[0].variety();
+  }
   if (!ElideSpelling) {
 OS << ", " << R.getName() << "Attr::Spelling S";
 if (Header)
@@ -2626,7 +2618,13 @@
   else
 OS << "NoSemaHandlerAttribute";
 
-  OS << ", Syntax";
+  if (Spellings.size() == 0)
+OS << ", AttributeCommonInfo::AS_Implicit";
+  else if (Spellings.size() == 1)
+OS << ", AttributeCommonInfo::AS_" << Spellings[0].variety();
+  else
+OS << ", Syntax";
+
   if (!ElideSpelling)
 OS << ", S";
   OS << ");\n";
@@ -2651,19 +2649,9 @@
   OS << "}\n\n";
 };
 
-auto emitBothImplicitAndNonCreates = [&](bool DelayedArgsOnly,
- bool emitFake, CreateKind Kind) {
-  emitC

[PATCH] D148102: [clang] Specify attribute syntax & spelling with a single argument

2023-04-12 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm created this revision.
rsandifo-arm added reviewers: erichkeane, aaron.ballman.
Herald added a subscriber: martong.
Herald added a reviewer: shafik.
Herald added a project: All.
rsandifo-arm requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When constructing an attribute, the syntactic form was specified
using two arguments: an attribute-independent syntax type and an
attribute-specific spelling index.  This patch replaces them with
a single argument.

In most cases, that's done using a new Form class that combines the
syntax and spelling into a single object.  This has the minor benefit
of removing a couple of constructors.  But the main purpose is to allow
additional information to be stored as well, beyond just the syntax and
spelling enums.

In the case of the attribute-specific Create and CreateImplicit
functions, the patch instead uses the attribute-specific spelling
enum.  This helps to ensure that the syntax and spelling are
consistent with each other and with the Attr.td definition.

If a Create or CreateImplicit caller specified a syntax and
a spelling, the patch drops the syntax argument and keeps the
spelling.  If the caller instead specified only a syntax
(so that the spelling was SpellingNotCalculated), the patch
simply drops the syntax argument.

There were two cases of the latter: TargetVersion and Weak.
TargetVersionAttrs were created with GNU syntax, which matches
their definition in Attr.td, but which is also the default.
WeakAttrs were created with Pragma syntax, which does not match
their definition in Attr.td.  Dropping the argument switches
them to AS_GNU too (to match [GCC<"weak">]).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148102

Files:
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/HLSLExternalSemaSource.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2378,6 +2378,13 @@
   OS << "#endif // CLANG_ATTR_ACCEPTS_EXPR_PACK\n\n";
 }
 
+static void emitFormInitializer(raw_ostream &OS,
+const FlattenedSpelling &Spelling,
+StringRef SpellingIndex) {
+  OS << "{AttributeCommonInfo::AS_" << Spelling.variety() << ", "
+ << SpellingIndex << "}";
+}
+
 static void emitAttributes(RecordKeeper &Records, raw_ostream &OS,
bool Header) {
   std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
@@ -2595,14 +2602,9 @@
   if (Header)
 OS << " = {}";
   if (Spellings.size() > 1) {
-OS << ", AttributeCommonInfo::Syntax Syntax";
+OS << ", Spelling S";
 if (Header)
-  OS << " = AttributeCommonInfo::AS_" << Spellings[0].variety();
-  }
-  if (!ElideSpelling) {
-OS << ", " << R.getName() << "Attr::Spelling S";
-if (Header)
-  OS << " = static_cast(SpellingNotCalculated)";
+  OS << " = " << SemanticToSyntacticMap[0];
   }
   OS << ")";
   if (Header) {
@@ -2618,15 +2620,31 @@
   else
 OS << "NoSemaHandlerAttribute";
 
-  if (Spellings.size() == 0)
+  if (Spellings.size() == 0) {
 OS << ", AttributeCommonInfo::AS_Implicit";
-  else if (Spellings.size() == 1)
-OS << ", AttributeCommonInfo::AS_" << Spellings[0].variety();
-  else
-OS << ", Syntax";
+  } else if (Spellings.size() == 1) {
+OS << ", ";
+emitFormInitializer(OS, Spellings[0], "0");
+  } else {
+OS << ", (\n";
+std::set Uniques;
+unsigned Idx = 0;
+for (auto I = Spellings.begin(), E = Spellings.end(); I != E;
+ ++I, ++Idx) {
+  const FlattenedSpelling &S = *I;
+  const auto &Name = SemanticToSyntacticMap[Idx];
+  if (Uniques.insert(Name).second) {
+OS << "S == " << Name << " ? AttributeCommonInfo::Form";
+emitFormInitializer(OS, S, "S");
+OS << " :\n";
+  }
+}
+OS << "(llvm_unreachable(\"Unknown attribute spelling!\"), "
+   << " AttributeCommonInfo::Form";
+emitFormInitializer(OS, Spellings[0], "0");
+OS << "))";
+  }
 
-  if (!ElideSpelling)
-OS << ", S";
   OS << ");\n";
   OS << "  return Create";
   if (Implicit)
Ind

[PATCH] D148103: [clang] Allow attributes to be constructed from keyword tokens

2023-04-12 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm created this revision.
rsandifo-arm added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
rsandifo-arm requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds an extra AttributeCommonInfo::Form constructor
for keywords, represented by their TokenKind.  This isn't a
win on its own, but it helps with later patches.

No functional change intended.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148103

Files:
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExprCXX.cpp

Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1300,7 +1300,7 @@
 SourceLocation AttrNameLoc = ConsumeToken();
 Attributes.addNew(AttrName, AttrNameLoc, /*ScopeName=*/nullptr,
   AttrNameLoc, /*ArgsUnion=*/nullptr,
-  /*numArgs=*/0, ParsedAttr::AS_Keyword);
+  /*numArgs=*/0, tok::kw___noinline__);
   } else if (Tok.is(tok::kw___attribute))
 ParseGNUAttributes(Attributes, /*LatePArsedAttrList=*/nullptr, &D);
   else
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -1370,9 +1370,9 @@
  tok::kw___multiple_inheritance,
  tok::kw___virtual_inheritance)) {
 IdentifierInfo *AttrName = Tok.getIdentifierInfo();
+auto Kind = Tok.getKind();
 SourceLocation AttrNameLoc = ConsumeToken();
-attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
- ParsedAttr::AS_Keyword);
+attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0, Kind);
   }
 }
 
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -828,7 +828,8 @@
 void Parser::ParseMicrosoftTypeAttributes(ParsedAttributes &attrs) {
   // Treat these like attributes
   while (true) {
-switch (Tok.getKind()) {
+auto Kind = Tok.getKind();
+switch (Kind) {
 case tok::kw___fastcall:
 case tok::kw___stdcall:
 case tok::kw___thiscall:
@@ -843,7 +844,7 @@
   IdentifierInfo *AttrName = Tok.getIdentifierInfo();
   SourceLocation AttrNameLoc = ConsumeToken();
   attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
-   ParsedAttr::AS_Keyword);
+   Kind);
   break;
 }
 default:
@@ -865,7 +866,7 @@
   SourceLocation AttrNameLoc = ConsumeToken();
   attrs.addNew(AttrName, AttrNameLoc, /*ScopeName=*/nullptr,
/*ScopeLoc=*/SourceLocation{}, /*Args=*/nullptr, /*numArgs=*/0,
-   ParsedAttr::AS_Keyword);
+   tok::kw___funcref);
 }
 
 void Parser::DiagnoseAndSkipExtendedMicrosoftTypeAttributes() {
@@ -910,7 +911,7 @@
 IdentifierInfo *AttrName = Tok.getIdentifierInfo();
 SourceLocation AttrNameLoc = ConsumeToken();
 attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
- ParsedAttr::AS_Keyword);
+ tok::kw___pascal);
   }
 }
 
@@ -920,7 +921,7 @@
 IdentifierInfo *AttrName = Tok.getIdentifierInfo();
 SourceLocation AttrNameLoc = ConsumeToken();
 attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
- ParsedAttr::AS_Keyword);
+ tok::kw___kernel);
   }
 }
 
@@ -929,7 +930,7 @@
 IdentifierInfo *AttrName = Tok.getIdentifierInfo();
 SourceLocation AttrNameLoc = ConsumeToken();
 attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
- ParsedAttr::AS_Keyword);
+ tok::kw___noinline__);
   }
 }
 
@@ -937,7 +938,7 @@
   IdentifierInfo *AttrName = Tok.getIdentifierInfo();
   SourceLocation AttrNameLoc = Tok.getLocation();
   Attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
-   ParsedAttr::AS_Keyword);
+   Tok.getKind());
 }
 
 bool Parser::isHLSLQualifier(const Token &Tok) const {
@@ -946,15 +947,16 @@
 
 void Parser::ParseHLSLQualifiers(ParsedAttributes &Attrs) {
   IdentifierInfo *AttrName = Tok.getIdentifierInfo();
+  auto Kind = Tok.getKind();
   SourceLocation AttrNameLoc = ConsumeToken();
-  Attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
-   ParsedAttr::AS_Keyword);
+  Attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0, Kind);
 }
 
 void Parser::ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs) {
   // Treat these like attributes, even though they're type specifiers.
   while (true) {
-switch (Tok.getKind()) {
+auto Ki

[PATCH] D148104: [clang] Type safety tweak for AttributeCommonInfo::Form

2023-04-12 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm created this revision.
rsandifo-arm added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
rsandifo-arm requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds static functions for constructing most
AttributeCommonInfo::Forms.  Direct construction is only retained where
all fields (currently the syntax and spelling) are specified explicitly.

This is a wash on its own.  The purpose is to allow extra fields
to be added to Form without disrupting all callers.  In particular,
it allows extra information to be stored about keywords without
affecting non-keyword uses.

No functional change intended.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148104

Files:
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseHLSL.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2621,7 +2621,7 @@
 OS << "NoSemaHandlerAttribute";
 
   if (Spellings.size() == 0) {
-OS << ", AttributeCommonInfo::AS_Implicit";
+OS << ", AttributeCommonInfo::Form::Implicit()";
   } else if (Spellings.size() == 1) {
 OS << ", ";
 emitFormInitializer(OS, Spellings[0], "0");
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4893,12 +4893,12 @@
 
 // If we're supposed to infer nullability, do so now.
 if (inferNullability && !inferNullabilityInnerOnlyComplete) {
-  ParsedAttr::Syntax syntax = inferNullabilityCS
-  ? ParsedAttr::AS_ContextSensitiveKeyword
-  : ParsedAttr::AS_Keyword;
+  ParsedAttr::Form form = inferNullabilityCS
+  ? ParsedAttr::Form::ContextSensitiveKeyword()
+  : ParsedAttr::Form::Keyword();
   ParsedAttr *nullabilityAttr = Pool.create(
   S.getNullabilityKeyword(*inferNullability), SourceRange(pointerLoc),
-  nullptr, SourceLocation(), nullptr, 0, syntax);
+  nullptr, SourceLocation(), nullptr, 0, form);
 
   attrs.addAtEnd(nullabilityAttr);
 
@@ -6025,7 +6025,7 @@
   ParsedAttr *attr = D.getAttributePool().create(
   &S.Context.Idents.get("objc_ownership"), SourceLocation(),
   /*scope*/ nullptr, SourceLocation(),
-  /*args*/ &Args, 1, ParsedAttr::AS_GNU);
+  /*args*/ &Args, 1, ParsedAttr::Form::GNU());
   chunk.getAttrs().addAtEnd(attr);
   // TODO: mark whether we did this inference?
 }
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -19862,7 +19862,7 @@
   NamedDecl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc,
  LookupOrdinaryName);
   AttributeCommonInfo Info(AliasName, SourceRange(AliasNameLoc),
-   AttributeCommonInfo::AS_Pragma);
+   AttributeCommonInfo::Form::Pragma());
   AsmLabelAttr *Attr = AsmLabelAttr::CreateImplicit(
   Context, AliasName->getName(), /*IsLiteralLabel=*/true, Info);
 
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -860,7 +860,7 @@
 return;
 
   AttributeCommonInfo Info(Ident, SourceRange(Loc),
-   AttributeCommonInfo::AS_Pragma);
+   AttributeCommonInfo::Form::Pragma());
   D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Info));
 }
 
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -2411,7 +2411,7 @@
 ArgsUnion(Hint.ValueExpr)};
 TempAttrs.addNew(Hint.PragmaNameLoc->Ident, Hint.Range, nullptr,
  Hint.PragmaNameLoc->Loc, ArgHints, 4,
- ParsedAttr::AS_Pragma);
+ ParsedAttr::Form::Pragma());
   }
 
   // Get the next statement.
Index: clang/lib/Parse/ParsePragma.cpp
===
--- clang/lib/Parse/ParsePragma.cpp
+++ clang/lib/Parse/ParsePragma.cpp
@@ -1850,11 +1850,12 @@
 
   if (Tok.isNot(tok::l_paren))
 Attrs.addNew(AttrN

[PATCH] D148105: [clang] Fix FIXME in isAlignasAttribute()

2023-04-12 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm created this revision.
rsandifo-arm added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
rsandifo-arm requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

AttributeCommonInfo::isAlignasAttribute() was used in one place:
isCXX11Attribute().  The intention was for isAlignasAttribute()
to return true for the C++ alignas keyword.  However, as a FIXME
noted, the function also returned true for the C _Alignas keyword.
This meant that isCXX11Attribute() returned true for _Alignas as
well as for alignas.

AttributeCommonInfos are now always constructed with an
AttributeCommonInfo::Form.  We can use that Form to convey whether
a keyword is alignas or not.

The patch uses 1 bit of an 8-bit hole in the current layout
of AttributeCommonInfo.  This might not be the best long-term design,
but it should be easy to adapt the layout if necessary (that is,
if other uses are found for the spare bits).

I don't know of a way of testing this (other than grep -c FIXME)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148105

Files:
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2381,8 +2381,11 @@
 static void emitFormInitializer(raw_ostream &OS,
 const FlattenedSpelling &Spelling,
 StringRef SpellingIndex) {
+  bool IsAlignas =
+  (Spelling.variety() == "Keyword" && Spelling.name() == "alignas");
   OS << "{AttributeCommonInfo::AS_" << Spelling.variety() << ", "
- << SpellingIndex << "}";
+ << SpellingIndex << ", " << (IsAlignas ? "true" : "false")
+ << " /*IsAlignas*/}";
 }
 
 static void emitAttributes(RecordKeeper &Records, raw_ostream &OS,
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -3091,11 +3091,14 @@
   unsigned ParsedKind = Record.readInt();
   unsigned Syntax = Record.readInt();
   unsigned SpellingIndex = Record.readInt();
+  bool IsAlignas = (ParsedKind == AttributeCommonInfo::AT_Aligned &&
+Syntax == AttributeCommonInfo::AS_Keyword &&
+SpellingIndex == AlignedAttr::Keyword_alignas);
 
   AttributeCommonInfo Info(
   AttrName, ScopeName, AttrRange, ScopeLoc,
   AttributeCommonInfo::Kind(ParsedKind),
-  {AttributeCommonInfo::Syntax(Syntax), SpellingIndex});
+  {AttributeCommonInfo::Syntax(Syntax), SpellingIndex, IsAlignas});
 
 #include "clang/Serialization/AttrPCHRead.inc"
 
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4893,9 +4893,9 @@
 
 // If we're supposed to infer nullability, do so now.
 if (inferNullability && !inferNullabilityInnerOnlyComplete) {
-  ParsedAttr::Form form = inferNullabilityCS
-  ? ParsedAttr::Form::ContextSensitiveKeyword()
-  : ParsedAttr::Form::Keyword();
+  ParsedAttr::Form form =
+  inferNullabilityCS ? ParsedAttr::Form::ContextSensitiveKeyword()
+ : ParsedAttr::Form::Keyword(false /*IsAlignAs*/);
   ParsedAttr *nullabilityAttr = Pool.create(
   S.getNullabilityKeyword(*inferNullability), SourceRange(pointerLoc),
   nullptr, SourceLocation(), nullptr, 0, form);
Index: clang/include/clang/Basic/AttributeCommonInfo.h
===
--- clang/include/clang/Basic/AttributeCommonInfo.h
+++ clang/include/clang/Basic/AttributeCommonInfo.h
@@ -76,6 +76,7 @@
   /// Corresponds to the Syntax enum.
   unsigned SyntaxUsed : 4;
   unsigned SpellingIndex : 4;
+  unsigned IsAlignas : 1;
 
 protected:
   static constexpr unsigned SpellingNotCalculated = 0xf;
@@ -85,20 +86,25 @@
   /// including its syntax and spelling.
   class Form {
   public:
-constexpr Form(Syntax SyntaxUsed, unsigned SpellingIndex)
-: SyntaxUsed(SyntaxUsed), SpellingIndex(SpellingIndex) {}
-constexpr Form(tok::TokenKind)
-: SyntaxUsed(AS_Keyword), SpellingIndex(SpellingNotCalculated) {}
+constexpr Form(Syntax SyntaxUsed, unsigned SpellingIndex, bool IsAlignas)
+: SyntaxUsed(SyntaxUsed), SpellingIndex(SpellingIndex),
+  IsAlignas(IsAlignas) {}
+constexpr Form(tok::TokenKind Tok)
+: SyntaxUsed(AS_Keyword), SpellingIndex(SpellingNotCalculated),
+  IsAlignas(Tok == tok::kw_alignas) {}
 
 Syntax getSyntax() const { return Syntax(Synt

[PATCH] D148105: [clang] Fix FIXME in isAlignasAttribute()

2023-04-12 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm added a comment.

FWIW, the original reason for looking at this was to explore ways of removing 
`AS_AttributeLikeKeyword` from https://reviews.llvm.org/D139028 .  I wanted to 
find a way of conveying extra information about a spelling without having to 
change the existing enums.  It seemed like that was essentially the same 
problem as the one described in the FIXME being fixed here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148105

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


[PATCH] D147610: [RISCV][MC] Add support for experimental Zfbfmin extension

2023-04-12 Thread Alex Bradbury via Phabricator via cfe-commits
asb updated this revision to Diff 512743.
asb edited the summary of this revision.
asb added a comment.

Rebase and use the new encoding suggested in 
https://github.com/riscv/riscv-bfloat16/issues/33 - hoping for the commits that 
alter the encoding to be pushed to the spec repo and a new PDF (with new 
version) to be generated ahead of landing this.


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

https://reviews.llvm.org/D147610

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/docs/ReleaseNotes.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZfbfmin.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZfh.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zfbfmin-invalid.s
  llvm/test/MC/RISCV/rv32zfbfmin-valid.s
  llvm/test/MC/RISCV/rv64zhinx-invalid.s
  llvm/test/MC/RISCV/rv64zhinxmin-invalid.s

Index: llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
===
--- llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
+++ llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
@@ -1,7 +1,7 @@
 # RUN: not llvm-mc -triple riscv64 -mattr=+zhinxmin %s 2>&1 | FileCheck %s
 
 # Not support float registers
-flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal){{$}}
+flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts){{$}}
 
 # Invalid instructions
 fsh a5, 12(sp) # CHECK: :[[@LINE]]:5: error: invalid operand for instruction
Index: llvm/test/MC/RISCV/rv64zhinx-invalid.s
===
--- llvm/test/MC/RISCV/rv64zhinx-invalid.s
+++ llvm/test/MC/RISCV/rv64zhinx-invalid.s
@@ -1,7 +1,7 @@
 # RUN: not llvm-mc -triple riscv64 -mattr=+zhinx %s 2>&1 | FileCheck %s
 
 # Not support float registers
-flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal){{$}}
+flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts){{$}}
 
 # Invalid instructions
 fsh a5, 12(sp) # CHECK: :[[@LINE]]:5: error: invalid operand for instruction
Index: llvm/test/MC/RISCV/rv32zfbfmin-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zfbfmin-valid.s
@@ -0,0 +1,56 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zfbfmin,+f -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zfbfmin,+f -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zfbfmin,+d < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zfbfmin,+f -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zfbfmin,+d < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zfbfmin,+f -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: flh ft0, 12(a0)
+# CHECK-ASM: encoding: [0x07,0x10,0xc5,0x00]
+flh f0, 12(a0)
+# CHECK-ASM-AND-OBJ: flh ft1, 4(ra)
+# CHECK-ASM: encoding: [0x87,0x90,0x40,0x00]
+flh f1, +4(ra)
+# CHECK-ASM-AND-OBJ: flh ft2, -2048(a3)
+# CHECK-ASM: encoding: [0x07,0x91,0x06,0x80]
+flh f2, -2048(x13)
+# CHECK-ASM-AND-OBJ: flh ft3, -2048(s1)
+# CHECK-ASM: encoding: [0x87,0x91,0x04,0x80]
+flh f3, %lo(2048)(s1)
+# CHECK-ASM-AND-OBJ: flh ft4, 2047(s2)
+# CHECK-ASM: encoding: [0x07,0x12,0xf9,0x7f]
+flh f4, 2047(s2)
+# CHECK-ASM-AND-OBJ: flh ft5, 0(s3)
+# CHECK-ASM: encoding: [0x87,0x92,0x09,0x00]
+flh f5, 0(s3)
+
+# CHECK-ASM-AND-OBJ: fsh ft6, 2047(s4)
+# CHECK-ASM: encoding: [0xa7,0x1f,0x6a,0x7e]
+fsh f6, 2047(s4)
+# CHECK-ASM-AND-OBJ: fsh ft7, -2048(s5)
+# CHECK-ASM: encoding: [0x27,0x90,0x7a,0x80]
+fsh f7, -2048(s5)
+# CHECK-ASM-AND-OBJ: fsh fs0, -2048(s6)
+# CHECK-ASM: encoding: [0x27,0x10,0x8b,0x80]
+fsh f8, %lo(2048)(s6)
+# CHECK-ASM-AND-OBJ: fsh fs1, 999(s7)
+# CHECK-ASM: encoding: [0xa7,0x93,0x9b,0x3e]
+fsh f9, 999(s7)
+
+# CHECK-ASM-AND-OBJ: fmv.x.h a2, fs7
+# CHECK-ASM: encoding: [0x53,0x86,0x0b,0xe4]
+fmv.x.h a2, fs7
+# CHECK-ASM-AND-OBJ: fmv.h.x ft1, a6
+# CHECK-ASM: encoding: [0xd3,0x00,0x08,0xf4]
+fmv.h.x ft1, a6
+
+# CHECK-ASM-AND-OBJ: fcvt.s.bf16 fa0

[PATCH] D147611: [RISCV][MC] Add support for experimental Zvfbfmin extension

2023-04-12 Thread Alex Bradbury via Phabricator via cfe-commits
asb updated this revision to Diff 512744.
asb added a comment.

Rebase.


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

https://reviews.llvm.org/D147611

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/docs/ReleaseNotes.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfoV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZvfbf.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rvv/zvfbfmin.s

Index: llvm/test/MC/RISCV/rvv/zvfbfmin.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvfbfmin.s
@@ -0,0 +1,42 @@
+# RUN: llvm-mc -triple=riscv32 -show-encoding -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv32 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv32 -filetype=obj -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:| llvm-objdump -d --mattr=+f,+experimental-zvfbfmin - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv32 -filetype=obj -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+# RUN: llvm-mc -triple=riscv64 -show-encoding -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv64 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv64 -filetype=obj -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:| llvm-objdump -d --mattr=+f,+experimental-zvfbfmin - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv64 -filetype=obj -mattr=+f,+experimental-zvfbfmin %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+# CHECK-INST: vfncvtbf16.f.f.w v8, v4, v0.t
+# CHECK-ENCODING: [0x57,0x94,0x4e,0x48]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfmin' (Vector BF16 Converts){{$}}
+# CHECK-UNKNOWN: 57 94 4e 48 
+vfncvtbf16.f.f.w v8, v4, v0.t
+
+# CHECK-INST: vfncvtbf16.f.f.w v8, v4
+# CHECK-ENCODING: [0x57,0x94,0x4e,0x4a]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfmin' (Vector BF16 Converts){{$}}
+# CHECK-UNKNOWN: 57 94 4e 4a 
+vfncvtbf16.f.f.w v8, v4
+
+# CHECK-INST: vfwcvtbf16.f.f.v v8, v4, v0.t
+# CHECK-ENCODING: [0x57,0x94,0x46,0x48]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfmin' (Vector BF16 Converts){{$}}
+# CHECK-UNKNOWN: 57 94 46 48 
+vfwcvtbf16.f.f.v v8, v4, v0.t
+
+# CHECK-INST: vfwcvtbf16.f.f.v v8, v4
+# CHECK-ENCODING: [0x57,0x94,0x46,0x4a]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfmin' (Vector BF16 Converts){{$}}
+# CHECK-UNKNOWN: 57 94 46 4a 
+vfwcvtbf16.f.f.v v8, v4
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -242,3 +242,6 @@
 
 .attribute arch, "rv32if_zfbfmin0p2"
 # CHECK: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin0p2"
+
+.attribute arch, "rv32if_zvfbfmin0p2"
+# CHECK: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfbfmin0p2_zvl32b1p0"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -66,6 +66,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+zve32x -mattr=+experimental-zvksh %s -o - | FileCheck --check-prefix=RV32ZVKSH %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicond %s -o - | FileCheck --check-prefix=RV32ZICOND %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZFBFMIN %s
+; RUN: llc -mtriple=riscv32 -mattr=+f,+experimental-zvfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZVFBFMIN %s
 
 ; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefixes=CHECK,RV64M %s
@@ -139,6 +140,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zve32x -mattr=+experimental-zvksh %s -o - | FileCheck --check-prefix=RV64ZVKSH %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicond %s -o - | FileCheck --check-prefix=RV64ZICOND %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZFBFMIN %s
+; RUN: llc -mtriple=riscv64 -mattr=+f,+experimental-zvfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZVFBFMIN %s
 
 ; CHECK: .attribute 4, 16
 
@@ -207,6 +209,7 @@
 ; RV32ZVKSH: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zvksh0p3_zvl32b1p0"
 ; RV32ZICOND: .attribute 5, "rv32i2p1_zicond1p0"
 ; RV32ZFBFMIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin0p2"
+; RV32ZVFBFMIN: .attribute 5,

[PATCH] D147612: [RISCV][MC] Add support for experimental Zvfbfwma extension

2023-04-12 Thread Alex Bradbury via Phabricator via cfe-commits
asb updated this revision to Diff 512745.
asb added a comment.

Rebase


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

https://reviews.llvm.org/D147612

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/docs/ReleaseNotes.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZvfbf.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv64zhinx-invalid.s
  llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
  llvm/test/MC/RISCV/rvv/zvfbfwma-invalid.s
  llvm/test/MC/RISCV/rvv/zvfbfwma.s

Index: llvm/test/MC/RISCV/rvv/zvfbfwma.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvfbfwma.s
@@ -0,0 +1,68 @@
+# RUN: llvm-mc -triple=riscv32 -show-encoding -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv32 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv32 -filetype=obj -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:| llvm-objdump -d --mattr=+f,+experimental-zvfbfwma - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv32 -filetype=obj -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+# RUN: llvm-mc -triple=riscv64 -show-encoding -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv64 -show-encoding -mattr=+v,+f %s 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv64 -filetype=obj -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:| llvm-objdump -d --mattr=+f,+experimental-zvfbfwma - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv64 -filetype=obj -mattr=+f,+experimental-zvfbfwma %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+# CHECK-INST: vfwmaccbf16.vv v8, v20, v4, v0.t
+# CHECK-ENCODING: [0x57,0x14,0x4a,0x8c]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 57 14 4a 8c 
+vfwmaccbf16.vv v8, v20, v4, v0.t
+
+# CHECK-INST: vfwmaccbf16.vv v8, v20, v4
+# CHECK-ENCODING: [0x57,0x14,0x4a,0x8e]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 57 14 4a 8e 
+vfwmaccbf16.vv v8, v20, v4
+
+# CHECK-INST: vfwmaccbf16.vf v8, fa0, v4, v0.t
+# CHECK-ENCODING: [0x57,0x54,0x45,0x8c]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 57 54 45 8c 
+vfwmaccbf16.vf v8, fa0, v4, v0.t
+
+# CHECK-INST: vfwmaccbf16.vf v8, fa0, v4
+# CHECK-ENCODING: [0x57,0x54,0x45,0x8e]
+# CHECK-ERROR: instruction requires the following: 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 57 54 45 8e 
+vfwmaccbf16.vf v8, fa0, v4
+
+# Check scalar half FP load/store/move included in this extension.
+
+# CHECK-INST: flh ft0, 12(a0)
+# CHECK-ENCODING: [0x07,0x10,0xc5,0x00]
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 07 10 c5 00 
+flh f0, 12(a0)
+
+# CHECK-INST: fsh ft6, 2047(s4)
+# CHECK-ENCODING: [0xa7,0x1f,0x6a,0x7e]
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: a7 1f 6a 7e 
+fsh f6, 2047(s4)
+
+# CHECK-INST: fmv.x.h a2, fs7
+# CHECK-ENCODING: [0x53,0x86,0x0b,0xe4]
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: 53 86 0b e4 
+fmv.x.h a2, fs7
+
+# CHECK-INST: fmv.h.x ft1, a6
+# CHECK-ENCODING: [0xd3,0x00,0x08,0xf4]
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-UNKNOWN: d3 00 08 f4 
+fmv.h.x ft1, a6
Index: llvm/test/MC/RISCV/rvv/zvfbfwma-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvfbfwma-invalid.s
@@ -0,0 +1,11 @@
+# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-zvfbfwma,+d < %s 2>&1 | \
+# RUN:   FileCheck %s
+# RUN: not llvm-mc -triple riscv64 -mattr=+experimental-zvfbfwma,+d < %s 2

[PATCH] D148089: [clang][CodeGen] Break up TargetInfo.cpp [1/6]

2023-04-12 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 created this revision.
Herald added a subscriber: pengfei.
Herald added a project: All.
barannikov88 added reviewers: rjmccall, aaron.ballman, erichkeane.
barannikov88 published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`CCState` is a helper class originally used by the x86 implementation
but has since been abused by other implementations.
Remove this dependency by implementing customized versions of the class
for implementations that need such functionality.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148089

Files:
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9071,13 +9071,17 @@
 
 namespace {
 class LanaiABIInfo : public DefaultABIInfo {
+  struct CCState {
+unsigned FreeRegs;
+  };
+
 public:
   LanaiABIInfo(CodeGen::CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
 
   bool shouldUseInReg(QualType Ty, CCState &State) const;
 
   void computeInfo(CGFunctionInfo &FI) const override {
-CCState State(FI);
+CCState State;
 // Lanai uses 4 registers to pass arguments unless the function has the
 // regparm attribute set.
 if (FI.getHasRegParm()) {
@@ -10092,6 +10096,10 @@
 namespace {
 
 class ARCABIInfo : public DefaultABIInfo {
+  struct CCState {
+unsigned FreeRegs;
+  };
+
 public:
   using DefaultABIInfo::DefaultABIInfo;
 
@@ -10114,7 +10122,7 @@
   }
 
   void computeInfo(CGFunctionInfo &FI) const override {
-CCState State(FI);
+CCState State;
 // ARC uses 8 registers to pass arguments.
 State.FreeRegs = 8;
 


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9071,13 +9071,17 @@
 
 namespace {
 class LanaiABIInfo : public DefaultABIInfo {
+  struct CCState {
+unsigned FreeRegs;
+  };
+
 public:
   LanaiABIInfo(CodeGen::CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
 
   bool shouldUseInReg(QualType Ty, CCState &State) const;
 
   void computeInfo(CGFunctionInfo &FI) const override {
-CCState State(FI);
+CCState State;
 // Lanai uses 4 registers to pass arguments unless the function has the
 // regparm attribute set.
 if (FI.getHasRegParm()) {
@@ -10092,6 +10096,10 @@
 namespace {
 
 class ARCABIInfo : public DefaultABIInfo {
+  struct CCState {
+unsigned FreeRegs;
+  };
+
 public:
   using DefaultABIInfo::DefaultABIInfo;
 
@@ -10114,7 +10122,7 @@
   }
 
   void computeInfo(CGFunctionInfo &FI) const override {
-CCState State(FI);
+CCState State;
 // ARC uses 8 registers to pass arguments.
 State.FreeRegs = 8;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148092: [clang][CodeGen] Break up TargetInfo.cpp [4/6]

2023-04-12 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 created this revision.
Herald added a project: All.
barannikov88 added reviewers: rjmccall, aaron.ballman, erichkeane.
barannikov88 published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Remove `getABIInfo` overrides returning references to target-specific
implementations of `ABIInfo`.
The methods may be convenient, but they are only used in one place and
prevent from `ABIInfo` implementations from being put into anonymous
namespaces in different cpp files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148092

Files:
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -2482,10 +2482,6 @@
 std::make_unique(CGT, /*SwiftErrorInRegister=*/true);
   }
 
-  const X86_64ABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   /// Disable tail call on x86-64. The epilogue code before the tail jump 
blocks
   /// autoreleaseRV/retainRV and autoreleaseRV/unsafeClaimRV optimizations.
   bool markARCOptimizedReturnCallsAsNoTail() const override { return true; }
@@ -2522,7 +2518,8 @@
   bool HasAVXType = false;
   for (CallArgList::const_iterator
  it = args.begin(), ie = args.end(); it != ie; ++it) {
-if (getABIInfo().isPassedUsingAVXType(it->Ty)) {
+if (static_cast(TargetCodeGenInfo::getABIInfo())
+.isPassedUsingAVXType(it->Ty)) {
   HasAVXType = true;
   break;
 }
@@ -6404,10 +6401,6 @@
 SwiftInfo = std::make_unique(CGT);
   }
 
-  const ARMABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
 return 13;
   }
@@ -6426,7 +6419,9 @@
   }
 
   unsigned getSizeOfUnwindException() const override {
-if (getABIInfo().isEABI()) return 88;
+if (static_cast(TargetCodeGenInfo::getABIInfo())
+.isEABI())
+  return 88;
 return TargetCodeGenInfo::getSizeOfUnwindException();
   }
 
@@ -6493,7 +6488,7 @@
 
 Fn->addFnAttr("interrupt", Kind);
 
-ARMABIKind ABI = cast(getABIInfo()).getABIKind();
+ARMABIKind ABI = static_cast(getABIInfo()).getABIKind();
 if (ABI == ARMABIKind::APCS)
   return;
 
@@ -7431,10 +7426,6 @@
 class SystemZTargetCodeGenInfo : public TargetCodeGenInfo {
   ASTContext &Ctx;
 
-  const SystemZABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   // These are used for speeding up the search for a visible vector ABI.
   mutable bool HasVisibleVecABIFlag = false;
   mutable std::set SeenTypes;
@@ -7884,7 +7875,9 @@
 // be passed via "hidden" pointer where any extra alignment is not
 // required (per GCC).
 const Type *SingleEltTy =
-  getABIInfo().GetSingleElementType(QualType(Ty, 0)).getTypePtr();
+static_cast(TargetCodeGenInfo::getABIInfo())
+.GetSingleElementType(QualType(Ty, 0))
+.getTypePtr();
 bool SingleVecEltStruct = SingleEltTy != Ty && SingleEltTy->isVectorType() 
&&
   Ctx.getTypeSize(SingleEltTy) == Ctx.getTypeSize(Ty);
 if (Ty->isVectorType() || SingleVecEltStruct)
@@ -11836,10 +11829,6 @@
 public:
   BPFTargetCodeGenInfo(CodeGenTypes &CGT)
   : TargetCodeGenInfo(std::make_unique(CGT)) {}
-
-  const BPFABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
 };
 
 }


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -2482,10 +2482,6 @@
 std::make_unique(CGT, /*SwiftErrorInRegister=*/true);
   }
 
-  const X86_64ABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   /// Disable tail call on x86-64. The epilogue code before the tail jump blocks
   /// autoreleaseRV/retainRV and autoreleaseRV/unsafeClaimRV optimizations.
   bool markARCOptimizedReturnCallsAsNoTail() const override { return true; }
@@ -2522,7 +2518,8 @@
   bool HasAVXType = false;
   for (CallArgList::const_iterator
  it = args.begin(), ie = args.end(); it != ie; ++it) {
-if (getABIInfo().isPassedUsingAVXType(it->Ty)) {
+if (static_cast(TargetCodeGenInfo::getABIInfo())
+.isPassedUsingAVXType(it->Ty)) {
   HasAVXType = true;
   break;
 }
@@ -6404,10 +6401,6 @@
 SwiftInfo = std::make_unique(CGT);
   }
 
-  const ARMABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
 return 13;
   }
@@ -6426,7 +6419,9 @@
   }
 
   unsigned getSizeOfUnwindException() const override {
-if (ge

[PATCH] D148090: [clang][CodeGen] Break up TargetInfo.cpp [2/6]

2023-04-12 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 created this revision.
Herald added a subscriber: dschuff.
Herald added a project: All.
barannikov88 added reviewers: rjmccall, aaron.ballman, erichkeane.
barannikov88 published this revision for review.
Herald added subscribers: cfe-commits, aheejin.
Herald added a project: clang.

Move `ABIKind` enums out of `*ABIInfo` classes to break the dependency
between `getTargetCodeGenInfo` and the classes.
This will allow to move the classes to different cpp files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148090

Files:
  clang/lib/CodeGen/TargetInfo.cpp

Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -827,19 +827,18 @@
 // This is a very simple ABI that relies a lot on DefaultABIInfo.
 //===--===//
 
-class WebAssemblyABIInfo final : public ABIInfo {
-public:
-  enum ABIKind {
-MVP = 0,
-ExperimentalMV = 1,
-  };
+enum class WebAssemblyABIKind {
+  MVP = 0,
+  ExperimentalMV = 1,
+};
 
-private:
+class WebAssemblyABIInfo final : public ABIInfo {
   DefaultABIInfo defaultInfo;
-  ABIKind Kind;
+  WebAssemblyABIKind Kind;
 
 public:
-  explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes &CGT, ABIKind Kind)
+  explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes &CGT,
+  WebAssemblyABIKind Kind)
   : ABIInfo(CGT), defaultInfo(CGT), Kind(Kind) {}
 
 private:
@@ -863,7 +862,7 @@
 class WebAssemblyTargetCodeGenInfo final : public TargetCodeGenInfo {
 public:
   explicit WebAssemblyTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
-WebAssemblyABIInfo::ABIKind K)
+WebAssemblyABIKind K)
   : TargetCodeGenInfo(std::make_unique(CGT, K)) {
 SwiftInfo =
 std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
@@ -928,7 +927,7 @@
 if (const Type *SeltTy = isSingleElementStruct(Ty, getContext()))
   return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
 // For the experimental multivalue ABI, fully expand all other aggregates
-if (Kind == ABIKind::ExperimentalMV) {
+if (Kind == WebAssemblyABIKind::ExperimentalMV) {
   const RecordType *RT = Ty->getAs();
   assert(RT);
   bool HasBitField = false;
@@ -961,7 +960,7 @@
   if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext()))
 return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
   // For the experimental multivalue ABI, return all other aggregates
-  if (Kind == ABIKind::ExperimentalMV)
+  if (Kind == WebAssemblyABIKind::ExperimentalMV)
 return ABIArgInfo::getDirect();
 }
   }
@@ -4988,21 +4987,19 @@
 // PowerPC-64
 
 namespace {
+enum class PPC64_SVR4_ABIKind {
+  ELFv1 = 0,
+  ELFv2,
+};
+
 /// PPC64_SVR4_ABIInfo - The 64-bit PowerPC ELF (SVR4) ABI information.
 class PPC64_SVR4_ABIInfo : public ABIInfo {
-public:
-  enum ABIKind {
-ELFv1 = 0,
-ELFv2
-  };
-
-private:
   static const unsigned GPRBits = 64;
-  ABIKind Kind;
+  PPC64_SVR4_ABIKind Kind;
   bool IsSoftFloatABI;
 
 public:
-  PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, ABIKind Kind,
+  PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, PPC64_SVR4_ABIKind Kind,
  bool SoftFloatABI)
   : ABIInfo(CGT), Kind(Kind), IsSoftFloatABI(SoftFloatABI) {}
 
@@ -5050,8 +5047,7 @@
 class PPC64_SVR4_TargetCodeGenInfo : public TargetCodeGenInfo {
 
 public:
-  PPC64_SVR4_TargetCodeGenInfo(CodeGenTypes &CGT,
-   PPC64_SVR4_ABIInfo::ABIKind Kind,
+  PPC64_SVR4_TargetCodeGenInfo(CodeGenTypes &CGT, PPC64_SVR4_ABIKind Kind,
bool SoftFloatABI)
   : TargetCodeGenInfo(
 std::make_unique(CGT, Kind, SoftFloatABI)) {
@@ -5150,7 +5146,7 @@
   // Likewise for ELFv2 homogeneous aggregates.
   const Type *Base = nullptr;
   uint64_t Members = 0;
-  if (!AlignAsType && Kind == ELFv2 &&
+  if (!AlignAsType && Kind == PPC64_SVR4_ABIKind::ELFv2 &&
   isAggregateTypeForABI(Ty) && isHomogeneousAggregate(Ty, Base, Members))
 AlignAsType = Base;
 
@@ -5344,7 +5340,7 @@
 // ELFv2 homogeneous aggregates are passed as array types.
 const Type *Base = nullptr;
 uint64_t Members = 0;
-if (Kind == ELFv2 &&
+if (Kind == PPC64_SVR4_ABIKind::ELFv2 &&
 isHomogeneousAggregate(Ty, Base, Members)) {
   llvm::Type *BaseTy = CGT.ConvertType(QualType(Base, 0));
   llvm::Type *CoerceTy = llvm::ArrayType::get(BaseTy, Members);
@@ -5414,7 +5410,7 @@
 // ELFv2 homogeneous aggregates are returned as array types.
 const Type *Base = nullptr;
 uint64_t Members = 0;
-if (Kind == ELFv2 &&
+if (Kind == PPC64_SVR4_ABIKind::ELFv2 &&
 isHomogeneousAggregate(RetTy, Base, Members)) {
   llvm::Type *BaseTy = CGT.ConvertType(QualType(

[PATCH] D148091: [clang][CodeGen] Break up TargetInfo.cpp [3/6]

2023-04-12 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 created this revision.
Herald added a project: All.
barannikov88 added reviewers: rjmccall, aaron.ballman, erichkeane.
barannikov88 published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Don't derive from `DefaultTargetCodeGenInfo`.
This class is going to stay in `TargetInfo.cpp`, whereas its derivants
are going to be moved to separate translation units. Just derive from
the base `TargetCodeGenInfo` class instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148091

Files:
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5064,9 +5064,10 @@
llvm::Value *Address) const override;
 };
 
-class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
+class PPC64TargetCodeGenInfo : public TargetCodeGenInfo {
 public:
-  PPC64TargetCodeGenInfo(CodeGenTypes &CGT) : DefaultTargetCodeGenInfo(CGT) {}
+  PPC64TargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
 
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
 // This is recovered from gcc output.
@@ -8599,10 +8600,10 @@
 
 namespace {
 
-class TCETargetCodeGenInfo : public DefaultTargetCodeGenInfo {
+class TCETargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   TCETargetCodeGenInfo(CodeGenTypes &CGT)
-: DefaultTargetCodeGenInfo(CGT) {}
+: TargetCodeGenInfo(std::make_unique(CGT)) {}
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &M) const override;


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5064,9 +5064,10 @@
llvm::Value *Address) const override;
 };
 
-class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
+class PPC64TargetCodeGenInfo : public TargetCodeGenInfo {
 public:
-  PPC64TargetCodeGenInfo(CodeGenTypes &CGT) : DefaultTargetCodeGenInfo(CGT) {}
+  PPC64TargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
 
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
 // This is recovered from gcc output.
@@ -8599,10 +8600,10 @@
 
 namespace {
 
-class TCETargetCodeGenInfo : public DefaultTargetCodeGenInfo {
+class TCETargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   TCETargetCodeGenInfo(CodeGenTypes &CGT)
-: DefaultTargetCodeGenInfo(CGT) {}
+: TargetCodeGenInfo(std::make_unique(CGT)) {}
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &M) const override;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6d3b779 - Set 'rounding_mode' to 'tonearest' with '#pragma STDC FENV_ACCESS OFF'.

2023-04-12 Thread Zahira Ammarguellat via cfe-commits

Author: Zahira Ammarguellat
Date: 2023-04-12T06:44:45-04:00
New Revision: 6d3b779792fbf9ec5cc119f1812655da01020b7a

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

LOG: Set 'rounding_mode' to 'tonearest' with '#pragma STDC FENV_ACCESS OFF'.

In strict mode the 'roundin_mode' is set to 'dynamic'. Using this pragma to
get out of strict mode doesn't have any effect on the 'rounding_mode'.
See https://godbolt.org/z/zoGTf4j1G
This patch fixes that.

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

Added: 


Modified: 
clang/lib/Sema/SemaAttr.cpp
clang/test/CodeGen/pragma-fenv_access.c

Removed: 




diff  --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 0b76c041bcd7..5080b22ed507 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -1336,6 +1336,7 @@ void Sema::ActOnPragmaFEnvAccess(SourceLocation Loc, bool 
IsEnabled) {
   Diag(Loc, diag::err_pragma_fenv_requires_precise);
   }
   NewFPFeatures.setAllowFEnvAccessOverride(IsEnabled);
+  NewFPFeatures.setRoundingMathOverride(IsEnabled);
   FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
   CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
 }

diff  --git a/clang/test/CodeGen/pragma-fenv_access.c 
b/clang/test/CodeGen/pragma-fenv_access.c
index c986d9cff2a1..afca115ed08d 100644
--- a/clang/test/CodeGen/pragma-fenv_access.c
+++ b/clang/test/CodeGen/pragma-fenv_access.c
@@ -1,13 +1,17 @@
 // RUN: %clang_cc1 -fexperimental-strict-floating-point 
-ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - | 
FileCheck --check-prefixes=CHECK,STRICT %s
+// RUN: %clang_cc1 -fexperimental-strict-floating-point -frounding-math 
-ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - | 
FileCheck --check-prefixes=CHECK,STRICT-RND %s
 // RUN: %clang_cc1 -fexperimental-strict-floating-point 
-ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - 
-fms-extensions -DMS | FileCheck --check-prefixes=CHECK,STRICT %s
+// RUN: %clang_cc1 -fexperimental-strict-floating-point -frounding-math 
-ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - 
-fms-extensions -DMS | FileCheck --check-prefixes=CHECK,STRICT-RND %s
 // RUN: %clang_cc1 -fexperimental-strict-floating-point -triple 
%itanium_abi_triple -emit-llvm %s -o - | FileCheck 
--check-prefixes=CHECK,DEFAULT %s
-
+// RUN: %clang_cc1 -fexperimental-strict-floating-point -frounding-math 
-triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck 
--check-prefixes=CHECK,DEFAULT-RND %s
 
 float func_00(float x, float y) {
   return x + y;
 }
 // CHECK-LABEL: @func_00
 // STRICT: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, 
float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
+// STRICT-RND: call float @llvm.experimental.constrained.fadd.f32(float 
{{.*}}, float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
+// DEFAULT-RND: call float @llvm.experimental.constrained.fadd.f32(float 
{{.*}}, float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.ignore")
 // DEFAULT: fadd float
 
 
@@ -224,3 +228,17 @@ float func_18(float x, float y) {
 // STRICT: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, 
float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
 // DEFAULT: fadd float
 
+#pragma STDC FENV_ACCESS ON
+float func_19(float x, float y) {
+  return x + y;
+}
+// CHECK-LABEL: @func_19
+// STRICT:  call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, 
float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
+
+#pragma STDC FENV_ACCESS OFF
+float func_20(float x, float y) {
+  return x + y;
+}
+// CHECK-LABEL: @func_20
+// STRICT: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, 
float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
+// DEFAULT: fadd float



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


[PATCH] D147733: Set rounding_mode to tonearest in presence of a #pragma STDC FENV_ACCESS OFF.

2023-04-12 Thread Zahira Ammarguellat via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6d3b779792fb: Set 'rounding_mode' to 
'tonearest' with '#pragma STDC FENV_ACCESS OFF'. (authored 
by zahiraam).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147733

Files:
  clang/lib/Sema/SemaAttr.cpp
  clang/test/CodeGen/pragma-fenv_access.c


Index: clang/test/CodeGen/pragma-fenv_access.c
===
--- clang/test/CodeGen/pragma-fenv_access.c
+++ clang/test/CodeGen/pragma-fenv_access.c
@@ -1,13 +1,17 @@
 // RUN: %clang_cc1 -fexperimental-strict-floating-point 
-ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - | 
FileCheck --check-prefixes=CHECK,STRICT %s
+// RUN: %clang_cc1 -fexperimental-strict-floating-point -frounding-math 
-ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - | 
FileCheck --check-prefixes=CHECK,STRICT-RND %s
 // RUN: %clang_cc1 -fexperimental-strict-floating-point 
-ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - 
-fms-extensions -DMS | FileCheck --check-prefixes=CHECK,STRICT %s
+// RUN: %clang_cc1 -fexperimental-strict-floating-point -frounding-math 
-ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - 
-fms-extensions -DMS | FileCheck --check-prefixes=CHECK,STRICT-RND %s
 // RUN: %clang_cc1 -fexperimental-strict-floating-point -triple 
%itanium_abi_triple -emit-llvm %s -o - | FileCheck 
--check-prefixes=CHECK,DEFAULT %s
-
+// RUN: %clang_cc1 -fexperimental-strict-floating-point -frounding-math 
-triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck 
--check-prefixes=CHECK,DEFAULT-RND %s
 
 float func_00(float x, float y) {
   return x + y;
 }
 // CHECK-LABEL: @func_00
 // STRICT: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, 
float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
+// STRICT-RND: call float @llvm.experimental.constrained.fadd.f32(float 
{{.*}}, float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
+// DEFAULT-RND: call float @llvm.experimental.constrained.fadd.f32(float 
{{.*}}, float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.ignore")
 // DEFAULT: fadd float
 
 
@@ -224,3 +228,17 @@
 // STRICT: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, 
float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
 // DEFAULT: fadd float
 
+#pragma STDC FENV_ACCESS ON
+float func_19(float x, float y) {
+  return x + y;
+}
+// CHECK-LABEL: @func_19
+// STRICT:  call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, 
float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
+
+#pragma STDC FENV_ACCESS OFF
+float func_20(float x, float y) {
+  return x + y;
+}
+// CHECK-LABEL: @func_20
+// STRICT: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, 
float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
+// DEFAULT: fadd float
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -1336,6 +1336,7 @@
   Diag(Loc, diag::err_pragma_fenv_requires_precise);
   }
   NewFPFeatures.setAllowFEnvAccessOverride(IsEnabled);
+  NewFPFeatures.setRoundingMathOverride(IsEnabled);
   FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
   CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
 }


Index: clang/test/CodeGen/pragma-fenv_access.c
===
--- clang/test/CodeGen/pragma-fenv_access.c
+++ clang/test/CodeGen/pragma-fenv_access.c
@@ -1,13 +1,17 @@
 // RUN: %clang_cc1 -fexperimental-strict-floating-point -ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck --check-prefixes=CHECK,STRICT %s
+// RUN: %clang_cc1 -fexperimental-strict-floating-point -frounding-math -ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck --check-prefixes=CHECK,STRICT-RND %s
 // RUN: %clang_cc1 -fexperimental-strict-floating-point -ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - -fms-extensions -DMS | FileCheck --check-prefixes=CHECK,STRICT %s
+// RUN: %clang_cc1 -fexperimental-strict-floating-point -frounding-math -ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - -fms-extensions -DMS | FileCheck --check-prefixes=CHECK,STRICT-RND %s
 // RUN: %clang_cc1 -fexperimental-strict-floating-point -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck --check-prefixes=CHECK,DEFAULT %s
-
+// RUN: %clang_cc1 -fexperimental-strict-floating-point -frounding-math -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck --check-prefixes=CHECK,DEFAULT-RND %s
 
 float func_00(float x, float y) {
   return x + y;
 }
 // CHECK-

[PATCH] D148093: [clang][CodeGen] Break up TargetInfo.cpp [5/6]

2023-04-12 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 created this revision.
Herald added a project: All.
barannikov88 updated this revision to Diff 512750.
barannikov88 added a comment.
barannikov88 updated this revision to Diff 512751.
barannikov88 updated this revision to Diff 512753.
barannikov88 edited the summary of this revision.
barannikov88 added reviewers: rjmccall, aaron.ballman, erichkeane.
barannikov88 published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Drop unintended changes


barannikov88 added a comment.

Attempt to overcome arc


barannikov88 added a comment.

Overcome arc, 2nd attempt




Comment at: clang/lib/CodeGen/TargetInfo.cpp:127
 /// This is intended to be the basis of a reasonable basic implementation
-/// of should{Pass,Return}IndirectlyForSwift.
+/// of should{Pass,Return}Indirectly.
 ///

Remnant of D130394


Remove `getABIInfo` overrides returning references to target-specific
implementations of `ABIInfo`.
The methods may be convenient, but they are only used in one place and
prevent from `ABIInfo` implementations from being put into anonymous
namespaces in different cpp files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148093

Files:
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -2481,10 +2481,6 @@
 std::make_unique(CGT, /*SwiftErrorInRegister=*/true);
   }
 
-  const X86_64ABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   /// Disable tail call on x86-64. The epilogue code before the tail jump 
blocks
   /// autoreleaseRV/retainRV and autoreleaseRV/unsafeClaimRV optimizations.
   bool markARCOptimizedReturnCallsAsNoTail() const override { return true; }
@@ -2521,7 +2517,8 @@
   bool HasAVXType = false;
   for (CallArgList::const_iterator
  it = args.begin(), ie = args.end(); it != ie; ++it) {
-if (getABIInfo().isPassedUsingAVXType(it->Ty)) {
+if (static_cast(TargetCodeGenInfo::getABIInfo())
+.isPassedUsingAVXType(it->Ty)) {
   HasAVXType = true;
   break;
 }
@@ -6403,10 +6400,6 @@
 SwiftInfo = std::make_unique(CGT);
   }
 
-  const ARMABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
 return 13;
   }
@@ -6425,7 +6418,9 @@
   }
 
   unsigned getSizeOfUnwindException() const override {
-if (getABIInfo().isEABI()) return 88;
+if (static_cast(TargetCodeGenInfo::getABIInfo())
+.isEABI())
+  return 88;
 return TargetCodeGenInfo::getSizeOfUnwindException();
   }
 
@@ -6492,7 +6487,7 @@
 
 Fn->addFnAttr("interrupt", Kind);
 
-ARMABIKind ABI = cast(getABIInfo()).getABIKind();
+ARMABIKind ABI = static_cast(getABIInfo()).getABIKind();
 if (ABI == ARMABIKind::APCS)
   return;
 
@@ -7430,10 +7425,6 @@
 class SystemZTargetCodeGenInfo : public TargetCodeGenInfo {
   ASTContext &Ctx;
 
-  const SystemZABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   // These are used for speeding up the search for a visible vector ABI.
   mutable bool HasVisibleVecABIFlag = false;
   mutable std::set SeenTypes;
@@ -7883,7 +7874,9 @@
 // be passed via "hidden" pointer where any extra alignment is not
 // required (per GCC).
 const Type *SingleEltTy =
-  getABIInfo().GetSingleElementType(QualType(Ty, 0)).getTypePtr();
+static_cast(TargetCodeGenInfo::getABIInfo())
+.GetSingleElementType(QualType(Ty, 0))
+.getTypePtr();
 bool SingleVecEltStruct = SingleEltTy != Ty && SingleEltTy->isVectorType() 
&&
   Ctx.getTypeSize(SingleEltTy) == Ctx.getTypeSize(Ty);
 if (Ty->isVectorType() || SingleVecEltStruct)
@@ -11835,10 +11828,6 @@
 public:
   BPFTargetCodeGenInfo(CodeGenTypes &CGT)
   : TargetCodeGenInfo(std::make_unique(CGT)) {}
-
-  const BPFABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
 };
 
 }


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -2481,10 +2481,6 @@
 std::make_unique(CGT, /*SwiftErrorInRegister=*/true);
   }
 
-  const X86_64ABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   /// Disable tail call on x86-64. The epilogue code before the tail jump blocks
   /// autoreleaseRV/retainRV and autoreleaseRV/unsafeClaimRV optimizations.
   bool markARCOptimizedReturnCallsAsNoTail() const override { return true; }
@@ -2521,7 +2517,8 @@
   bool HasAVXType = false;
   for (CallArgList::const_iterator
  i

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

2023-04-12 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 created this revision.
Herald added subscribers: luke, nlopes, kosarev, mattd, gchakrabarti, pmatos, 
asb, asavonic, frasercrmck, kerbowa, luismarques, apazos, sameer.abuasal, 
s.egerton, Jim, mstorsjo, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, 
rogfer01, atanasyan, mgrang, edward-jones, zzheng, jrtc27, niosHD, sabuasal, 
simoncook, johnrusso, rbar, fedor.sergeev, kbarton, jgravelle-google, sbc100, 
jvesely, nemanjai, sdardis, dylanmckay, jyknight, dschuff.
Herald added a project: All.
barannikov88 retitled this revision from "[clang][CodeGen] Break up 
TargetInfo.cpp [6/6]" to "[DRAFT][clang][CodeGen] Break up TargetInfo.cpp 
[6/6]".
barannikov88 added reviewers: rjmccall, aaron.ballman, erichkeane.
barannikov88 published this revision for review.
Herald added subscribers: cfe-commits, jplehr, pcwang-thead, sstefan1, MaskRay, 
aheejin, jholewinski.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148094

Files:
  clang/lib/CodeGen/ABIInfo.cpp
  clang/lib/CodeGen/ABIInfoImpl.cpp
  clang/lib/CodeGen/ABIInfoImpl.h
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/Targets/AArch64.cpp
  clang/lib/CodeGen/Targets/AArch64.h
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/lib/CodeGen/Targets/AMDGPU.h
  clang/lib/CodeGen/Targets/ARC.cpp
  clang/lib/CodeGen/Targets/ARC.h
  clang/lib/CodeGen/Targets/ARM.cpp
  clang/lib/CodeGen/Targets/ARM.h
  clang/lib/CodeGen/Targets/AVR.cpp
  clang/lib/CodeGen/Targets/AVR.h
  clang/lib/CodeGen/Targets/BPF.cpp
  clang/lib/CodeGen/Targets/BPF.h
  clang/lib/CodeGen/Targets/CSKY.cpp
  clang/lib/CodeGen/Targets/CSKY.h
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Hexagon.h
  clang/lib/CodeGen/Targets/Lanai.cpp
  clang/lib/CodeGen/Targets/Lanai.h
  clang/lib/CodeGen/Targets/LoongArch.cpp
  clang/lib/CodeGen/Targets/LoongArch.h
  clang/lib/CodeGen/Targets/M68k.cpp
  clang/lib/CodeGen/Targets/M68k.h
  clang/lib/CodeGen/Targets/MSP430.cpp
  clang/lib/CodeGen/Targets/MSP430.h
  clang/lib/CodeGen/Targets/Mips.cpp
  clang/lib/CodeGen/Targets/Mips.h
  clang/lib/CodeGen/Targets/NVPTX.cpp
  clang/lib/CodeGen/Targets/NVPTX.h
  clang/lib/CodeGen/Targets/PNaCl.cpp
  clang/lib/CodeGen/Targets/PNaCl.h
  clang/lib/CodeGen/Targets/PPC.cpp
  clang/lib/CodeGen/Targets/PPC.h
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/lib/CodeGen/Targets/RISCV.h
  clang/lib/CodeGen/Targets/SPIR.cpp
  clang/lib/CodeGen/Targets/SPIR.h
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/Sparc.h
  clang/lib/CodeGen/Targets/SystemZ.cpp
  clang/lib/CodeGen/Targets/SystemZ.h
  clang/lib/CodeGen/Targets/TCE.cpp
  clang/lib/CodeGen/Targets/TCE.h
  clang/lib/CodeGen/Targets/VE.cpp
  clang/lib/CodeGen/Targets/VE.h
  clang/lib/CodeGen/Targets/WebAssembly.cpp
  clang/lib/CodeGen/Targets/WebAssembly.h
  clang/lib/CodeGen/Targets/X86.cpp
  clang/lib/CodeGen/Targets/X86.h
  clang/lib/CodeGen/Targets/XCore.cpp
  clang/lib/CodeGen/Targets/XCore.h

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


[PATCH] D148110: [clang-tidy] Ctor arguments are sequenced if ctor call is written as list-initialization.

2023-04-12 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

See

https://timsong-cpp.github.io/cppwp/n4868/dcl.init#list-4

This eliminates a false positive in bugprone-use-after-move; the newly added
test triggers this case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148110

Files:
  clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
@@ -1160,42 +1160,58 @@
   }
 }
 
+namespace {
+
+struct S1 {
+  int i;
+  A a;
+};
+
+struct S2 {
+  A a;
+  int i;
+};
+
+struct S3 {
+  S3();
+  template  S3(int, F);
+
+  int i;
+  A a;
+};
+
 // An initializer list sequences its initialization clauses.
 void initializerListSequences() {
   {
-struct S1 {
-  int i;
-  A a;
-};
-{
-  A a;
-  S1 s1{a.getInt(), std::move(a)};
-}
-{
-  A a;
-  S1 s1{.i = a.getInt(), .a = std::move(a)};
-}
+A a;
+S1 s1{a.getInt(), std::move(a)};
   }
   {
-struct S2 {
-  A a;
-  int i;
-};
-{
-  A a;
-  S2 s2{std::move(a), a.getInt()};
-  // CHECK-NOTES: [[@LINE-1]]:27: warning: 'a' used after it was moved
-  // CHECK-NOTES: [[@LINE-2]]:13: note: move occurred here
-}
-{
-  A a;
-  S2 s2{.a = std::move(a), .i = a.getInt()};
-  // CHECK-NOTES: [[@LINE-1]]:37: warning: 'a' used after it was moved
-  // CHECK-NOTES: [[@LINE-2]]:13: note: move occurred here
-}
+A a;
+S1 s1{.i = a.getInt(), .a = std::move(a)};
+  }
+  {
+A a;
+S2 s2{std::move(a), a.getInt()};
+// CHECK-NOTES: [[@LINE-1]]:25: warning: 'a' used after it was moved
+// CHECK-NOTES: [[@LINE-2]]:11: note: move occurred here
+  }
+  {
+A a;
+S2 s2{.a = std::move(a), .i = a.getInt()};
+// CHECK-NOTES: [[@LINE-1]]:35: warning: 'a' used after it was moved
+// CHECK-NOTES: [[@LINE-2]]:11: note: move occurred here
+  }
+  {
+// TODO: Note that this is a regression test.
+A a;
+S3 s3;
+s3 = {a.getInt(), [a = std::move(a)] { return a; }};
   }
 }
 
+} // namespace
+
 // A declaration statement containing multiple declarations sequences the
 // initializer expressions.
 void declarationSequences() {
Index: clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
===
--- clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
+++ clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
@@ -131,6 +131,16 @@
   }
 }
   }
+} else if (const auto *ConstructExpr = dyn_cast(Parent)) {
+  // Constructor arguments are sequenced if the constructor call is written
+  // as list-initialization.
+  if (ConstructExpr->isListInitialization()) {
+for (unsigned I = 1; I < ConstructExpr->getNumArgs(); ++I) {
+  if (ConstructExpr->getArg(I - 1) == S) {
+return ConstructExpr->getArg(I);
+  }
+}
+  }
 } else if (const auto *Compound = dyn_cast(Parent)) {
   // Compound statement: Each sub-statement is sequenced after the
   // statements that precede it.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148112: [include-cleaner] Improve handling for templates

2023-04-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
Herald added a subscriber: mgrang.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Principal here is:

- Making sure each template instantiation implies use of the most specialized 
template. As explicit instantiations/specializations are not redeclarations of 
the primary template.
- Introducing a use from explicit instantiions/specializaitons to the primary 
template, as they're required but not traversed as part of the RAV.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148112

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -6,24 +6,32 @@
 //
 //===--===//
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Types.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Testing/TestAST.h"
-#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/GenericUniformityImpl.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Testing/Annotations/Annotations.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 #include 
 
 namespace clang::include_cleaner {
 namespace {
+using testing::ElementsAre;
 
 // Specifies a test of which symbols are referenced by a piece of code.
 // Target should contain points annotated with the reference kind.
@@ -31,7 +39,9 @@
 //   Target:  int $explicit^foo();
 //   Referencing: int x = ^foo();
 // There must be exactly one referencing location marked.
-void testWalk(llvm::StringRef TargetCode, llvm::StringRef ReferencingCode) {
+// Returns target decl kinds.
+std::vector testWalk(llvm::StringRef TargetCode,
+  llvm::StringRef ReferencingCode) {
   llvm::Annotations Target(TargetCode);
   llvm::Annotations Referencing(ReferencingCode);
 
@@ -51,6 +61,7 @@
   FileID TargetFile = SM.translateFile(
   llvm::cantFail(AST.fileManager().getFileRef("target.h")));
 
+  std::vector TargetDeclKinds;
   // Perform the walk, and capture the offsets of the referenced targets.
   std::unordered_map> ReferencedOffsets;
   for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
@@ -63,6 +74,7 @@
   if (NDLoc.first != TargetFile)
 return;
   ReferencedOffsets[RT].push_back(NDLoc.second);
+  TargetDeclKinds.push_back(ND.getDeclKindName());
 });
   }
   for (auto &Entry : ReferencedOffsets)
@@ -94,6 +106,9 @@
   // If there were any differences, we print the entire referencing code once.
   if (!DiagBuf.empty())
 ADD_FAILURE() << DiagBuf << "\nfrom code:\n" << ReferencingCode;
+  llvm::sort(TargetDeclKinds);
+  TargetDeclKinds.erase(llvm::unique(TargetDeclKinds), TargetDeclKinds.end());
+  return TargetDeclKinds;
 }
 
 TEST(WalkAST, DeclRef) {
@@ -114,25 +129,123 @@
   // One explicit call from the TypeLoc in constructor spelling, another
   // implicit reference through the constructor call.
   testWalk("struct $explicit^$implicit^S { static int x; };", "auto y = ^S();");
-  testWalk("template struct $explicit^Foo {};", "^Foo x;");
-  testWalk(R"cpp(
+}
+
+TEST(WalkAST, ClassTemplates) {
+  // Explicit instantiation and (partial) specialization references primary
+  // template.
+  EXPECT_THAT(testWalk("template struct $explicit^Foo{};",
+   "template struct ^Foo;"),
+  ElementsAre("ClassTemplate"));
+  EXPECT_THAT(testWalk("template struct $explicit^Foo{};",
+   "template<> struct ^Foo {};"),
+  ElementsAre("ClassTemplate"));
+  EXPECT_THAT(testWalk("template struct $explicit^Foo{};",
+   "template struct ^Foo {};"),
+  ElementsAre("ClassTemplate"));
+
+  // Implicit instantiations references most relevant template.
+  EXPECT_THAT(
+  testWalk("template struct $explicit^Foo {};", "^Foo x;"),
+  ElementsAre("ClassTemplate"));
+  EXPECT_THAT(testWalk(R"cpp(
 template struct Foo {};
 template<> struct $explicit^Foo {};)cpp",
-   "^Foo x;");
-  testWalk(R"cpp(
+   "^Foo x;"),
+  ElementsAre("ClassTemplateSpecialization"));
+  EXPECT_THAT(testWalk(R"cpp(
 temp

[PATCH] D147969: Add InsertBraces to ChromiumStyle

2023-04-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Format/Format.cpp:1699
 ChromiumStyle.DerivePointerAlignment = false;
+ChromiumStyle.InsertBraces = true;
 if (Language == FormatStyle::LK_ObjC)

MyDeveloperDay wrote:
> owenpan wrote:
> > aaron.ballman wrote:
> > > HazardyKnusperkeks wrote:
> > > > MyDeveloperDay wrote:
> > > > > This is an code modifying feature, we agreed that all code modifying 
> > > > > features would be off by default, opt in only
> > > > Now the question arises if //default// simply only applies to 
> > > > `LLVMStyle`, since that's the //default// when nothing is stated, or if 
> > > > other styles are free to enable such features in their style //by 
> > > > default//.
> > > > 
> > > > I'd say if chromium wants to do that, they should be allowed to.
> > > The community reacted pretty strongly to clang-format mutating code in 
> > > ways that may change the meaning of code unless there is an explicit 
> > > opt-in. The reason for that is because the opt-in + documentation is what 
> > > informs the user that the feature may break their code, so removing that 
> > > opt-in for the Chromium style means those users have no idea about the 
> > > dangers. (In general, users take a dim view of a formatting tool that 
> > > breaks code.)
> > > 
> > > Personally, I think if the Chromium *project* wants that to be the 
> > > default, they can use .clang-format files in their version control to 
> > > make it so, but I don't think the Chromium *style* built into 
> > > clang-format should allow it by default because that may be used by a 
> > > wider audience than just Chromium developers. Basically, I think we want 
> > > to be conservative with formatting features that can potentially break 
> > > code (once we start breaking user code with a formatting tool, that tool 
> > > gets pulled out of affected people's CI pipelines pretty quickly, which I 
> > > think we generally want to avoid).
> > I'm with @MyDeveloperDay and @aaron.ballman on this.
> I personally would feel quite uncomfortable about going against what we 
> agreed in the RFC.
That sounds like we've got consensus amongst code owners not to proceed with 
this patch. However, we still appreciate the patch and the discussion!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147969

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


[clang] 3820e9a - Reapply (4) "[Assignment Tracking] Enable by default"

2023-04-12 Thread via cfe-commits

Author: OCHyams
Date: 2023-04-12T12:35:17+01:00
New Revision: 3820e9a2b29a2e268319ed6635da0d59e18d736d

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

LOG: Reapply (4) "[Assignment Tracking] Enable by default"

Re-land D146987.

This reverts commit 8af575657b1dc1113640286b3649842c2473c2cf
which reverts D146987.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/CodeGen/assignment-tracking/flag.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5e008fc9b26ee..0e3c7b708071f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5815,7 +5815,7 @@ def experimental_assignment_tracking_EQ : Joined<["-"], 
"fexperimental-assignmen
   Group, CodeGenOpts<"EnableAssignmentTracking">,
   NormalizedValuesScope<"CodeGenOptions::AssignmentTrackingOpts">,
   Values<"disabled,enabled,forced">, 
NormalizedValues<["Disabled","Enabled","Forced"]>,
-  MarshallingInfoEnum, "Disabled">;
+  MarshallingInfoEnum, "Enabled">;
 
 } // let Flags = [CC1Option, NoDriverOption]
 

diff  --git a/clang/test/CodeGen/assignment-tracking/flag.cpp 
b/clang/test/CodeGen/assignment-tracking/flag.cpp
index aa1f054dae4d7..3bd974fe07c6c 100644
--- a/clang/test/CodeGen/assignment-tracking/flag.cpp
+++ b/clang/test/CodeGen/assignment-tracking/flag.cpp
@@ -8,10 +8,10 @@
 // RUN: -emit-llvm  %s -o - -fexperimental-assignment-tracking=disabled 
-O1\
 // RUN: | FileCheck %s --check-prefixes=DISABLE
 
- Disabled by default:
+ Enabled by default:
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   
\
 // RUN: -emit-llvm  %s -o - -O1
\
-// RUN: | FileCheck %s --check-prefixes=DISABLE
+// RUN: | FileCheck %s --check-prefixes=ENABLE
 
  Disabled at O0 unless forced.
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   
\



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


[PATCH] D143260: [clangd] Add semantic token for labels

2023-04-12 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.

Hello?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143260

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


[PATCH] D148112: [include-cleaner] Improve handling for templates

2023-04-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 512775.
kadircet edited the summary of this revision.
kadircet added a comment.

- Use template instantion pattern helper instead of dealing with partial 
specializations


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148112

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -6,24 +6,32 @@
 //
 //===--===//
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Types.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Testing/TestAST.h"
-#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/GenericUniformityImpl.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Testing/Annotations/Annotations.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 #include 
 
 namespace clang::include_cleaner {
 namespace {
+using testing::ElementsAre;
 
 // Specifies a test of which symbols are referenced by a piece of code.
 // Target should contain points annotated with the reference kind.
@@ -31,7 +39,9 @@
 //   Target:  int $explicit^foo();
 //   Referencing: int x = ^foo();
 // There must be exactly one referencing location marked.
-void testWalk(llvm::StringRef TargetCode, llvm::StringRef ReferencingCode) {
+// Returns target decl kinds.
+std::vector testWalk(llvm::StringRef TargetCode,
+  llvm::StringRef ReferencingCode) {
   llvm::Annotations Target(TargetCode);
   llvm::Annotations Referencing(ReferencingCode);
 
@@ -51,6 +61,7 @@
   FileID TargetFile = SM.translateFile(
   llvm::cantFail(AST.fileManager().getFileRef("target.h")));
 
+  std::vector TargetDeclKinds;
   // Perform the walk, and capture the offsets of the referenced targets.
   std::unordered_map> ReferencedOffsets;
   for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
@@ -63,6 +74,7 @@
   if (NDLoc.first != TargetFile)
 return;
   ReferencedOffsets[RT].push_back(NDLoc.second);
+  TargetDeclKinds.push_back(ND.getDeclKindName());
 });
   }
   for (auto &Entry : ReferencedOffsets)
@@ -94,6 +106,9 @@
   // If there were any differences, we print the entire referencing code once.
   if (!DiagBuf.empty())
 ADD_FAILURE() << DiagBuf << "\nfrom code:\n" << ReferencingCode;
+  llvm::sort(TargetDeclKinds);
+  TargetDeclKinds.erase(llvm::unique(TargetDeclKinds), TargetDeclKinds.end());
+  return TargetDeclKinds;
 }
 
 TEST(WalkAST, DeclRef) {
@@ -114,25 +129,123 @@
   // One explicit call from the TypeLoc in constructor spelling, another
   // implicit reference through the constructor call.
   testWalk("struct $explicit^$implicit^S { static int x; };", "auto y = ^S();");
-  testWalk("template struct $explicit^Foo {};", "^Foo x;");
-  testWalk(R"cpp(
+}
+
+TEST(WalkAST, ClassTemplates) {
+  // Explicit instantiation and (partial) specialization references primary
+  // template.
+  EXPECT_THAT(testWalk("template struct $explicit^Foo{};",
+   "template struct ^Foo;"),
+  ElementsAre("ClassTemplate"));
+  EXPECT_THAT(testWalk("template struct $explicit^Foo{};",
+   "template<> struct ^Foo {};"),
+  ElementsAre("ClassTemplate"));
+  EXPECT_THAT(testWalk("template struct $explicit^Foo{};",
+   "template struct ^Foo {};"),
+  ElementsAre("ClassTemplate"));
+
+  // Implicit instantiations references most relevant template.
+  EXPECT_THAT(
+  testWalk("template struct $explicit^Foo {};", "^Foo x;"),
+  ElementsAre("CXXRecord"));
+  EXPECT_THAT(testWalk(R"cpp(
 template struct Foo {};
 template<> struct $explicit^Foo {};)cpp",
-   "^Foo x;");
-  testWalk(R"cpp(
+   "^Foo x;"),
+  ElementsAre("ClassTemplateSpecialization"));
+  EXPECT_THAT(testWalk(R"cpp(
 template struct Foo {};
 template struct $explicit^Foo { void x(); };)cpp",
-   "^Foo x;");
-  testWalk(R"cpp(
+   "^Foo x;"),
+  ElementsAre("ClassTemplatePartialSpecialization"));
+  EXPECT_THAT(testWalk(R"cpp(
 template struct Foo {};
 template str

[PATCH] D147263: Fix an assertion failure in unwrapSugar

2023-04-12 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/test/SemaObjCXX/arc-objc-lifetime.mm:69-79
+// See https://github.com/llvm/llvm-project/issues/61419
+
+template  struct pair {
+  T0 first;
+  T1 second;
+};
+

I think the fix looks good, although this test may be out of place in this file.

Ideally, if I had thought of this test case, it would have gone into 
`clang/test/SemaCXX/sugared-auto.cpp`.

The existing tests there would try to trigger this bug through return type 
deduction, and not through the ternary operator as in your reduction.

A second good option would be to add it to 
`clang/test/SemaCXX/sugar-common-types.cpp`, as that tests ternary operator 
cases, but you would have to extend the compile flags to accept the ObjC++ 
stuff.

Also, if you want to add an isolated test for a bug in a file where it 
otherwise doesn't follow the style of the existing tests, we would isolate it 
in a namespace named after the PR.

Something like:
```
namespace PR61419 {

} // namespace PR61419
```

This makes it easier to extend and not accidentally break existing tests.

Also, it looks like this test could be a bit more minimal, as suggested in the 
edit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147263

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


[PATCH] D147263: Fix an assertion failure in unwrapSugar

2023-04-12 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov accepted this revision.
mizvekov 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/D147263/new/

https://reviews.llvm.org/D147263

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


[PATCH] D147875: [clang][Diagnostics] WIP: Show line numbers when printing code snippets

2023-04-12 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 512784.
tbaeder set the repository for this revision to rG LLVM Github Monorepo.
Herald added a subscriber: MaskRay.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147875

Files:
  clang/include/clang/Basic/DiagnosticOptions.def
  clang/include/clang/Basic/DiagnosticOptions.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/TextDiagnostic.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/FixIt/fixit-newline-style.c
  clang/test/FixIt/fixit-unicode-with-utf8-output.c
  clang/test/FixIt/fixit-unicode.c
  clang/test/Lexer/header.cpp
  clang/test/Lexer/string-literal-errors.cpp
  clang/test/Parser/brackets.c
  clang/test/Parser/brackets.cpp
  clang/test/SemaCXX/struct-class-redecl.cpp

Index: clang/test/SemaCXX/struct-class-redecl.cpp
===
--- clang/test/SemaCXX/struct-class-redecl.cpp
+++ clang/test/SemaCXX/struct-class-redecl.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -verify %s
-// RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers -verify %s
+// RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s
 class X; // expected-note 2{{here}}
 typedef struct X * X_t; // expected-warning{{previously declared}}
 union X { int x; float y; }; // expected-error{{use of 'X' with tag type that does not match previous declaration}}
Index: clang/test/Parser/brackets.cpp
===
--- clang/test/Parser/brackets.cpp
+++ clang/test/Parser/brackets.cpp
@@ -2,7 +2,7 @@
 // RUN: cp %s %t
 // RUN: not %clang_cc1 -fixit %t -x c++ -DFIXIT
 // RUN: %clang_cc1 -fsyntax-only %t -x c++ -DFIXIT
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -strict-whitespace
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s -strict-whitespace
 
 void test1() {
   int a[] = {0,1,1,2,3};
Index: clang/test/Parser/brackets.c
===
--- clang/test/Parser/brackets.c
+++ clang/test/Parser/brackets.c
@@ -2,7 +2,7 @@
 // RUN: cp %s %t
 // RUN: not %clang_cc1 -fixit %t -x c -DFIXIT
 // RUN: %clang_cc1 -fsyntax-only %t -x c -DFIXIT
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -strict-whitespace
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s -strict-whitespace
 
 void test1(void) {
   int a[] = {0,1,1,2,3};
Index: clang/test/Lexer/string-literal-errors.cpp
===
--- clang/test/Lexer/string-literal-errors.cpp
+++ clang/test/Lexer/string-literal-errors.cpp
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s
+// RUN: not %clang_cc1 -fsyntax-only -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck -strict-whitespace %s
 
 void foo() {
   (void)"\q \u123z \x \U \U123 \U12345 \u123 \xyzzy \777 \U"
Index: clang/test/Lexer/header.cpp
===
--- clang/test/Lexer/header.cpp
+++ clang/test/Lexer/header.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wno-header-guard %s
-// RUN: %clang_cc1 -fsyntax-only -Wheader-guard %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -Wheader-guard -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s
 
 #include "Inputs/good-header-guard.h"
 #include "Inputs/no-define.h"
Index: clang/test/FixIt/fixit-unicode.c
===
--- clang/test/FixIt/fixit-unicode.c
+++ clang/test/FixIt/fixit-unicode.c
@@ -2,8 +2,8 @@
 // There's a set of additional checks for systems with proper support of UTF-8
 // on the standard output in fixit-unicode-with-utf8-output.c.
 
-// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck -check-prefix=CHECK-MACHINE %s
+// RUN: not %clang_cc1 -fsyntax-only -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck -strict-whitespace %s
+// RUN: not %clang_cc1 -fsyntax-only -fno-diagnostics-show-line-numbers -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck -check-prefix=CHECK-MACHINE %s
 
 struct Foo {
   int bar;
Index: clang/test/FixIt/fixit-unicode-with-utf8-output.c
===
--- clang/test/FixIt/fixit-unicode-with-utf8-output.c
+++ clang/test/FixIt/fixit-unicode-with-utf8-output.c
@@ -1,7 +1,7 @@
 // This test 

[PATCH] D147875: [clang][Diagnostics] WIP: Show line numbers when printing code snippets

2023-04-12 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 512785.

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

https://reviews.llvm.org/D147875

Files:
  clang/include/clang/Basic/DiagnosticOptions.def
  clang/include/clang/Basic/DiagnosticOptions.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/TextDiagnostic.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/FixIt/fixit-newline-style.c
  clang/test/FixIt/fixit-unicode-with-utf8-output.c
  clang/test/FixIt/fixit-unicode.c
  clang/test/Lexer/header.cpp
  clang/test/Lexer/string-literal-errors.cpp
  clang/test/Parser/brackets.c
  clang/test/Parser/brackets.cpp
  clang/test/SemaCXX/struct-class-redecl.cpp

Index: clang/test/SemaCXX/struct-class-redecl.cpp
===
--- clang/test/SemaCXX/struct-class-redecl.cpp
+++ clang/test/SemaCXX/struct-class-redecl.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -verify %s
-// RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers -verify %s
+// RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s
 class X; // expected-note 2{{here}}
 typedef struct X * X_t; // expected-warning{{previously declared}}
 union X { int x; float y; }; // expected-error{{use of 'X' with tag type that does not match previous declaration}}
Index: clang/test/Parser/brackets.cpp
===
--- clang/test/Parser/brackets.cpp
+++ clang/test/Parser/brackets.cpp
@@ -2,7 +2,7 @@
 // RUN: cp %s %t
 // RUN: not %clang_cc1 -fixit %t -x c++ -DFIXIT
 // RUN: %clang_cc1 -fsyntax-only %t -x c++ -DFIXIT
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -strict-whitespace
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s -strict-whitespace
 
 void test1() {
   int a[] = {0,1,1,2,3};
Index: clang/test/Parser/brackets.c
===
--- clang/test/Parser/brackets.c
+++ clang/test/Parser/brackets.c
@@ -2,7 +2,7 @@
 // RUN: cp %s %t
 // RUN: not %clang_cc1 -fixit %t -x c -DFIXIT
 // RUN: %clang_cc1 -fsyntax-only %t -x c -DFIXIT
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -strict-whitespace
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s -strict-whitespace
 
 void test1(void) {
   int a[] = {0,1,1,2,3};
Index: clang/test/Lexer/string-literal-errors.cpp
===
--- clang/test/Lexer/string-literal-errors.cpp
+++ clang/test/Lexer/string-literal-errors.cpp
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s
+// RUN: not %clang_cc1 -fsyntax-only -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck -strict-whitespace %s
 
 void foo() {
   (void)"\q \u123z \x \U \U123 \U12345 \u123 \xyzzy \777 \U"
Index: clang/test/Lexer/header.cpp
===
--- clang/test/Lexer/header.cpp
+++ clang/test/Lexer/header.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wno-header-guard %s
-// RUN: %clang_cc1 -fsyntax-only -Wheader-guard %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -Wheader-guard -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s
 
 #include "Inputs/good-header-guard.h"
 #include "Inputs/no-define.h"
Index: clang/test/FixIt/fixit-unicode.c
===
--- clang/test/FixIt/fixit-unicode.c
+++ clang/test/FixIt/fixit-unicode.c
@@ -2,8 +2,8 @@
 // There's a set of additional checks for systems with proper support of UTF-8
 // on the standard output in fixit-unicode-with-utf8-output.c.
 
-// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck -check-prefix=CHECK-MACHINE %s
+// RUN: not %clang_cc1 -fsyntax-only -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck -strict-whitespace %s
+// RUN: not %clang_cc1 -fsyntax-only -fno-diagnostics-show-line-numbers -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck -check-prefix=CHECK-MACHINE %s
 
 struct Foo {
   int bar;
Index: clang/test/FixIt/fixit-unicode-with-utf8-output.c
===
--- clang/test/FixIt/fixit-unicode-with-utf8-output.c
+++ clang/test/FixIt/fixit-unicode-with-utf8-output.c
@@ -1,7 +1,7 @@
 // This test is an additional set of checks for the fixit-unicode.c test for
 // systems capable of outputting Unicode characters to the standard output in
 // t

[PATCH] D148112: [include-cleaner] Improve handling for templates

2023-04-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:91
+auto *CTSD = llvm::cast(TD);
+if (CTSD->isExplicitInstantiationOrSpecialization())
+  return CTSD;

We could consider the other order:

```
if (auto *Pattern = TD->getTemplateInstantiationPattern())
  return Pattern;
return TD;
```

To me this feels a bit more like there's an obvious principle and less like 
case bashing.

Concretely I think the difference is that we now report the pattern rather than 
the specialization for explicit template instantiations. As discussed offline, 
I'm not very familiar with the patterns where explicit instantiations are used. 
But it seems at least ambiguous whether a visible explicit instantiation is 
semantically significant, whereas it's clear that the pattern is important. So 
I think preferring the pattern here would be slightly better too, up to you.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:194
+  // Report a reference from explicit specializations/instantiations to the
+  // specialized template.
+  bool

maybe add to the comment that implicit ones are never visited?
(It should have been obvious to me, but it's easy to fall into the trap of 
"what are all the things a CTSD can be again?")



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:109
 ADD_FAILURE() << DiagBuf << "\nfrom code:\n" << ReferencingCode;
+  llvm::sort(TargetDeclKinds);
+  TargetDeclKinds.erase(llvm::unique(TargetDeclKinds), TargetDeclKinds.end());

this seems a little ad-hoc (is class name always enough info, why are we 
sorting/uniquing here)

Consider returning vector and using a matcher to verify the things 
you care about (`kind(Decl::ClassTemplate)` or so?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148112

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


[PATCH] D147875: [clang][Diagnostics] WIP: Show line numbers when printing code snippets

2023-04-12 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 512795.

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

https://reviews.llvm.org/D147875

Files:
  clang/include/clang/Basic/DiagnosticOptions.def
  clang/include/clang/Basic/DiagnosticOptions.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/TextDiagnostic.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/FixIt/fixit-newline-style.c
  clang/test/FixIt/fixit-unicode-with-utf8-output.c
  clang/test/FixIt/fixit-unicode.c
  clang/test/Lexer/header.cpp
  clang/test/Lexer/string-literal-errors.cpp
  clang/test/Parser/brackets.c
  clang/test/Parser/brackets.cpp
  clang/test/SemaCXX/struct-class-redecl.cpp

Index: clang/test/SemaCXX/struct-class-redecl.cpp
===
--- clang/test/SemaCXX/struct-class-redecl.cpp
+++ clang/test/SemaCXX/struct-class-redecl.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -verify %s
-// RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers -verify %s
+// RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s
 class X; // expected-note 2{{here}}
 typedef struct X * X_t; // expected-warning{{previously declared}}
 union X { int x; float y; }; // expected-error{{use of 'X' with tag type that does not match previous declaration}}
Index: clang/test/Parser/brackets.cpp
===
--- clang/test/Parser/brackets.cpp
+++ clang/test/Parser/brackets.cpp
@@ -2,7 +2,7 @@
 // RUN: cp %s %t
 // RUN: not %clang_cc1 -fixit %t -x c++ -DFIXIT
 // RUN: %clang_cc1 -fsyntax-only %t -x c++ -DFIXIT
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -strict-whitespace
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s -strict-whitespace
 
 void test1() {
   int a[] = {0,1,1,2,3};
Index: clang/test/Parser/brackets.c
===
--- clang/test/Parser/brackets.c
+++ clang/test/Parser/brackets.c
@@ -2,7 +2,7 @@
 // RUN: cp %s %t
 // RUN: not %clang_cc1 -fixit %t -x c -DFIXIT
 // RUN: %clang_cc1 -fsyntax-only %t -x c -DFIXIT
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -strict-whitespace
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s -strict-whitespace
 
 void test1(void) {
   int a[] = {0,1,1,2,3};
Index: clang/test/Lexer/string-literal-errors.cpp
===
--- clang/test/Lexer/string-literal-errors.cpp
+++ clang/test/Lexer/string-literal-errors.cpp
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s
+// RUN: not %clang_cc1 -fsyntax-only -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck -strict-whitespace %s
 
 void foo() {
   (void)"\q \u123z \x \U \U123 \U12345 \u123 \xyzzy \777 \U"
Index: clang/test/Lexer/header.cpp
===
--- clang/test/Lexer/header.cpp
+++ clang/test/Lexer/header.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wno-header-guard %s
-// RUN: %clang_cc1 -fsyntax-only -Wheader-guard %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -Wheader-guard -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s
 
 #include "Inputs/good-header-guard.h"
 #include "Inputs/no-define.h"
Index: clang/test/FixIt/fixit-unicode.c
===
--- clang/test/FixIt/fixit-unicode.c
+++ clang/test/FixIt/fixit-unicode.c
@@ -2,8 +2,8 @@
 // There's a set of additional checks for systems with proper support of UTF-8
 // on the standard output in fixit-unicode-with-utf8-output.c.
 
-// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck -check-prefix=CHECK-MACHINE %s
+// RUN: not %clang_cc1 -fsyntax-only -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck -strict-whitespace %s
+// RUN: not %clang_cc1 -fsyntax-only -fno-diagnostics-show-line-numbers -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck -check-prefix=CHECK-MACHINE %s
 
 struct Foo {
   int bar;
Index: clang/test/FixIt/fixit-unicode-with-utf8-output.c
===
--- clang/test/FixIt/fixit-unicode-with-utf8-output.c
+++ clang/test/FixIt/fixit-unicode-with-utf8-output.c
@@ -1,7 +1,7 @@
 // This test is an additional set of checks for the fixit-unicode.c test for
 // systems capable of outputting Unicode characters to the standard output in
 // t

[PATCH] D146101: [clang-format] Add BracedInitializerIndentWidth option.

2023-04-12 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added a comment.

Ping for review again plz.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


[PATCH] D146101: [clang-format] Add BracedInitializerIndentWidth option.

2023-04-12 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

If all comments and concerns are done, then I'm inclined to accept, but I'd 
like @owenpan  and @HazardyKnusperkeks to give their opinion before we land 
this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


[PATCH] D125171: [clang-format] Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-04-12 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

is it possible to point to a github issue that this related to in the review 
summary, if not please can you make one so we can track the issue its trying to 
solve


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

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


[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane requested changes to this revision.
erichkeane added a comment.
This revision now requires changes to proceed.

Requesting changes so we don't accidentally commit this.  There is some 
confusion elsewhere on how ready this is for commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

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


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D145088#4259377 , @craig.topper 
wrote:

> In D145088#4258856 , @erichkeane 
> wrote:
>
>> So I don't see any handling of the dependent version of this, we probably 
>> need tests for those at minimum.
>
> Does SVE handle the dependent version?

It does, I believe we insisted on it at the time.  You may inherit it 
sufficiently, so tests for it are perhaps all that is necessary.




Comment at: clang/include/clang/AST/ASTContext.h:2262
+  /// Return true if the given vector types are lax-compatible RISC-V vector
+  /// types as defined by -flax-vector-conversions=, false otherwise.
+  bool areLaxCompatibleRVVTypes(QualType FirstType, QualType SecondType);

I still had to look this one up.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:11371
+  unsigned EltSize = getContext().getTypeSize(BT);
+  switch (BT->getKind()) {
+  default:

Having the switch still is awkward, since it only exists for an unreachable.  I 
wonder if splitting off this type checking to a separate function and asserting 
on it is more valuable?  AND could be used elsewhere if we use this pattern 
again?

I'll leave that up to the CodeGen code owners to require however.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D147909: [clang] Implement CWG 2397

2023-04-12 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/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp:5
   int b[5];
-  auto a[5] = b; // expected-error{{'a' declared as array of 'auto'}}
-  auto *c[5] = b; // expected-error{{'c' declared as array of 'auto *'}}
+  auto a[5] = b; // expected-error{{variable 'a' with type 'auto[5]' has 
incompatible initializer of type 'int[5]'}}
+  auto *c[5] = b; // expected-error{{variable 'c' with type 'auto *[5]' has 
incompatible initializer of type 'int[5]'}}

zyounan wrote:
> aaron.ballman wrote:
> > I've seen worse diagnostics, but the phrasing here is interesting -- if you 
> > use `int a[5] = b;` instead of `auto`, you get `array initializer must be 
> > an initializer list` as a diagnostic, so I wonder why we're getting such a 
> > drastically different diagnostic for `auto`. Same for the diagnostic below.
> You're right that such diagnostic looks a bit strange but FYI, GCC now emits 
> diagnostic like so:
> ```
> auto a[5] = b; // error: unable to deduce 'auto [5]' from 'b'
> int c[5] = b;  // error: array must be initialized with a brace-enclosed 
> initializer
> ```
> I agree that what we expect here is to emit messages just like `int a[5] = 
> b;` would produce with respect to better understandability, however, the 
> `err_auto_var_deduction_failure` error is actually emitted due to type 
> deduction failure, whereas `err_array_init_not_init_list` would be produced 
> **later** by initialization error IIUC. So, IMHO such message makes sence as 
> per what standard says, that for each type `P`, after being substituted with 
> deduced `A`, shall be **compatible** with type `A`. 
> [temp.deduct.type/1](https://eel.is/c++draft/temp.deduct.type#1.sentence-1)
> 
> // Feel free to correct me if I'm wrong :)
Ah, good catch! Okay, this seems reasonable to me now that I understand it 
better, thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147909

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


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-12 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 512801.
junaire added a comment.

use unsigned long instead of std::size_t when including the runtimes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +281,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +318,55 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_TRUE(V1.isValid());
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+  EXPECT_EQ(V1.getKind(), Value::K_Int);
+  EXPECT_FALSE(V1.isManuallyAlloc());
+  EXPECT_FALSE(V1.isPointerOrObjectType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_TRUE(V2.isValid());
+  EXPECT_EQ(V2.getDouble(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.getKind(), Value::K_Double);
+  EXPECT_FALSE(V2.isManuallyAlloc());
+  EXPECT_FALSE(V2.isPointerOrObjectType());
+
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute(
+  "struct S { int* p; S() { p = new int(42); } ~S() { delete p; }};"));
+  llvm::cantFail(Interp->ParseAndExecute("S{}", &V3));
+  EXPECT_TRUE(V3.isValid());
+  EXPECT_TRUE(V3.getType()->isRecordType());
+  EXPECT_EQ(V3.getKind(), Value::K_PtrOrObj);
+  EXPECT_TRUE(V3.isManuallyAlloc());
+  EXPECT_TRUE(V3.isPointerOrObjectType());
+
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 42);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  Value V5;
+  // Change the global from the compiled code.
+  setGlobal(43);
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V5));
+  EXPECT_EQ(V5.getInt(), 43);
+  EXPECT_TRUE(V5.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   cl

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Precommit CI has several failures introduced by this patch -- some test cases 
need to be fixed up (in addition to the new test coverage).




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3424
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum class}1\" to apply 
attribute to "
   "type declaration">, InGroup;

tbaeder wrote:
> "enum struct" is also possible in C++, so I think this needs to be covered as 
> well.
If that turns out to be frustrating for some reason, we could perhaps reuse 
`class` or `struct` instead of adding `enum ` as another option. e.g.,
```
__attribute__((whatever)) // warning: attribute 'whatever' is ignored, place it 
after "class" to apply attribute to type declaration
enum class foo {
};
```
coupled with the insert caret and fix-it hint, it's pretty clear where to move 
the attribute to despite the warning not saying `enum class` specifically.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147989

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


[PATCH] D148124: [RISCV][Driver] Allow the use of CPUs with a different XLEN than the triple.

2023-04-12 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng created this revision.
kito-cheng added reviewers: asb, craig.topper, luismarques.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
evandro, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, 
the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
kito-cheng requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.

Our downstream toolchain release got some issue is we set the default
triple by creating symbolic link of clang like `riscv64-unknown-elf-clang`,
and has lots of multi-lib config including rv32's config.

However when we trying to set arch by a 32 bit CPU like generic-rv32
but got error message below:
error: unsupported argument 'generic-rv32' to option '-mcpu='

`generic-rv32` is listed in the output of `-mcpu=help`, that
might be confusing for user since help message say supported.

So let clang driver also consider -mcpu option during computing
the target triple to archvie that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148124

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Driver/riscv-cpus.c


Index: clang/test/Driver/riscv-cpus.c
===
--- clang/test/Driver/riscv-cpus.c
+++ clang/test/Driver/riscv-cpus.c
@@ -174,6 +174,3 @@
 
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv32 
-march=rv64i | FileCheck -check-prefix=MISMATCH-ARCH %s
 // MISMATCH-ARCH: cpu 'generic-rv32' does not support rv64
-
-// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv64 | FileCheck 
-check-prefix=MISMATCH-MCPU %s
-// MISMATCH-MCPU: error: cpu 'generic-rv64' does not support rv32
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -382,12 +382,20 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
 // RUN: %clang --target=riscv64-unknown-elf -march=rv32i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
+// RUN: %clang --target=riscv32-unknown-elf -mcpu=generic-rv32 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
+// RUN: %clang --target=riscv64-unknown-elf -mcpu=generic-rv32 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s
 // RV32-TARGET: "-triple" "riscv32-unknown-unknown-elf"
 
 // RUN: %clang --target=riscv32-unknown-elf -march=rv64i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
 // RUN: %clang --target=riscv64-unknown-elf -march=rv64i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
+// RUN: %clang --target=riscv32-unknown-elf -mcpu=generic-rv64 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
+// RUN: %clang --target=riscv64-unknown-elf -mcpu=generic-rv64 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
 // RV64-TARGET: "-triple" "riscv64-unknown-unknown-elf"
 
 // RUN: %clang --target=riscv32-unknown-elf -march=rv32ifzfh01p0 -### %s \
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -12,6 +12,7 @@
 #include "ToolChains/AMDGPUOpenMP.h"
 #include "ToolChains/AVR.h"
 #include "ToolChains/Ananas.h"
+#include "ToolChains/Arch/RISCV.h"
 #include "ToolChains/BareMetal.h"
 #include "ToolChains/CSKYToolChain.h"
 #include "ToolChains/Clang.h"
@@ -689,8 +690,9 @@
   // If target is RISC-V adjust the target triple according to
   // provided architecture name
   if (Target.isRISCV()) {
-if ((A = Args.getLastArg(options::OPT_march_EQ))) {
-  StringRef ArchName = A->getValue();
+if (Args.hasArg(options::OPT_march_EQ) ||
+Args.hasArg(options::OPT_mcpu_EQ)) {
+  StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
   if (ArchName.startswith_insensitive("rv32"))
 Target.setArch(llvm::Triple::riscv32);
   else if (ArchName.startswith_insensitive("rv64"))


Index: clang/test/Driver/riscv-cpus.c
===
--- clang/test/Driver/riscv-cpus.c
+++ clang/test/Driver/riscv-cpus.c
@@ -174,6 +174,3 @@
 
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv32 -march=rv64i | FileCheck -check-prefix=MISMATCH-ARCH %s
 // MISMATCH-ARCH: cpu 'generic-rv32' does not support rv64
-
-// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv64 | FileCheck -check-prefix=MISMATCH-MCPU %s
-// MISMATCH-MCPU: error: cpu 'generic-rv64' does not support rv32
Index: clang/test/Driver/riscv-arch.c
=

[PATCH] D147217: [OpenMP][OMPIRBuilder] OpenMPIRBuilder support for requires directive

2023-04-12 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 512805.
skatrak added a comment.

Add unit test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147217

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -9,12 +9,14 @@
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
 #include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Constants.h"
 #include "llvm/IR/DIBuilder.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/InstIterator.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
 #include "llvm/IR/Verifier.h"
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Support/Casting.h"
@@ -5731,7 +5733,8 @@
 
 TEST_F(OpenMPIRBuilderTest, OffloadEntriesInfoManager) {
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.setConfig(OpenMPIRBuilderConfig(true, false, false, false));
+  OMPBuilder.setConfig(
+  OpenMPIRBuilderConfig(true, false, false, false, false, false, false));
   OffloadEntriesInfoManager &InfoManager = OMPBuilder.OffloadInfoManager;
   TargetRegionEntryInfo EntryInfo("parent", 1, 2, 4, 0);
   InfoManager.initializeTargetRegionEntryInfo(EntryInfo, 0);
@@ -5746,4 +5749,43 @@
   GlobalValue::WeakAnyLinkage);
   EXPECT_TRUE(InfoManager.hasDeviceGlobalVarEntryInfo("gvar"));
 }
+
+TEST_F(OpenMPIRBuilderTest, CreateRegisterRequires) {
+  OpenMPIRBuilder OMPBuilder(*M);
+  OMPBuilder.initialize();
+
+  OMPBuilder.setConfig(
+  OpenMPIRBuilderConfig(/*IsEmbedded=*/true,
+/*IsTargetCodegen=*/false,
+/*OpenMPOffloadMandatory=*/false,
+/*HasRequiresReverseOffload=*/true,
+/*HasRequiresUnifiedAddress=*/false,
+/*HasRequiresUnifiedSharedMemory=*/true,
+/*HasRequiresDynamicAllocators=*/false));
+
+  auto FName =
+  OMPBuilder.createPlatformSpecificName({"omp_offloading", "requires_reg"});
+  EXPECT_EQ(FName, ".omp_offloading.requires_reg");
+
+  Function *Fn = OMPBuilder.createRegisterRequires(FName);
+  EXPECT_EQ(FName, Fn->getName());
+
+  EXPECT_EQ(Fn->getSection(), ".text.startup");
+  EXPECT_TRUE(Fn->hasInternalLinkage());
+  EXPECT_TRUE(Fn->hasFnAttribute(Attribute::NoInline));
+  EXPECT_TRUE(Fn->hasFnAttribute(Attribute::NoUnwind));
+  EXPECT_EQ(Fn->size(), 1u);
+
+  BasicBlock *Entry = &Fn->getEntryBlock();
+  EXPECT_FALSE(Entry->empty());
+  EXPECT_EQ(Fn->getReturnType()->getTypeID(), Type::VoidTyID);
+
+  CallInst *Call = &cast(*Entry->begin());
+  EXPECT_EQ(Call->getCalledFunction()->getName(), "__tgt_register_requires");
+  EXPECT_EQ(Call->getNumOperands(), 2u);
+
+  Value *Flags = Call->getArgOperand(0);
+  EXPECT_EQ(cast(Flags)->getSExtValue(),
+OMPBuilder.Config.getRequiresFlags());
+}
 } // namespace
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -21,10 +21,12 @@
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/CFG.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
 #include "llvm/IR/GlobalVariable.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/MDBuilder.h"
@@ -328,6 +330,104 @@
   return splitBB(Builder, CreateBranch, Old->getName() + Suffix);
 }
 
+//===--===//
+// OpenMPIRBuilderConfig
+//===--===//
+
+namespace {
+LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
+/// Values for bit flags for marking which requires clauses have been used.
+enum OpenMPOffloadingRequiresDirFlags {
+  /// flag undefined.
+  OMP_REQ_UNDEFINED = 0x000,
+  /// no requires directive present.
+  OMP_REQ_NONE = 0x001,
+  /// reverse_offload clause.
+  OMP_REQ_REVERSE_OFFLOAD = 0x002,
+  /// unified_address clause.
+  OMP_REQ_UNIFIED_ADDRESS = 0x004,
+  /// unified_shared_memory clause.
+  OMP_REQ_UNIFIED_SHARED_MEMORY = 0x008,
+  /// dynamic_allocators clause.
+  OMP_REQ_DYNAMIC_ALLOCATORS = 0x010,
+  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/OMP_REQ_DYNAMIC_ALLOCATORS)
+};
+
+} // anonymous namespace

[PATCH] D148101: [clang] Ensure that Attr::Create(Implicit) chooses a valid syntax

2023-04-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

1 suggestion to catch a few more cases that I think are incorrect, but this is 
a move in the right direction.  Thanks!




Comment at: clang/include/clang/Basic/AttributeCommonInfo.h:55
+
+/// The attibute has no source code manifestation and is only created
+/// implicitly.

If I recall, there was some pretty awful funny business in some attributes, 
which would explicitly use '0' instead of AS_GNU as implicit.  Did you run into 
any of these?

Would it make sense to make AS_Implicit 'first' here to catch those?  Or 
perhaps make '0' ill-formed (and assert?) and make this '1'?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148101

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


[PATCH] D98012: [RFC][doc] Document that RISC-V's __fp16 has different behavior

2023-04-12 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng abandoned this revision.
kito-cheng added a comment.
Herald added subscribers: pcwang-thead, VincentWu, arichardson.
Herald added a project: All.

RISC-V using `_Float16` as official half-precision type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98012

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


[PATCH] D148102: [clang] Specify attribute syntax & spelling with a single argument

2023-04-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I'm not sold on the value of this patch, but I don't see any problems with it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148102

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


[PATCH] D148103: [clang] Allow attributes to be constructed from keyword tokens

2023-04-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Again, not sold on value, but no problems with the patch itself.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148103

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


[PATCH] D138777: [clang-tidy] Add check bugprone-multiple-new-in-one-expression.

2023-04-12 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 512808.
balazske added a comment.

Simplified AST matchers a bit.
Added check for list-initialization syntax at constructor call.
Added some tests.
Updated documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138777

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone/multiple-new-in-one-expression.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/multiple-new-in-one-expression.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/multiple-new-in-one-expression.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/multiple-new-in-one-expression.cpp
@@ -0,0 +1,197 @@
+// RUN: %check_clang_tidy -std=c++11 -check-suffixes=ALL,CPP11 %s bugprone-multiple-new-in-one-expression %t
+// RUN: %check_clang_tidy -std=c++17 -check-suffixes=ALL,CPP17 %s bugprone-multiple-new-in-one-expression %t
+
+namespace std {
+typedef __typeof__(sizeof(0)) size_t;
+enum class align_val_t : std::size_t {};
+class exception {};
+class bad_alloc : public exception {};
+struct nothrow_t {};
+extern const nothrow_t nothrow;
+} // namespace std
+
+void *operator new(std::size_t, const std::nothrow_t &) noexcept;
+void *operator new(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept;
+void *operator new(std::size_t, void *) noexcept;
+void *operator new(std::size_t, char);
+
+struct B;
+
+struct A { int VarI; int *PtrI; B *PtrB; };
+
+struct B { int VarI; };
+
+struct G {
+  G(A*, B*) {}
+  int operator+=(A *) { return 3; };
+};
+
+struct H {
+  int *a;
+  int *b;
+};
+
+int f(int);
+int f(A*);
+int f(A*, B*);
+int f(int, B*);
+int f(G, G);
+int f(B*);
+int f(const H &);
+void f1(void *, void *);
+A *g(A *);
+
+G operator+(const G&, const G&);
+
+void test_function_parameter(A *XA, B *XB) {
+  (void)f(new A, new B);
+  try {
+(void)f(new A, new B);
+  }
+  catch (A) {};
+  try {
+(void)f(new A, new B);
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:13: warning: memory allocation may leak if an other allocation is sequenced after it and throws an exception; order of these allocations is undefined [
+(void)f(f(new A, new B));
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:15: warning: memory allocation may leak if an other allocation is sequenced after it and throws an exception;
+int X = f(new A, new B);
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:15: warning: memory allocation may leak if an other allocation is sequenced after it and throws an exception;
+X = f(new A, new B);
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:11: warning: memory allocation may leak if an other allocation is sequenced after it and throws an exception;
+X = 1 + f(new A, new B);
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:15: warning: memory allocation may leak if an other allocation is sequenced after it and throws an exception;
+
+(void)f(g(new A), new B);
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:15: warning: memory allocation may leak if an other allocation is sequenced after it and throws an exception;
+
+(void)f(1 + f(new A), new B);
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:19: warning: memory allocation may leak if an other allocation is sequenced after it and throws an exception;
+(void)f(XA = new A, new B);
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:18: warning: memory allocation may leak if an other allocation is sequenced after it and throws an exception;
+(void)f(1 + f(new A), XB = new B);
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:19: warning: memory allocation may leak if an other allocation is sequenced after it and throws an exception;
+  }
+  catch (std::exception) {}
+}
+
+void test_operator(G *G1) {
+  (void)(f(new A) + f(new B));
+  try {
+(void)(f(new A) + f(new B));
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:14: warning: memory allocation may leak if an other allocation is sequenced after it and throws an exception;
+(void)f(f(new A) + f(new B));
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:15: warning: memory allocation may leak if an other allocation is sequenced after it and throws an exception;
+int X = f(new A) + f(new B);
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:15: warning: memory allocation may leak if an other allocation is sequenced after it and throws an exception;
+X = f(new A) + f(new B);
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:11: warning: memory allocation may leak if an other allocation is sequenced after it and throws an exception;
+X = 1 + f(new A) + 1 + f(new B);
+ /

[PATCH] D138777: [clang-tidy] Add check bugprone-multiple-new-in-one-expression.

2023-04-12 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 2 inline comments as done.
balazske added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp:44-45
+return BinOp->getOpcode() == BO_Assign &&
+   BinOp->getRHS()->IgnoreParenCasts() == E;
+
+  return isa(ParentE);

donat.nagy wrote:
> In general, a value can be stored by passing it to a CompoundAssignOperator. 
> This is not relevant in the current application (pointers do not appear on 
> the RHS of compound assignment operators); but perhaps it's worth to mention 
> this in a short comment in case someone wishes to reuse this function in some 
> other checker.
It is mentioned now in the comment before the function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138777

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


[PATCH] D125171: [clang-format] Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-04-12 Thread jonathan molinatto via Phabricator via cfe-commits
jrmolin added a comment.

In D125171#4261301 , @MyDeveloperDay 
wrote:

> is it possible to point to a github issue that this related to in the review 
> summary, if not please can you make one so we can track the issue its trying 
> to solve

added an issue: https://github.com/llvm/llvm-project/issues/62092


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

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


[PATCH] D147888: Update declaration message of extern linkage

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



Comment at: clang/test/SemaCXX/extern_static.cpp:1
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wabstract-vbase-init
+void f(void)

That's unnecessary, isn't it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147888

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


[PATCH] D148105: [clang] Fix FIXME in isAlignasAttribute()

2023-04-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

Huh, this is much less disruptive than I thought it was going to be.  LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148105

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


[PATCH] D148103: [clang] Allow attributes to be constructed from keyword tokens

2023-04-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

Later patches show enough value to this, I'm OK with it.  Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148103

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


[PATCH] D148102: [clang] Specify attribute syntax & spelling with a single argument

2023-04-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Later patches show enough value to this, I'm OK with it.  Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148102

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


[PATCH] D147875: [clang][Diagnostics] WIP: Show line numbers when printing code snippets

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

Since basically nobody has seen multiple snippet lines being printed, we 
probably need to fix up a bunch of diagnostics afterwards to be more useful, 
e.g.

  ./array.cpp:111:5: error: no matching function for call to 'func'
111 | func(1, 2, 3, 4), "hah, reason!");
| ^~~~
  ./array.cpp:96:16: note: candidate function not viable: requires 7 arguments, 
but 4 were provided
 96 | consteval bool func(int why,
|^
 97 | int would_my,
| ~
 98 | int compiler_complain,
| ~~
 99 | int about_the_arguments,
| 
100 | int but_not_show_them_to_me,
| 
101 | int if_the_declaration_covers_multiple_lines,
| ~
102 | int big_question_mark) {
| ~
  1 error generated.

has annoyed me  in the past (using one argument per line is common in some 
coding styles).


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

https://reviews.llvm.org/D147875

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


[clang] 2266f4a - [Flang][Driver][OpenMP] Enable options for selecting offloading phases in flang

2023-04-12 Thread Sergio Afonso via cfe-commits

Author: Sergio Afonso
Date: 2023-04-12T14:59:37+01:00
New Revision: 2266f4a3b38f4b59d313cdd2a9209952afb29d14

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

LOG: [Flang][Driver][OpenMP] Enable options for selecting offloading phases in 
flang

This patch unlocks the "--offload-device-only", "--offload-host-only" and
"--offload-host-device" options available in Clang for use by the Flang driver.
These can be used to modify the behavior of the driver to select which
compilation invocations are triggered during OpenMP offloading.

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

Added: 
flang/test/Driver/omp-driver-offload.f90

Modified: 
clang/include/clang/Driver/Options.td
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 
flang/test/Driver/omp-frontend-forwarding.f90



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0e3c7b708071f..7a2d9bf2a3915 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2735,11 +2735,11 @@ def offload_new_driver : Flag<["--"], 
"offload-new-driver">, Flags<[CC1Option]>,
   MarshallingInfoFlag>, HelpText<"Use the new 
driver for offloading compilation.">;
 def no_offload_new_driver : Flag<["--"], "no-offload-new-driver">, 
Flags<[CC1Option]>, Group,
   HelpText<"Don't Use the new driver for offloading compilation.">;
-def offload_device_only : Flag<["--"], "offload-device-only">,
+def offload_device_only : Flag<["--"], "offload-device-only">, 
Flags<[FlangOption]>,
   HelpText<"Only compile for the offloading device.">;
-def offload_host_only : Flag<["--"], "offload-host-only">,
+def offload_host_only : Flag<["--"], "offload-host-only">, 
Flags<[FlangOption]>,
   HelpText<"Only compile for the offloading host.">;
-def offload_host_device : Flag<["--"], "offload-host-device">,
+def offload_host_device : Flag<["--"], "offload-host-device">, 
Flags<[FlangOption]>,
   HelpText<"Only compile for the offloading host.">;
 def cuda_device_only : Flag<["--"], "cuda-device-only">, 
Alias,
   HelpText<"Compile CUDA code for device only">;

diff  --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 1a5fb4e996294..c365fbf16de35 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -69,6 +69,9 @@
 ! CHECK-NEXT: -mmlir  Additional arguments to forward to MLIR's 
option processing
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -nocpp Disable predefined and command line 
preprocessor macros
+! CHECK-NEXT: --offload-device-only   Only compile for the offloading device.
+! CHECK-NEXT: --offload-host-device   Only compile for the offloading host.
+! CHECK-NEXT: --offload-host-only Only compile for the offloading host.
 ! CHECK-NEXT: -o  Write output to 
 ! CHECK-NEXT: -pedantic  Warn on language extensions
 ! CHECK-NEXT: -print-effective-triple Print the effective target triple

diff  --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index 84707791a2e32..25871db048911 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -65,6 +65,9 @@
 ! HELP-NEXT: -mmlir  Additional arguments to forward to MLIR's 
option processing
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -nocpp Disable predefined and command line 
preprocessor macros
+! HELP-NEXT: --offload-device-only   Only compile for the offloading device.
+! HELP-NEXT: --offload-host-device   Only compile for the offloading host.
+! HELP-NEXT: --offload-host-only Only compile for the offloading host.
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -pedantic  Warn on language extensions
 ! HELP-NEXT: -print-effective-triple Print the effective target triple

diff  --git a/flang/test/Driver/omp-frontend-forwarding.f90 
b/flang/test/Driver/omp-driver-offload.f90
similarity index 69%
rename from flang/test/Driver/omp-frontend-forwarding.f90
rename to flang/test/Driver/omp-driver-offload.f90
index ef4875ce2fae8..ec107261d4c2b 100644
--- a/flang/test/Driver/omp-frontend-forwarding.f90
+++ b/flang/test/Driver/omp-driver-offload.f90
@@ -7,6 +7,42 @@
 ! CHECK-OPENMP: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}}.f90"
 ! CHECK-OPENMP-NOT: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} 
"-fopenmp-is-device" {{.*}}.f90"
 
+! Test regular -fopenmp with offload, and invocation filtering options
+! RUN: %flang -S -### %s -o %t 2>&1 \
+! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 \
+! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN:   | FileCheck %s --check-prefix=OFFLOAD-

[PATCH] D147941: [Flang][Driver][OpenMP] Enable options for selecting offloading phases in flang

2023-04-12 Thread Sergio Afonso via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
skatrak marked 2 inline comments as done.
Closed by commit rG2266f4a3b38f: [Flang][Driver][OpenMP] Enable options for 
selecting offloading phases in flang (authored by skatrak).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147941

Files:
  clang/include/clang/Driver/Options.td
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/omp-driver-offload.f90
  flang/test/Driver/omp-frontend-forwarding.f90


Index: flang/test/Driver/omp-driver-offload.f90
===
--- flang/test/Driver/omp-driver-offload.f90
+++ flang/test/Driver/omp-driver-offload.f90
@@ -7,6 +7,42 @@
 ! CHECK-OPENMP: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}}.f90"
 ! CHECK-OPENMP-NOT: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} 
"-fopenmp-is-device" {{.*}}.f90"
 
+! Test regular -fopenmp with offload, and invocation filtering options
+! RUN: %flang -S -### %s -o %t 2>&1 \
+! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 \
+! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN:   | FileCheck %s --check-prefix=OFFLOAD-HOST-AND-DEVICE
+
+! RUN: %flang -S -### %s -o %t 2>&1 \
+! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 
--offload-host-device \
+! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN:   | FileCheck %s --check-prefix=OFFLOAD-HOST-AND-DEVICE
+
+! OFFLOAD-HOST-AND-DEVICE: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
+! OFFLOAD-HOST-AND-DEVICE-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"amdgcn-amd-amdhsa"
+! OFFLOAD-HOST-AND-DEVICE-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"nvptx64-nvidia-cuda"
+! OFFLOAD-HOST-AND-DEVICE: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
+
+! RUN: %flang -S -### %s -o %t 2>&1 \
+! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 --offload-host-only 
\
+! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN:   | FileCheck %s --check-prefix=OFFLOAD-HOST
+
+! OFFLOAD-HOST: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
+! OFFLOAD-HOST-NOT: "-triple" "amdgcn-amd-amdhsa"
+! OFFLOAD-HOST-NOT: "-triple" "nvptx64-nvidia-cuda"
+! OFFLOAD-HOST-NOT: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
+
+! RUN: %flang -S -### %s -o %t 2>&1 \
+! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 
--offload-device-only \
+! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN:   | FileCheck %s --check-prefix=OFFLOAD-DEVICE
+
+! OFFLOAD-DEVICE: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
+! OFFLOAD-DEVICE-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"amdgcn-amd-amdhsa"
+! OFFLOAD-DEVICE-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"nvptx64-nvidia-cuda"
+! OFFLOAD-DEVICE-NOT: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
+
 ! Test regular -fopenmp with offload for basic fopenmp-is-device flag addition 
and correct fopenmp 
 ! RUN: %flang -### -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa %s 2>&1 | 
FileCheck --check-prefixes=CHECK-OPENMP-IS-DEVICE %s
 ! CHECK-OPENMP-IS-DEVICE: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} 
"-fopenmp-is-device" {{.*}}.f90"
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -65,6 +65,9 @@
 ! HELP-NEXT: -mmlir  Additional arguments to forward to MLIR's 
option processing
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -nocpp Disable predefined and command line 
preprocessor macros
+! HELP-NEXT: --offload-device-only   Only compile for the offloading device.
+! HELP-NEXT: --offload-host-device   Only compile for the offloading host.
+! HELP-NEXT: --offload-host-only Only compile for the offloading host.
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -pedantic  Warn on language extensions
 ! HELP-NEXT: -print-effective-triple Print the effective target triple
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -69,6 +69,9 @@
 ! CHECK-NEXT: -mmlir  Additional arguments to forward to MLIR's 
option processing
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -nocpp Disable predefined and command line 
preprocessor macros
+! CHECK-NEXT: --offload-device-only   Only compile for the offloading device.
+! CHECK-NEXT: --offload-host-device   Only compile for the offloading host.
+! CHECK-NEXT: --offload-host-only Only compile for the offloading host.
 ! CHECK-NEXT: -o  Write output to 
 ! CHECK-NEXT: -pedantic  Warn on language extensions
 ! CHECK-

[PATCH] D146101: [clang-format] Add BracedInitializerIndentWidth option.

2023-04-12 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added a comment.

In D146101#4261293 , @MyDeveloperDay 
wrote:

> If all comments and concerns are done, then I'm inclined to accept, but I'd 
> like @owenpan  and @HazardyKnusperkeks to give their opinion before we land 
> this.

Sure. Thanks!




Comment at: clang/lib/Format/ContinuationIndenter.cpp:1665-1669
+  const auto DesignatedInitializerIndentWidth =
+  Style.DesignatedInitializerIndentWidth < 0
+  ? Style.ContinuationIndentWidth
+  : Style.DesignatedInitializerIndentWidth;
+  NewIndent = CurrentState.LastSpace + DesignatedInitializerIndentWidth;

owenpan wrote:
> HazardyKnusperkeks wrote:
> > MyDeveloperDay wrote:
> > > rymiel wrote:
> > > > owenpan wrote:
> > > > > jp4a50 wrote:
> > > > > > HazardyKnusperkeks wrote:
> > > > > > > owenpan wrote:
> > > > > > > > jp4a50 wrote:
> > > > > > > > > HazardyKnusperkeks wrote:
> > > > > > > > > > owenpan wrote:
> > > > > > > > > > > jp4a50 wrote:
> > > > > > > > > > > > owenpan wrote:
> > > > > > > > > > > > > owenpan wrote:
> > > > > > > > > > > > > > Using -1 to mean `ContinuationIndentWidth` is 
> > > > > > > > > > > > > > unnecessary and somewhat confusing IMO.
> > > > > > > > > > > > > Please disregard my comment above.
> > > > > > > > > > > > Just to make sure we are on the same page, does this 
> > > > > > > > > > > > mean that you are happy with the approach of using `-1` 
> > > > > > > > > > > > as a default value to indicate that 
> > > > > > > > > > > > `ContinuationIndentWidth` should be used?
> > > > > > > > > > > > 
> > > > > > > > > > > > I did initially consider using 
> > > > > > > > > > > > `std::optional` and using empty optional to 
> > > > > > > > > > > > indicate that `ContinuationIndentWidth` should be used 
> > > > > > > > > > > > but I saw that `PPIndentWidth` was using `-1` to 
> > > > > > > > > > > > default to using `IndentWidth` so I followed that 
> > > > > > > > > > > > precedent.
> > > > > > > > > > > Yep! I would prefer the `optional`, but as you pointed 
> > > > > > > > > > > out, we already got `PPIndentWidth`using `-1`.
> > > > > > > > > > From the C++ side I totally agree. One could use 
> > > > > > > > > > `value_or()`, which would make the code much more readable.
> > > > > > > > > > And just because `PPIndentWidth` is using -1 is no reason 
> > > > > > > > > > to repeat that, we could just as easily change 
> > > > > > > > > > `PPIndentWidht` to an optional.
> > > > > > > > > > 
> > > > > > > > > > But how would it look in yaml?
> > > > > > > > > In YAML we wouldn't need to support empty optional being 
> > > > > > > > > *explicitly* specified - it would just be the default.
> > > > > > > > > 
> > > > > > > > > So specifying `DesignatedInitializerIndentWidth: 4` would set 
> > > > > > > > > the `std::optional` to `4` but if 
> > > > > > > > > `DesignatedInitializerIndentWidth` was omitted from the YAML 
> > > > > > > > > then the optional would simply not be set during parsing.
> > > > > > > > > 
> > > > > > > > > Of course, if we were to change `PPIndentWidth` to work that 
> > > > > > > > > way too, it would technically be a breaking change because 
> > > > > > > > > users may have *explicitly* specified `-1` in their YAML.
> > > > > > > > > And just because `PPIndentWidth` is using -1 is no reason to 
> > > > > > > > > repeat that, we could just as easily change `PPIndentWidht` 
> > > > > > > > > to an optional.
> > > > > > > > 
> > > > > > > > We would have to deal with backward compatibility to avoid 
> > > > > > > > regressions though.
> > > > > > > > In YAML we wouldn't need to support empty optional being 
> > > > > > > > *explicitly* specified - it would just be the default.
> > > > > > > > 
> > > > > > > > So specifying `DesignatedInitializerIndentWidth: 4` would set 
> > > > > > > > the `std::optional` to `4` but if 
> > > > > > > > `DesignatedInitializerIndentWidth` was omitted from the YAML 
> > > > > > > > then the optional would simply not be set during parsing.
> > > > > > > > 
> > > > > > > > Of course, if we were to change `PPIndentWidth` to work that 
> > > > > > > > way too, it would technically be a breaking change because 
> > > > > > > > users may have *explicitly* specified `-1` in their YAML.
> > > > > > > 
> > > > > > > You need an explicit entry, because you need to be able to write 
> > > > > > > the empty optional on `--dump-config`.
> > > > > > > > In YAML we wouldn't need to support empty optional being 
> > > > > > > > *explicitly* specified - it would just be the default.
> > > > > > > > 
> > > > > > > > So specifying `DesignatedInitializerIndentWidth: 4` would set 
> > > > > > > > the `std::optional` to `4` but if 
> > > > > > > > `DesignatedInitializerIndentWidth` was omitted from the YAML 
> > > > > > > > then the optional would simply not be set during parsing.
> > > > > > > > 
> > > > > > > > Of course, if we were to change `PPIndentWidth` to work that 
> > > 

[PATCH] D148131: Avoid unnecessarily aggressive line-breaking when using "LambdaBodyIndentation: OuterScope" with argument bin-packing.

2023-04-12 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
jp4a50 requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148131

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22011,8 +22011,7 @@
"  []() -> auto {\n"
"int b = 32;\n"
"return 3;\n"
-   "  },\n"
-   "  foo, bar)\n"
+   "  }, foo, bar)\n"
"  .foo();\n"
"}",
Style);
@@ -22038,32 +22037,12 @@
"  })));\n"
"}",
Style);
-  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
-  verifyFormat("void foo() {\n"
-   "  aFunction(\n"
-   "  1, b(c(\n"
-   " [](d) -> Foo {\n"
-   "auto f = e(d);\n"
-   "return f;\n"
-   "  },\n"
-   " foo, Bar{},\n"
-   " [] {\n"
-   "auto g = h();\n"
-   "return g;\n"
-   "  },\n"
-   " baz)));\n"
-   "}",
-   Style);
   verifyFormat("void foo() {\n"
"  aFunction(1, b(c(foo, Bar{}, baz, [](d) -> Foo {\n"
-   "auto f = e(\n"
-   "foo,\n"
-   "[&] {\n"
+   "auto f = e(foo, [&] {\n"
"  auto g = h();\n"
"  return g;\n"
-   "},\n"
-   "qux,\n"
-   "[&] -> Bar {\n"
+   "}, qux, [&] -> Bar {\n"
"  auto i = j();\n"
"  return i;\n"
"});\n"
@@ -22071,28 +22050,74 @@
"  })));\n"
"}",
Style);
-  verifyFormat("Namespace::Foo::Foo(\n"
-   "LongClassName bar, AnotherLongClassName baz)\n"
+  verifyFormat("Namespace::Foo::Foo(LongClassName bar,\n"
+   "AnotherLongClassName baz)\n"
": baz{baz}, func{[&] {\n"
"  auto qux = bar;\n"
"  return aFunkyFunctionCall(qux);\n"
"}} {}",
Style);
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  // As long as all the non-lambda arguments fit on a single line, AlwaysBreak
+  // doesn't force an initial line break, even if lambdas span multiple lines.
+  // This should probably be considered a bug.
+  verifyFormat("void foo() {\n"
+   "  aFunction([](d) -> Foo {\n"
+   "auto f = e(d);\n"
+   "return f;\n"
+   "  }, foo, Bar{}, [] {\n"
+   "auto g = h();\n"
+   "return g;\n"
+   "  }, baz);\n"
+   "}",
+   Style);
+  // A long non-lambda argument forces arguments to span multiple lines and thus
+  // forces an initial line break when using AlwaysBreak.
+  verifyFormat("void foo() {\n"
+   "  aFunction(\n"
+   "  1,\n"
+   "  [](d) -> Foo {\n"
+   "auto f = e(d);\n"
+   "return f;\n"
+   "  }, foo, Bar{},\n"
+   "  [] {\n"
+   "auto g = h();\n"
+   "return g;\n"
+   "  }, baz,\n"
+   "  qx);\n"
+   "}",
+   Style);
+  Style.BinPackArguments = false;
+  verifyFormat("void foo() {\n"
+   "  aFunction(\n"
+   "  1,\n"
+   "  [](d) -> Foo {\n"
+   "auto f = e(d);\n"
+   "return f;\n"
+   "  },\n"
+   "  foo,\n"
+   "  Bar{},\n"
+   "  [] {\n"
+   "auto g = h();\n"
+   "return g;\n"
+   "  },\n"
+   "  baz,\n"
+   "  qx);\n"
+   "}",
+   Style);
+  Style.BinPackArguments = true;
   Style.BreakBeforeBraces = FormatStyle::BS_Custom;
   Style.BraceWrapping.BeforeLambdaBody = true;
   verifyFormat("void foo() {\n"
"  aFunction(\n"
-   "  1, b(c(foo, Bar{}, baz,\n"
-   " [](d) -> Foo\n"
+   "  1, b(c(foo, Bar{}, baz, [](d) -> Foo\n"
   

[clang] d982643 - [clang] Implement CWG 2397

2023-04-12 Thread Younan Zhang via cfe-commits

Author: Younan Zhang
Date: 2023-04-12T22:30:23+08:00
New Revision: d9826433f31cd081d0229d47d7982b5bf3c0055f

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

LOG: [clang] Implement CWG 2397

This patch implements CWG 2397, allowing array of placeholder type
to be valid.

See also https://wg21.cmeerw.net/cwg/issue2397.

Reviewed By: aaron.ballman, #clang-language-wg

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

Added: 
clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/cwg2397.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaType.cpp
clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp
clang/test/CXX/drs/dr23xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dd66c71122999..e08aecfcc881f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -103,6 +103,8 @@ C++2b Feature Support
 
 Resolutions to C++ Defect Reports
 ^
+- Implemented `DR2397 `_ which allows ``auto`` 
specifier for pointers
+  and reference to arrays.
 
 C Language Changes
 --

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index cd5930d385e69..18a0154b00411 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2314,8 +2314,6 @@ def err_auto_variable_cannot_appear_in_own_initializer : 
Error<
 def err_binding_cannot_appear_in_own_initializer : Error<
   "binding %0 cannot appear in the initializer of its own "
   "decomposition declaration">;
-def err_illegal_decl_array_of_auto : Error<
-  "'%0' declared as array of %1">;
 def err_new_array_of_auto : Error<
   "cannot allocate array of 'auto'">;
 def err_auto_not_allowed : Error<

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index f557ff7b203fa..99e7ccfd88351 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5130,17 +5130,6 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
   D.setInvalidType(true);
 }
   }
-  const AutoType *AT = T->getContainedAutoType();
-  // Allow arrays of auto if we are a generic lambda parameter.
-  // i.e. [](auto (&array)[5]) { return array[0]; }; OK
-  if (AT && D.getContext() != DeclaratorContext::LambdaExprParameter) {
-// We've already diagnosed this for decltype(auto).
-if (!AT->isDecltypeAuto())
-  S.Diag(DeclType.Loc, diag::err_illegal_decl_array_of_auto)
-  << getPrintableNameForEntity(Name) << T;
-T = QualType();
-break;
-  }
 
   // Array parameters can be marked nullable as well, although it's not
   // necessary if they're marked 'static'.

diff  --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/cwg2397.cpp 
b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/cwg2397.cpp
new file mode 100644
index 0..f280d02a97513
--- /dev/null
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/cwg2397.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14
+
+void f() {
+  int a[5];
+  auto (*b)[5] = &a;
+  auto (&c)[5] = a;
+  auto (&&d)[5] = static_cast(a);
+  auto e[] = {0}; // expected-error{{cannot deduce actual type for variable 
'e' with type 'auto[]' from initializer list}}
+  static_assert(__is_same(decltype(b), int (*)[5]), "");
+  static_assert(__is_same(decltype(c), int (&)[5]), "");
+  static_assert(__is_same(decltype(d), int (&&)[5]), "");
+}
+
+#if __cplusplus >= 201402L
+
+constexpr int g() {
+  int a[] = {1, 2, 3};
+  auto (&b)[3] = a;
+  return b[1];
+}
+
+static_assert(g() == 2, "");
+
+#endif

diff  --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp 
b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp
index 102746c3db292..a3482d58afa1f 100644
--- a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp
@@ -2,6 +2,6 @@
 
 void f() {
   int b[5];
-  auto a[5] = b; // expected-error{{'a' declared as array of 'auto'}}
-  auto *c[5] = b; // expected-error{{'c' declared as array of 'auto *'}}
+  auto a[5] = b; // expected-error{{variable 'a' with type 'auto[5]' has 
incompatible initializer of type 'int[5]'}}
+  auto *c[5] = b; // expected-error{{variable 'c' with type 'auto *[5]' has 
incompatible initializer of type 'int[5]'}}
 }

diff  --git a/clang/test/CXX/drs/dr23xx.cpp b/clang/test/CXX/drs/dr23xx.cpp
index 4f16746aad8be..51879e913c6ba 100644
--- a/clang/test/

[PATCH] D147909: [clang] Implement CWG 2397

2023-04-12 Thread Younan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd9826433f31c: [clang] Implement CWG 2397 (authored by 
zyounan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147909

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaType.cpp
  clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/cwg2397.cpp
  clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp
  clang/test/CXX/drs/dr23xx.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -14189,7 +14189,7 @@
 https://wg21.link/cwg2397";>2397
 CD6
 auto specifier for pointers and references to arrays
-Unknown
+Clang 17
   
   
 https://wg21.link/cwg2398";>2398
Index: clang/test/CXX/drs/dr23xx.cpp
===
--- clang/test/CXX/drs/dr23xx.cpp
+++ clang/test/CXX/drs/dr23xx.cpp
@@ -213,3 +213,14 @@
   // void g(A a) { a.operator decltype(B()) B::*(); }
   // void g2(A a) { a.operator B decltype(B())::*(); }
 }
+
+#if __cplusplus >= 201103L
+namespace dr2397 { // dr2397: 17
+  void foo() {
+int a[5];
+
+auto (&b)[5] = a;
+auto (*c)[5] = &a;
+  }
+} // namespace dr2397
+#endif
Index: clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp
===
--- clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp
+++ clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp
@@ -2,6 +2,6 @@
 
 void f() {
   int b[5];
-  auto a[5] = b; // expected-error{{'a' declared as array of 'auto'}}
-  auto *c[5] = b; // expected-error{{'c' declared as array of 'auto *'}}
+  auto a[5] = b; // expected-error{{variable 'a' with type 'auto[5]' has incompatible initializer of type 'int[5]'}}
+  auto *c[5] = b; // expected-error{{variable 'c' with type 'auto *[5]' has incompatible initializer of type 'int[5]'}}
 }
Index: clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/cwg2397.cpp
===
--- /dev/null
+++ clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/cwg2397.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14
+
+void f() {
+  int a[5];
+  auto (*b)[5] = &a;
+  auto (&c)[5] = a;
+  auto (&&d)[5] = static_cast(a);
+  auto e[] = {0}; // expected-error{{cannot deduce actual type for variable 'e' with type 'auto[]' from initializer list}}
+  static_assert(__is_same(decltype(b), int (*)[5]), "");
+  static_assert(__is_same(decltype(c), int (&)[5]), "");
+  static_assert(__is_same(decltype(d), int (&&)[5]), "");
+}
+
+#if __cplusplus >= 201402L
+
+constexpr int g() {
+  int a[] = {1, 2, 3};
+  auto (&b)[3] = a;
+  return b[1];
+}
+
+static_assert(g() == 2, "");
+
+#endif
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5130,17 +5130,6 @@
   D.setInvalidType(true);
 }
   }
-  const AutoType *AT = T->getContainedAutoType();
-  // Allow arrays of auto if we are a generic lambda parameter.
-  // i.e. [](auto (&array)[5]) { return array[0]; }; OK
-  if (AT && D.getContext() != DeclaratorContext::LambdaExprParameter) {
-// We've already diagnosed this for decltype(auto).
-if (!AT->isDecltypeAuto())
-  S.Diag(DeclType.Loc, diag::err_illegal_decl_array_of_auto)
-  << getPrintableNameForEntity(Name) << T;
-T = QualType();
-break;
-  }
 
   // Array parameters can be marked nullable as well, although it's not
   // necessary if they're marked 'static'.
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2314,8 +2314,6 @@
 def err_binding_cannot_appear_in_own_initializer : Error<
   "binding %0 cannot appear in the initializer of its own "
   "decomposition declaration">;
-def err_illegal_decl_array_of_auto : Error<
-  "'%0' declared as array of %1">;
 def err_new_array_of_auto : Error<
   "cannot allocate array of 'auto'">;
 def err_auto_not_allowed : Error<
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -103,6 +103,8 @@
 
 Resolutions to C++ Defect Reports
 ^
+- Implemented `DR2397 `_ which allows ``auto`` specifier for pointers
+  and reference to arrays.
 
 C Language Changes
 --
_

[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-12 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D147073#4258981 , @aaron.ballman 
wrote:

> In D147073#4258664 , @zequanwu 
> wrote:
>
>> In D147073#4258529 , 
>> @aaron.ballman wrote:
>>
>>> In D147073#4258426 , @zequanwu 
>>> wrote:
>>>
 In D147073#4258396 , 
 @aaron.ballman wrote:

> In D147073#4258384 , @hans 
> wrote:
>
>> Again not an expert here, but lgtm.
>>
>> (Nit: the 
>> https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaExprCXX.cpp#L1528-L1530
>>  link in the description seems to point to the wrong code now, since 
>> main changed. Here is a link for 16.0.1: 
>> https://github.com/llvm/llvm-project/blob/llvmorg-16.0.1/clang/lib/Sema/SemaExprCXX.cpp#L1536)
>
> I'm confused -- I thought D147569  
> resolved the issue and so this patch is no longer needed?

 D147569  fixes 
 https://github.com/llvm/llvm-project/issues/45481. This one fixes another 
 issue crbug.com/1427933. Their stack trace look similar but not caused by 
 the same issue.

 Updated the link in summary to: 
 https://github.com/llvm/llvm-project/blob/llvmorg-16.0.1/clang/lib/Sema/SemaExprCXX.cpp#L1536
>>>
>>> Thank you for clarifying, I was confused. :-)
>>>
>>> I don't think the changes here are correct either -- it's glossing over an 
>>> issue that we're not properly tracking the source location in the AST. 
>>> Playing around with the reduced example is interesting though. If you 
>>> remove the default argument in the `T` constructor, the issue goes away. If 
>>> you stop using a forward declaration in the instantiation of `T`, the issue 
>>> goes away. If `S1` isn't a template, the issue goes away (but the issue 
>>> will come back if you then make `foo()` a template instead of `S1`). So it 
>>> seems that something about template instantiation is dropping the source 
>>> location information (perhaps) and we should be trying to track down where 
>>> that is to fix the root cause rather than work around it here for coverage 
>>> mapping alone. (The end location being incorrect can impact other things 
>>> that are harder to test because it'll be for things like fix-its that don't 
>>> work properly, which are easy to miss.)
>>
>> I agree that the real fix is to fix the source location information. If I 
>> just change [1] to `SourceRange Locs = SourceRange(LParenOrBraceLoc, 
>> RParenOrBraceLoc);`, the crash is gone. However, as the "FIXME" comment in 
>> [1] says, it's an intended work-around to drop source locations here. So, 
>> I'm assuming this kind of source location work-around could happen in 
>> multiple places in clang, and could happen in the future as a temporary 
>> work-around. Instead of crashing clang coverage for those work-around, we 
>> can at least skip coverage info for those expressions/statements.
>>
>> [1]: 
>> https://github.com/llvm/llvm-project/blob/llvmorg-16.0.1/clang/lib/Sema/SemaExprCXX.cpp#L1538
>
> Ugh, that workaround is unfortunate.
>
> You are correct that this same situation may come up in the future, but each 
> time it happens, I think it's a bug in the FE that needs to be addressed. I 
> worry that silencing the issues here will 1) lead to the actual bug staying 
> in the code base forever, and 2) be used as justification for making the same 
> workaround elsewhere in the code base, perhaps so often that it becomes "the 
> way things are supposed to work".
>
> Perhaps a way to split the middle would be to assert that the source 
> locations are valid in coverage mapping, but then do the right thing in 
> non-asserts builds instead of crashing. This way, we don't lose the benefit 
> of knowing the issues happen in development builds, but we don't punish users 
> of coverage mapping with the released product. WDYT?

Won't this still cause assertion failure on assert builds? I don't quite 
understand "do the right thing in non-asserts builds instead of crashing".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147073

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


[PATCH] D148131: Avoid unnecessarily aggressive line-breaking when using "LambdaBodyIndentation: OuterScope" with argument bin-packing.

2023-04-12 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added inline comments.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:333
+  // enabled.
+  !(Current.is(TT_LambdaLBrace) && Style.BraceWrapping.BeforeLambdaBody) &&
   CurrentState.NoLineBreakInOperand) {

AFAICT, this only matters when using `OuterScope`, but it seems like a sensible 
exception to make in the general case, so I haven't included a check for 
`OuterScope` here.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1040
+  //
+  // We specifically special case "OuterScope"-formatted lambdas here
+  // because, when using that setting, breaking before the parameter

So I genuinely think that the original implementation here (which I've left 
intact *except* for when OuterScope is enabled) does not match up to the 
intention expressed in the comment in line 1018.

It effectively seems to assume that the parenthesis level entry which is second 
from the top is the 'parent' parenthesis level, but this ignores the fact that 
there are often "fake parens" entries in the parenthesis state stack which 
presumably should be ignored (as I have done in my implementation for 
OuterScope).

As such, there are a lot of cases where (when OuterScope is not enabled) we 
apply `BreakBeforeParameter` to the *existing* parenthesis level rather than 
the parent parenthesis level. So when I tried to "fix" this behaviour in the 
general case it broke a lot of tests, even though I think the behaviour may be 
what was originally intended.

Happy to discuss this and be proven wrong, but I thought I'd explain why I've 
added a special case here for OuterScope in even greater detail than I have in 
the comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148131

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


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-12 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 512837.
junaire added a comment.

dont include  if we don't have it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +281,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +318,55 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_TRUE(V1.isValid());
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+  EXPECT_EQ(V1.getKind(), Value::K_Int);
+  EXPECT_FALSE(V1.isManuallyAlloc());
+  EXPECT_FALSE(V1.isPointerOrObjectType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_TRUE(V2.isValid());
+  EXPECT_EQ(V2.getDouble(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.getKind(), Value::K_Double);
+  EXPECT_FALSE(V2.isManuallyAlloc());
+  EXPECT_FALSE(V2.isPointerOrObjectType());
+
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute(
+  "struct S { int* p; S() { p = new int(42); } ~S() { delete p; }};"));
+  llvm::cantFail(Interp->ParseAndExecute("S{}", &V3));
+  EXPECT_TRUE(V3.isValid());
+  EXPECT_TRUE(V3.getType()->isRecordType());
+  EXPECT_EQ(V3.getKind(), Value::K_PtrOrObj);
+  EXPECT_TRUE(V3.isManuallyAlloc());
+  EXPECT_TRUE(V3.isPointerOrObjectType());
+
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 42);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  Value V5;
+  // Change the global from the compiled code.
+  setGlobal(43);
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V5));
+  EXPECT_EQ(V5.getInt(), 43);
+  EXPECT_TRUE(V5.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Par

[PATCH] D148136: [clang] Add test for CWG1894 and CWG2199

2023-04-12 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill created this revision.
Endill added a reviewer: clang-language-wg.
Herald added a project: All.
Endill requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

P1787 : CWG1894 and its duplicate CWG2199 are resolved 
per Richard’s proposal for “dr407 still leaves open questions about typedef / 
tag hiding” 
, using 
generic conflicting-declaration rules even for typedef, and discarding a 
redundant typedef-name when looking up an elaborated-type-specifier.
Wording: See changes to [dcl.typedef], [basic.lookup.elab], and 
[basic.lookup]/4.

Generic conflicting-declaration rules are specified in changes to 
[basic.scope.scope]. CWG407 , 
CWG1894 , and CWG2199 
 discuss how elaborated type 
specifiers interact with typedef, using directives, and using declarations. 
Since existing test for CWG407 covers examples provided in CWG1894 and CWG2199, 
and does it in accordance with P1787 , I reused 
it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148136

Files:
  clang/test/CXX/drs/dr18xx.cpp
  clang/test/CXX/drs/dr21xx.cpp
  clang/test/CXX/drs/dr4xx.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -11171,7 +11171,7 @@
 https://wg21.link/cwg1894";>1894
 CD6
 typedef-names and using-declarations
-Unknown
+Clang 3.8
   
   
 https://wg21.link/cwg1895";>1895
@@ -13001,7 +13001,7 @@
 https://wg21.link/cwg2199";>2199
 CD6
 Typedefs and tags
-Unknown
+Clang 3.8
   
   
 https://wg21.link/cwg2200";>2200
Index: clang/test/CXX/drs/dr4xx.cpp
===
--- clang/test/CXX/drs/dr4xx.cpp
+++ clang/test/CXX/drs/dr4xx.cpp
@@ -124,6 +124,7 @@
 }
 
 namespace dr407 { // dr407: 3.8
+  // NB: reused by dr1894 and dr2199
   struct S;
   typedef struct S S;
   void f() {
Index: clang/test/CXX/drs/dr21xx.cpp
===
--- clang/test/CXX/drs/dr21xx.cpp
+++ clang/test/CXX/drs/dr21xx.cpp
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2b -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 
 #if __cplusplus < 201103L
 // expected-error@+1 {{variadic macro}}
@@ -188,3 +190,60 @@
   B &B::operator=(B&&) = default; // expected-error {{would delete}} expected-note@-10{{inaccessible move assignment}}
 #endif
 }
+
+namespace dr2199 { // dr2199: 3.8
+   // NB: reusing dr407 test
+  struct S;
+  typedef struct S S;
+  void f() {
+struct S *p;
+{
+  typedef struct S S; // #dr2199-typedef-S-S
+  struct S *p;
+  // expected-error@-1 {{typedef 'S' cannot be referenced with a struct specifier}}
+  // expected-note@#dr2199-typedef-S-S {{here}}
+}
+  }
+  struct S {};
+
+  namespace UsingDir {
+namespace A {
+  struct S {}; // #dr2199-struct-S
+}
+namespace B {
+  typedef int S; // #dr2199-typedef-int-S
+}
+namespace C {
+  using namespace A;
+  using namespace B;
+  struct S s;
+  // expected-error@-1 {{ambiguous}}
+  // expected-note@#dr2199-struct-S {{candidate}}
+  // expected-note@#dr2199-typedef-int-S {{candidate}}
+}
+namespace D {
+  using A::S;
+  typedef struct S S;
+  struct S s;
+}
+namespace E {
+  typedef A::S S;
+  using A::S;
+  struct S s;
+}
+namespace F {
+  typedef A::S S;
+}
+
+namespace G {
+  using namespace A;
+  using namespace F;
+  struct S s;
+}
+namespace H {
+  using namespace F;
+  using namespace A;
+  struct S s;
+}
+  }
+}
Index: clang/test/

[PATCH] D147888: Update declaration message of extern linkage

2023-04-12 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 512848.
Krishna-13-cyber added a comment.

- Updated with removing redundant flags


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147888

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/extern_static.cpp


Index: clang/test/SemaCXX/extern_static.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/extern_static.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+void f(void)
+{
+static int x; // expected-note {{previous definition is here}}
+extern int x; // expected-error {{extern declaration of 'x' follows static 
declaration}}
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4637,6 +4637,15 @@
   //   the prior declaration. If no prior declaration is visible, or
   //   if the prior declaration specifies no linkage, then the
   //   identifier has external linkage.
+
+  if (New->hasExternalStorage() &&
+  Old->getCanonicalDecl()->getStorageClass() == SC_Static &&
+  Old->isLocalVarDeclOrParm()) {
+Diag(New->getLocation(), diag::err_extern_static) << New->getDeclName();
+Diag(OldLocation, PrevDiag);
+return New->setInvalidDecl();
+  }
+
   if (New->hasExternalStorage() && Old->hasLinkage())
 /* Okay */;
   else if (New->getCanonicalDecl()->getStorageClass() != SC_Static &&
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5799,6 +5799,8 @@
   InGroup;
 def err_non_static_static : Error<
   "non-static declaration of %0 follows static declaration">;
+def err_extern_static : Error<
+  "extern declaration of %0 follows static declaration">;
 def err_extern_non_extern : Error<
   "extern declaration of %0 follows non-extern declaration">;
 def err_non_extern_extern : Error<


Index: clang/test/SemaCXX/extern_static.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/extern_static.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+void f(void)
+{
+static int x; // expected-note {{previous definition is here}}
+extern int x; // expected-error {{extern declaration of 'x' follows static declaration}}
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4637,6 +4637,15 @@
   //   the prior declaration. If no prior declaration is visible, or
   //   if the prior declaration specifies no linkage, then the
   //   identifier has external linkage.
+
+  if (New->hasExternalStorage() &&
+  Old->getCanonicalDecl()->getStorageClass() == SC_Static &&
+  Old->isLocalVarDeclOrParm()) {
+Diag(New->getLocation(), diag::err_extern_static) << New->getDeclName();
+Diag(OldLocation, PrevDiag);
+return New->setInvalidDecl();
+  }
+
   if (New->hasExternalStorage() && Old->hasLinkage())
 /* Okay */;
   else if (New->getCanonicalDecl()->getStorageClass() != SC_Static &&
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5799,6 +5799,8 @@
   InGroup;
 def err_non_static_static : Error<
   "non-static declaration of %0 follows static declaration">;
+def err_extern_static : Error<
+  "extern declaration of %0 follows static declaration">;
 def err_extern_non_extern : Error<
   "extern declaration of %0 follows non-extern declaration">;
 def err_non_extern_extern : Error<
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148124: [RISCV][Driver] Allow the use of CPUs with a different XLEN than the triple.

2023-04-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

What is the interaction between this and the -m32 and -m64 options?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148124

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


[PATCH] D148112: [include-cleaner] Improve handling for templates

2023-04-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 512851.
kadircet marked an inline comment as done.
kadircet added a comment.
Herald added a subscriber: ChuanqiXu.

- Ignore explicit instantiations
- Update tests to use decls


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148112

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -6,24 +6,34 @@
 //
 //===--===//
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Types.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Testing/TestAST.h"
-#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/GenericUniformityImpl.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Testing/Annotations/Annotations.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 #include 
 
 namespace clang::include_cleaner {
 namespace {
+using testing::ElementsAre;
 
 // Specifies a test of which symbols are referenced by a piece of code.
 // Target should contain points annotated with the reference kind.
@@ -31,7 +41,9 @@
 //   Target:  int $explicit^foo();
 //   Referencing: int x = ^foo();
 // There must be exactly one referencing location marked.
-void testWalk(llvm::StringRef TargetCode, llvm::StringRef ReferencingCode) {
+// Returns target decls.
+std::vector testWalk(llvm::StringRef TargetCode,
+  llvm::StringRef ReferencingCode) {
   llvm::Annotations Target(TargetCode);
   llvm::Annotations Referencing(ReferencingCode);
 
@@ -51,6 +63,7 @@
   FileID TargetFile = SM.translateFile(
   llvm::cantFail(AST.fileManager().getFileRef("target.h")));
 
+  std::vector TargetDecls;
   // Perform the walk, and capture the offsets of the referenced targets.
   std::unordered_map> ReferencedOffsets;
   for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
@@ -63,6 +76,7 @@
   if (NDLoc.first != TargetFile)
 return;
   ReferencedOffsets[RT].push_back(NDLoc.second);
+  TargetDecls.push_back(&ND);
 });
   }
   for (auto &Entry : ReferencedOffsets)
@@ -94,6 +108,7 @@
   // If there were any differences, we print the entire referencing code once.
   if (!DiagBuf.empty())
 ADD_FAILURE() << DiagBuf << "\nfrom code:\n" << ReferencingCode;
+  return TargetDecls;
 }
 
 TEST(WalkAST, DeclRef) {
@@ -114,25 +129,127 @@
   // One explicit call from the TypeLoc in constructor spelling, another
   // implicit reference through the constructor call.
   testWalk("struct $explicit^$implicit^S { static int x; };", "auto y = ^S();");
-  testWalk("template struct $explicit^Foo {};", "^Foo x;");
-  testWalk(R"cpp(
+}
+
+MATCHER_P(HasKind, Kind, "") {
+  if (arg->getKind() == Kind)
+return true;
+  *result_listener << "Got kind: " << arg->getDeclKindName();
+  return false;
+}
+
+TEST(WalkAST, ClassTemplates) {
+  // Explicit instantiation and (partial) specialization references primary
+  // template.
+  EXPECT_THAT(testWalk("template struct $explicit^Foo{};",
+   "template struct ^Foo;"),
+  ElementsAre(HasKind(Decl::CXXRecord)));
+  EXPECT_THAT(testWalk("template struct $explicit^Foo{};",
+   "template<> struct ^Foo {};"),
+  ElementsAre(HasKind(Decl::CXXRecord)));
+  EXPECT_THAT(testWalk("template struct $explicit^Foo{};",
+   "template struct ^Foo {};"),
+  ElementsAre(HasKind(Decl::CXXRecord)));
+
+  // Implicit instantiations references most relevant template.
+  EXPECT_THAT(
+  testWalk("template struct $explicit^Foo {};", "^Foo x;"),
+  ElementsAre(HasKind(Decl::CXXRecord)));
+  EXPECT_THAT(testWalk(R"cpp(
 template struct Foo {};
 template<> struct $explicit^Foo {};)cpp",
-   "^Foo x;");
-  testWalk(R"cpp(
+   "^Foo x;"),
+  ElementsAre(HasKind(Decl::ClassTemplateSpecialization)));
+  EXPECT_THAT(testWalk(R"cpp(
 template struct Foo {};
 template struct $explicit^Foo { void x(); };)cpp",
-   "^Foo x;");
-  testWalk(R"cpp(
-template struct Foo {};
-templ

[PATCH] D148112: [include-cleaner] Improve handling for templates

2023-04-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 3 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:109
 ADD_FAILURE() << DiagBuf << "\nfrom code:\n" << ReferencingCode;
+  llvm::sort(TargetDeclKinds);
+  TargetDeclKinds.erase(llvm::unique(TargetDeclKinds), TargetDeclKinds.end());

sammccall wrote:
> this seems a little ad-hoc (is class name always enough info, why are we 
> sorting/uniquing here)
> 
> Consider returning vector and using a matcher to verify the 
> things you care about (`kind(Decl::ClassTemplate)` or so?)
sorry was planning to drop this actually, analysistest covers the "we're 
picking the right declaration at a certain location" logic. but since i forgot, 
i might as well change it to keep decls around :P


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148112

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


[clang-tools-extra] 34f5774 - [include-cleaner] Improve handling for templates

2023-04-12 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-04-12T17:36:05+02:00
New Revision: 34f5774920f54f81b3e3a361a7c7f21a61e39b39

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

LOG: [include-cleaner] Improve handling for templates

Principal here is:
- Making sure each template instantiation implies use of the most specialized
  template. As explicit instantiations/specializations are not redeclarations of
  the primary template.
- Introducing a use from explicit instantions/specializaitons to the primary
  template, as they're required but not traversed as part of the RAV.

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp 
b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index f702460ccbb22..25afdaa3a75b0 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -8,8 +8,10 @@
 
 #include "AnalysisInternal.h"
 #include "clang-include-cleaner/Types.h"
+#include "clang/AST/ASTFwd.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
@@ -72,17 +74,25 @@ class ASTWalker : public RecursiveASTVisitor {
   // Picks the most specific specialization for a
   // (Deduced)TemplateSpecializationType, while prioritizing using-decls.
   NamedDecl *getMostRelevantTemplatePattern(const T *TST) {
-// This is the underlying decl used by TemplateSpecializationType, can be
-// null when type is dependent.
-auto *RD = TST->getAsTagDecl();
-auto *ND = resolveTemplateName(TST->getTemplateName());
 // In case of exported template names always prefer the using-decl. This
 // implies we'll point at the using-decl even when there's an explicit
 // specializaiton using the exported name, but that's rare.
+auto *ND = resolveTemplateName(TST->getTemplateName());
 if (llvm::isa_and_present(ND))
   return ND;
-// Fallback to primary template for dependent instantiations.
-return RD ? RD : ND;
+// This is the underlying decl used by TemplateSpecializationType, can be
+// null when type is dependent if so fallback to primary template.
+CXXRecordDecl *TD = TST->getAsCXXRecordDecl();
+if (!TD)
+  return ND;
+// We ignore explicit instantiations. This might imply marking the wrong
+// declaration as used in specific cases, but seems like the right 
trade-off
+// in general (e.g. we don't want to include a custom library that has an
+// explicit specialization of a common type).
+if (auto *Pat = TD->getTemplateInstantiationPattern())
+  return Pat;
+// For explicit specializations, use the specialized decl directly.
+return TD;
   }
 
 public:
@@ -182,6 +192,23 @@ class ASTWalker : public RecursiveASTVisitor {
 return true;
   }
 
+  // Report a reference from explicit specializations to the specialized
+  // template. Implicit ones are filtered out by RAV and explicit 
instantiations
+  // are already traversed through typelocs.
+  bool
+  VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *CTSD) {
+if (CTSD->isExplicitSpecialization())
+  report(CTSD->getLocation(),
+ CTSD->getSpecializedTemplate()->getTemplatedDecl());
+return true;
+  }
+  bool VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *VTSD) 
{
+if (VTSD->isExplicitSpecialization())
+  report(VTSD->getLocation(),
+ VTSD->getSpecializedTemplate()->getTemplatedDecl());
+return true;
+  }
+
   // TypeLoc visitors.
   bool VisitUsingTypeLoc(UsingTypeLoc TL) {
 report(TL.getNameLoc(), TL.getFoundDecl());

diff  --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
index dc649b1392294..8593d05a1b12d 100644
--- a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -16,11 +16,11 @@
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Format/Format.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ScopedPrinter.h"

[PATCH] D148112: [include-cleaner] Improve handling for templates

2023-04-12 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 rG34f5774920f5: [include-cleaner] Improve handling for 
templates (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148112

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -6,24 +6,34 @@
 //
 //===--===//
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Types.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Testing/TestAST.h"
-#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/GenericUniformityImpl.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Testing/Annotations/Annotations.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 #include 
 
 namespace clang::include_cleaner {
 namespace {
+using testing::ElementsAre;
 
 // Specifies a test of which symbols are referenced by a piece of code.
 // Target should contain points annotated with the reference kind.
@@ -31,7 +41,9 @@
 //   Target:  int $explicit^foo();
 //   Referencing: int x = ^foo();
 // There must be exactly one referencing location marked.
-void testWalk(llvm::StringRef TargetCode, llvm::StringRef ReferencingCode) {
+// Returns target decls.
+std::vector testWalk(llvm::StringRef TargetCode,
+  llvm::StringRef ReferencingCode) {
   llvm::Annotations Target(TargetCode);
   llvm::Annotations Referencing(ReferencingCode);
 
@@ -51,6 +63,7 @@
   FileID TargetFile = SM.translateFile(
   llvm::cantFail(AST.fileManager().getFileRef("target.h")));
 
+  std::vector TargetDecls;
   // Perform the walk, and capture the offsets of the referenced targets.
   std::unordered_map> ReferencedOffsets;
   for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
@@ -63,6 +76,7 @@
   if (NDLoc.first != TargetFile)
 return;
   ReferencedOffsets[RT].push_back(NDLoc.second);
+  TargetDecls.push_back(&ND);
 });
   }
   for (auto &Entry : ReferencedOffsets)
@@ -94,6 +108,7 @@
   // If there were any differences, we print the entire referencing code once.
   if (!DiagBuf.empty())
 ADD_FAILURE() << DiagBuf << "\nfrom code:\n" << ReferencingCode;
+  return TargetDecls;
 }
 
 TEST(WalkAST, DeclRef) {
@@ -114,25 +129,127 @@
   // One explicit call from the TypeLoc in constructor spelling, another
   // implicit reference through the constructor call.
   testWalk("struct $explicit^$implicit^S { static int x; };", "auto y = ^S();");
-  testWalk("template struct $explicit^Foo {};", "^Foo x;");
-  testWalk(R"cpp(
+}
+
+MATCHER_P(HasKind, Kind, "") {
+  if (arg->getKind() == Kind)
+return true;
+  *result_listener << "Got kind: " << arg->getDeclKindName();
+  return false;
+}
+
+TEST(WalkAST, ClassTemplates) {
+  // Explicit instantiation and (partial) specialization references primary
+  // template.
+  EXPECT_THAT(testWalk("template struct $explicit^Foo{};",
+   "template struct ^Foo;"),
+  ElementsAre(HasKind(Decl::CXXRecord)));
+  EXPECT_THAT(testWalk("template struct $explicit^Foo{};",
+   "template<> struct ^Foo {};"),
+  ElementsAre(HasKind(Decl::CXXRecord)));
+  EXPECT_THAT(testWalk("template struct $explicit^Foo{};",
+   "template struct ^Foo {};"),
+  ElementsAre(HasKind(Decl::CXXRecord)));
+
+  // Implicit instantiations references most relevant template.
+  EXPECT_THAT(
+  testWalk("template struct $explicit^Foo {};", "^Foo x;"),
+  ElementsAre(HasKind(Decl::CXXRecord)));
+  EXPECT_THAT(testWalk(R"cpp(
 template struct Foo {};
 template<> struct $explicit^Foo {};)cpp",
-   "^Foo x;");
-  testWalk(R"cpp(
+   "^Foo x;"),
+  ElementsAre(HasKind(Decl::ClassTemplateSpecialization)));
+  EXPECT_THAT(testWalk(R"cpp(
 template struct Foo {};
 template struct $explicit^Foo { void x(); };)cpp",
-   "^Foo x;");
-  testWalk(R"cpp(
-template struc

[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D147073#4261633 , @zequanwu wrote:

> In D147073#4258981 , @aaron.ballman 
> wrote:
>
>> Perhaps a way to split the middle would be to assert that the source 
>> locations are valid in coverage mapping, but then do the right thing in 
>> non-asserts builds instead of crashing. This way, we don't lose the benefit 
>> of knowing the issues happen in development builds, but we don't punish 
>> users of coverage mapping with the released product. WDYT?
>
> Won't this still cause assertion failure on assert builds?

Yes, it will, but that's the goal in this case. I think we want the loud 
failure to tell us when we've

> I don't quite understand "do the right thing in non-asserts builds instead of 
> crashing".

For example:

  // If either of these locations is invalid, something elsewhere in the 
compiler has broken...
  assert(StartLoc && StartLoc->isInvalid() && "Start location is not valid");
  assert(EndLoc && EndLoc->isInvalid() && "End location is not valid");
  
  // ... however, we can still recover without crashing.
  if (StartLoc && StartLoc->isInvalid())
StartLoc = std::nullopt;
  if (EndLoc && EndLoc->isInvalid())
EndLoc = std::nullopt;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147073

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


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/test/SemaCXX/attr-riscv-rvv-vector-bits.cpp:12
+
+template struct S { T var; };
+

@erichkeane does this cover the dependent case or were you looking for 
something else?

Here are on the only mentions of template I see in SVE tests that use this 
attribute.

```
clang/test$ ack template `ack arm_sve_vector -l`
CodeGenCXX/aarch64-mangle-sve-fixed-vectors.cpp
37:template  struct S {};

SemaCXX/attr-arm-sve-vector-bits.cpp
16:template struct S { T var; };
```

Here is the result for this patch

```
clang/test$ ack template `ack riscv_rvv_vector -l`
CodeGenCXX/riscv-mangle-rvv-fixed-vectors.cpp
48:template  struct S {};

SemaCXX/attr-riscv-rvv-vector-bits.cpp
12:template struct S { T var; };
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/AST/ASTContext.h:2262
+  /// Return true if the given vector types are lax-compatible RISC-V vector
+  /// types as defined by -flax-vector-conversions=, false otherwise.
+  bool areLaxCompatibleRVVTypes(QualType FirstType, QualType SecondType);

erichkeane wrote:
> I still had to look this one up.
That's not quite the description of -flax-vector-conversion. The total vector 
size must be the same. But the element size and number of elements can be 
different.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-12 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

> Well, MSVC cl removes redundant dots so we shouldn't remove 
> llvm::sys::path::remove_dots.

Could we do the `remove_dots` on the Clang side, where we can decide based on 
the LangOpts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147256

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


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/include/clang/AST/ASTContext.h:2263
+  /// types as defined by -flax-vector-conversions=, which permits implicit
+  /// conversions between vectors wit different number of elemnts and/or
+  /// incompatible element types, false otherwise.





Comment at: clang/test/SemaCXX/attr-riscv-rvv-vector-bits.cpp:12
+
+template struct S { T var; };
+

craig.topper wrote:
> @erichkeane does this cover the dependent case or were you looking for 
> something else?
> 
> Here are on the only mentions of template I see in SVE tests that use this 
> attribute.
> 
> ```
> clang/test$ ack template `ack arm_sve_vector -l`
> CodeGenCXX/aarch64-mangle-sve-fixed-vectors.cpp
> 37:template  struct S {};
> 
> SemaCXX/attr-arm-sve-vector-bits.cpp
> 16:template struct S { T var; };
> ```
> 
> Here is the result for this patch
> 
> ```
> clang/test$ ack template `ack riscv_rvv_vector -l`
> CodeGenCXX/riscv-mangle-rvv-fixed-vectors.cpp
> 48:template  struct S {};
> 
> SemaCXX/attr-riscv-rvv-vector-bits.cpp
> 12:template struct S { T var; };
> ```
Thats unfortunate, and I wish I'd thought of it at the time/been more active 
reviewing the SVE stuff then.  Really what I'm looking for is:

```
template 
struct Whatever {
  using Something = char __attribute((riscv_rvv_vector_bits(N)));
};

void Func(Whatever<5>::Something MyVar){}

```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D147073: [Coverage] Handle invalid end location of an expression/statement.

2023-04-12 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 512868.
zequanwu added a comment.

Add assertion on source locations in `pushRegion`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147073

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp


Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,19 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If either of these locations is invalid, something elsewhere in the
+// compiler has broken.
+assert((!StartLoc || StartLoc->isValid()) && "Start location is not 
valid");
+assert((!EndLoc || EndLoc->isValid()) && "End location is not valid");
+
+// However, we can still recover without crashing.
+// If either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +637,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion &Region = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +705,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
   RegionStack.pop_back();
 }
   }


Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -602,6 +602,19 @@
   MostRecentLocation = *StartLoc;
 }
 
+// If either of these locations is invalid, something elsewhere in the
+// compiler has broken.
+assert((!StartLoc || StartLoc->isValid()) && "Start location is not valid");
+assert((!EndLoc || EndLoc->isValid()) && "End location is not valid");
+
+// However, we can still recover without crashing.
+// If either location is invalid, set it to std::nullopt to avoid
+// letting users of RegionStack think that region has a valid start/end
+// location.
+if (StartLoc && StartLoc->isInvalid())
+  StartLoc = std::nullopt;
+if (EndLoc && EndLoc->isInvalid())
+  EndLoc = std::nullopt;
 RegionStack.emplace_back(Count, FalseCount, StartLoc, EndLoc);
 
 return RegionStack.size() - 1;
@@ -624,7 +637,8 @@
 assert(RegionStack.size() >= ParentIndex && "parent not in stack");
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion &Region = RegionStack.back();
-  if (Region.hasStartLoc()) {
+  if (Region.hasStartLoc() &&
+  (Region.hasEndLoc() || RegionStack[ParentIndex].hasEndLoc())) {
 SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? Region.getEndLoc()
@@ -691,7 +705,7 @@
 assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc));
 assert(SpellingRegion(SM, Region).isInSourceOrder());
 SourceRegions.push_back(Region);
-}
+  }
   RegionStack.pop_back();
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-12 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 512869.
junaire added a comment.

fix ci


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +281,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +318,55 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_TRUE(V1.isValid());
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+  EXPECT_EQ(V1.getKind(), Value::K_Int);
+  EXPECT_FALSE(V1.isManuallyAlloc());
+  EXPECT_FALSE(V1.isPointerOrObjectType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_TRUE(V2.isValid());
+  EXPECT_EQ(V2.getDouble(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.getKind(), Value::K_Double);
+  EXPECT_FALSE(V2.isManuallyAlloc());
+  EXPECT_FALSE(V2.isPointerOrObjectType());
+
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute(
+  "struct S { int* p; S() { p = new int(42); } ~S() { delete p; }};"));
+  llvm::cantFail(Interp->ParseAndExecute("S{}", &V3));
+  EXPECT_TRUE(V3.isValid());
+  EXPECT_TRUE(V3.getType()->isRecordType());
+  EXPECT_EQ(V3.getKind(), Value::K_PtrOrObj);
+  EXPECT_TRUE(V3.isManuallyAlloc());
+  EXPECT_TRUE(V3.isPointerOrObjectType());
+
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 42);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  Value V5;
+  // Change the global from the compiled code.
+  setGlobal(43);
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V5));
+  EXPECT_EQ(V5.getInt(), 43);
+  EXPECT_TRUE(V5.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Parse/Parser.cpp
=

[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-12 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D147256#4261949 , @hans wrote:

>> Well, MSVC cl removes redundant dots so we shouldn't remove 
>> llvm::sys::path::remove_dots.
>
> Could we do the `remove_dots` on the Clang side, where we can decide based on 
> the LangOpts?

Yes, we can do that. Is there a reason to favor there over here? At here, the 
object path in llc output can also benefits from `remove_dots`, not just clang.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147256

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


[PATCH] D148143: [clangd] Treat preamble patch as main file for include-cleaner analysis

2023-04-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
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.

Since we redefine all macros in preamble-patch, and it's parsed after
consuming the preamble macros, we can get false missing-include diagnostics
while a fresh preamble is being rebuilt.

This patch makes sure preamble-patch is treated same as main file for
include-cleaner purposes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148143

Files:
  clang-tools-extra/clangd/IncludeCleaner.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
@@ -666,6 +666,7 @@
   Config Cfg;
   Cfg.Diagnostics.AllowStalePreamble = true;
   Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict;
+  Cfg.Diagnostics.MissingIncludes = Config::IncludesPolicy::Strict;
   WithContextValue WithCfg(Config::Key, std::move(Cfg));
 
   llvm::StringMap AdditionalFiles;
@@ -699,6 +700,8 @@
   {
 Annotations Code("#define [[FOO]] 1\n");
 // Check ranges for notes.
+// This also makes sure we don't generate missing-include diagnostics
+// because macros are redefined in preamble-patch.
 Annotations NewCode(R"(#define BARXYZ 1
 #define $foo1[[FOO]] 1
 void foo();
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -11,6 +11,7 @@
 #include "Diagnostics.h"
 #include "Headers.h"
 #include "ParsedAST.h"
+#include "Preamble.h"
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "URI.h"
@@ -112,12 +113,12 @@
   return false;
 // Check if main file is the public interface for a private header. If so 
we
 // shouldn't diagnose it as unused.
-if(auto PHeader = PI->getPublic(*FE); !PHeader.empty()) {
+if (auto PHeader = PI->getPublic(*FE); !PHeader.empty()) {
   PHeader = PHeader.trim("<>\"");
   // Since most private -> public mappings happen in a verbatim way, we
   // check textually here. This might go wrong in presence of symlinks or
   // header mappings. But that's not different than rest of the places.
-  if(AST.tuPath().endswith(PHeader))
+  if (AST.tuPath().endswith(PHeader))
 return false;
 }
   }
@@ -374,7 +375,8 @@
 bool Satisfied = false;
 for (const auto &H : Providers) {
   if (H.kind() == include_cleaner::Header::Physical &&
-  H.physical() == MainFile) {
+  (H.physical() == MainFile ||
+   H.physical()->getName().endswith(PreamblePatch::HeaderName))) {
 Satisfied = true;
 continue;
   }


Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -666,6 +666,7 @@
   Config Cfg;
   Cfg.Diagnostics.AllowStalePreamble = true;
   Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict;
+  Cfg.Diagnostics.MissingIncludes = Config::IncludesPolicy::Strict;
   WithContextValue WithCfg(Config::Key, std::move(Cfg));
 
   llvm::StringMap AdditionalFiles;
@@ -699,6 +700,8 @@
   {
 Annotations Code("#define [[FOO]] 1\n");
 // Check ranges for notes.
+// This also makes sure we don't generate missing-include diagnostics
+// because macros are redefined in preamble-patch.
 Annotations NewCode(R"(#define BARXYZ 1
 #define $foo1[[FOO]] 1
 void foo();
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -11,6 +11,7 @@
 #include "Diagnostics.h"
 #include "Headers.h"
 #include "ParsedAST.h"
+#include "Preamble.h"
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "URI.h"
@@ -112,12 +113,12 @@
   return false;
 // Check if main file is the public interface for a private header. If so we
 // shouldn't diagnose it as unused.
-if(auto PHeader = PI->getPublic(*FE); !PHeader.empty()) {
+if (auto PHeader = PI->getPublic(*FE); !PHeader.empty()) {
   PHeader = PHeader.trim("<>\"");
   // Since most private -> public mappings happen in a verbatim way, we
   // check textually here. This might go wrong in presence of symlinks or
   // header mappings. But that's not different than rest of the places.
-  if(AST.tuPath().endswith(PHeader))
+  if (AST.tuPath(

[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/test/SemaCXX/attr-riscv-rvv-vector-bits.cpp:12
+
+template struct S { T var; };
+

erichkeane wrote:
> craig.topper wrote:
> > @erichkeane does this cover the dependent case or were you looking for 
> > something else?
> > 
> > Here are on the only mentions of template I see in SVE tests that use this 
> > attribute.
> > 
> > ```
> > clang/test$ ack template `ack arm_sve_vector -l`
> > CodeGenCXX/aarch64-mangle-sve-fixed-vectors.cpp
> > 37:template  struct S {};
> > 
> > SemaCXX/attr-arm-sve-vector-bits.cpp
> > 16:template struct S { T var; };
> > ```
> > 
> > Here is the result for this patch
> > 
> > ```
> > clang/test$ ack template `ack riscv_rvv_vector -l`
> > CodeGenCXX/riscv-mangle-rvv-fixed-vectors.cpp
> > 48:template  struct S {};
> > 
> > SemaCXX/attr-riscv-rvv-vector-bits.cpp
> > 12:template struct S { T var; };
> > ```
> Thats unfortunate, and I wish I'd thought of it at the time/been more active 
> reviewing the SVE stuff then.  Really what I'm looking for is:
> 
> ```
> template 
> struct Whatever {
>   using Something = char __attribute((riscv_rvv_vector_bits(N)));
> };
> 
> void Func(Whatever<5>::Something MyVar){}
> 
> ```
That does not appear to work.

```
$ ./bin/clang test.cpp --target=riscv64 -march=rv64gcv -mrvv-vector-bits=zvl
test.cpp:3:41: error: 'riscv_rvv_vector_bits' attribute requires an integer 
constant
using Something = char __attribute((riscv_rvv_vector_bits(N)));
```

It's not very useful as a template parameter. There's only one value that works 
and that's whatever __RISCV_RVV_VLEN_BITS is set to.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D146030: [clang][Interp] Handle LambdaExprs

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

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146030

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


[clang] 3704752 - [clang][NFC] Use range-for loop in TextDiagnostic.cpp

2023-04-12 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-12T18:50:37+02:00
New Revision: 37047523a9fb5ffa74eaf94d9d52db831f99c062

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

LOG: [clang][NFC] Use range-for loop in TextDiagnostic.cpp

Added: 


Modified: 
clang/lib/Frontend/TextDiagnostic.cpp

Removed: 




diff  --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 809d5309d1af..95b5f257c63d 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -1168,11 +1168,10 @@ void TextDiagnostic::emitSnippetAndCaret(
   // Find the set of lines to include.
   const unsigned MaxLines = DiagOpts->SnippetLineLimit;
   std::pair Lines = {CaretLineNo, CaretLineNo};
-  for (SmallVectorImpl::iterator I = Ranges.begin(),
-  E = Ranges.end();
-   I != E; ++I)
-if (auto OptionalRange = findLinesForRange(*I, FID, SM))
+  for (auto &I : Ranges) {
+if (auto OptionalRange = findLinesForRange(I, FID, SM))
   Lines = maybeAddRange(Lines, *OptionalRange, MaxLines);
+  }
 
   for (unsigned LineNo = Lines.first; LineNo != Lines.second + 1; ++LineNo) {
 const char *BufStart = BufData.data();
@@ -1212,10 +1211,8 @@ void TextDiagnostic::emitSnippetAndCaret(
 std::string CaretLine(sourceColMap.columns(), ' ');
 
 // Highlight all of the characters covered by Ranges with ~ characters.
-for (SmallVectorImpl::iterator I = Ranges.begin(),
-E = Ranges.end();
- I != E; ++I)
-  highlightRange(*I, LineNo, FID, sourceColMap, CaretLine, SM, LangOpts);
+for (auto &I : Ranges)
+  highlightRange(I, LineNo, FID, sourceColMap, CaretLine, SM, LangOpts);
 
 // Next, insert the caret itself.
 if (CaretLineNo == LineNo) {



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


[PATCH] D148143: [clangd] Treat preamble patch as main file for include-cleaner analysis

2023-04-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:379
+  (H.physical() == MainFile ||
+   H.physical()->getName().endswith(PreamblePatch::HeaderName))) {
 Satisfied = true;

Comparing strings here every time seems odd & slow.

Is it too fragile to add a function somewhere (Preamble.h?) to get the preamble 
patch file ID from a source manager? (By reconstructing the path and then 
looking it up)

That way it can be done outside this loop, and without encoding such details 
here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148143

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


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/test/SemaCXX/attr-riscv-rvv-vector-bits.cpp:12
+
+template struct S { T var; };
+

craig.topper wrote:
> erichkeane wrote:
> > craig.topper wrote:
> > > @erichkeane does this cover the dependent case or were you looking for 
> > > something else?
> > > 
> > > Here are on the only mentions of template I see in SVE tests that use 
> > > this attribute.
> > > 
> > > ```
> > > clang/test$ ack template `ack arm_sve_vector -l`
> > > CodeGenCXX/aarch64-mangle-sve-fixed-vectors.cpp
> > > 37:template  struct S {};
> > > 
> > > SemaCXX/attr-arm-sve-vector-bits.cpp
> > > 16:template struct S { T var; };
> > > ```
> > > 
> > > Here is the result for this patch
> > > 
> > > ```
> > > clang/test$ ack template `ack riscv_rvv_vector -l`
> > > CodeGenCXX/riscv-mangle-rvv-fixed-vectors.cpp
> > > 48:template  struct S {};
> > > 
> > > SemaCXX/attr-riscv-rvv-vector-bits.cpp
> > > 12:template struct S { T var; };
> > > ```
> > Thats unfortunate, and I wish I'd thought of it at the time/been more 
> > active reviewing the SVE stuff then.  Really what I'm looking for is:
> > 
> > ```
> > template 
> > struct Whatever {
> >   using Something = char __attribute((riscv_rvv_vector_bits(N)));
> > };
> > 
> > void Func(Whatever<5>::Something MyVar){}
> > 
> > ```
> That does not appear to work.
> 
> ```
> $ ./bin/clang test.cpp --target=riscv64 -march=rv64gcv -mrvv-vector-bits=zvl
> test.cpp:3:41: error: 'riscv_rvv_vector_bits' attribute requires an integer 
> constant
> using Something = char __attribute((riscv_rvv_vector_bits(N)));
> ```
> 
> It's not very useful as a template parameter. There's only one value that 
> works and that's whatever __RISCV_RVV_VLEN_BITS is set to.
Thats really unfortunate, but it makes me wonder what `DependentVectorType ` is 
for in this case, or the handling of said things.  Because I would expect:

```
template
using RiscvVector = T __attribute__((risv_rvv_vector_bits(Size)));

RiscvVector> Foo;
```
to be useful.  Even if not, I'd expect:
```
template
using RiscvVector = T __attribute__((risv_rvv_vector_bits(TheRightAnswer)));
RiscvVector Foo;
```
to both work.

>>It's not very useful as a template parameter. There's only one value that 
>>works and that's whatever __RISCV_RVV_VLEN_BITS is set to.
This makes me wonder why this attribute takes an integer constant anyway, if it 
is just a 'guess what the right answer is!' sorta thing.  Seems to me this 
never should have taken a parameter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D144634: [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-04-12 Thread Sunil K via Phabricator via cfe-commits
koops added inline comments.



Comment at: clang/test/OpenMP/loop_bind_codegen.cpp:51-56
+void thread_loop2() {
+  #pragma omp loop bind(thread)
+  for (int j = 0 ; j < NNN ; j++) {
+aaa[j] = j*NNN;
+  }
+}

ABataev wrote:
> I think it should trigger the assert in setCurrentDirective
I did not see any crash at this point. Can you please give me other examples 
where I can see this crash?


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

https://reviews.llvm.org/D144634

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


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/SemaCXX/attr-riscv-rvv-vector-bits.cpp:12
+
+template struct S { T var; };
+

erichkeane wrote:
> craig.topper wrote:
> > erichkeane wrote:
> > > craig.topper wrote:
> > > > @erichkeane does this cover the dependent case or were you looking for 
> > > > something else?
> > > > 
> > > > Here are on the only mentions of template I see in SVE tests that use 
> > > > this attribute.
> > > > 
> > > > ```
> > > > clang/test$ ack template `ack arm_sve_vector -l`
> > > > CodeGenCXX/aarch64-mangle-sve-fixed-vectors.cpp
> > > > 37:template  struct S {};
> > > > 
> > > > SemaCXX/attr-arm-sve-vector-bits.cpp
> > > > 16:template struct S { T var; };
> > > > ```
> > > > 
> > > > Here is the result for this patch
> > > > 
> > > > ```
> > > > clang/test$ ack template `ack riscv_rvv_vector -l`
> > > > CodeGenCXX/riscv-mangle-rvv-fixed-vectors.cpp
> > > > 48:template  struct S {};
> > > > 
> > > > SemaCXX/attr-riscv-rvv-vector-bits.cpp
> > > > 12:template struct S { T var; };
> > > > ```
> > > Thats unfortunate, and I wish I'd thought of it at the time/been more 
> > > active reviewing the SVE stuff then.  Really what I'm looking for is:
> > > 
> > > ```
> > > template 
> > > struct Whatever {
> > >   using Something = char __attribute((riscv_rvv_vector_bits(N)));
> > > };
> > > 
> > > void Func(Whatever<5>::Something MyVar){}
> > > 
> > > ```
> > That does not appear to work.
> > 
> > ```
> > $ ./bin/clang test.cpp --target=riscv64 -march=rv64gcv -mrvv-vector-bits=zvl
> > test.cpp:3:41: error: 'riscv_rvv_vector_bits' attribute requires an integer 
> > constant
> > using Something = char __attribute((riscv_rvv_vector_bits(N)));
> > ```
> > 
> > It's not very useful as a template parameter. There's only one value that 
> > works and that's whatever __RISCV_RVV_VLEN_BITS is set to.
> Thats really unfortunate, but it makes me wonder what `DependentVectorType ` 
> is for in this case, or the handling of said things.  Because I would expect:
> 
> ```
> template
> using RiscvVector = T __attribute__((risv_rvv_vector_bits(Size)));
> 
> RiscvVector> Foo;
> ```
> to be useful.  Even if not, I'd expect:
> ```
> template
> using RiscvVector = T __attribute__((risv_rvv_vector_bits(TheRightAnswer)));
> RiscvVector Foo;
> ```
> to both work.
> 
> >>It's not very useful as a template parameter. There's only one value that 
> >>works and that's whatever __RISCV_RVV_VLEN_BITS is set to.
> This makes me wonder why this attribute takes an integer constant anyway, if 
> it is just a 'guess what the right answer is!' sorta thing.  Seems to me this 
> never should have taken a parameter.
> It's not very useful as a template parameter. There's only one value that 
> works and that's whatever __RISCV_RVV_VLEN_BITS is set to.

Can you help me understand why the argument exists then?

We're pretty inconsistent about attribute arguments properly handling things 
like constant expressions vs integer literals, but the trend lately is to 
accept a constant expression rather than only a literal because of how often 
users like to give names to literals and how much more constexpr code we're 
seeing in the wild.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I've not done a complete review yet, but I got started on it and have a handful 
of comments.




Comment at: clang/include/clang/Basic/TokenKinds.def:945
+// Annotation for end of input in clang-repl.
+ANNOTATION(input_end)
+

Should we name this `repl_input_end` to make it clear this is generally 
expected to only be used for REPL input?



Comment at: clang/include/clang/Interpreter/Interpreter.h:59
+
+  Value LastValue;
 

I think I'm surprised to see this as a data member of `Interpreter` but mostly 
because my brain keeps thinking this interpreter is to interpret whole 
programs, so the idea of a "last value" is a bit odd from that context. The 
name is probably fine as-is, but I figured it may be worth mentioning just the 
same.



Comment at: clang/include/clang/Interpreter/Interpreter.h:65
   create(std::unique_ptr CI);
+  ASTContext &getASTContext() const;
   const CompilerInstance *getCompilerInstance() const;

Overload set for some better const correctness.



Comment at: clang/include/clang/Interpreter/Interpreter.h:72
+  llvm::Error ParseAndExecute(llvm::StringRef Code, Value *V = nullptr);
+  llvm::Expected CompileDtorCall(CXXRecordDecl *CXXRD);
 

Hopefully this function isn't intending to mutate the passed object?



Comment at: clang/include/clang/Interpreter/Interpreter.h:98-100
+  llvm::SmallVectorImpl &getValuePrintingInfo() {
+return ValuePrintingInfo;
+  }

`const` overload here as well.



Comment at: clang/include/clang/Interpreter/Interpreter.h:102
+
+  Expr *SynthesizeExpr(clang::Expr *E);
+

Any chance we can make this const correct as well? (I'll stop asking in this 
review -- can you take a pass through it to add const correctness where it 
isn't obnoxiously viral to do so?)



Comment at: clang/include/clang/Interpreter/Value.h:17
+
+#include 
+

Unused include can be removed.



Comment at: clang/include/clang/Interpreter/Value.h:43
+
+class Interpreter;
+class QualType;

Duplicates line 27, can be removed.



Comment at: clang/include/clang/Interpreter/Value.h:44
+class Interpreter;
+class QualType;
+

Move this up to the rest of the forward declarations (and probably keep them in 
alphabetical order).



Comment at: clang/include/clang/Interpreter/Value.h:46
+
+#define REPL_BUILTIN_TYPES 
\
+  X(bool, Bool)
\

Is this expected to be a complete list of builtin types? e.g., should this have 
`char8_t` and `void` and `wchar_t`, etc? Should this be including 
`clang/include/clang/AST/BuiltinTypes.def` instead of manually maintaining the 
list?



Comment at: clang/include/clang/Interpreter/Value.h:77
+
+K_Void,
+K_PtrOrObj,

Fixing indentation



Comment at: clang/include/clang/Interpreter/Value.h:83
+  Value() = default;
+  Value(void /*Interpreter*/ *In, void /*QualType*/ *Ty);
+  Value(const Value &RHS);

Why do these take `void *` instead of the expected type?



Comment at: clang/include/clang/Interpreter/Value.h:121
+static T cast(const Value &V) {
+  if (V.isPointerOrObjectType())
+return (T)(uintptr_t)V.getAs();

Do we have to worry about member function pointers where a single pointer value 
may not be sufficient?



Comment at: clang/include/clang/Interpreter/Value.h:143
+  /// Values referencing an object are treated as pointers to the object.
+  template  T castAs() const { return CastFwd::cast(*this); }
+

This doesn't match the usual pattern used in Clang where the `get` variant 
returns `nullptr` and the `cast` variant asserts if the cast would be invalid. 
Should we go with a similar approach?



Comment at: clang/include/clang/Interpreter/Value.h:160-162
+  // Interpreter, QualType are stored as void* to reduce dependencies.
+  void *Interp = nullptr;
+  void *OpaqueType = nullptr;

Why don't forward declares suffice if we're storing the information by pointer?



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:7226
+  // assert(DeferredDeclsToEmit.empty() &&
+  //"Should have emitted all decls deferred to emit.");
   assert(NewBuilder->DeferredDecls.empty() &&

v.g.vassilev wrote:
> That should probably be a separate review with a testcase.
+1 -- the codegen code owners should weigh in on whether this is reasonable as 
a temporary measure or not.



Comment at: clang/lib/Interpreter/CMakeLists.txt:14-16
   Interpreter.cpp
+  Value.cpp
+  InterpreterUtils.cp

[PATCH] D148136: [clang] Add test for CWG1894 and CWG2199

2023-04-12 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/test/CXX/drs/dr18xx.cpp:172-227
+namespace dr1894 { // dr1894: 3.8
+   // NB: reusing dr407 test
+  struct S;
+  typedef struct S S;
+  void f() {
+struct S *p;
+{

I think i would prefer reusing verbatim the example in 1894 - lines 207 and 
following basically - as the issue clearly state that what comes before is 
resolved by 407 so not really relevant here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148136

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


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/test/SemaCXX/attr-riscv-rvv-vector-bits.cpp:12
+
+template struct S { T var; };
+

aaron.ballman wrote:
> erichkeane wrote:
> > craig.topper wrote:
> > > erichkeane wrote:
> > > > craig.topper wrote:
> > > > > @erichkeane does this cover the dependent case or were you looking 
> > > > > for something else?
> > > > > 
> > > > > Here are on the only mentions of template I see in SVE tests that use 
> > > > > this attribute.
> > > > > 
> > > > > ```
> > > > > clang/test$ ack template `ack arm_sve_vector -l`
> > > > > CodeGenCXX/aarch64-mangle-sve-fixed-vectors.cpp
> > > > > 37:template  struct S {};
> > > > > 
> > > > > SemaCXX/attr-arm-sve-vector-bits.cpp
> > > > > 16:template struct S { T var; };
> > > > > ```
> > > > > 
> > > > > Here is the result for this patch
> > > > > 
> > > > > ```
> > > > > clang/test$ ack template `ack riscv_rvv_vector -l`
> > > > > CodeGenCXX/riscv-mangle-rvv-fixed-vectors.cpp
> > > > > 48:template  struct S {};
> > > > > 
> > > > > SemaCXX/attr-riscv-rvv-vector-bits.cpp
> > > > > 12:template struct S { T var; };
> > > > > ```
> > > > Thats unfortunate, and I wish I'd thought of it at the time/been more 
> > > > active reviewing the SVE stuff then.  Really what I'm looking for is:
> > > > 
> > > > ```
> > > > template 
> > > > struct Whatever {
> > > >   using Something = char __attribute((riscv_rvv_vector_bits(N)));
> > > > };
> > > > 
> > > > void Func(Whatever<5>::Something MyVar){}
> > > > 
> > > > ```
> > > That does not appear to work.
> > > 
> > > ```
> > > $ ./bin/clang test.cpp --target=riscv64 -march=rv64gcv 
> > > -mrvv-vector-bits=zvl
> > > test.cpp:3:41: error: 'riscv_rvv_vector_bits' attribute requires an 
> > > integer constant
> > > using Something = char __attribute((riscv_rvv_vector_bits(N)));
> > > ```
> > > 
> > > It's not very useful as a template parameter. There's only one value that 
> > > works and that's whatever __RISCV_RVV_VLEN_BITS is set to.
> > Thats really unfortunate, but it makes me wonder what `DependentVectorType 
> > ` is for in this case, or the handling of said things.  Because I would 
> > expect:
> > 
> > ```
> > template
> > using RiscvVector = T __attribute__((risv_rvv_vector_bits(Size)));
> > 
> > RiscvVector> Foo;
> > ```
> > to be useful.  Even if not, I'd expect:
> > ```
> > template
> > using RiscvVector = T __attribute__((risv_rvv_vector_bits(TheRightAnswer)));
> > RiscvVector Foo;
> > ```
> > to both work.
> > 
> > >>It's not very useful as a template parameter. There's only one value that 
> > >>works and that's whatever __RISCV_RVV_VLEN_BITS is set to.
> > This makes me wonder why this attribute takes an integer constant anyway, 
> > if it is just a 'guess what the right answer is!' sorta thing.  Seems to me 
> > this never should have taken a parameter.
> > It's not very useful as a template parameter. There's only one value that 
> > works and that's whatever __RISCV_RVV_VLEN_BITS is set to.
> 
> Can you help me understand why the argument exists then?
> 
> We're pretty inconsistent about attribute arguments properly handling things 
> like constant expressions vs integer literals, but the trend lately is to 
> accept a constant expression rather than only a literal because of how often 
> users like to give names to literals and how much more constexpr code we're 
> seeing in the wild.
This is what's in ARM's ACLE documentation:



> The ACLE only defines the effect of the attribute if all of the following are 
> true:
> 1. the attribute is attached to a single SVE vector type (such as svint32_t) 
> or to the SVE predicate
> type svbool_t;
> 2. the arguments “…” consist of a single nonzero integer constant expression 
> (referred to as N below); and
> 3. N==__ARM_FEATURE_SVE_BITS.
> In other cases the implementation must do one of the following:
> • ignore the attribute; a warning would then be appropriate, but is not 
> required
> • reject the program with a diagnostic
> • extend requirement (3) above to support other values of N besides 
> __ARM_FEATURE_SVE_BITS
> • process the attribute in accordance with a later revision of the ACLE





So there's a bullet in there that allows an implementation to support other 
values, but it is not required.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D148146: [clang] Make make_cxx_dr_status script runnable from anywhere

2023-04-12 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill created this revision.
Endill added reviewers: clang-language-wg, cor3ntin.
Herald added a project: All.
Endill requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This script has hardcoded relative paths to `clang/test/CXX/drs`, 
`cwg_index.html`, and `cxx_dr_status.html`, which requires running it with 
`clang/www` CWD. This patch makes those paths relative to path of the script 
itself, so that it could be run from anywhere.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148146

Files:
  clang/www/make_cxx_dr_status


Index: clang/www/make_cxx_dr_status
===
--- clang/www/make_cxx_dr_status
+++ clang/www/make_cxx_dr_status
@@ -2,10 +2,11 @@
 import sys, os, re, urllib.request
 
 
-default_issue_list_path = 'cwg_index.html'
+clang_www_dir = os.path.dirname(__file__)
+default_issue_list_path = os.path.join(clang_www_dir, 'cwg_index.html')
 issue_list_url = "https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_index.html";
-output = 'cxx_dr_status.html'
-dr_test_dir = '../test/CXX/drs'
+output = os.path.join(clang_www_dir, 'cxx_dr_status.html')
+dr_test_dir = os.path.join(clang_www_dir, '../test/CXX/drs')
 
 class DR:
   def __init__(self, section, issue, url, status, title):


Index: clang/www/make_cxx_dr_status
===
--- clang/www/make_cxx_dr_status
+++ clang/www/make_cxx_dr_status
@@ -2,10 +2,11 @@
 import sys, os, re, urllib.request
 
 
-default_issue_list_path = 'cwg_index.html'
+clang_www_dir = os.path.dirname(__file__)
+default_issue_list_path = os.path.join(clang_www_dir, 'cwg_index.html')
 issue_list_url = "https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_index.html";
-output = 'cxx_dr_status.html'
-dr_test_dir = '../test/CXX/drs'
+output = os.path.join(clang_www_dir, 'cxx_dr_status.html')
+dr_test_dir = os.path.join(clang_www_dir, '../test/CXX/drs')
 
 class DR:
   def __init__(self, section, issue, url, status, title):
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148146: [clang] Make make_cxx_dr_status script runnable from anywhere

2023-04-12 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

Great idea, looks good!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148146

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


[PATCH] D143364: [RISCV] Support scalar/fix-length vector NTLH intrinsic with different domain

2023-04-12 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c:19
+typedef signed short v8ss __attribute__((vector_size(16)));
+typedef signed char v16sc __attribute__((vector_size(16)));
+v4si v4si1, v4si2;

What about the rvv builtin types for scalable vectors?



Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:15347
+  if (NontemporalLevel == 1)
+NontemporalLevel = 5;
+

Should we default Nontemporal level to 5 before looking at 
riscv-nontemporal-domain? Then only 2-5 are legal values?



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfo.cpp:2635
+  static const std::pair TargetFlags[] 
=
+  {{MONontemporalBit0, "riscv-non-temporal-domain-bit-0"},
+   {MONontemporalBit1, "riscv-non-temporal-domain-bit-1"}};

This uses "non-temporal" and the metadata uses "nontemporal". I think we should 
be consistent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143364

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


[PATCH] D148136: [clang] Add test for CWG1894 and CWG2199

2023-04-12 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

Thank you for taking a look at this.




Comment at: clang/test/CXX/drs/dr18xx.cpp:172-227
+namespace dr1894 { // dr1894: 3.8
+   // NB: reusing dr407 test
+  struct S;
+  typedef struct S S;
+  void f() {
+struct S *p;
+{

cor3ntin wrote:
> I think i would prefer reusing verbatim the example in 1894 - lines 207 and 
> following basically - as the issue clearly state that what comes before is 
> resolved by 407 so not really relevant here
Does the same apply to 2199? It also contains examples resolved by 407.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148136

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


[PATCH] D148136: [clang] Add test for CWG1894 and CWG2199

2023-04-12 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/test/CXX/drs/dr18xx.cpp:172-227
+namespace dr1894 { // dr1894: 3.8
+   // NB: reusing dr407 test
+  struct S;
+  typedef struct S S;
+  void f() {
+struct S *p;
+{

Endill wrote:
> cor3ntin wrote:
> > I think i would prefer reusing verbatim the example in 1894 - lines 207 and 
> > following basically - as the issue clearly state that what comes before is 
> > resolved by 407 so not really relevant here
> Does the same apply to 2199? It also contains examples resolved by 407.
Yes, i think so. That way it better shows what is actually resolved / tested - 
amd avoid to much duplication


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148136

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


  1   2   >