[PATCH] D149160: [clang][analyzer] Handle special value AT_FDCWD in affected standard functions

2023-04-27 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1988
+  return std::make_shared(
+  ArgN, WithinRange, Range({AT_FDCWDv, AT_FDCWDv}, {0, IntMax}), "");
+};

Should we define a specific constraint description?
If not, then we should not specify it explicitly - given that it's already 
defined as an empty string by default.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1530-1541
+  // Get platform dependent values of some macros.
+  // Try our best to parse this from the Preprocessor, otherwise fallback to a
+  // default value (what is found in a library header).
+  auto GetMacroValue = [&C](const char *Name, int Default) -> RangeInt {
 if (const std::optional OptInt =
-tryExpandAsInteger("EOF", C.getPreprocessor()))
+tryExpandAsInteger(Name, C.getPreprocessor()))
   return *OptInt;

steakhal wrote:
> 
What is your response @balazske?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149160

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


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

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

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

https://reviews.llvm.org/D147875

Files:
  
clang-tools-extra/test/clang-tidy/checkers/cert/uppercase-literal-suffix-integer.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-float16.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-floating-point-opencl-half.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-floating-point.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-hexadecimal-floating-point.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-integer-custom-list.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-integer-ms.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-integer.cpp
  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/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
  clang/test/FixIt/fixit-function-call.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/Frontend/source-col-map.c
  clang/test/Lexer/header.cpp
  clang/test/Lexer/string-literal-errors.cpp
  clang/test/Misc/caret-diags-macros.c
  clang/test/Misc/caret-diags-multiline.cpp
  clang/test/Misc/diag-macro-backtrace.c
  clang/test/Misc/message-length.c
  clang/test/Misc/tabstop.c
  clang/test/Misc/unnecessary-elipses.cpp
  clang/test/Misc/unprintable.c
  clang/test/Misc/wrong-encoding.c
  clang/test/Parser/brackets.c
  clang/test/Parser/brackets.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/caret-diags-complex-init.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/Sema/caret-diags-complex-init.cpp
===
--- clang/test/Sema/caret-diags-complex-init.cpp
+++ clang/test/Sema/caret-diags-complex-init.cpp
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fcaret-diagnostics-max-lines 5 %s 2>&1 | FileCheck %s -strict-whitespace
+// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines 5 %s 2>&1 | FileCheck %s -strict-whitespace
 
 
 //CHECK: {{.*}}: error: excess elements in scalar initializer
Index: clang/test/Preprocessor/ucn-pp-identifier.c
===
--- clang/test/Preprocessor/ucn-pp-identifier.c
+++ clang/test/Preprocessor/ucn-pp-identifier.c
@@ -112,9 +112,9 @@
 #define capital_u_\U00FC
 // expected-warning@-1 {{incomplete universal character name}} expected-note@-1 {{did you mean to use '\u'?}} expected-warning@-1 {{whitespace}}
 // CHECK: note: did you mean to use '\u'?
-// CHECK-NEXT:   #define capital_u_\U00FC
-// CHECK-NEXT: {{^   \^}}
-// CHECK-NEXT: {{^   u}}
+// CHECK-NEXT: {{^  112 | #define capital_u_\U00FC}}
+// CHECK-NEXT: {{^  |\^}}
+// CHECK-NEXT: {{^  |u}}
 
 #define \u{}   // expected-warning {{empty delimited universal character name; treating as '\' 'u' '{' '}'}} expected-error {{macro name must be an identifier}}
 #define \u1{123}   // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{macro name must be an identifier}}
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 

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

2023-04-27 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cert/uppercase-literal-suffix-integer.cpp:34
   // CHECK-MESSAGES-NEXT: ^~
-  // CHECK-MESSAGES-NEXT: {{^ *}}L{{$}}
+  // CHECK-MESSAGES-NEXT: {{^ *| *}}L{{$}}
   // CHECK-FIXES: static constexpr auto v5 = 1L;

In theory you should escape this character (`|`) by using `\`, otherwise it 
could be interpreted as an regexp or. Still looks like this test file passes, 
so 7 to go.


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


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

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



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cert/uppercase-literal-suffix-integer.cpp:34
   // CHECK-MESSAGES-NEXT: ^~
-  // CHECK-MESSAGES-NEXT: {{^ *}}L{{$}}
+  // CHECK-MESSAGES-NEXT: {{^ *| *}}L{{$}}
   // CHECK-FIXES: static constexpr auto v5 = 1L;

PiotrZSL wrote:
> In theory you should escape this character (`|`) by using `\`, otherwise it 
> could be interpreted as an regexp or. Still looks like this test file passes, 
> so 7 to go.
Yeah I noticed the missing backslash but the test passed. 

For the other tests, I've just removed the `{{^ *}}` before the uppercase 
suffix. It seems pointless to check that the line contains nothing else(?). I 
can revert that of course, but it seemed like the easier fix.


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


[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-04-27 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/PrintfToStdPrintCheck.cpp:28
+  ReplacementPrintFunction(Options.get("PrintFunction", "std::print")) {
+  PrintfLikeFunctions.push_back("printf");
+  PrintfLikeFunctions.push_back("absl::PrintF");

NOTE: Consider using fully qualified names, like `::printf`



Comment at: clang-tools-extra/clang-tidy/modernize/PrintfToStdPrintCheck.cpp:45
+  Finder->addMatcher(
+  traverse(TK_AsIs,
+   callExpr(callee(functionDecl(matchers::matchesAnyListedName(

TK_IgnoreUnlessSpelledInSource should be fine for this.



Comment at: clang-tools-extra/clang-tidy/modernize/PrintfToStdPrintCheck.cpp:68
+DiagnosticBuilder Diag =
+diag(PrintfCall->getBeginLoc(), "Replace %0 with '%1'")
+<< OldFunction->getIdentifier() << ReplacementPrintFunction;

start warning with lower case, and maybe something like "use %0 instead of %1" 
(or whatever)



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.h:32-47
+  const ASTContext *Context;
+  bool ConversionPossible = true;
+  bool FormatStringNeededRewriting = false;
+  size_t PrintfFormatStringPos = 0U;
+  StringRef PrintfFormatString;
+
+  const Expr *const *Args;

NOTE: Consider re-ordering private-public, like in other files, to first put 
public stuff, then private.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D136515: [builtins] Add __builtin_assume_separate_storage.

2023-04-27 Thread Ofek Shilon via Phabricator via cfe-commits
OfekShilon added subscribers: kosarev, OfekShilon.
OfekShilon added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:2393
+particular object (so for example, it's never correct to call this function
+passing the addresses of fields in the same struct, elements of the same array,
+etc.).

bruno wrote:
> davidtgoldblatt wrote:
> > bruno wrote:
> > > Not necessarily a blocker, but it seems like some of these things you 
> > > mention can actually be caught by diagnostics without too much effort? 
> > > Any plans to add them?
> > I hadn't planned to (at least in the short term). Practically I expect uses 
> > of this to be mostly backed out from looking at bad assembly (this is the 
> > way I've been using it so far in experimentation). You wouldn't generally 
> > expect people to want to try to express "these two struct fields don't 
> > alias" and so on because alias analysis can already handle those cases 
> > fairly well.
> > 
> > My inclination would be to wait on the diagnostics until we see if it's a 
> > real problem, but I'm not strongly opposed if you'd really like them in v1. 
> > (Although in that case I'll probably bug you for some help with where / how 
> > to put the diagnostics).
> > My inclination would be to wait on the diagnostics until we see if it's a 
> > real problem
> 
> Sounds fair! Feel free to bug me when/if you decide to explore that route.
+2c: as of today tbaa *doesn't* handle well aliasing of two struct fields. 
There was some work to mitigate it by @kosarev 
(https://reviews.llvm.org/D41539) but it is still hidden behind a 
`-new-struct-path-tbaa` switch.   Example: https://godbolt.org/z/xPMzfea8W


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136515

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


[PATCH] D149160: [clang][analyzer] Handle special value AT_FDCWD in affected standard functions

2023-04-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 517470.
balazske marked an inline comment as done.
balazske added a comment.

using short way for getting macro value
added constraint description


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149160

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

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
@@ -3,6 +3,7 @@
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
 // RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -triple x86_64-unknown-linux-gnu \
@@ -13,6 +14,7 @@
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
 // RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -triple x86_64-unknown-linux-gnu \
@@ -309,3 +311,26 @@
   // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint_concrete' is out of the accepted range; It should be a buffer with size equal to or greater than 10}} \
   // bugpath-note{{The 1st argument to '__buf_size_arg_constraint_concrete' is out of the accepted range; It should be a buffer with size equal to or greater than 10}}
 }
+
+void test_file_fd_at_functions() {
+  (void)linkat(-22, "from", AT_FDCWD, "to", 0); // \
+  // report-warning{{The 1st argument to 'linkat' is -22 but should be a valid file descriptor or AT_FDCWD}} \
+  // bugpath-warning{{The 1st argument to 'linkat' is -22 but should be a valid file descriptor or AT_FDCWD}} \
+  // bugpath-note{{The 1st argument to 'linkat' is -22 but should be a valid file descriptor or AT_FDCWD}}
+
+  // no warning for these functions if the AT_FDCWD value is used
+  (void)linkat(AT_FDCWD, "from", AT_FDCWD, "to", 0);
+  (void)faccessat(AT_FDCWD, "path", 0, 0);
+  (void)symlinkat("oldpath", AT_FDCWD, "newpath");
+  (void)mkdirat(AT_FDCWD, "path", 0);
+  (void)mknodat(AT_FDCWD, "path", 0, 0);
+  (void)fchmodat(AT_FDCWD, "path", 0, 0);
+  (void)fchownat(AT_FDCWD, "path", 0, 0, 0);
+  (void)linkat(AT_FDCWD, "oldpath", AT_FDCWD, "newpath", 0);
+  (void)unlinkat(AT_FDCWD, "newpath", 0);
+  struct stat St;
+  (void)fstatat(AT_FDCWD, "newpath", &St, 0);
+  char Buf[10];
+  (void)readlinkat(AT_FDCWD, "newpath", Buf, 10);
+  (void)renameat(AT_FDCWD, "oldpath", AT_FDCWD, "newpath");
+}
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -1392,6 +1392,7 @@
   SValBuilder &SVB = C.getSValBuilder();
   BasicValueFactory &BVF = SVB.getBasicValueFactory();
   const ASTContext &ACtx = BVF.getContext();
+  Preprocessor &PP = C.getPreprocessor();
 
   // Helper class to lookup a type by its name.
   class LookupType {
@@ -1527,14 +1528,11 @@
   const RangeInt UCharRangeMax =
   std::min(BVF.getMaxValue(ACtx.UnsignedCharTy).getLimitedValue(), IntMax);
 
-  // The platform dependent value of EOF.
-  // Try our best to parse this from the Preprocessor, otherwise fallback to -1.
-  const auto EOFv = [&C]() -> RangeInt {
-if (const std::optional OptInt =
-tryExpandAsInteger("EOF", C.getPreprocessor()))
-  return *OptInt;
-return -1;
-  }();
+  // Get platform dependent values of some macros.
+  // Try our best to parse this from the Preprocessor, otherwise fallback to a
+  // default value (what is found in a library header).
+  const auto EOFv = tryExpandAsInteger("EOF", PP).value_or(-1);
+  const auto AT_FDCWDv = tryExpandAsInteger("AT_FDCWD", PP).value_or(-100);
 
   // Auxiliary class to aid adding summaries to the summary map.
   struct AddToFunctionSummaryMap {
@@ -1979,6 +1977,12 @@
 ConstraintSet{ReturnValueCondition(WithinRange, Range(-1, IntMax))};
 const auto &ReturnsValidFileDescriptor = ReturnsNonnegative;
 
+auto ValidFileDescriptorOrAtFdcwd = [&](ArgNo ArgN) {
+  return std::make_shared(
+  ArgN, WithinRange, Range({AT_FDCWDv, AT_FDCWDv}, {0, IntMax}),
+  "a valid file descriptor or AT_FDCWD");
+};
+
 // FILE *fopen(const char *restrict pathname, const char *restrict mode);
 add

[PATCH] D149160: [clang][analyzer] Handle special value AT_FDCWD in affected standard functions

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



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1988
+  return std::make_shared(
+  ArgN, WithinRange, Range({AT_FDCWDv, AT_FDCWDv}, {0, IntMax}), "");
+};

steakhal wrote:
> Should we define a specific constraint description?
> If not, then we should not specify it explicitly - given that it's already 
> defined as an empty string by default.
Now a description is added. This looks better, but the user should know what is 
a "valid file descriptor" (is 0 allowed or not), it is not shown now.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1530-1541
+  // Get platform dependent values of some macros.
+  // Try our best to parse this from the Preprocessor, otherwise fallback to a
+  // default value (what is found in a library header).
+  auto GetMacroValue = [&C](const char *Name, int Default) -> RangeInt {
 if (const std::optional OptInt =
-tryExpandAsInteger("EOF", C.getPreprocessor()))
+tryExpandAsInteger(Name, C.getPreprocessor()))
   return *OptInt;

steakhal wrote:
> steakhal wrote:
> > 
> What is your response @balazske?
This is much better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149160

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


[PATCH] D149321: [clang][analyzer] Display buffer sizes in StdCLibraryFunctionArgs checker

2023-04-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, gamesh411, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a reviewer: NoQ.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If a wrong (too small) buffer argument is found, the dynamic buffer size and
values of connected arguments are displayed in the warning message, if
these are simple known integer values.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149321

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.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

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
@@ -210,9 +210,9 @@
   // The 3rd parameter should be the number of elements to read, not
   // the size in bytes.
   fread(wbuf, size, nitems, file); // \
-  // report-warning{{The 1st argument to 'fread' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-warning{{The 1st argument to 'fread' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-note{{The 1st argument to 'fread' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}}
+  // report-warning{{The 1st argument to 'fread' is a buffer with size 4096 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 4096)}} \
+  // bugpath-warning{{The 1st argument to 'fread' is a buffer with size 4096 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 4096)}} \
+  // bugpath-note{{The 1st argument to 'fread' is a buffer with size 4096 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 4096)}}
 }
 
 int __two_constrained_args(int, int);
@@ -254,9 +254,9 @@
 void test_buf_size_concrete(void) {
   char buf[3];   // bugpath-note{{'buf' initialized here}}
   __buf_size_arg_constraint(buf, 4); // \
-  // report-warning{{The 1st argument to '__buf_size_arg_constraint' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument}} \
-  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument}} \
-  // bugpath-note{{The 1st argument to '__buf_size_arg_constraint' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument}}
+  // report-warning{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4)}} \
+  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4)}} \
+  // bugpath-note{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4)}}
 }
 void test_buf_size_symbolic(int s) {
   char buf[3];
@@ -281,9 +281,9 @@
 void test_buf_size_concrete_with_multiplication(void) {
   short buf[3]; // bugpath-note{{'buf' initialized here}}
   __buf_size_arg_constraint_mul(buf, 4, sizeof(short)); // \
-  // report-warning{{The 1st argument to '__buf_size_arg_constraint_mul' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint_mul' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-note{{The 1st argument to '__buf_size_arg_constraint_mul' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}}
+  // report-warning{{The 1st argumen

[PATCH] D149321: [clang][analyzer] Display buffer sizes in StdCLibraryFunctionArgs checker

2023-04-27 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added reviewers: steakhal, gamesh411.
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

I am Szelethus, and I approve this warning message!

Now, on another issue, if we can output such a thorough message, we should 
start to consider that in the few cases where we cannot, maybe we should just 
choose to suppress the warning. But that is a job for another patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149321

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


[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 517478.
pmatos marked 6 inline comments as done.
pmatos added a comment.

Complete fixing tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139010

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Type.cpp
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/builtins-table.c
  clang/test/Sema/builtins-wasm.c
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/Sema/wasm-refs.c
  clang/test/SemaCXX/wasm-refs-and-tables.cpp
  clang/test/SemaCXX/wasm-refs.cpp
  llvm/include/llvm/CodeGen/WasmAddressSpaces.h
  llvm/include/llvm/IR/Type.h
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
@@ -62,8 +62,9 @@
   for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
 PtrToIntInst *PTI = dyn_cast(&*I);
 IntToPtrInst *ITP = dyn_cast(&*I);
-if (!(PTI && WebAssembly::isRefType(PTI->getPointerOperand()->getType())) &&
-!(ITP && WebAssembly::isRefType(ITP->getDestTy(
+if (!(PTI &&
+  PTI->getPointerOperand()->getType()->isWebAssemblyReferenceType()) &&
+!(ITP && ITP->getDestTy()->isWebAssemblyReferenceType()))
   continue;
 
 UndefValue *U = UndefValue::get(I->getType());
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -1203,7 +1203,7 @@
   // Lastly, if this is a call to a funcref we need to add an instruction
   // table.set to the chain and transform the call.
   if (CLI.CB &&
-  WebAssembly::isFuncrefType(CLI.CB->getCalledOperand()->getType())) {
+  CLI.CB->getCalledOperand()->getType()->isWebAssemblyFuncrefType()) {
 // In the absence of function references proposal where a funcref call is
 // lowered to call_ref, using reference types we generate a table.set to set
 // the funcref to a special table used solely for this purpose, followed by
Index: llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
===
--- llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -27,43 +27,6 @@
 
 namespace WebAssembly {
 
-enum WasmAddressSpace : unsigned {
-  // Default address space, for pointers to linear memory (stack, heap, data).
-  WASM_ADDRESS_SPACE_DEFAULT = 0,
-  // A non-integral address space for pointers to named objects outside of
-  // linear memory: WebAssembly globals or WebAssembly locals.  Loads and stores
-  // to these pointers are lowered to global.get / global.set or local.get /
-  // local.set, as appropriate.
-  WASM_ADDRESS_SPACE_VAR = 1,
-  // A non-integral address space for externref values
-  WASM_ADDRESS_SPACE_EXTERNREF = 10,
-  // A non-integral address space for funcref values
-  WASM_ADDRESS_SPACE_FUNCREF = 20,
-};
-
-inline bool isDefaultAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_DEFAULT;
-}
-inline bool isWasmVarAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_VAR;
-}
-inline bool isValidAddressSpace(unsigned AS) {
-  return isDefaultAddressSpace(AS) || isWasmVarAddressSpace(AS);
-}
-inline bool isFuncrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
-}
-inline bool isExternrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
-}
-inline bool isRefType(const Type *Ty) {
-  return isFuncrefType(Ty) || isExternrefType(Ty);
-}
-
 // Convert StringRef to ValType / HealType / BlockType
 
 MVT parseMVT(StringRef Type);
Index: llvm/lib/Target/WebAssembly/Utils/We

[PATCH] D149321: [clang][analyzer] Display buffer sizes in StdCLibraryFunctionArgs checker

2023-04-27 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:889
+  State, getArgSVal(Call, ArgN)))
+Out << " (that is " << *Val << ")";
+}

I think this would be correct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149321

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


[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-27 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 517488.
cor3ntin marked 8 inline comments as done.
cor3ntin added a comment.

- Fix tests
- Address aaron's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/cxx1z-decomposition.cpp
  clang/test/Parser/cxx2b-auto-x.cpp

Index: clang/test/Parser/cxx2b-auto-x.cpp
===
--- clang/test/Parser/cxx2b-auto-x.cpp
+++ clang/test/Parser/cxx2b-auto-x.cpp
@@ -18,7 +18,31 @@
 
 using T = looks_like_declaration *;
 void f() { T(&a)->n = 1; }
-// FIXME: They should be deemed expressions without breaking function pointer
-//parameter declarations with trailing return types.
-// void g() { auto(&a)->n = 0; }
-// void h() { auto{&a}->n = 0; }
+void g() { auto(&a)->n = 0; } // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{'auto' not allowed here}}
+void h() { auto{&a}->n = 0; } // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{'auto' not allowed here}}
+
+void e(auto (*p)(int y) -> decltype(y)) {}
+
+struct M;
+struct S{
+S operator()();
+S* operator->();
+int N;
+int M;
+} s; // expected-note {{here}}
+
+void test() {
+auto(s)()->N; // cxx2b-warning {{expression result unused}} \
+  // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{'auto' not allowed here}}
+auto(s)()->M; // expected-error {{redefinition of 's' as different kind of symbol}}
+}
+
+void test_paren() {
+int a = (auto(0)); // cxx2b-warning {{before C++2b}} \
+   // cxx20-error {{'auto' not allowed here}}
+int b = (auto{0}); // cxx2b-warning {{before C++2b}} \
+   // cxx20-error {{'auto' not allowed here}}
+}
Index: clang/test/Parser/cxx1z-decomposition.cpp
===
--- clang/test/Parser/cxx1z-decomposition.cpp
+++ clang/test/Parser/cxx1z-decomposition.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -std=c++17 %s -verify -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++17 %s -verify=expected,cxx17 -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++2b %s -verify=expected,cxx2b -fcxx-exceptions
 // RUN: not %clang_cc1 -std=c++17 %s -emit-llvm-only -fcxx-exceptions
 
 struct S { int a, b, c; };
@@ -30,7 +31,7 @@
 namespace OtherDecl {
   // A parameter-declaration is not a simple-declaration.
   // This parses as an array declaration.
-  void f(auto [a, b, c]); // expected-error {{'auto' not allowed in function prototype}} expected-error {{'a'}}
+  void f(auto [a, b, c]); // cxx17-error {{'auto' not allowed in function prototype}} expected-error {{'a'}}
 
   void g() {
 // A condition is allowed as a Clang extension.
@@ -57,7 +58,7 @@
 namespace GoodSpecifiers {
   void f() {
 int n[1];
-const volatile auto &[a] = n;
+const volatile auto &[a] = n; // cxx2b-warning {{volatile qualifier in structured binding declaration is deprecated}}
   }
 }
 
@@ -67,8 +68,8 @@
   struct S { int n; } s;
   void f() {
 // storage-class-specifiers
-static auto &[a] = n; // expected-warning {{declared 'static' is a C++20 extension}}
-thread_local auto &[b] = n; // expected-warning {{declared 'thread_local' is a C++20 extension}}
+static auto &[a] = n; // cxx17-warning {{declared 'static' is a C++20 extension}}
+thread_local auto &[b] = n; // cxx17-warning {{declared 'thread_local' is a C++20 extension}}
 extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
 struct S {
   mutable auto &[d] = n; // expected-error {{not permitted in this context}}
@@ -85,16 +86,19 @@
   }
 
   static constexpr inline thread_local auto &[j1] = n; // expected-error {{cannot be declared with 'constexpr inline' specifiers}}
-  static thread_local auto &[j2] = n; // expected-warning {{declared with 'static thread_local' specifiers is a C++20 extension}}
+  static thread_local auto &[j2] = n; // cxx17-warning {{declared with 'static thread_local' specifiers is a C++20 extension}}
 
   inline auto &[k] = n; // expected-error {{cannot be declared 'inline'}}
 
   const int K = 5;
+  auto ([c]) = s; // expected-error {{decomposition declaration cannot be declared with parentheses}}
   void g() {
 // defining-type-specifiers other than cv-qualifiers and 'auto'
 S [a] = s; // expected-error {{cannot be declared with type 'S'}}
 decltype(auto) [b] = s; // expected-error {{cannot be declared with type 'decltype(auto)'}}
-auto ([c]) = s; // expected-error {{cannot be declared with parentheses}}
+auto ([c2]) = s; // cxx17-error {

cfe-commits@lists.llvm.org

2023-04-27 Thread Jens Massberg via Phabricator via cfe-commits
massberg updated this revision to Diff 517489.
massberg added a comment.

Updated  errort messages, code and tests. 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148924

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
  clang/test/CodeGenCXX/virtual-compare.cpp

Index: clang/test/CodeGenCXX/virtual-compare.cpp
===
--- clang/test/CodeGenCXX/virtual-compare.cpp
+++ clang/test/CodeGenCXX/virtual-compare.cpp
@@ -21,8 +21,6 @@
   virtual std::strong_ordering operator<=>(const A &) const & = default;
   // CHECK-SAME: @_ZN1A1gEv
   virtual void g();
-  // CHECK-SAME: @_ZNKO1AssERKS_
-  virtual std::strong_ordering operator<=>(const A &) const && = default;
   // CHECK-SAME: @_ZN1A1hEv
   virtual void h();
 
@@ -35,9 +33,6 @@
 
   // CHECK-SAME: @_ZNKR1AeqERKS_
   // implicit virtual A &operator==(const A&) const & = default;
-
-  // CHECK-SAME: @_ZNKO1AeqERKS_
-  // implicit virtual A &operator==(const A&) const && = default;
 };
 
 // For Y:
Index: clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -15,7 +15,8 @@
 
   bool operator<(const A&) const;
   bool operator<=(const A&) const = default;
-  bool operator==(const A&) const volatile && = default; // surprisingly, OK
+  bool operator==(const A&) const && = default; // expected-error {{ref-qualifier '&&' is not allowed on a defaulted comparison operators}}
+  bool operator>=(const A&) const volatile = default; // expected-error {{defaulted comparison function must not be volatile}}
   bool operator<=>(const A&) = default; // expected-error {{defaulted member three-way comparison operator must be const-qualified}}
   bool operator>=(const B&) const = default; // expected-error-re {{invalid parameter type for defaulted relational comparison operator; found 'const B &', expected 'const A &'{{$
   static bool operator>(const B&) = default; // expected-error {{overloaded 'operator>' cannot be a static member function}}
@@ -185,6 +186,11 @@
 friend bool operator==(const S6&, const S6&) = default; // expected-error {{because it was already declared outside}}
 };
 
+struct S7 {
+  bool operator==(S7 const &) const &&;
+};
+bool S7::operator==(S7 const &) const && = default; // expected-error {{ref-qualifier '&&' is not allowed on a defaulted comparison operators}}
+
 enum e {};
 bool operator==(e, int) = default; // expected-error{{expected class or reference to a constant class}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -8579,8 +8579,8 @@
   // C++2a [class.compare.default]p1:
   //   A defaulted comparison operator function for some class C shall be a
   //   non-template function declared in the member-specification of C that is
-  //-- a non-static const member of C having one parameter of type
-  //   const C&, or
+  //-- a non-static const non-volatile member of C having one parameter of type
+  //   const C& and either no ref-qualifier or the ref-qualifier &, or
   //-- a friend of C having two parameters of type const C& or two
   //   parameters of type C.
 
@@ -8590,6 +8590,17 @@
 auto *MD = cast(FD);
 assert(!MD->isStatic() && "comparison function cannot be a static member");
 
+if (MD->getRefQualifier() == RQ_RValue) {
+  Diag(MD->getLocation(), diag::err_ref_qualifier_comparison_operator);
+
+  // Remove the ref qualifier to recover.
+  const auto *FPT = MD->getType()->castAs();
+  FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+  EPI.RefQualifier = RQ_None;
+  MD->setType(Context.getFunctionType(FPT->getReturnType(),
+  FPT->getParamTypes(), EPI));
+}
+
 // If we're out-of-class, this is the class we're comparing.
 if (!RD)
   RD = MD->getParent();
@@ -8612,6 +8623,17 @@
   MD->setType(Context.getFunctionType(FPT->getReturnType(),
   FPT->getParamTypes(), EPI));
 }
+
+if (MD->isVolatile()) {
+  Diag(MD->getLocation(), diag::err_volatile_comparison_operator);
+
+  // Remove the 'volatile' from the type to recover.
+  const auto *FPT = MD->getType()->castAs();
+  FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+  EPI.TypeQuals.removeVolatile();
+  MD->setType(Context.getFunctionType(FPT->getReturnType(),
+  FPT->getParamTypes(), EPI));
+}
   }
 
   if (FD->getNumParams() 

[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-27 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 517491.
cor3ntin added a comment.

Do not parse auto( as an expression before C++23


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/cxx1z-decomposition.cpp
  clang/test/Parser/cxx2b-auto-x.cpp

Index: clang/test/Parser/cxx2b-auto-x.cpp
===
--- clang/test/Parser/cxx2b-auto-x.cpp
+++ clang/test/Parser/cxx2b-auto-x.cpp
@@ -18,7 +18,31 @@
 
 using T = looks_like_declaration *;
 void f() { T(&a)->n = 1; }
-// FIXME: They should be deemed expressions without breaking function pointer
-//parameter declarations with trailing return types.
-// void g() { auto(&a)->n = 0; }
-// void h() { auto{&a}->n = 0; }
+void g() { auto(&a)->n = 0; } // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{'auto' not allowed here}}
+void h() { auto{&a}->n = 0; } // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{'auto' not allowed here}}
+
+void e(auto (*p)(int y) -> decltype(y)) {}
+
+struct M;
+struct S{
+S operator()();
+S* operator->();
+int N;
+int M;
+} s; // expected-note {{here}}
+
+void test() {
+auto(s)()->N; // cxx2b-warning {{expression result unused}} \
+  // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{'auto' not allowed here}}
+auto(s)()->M; // expected-error {{redefinition of 's' as different kind of symbol}}
+}
+
+void test_paren() {
+int a = (auto(0)); // cxx2b-warning {{before C++2b}} \
+   // cxx20-error {{'auto' not allowed here}}
+int b = (auto{0}); // cxx2b-warning {{before C++2b}} \
+   // cxx20-error {{'auto' not allowed here}}
+}
Index: clang/test/Parser/cxx1z-decomposition.cpp
===
--- clang/test/Parser/cxx1z-decomposition.cpp
+++ clang/test/Parser/cxx1z-decomposition.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -std=c++17 %s -verify -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++17 %s -verify=expected,cxx17 -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++2b %s -verify=expected,cxx2b -fcxx-exceptions
 // RUN: not %clang_cc1 -std=c++17 %s -emit-llvm-only -fcxx-exceptions
 
 struct S { int a, b, c; };
@@ -30,7 +31,7 @@
 namespace OtherDecl {
   // A parameter-declaration is not a simple-declaration.
   // This parses as an array declaration.
-  void f(auto [a, b, c]); // expected-error {{'auto' not allowed in function prototype}} expected-error {{'a'}}
+  void f(auto [a, b, c]); // cxx17-error {{'auto' not allowed in function prototype}} expected-error {{'a'}}
 
   void g() {
 // A condition is allowed as a Clang extension.
@@ -57,7 +58,7 @@
 namespace GoodSpecifiers {
   void f() {
 int n[1];
-const volatile auto &[a] = n;
+const volatile auto &[a] = n; // cxx2b-warning {{volatile qualifier in structured binding declaration is deprecated}}
   }
 }
 
@@ -67,8 +68,8 @@
   struct S { int n; } s;
   void f() {
 // storage-class-specifiers
-static auto &[a] = n; // expected-warning {{declared 'static' is a C++20 extension}}
-thread_local auto &[b] = n; // expected-warning {{declared 'thread_local' is a C++20 extension}}
+static auto &[a] = n; // cxx17-warning {{declared 'static' is a C++20 extension}}
+thread_local auto &[b] = n; // cxx17-warning {{declared 'thread_local' is a C++20 extension}}
 extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
 struct S {
   mutable auto &[d] = n; // expected-error {{not permitted in this context}}
@@ -85,16 +86,19 @@
   }
 
   static constexpr inline thread_local auto &[j1] = n; // expected-error {{cannot be declared with 'constexpr inline' specifiers}}
-  static thread_local auto &[j2] = n; // expected-warning {{declared with 'static thread_local' specifiers is a C++20 extension}}
+  static thread_local auto &[j2] = n; // cxx17-warning {{declared with 'static thread_local' specifiers is a C++20 extension}}
 
   inline auto &[k] = n; // expected-error {{cannot be declared 'inline'}}
 
   const int K = 5;
+  auto ([c]) = s; // expected-error {{decomposition declaration cannot be declared with parentheses}}
   void g() {
 // defining-type-specifiers other than cv-qualifiers and 'auto'
 S [a] = s; // expected-error {{cannot be declared with type 'S'}}
 decltype(auto) [b] = s; // expected-error {{cannot be declared with type 'decltype(auto)'}}
-auto ([c]) = s; // expected-error {{cannot be declared with parentheses}}
+auto ([c2]) = s; // cxx17-error {{decomposition declaration cannot

[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

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



Comment at: clang/lib/Parse/ParseTentative.cpp:1067
+bool mayHaveDirectInit,
+bool mayHaveTrailingReturnType) {
   // declarator:

Not part of this commit I guess, but //four// bool parameters is truly horrific 
:/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

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


cfe-commits@lists.llvm.org

2023-04-27 Thread Jens Massberg via Phabricator via cfe-commits
massberg marked 5 inline comments as done.
massberg added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8593
 
+const FunctionProtoType *FnType = 
FD->getType()->castAs();
+if (FnType->isVolatile()) {

aaron.ballman wrote:
> aaron.ballman wrote:
> > ilya-biryukov wrote:
> > > NIT: this version is simpler and more aligned with the code below.
> > > Also, could you move the `volatile` handling after the check for `const`?
> > > 
> > > 
> > > Additionally, we seem to recover in case of `const` by adding it to the 
> > > type and suggesting a fix-it to add it in the code.
> > > Could we do the same for `volatile` and `ref-qualifier`, i.e. suggest a 
> > > fix-it to remove the `ref-qualifier` and `volatile` and change the 
> > > corresponding type to make AST pretend they were never there?
> > 
> Note, you can shorten it further with:
> ```
> return Diag(...);
> ```
> because that will return true for you.
Thanks! Which the change suggested by Ilya this has become obsolete.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8593-8601
+const FunctionProtoType *FnType = 
FD->getType()->castAs();
+if (FnType->isVolatile()) {
+  Diag(FD->getLocation(), diag::err_volatile_comparison_operator);
+  return true;
+}
+if (FnType->getRefQualifier() == RQ_RValue) {
+  Diag(FD->getLocation(), diag::err_ref_qualifier_comparison_operator);

massberg wrote:
> aaron.ballman wrote:
> > aaron.ballman wrote:
> > > ilya-biryukov wrote:
> > > > NIT: this version is simpler and more aligned with the code below.
> > > > Also, could you move the `volatile` handling after the check for 
> > > > `const`?
> > > > 
> > > > 
> > > > Additionally, we seem to recover in case of `const` by adding it to the 
> > > > type and suggesting a fix-it to add it in the code.
> > > > Could we do the same for `volatile` and `ref-qualifier`, i.e. suggest a 
> > > > fix-it to remove the `ref-qualifier` and `volatile` and change the 
> > > > corresponding type to make AST pretend they were never there?
> > > 
> > Note, you can shorten it further with:
> > ```
> > return Diag(...);
> > ```
> > because that will return true for you.
> Thanks! Which the change suggested by Ilya this has become obsolete.
Thanks, this is much simpler!

I have moved the code and added a recovery. However, adding a fix-it is much 
more complex as there is no simple way to get location to remove the keywords. 
Thus I decided to not offering a fix-it in this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148924

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


[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

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



Comment at: clang/lib/Parse/ParseTentative.cpp:237
   ConsumeAnnotationToken();
-if (Tok.is(tok::identifier))
+if (Tok.isOneOf(tok::identifier, tok::kw_auto))
   ConsumeToken();

aaron.ballman wrote:
> This smells a bit off to me because of the comments above -- this is trying 
> to parse an elaborated type specifier, and `auto` cannot appear in this 
> position for that case. Can you help me understand what's going on?
You are right, this should not have been committed, nice catch!



Comment at: clang/test/Parser/cxx1z-decomposition.cpp:97
 decltype(auto) [b] = s; // expected-error {{cannot be declared with type 
'decltype(auto)'}}
-auto ([c]) = s; // expected-error {{cannot be declared with parentheses}}
+auto ([c]) = s; // expected-error {{'auto' not allowed here}} \
+// expected-error {{use of undeclared identifier 'c'}} \

aaron.ballman wrote:
> This first diagnostic is incorrect -- `auto` is definitely allowed there, 
> just that the rest of the declaration is nonsense. I think the "use of 
> undeclared identifier" diagnostic is reasonable. The lambda diagnostic is 
> interesting.
> 
> Any way you can improve this, or is that a slog?
There were multiple issues there.

The "decomposition declaration cannot be declared with parenthese" error which 
i had remove can still occur at global scope where a declaration is expected so 
i put that back and added a test.
Then, I'm running all the tests in c++17 and 23 modes as the behavior is 
different.

I did restore the current behavior in C++20 and earlier modes, such that we 
will always consider `auto` starts a declaration. That way we can have that 
structured binding in parentheses diag.

But in c++23 mode,  We establish it's not a valid declarator. so we parse it as 
an expression. `[` is always considered as a lambda introducer, which it could 
be, ie `auto([c] {});` is a valid expression assuming that C exists.
At that point trying to figure out that `]` is not followed by `{` and is 
therefore not a lambda seems extremely tricky as you can have arbitrary long 
expressions between the square brackets.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

___
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-27 Thread Xinlong Wu via Phabricator via cfe-commits
VincentWu updated this revision to Diff 517494.
VincentWu marked 3 inline comments as done.
VincentWu added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132819

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/lib/Target/RISCV/RISCVRegisterInfo.td
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcmp-invalid.s
  llvm/test/MC/RISCV/rv32zcmp-valid.s
  llvm/test/MC/RISCV/rv64zcmp-invalid.s
  llvm/test/MC/RISCV/rv64zcmp-valid.s

Index: llvm/test/MC/RISCV/rv64zcmp-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zcmp-valid.s
@@ -0,0 +1,149 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=experimental-zcmp -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=experimental-zcmp < %s \
+# RUN: | llvm-objdump --mattr=-c,experimental-zcmp -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: cm.mvsa01 s1, s0
+# CHECK-ASM: encoding: [0xa2,0xac]
+cm.mvsa01 s1, s0
+
+# CHECK-ASM-AND-OBJ: cm.mva01s s1, s0
+# CHECK-ASM: encoding: [0xe2,0xac]
+cm.mva01s s1, s0
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra}, 16
+# CHECK-ASM: encoding: [0x42,0xbe]
+cm.popret {ra}, 16
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra}, 32
+# CHECK-ASM: encoding: [0x46,0xbe]
+cm.popret {ra}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0}, 64
+# CHECK-ASM: encoding: [0x5e,0xbe]
+cm.popret {ra, s0}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s1}, 32
+# CHECK-ASM: encoding: [0x62,0xbe]
+cm.popret {ra,s0-s1}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s2}, 32
+# CHECK-ASM: encoding: [0x72,0xbe]
+cm.popret {ra, s0-s2}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s3}, 64
+# CHECK-ASM: encoding: [0x86,0xbe]
+cm.popret {ra, s0-s3}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s5}, 64
+# CHECK-ASM: encoding: [0xa2,0xbe]
+cm.popret {ra, s0-s5}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s7}, 80
+# CHECK-ASM: encoding: [0xc2,0xbe]
+cm.popret {ra, s0-s7}, 80
+
+# CHECK-ASM-AND-OBJ: cm.popret   {ra, s0-s11}, 112
+# CHECK-ASM: encoding: [0xf2,0xbe]
+cm.popret {ra, s0-s11}, 112
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra}, 16
+# CHECK-ASM: encoding: [0x42,0xbc]
+cm.popretz {ra}, 16
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra}, 32
+# CHECK-ASM: encoding: [0x46,0xbc]
+cm.popretz {ra}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0}, 64
+# CHECK-ASM: encoding: [0x5e,0xbc]
+cm.popretz {ra, s0}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s1}, 32
+# CHECK-ASM: encoding: [0x62,0xbc]
+cm.popretz {ra, s0-s1}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s2}, 32
+# CHECK-ASM: encoding: [0x72,0xbc]
+cm.popretz {ra, s0-s2}, 32
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s3}, 64
+# CHECK-ASM: encoding: [0x86,0xbc]
+cm.popretz {ra, s0-s3}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s5}, 64
+# CHECK-ASM: encoding: [0xa2,0xbc]
+cm.popretz {ra, s0-s5}, 64
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s7}, 80
+# CHECK-ASM: encoding: [0xc2,0xbc]
+cm.popretz {ra, s0-s7}, 80
+
+# CHECK-ASM-AND-OBJ: cm.popretz   {ra, s0-s11}, 112
+# CHECK-ASM: encoding: [0xf2,0xbc]
+cm.popretz {ra, s0-s11}, 112
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra}, 16
+# CHECK-ASM: encoding: [0x42,0xba]
+cm.pop {ra}, 16
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra}, 32
+# CHECK-ASM: encoding: [0x46,0xba]
+cm.pop {ra}, 32
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0}, 16
+# CHECK-ASM: encoding: [0x52,0xba]
+cm.pop {ra, s0}, 16
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s1}, 32
+# CHECK-ASM: encoding: [0x62,0xba]
+cm.pop {ra, s0-s1}, 32
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s2}, 32
+# CHECK-ASM: encoding: [0x72,0xba]
+cm.pop {ra, s0-s2}, 32
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s5}, 64
+# CHECK-ASM: encoding: [0xa2,0xba]
+cm.pop {ra, s0-s5}, 64
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s7}, 80
+# CHECK-ASM: encoding: [0xc2,0xba]
+cm.pop {ra, s0-s7}, 80
+
+# CHECK-ASM-AND-OBJ: cm.pop  {ra, s0-s11}, 112
+# CHECK-ASM: encoding: [0xf2,0xba]
+cm.pop {ra, s0-s11}, 112
+
+# CHECK-ASM-AND-OBJ: cm.push {ra}, -16
+# CHECK-ASM: encoding: [0x42,0xb8]
+cm.push {ra}, -16
+
+# CHECK-ASM-AND-OBJ: cm.push {ra, s0}, -32
+# CHECK-ASM: encoding: [0x56,0xb8]
+cm.push {ra, s0}, -32
+
+# CHECK-ASM-AND-OBJ: cm.push {ra, s0-s1}, -32
+# CHECK-A

[PATCH] D149246: [RISCV] Relax rules for ordering s/z/x prefixed extensions in ISA naming strings

2023-04-27 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng accepted this revision.
kito-cheng added a comment.

I am really happy to see this happen, binutils has relaxed for a while in more 
relaxed way[1] - only require must start with `rv[32|64][e|i|g]`, personally I 
would like to relax the order at all like binutils did for GCC, but I don't 
want to disturb that before making sure clang will going same way - otherwise 
just making more incomparable.

The order is kind of not friendly for user, I don't believe how many people 
remember the right order between `z*` extension in short time - even after read 
the RISC-V ISA spec.

[1] https://sourceware.org/pipermail/binutils/2022-December/125267.html


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

https://reviews.llvm.org/D149246

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


[clang] 7c97dc2 - [clang] Do not crash on undefined template partial specialization

2023-04-27 Thread Mariya Podchishchaeva via cfe-commits

Author: Mariya Podchishchaeva
Date: 2023-04-27T05:38:41-04:00
New Revision: 7c97dc20ab6148289f2cc01b2999130e32a19eb3

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

LOG: [clang] Do not crash on undefined template partial specialization

Before checking that template partial specialization is "reachable",
ensure it exists.

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

Reviewed By: shafik, erichkeane

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

Added: 
clang/test/SemaCXX/undefined-partial-specialization.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaCXXScopeSpec.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ab7b2e05e54c1..f473f97f6c74e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -325,6 +325,8 @@ Bug Fixes in This Version
   member pointer as an invalid expression.
 - Fix crash when member function contains invalid default argument.
   (`#62122 `_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index 759ed6f352c81..b11f4f1b7cdd9 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -131,7 +131,8 @@ DeclContext *Sema::computeDeclContext(const CXXScopeSpec 
&SS,
 // entering the context, and that can't happen in a SFINAE context.
 assert(!isSFINAEContext() && "partial specialization scope "
  "specifier in SFINAE context?");
-if (!hasReachableDefinition(PartialSpec))
+if (PartialSpec->hasDefinition() &&
+!hasReachableDefinition(PartialSpec))
   diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,
 MissingImportKind::PartialSpecialization,
 true);

diff  --git a/clang/test/SemaCXX/undefined-partial-specialization.cpp 
b/clang/test/SemaCXX/undefined-partial-specialization.cpp
new file mode 100644
index 0..b07a513270fd6
--- /dev/null
+++ b/clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH61356 {
+
+template 
+class boo {void foo();};
+
+template 
+class boo;
+
+template
+void boo::foo(){} // expected-error{{out-of-line definition of 'foo' 
from class 'boo' without definition}}
+
+}



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


[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

2023-04-27 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7c97dc20ab61: [clang] Do not crash on undefined template 
partial specialization (authored by Fznamznon).

Changed prior to commit:
  https://reviews.llvm.org/D148330?vs=513581&id=517496#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148330

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/test/SemaCXX/undefined-partial-specialization.cpp


Index: clang/test/SemaCXX/undefined-partial-specialization.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH61356 {
+
+template 
+class boo {void foo();};
+
+template 
+class boo;
+
+template
+void boo::foo(){} // expected-error{{out-of-line definition of 'foo' 
from class 'boo' without definition}}
+
+}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -131,7 +131,8 @@
 // entering the context, and that can't happen in a SFINAE context.
 assert(!isSFINAEContext() && "partial specialization scope "
  "specifier in SFINAE context?");
-if (!hasReachableDefinition(PartialSpec))
+if (PartialSpec->hasDefinition() &&
+!hasReachableDefinition(PartialSpec))
   diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,
 MissingImportKind::PartialSpecialization,
 true);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -325,6 +325,8 @@
   member pointer as an invalid expression.
 - Fix crash when member function contains invalid default argument.
   (`#62122 `_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/undefined-partial-specialization.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH61356 {
+
+template 
+class boo {void foo();};
+
+template 
+class boo;
+
+template
+void boo::foo(){} // expected-error{{out-of-line definition of 'foo' from class 'boo' without definition}}
+
+}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -131,7 +131,8 @@
 // entering the context, and that can't happen in a SFINAE context.
 assert(!isSFINAEContext() && "partial specialization scope "
  "specifier in SFINAE context?");
-if (!hasReachableDefinition(PartialSpec))
+if (PartialSpec->hasDefinition() &&
+!hasReachableDefinition(PartialSpec))
   diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,
 MissingImportKind::PartialSpecialization,
 true);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -325,6 +325,8 @@
   member pointer as an invalid expression.
 - Fix crash when member function contains invalid default argument.
   (`#62122 `_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148712: [clang] Diagnose shadowing of lambda's template parameter by a capture

2023-04-27 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 517502.
Fznamznon added a comment.

Rebase to double check that pre-commit fail is unrelated, add a release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148712

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp


Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow 
-Wshadow-uncaptured-local %s
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow-all %s
 // RUN: %clang_cc1 -std=c++17 -verify -fsyntax-only -Wshadow-all %s
+// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only -Wshadow-all %s
 
 void foo(int param) { // expected-note 1+ {{previous declaration is here}}
   int var = 0; // expected-note 1+ {{previous declaration is here}}
@@ -146,3 +147,22 @@
 int b = 0; // expected-error {{redefinition of 'b'}}
   };
 }
+
+namespace GH61105 {
+void f() {
+  int y = 0;
+  int x = 0;
+#if __cplusplus >= 202002L
+  auto l1 = [y](y) { return 0; }; // expected-error {{declaration 
of 'y' shadows template parameter}} \
+  // expected-note {{template 
parameter is declared here}}
+  auto l2 = [=]() { int a = y; return 0; }; // expected-error 
{{'y' does not refer to a value}} \
+// expected-note 
{{declared here}}
+  auto l3 = [&, y](y) { int a = x; return 0; }; // 
expected-error {{declaration of 'y' shadows template parameter}} \
+  // 
expected-note {{template parameter is declared here}}
+  auto l4 = [x, y]() { return 0; }; // expected-error 
{{declaration of 'y' shadows template parameter}} \
+   // expected-error 
{{declaration of 'x' shadows template parameter}} \
+   // expected-note 
2{{template parameter is declared here}}
+  auto l5 = [](y) { return 0; }; // No diagnostic
+#endif
+}
+}
Index: 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
===
--- /dev/null
+++ 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+void f() {
+  int x = 0;
+  auto g = [x](int x) { return 0; }; // expected-error {{a lambda parameter 
cannot shadow an explicitly captured entity}} \
+ // expected-note {{variable 'x' is 
explicitly captured here}}
+  auto h = [y = 0](y) { return 0; };  // expected-error 
{{declaration of 'y' shadows template parameter}} \
+  // expected-note {{template 
parameter is declared here}}
+
+}
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1365,6 +1365,26 @@
 PushOnScopeChains(P, CurScope);
   }
 
+  // C++23 [expr.prim.lambda.capture]p5:
+  // If an identifier in a capture appears as the declarator-id of a parameter
+  // of the lambda-declarator's parameter-declaration-clause or as the name of 
a
+  // template parameter of the lambda-expression's template-parameter-list, the
+  // program is ill-formed.
+  TemplateParameterList *TemplateParams =
+  getGenericLambdaTemplateParameterList(LSI, *this);
+  if (TemplateParams) {
+for (const auto *TP : TemplateParams->asArray()) {
+  if (!TP->getIdentifier())
+continue;
+  for (const auto &Capture : Intro.Captures) {
+if (Capture.Id == TP->getIdentifier()) {
+  Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
+  Diag(TP->getLocation(), diag::note_template_param_here);
+}
+  }
+}
+  }
+
   // C++20: dcl.decl.general p4:
   // The optional requires-clause ([temp.pre]) in an init-declarator or
   // member-declarator shall be present only if the declarator declares a
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -231,6 +231,8 @@
 - ``-Wformat`` now recognizes ``%lb`` for the ``printf``/``scanf`` family of
   functions.
   (`#62247: `_).
+- Clang now diagnoses shadowing of lambda's template parameter by a capture.
+  (`#61105: `_).
 
 Bug Fixes in This Version
 --

[clang] 6cf14a7 - [clang][Interp] Check Neg ops for errors

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

Author: Timm Bäder
Date: 2023-04-27T12:05:23+02:00
New Revision: 6cf14a72390f0914b18f30f2f357b783ff84533c

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

LOG: [clang][Interp] Check Neg ops for errors

This should fail when negating __INT_MIN__.

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

Added: 


Modified: 
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/PrimType.h
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 932caca29b9f0..cc7c7a9d2430e 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -223,6 +223,9 @@ template  class Integral final {
   }
 
   static bool neg(Integral A, Integral *R) {
+if (Signed && A.isMin())
+  return true;
+
 *R = -A;
 return false;
   }

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 152a876a42964..7b80bb9649916 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -413,12 +413,32 @@ bool Inv(InterpState &S, CodePtr OpPC) {
 
 template ::T>
 bool Neg(InterpState &S, CodePtr OpPC) {
-  const T &Val = S.Stk.pop();
+  const T &Value = S.Stk.pop();
   T Result;
-  T::neg(Val, &Result);
 
+  if (!T::neg(Value, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+
+  assert(isIntegralType(Name) &&
+ "don't expect other types to fail at constexpr negation");
   S.Stk.push(Result);
-  return true;
+
+  APSInt NegatedValue = -Value.toAPSInt(Value.bitWidth() + 1);
+  const Expr *E = S.Current->getExpr(OpPC);
+  QualType Type = E->getType();
+
+  if (S.checkingForUndefinedBehavior()) {
+SmallString<32> Trunc;
+NegatedValue.trunc(Result.bitWidth()).toString(Trunc, 10);
+auto Loc = E->getExprLoc();
+S.report(Loc, diag::warn_integer_constant_overflow) << Trunc << Type;
+return true;
+  }
+
+  S.CCEDiag(E, diag::note_constexpr_overflow) << NegatedValue << Type;
+  return S.noteUndefinedBehavior();
 }
 
 enum class PushVal : bool {

diff  --git a/clang/lib/AST/Interp/PrimType.h b/clang/lib/AST/Interp/PrimType.h
index 30bec3f2a17cf..693e57210608d 100644
--- a/clang/lib/AST/Interp/PrimType.h
+++ b/clang/lib/AST/Interp/PrimType.h
@@ -42,6 +42,8 @@ enum PrimType : unsigned {
   PT_FnPtr,
 };
 
+constexpr bool isIntegralType(PrimType T) { return T <= PT_Uint64; }
+
 /// Mapping from primitive types to their representation.
 template  struct PrimConv;
 template <> struct PrimConv { using T = Integral<8, true>; };

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 598d748c266b4..acad760bc43ee 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -80,6 +80,12 @@ static_assert(~255 == -256, "");
 static_assert(~INT_MIN == INT_MAX, "");
 static_assert(~INT_MAX == INT_MIN, "");
 
+static_assert(-(1 << 31), ""); // expected-error {{not an integral constant 
expression}} \
+   // expected-note {{outside the range of 
representable values}} \
+   // ref-error {{not an integral constant 
expression}} \
+   // ref-note {{outside the range of 
representable values}} \
+
+
 enum E {};
 constexpr E e = static_cast(0);
 static_assert(~e == -1, "");



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


[PATCH] D148987: [clang][Interp] Check Neg ops for errors

2023-04-27 Thread Timm Bäder 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 rG6cf14a72390f: [clang][Interp] Check Neg ops for errors 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D148987?vs=517054&id=517503#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148987

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/PrimType.h
  clang/test/AST/Interp/literals.cpp


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -80,6 +80,12 @@
 static_assert(~INT_MIN == INT_MAX, "");
 static_assert(~INT_MAX == INT_MIN, "");
 
+static_assert(-(1 << 31), ""); // expected-error {{not an integral constant 
expression}} \
+   // expected-note {{outside the range of 
representable values}} \
+   // ref-error {{not an integral constant 
expression}} \
+   // ref-note {{outside the range of 
representable values}} \
+
+
 enum E {};
 constexpr E e = static_cast(0);
 static_assert(~e == -1, "");
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -42,6 +42,8 @@
   PT_FnPtr,
 };
 
+constexpr bool isIntegralType(PrimType T) { return T <= PT_Uint64; }
+
 /// Mapping from primitive types to their representation.
 template  struct PrimConv;
 template <> struct PrimConv { using T = Integral<8, true>; };
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -413,12 +413,32 @@
 
 template ::T>
 bool Neg(InterpState &S, CodePtr OpPC) {
-  const T &Val = S.Stk.pop();
+  const T &Value = S.Stk.pop();
   T Result;
-  T::neg(Val, &Result);
 
+  if (!T::neg(Value, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+
+  assert(isIntegralType(Name) &&
+ "don't expect other types to fail at constexpr negation");
   S.Stk.push(Result);
-  return true;
+
+  APSInt NegatedValue = -Value.toAPSInt(Value.bitWidth() + 1);
+  const Expr *E = S.Current->getExpr(OpPC);
+  QualType Type = E->getType();
+
+  if (S.checkingForUndefinedBehavior()) {
+SmallString<32> Trunc;
+NegatedValue.trunc(Result.bitWidth()).toString(Trunc, 10);
+auto Loc = E->getExprLoc();
+S.report(Loc, diag::warn_integer_constant_overflow) << Trunc << Type;
+return true;
+  }
+
+  S.CCEDiag(E, diag::note_constexpr_overflow) << NegatedValue << Type;
+  return S.noteUndefinedBehavior();
 }
 
 enum class PushVal : bool {
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -223,6 +223,9 @@
   }
 
   static bool neg(Integral A, Integral *R) {
+if (Signed && A.isMin())
+  return true;
+
 *R = -A;
 return false;
   }


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -80,6 +80,12 @@
 static_assert(~INT_MIN == INT_MAX, "");
 static_assert(~INT_MAX == INT_MIN, "");
 
+static_assert(-(1 << 31), ""); // expected-error {{not an integral constant expression}} \
+   // expected-note {{outside the range of representable values}} \
+   // ref-error {{not an integral constant expression}} \
+   // ref-note {{outside the range of representable values}} \
+
+
 enum E {};
 constexpr E e = static_cast(0);
 static_assert(~e == -1, "");
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -42,6 +42,8 @@
   PT_FnPtr,
 };
 
+constexpr bool isIntegralType(PrimType T) { return T <= PT_Uint64; }
+
 /// Mapping from primitive types to their representation.
 template  struct PrimConv;
 template <> struct PrimConv { using T = Integral<8, true>; };
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -413,12 +413,32 @@
 
 template ::T>
 bool Neg(InterpState &S, CodePtr OpPC) {
-  const T &Val = S.Stk.pop();
+  const T &Value = S.Stk.pop();
   T Result;
-  T::neg(Val, &Result);
 
+  if (!T::neg(Value, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+
+  assert(isIntegralType(Name) &&
+ "don't expect other types to fail at constexpr negation");
   S.Stk.push

[clang-tools-extra] 4b1cec0 - [clangd] Add batch fixes for include-cleaner diagnostics

2023-04-27 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-04-27T12:08:59+02:00
New Revision: 4b1cec065227db64f870a179a2d45cffa314641a

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

LOG: [clangd] Add batch fixes for include-cleaner diagnostics

For each unused-include/missing-include diagnostic, we provide fix-all
alternative to them.

This patch also adds LSP ChangeAnnotation support.

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

Added: 
clang-tools-extra/clangd/test/Inputs/include-cleaner/all1.h
clang-tools-extra/clangd/test/Inputs/include-cleaner/all2.h
clang-tools-extra/clangd/test/Inputs/include-cleaner/bar.h
clang-tools-extra/clangd/test/Inputs/include-cleaner/foo.h
clang-tools-extra/clangd/test/include-cleaner-batch-fix.test

Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/Diagnostics.cpp
clang-tools-extra/clangd/Diagnostics.h
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index bef6c4de131ed..26e239fa7bed6 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -99,19 +99,29 @@ CodeAction toCodeAction(const ClangdServer::TweakRef &T, 
const URIForFile &File,
 /// Convert from Fix to LSP CodeAction.
 CodeAction toCodeAction(const Fix &F, const URIForFile &File,
 const std::optional &Version,
-bool SupportsDocumentChanges) {
+bool SupportsDocumentChanges,
+bool SupportChangeAnnotation) {
   CodeAction Action;
   Action.title = F.Message;
   Action.kind = std::string(CodeAction::QUICKFIX_KIND);
   Action.edit.emplace();
   if (!SupportsDocumentChanges) {
 Action.edit->changes.emplace();
-(*Action.edit->changes)[File.uri()] = {F.Edits.begin(), F.Edits.end()};
+auto &Changes = (*Action.edit->changes)[File.uri()];
+for (const auto &E : F.Edits)
+  Changes.push_back({E.range, E.newText, /*annotationId=*/""});
   } else {
 Action.edit->documentChanges.emplace();
-TextDocumentEdit& Edit = Action.edit->documentChanges->emplace_back();
+TextDocumentEdit &Edit = Action.edit->documentChanges->emplace_back();
 Edit.textDocument = VersionedTextDocumentIdentifier{{File}, Version};
-Edit.edits = {F.Edits.begin(), F.Edits.end()};
+for (const auto &E : F.Edits)
+  Edit.edits.push_back(
+  {E.range, E.newText,
+   SupportChangeAnnotation ? E.annotationId : ""});
+if (SupportChangeAnnotation) {
+  for (const auto &[AID, Annotation]: F.Annotations)
+Action.edit->changeAnnotations[AID] = Annotation;
+}
   }
   return Action;
 }
@@ -509,6 +519,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
   SupportsReferenceContainer = Params.capabilities.ReferenceContainer;
   SupportFileStatus = Params.initializationOptions.FileStatus;
   SupportsDocumentChanges = Params.capabilities.DocumentChanges;
+  SupportsChangeAnnotation = Params.capabilities.ChangeAnnotation;
   HoverContentFormat = Params.capabilities.HoverContentFormat;
   Opts.LineFoldingOnly = Params.capabilities.LineFoldingOnly;
   SupportsOffsetsInSignatureHelp = Params.capabilities.OffsetsInSignatureHelp;
@@ -1742,7 +1753,8 @@ void ClangdLSPServer::onDiagnosticsReady(PathRef File, 
llvm::StringRef Version,
  for (const auto &Fix : Fixes)
CodeActions.push_back(toCodeAction(Fix, Notification.uri,
   Notification.version,
-  
SupportsDocumentChanges));
+  SupportsDocumentChanges,
+  
SupportsChangeAnnotation));
 
  if (DiagOpts.EmbedFixesInDiagnostics) {
Diag.codeActions.emplace(CodeActions);

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index e5e2104dcec2f..33c8d221f9bd4 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -277,6 +277,9 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
   bool SupportsOffsetsInSignatureHelp = false;
   /// Whether the client supports the versioned document changes.
   bool SupportsDocumentChanges = fals

[PATCH] D147684: [clangd] Add batch fixes for include-cleaner diagnostics

2023-04-27 Thread Haojian Wu 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 rG4b1cec065227: [clangd] Add batch fixes for include-cleaner 
diagnostics (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D147684?vs=517157&id=517505#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147684

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/test/Inputs/include-cleaner/all1.h
  clang-tools-extra/clangd/test/Inputs/include-cleaner/all2.h
  clang-tools-extra/clangd/test/Inputs/include-cleaner/bar.h
  clang-tools-extra/clangd/test/Inputs/include-cleaner/foo.h
  clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -45,8 +45,8 @@
 using ::testing::Pointee;
 using ::testing::UnorderedElementsAre;
 
-Matcher withFix(::testing::Matcher FixMatcher) {
-  return Field(&Diag::Fixes, ElementsAre(FixMatcher));
+Matcher withFix(std::vector<::testing::Matcher> FixMatcheres) {
+  return Field(&Diag::Fixes, testing::UnorderedElementsAreArray(FixMatcheres));
 }
 
 MATCHER_P2(Diag, Range, Message,
@@ -60,6 +60,8 @@
   return arg.Message == Message && arg.Edits.size() == 1 &&
  arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
 }
+MATCHER_P(FixMessage, Message, "") { return arg.Message == Message; }
+
 
 std::string guard(llvm::StringRef Code) {
   return "#pragma once\n" + Code.str();
@@ -255,42 +257,51 @@
   UnorderedElementsAre(
   AllOf(Diag(MainFile.range("b"),
  "No header providing \"b\" is directly included"),
-withFix(Fix(MainFile.range("insert_b"), "#include \"b.h\"\n",
-"#include \"b.h\""))),
+withFix({Fix(MainFile.range("insert_b"), "#include \"b.h\"\n",
+ "#include \"b.h\""),
+ FixMessage("add all missing includes")})),
   AllOf(Diag(MainFile.range("bar"),
  "No header providing \"ns::Bar\" is directly included"),
-withFix(Fix(MainFile.range("insert_d"),
-"#include \"dir/d.h\"\n", "#include \"dir/d.h\""))),
+withFix({Fix(MainFile.range("insert_d"),
+ "#include \"dir/d.h\"\n", "#include \"dir/d.h\""),
+ FixMessage("add all missing includes")})),
   AllOf(Diag(MainFile.range("f"),
  "No header providing \"f\" is directly included"),
-withFix(Fix(MainFile.range("insert_f"), "#include \n",
-"#include "))),
+withFix({Fix(MainFile.range("insert_f"), "#include \n",
+ "#include "),
+ FixMessage("add all missing includes")})),
   AllOf(
   Diag(MainFile.range("foobar"),
"No header providing \"foobar\" is directly included"),
-  withFix(Fix(MainFile.range("insert_foobar"),
-  "#include \"public.h\"\n", "#include \"public.h\""))),
+  withFix({Fix(MainFile.range("insert_foobar"),
+   "#include \"public.h\"\n", "#include \"public.h\""),
+   FixMessage("add all missing includes")})),
   AllOf(
   Diag(MainFile.range("vector"),
"No header providing \"std::vector\" is directly included"),
-  withFix(Fix(MainFile.range("insert_vector"),
-  "#include \n", "#include "))),
+  withFix({Fix(MainFile.range("insert_vector"),
+   "#include \n", "#include "),
+   FixMessage("add all missing includes"),})),
   AllOf(Diag(MainFile.range("FOO"),
  "No header providing \"FOO\" is directly included"),
-withFix(Fix(MainFile.range("insert_foo"),
-"#include \"foo.h\"\n", "#include \"foo.h\""))),
+withFix({Fix(MainFile.range("insert_foo"),
+ "#include \"foo.h\"\n", "#include \"foo.h\""),
+ FixMessage("add all missing includes")})),
  

[clang] f8a9c55 - [clang][Interp] Emit diagnostic when comparing function pointers

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

Author: Timm Bäder
Date: 2023-04-27T12:33:28+02:00
New Revision: f8a9c55bef380a592c4588025f8b6ca4dfc94c47

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

LOG: [clang][Interp] Emit diagnostic when comparing function pointers

Function pointers can be compared for (in)equality but, but LE, GE, LT,
and GT opcodes should emit an error and abort.

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

Added: 


Modified: 
clang/lib/AST/Interp/FunctionPointer.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/FunctionPointer.h 
b/clang/lib/AST/Interp/FunctionPointer.h
index 2d449bdb031d..20d4d7793185 100644
--- a/clang/lib/AST/Interp/FunctionPointer.h
+++ b/clang/lib/AST/Interp/FunctionPointer.h
@@ -8,6 +8,7 @@
 #include "clang/AST/APValue.h"
 
 namespace clang {
+class ASTContext;
 namespace interp {
 
 class FunctionPointer final {
@@ -38,6 +39,13 @@ class FunctionPointer final {
 OS << ")";
   }
 
+  std::string toDiagnosticString(const ASTContext &Ctx) const {
+if (!Func)
+  return "nullptr";
+
+return toAPValue().getAsString(Ctx, Func->getDecl()->getType());
+  }
+
   ComparisonCategoryResult compare(const FunctionPointer &RHS) const {
 if (Func == RHS.Func)
   return ComparisonCategoryResult::Equal;

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 7b80bb964991..d751ba021b11 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -574,6 +574,29 @@ bool CmpHelperEQ(InterpState &S, CodePtr OpPC, CompareFn 
Fn) {
   return CmpHelper(S, OpPC, Fn);
 }
 
+/// Function pointers cannot be compared in an ordered way.
+template <>
+inline bool CmpHelper(InterpState &S, CodePtr OpPC,
+   CompareFn Fn) {
+  const auto &RHS = S.Stk.pop();
+  const auto &LHS = S.Stk.pop();
+
+  const SourceInfo &Loc = S.Current->getSource(OpPC);
+  S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
+  << LHS.toDiagnosticString(S.getCtx())
+  << RHS.toDiagnosticString(S.getCtx());
+  return false;
+}
+
+template <>
+inline bool CmpHelperEQ(InterpState &S, CodePtr OpPC,
+ CompareFn Fn) {
+  const auto &RHS = S.Stk.pop();
+  const auto &LHS = S.Stk.pop();
+  S.Stk.push(Boolean::from(Fn(LHS.compare(RHS;
+  return true;
+}
+
 template <>
 inline bool CmpHelper(InterpState &S, CodePtr OpPC, CompareFn Fn) {
   using BoolT = PrimConv::T;

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index ed0774a78833..717c4629fcc3 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -94,7 +94,7 @@ def AllTypeClass : TypeClass {
 }
 
 def ComparableTypeClass : TypeClass {
-  let Types = !listconcat(AluTypeClass.Types, [Ptr], [Float]);
+  let Types = !listconcat(AluTypeClass.Types, [Ptr], [Float], [FnPtr]);
 }
 
 class SingletonTypeClass : TypeClass {

diff  --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index a8681aae0d58..5bb48ffc54dd 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -178,6 +178,31 @@ namespace FunctionReturnType {
   static_assert(s.fp == nullptr, ""); // zero-initialized function pointer.
 }
 
+namespace Comparison {
+  void f(), g();
+  constexpr void (*pf)() = &f, (*pg)() = &g;
+
+  constexpr bool u13 = pf < pg; // ref-warning {{ordered comparison of 
function pointers}} \
+// ref-error {{must be initialized by a 
constant expression}} \
+// ref-note {{comparison between '&f' and '&g' 
has unspecified value}} \
+// expected-warning {{ordered comparison of 
function pointers}} \
+// expected-error {{must be initialized by a 
constant expression}} \
+// expected-note {{comparison between '&f' and 
'&g' has unspecified value}}
+
+  constexpr bool u14 = pf < (void(*)())nullptr; // ref-warning {{ordered 
comparison of function pointers}} \
+// ref-error {{must be 
initialized by a constant expression}} \
+// ref-note {{comparison 
between '&f' and 'nullptr' has unspecified value}} \
+// expected-warning {{ordered 
comparison of function pointers}} \
+// expected-error {{must be 
initialized by a constant expression}} \
+// expected-note {{comparison 
between '&f' and 'nullptr' has u

[PATCH] D149154: [clang][Interp] Emit diagnostic when comparing function pointers

2023-04-27 Thread Timm Bäder 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 rGf8a9c55bef38: [clang][Interp] Emit diagnostic when comparing 
function pointers (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D149154?vs=516790&id=517506#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149154

Files:
  clang/lib/AST/Interp/FunctionPointer.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/functions.cpp

Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -178,6 +178,31 @@
   static_assert(s.fp == nullptr, ""); // zero-initialized function pointer.
 }
 
+namespace Comparison {
+  void f(), g();
+  constexpr void (*pf)() = &f, (*pg)() = &g;
+
+  constexpr bool u13 = pf < pg; // ref-warning {{ordered comparison of function pointers}} \
+// ref-error {{must be initialized by a constant expression}} \
+// ref-note {{comparison between '&f' and '&g' has unspecified value}} \
+// expected-warning {{ordered comparison of function pointers}} \
+// expected-error {{must be initialized by a constant expression}} \
+// expected-note {{comparison between '&f' and '&g' has unspecified value}}
+
+  constexpr bool u14 = pf < (void(*)())nullptr; // ref-warning {{ordered comparison of function pointers}} \
+// ref-error {{must be initialized by a constant expression}} \
+// ref-note {{comparison between '&f' and 'nullptr' has unspecified value}} \
+// expected-warning {{ordered comparison of function pointers}} \
+// expected-error {{must be initialized by a constant expression}} \
+// expected-note {{comparison between '&f' and 'nullptr' has unspecified value}}
+
+
+
+  static_assert(pf != pg, "");
+  static_assert(pf == &f, "");
+  static_assert(pg == &g, "");
+}
+
 }
 
 struct F {
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -94,7 +94,7 @@
 }
 
 def ComparableTypeClass : TypeClass {
-  let Types = !listconcat(AluTypeClass.Types, [Ptr], [Float]);
+  let Types = !listconcat(AluTypeClass.Types, [Ptr], [Float], [FnPtr]);
 }
 
 class SingletonTypeClass : TypeClass {
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -574,6 +574,29 @@
   return CmpHelper(S, OpPC, Fn);
 }
 
+/// Function pointers cannot be compared in an ordered way.
+template <>
+inline bool CmpHelper(InterpState &S, CodePtr OpPC,
+   CompareFn Fn) {
+  const auto &RHS = S.Stk.pop();
+  const auto &LHS = S.Stk.pop();
+
+  const SourceInfo &Loc = S.Current->getSource(OpPC);
+  S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
+  << LHS.toDiagnosticString(S.getCtx())
+  << RHS.toDiagnosticString(S.getCtx());
+  return false;
+}
+
+template <>
+inline bool CmpHelperEQ(InterpState &S, CodePtr OpPC,
+ CompareFn Fn) {
+  const auto &RHS = S.Stk.pop();
+  const auto &LHS = S.Stk.pop();
+  S.Stk.push(Boolean::from(Fn(LHS.compare(RHS;
+  return true;
+}
+
 template <>
 inline bool CmpHelper(InterpState &S, CodePtr OpPC, CompareFn Fn) {
   using BoolT = PrimConv::T;
Index: clang/lib/AST/Interp/FunctionPointer.h
===
--- clang/lib/AST/Interp/FunctionPointer.h
+++ clang/lib/AST/Interp/FunctionPointer.h
@@ -8,6 +8,7 @@
 #include "clang/AST/APValue.h"
 
 namespace clang {
+class ASTContext;
 namespace interp {
 
 class FunctionPointer final {
@@ -38,6 +39,13 @@
 OS << ")";
   }
 
+  std::string toDiagnosticString(const ASTContext &Ctx) const {
+if (!Func)
+  return "nullptr";
+
+return toAPValue().getAsString(Ctx, Func->getDecl()->getType());
+  }
+
   ComparisonCategoryResult compare(const FunctionPointer &RHS) const {
 if (Func == RHS.Func)
   return ComparisonCategoryResult::Equal;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148663: [RFC][clangd] Use interpolation for CDB pushed via LSP protocol

2023-04-27 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

In D148663#4298496 , @ilya-biryukov 
wrote:

> I wanted to chime in and provide a bit of context.
> This was a long time ago, so I might misremember, so take this with a grain 
> of salt.
>
> Idea behind pushing the CDB over LSP was to allow the capable client to 
> **fully** control the commands produced for the files.
> Decisions like interpolation were pushed towards the clients intentionally, 
> not accidentally.
> IIRC, the motivation back in the day was either sourcekit-lsp or Theia.
>
> I will let other do the actual review, just wanted to bring up the history 
> for a complete picutre.

Thank you for sharing the context. I completely agree with the idea that 
nothing should prevent clangd clients from fully controlling CDB if they want 
it.
And, if they do so, this diff will just does nothing because there is an exact 
match. It starts playing only if client provided partial CDB and inference is 
required.
So I think it shouldn't break any existing scenarios. But IMHO having inference 
is a good feature for clangd because it allows pushing exactly the same CDB as 
in
compile_commands.json file and re-using clangd logic how to transfer compile 
commands from source to header. Pushing command via LSP might be preferable
in comparison with file based approach to avoid race condition with updating 
the file and clangd reading it + it works better with build systems that can 
generate
compiles commands on the fly for files and generating all of them in advance 
may not be possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148663

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


[PATCH] D137414: [TySan] Fix Type Sanitizer build on Linux

2023-04-27 Thread Mingjie Xu via Phabricator via cfe-commits
Enna1 created this revision.
Herald added a project: All.
Enna1 updated this revision to Diff 474450.
Enna1 added a comment.
Enna1 added a reviewer: fhahn.
Enna1 added a subscriber: MTC.
Enna1 published this revision for review.
Herald added subscribers: Sanitizers, cfe-commits, StephenFan.
Herald added projects: clang, Sanitizers.

update


fhahn added a comment.

Thanks! It looks like this makes the pre-commit testing happy!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137414

Files:
  clang/runtime/CMakeLists.txt
  compiler-rt/lib/tysan/CMakeLists.txt
  compiler-rt/lib/tysan/tysan_interceptors.cpp

Index: compiler-rt/lib/tysan/tysan_interceptors.cpp
===
--- compiler-rt/lib/tysan/tysan_interceptors.cpp
+++ compiler-rt/lib/tysan/tysan_interceptors.cpp
@@ -84,7 +84,7 @@
   return res;
 }
 
-#ifndef SANITIZER_APPLE
+#if !SANITIZER_APPLE
 INTERCEPTOR(void *, mmap64, void *addr, SIZE_T length, int prot, int flags,
 int fd, OFF64_T offset) {
   void *res = REAL(mmap64)(addr, length, prot, flags, fd, offset);
@@ -154,35 +154,54 @@
   return res;
 }
 
-#ifndef SANITIZER_APPLE
+#if SANITIZER_INTERCEPT_MEMALIGN
 INTERCEPTOR(void *, memalign, uptr alignment, uptr size) {
   void *res = REAL(memalign)(alignment, size);
   if (res)
 tysan_set_type_unknown(res, size);
   return res;
 }
+#define TYSAN_MAYBE_INTERCEPT_MEMALIGN INTERCEPT_FUNCTION(memalign)
+#else
+#define TYSAN_MAYBE_INTERCEPT_MEMALIGN
+#endif // SANITIZER_INTERCEPT_MEMALIGN
 
+#if SANITIZER_INTERCEPT___LIBC_MEMALIGN
 INTERCEPTOR(void *, __libc_memalign, uptr alignment, uptr size) {
   void *res = REAL(__libc_memalign)(alignment, size);
   if (res)
 tysan_set_type_unknown(res, size);
   return res;
 }
+#define TYSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN  \
+  INTERCEPT_FUNCTION(__libc_memalign)
+#else
+#define TYSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN
+#endif // SANITIZER_INTERCEPT___LIBC_MEMALIGN
 
+#if SANITIZER_INTERCEPT_PVALLOC
 INTERCEPTOR(void *, pvalloc, uptr size) {
   void *res = REAL(pvalloc)(size);
   if (res)
 tysan_set_type_unknown(res, size);
   return res;
 }
-#endif
+#define TYSAN_MAYBE_INTERCEPT_PVALLOC INTERCEPT_FUNCTION(pvalloc)
+#else
+#define TYSAN_MAYBE_INTERCEPT_PVALLOC
+#endif // SANITIZER_INTERCEPT_PVALLOC
 
+#if SANITIZER_INTERCEPT_ALIGNED_ALLOC
 INTERCEPTOR(void *, aligned_alloc, uptr alignment, uptr size) {
   void *res = REAL(aligned_alloc)(alignment, size);
   if (res)
 tysan_set_type_unknown(res, size);
   return res;
 }
+#define TYSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC INTERCEPT_FUNCTION(aligned_alloc)
+#else
+#define TYSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC
+#endif
 
 INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) {
   int res = REAL(posix_memalign)(memptr, alignment, size);
@@ -216,10 +235,10 @@
   INTERCEPT_FUNCTION(free);
   INTERCEPT_FUNCTION(realloc);
   INTERCEPT_FUNCTION(valloc);
-  INTERCEPT_FUNCTION(memalign);
-  INTERCEPT_FUNCTION(__libc_memalign);
-  INTERCEPT_FUNCTION(pvalloc);
-  INTERCEPT_FUNCTION(aligned_alloc);
+  TYSAN_MAYBE_INTERCEPT_MEMALIGN;
+  TYSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN;
+  TYSAN_MAYBE_INTERCEPT_PVALLOC;
+  TYSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC
   INTERCEPT_FUNCTION(posix_memalign);
 
   INTERCEPT_FUNCTION(memset);
Index: compiler-rt/lib/tysan/CMakeLists.txt
===
--- compiler-rt/lib/tysan/CMakeLists.txt
+++ compiler-rt/lib/tysan/CMakeLists.txt
@@ -46,4 +46,19 @@
 CFLAGS ${TYSAN_CFLAGS}
 DEFS ${TYSAN_COMMON_DEFINITIONS}
 PARENT_TARGET tysan)
+else()
+  foreach(arch ${TYSAN_SUPPORTED_ARCH})
+set(TYSAN_CFLAGS ${TYSAN_COMMON_CFLAGS})
+append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE TYSAN_CFLAGS)
+add_compiler_rt_runtime(clang_rt.tysan
+  STATIC
+  ARCHS ${arch}
+  SOURCES ${TYSAN_SOURCES}
+  $
+  $
+  $
+  $
+  CFLAGS ${TYSAN_CFLAGS}
+  PARENT_TARGET tysan)
+  endforeach()
 endif()
Index: clang/runtime/CMakeLists.txt
===
--- clang/runtime/CMakeLists.txt
+++ clang/runtime/CMakeLists.txt
@@ -119,7 +119,7 @@
COMPONENT compiler-rt)
 
   # Add top-level targets that build specific compiler-rt runtimes.
-  set(COMPILER_RT_RUNTIMES fuzzer asan builtins dfsan lsan msan profile tsan ubsan ubsan-minimal)
+  set(COMPILER_RT_RUNTIMES fuzzer asan builtins dfsan lsan msan profile tsan tysan ubsan ubsan-minimal)
   foreach(runtime ${COMPILER_RT_RUNTIMES})
 get_ext_project_build_command(build_runtime_cmd ${runtime})
 add_custom_target(${runtime}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149172: [clang][Interp] Emit proper diagnostic when comparing unrelated pointers

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

Meh, turns out `(void*)&s.a;` is a bitcast, so can't push this yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149172

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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-27 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D143347#4298613 , @kpdev42 wrote:

> So what are next steps? Are we going for implementation of 
> `DW_AT_no_unique_address` (which is going to be a non-standard extension) ? 
> @dblaikie @aprantl @Michael137

in my opinion that would be the most convenient way forward. Perhaps something 
like `DW_AT_LLVM_no_unique_address` even?

Btw what does GCC/gdb do in this case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

___
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-27 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov updated this revision to Diff 517513.
alexander-shaposhnikov added a comment.

Add more tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/Sema/Template.h
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaTemplate/concepts-friends.cpp
  clang/test/SemaTemplate/concepts-out-of-line-def.cpp
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -816,3 +816,62 @@
 static_assert(Parent::TakesBinary::i == 0);
 }
 
+namespace TemplateInsideNonTemplateClass {
+template concept C = true;
+
+template auto L = [] U>() {};
+
+struct Q {
+  template U> friend constexpr auto decltype(L)::operator()() const;
+};
+} // namespace TemplateInsideNonTemplateClass
+
+namespace GH61959 {
+template 
+concept C = (sizeof(T0) >= 4);
+
+template
+struct Orig { };
+
+template
+struct Orig {
+  template requires C
+  void f() { }
+
+  template requires true
+  void f() { }
+};
+
+template  struct Mod {};
+
+template 
+struct Mod {
+  template  requires C
+  constexpr static int f() { return 1; }
+
+  template  requires C
+  constexpr static int f() { return 2; }
+};
+
+static_assert(Mod::f() == 1);
+static_assert(Mod::f() == 2);
+
+template
+struct Outer {
+  template
+  struct Inner {};
+
+  template
+  struct Inner {
+template
+void foo()  requires C && C && C{}
+template
+void foo()  requires true{}
+  };
+};
+
+void bar() {
+  Outer::Inner I;
+  I.foo();
+}
+}
Index: clang/test/SemaTemplate/concepts-out-of-line-def.cpp
===
--- clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -127,3 +127,220 @@
 static_assert(S::specialization("str") == SPECIALIZATION_REQUIRES);
 
 } // namespace multiple_template_parameter_lists
+
+static constexpr int CONSTRAINED_METHOD_1 = 1;
+static constexpr int CONSTRAINED_METHOD_2 = 2;
+
+namespace constrained_members {
+
+template 
+struct S {
+  template 
+  static constexpr int constrained_method();
+};
+
+template <>
+template 
+constexpr int S<1>::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  template T4>
+  static constexpr int constrained_method();
+};
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained members
+
+namespace constrained_members_of_nested_types {
+
+template 
+struct S {
+  struct Inner0 {
+struct Inner1 {
+  template 
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template <>
+template 
+constexpr int S<1>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  struct Inner0 {
+struct Inner1 {
+  template T4>
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained_members_of_nested_types
+
+namespace constrained_member_sfinae {
+
+template struct S {
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N * 1073741824 + 4]) == 16) {
+return CONSTRAINED_METHOD_1;
+  }
+
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N]) == 16);
+};
+
+template<>
+template
+constexpr int S<4>::constra

[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

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



Comment at: clang/test/Sema/wasm-refs-and-tables.c:17
+static __externref_t t6[] = {0}; // expected-error {{only zero-length 
WebAssembly tables are currently supported}}
+__externref_t t7[0]; // expected-error {{WebAssembly table must be 
static}}
+static __externref_t t8[0][0];   // expected-error {{multi-dimensional arrays 
of WebAssembly references are not allowed}}

pmatos wrote:
> aaron.ballman wrote:
> > So why is `extern __externref_t r2;` allowed? Is it because it's not an 
> > array declaration?
> I am not sure I understand the question. The externref value can be declared 
> in another module and here we just define that. Array declarations of 
> externref just define tables of externref values.
Thanks, that helps explain my confusion (boy, I *really* do not like these 
types; they are quite unintuitive). What was confusing me here is that 
`__externref_t t7[0];` fails because the declaration doesn't declare a static 
identifier (yet, in C, it doesn't declare *anything at all* because it an array 
of zero elements of a sizeless type) while `extern __externref_t r2;` is fine 
despite not declaring a static identifier (yet, in C, it also doesn't declare 
*anything at all* because it's a sizeless type). I don't think there's anything 
to be done about this, the design is what it is in the WebAssembly standard, 
but all of my discomfort stems around how deeply weird this design is (and it 
shows with just how much effort we have to go to in order to restrict all the 
various ways you can use these identifiers).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139010

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


[PATCH] D149334: [RISCV] Enable strict fp for RISC-V in clang.

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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149334

Files:
  clang/lib/Basic/Targets/RISCV.h
  clang/test/CodeGen/RISCV/fpconstrained.c


Index: clang/test/CodeGen/RISCV/fpconstrained.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/fpconstrained.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple riscv64 -frounding-math 
-ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm 
-o - %s | FileCheck %s -check-prefix=FPMODELSTRICT
+// RUN: %clang_cc1 -triple riscv64 -ffp-contract=fast -emit-llvm -o - %s | 
FileCheck %s -check-prefix=PRECISE
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast -emit-llvm 
-o - %s | FileCheck %s -check-prefix=FAST
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -emit-llvm -o - %s | FileCheck 
%s -check-prefix=FASTNOCONTRACT
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast 
-ffp-exception-behavior=ignore -emit-llvm -o - %s | FileCheck %s 
-check-prefix=FAST
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast 
-ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm 
-o - %s | FileCheck %s -check-prefix=EXCEPT
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast 
-ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm 
-o - %s | FileCheck %s -check-prefix=MAYTRAP
+
+// Test strict-fp support in RISC-V.
+
+float f0, f1, f2;
+
+void foo(void) {
+  // CHECK-LABEL: define {{.*}}void @foo()
+
+  // MAYTRAP: llvm.experimental.constrained.fadd.f32(float %{{.*}}, float 
%{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.maytrap")
+  // EXCEPT: llvm.experimental.constrained.fadd.f32(float %{{.*}}, float 
%{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
+  // FPMODELSTRICT: llvm.experimental.constrained.fadd.f32(float %{{.*}}, 
float %{{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
+  // STRICTEXCEPT: llvm.experimental.constrained.fadd.f32(float %{{.*}}, float 
%{{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
+  // STRICTNOEXCEPT: llvm.experimental.constrained.fadd.f32(float %{{.*}}, 
float %{{.*}}, metadata !"round.dynamic", metadata !"fpexcept.ignore")
+  // PRECISE: fadd contract float %{{.*}}, %{{.*}}
+  // FAST: fadd fast
+  // FASTNOCONTRACT: fadd reassoc nnan ninf nsz arcp afn float
+  f0 = f1 + f2;
+
+  // CHECK: ret
+}
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -41,6 +41,7 @@
 HasRISCVVTypes = true;
 MCountName = "_mcount";
 HasFloat16 = true;
+HasStrictFP = true;
   }
 
   bool setCPU(const std::string &Name) override {


Index: clang/test/CodeGen/RISCV/fpconstrained.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/fpconstrained.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple riscv64 -frounding-math -ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s -check-prefix=FPMODELSTRICT
+// RUN: %clang_cc1 -triple riscv64 -ffp-contract=fast -emit-llvm -o - %s | FileCheck %s -check-prefix=PRECISE
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast -emit-llvm -o - %s | FileCheck %s -check-prefix=FAST
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -emit-llvm -o - %s | FileCheck %s -check-prefix=FASTNOCONTRACT
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast -ffp-exception-behavior=ignore -emit-llvm -o - %s | FileCheck %s -check-prefix=FAST
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast -ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s -check-prefix=EXCEPT
+// RUN: %clang_cc1 -triple riscv64 -ffast-math -ffp-contract=fast -ffp-exception-behavior=maytrap -fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s -check-prefix=MAYTRAP
+
+// Test strict-fp support in RISC-V.
+
+float f0, f1, f2;
+
+void foo(void) {
+  // CHECK-LABEL: define {{.*}}void @foo()
+
+  // MAYTRAP: llvm.experimental.constrained.fadd.f32(float %{{.*}}, float %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.maytrap")
+  // EXCEPT: llvm.experimental.constrained.fadd.f32(float %{{.*}}, float

[clang] a3e56a8 - [KMSAN] Enable on SystemZ

2023-04-27 Thread Ilya Leoshkevich via cfe-commits

Author: Ilya Leoshkevich
Date: 2023-04-27T13:44:54+02:00
New Revision: a3e56a8792ffaf3a3d3538736e1042b8db45ab89

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

LOG: [KMSAN] Enable on SystemZ

Enable -fsanitize=kernel-memory support in Clang.

The x86_64 ABI requires that shadow_origin_ptr_t must be returned via a
register pair, and the s390x ABI requires that it must be returned via
memory pointed to by a hidden parameter. Normally Clang takes care of
the ABI, but the sanitizers run long after it, so unfortunately they
have to duplicate the ABI logic.

Therefore add a special case for SystemZ and manually emit the
s390x-ABI-compliant calling sequences. Since it's only 2 architectures,
do not create a VarArgHelper-like abstraction layer.

The kernel functions are compiled with the "packed-stack" and
"use-soft-float" attributes. For the "packed-stack" functions, it's not
correct for copyRegSaveArea() to copy 160 bytes of shadow and origins,
since the save area is dynamically sized. Things are greatly simplified
by the fact that the vararg "use-soft-float" functions use precisely
56 bytes in order to save the argument registers to where va_arg() can
find them.

Make copyRegSaveArea() copy only 56 bytes in the "use-soft-float" case.
The "packed-stack" && !"use-soft-float" case has no practical uses at
the moment, so leave it for the future.

Add tests.

Reviewed By: eugenis

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

Added: 
llvm/test/Instrumentation/MemorySanitizer/SystemZ/basic-kernel.ll

Modified: 
clang/lib/Driver/ToolChains/Linux.cpp
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 1fbd26aed596d..5b1922970ce2b 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -795,7 +795,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64 || IsSystemZ ||
   IsLoongArch64)
 Res |= SanitizerKind::Thread;
-  if (IsX86_64)
+  if (IsX86_64 || IsSystemZ)
 Res |= SanitizerKind::KernelMemory;
   if (IsX86 || IsX86_64)
 Res |= SanitizerKind::Function;

diff  --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index 93667c9482921..e2269c2a8638d 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -122,6 +122,10 @@
 ///Arbitrary sized accesses are handled with:
 ///  __msan_metadata_ptr_for_load_n(ptr, size)
 ///  __msan_metadata_ptr_for_store_n(ptr, size);
+///Note that the sanitizer code has to deal with how shadow/origin pairs
+///returned by the these functions are represented in 
diff erent ABIs. In
+///the X86_64 ABI they are returned in RDX:RAX, and in the SystemZ ABI they
+///are written to memory pointed to by a hidden parameter.
 ///  - TLS variables are stored in a single per-task struct. A call to a
 ///function __msan_get_context_state() returning a pointer to that struct
 ///is inserted into every instrumented function before the entry block;
@@ -135,7 +139,7 @@
 /// Also, KMSAN currently ignores uninitialized memory passed into inline asm
 /// calls, making sure we're on the safe side wrt. possible false positives.
 ///
-///  KernelMemorySanitizer only supports X86_64 at the moment.
+///  KernelMemorySanitizer only supports X86_64 and SystemZ at the moment.
 ///
 //
 // FIXME: This sanitizer does not yet handle scalable vectors
@@ -543,6 +547,10 @@ class MemorySanitizer {
   void createKernelApi(Module &M, const TargetLibraryInfo &TLI);
   void createUserspaceApi(Module &M, const TargetLibraryInfo &TLI);
 
+  template 
+  FunctionCallee getOrInsertMsanMetadataFunction(Module &M, StringRef Name,
+ ArgsTy... Args);
+
   /// True if we're compiling the Linux kernel.
   bool CompileKernel;
   /// Track origins (allocation points) of uninitialized values.
@@ -550,6 +558,7 @@ class MemorySanitizer {
   bool Recover;
   bool EagerChecks;
 
+  Triple TargetTriple;
   LLVMContext *C;
   Type *IntptrTy;
   Type *OriginTy;
@@ -620,13 +629,18 @@ class MemorySanitizer {
   /// Functions for poisoning/unpoisoning local variables
   FunctionCallee MsanPoisonAllocaFn, MsanUnpoisonAllocaFn;
 
-  /// Each of the MsanMetadataPtrXxx functions returns a pair of shadow/origin
-  /// pointers.
+  /// Pair of shadow/origin pointers.
+  Type *MsanMetadata;
+
+  /// Each of the MsanMetadataPtrXxx functions returns a MsanMetadata.
   FunctionCallee Msa

[PATCH] D148596: [KMSAN] Enable on SystemZ

2023-04-27 Thread Ilya Leoshkevich 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 rGa3e56a8792ff: [KMSAN] Enable on SystemZ (authored by iii).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148596

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/test/Instrumentation/MemorySanitizer/SystemZ/basic-kernel.ll
  llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll

Index: llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll
===
--- llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll
+++ llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll
@@ -3,9 +3,60 @@
 target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"
 target triple = "s390x-unknown-linux-gnu"
 
-declare i64 @foo(i64 %guard, ...) #0
+%struct.__va_list = type { i64, i64, ptr, ptr }
+declare void @llvm.lifetime.start.p0(i64, ptr)
+declare void @llvm.va_start(ptr)
+declare void @llvm.va_end(ptr)
+declare void @llvm.lifetime.end.p0(i64, ptr)
+
+define i64 @foo(i64 %guard, ...) #1 {
+  %vl = alloca %struct.__va_list
+  call void @llvm.lifetime.start.p0(i64 32, ptr %vl)
+  call void @llvm.va_start(ptr %vl)
+  call void @llvm.va_end(ptr %vl)
+  call void @llvm.lifetime.end.p0(i64 32, ptr %vl)
+  ret i64 0
+}
 
-attributes #0 = { "target-features"="+soft-float" "use-soft-float"="true" }
+; CHECK-LABEL: define {{[^@]+}}@foo(
+
+; Callers store variadic arguments' shadow and origins into va_arg_shadow and
+; va_arg_origin. Their layout is: the register save area (160 bytes) followed
+; by the overflow arg area. It does not depend on "packed-stack".
+; Check that callees correctly backup shadow into a local variable.
+
+; CHECK: [[TMP:%.*]] = alloca { ptr, ptr }
+; CHECK: [[OverflowSize:%.*]] = load i64, ptr %va_arg_overflow_size
+; CHECK: [[MetaSize:%.*]] = add i64 160, [[OverflowSize]]
+; CHECK: [[ShadowBackup:%.*]] = alloca {{.*}} [[MetaSize]]
+; CHECK: [[MetaCopySize:%.*]] = call i64 @llvm.umin.i64(i64 [[MetaSize]], i64 800)
+; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[ShadowBackup]], ptr align 8 %va_arg_shadow, i64 [[MetaCopySize]], i1 false)
+; CHECK: [[OverflowBackup:%.*]] = alloca {{.*}} [[MetaSize]]
+; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[OverflowBackup]], ptr align 8 %va_arg_origin, i64 [[MetaCopySize]], i1 false)
+
+; Check that va_start() correctly copies the shadow backup into the shadow of
+; the va_list. Register save area and overflow arg area are copied separately.
+; Only 56 bytes of the register save area is copied, because of
+; "use-soft-float".
+
+; CHECK: call void @llvm.va_start(ptr %vl)
+; CHECK: [[VlAddr:%.*]] = ptrtoint ptr %vl to i64
+; CHECK: [[RegSaveAreaAddrAddr:%.*]] = add i64 [[VlAddr]], 24
+; CHECK: [[RegSaveAreaAddr:%.*]] = inttoptr i64 [[RegSaveAreaAddrAddr]] to ptr
+; CHECK: [[RegSaveArea:%.*]] = load ptr, ptr [[RegSaveAreaAddr]]
+; CHECK: call void @__msan_metadata_ptr_for_store_1(ptr [[TMP]], ptr [[RegSaveArea]])
+; CHECK: [[RegSaveAreaMeta:%.*]] = load { ptr, ptr }, ptr [[TMP]]
+; CHECK: [[RegSaveAreaShadow:%.*]] = extractvalue { ptr, ptr } [[RegSaveAreaMeta]], 0
+; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[RegSaveAreaShadow]], ptr align 8 [[ShadowBackup]], i64 56, i1 false)
+; CHECK: [[VlAddr:%.*]] = ptrtoint ptr %vl to i64
+; CHECK: [[OverflowAddrAddr:%.*]] = add i64 [[VlAddr]], 16
+; CHECK: [[OverflowAddr:%.*]] = inttoptr i64 [[OverflowAddrAddr]] to ptr
+; CHECK: [[Overflow:%.*]] = load ptr, ptr [[OverflowAddr]]
+; CHECK: call void @__msan_metadata_ptr_for_store_1(ptr [[TMP]], ptr [[Overflow]])
+; CHECK: [[OverflowMeta:%.*]] = load { ptr, ptr }, ptr [[TMP]]
+; CHECK: [[OverflowShadow:%.*]] = extractvalue { ptr, ptr } [[OverflowMeta]], 0
+; CHECK: [[OverflowShadowBackup:%.*]] = getelementptr i8, ptr [[ShadowBackup]], i32 160
+; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[OverflowShadow]], ptr align 8 [[OverflowShadowBackup]], i64 [[OverflowSize]], i1 false)
 
 declare i32 @random_i32()
 declare i64 @random_i64()
Index: llvm/test/Instrumentation/MemorySanitizer/SystemZ/basic-kernel.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/MemorySanitizer/SystemZ/basic-kernel.ll
@@ -0,0 +1,169 @@
+; RUN: opt < %s -S -mcpu=z13 -msan-kernel=1 -float-abi=soft -passes=msan 2>&1 | FileCheck %s
+
+target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"
+target triple = "s390x-unknown-linux-gnu"
+
+define void @Store1(ptr %p, i8 %x) sanitize_memory {
+entry:
+  store i8 %x, ptr %p
+  ret void
+}
+
+; CHECK-LABEL: define {{[^@]+}}@Store1(
+; CHECK: [[META_PTR:%[a-z0-9_]+]] = alloca { ptr, ptr }
+; CHECK: call void @__msan_metadata_ptr_for_store_1(ptr [[META_PTR]

[PATCH] D134821: [flang][driver] Allow main program to be in an archive

2023-04-27 Thread Shao-Ce SUN via Phabricator via cfe-commits
sunshaoce added a comment.

Any further suggestions?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134821

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


[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

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



Comment at: clang/test/Frontend/backend-attribute-error-warning-optimize.c:12
   foo(); // expected-error {{call to 'foo' declared with 'error' attribute: oh 
no foo}}
+ // expected-note@* {{In function 'baz'}}
   if (x())

nickdesaulniers wrote:
> cjdb wrote:
> > aaron.ballman wrote:
> > > nickdesaulniers wrote:
> > > > nickdesaulniers wrote:
> > > > > aaron.ballman wrote:
> > > > > > Instead of allowing this note to appear anywhere in the file, I 
> > > > > > think it's better to use "bookmark" comments. e.g.,
> > > > > > ```
> > > > > > void baz() { // #baz_defn
> > > > > > }
> > > > > > 
> > > > > > void foo() {
> > > > > >   baz(); // expected-note@#baz_defn {{whatever note text}}
> > > > > > }
> > > > > > ```
> > > > > > so that we're testing where the diagnostic is emitted. (This is 
> > > > > > especially important given that the changes are about location 
> > > > > > tracking.)
> > > > > oh, that's new (to me)! will do
> > > > It looks like the "bookmarks" don't work because the notes do not 
> > > > line+col info. They follow the warning/error diagnostic which does, on 
> > > > the bottom most call site.
> > > > 
> > > > The warning is supposed to be emitted on the callsite, not the 
> > > > definition.
> > > I still don't think this is reasonable for test coverage because this 
> > > means we'll accept the note *anywhere* in the file. This makes it much 
> > > too easy to regress the behavior accidentally (e.g., accidentally emit 
> > > all the notes on line 1 of the file). I think we need *some* way to nail 
> > > down where these notes are emitted in the test. However, I might be 
> > > asking you to solve "please track location information through the 
> > > backend" for that, so perhaps this isn't a reasonable request?
> > > 
> > > Also, CC @cjdb for awareness of how this kind of diagnostic is produced 
> > > (Chris is working on an idea for how we emit diagnostics so we get better 
> > > structured information from them, so knowing about this novel approach 
> > > might impact that idea).
> > Very interesting, thanks for the heads up! Cross-phase diagnostics are 
> > definitely something I hadn't considered, and it **does** impact the design 
> > (but not in a derailing way).
> I think we're back at "please track location information through the backend".
> 
> That is the tradeoff with this approach; not measurably regressing 
> performance when these attributes aren't used in source in exchange for Note 
> diagnostics that lack precise line+col info, but in practice provide enough 
> info for the user to understand what's going wrong where.
> 
> Your call if the tradeoff is worth it.
Here's my thinking, please correct any misunderstandings I have:

* This functionality is primarily for use with `_FORTIFY_SOURCE` (but not 
solely for that purpose), and that's an important security feature used by 
glibc and the Linux kernel.
* Security of C and C++ source code is Very Important, especially now that 
various gov't agencies [1][2] are suggesting to not use C or C++ for new 
projects specifically because the security posture of the languages and their 
tools.
* Therefore, the ergonomics of this functionality are quite important for the 
intended use cases and the ecosystem as a whole.
* Emitting only the function name but without location information does not 
give a good user experience, especially in circumstances where the function has 
multiple overloads, because it pushes the burden onto the programmer to figure 
out which functions are actually involved in the call chain. This issue is also 
present in C because of support for `__attribute__((overloadable))` and is not 
just a C++ concern.
* The compile-time performance costs of tracking this location information are 
roughly 1%, and there are no runtime or binary size overhead costs unless other 
functionality is enabled (such as emitting debug info).
* We can determine whether we need to enable this location tracking while 
building the AST when we see one of these two attributes being used, so we 
could enable this functionality selectively without burdening the user with 
enabling it manually via a flag. (We could still consider giving the user a 
flag to never track this even in the presence of the attributes if a user had a 
compelling use case for it.)

If this is all reasonably accurate, I think it's worth seriously considering 
accepting the costs. I don't want to increase our compile time overhead, but at 
the same time, if ~1% is a "make or break" amount of compile-time performance 
to lose, we should be addressing *that* issue rather than hamstringing a 
user-facing diagnostic feature related to security. It's hard to argue "that 
CVE was totally worth it because we could then compile 1% faster". That said, 
perhaps others have a strong contrary opinion they'd like to argue in favor of?

[1] 
https://media.defense.gov/2022/Nov/10/2003112742/-1/-1

[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos marked 2 inline comments as done.
pmatos added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsWebAssembly.def:205-210
+TARGET_BUILTIN(__builtin_wasm_table_set,  "viii", "t", "reference-types")
+TARGET_BUILTIN(__builtin_wasm_table_get,  "iii", "t", "reference-types")
+TARGET_BUILTIN(__builtin_wasm_table_size, "ii", "nt", "reference-types")
+TARGET_BUILTIN(__builtin_wasm_table_grow, "", "nt", "reference-types")
+TARGET_BUILTIN(__builtin_wasm_table_fill, "v", "t", "reference-types")
+TARGET_BUILTIN(__builtin_wasm_table_copy, "vi", "t", "reference-types")

aaron.ballman wrote:
> All of these should be documented in `docs/LanguageExtensions.rst` (you can 
> make a Web Assembly section if one doesn't already exist; we've historically 
> been bad about documenting our builtins).
Working on this - thanks for the reminder.



Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:6-7
+
+// Using c++11 to test dynamic exception specifications (which are not 
+// allowed in c++17).
+

aaron.ballman wrote:
> Much of this file is the same test coverage as in the C case; I'd recommend 
> combining the .c and .cpp files into one test with two RUN lines, and use 
> `-verify=whatever` to distinguish between C vs C++ vs both diagnostic 
> behaviors. The C++ specific code can then be split into a much smaller 
> .cpp-specific file.
I have don't this know. I was not aware we could pass an argument to verify - 
thanks.



Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:14
+
+__externref_t *t1;   // expected-error {{pointer to WebAssembly 
reference type is not allowed}}
+__externref_t **t2;  // expected-error {{pointer to WebAssembly 
reference type is not allowed}}

aaron.ballman wrote:
> Anywhere you'd testing pointer behavior for C++, you should have a test with 
> an lvalue reference as well. I presume those will behave the same as 
> pointers? It'd probably be wise to have tests for rvalue references as well.
Here I guess you're talking about testing __externref_t &. However, this might 
be outside the scope of the patch which deals only with tables.

I could add further lvalue and rvalue reference tests to externref and funcref 
in another patch. What do you think?



Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:16-17
+__externref_t **t2;  // expected-error {{pointer to WebAssembly 
reference type is not allowed}}
+__externref_t **t3;  // expected-error {{pointer to WebAssembly 
reference type is not allowed}}
+static __externref_t t4[3];  // expected-error {{only zero-length 
WebAssembly tables are currently supported}}
+static __externref_t t5[];   // expected-error {{only zero-length 
WebAssembly tables are currently supported}}

aaron.ballman wrote:
> pmatos wrote:
> > aaron.ballman wrote:
> > > This seems really... confused. We can't form a pointer to the type, but 
> > > we can form an array of the type (which decays into a pointer when you 
> > > sneeze near it, and it's not clear whether that should be allowed or not) 
> > > so long as it's a zero-length array (which is an extension in C and C++, 
> > > so do we need to silence pedantic warnings in WASM for this?).
> > As it stands, tables are declared as static arrays of size zero. Then to 
> > access them we need to use builtins. No subscripting, no comparison, no 
> > pointer decay, etc. No passing into functions, returning from functions, 
> > etc. Nothing besides using them as arguments to wasm_table... builtins.
> Okay, that's less confused now, thank you! What should the `-pedantic` 
> behavior be for this:
> ```
> static __externref_t table[0];
> ```
> I presume you don't want the usual "zero size arrays are an extension" 
> warning?
I have fixed this but unsure how to best merge it with the remainder of the 
tests, so created a new test file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139010

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


[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 517521.
pmatos marked 2 inline comments as done.
pmatos added a comment.

Update a few more tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139010

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Type.cpp
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/builtins-table.c
  clang/test/Sema/builtins-wasm.c
  clang/test/Sema/wasm-refs-and-table-ped.c
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/Sema/wasm-refs.c
  clang/test/SemaCXX/wasm-refs-and-tables.cpp
  clang/test/SemaCXX/wasm-refs.cpp
  llvm/include/llvm/CodeGen/WasmAddressSpaces.h
  llvm/include/llvm/IR/Type.h
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
@@ -62,8 +62,9 @@
   for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
 PtrToIntInst *PTI = dyn_cast(&*I);
 IntToPtrInst *ITP = dyn_cast(&*I);
-if (!(PTI && WebAssembly::isRefType(PTI->getPointerOperand()->getType())) &&
-!(ITP && WebAssembly::isRefType(ITP->getDestTy(
+if (!(PTI &&
+  PTI->getPointerOperand()->getType()->isWebAssemblyReferenceType()) &&
+!(ITP && ITP->getDestTy()->isWebAssemblyReferenceType()))
   continue;
 
 UndefValue *U = UndefValue::get(I->getType());
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -1203,7 +1203,7 @@
   // Lastly, if this is a call to a funcref we need to add an instruction
   // table.set to the chain and transform the call.
   if (CLI.CB &&
-  WebAssembly::isFuncrefType(CLI.CB->getCalledOperand()->getType())) {
+  CLI.CB->getCalledOperand()->getType()->isWebAssemblyFuncrefType()) {
 // In the absence of function references proposal where a funcref call is
 // lowered to call_ref, using reference types we generate a table.set to set
 // the funcref to a special table used solely for this purpose, followed by
Index: llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
===
--- llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -27,43 +27,6 @@
 
 namespace WebAssembly {
 
-enum WasmAddressSpace : unsigned {
-  // Default address space, for pointers to linear memory (stack, heap, data).
-  WASM_ADDRESS_SPACE_DEFAULT = 0,
-  // A non-integral address space for pointers to named objects outside of
-  // linear memory: WebAssembly globals or WebAssembly locals.  Loads and stores
-  // to these pointers are lowered to global.get / global.set or local.get /
-  // local.set, as appropriate.
-  WASM_ADDRESS_SPACE_VAR = 1,
-  // A non-integral address space for externref values
-  WASM_ADDRESS_SPACE_EXTERNREF = 10,
-  // A non-integral address space for funcref values
-  WASM_ADDRESS_SPACE_FUNCREF = 20,
-};
-
-inline bool isDefaultAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_DEFAULT;
-}
-inline bool isWasmVarAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_VAR;
-}
-inline bool isValidAddressSpace(unsigned AS) {
-  return isDefaultAddressSpace(AS) || isWasmVarAddressSpace(AS);
-}
-inline bool isFuncrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
-}
-inline bool isExternrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
-}
-inline bool isRefType(const Type *Ty) {
-  return isFuncrefType(Ty) || isExternrefType(Ty);
-}
-
 // Convert StringRef to ValType / HealType / BlockType
 
 MVT parseMVT(StringRef Type

[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos marked an inline comment as done.
pmatos added inline comments.



Comment at: clang/test/Sema/wasm-refs-and-tables.c:17
+static __externref_t t6[] = {0}; // expected-error {{only zero-length 
WebAssembly tables are currently supported}}
+__externref_t t7[0]; // expected-error {{WebAssembly table must be 
static}}
+static __externref_t t8[0][0];   // expected-error {{multi-dimensional arrays 
of WebAssembly references are not allowed}}

aaron.ballman wrote:
> pmatos wrote:
> > aaron.ballman wrote:
> > > So why is `extern __externref_t r2;` allowed? Is it because it's not an 
> > > array declaration?
> > I am not sure I understand the question. The externref value can be 
> > declared in another module and here we just define that. Array declarations 
> > of externref just define tables of externref values.
> Thanks, that helps explain my confusion (boy, I *really* do not like these 
> types; they are quite unintuitive). What was confusing me here is that 
> `__externref_t t7[0];` fails because the declaration doesn't declare a static 
> identifier (yet, in C, it doesn't declare *anything at all* because it an 
> array of zero elements of a sizeless type) while `extern __externref_t r2;` 
> is fine despite not declaring a static identifier (yet, in C, it also doesn't 
> declare *anything at all* because it's a sizeless type). I don't think 
> there's anything to be done about this, the design is what it is in the 
> WebAssembly standard, but all of my discomfort stems around how deeply weird 
> this design is (and it shows with just how much effort we have to go to in 
> order to restrict all the various ways you can use these identifiers).
Yes, I understand. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139010

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


[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 517525.
pmatos marked an inline comment as done.
pmatos added a comment.

Quick fixup of test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139010

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Type.cpp
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/builtins-table.c
  clang/test/Sema/builtins-wasm.c
  clang/test/Sema/wasm-refs-and-table-ped.c
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/Sema/wasm-refs.c
  clang/test/SemaCXX/wasm-refs-and-tables.cpp
  clang/test/SemaCXX/wasm-refs.cpp
  llvm/include/llvm/CodeGen/WasmAddressSpaces.h
  llvm/include/llvm/IR/Type.h
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
@@ -62,8 +62,9 @@
   for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
 PtrToIntInst *PTI = dyn_cast(&*I);
 IntToPtrInst *ITP = dyn_cast(&*I);
-if (!(PTI && WebAssembly::isRefType(PTI->getPointerOperand()->getType())) &&
-!(ITP && WebAssembly::isRefType(ITP->getDestTy(
+if (!(PTI &&
+  PTI->getPointerOperand()->getType()->isWebAssemblyReferenceType()) &&
+!(ITP && ITP->getDestTy()->isWebAssemblyReferenceType()))
   continue;
 
 UndefValue *U = UndefValue::get(I->getType());
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -1203,7 +1203,7 @@
   // Lastly, if this is a call to a funcref we need to add an instruction
   // table.set to the chain and transform the call.
   if (CLI.CB &&
-  WebAssembly::isFuncrefType(CLI.CB->getCalledOperand()->getType())) {
+  CLI.CB->getCalledOperand()->getType()->isWebAssemblyFuncrefType()) {
 // In the absence of function references proposal where a funcref call is
 // lowered to call_ref, using reference types we generate a table.set to set
 // the funcref to a special table used solely for this purpose, followed by
Index: llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
===
--- llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -27,43 +27,6 @@
 
 namespace WebAssembly {
 
-enum WasmAddressSpace : unsigned {
-  // Default address space, for pointers to linear memory (stack, heap, data).
-  WASM_ADDRESS_SPACE_DEFAULT = 0,
-  // A non-integral address space for pointers to named objects outside of
-  // linear memory: WebAssembly globals or WebAssembly locals.  Loads and stores
-  // to these pointers are lowered to global.get / global.set or local.get /
-  // local.set, as appropriate.
-  WASM_ADDRESS_SPACE_VAR = 1,
-  // A non-integral address space for externref values
-  WASM_ADDRESS_SPACE_EXTERNREF = 10,
-  // A non-integral address space for funcref values
-  WASM_ADDRESS_SPACE_FUNCREF = 20,
-};
-
-inline bool isDefaultAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_DEFAULT;
-}
-inline bool isWasmVarAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_VAR;
-}
-inline bool isValidAddressSpace(unsigned AS) {
-  return isDefaultAddressSpace(AS) || isWasmVarAddressSpace(AS);
-}
-inline bool isFuncrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
-}
-inline bool isExternrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
-}
-inline bool isRefType(const Type *Ty) {
-  return isFuncrefType(Ty) || isExternrefType(Ty);
-}
-
 // Convert StringRef to ValType / HealType / BlockType
 
 MVT parseMVT(StringRef Type);
I

[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added inline comments.



Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:35
+task<__externref_t[]> g() {
+  co_return table;
+}

@aaron.ballman I tried and failed to create a good testcase for co_return. 
However creating coroutines seems to be an stdlib thing which I am not sure how 
to test here. Do you have any suggestions here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139010

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


[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

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



Comment at: clang/lib/Parse/ParseTentative.cpp:1067
+bool mayHaveDirectInit,
+bool mayHaveTrailingReturnType) {
   // declarator:

tbaeder wrote:
> Not part of this commit I guess, but //four// bool parameters is truly 
> horrific :/
Yeah, a refactoring here would not be amiss (but outside of this patch, I 
think).



Comment at: clang/lib/Parse/ParseTentative.cpp:1416-1417
+  case tok::kw_auto: {
+if (NextToken().is(tok::l_brace))
+  return TPResult::False;
+if (NextToken().is(tok::l_paren)) {

aaron.ballman wrote:
> This seems incorrect to me, consider:
> ```
> auto [[clang::annotate_type("test")]] i = 12;
> ```
> https://godbolt.org/z/7Gx3Gb18h
Ignore this -- `l_brace` is not `l_square`. :-D



Comment at: clang/test/Parser/cxx1z-decomposition.cpp:97
 decltype(auto) [b] = s; // expected-error {{cannot be declared with type 
'decltype(auto)'}}
-auto ([c]) = s; // expected-error {{cannot be declared with parentheses}}
+auto ([c]) = s; // expected-error {{'auto' not allowed here}} \
+// expected-error {{use of undeclared identifier 'c'}} \

cor3ntin wrote:
> aaron.ballman wrote:
> > This first diagnostic is incorrect -- `auto` is definitely allowed there, 
> > just that the rest of the declaration is nonsense. I think the "use of 
> > undeclared identifier" diagnostic is reasonable. The lambda diagnostic 
> > is interesting.
> > 
> > Any way you can improve this, or is that a slog?
> There were multiple issues there.
> 
> The "decomposition declaration cannot be declared with parenthese" error 
> which i had remove can still occur at global scope where a declaration is 
> expected so i put that back and added a test.
> Then, I'm running all the tests in c++17 and 23 modes as the behavior is 
> different.
> 
> I did restore the current behavior in C++20 and earlier modes, such that we 
> will always consider `auto` starts a declaration. That way we can have that 
> structured binding in parentheses diag.
> 
> But in c++23 mode,  We establish it's not a valid declarator. so we parse it 
> as an expression. `[` is always considered as a lambda introducer, which it 
> could be, ie `auto([c] {});` is a valid expression assuming that C exists.
> At that point trying to figure out that `]` is not followed by `{` and is 
> therefore not a lambda seems extremely tricky as you can have arbitrary long 
> expressions between the square brackets.
> 
Thanks for the explanation -- that seems defensible to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

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


[PATCH] D149206: [clang][driver] Enable MisExpect diagnostics flag outside of CC1

2023-04-27 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149206

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


[PATCH] D134821: [flang][driver] Allow main program to be in an archive

2023-04-27 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski accepted this revision.
awarzynski added a comment.

In D134821#4301701 , @sunshaoce wrote:

> Any further suggestions?

I am happy for you to land this, thanks! LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134821

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


cfe-commits@lists.llvm.org

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

Basically looking good to me now, but the changes need a release note and I 
does this mean we can change cxx_status.html to claim full support for P2002R1 
now or is there more left to be done for that? (If there's more left to do, 
adding those details to the cxx_status page would be appropriate.)




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:9436
+def err_ref_qualifier_comparison_operator : Error<
+  "ref-qualifier '&&' is not allowed on defaulted comparison operators">;
 

ilya-biryukov wrote:
> NIT: for consistency with the wording of `err_ref_qualifier_constructor`
Still need to drop the `s` from `operators`



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8593-8601
+const FunctionProtoType *FnType = 
FD->getType()->castAs();
+if (FnType->isVolatile()) {
+  Diag(FD->getLocation(), diag::err_volatile_comparison_operator);
+  return true;
+}
+if (FnType->getRefQualifier() == RQ_RValue) {
+  Diag(FD->getLocation(), diag::err_ref_qualifier_comparison_operator);

massberg wrote:
> massberg wrote:
> > aaron.ballman wrote:
> > > aaron.ballman wrote:
> > > > ilya-biryukov wrote:
> > > > > NIT: this version is simpler and more aligned with the code below.
> > > > > Also, could you move the `volatile` handling after the check for 
> > > > > `const`?
> > > > > 
> > > > > 
> > > > > Additionally, we seem to recover in case of `const` by adding it to 
> > > > > the type and suggesting a fix-it to add it in the code.
> > > > > Could we do the same for `volatile` and `ref-qualifier`, i.e. suggest 
> > > > > a fix-it to remove the `ref-qualifier` and `volatile` and change the 
> > > > > corresponding type to make AST pretend they were never there?
> > > > 
> > > Note, you can shorten it further with:
> > > ```
> > > return Diag(...);
> > > ```
> > > because that will return true for you.
> > Thanks! Which the change suggested by Ilya this has become obsolete.
> Thanks, this is much simpler!
> 
> I have moved the code and added a recovery. However, adding a fix-it is much 
> more complex as there is no simple way to get location to remove the 
> keywords. Thus I decided to not offering a fix-it in this patch.
Yeah, it seems we don't track the ref qualifier location on any of the 
`CXXMethodDecl`, `FunctionProtoType`, or `FunctionProtoTypeLoc` classes. A 
future refactoring can consider adding locations for those to 
`FunctionProtoTypeLoc`, but needs to be able to handle multiple qualifiers 
(e.g., `void func() const &;` should track both the `const` and the `&` 
separately).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148924

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


[clang-tools-extra] 6cfcf02 - [clangd] Fix the include-cleaner-batch-fix.test failure on some

2023-04-27 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-04-27T14:59:37+02:00
New Revision: 6cfcf0242f3260a3a90bac68e9f271548caa8372

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

LOG: [clangd] Fix the include-cleaner-batch-fix.test failure on some
platforms

It seems that on some platforms, the spelling include doesn't work. Make
the test less strict on it.

Added: 


Modified: 
clang-tools-extra/clangd/test/include-cleaner-batch-fix.test

Removed: 




diff  --git a/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test 
b/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
index b07da2a9b4df8..4b2208ba3e146 100644
--- a/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
+++ b/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
@@ -123,7 +123,7 @@
 # CHECK-NEXT:{
 # CHECK-NEXT:  "edits": [
 # CHECK-NEXT:{
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}foo.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -145,7 +145,7 @@
 # CHECK-NEXT:}
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  "command": "clangd.applyFix",
-# CHECK-NEXT:  "title": "Apply fix: #include "
+# CHECK-NEXT:  "title": "Apply fix: #include {{.*}}foo.h{{.*}}"
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "arguments": [
@@ -165,7 +165,7 @@
 # CHECK-NEXT:  "edits": [
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes0",
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}bar.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -179,7 +179,7 @@
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes1",
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}foo.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -257,7 +257,7 @@
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes0",
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}bar.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -271,7 +271,7 @@
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes1",
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}foo.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -442,7 +442,7 @@
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes0",
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}bar.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,
@@ -456,7 +456,7 @@
 # CHECK-NEXT:},
 # CHECK-NEXT:{
 # CHECK-NEXT:  "annotationId": "AddAllMissingIncludes1",
-# CHECK-NEXT:  "newText": "#include \n",
+# CHECK-NEXT:  "newText": "#include {{.*}}foo.h{{.*}}",
 # CHECK-NEXT:  "range": {
 # CHECK-NEXT:"end": {
 # CHECK-NEXT:  "character": 0,



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


[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 517535.
pmatos added a comment.

Add documentation for table builtins.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139010

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Type.cpp
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/builtins-table.c
  clang/test/Sema/builtins-wasm.c
  clang/test/Sema/wasm-refs-and-table-ped.c
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/Sema/wasm-refs.c
  clang/test/SemaCXX/wasm-refs-and-tables.cpp
  clang/test/SemaCXX/wasm-refs.cpp
  llvm/include/llvm/CodeGen/WasmAddressSpaces.h
  llvm/include/llvm/IR/Type.h
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
@@ -62,8 +62,9 @@
   for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
 PtrToIntInst *PTI = dyn_cast(&*I);
 IntToPtrInst *ITP = dyn_cast(&*I);
-if (!(PTI && WebAssembly::isRefType(PTI->getPointerOperand()->getType())) &&
-!(ITP && WebAssembly::isRefType(ITP->getDestTy(
+if (!(PTI &&
+  PTI->getPointerOperand()->getType()->isWebAssemblyReferenceType()) &&
+!(ITP && ITP->getDestTy()->isWebAssemblyReferenceType()))
   continue;
 
 UndefValue *U = UndefValue::get(I->getType());
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -1203,7 +1203,7 @@
   // Lastly, if this is a call to a funcref we need to add an instruction
   // table.set to the chain and transform the call.
   if (CLI.CB &&
-  WebAssembly::isFuncrefType(CLI.CB->getCalledOperand()->getType())) {
+  CLI.CB->getCalledOperand()->getType()->isWebAssemblyFuncrefType()) {
 // In the absence of function references proposal where a funcref call is
 // lowered to call_ref, using reference types we generate a table.set to set
 // the funcref to a special table used solely for this purpose, followed by
Index: llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
===
--- llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -27,43 +27,6 @@
 
 namespace WebAssembly {
 
-enum WasmAddressSpace : unsigned {
-  // Default address space, for pointers to linear memory (stack, heap, data).
-  WASM_ADDRESS_SPACE_DEFAULT = 0,
-  // A non-integral address space for pointers to named objects outside of
-  // linear memory: WebAssembly globals or WebAssembly locals.  Loads and stores
-  // to these pointers are lowered to global.get / global.set or local.get /
-  // local.set, as appropriate.
-  WASM_ADDRESS_SPACE_VAR = 1,
-  // A non-integral address space for externref values
-  WASM_ADDRESS_SPACE_EXTERNREF = 10,
-  // A non-integral address space for funcref values
-  WASM_ADDRESS_SPACE_FUNCREF = 20,
-};
-
-inline bool isDefaultAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_DEFAULT;
-}
-inline bool isWasmVarAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_VAR;
-}
-inline bool isValidAddressSpace(unsigned AS) {
-  return isDefaultAddressSpace(AS) || isWasmVarAddressSpace(AS);
-}
-inline bool isFuncrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
-}
-inline bool isExternrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
-}
-inline bool isRefType(const Type *Ty) {
-  return isFuncrefType(Ty) || isExternrefType(Ty);
-}
-
 // Convert StringRef to ValType / HealType / BlockType
 
 MVT parseMVT(StringRef Type);
Index: llvm/lib/Target/We

[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-04-27 Thread Paulo Matos via Phabricator via cfe-commits
pmatos marked an inline comment as done.
pmatos added a comment.

I think we are almost there. @aaron.ballman what do you think?




Comment at: clang/test/Sema/wasm-refs-and-tables.c:81
+
+  funcref_t func = __builtin_wasm_ref_null_func(0); // expected-error {{too 
many arguments to function call, expected 0, have 1}}
+

aaron.ballman wrote:
> Shouldn't this be in builtins-wasm.c instead?
Moved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139010

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


[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-27 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 517536.
cor3ntin added a comment.

Fix tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/cxx1z-decomposition.cpp
  clang/test/Parser/cxx2b-auto-x.cpp

Index: clang/test/Parser/cxx2b-auto-x.cpp
===
--- clang/test/Parser/cxx2b-auto-x.cpp
+++ clang/test/Parser/cxx2b-auto-x.cpp
@@ -18,7 +18,37 @@
 
 using T = looks_like_declaration *;
 void f() { T(&a)->n = 1; }
-// FIXME: They should be deemed expressions without breaking function pointer
-//parameter declarations with trailing return types.
-// void g() { auto(&a)->n = 0; }
-// void h() { auto{&a}->n = 0; }
+void g() { auto(&a)->n = 0; } // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{declaration of variable 'a' with deduced type 'auto (&)' requires an initializer}} \
+  // cxx20-error {{expected ';' at end of declaration}}
+void h() { auto{&a}->n = 0; } // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{expected unqualified-id}} \
+  // cxx20-error {{expected expression}}
+
+void e(auto (*p)(int y) -> decltype(y)) {}
+
+struct M;
+struct S{
+S operator()();
+S* operator->();
+int N;
+int M;
+} s; // expected-note {{here}}
+
+void test() {
+auto(s)()->N; // cxx2b-warning {{expression result unused}} \
+  // cxx2b-warning {{before C++2b}} \
+  // cxx20-error {{unknown type name 'N'}}
+auto(s)()->M; // expected-error {{redefinition of 's' as different kind of symbol}}
+}
+
+void test_paren() {
+int a = (auto(0)); // cxx2b-warning {{before C++2b}} \
+   // cxx20-error {{expected expression}} \
+   // cxx20-error {{expected ')'}} \
+   // cxx20-note  {{to match this '('}}
+int b = (auto{0}); // cxx2b-warning {{before C++2b}} \
+   // cxx20-error {{expected expression}} \
+   // cxx20-error {{expected ')'}} \
+   // cxx20-note  {{to match this '('}}
+}
Index: clang/test/Parser/cxx1z-decomposition.cpp
===
--- clang/test/Parser/cxx1z-decomposition.cpp
+++ clang/test/Parser/cxx1z-decomposition.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -std=c++17 %s -verify -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++17 %s -verify=expected,cxx17 -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++2b %s -verify=expected,cxx2b -fcxx-exceptions
 // RUN: not %clang_cc1 -std=c++17 %s -emit-llvm-only -fcxx-exceptions
 
 struct S { int a, b, c; };
@@ -30,7 +31,7 @@
 namespace OtherDecl {
   // A parameter-declaration is not a simple-declaration.
   // This parses as an array declaration.
-  void f(auto [a, b, c]); // expected-error {{'auto' not allowed in function prototype}} expected-error {{'a'}}
+  void f(auto [a, b, c]); // cxx17-error {{'auto' not allowed in function prototype}} expected-error {{'a'}}
 
   void g() {
 // A condition is allowed as a Clang extension.
@@ -57,7 +58,7 @@
 namespace GoodSpecifiers {
   void f() {
 int n[1];
-const volatile auto &[a] = n;
+const volatile auto &[a] = n; // cxx2b-warning {{volatile qualifier in structured binding declaration is deprecated}}
   }
 }
 
@@ -67,8 +68,8 @@
   struct S { int n; } s;
   void f() {
 // storage-class-specifiers
-static auto &[a] = n; // expected-warning {{declared 'static' is a C++20 extension}}
-thread_local auto &[b] = n; // expected-warning {{declared 'thread_local' is a C++20 extension}}
+static auto &[a] = n; // cxx17-warning {{declared 'static' is a C++20 extension}}
+thread_local auto &[b] = n; // cxx17-warning {{declared 'thread_local' is a C++20 extension}}
 extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
 struct S {
   mutable auto &[d] = n; // expected-error {{not permitted in this context}}
@@ -85,16 +86,19 @@
   }
 
   static constexpr inline thread_local auto &[j1] = n; // expected-error {{cannot be declared with 'constexpr inline' specifiers}}
-  static thread_local auto &[j2] = n; // expected-warning {{declared with 'static thread_local' specifiers is a C++20 extension}}
+  static thread_local auto &[j2] = n; // cxx17-warning {{declared with 'static thread_local' specifiers is a C++20 extension}}
 
   inline auto &[k] = n; // expected-error {{cannot be declared 'inline'}}
 
   const int K = 5;
+  auto ([c]) = s; // expected-error {{decomposition declaration cannot be declared with parent

[PATCH] D149264: GH62362: Handle constraints on "Using" inherited constructors

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

Confirmed this is all fixed by your patch.  Thanks!




Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:138-144
+bool SkipForSpecialization,
+bool ForConstraintInstantiation) {
   if (!ClassTemplSpec->isClassScopeExplicitSpecialization()) {
 // We're done when we hit an explicit specialization.
 if (ClassTemplSpec->getSpecializationKind() == TSK_ExplicitSpecialization 
&&
-!isa(ClassTemplSpec))
+!isa(ClassTemplSpec) &&
+!ForConstraintInstantiation)

rsmith wrote:
> rsmith wrote:
> > It seems to me that a namespace-scope explicit specialization shouldn't 
> > pick up template arguments, even during constraint checking:
> > 
> > ```
> > template struct A {};
> > template<> struct A {
> >   template void f() requires U::value;
> > };
> > ```
> > Constraint checking for `A::f` should produce a single level of 
> > template arguments, ``, not two layers `, `, because `U` in 
> > `U::value` is a depth-0 index-0 parameter.
> Complete testcase:
> ```
> struct X {}; struct Y { static constexpr bool value = true; };
> template struct A {};
> template<> struct A {  
>   template void f() requires U::value;
> };   
> void g(A a) { a.f(); }
> ```
Ah! Thanks for the reproducer.  I was having a really hard time determining a 
case where this would break, everything I came up with was blocked by 
https://reviews.llvm.org/D146178

The difficulty was that the parent of the inherited constructor was an inline 
definition of the explicit specialization, so it DID have depth, but it wasn't 
clear how to differentiate the two. I think your patch as listed fixes all the 
issues I was trying to fix as you said, so I'll abandon this, though I'll 
include the tests as an NFC/RAC patch for completeness.




Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:217-219
+  if (Ctor->isImplicit() && Ctor->isInheritingConstructor() &&
+  Ctor->getInheritedConstructor().getConstructor())
+Ctor = Ctor->getInheritedConstructor().getConstructor();

rsmith wrote:
> These checks can be simplified.
Ah, thanks!  I must have been looking at the wrong thing, I wasn't convinced 
that the `getInheritedConstructor` call was always legal, but looking again, I 
see that should have been obvious.  


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

https://reviews.llvm.org/D149264

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


[clang] f539b6f - [NFC] Add tests from my fix for GH62362.

2023-04-27 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2023-04-27T06:33:34-07:00
New Revision: f539b6ffc25144703498176558035c499825dc48

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

LOG: [NFC] Add tests from my fix for GH62362.

This ended up being fixed separately by @rsmith in 1e43349e3 in a
better/correct way. This patch adds the tests from the original, as
though they are reasonably covered in his patch, explicit versions seem
to have value here.

Additionally, this adds a release note for 1e43349e3.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/test/SemaTemplate/concepts-inherited-ctor.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f473f97f6c74..26fdffe920e9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -327,6 +327,10 @@ Bug Fixes in This Version
   (`#62122 `_)
 - Fix crash when handling undefined template partial specialization
   (`#61356 `_)
+- Fix a crash caused by incorrectly evaluating constraints on an inheriting
+  constructor declaration.
+  (`#62361 `_)
+  (`#62362 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/test/SemaTemplate/concepts-inherited-ctor.cpp 
b/clang/test/SemaTemplate/concepts-inherited-ctor.cpp
index f50a6aebeeab..d6f3546b25fb 100644
--- a/clang/test/SemaTemplate/concepts-inherited-ctor.cpp
+++ b/clang/test/SemaTemplate/concepts-inherited-ctor.cpp
@@ -68,3 +68,25 @@ namespace no_early_substitution {
 C();
   }
 }
+
+namespace GH62362 {
+  template
+concept C = true;
+  template  struct Test {
+Test()
+  requires(C);
+  };
+  struct Bar : public Test {
+using Test::Test;
+  };
+  template <>
+struct Test : public Test {
+  using Test::Test;
+};
+
+  void foo() {
+Bar();
+Test();
+  }
+}
+}



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


[PATCH] D149264: GH62362: Handle constraints on "Using" inherited constructors

2023-04-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane abandoned this revision.
erichkeane added a comment.

Fixed by Richard!  Tests and release note added in f539bffc


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

https://reviews.llvm.org/D149264

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


[PATCH] D149210: [IR] Change shufflevector undef mask to poison

2023-04-27 Thread Manuel Brito 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 rG8b56da5e9f3b: [IR] Change shufflevector undef mask to poison 
(authored by ManuelJBrito).

Changed prior to commit:
  https://reviews.llvm.org/D149210?vs=517150&id=517542#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149210

Files:
  clang/test/CodeGen/PowerPC/builtins-ppc-p10vector.c
  clang/test/CodeGen/PowerPC/builtins-ppc-p9vector.c
  clang/test/CodeGen/builtins-nondeterministic-value.c
  clang/test/CodeGen/builtinshufflevector2.c
  clang/test/CodeGen/ext-vector.c
  clang/test/CodeGenOpenCL/as_type.cl
  clang/test/CodeGenOpenCL/partial_initializer.cl
  clang/test/CodeGenOpenCL/preserve_vec3.cl
  clang/test/CodeGenOpenCL/vector_literals.cl
  clang/test/CodeGenOpenCL/vector_shufflevector.cl
  llvm/lib/IR/AsmWriter.cpp
  llvm/test/Analysis/CostModel/RISCV/shuffle-extract_subvector.ll
  llvm/test/Analysis/CostModel/RISCV/shuffle-insert_subvector.ll
  llvm/test/Analysis/CostModel/X86/reduction.ll
  llvm/test/Analysis/CostModel/X86/shuffle-extract_subvector-codesize.ll
  llvm/test/Analysis/CostModel/X86/shuffle-extract_subvector-latency.ll
  llvm/test/Analysis/CostModel/X86/shuffle-extract_subvector-sizelatency.ll
  llvm/test/Analysis/CostModel/X86/shuffle-extract_subvector.ll
  llvm/test/Analysis/CostModel/X86/shuffle-insert_subvector-codesize.ll
  llvm/test/Analysis/CostModel/X86/shuffle-insert_subvector-latency.ll
  llvm/test/Analysis/CostModel/X86/shuffle-insert_subvector-sizelatency.ll
  llvm/test/Analysis/CostModel/X86/shuffle-insert_subvector.ll
  llvm/test/Analysis/CostModel/X86/shuffle-single-src-codesize.ll
  llvm/test/Analysis/CostModel/X86/shuffle-single-src-latency.ll
  llvm/test/Analysis/CostModel/X86/shuffle-single-src-sizelatency.ll
  llvm/test/Analysis/CostModel/X86/shuffle-single-src.ll
  llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-break-large-phis-heuristics.ll
  llvm/test/CodeGen/AMDGPU/rewrite-out-arguments.ll
  llvm/test/CodeGen/Generic/expand-experimental-reductions.ll
  llvm/test/CodeGen/PowerPC/arg_promotion.ll
  llvm/test/Instrumentation/MemorySanitizer/avx-intrinsics-x86.ll
  llvm/test/Transforms/Attributor/nofpclass.ll
  llvm/test/Transforms/CodeGenPrepare/X86/x86-shuffle-sink-inseltpoison.ll
  llvm/test/Transforms/CodeGenPrepare/X86/x86-shuffle-sink.ll
  llvm/test/Transforms/DeadStoreElimination/masked-dead-store-inseltpoison.ll
  llvm/test/Transforms/DeadStoreElimination/masked-dead-store.ll
  llvm/test/Transforms/InstCombine/AArch64/demandelts.ll
  
llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-demanded-vector-elts-inseltpoison.ll
  llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-demanded-vector-elts.ll
  llvm/test/Transforms/InstCombine/X86/x86-addsub-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-addsub.ll
  llvm/test/Transforms/InstCombine/X86/x86-avx2-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-avx2.ll
  llvm/test/Transforms/InstCombine/X86/x86-avx512-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-avx512.ll
  llvm/test/Transforms/InstCombine/X86/x86-muldq-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-muldq.ll
  llvm/test/Transforms/InstCombine/X86/x86-pack-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-pack.ll
  llvm/test/Transforms/InstCombine/X86/x86-pshufb-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-pshufb.ll
  llvm/test/Transforms/InstCombine/X86/x86-sse4a-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-sse4a.ll
  llvm/test/Transforms/InstCombine/X86/x86-vpermil-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-vpermil.ll
  llvm/test/Transforms/InstCombine/bitreverse.ll
  llvm/test/Transforms/InstCombine/broadcast-inseltpoison.ll
  llvm/test/Transforms/InstCombine/broadcast.ll
  llvm/test/Transforms/InstCombine/bswap-inseltpoison.ll
  llvm/test/Transforms/InstCombine/bswap.ll
  llvm/test/Transforms/InstCombine/canonicalize-vector-insert.ll
  llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
  llvm/test/Transforms/InstCombine/extractelement.ll
  llvm/test/Transforms/InstCombine/insert-const-shuf-inseltpoison.ll
  llvm/test/Transforms/InstCombine/insert-const-shuf.ll
  llvm/test/Transforms/InstCombine/insert-extract-shuffle-inseltpoison.ll
  llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
  llvm/test/Transforms/InstCombine/masked_intrinsics-inseltpoison.ll
  llvm/test/Transforms/InstCombine/masked_intrinsics.ll
  llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
  llvm/test/Transforms/InstCombine/nsw-inseltpoison.ll
  llvm/test/Transforms/InstCombine/nsw.ll
  llvm/test/Transforms/InstCombine/reduction-shufflevector.ll
  llvm/test/Transforms/InstCombine/select-extractelement-inseltpoison.ll
  llvm/test/Transforms/InstCombine/select-extractelement.ll
  llvm/test/Transforms/InstCombine/select-select.ll
  llvm/t

[PATCH] D149272: [clang] Call printName to get name of Decl

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



Comment at: clang/lib/AST/DeclarationName.cpp:119-125
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
+  InjTy->getDecl()->printName(OS, Policy);

dankm wrote:
> aaron.ballman wrote:
> > This isn't the right way to go about this -- the diagnostic engine knows 
> > how to print a `NamedDecl` when given one, and that's what should be fixed. 
> > (We pass in a `NamedDecl` all over the place -- it's preferred to passing 
> > in a string.)
> > 
> > https://github.com/llvm/llvm-project/blob/b893368fd4fdf40b7778df8d0b17312def1a8156/clang/lib/AST/ASTDiagnostic.cpp#L460
> >  is one place where that happens, and 
> > https://github.com/llvm/llvm-project/blob/b893368fd4fdf40b7778df8d0b17312def1a8156/clang/lib/Basic/Diagnostic.cpp#L1060
> >  is another, so I'd start investigating from there.
> Maybe I could have been more clear in my description of the problem; it's not 
> diagnostics. It's naming in the output. With -ffile-prefix-map in use and 
> without this change I see this:
> 
> ```
> % strings lib/x86_64-dankm-freebsd13.2/libc++.so.1.0|grep barrier.cpp
> std::__1::__barrier_algorithm_base::__state_t::(unnamed struct at 
> /home/dan/llvm/llvm-wip/libcxx/src/barrier.cpp:24:9)
> ```
> 
> when I expect (and get with this change):
> 
> ```
> % strings lib/x86_64-dankm-freebsd13.2/libc++.so.1.0|grep barrier.cpp
> std::__1::__barrier_algorithm_base::__state_t::(unnamed struct at 
> /llvm-root/libcxx/src/barrier.cpp:24:9)
> ```
> 
> It looks like every other call in the DeclarationName::print function 
> preserves the policy, these weren't. As far as I can tell, this is the only 
> place this is used.
Ah, thank you for the explanation, now I see what's going on.



Comment at: clang/test/CodeGen/debug-prefix-map.cpp:1
+// RUN: %clang++ -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+

I'm taking a guess at correcting the RUN line here, but more tweaks may be 
needed. Basically, `%clang++` isn't a thing, so this test fails. Most of our 
tests should be testing `%clang_cc1` to test the frontend invocation, but some 
of the debug prefix map tests use `%clang` to test the driver functionality. I 
don't think there's a need to test the driver here, so I went with 
`%clang_cc1`. I'm not 100% certain whether `-debug-info-kind=` is necessary or 
not, but the other tests seem to be using that, which may be worth paying 
attention to.

Finally, there's no need to have a custom check prefix for `FileCheck`, the 
builtin `CHECK` prefix suffices.



Comment at: clang/test/CodeGen/debug-prefix-map.cpp:11
+
+// CHECK-REL: !DISubprogram(name: "(unnamed struct at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}",




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149272

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


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-27 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added a comment.

In D146557#4295550 , 
@kiranchandramohan wrote:

> In D146557#4292223 , @TIFitis wrote:
>
>> Cleaned up how IsBegin argument is passed for createTargetData call.
>
> Please submit this directly as an NFC patch.

I have merged it separately.

> We should always work towards simple patches that are easy to review. 
> Sometimes a big patch is required to give the full context. But it can then 
> be broken up into small patches for faster review. I have created D149153 
>  for the `inlineConvertOmpRegions` change.

Thanks for creating your patch. I'll try to make my patches shorter in the 
future.

Once D149153  is merged I'll rebase this 
patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

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


[PATCH] D148601: [Clang] Handle Error message to output proper Prefix

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

Thank you for working on this! These changes should come with test coverage (we 
have a handful of verifier tests in `clang/test/Frontend` -- you can add a new 
test file there), but I don't think a release note is required because this is 
a fix for internal functionality. The test should cover the simple case of 
`-verify=something` as well as a more complex test with `-verify=something, 
something_else`.




Comment at: clang/include/clang/Basic/DiagnosticFrontendKinds.td:175-176
 def err_verify_invalid_no_diags : Error<
 "%select{expected|'expected-no-diagnostics'}0 directive cannot follow "
 "%select{'expected-no-diagnostics' directive|other expected directives}0">;
 def err_verify_no_directives : Error<

Should we be handling this situation at the same time, as it's effectively the 
same concern? e.g., https://godbolt.org/z/4Mn1rW9oa


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148601

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


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-27 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 517548.
TIFitis added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -12,32 +12,24 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
 // CHECK-LABEL: define void @_QPopenmp_target_data() {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
-// CHECK: br label %[[VAL_4:.*]]
-// CHECK:   entry:; preds = %[[VAL_5:.*]]
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_2:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
+// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_5]], align 8
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_7]], ptr %[[VAL_8]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store i32 99, ptr %[[VAL_2]], align 4
 // CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
-// CHECK: br label %[[VAL_12:.*]]
-// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
-// CHECK: store i32 99, ptr %[[VAL_3]], align 4
-// CHECK: br label %[[VAL_13:.*]]
-// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
-// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
 // CHECK: ret void
 
 // -
@@ -56,38 +48,30 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4096]
 // CHECK-LABEL: define void @_QPopenmp_target_data_region
 // CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: br label %

[clang] 843450b - [clang] Try to fix check-clang after f539b6ffc251

2023-04-27 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2023-04-27T10:12:39-04:00
New Revision: 843450b9a67c57f134913a2b90dcb5ba95114e0f

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

LOG: [clang] Try to fix check-clang after f539b6ffc251

Added: 


Modified: 
clang/test/SemaTemplate/concepts-inherited-ctor.cpp

Removed: 




diff  --git a/clang/test/SemaTemplate/concepts-inherited-ctor.cpp 
b/clang/test/SemaTemplate/concepts-inherited-ctor.cpp
index d6f3546b25fb..6ac5a1618784 100644
--- a/clang/test/SemaTemplate/concepts-inherited-ctor.cpp
+++ b/clang/test/SemaTemplate/concepts-inherited-ctor.cpp
@@ -89,4 +89,3 @@ namespace GH62362 {
 Test();
   }
 }
-}



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


[PATCH] D148802: [Sema] Lambdas are not part of immediate context for deduction

2023-04-27 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 517550.
ilya-biryukov marked 5 inline comments as done.
ilya-biryukov added a comment.

- Add a note when substituting into a lambda
- Quote the standard and add explanation for the test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148802

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/default-arguments.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
  clang/test/CXX/temp/temp.deduct/p9.cpp
  clang/test/CXX/temp/temp.param/p15-cxx0x.cpp
  clang/test/PCH/cxx1y-init-captures.cpp
  clang/test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp
  clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
  clang/test/SemaCXX/cxx1y-init-captures.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
  clang/test/SemaCXX/cxx20-decomposition.cpp
  clang/test/SemaCXX/lambda-expressions.cpp
  clang/test/SemaCXX/lambda-pack-expansion.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp
  clang/test/SemaCXX/vartemplate-lambda.cpp
  clang/test/SemaCXX/warn-unused-lambda-capture.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/test/SemaTemplate/cxx1z-using-declaration.cpp
  clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
  clang/test/SemaTemplate/instantiate-local-class.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1024,11 +1024,7 @@
 
   Lambdas in unevaluated contexts
   https://wg21.link/p0315r4";>P0315R4
-  
-Partial
-  temp.deduct/9 is not implemented yet.
-
-  
+  Clang 17
 
 
 
Index: clang/test/SemaTemplate/instantiate-local-class.cpp
===
--- clang/test/SemaTemplate/instantiate-local-class.cpp
+++ clang/test/SemaTemplate/instantiate-local-class.cpp
@@ -473,7 +473,8 @@
   template  void bar() {
 auto lambda = [](T a = "") {}; // expected-error {{conversion function from 'const char[1]' to 'rdar23721638::A' invokes a deleted function}} \
// expected-note  {{in instantiation of default function argument expression for 'operator()' required here}} \
-   // expected-note  {{passing argument to parameter 'a' here}}
+   // expected-note  {{passing argument to parameter 'a' here}} \
+   // expected-note {{while substituting into a lambda}}
 lambda();
   }
   template void bar(); // expected-note {{in instantiation}}
@@ -496,6 +497,7 @@
   // expected-error@-1 {{cannot initialize a parameter of type 'int' with an rvalue of type 'std::nullptr_t'}}
   // expected-note@-2  {{in instantiation of default function argument expression for 'operator()' required here}}
   // expected-note@-3  {{passing argument to parameter 'x' here}}
+  // expected-note@-4  {{while substituting into a lambda}}
 
   void g() { f(); }
   // expected-note@-1 {{in instantiation of default function argument expression for 'f' required here}}
Index: clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
===
--- clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
+++ clang/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
@@ -160,7 +160,7 @@
 consume([]() noexcept(sizeof(T) == 4) {} ...);
   }
   template void j() {
-consume([](void (*p)() noexcept(B)) {
+consume([](void (*p)() noexcept(B)) { // expected-note {{substituting into a lambda}}
   void (*q)() noexcept = p; // expected-error {{not superset of source}}
 } ...);
   }
Index: clang/test/SemaTemplate/cxx1z-using-declaration.cpp
===
--- clang/test/SemaTemplate/cxx1z-using-declaration.cpp
+++ clang/test/SemaTemplate/cxx1z-using-declaration.cpp
@@ -157,7 +157,7 @@
 
 // Test partial substitution into class-scope pack.
 template auto lambda1() {
-  return [](auto x) {
+  return [](auto x) { // expected-note 1+{{substituting into a lambda}}
 struct A : T::template X... { // expected-note 1+{{instantiation of}}
   using T::template X::f ...;
   using typename T::template X::type ...;
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -119,7 +119,7 @@
 []() -> C auto{ r

[PATCH] D148802: [Sema] Lambdas are not part of immediate context for deduction

2023-04-27 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D148802#4283566 , @erichkeane 
wrote:

> My one concern is that this is going to expose our incorrect instantiation of 
> lambdas further and more painfully (see 
> https://github.com/llvm/llvm-project/issues/58872).  Else, I don't see 
> anything to be concerned about here.

That's true, but it seems that as a result of this patch, Clang will start 
rejecting some valid C++ programs when lambdas are used in unevaluated 
contexts, but will stop (incorrectly) accepting a class of programs that are 
invalid according to C++ standard.
I would err on the side of false negatives (correct program not compiled) 
instead of false positives (incorrect program complied). Otherwise, future 
changes that make Clang compliant can potentially require rewriting the code 
that relied on incorrect behavior.
It's still unfortunate that we don't accept valid programs, but at least 
existing code will not need to be changed after GH58872 
 is fixed.
My perspective is based on the need to support a large codebase, in which 
codebase-wide refactorings are expensive, other might have a different opinion 
here.




Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:965
+case CodeSynthesisContext::LambdaExpressionSubstitution:
+  // FIXME: add a note for lambdas.
   break;

erichkeane wrote:
> ilya-biryukov wrote:
> > erichkeane wrote:
> > > Would really like this note here, it shouldn't be too difficult, right? 
> > Ah, sorry, I added a comment here that I forgot to submit. The question is: 
> > could it be that we want to skip this note?
> > 
> > I wanted to double-check if folks find this note useful.
> > On one hand, this probably creates some noise as there will always be other 
> > notes that point into the location of a corresponding substitution location 
> > that contains the lambda.
> > On the other hand, since the lambda is not an immediate context, this may 
> > give hints to users on why SFINAE does not apply.
> > 
> > If you feel like the note is useful, I will follow up with an 
> > implementation.
> I think it is useful for exactly the reason you mentioned: this is going to 
> be somewhat shocking behavior to most people, so explaining it better will be 
> helpful.
Makes sense. Added a corresponding note.



Comment at: clang/test/SemaCXX/warn-unused-lambda-capture.cpp:192
 void test_use_template() {
-  test_templated(); // expected-note{{in instantiation of function 
template specialization 'test_templated' requested here}}
+  test_templated(); // expected-note 13{{in instantiation of function 
template specialization 'test_templated' requested here}}
 }

shafik wrote:
> Why the 12 extra notes here, I feel I am missing something but not sure what. 
> I see the increase in notes in other cases as well.
I'm not entirely sure, but it seems there is some deduplication of notes that's 
happening when the stacks of code-synthesis-contexts for subsequent errors are 
the same.
However, this patch introduces a different code synthesis context for lambda 
substitutions, forcing the notes to be added.
In the new version of the patch, the added context actually shows up in the 
notes as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148802

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


[PATCH] D141627: [Clang][OpenMP] Fix the issue that list items in `has_device_addr` are still mapped to the target device

2023-04-27 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141627

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


[PATCH] D149321: [clang][analyzer] Display buffer sizes in StdCLibraryFunctionArgs checker

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

using "wihch" at argument values


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149321

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.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

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
@@ -210,9 +210,9 @@
   // The 3rd parameter should be the number of elements to read, not
   // the size in bytes.
   fread(wbuf, size, nitems, file); // \
-  // report-warning{{The 1st argument to 'fread' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-warning{{The 1st argument to 'fread' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-note{{The 1st argument to 'fread' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}}
+  // report-warning{{The 1st argument to 'fread' is a buffer with size 4096 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 4096)}} \
+  // bugpath-warning{{The 1st argument to 'fread' is a buffer with size 4096 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 4096)}} \
+  // bugpath-note{{The 1st argument to 'fread' is a buffer with size 4096 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 4096)}}
 }
 
 int __two_constrained_args(int, int);
@@ -254,9 +254,9 @@
 void test_buf_size_concrete(void) {
   char buf[3];   // bugpath-note{{'buf' initialized here}}
   __buf_size_arg_constraint(buf, 4); // \
-  // report-warning{{The 1st argument to '__buf_size_arg_constraint' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument}} \
-  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument}} \
-  // bugpath-note{{The 1st argument to '__buf_size_arg_constraint' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument}}
+  // report-warning{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4)}} \
+  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4)}} \
+  // bugpath-note{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4)}}
 }
 void test_buf_size_symbolic(int s) {
   char buf[3];
@@ -281,9 +281,9 @@
 void test_buf_size_concrete_with_multiplication(void) {
   short buf[3]; // bugpath-note{{'buf' initialized here}}
   __buf_size_arg_constraint_mul(buf, 4, sizeof(short)); // \
-  // report-warning{{The 1st argument to '__buf_size_arg_constraint_mul' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint_mul' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}} \
-  // bugpath-note{{The 1st argument to '__buf_size_arg_constraint_mul' is out of the accepted range; It should be a buffer with size equal to or greater than the value of the 2nd argument times the 3rd argument}}
+  // report-warning{{The 1st argument to '__buf_size_arg_constraint_mul' is a buffer with size 6 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 2)}} \
+  // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint_mul' is a buffer with size 6 but should be a buffer with size equal to or greater than the value of the 2nd argument (that is 4) times the 3rd argument (that is 2)}

[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-04-27 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/PrintfToStdPrintCheck.cpp:66
+  if (Converter.canApply()) {
+const auto *PrintfCall = Printf->getCallee();
+DiagnosticBuilder Diag =

Please don't use `auto` unless type is explicitly stated in same statement or 
iterator.



Comment at: clang-tools-extra/clang-tidy/modernize/PrintfToStdPrintCheck.h:15
+namespace clang::tidy::modernize {
+/// Documentation goes here.
+///

Should be elaborated or removed.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:171
 
+- New :doc: `modernize-printf-to-std-print
+  ` check.

Please keep alphabetical order (by check name) in this section.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/printf-to-std-print.rst:6
+
+This check is capable of converting calls to printf to calls to std::print
+whilst also modifying the format string appropriately.

Please make first statement same as in Release Notes. Please highlight language 
constructs (like `printf`) with double back-ticks.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/printf-to-std-print.rst:11
+
+ fprintf(stderr, "The %s is %3d\n", answer, value);
+

Please prepend with `.. code-block:: c++` line. Same for other snippets.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/printf-to-std-print.rst:73
+   printf-style format string and the arguments to be formatted follow
+   immediately afterwards.
+

Please add information about default value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D148088: [RFC][clangd] Move preamble index task to a seperate task

2023-04-27 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

> We would like to move the preamble index out of the critical path

Could you provide motivation why you need to do it? What is the underlying 
problem that this change is trying to solve?
We rely on preamble being indexed at that particular time for correct results 
in future steps, it's definitely not a no-op change even if the threading 
issues are resolved (see the other comment).




Comment at: clang-tools-extra/clangd/ClangdServer.cpp:88
+if (PreambleIndexTask)
+  PreambleIndexTask->runAsync("task:" + Path + Version,
+  std::move(Task));

This definitely does not work. After `onPreambleAST` returns, the AST will be 
destroyed and async tasks may access it afterwards.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148088

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


[PATCH] D148088: [RFC][clangd] Move preamble index task to a seperate task

2023-04-27 Thread Kugan Vivekanandarajah via Phabricator via cfe-commits
kuganv added a comment.

In D148088#4302092 , @ilya-biryukov 
wrote:

>> We would like to move the preamble index out of the critical path
>
> Could you provide motivation why you need to do it? What is the underlying 
> problem that this change is trying to solve?
> We rely on preamble being indexed at that particular time for correct results 
> in future steps, it's definitely not a no-op change even if the threading 
> issues are resolved (see the other comment).

Thanks for your comment. Motivation for this is:

1. We see preamble indexing taking as much as 18% of the time for some files.  
Moving  preamble indexing out of the critical path helps there.
2. We are also experimenting with preamble caching with clang modules. Early 
results from this also shows that preamble indexing outside  the critical path 
improves performance.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148088

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


[clang] 05d0cae - [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2023-04-27T08:21:36-07:00
New Revision: 05d0caef6081e1a6cb23a5a5afe43dc82e8ca558

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

LOG: [RISCV] Remove support for attribute interrupt("user").

This was part of the N extension which didn't make it version
1.12 of the privilege specification.

Reviewed By: kito-cheng

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

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/CodeGen/TargetInfo.cpp
clang/test/Sema/riscv-interrupt-attr.c

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index a23dd5ce3634b..4863ece832307 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1864,8 +1864,8 @@ def RISCVInterrupt : InheritableAttr, 
TargetSpecificAttr {
   let Spellings = [GCC<"interrupt">];
   let Subjects = SubjectList<[Function]>;
   let Args = [EnumArgument<"Interrupt", "InterruptType",
-   ["user", "supervisor", "machine"],
-   ["user", "supervisor", "machine"],
+   ["supervisor", "machine"],
+   ["supervisor", "machine"],
1>];
   let ParseKind = "Interrupt";
   let Documentation = [RISCVInterruptDocs];

diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index cc332aeee40d4..a19f1605bd3aa 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -11524,7 +11524,6 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo 
{
 
 const char *Kind;
 switch (Attr->getInterrupt()) {
-case RISCVInterruptAttr::user: Kind = "user"; break;
 case RISCVInterruptAttr::supervisor: Kind = "supervisor"; break;
 case RISCVInterruptAttr::machine: Kind = "machine"; break;
 }

diff  --git a/clang/test/Sema/riscv-interrupt-attr.c 
b/clang/test/Sema/riscv-interrupt-attr.c
index 2f5f2a44c778d..e66a5799bb394 100644
--- a/clang/test/Sema/riscv-interrupt-attr.c
+++ b/clang/test/Sema/riscv-interrupt-attr.c
@@ -4,26 +4,21 @@
 // RUN: %clang_cc1 %s -triple riscv64-unknown-elf -verify -fsyntax-only
 
 #if defined(CHECK_IR)
-// CHECK-LABEL:  @foo_user() #0
-// CHECK: ret void
-__attribute__((interrupt("user"))) void foo_user(void) {}
-// CHECK-LABEL:  @foo_supervisor() #1
+// CHECK-LABEL:  @foo_supervisor() #0
 // CHECK: ret void
 __attribute__((interrupt("supervisor"))) void foo_supervisor(void) {}
-// CHECK-LABEL:  @foo_machine() #2
+// CHECK-LABEL:  @foo_machine() #1
 // CHECK: ret void
 __attribute__((interrupt("machine"))) void foo_machine(void) {}
-// CHECK-LABEL:  @foo_default() #2
+// CHECK-LABEL:  @foo_default() #1
 // CHECK: ret void
 __attribute__((interrupt())) void foo_default(void) {}
-// CHECK-LABEL:  @foo_default2() #2
+// CHECK-LABEL:  @foo_default2() #1
 // CHECK: ret void
 __attribute__((interrupt())) void foo_default2(void) {}
 // CHECK: attributes #0
-// CHECK: "interrupt"="user"
-// CHECK: attributes #1
 // CHECK: "interrupt"="supervisor"
-// CHECK: attributes #2
+// CHECK: attributes #1
 // CHECK: "interrupt"="machine"
 #else
 struct a { int b; };
@@ -31,8 +26,10 @@ struct a { int b; };
 struct a test __attribute__((interrupt)); // expected-warning {{'interrupt' 
attribute only applies to functions}}
 
 __attribute__((interrupt("USER"))) void foo1(void) {} // expected-warning 
{{'interrupt' attribute argument not supported: USER}}
+__attribute__((interrupt("user"))) void foo1b(void) {} // expected-warning 
{{'interrupt' attribute argument not supported: user}}
+__attribute__((interrupt("MACHINE"))) void foo1c(void) {} // expected-warning 
{{'interrupt' attribute argument not supported: MACHINE}}
 
-__attribute__((interrupt("user", 1))) void foo2(void) {} // expected-error 
{{'interrupt' attribute takes no more than 1 argument}}
+__attribute__((interrupt("machine", 1))) void foo2(void) {} // expected-error 
{{'interrupt' attribute takes no more than 1 argument}}
 
 __attribute__((interrupt)) int foo3(void) {return 0;} // expected-warning 
{{RISC-V 'interrupt' attribute only applies to functions that have a 'void' 
return type}}
 
@@ -41,7 +38,7 @@ __attribute__((interrupt())) void foo4(void) {}
 
 __attribute__((interrupt())) void foo5(int a) {} // expected-warning {{RISC-V 
'interrupt' attribute only applies to functions that have no parameters}}
 
-__attribute__((interrupt("user"), interrupt("supervisor"))) void foo6(void) {} 
// expected-warning {{repeated RISC-V 'interrupt' attribute}} \
+__attribute__((interrupt("machine"), interrupt("supervisor"))) void foo6(void) 
{} // expected-warning {{repeated RISC-V 'interrupt' attribute}} \
   // expected-note {{repeated RISC-V 'interrupt' attribute is h

[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Craig Topper 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 rG05d0caef6081: [RISCV] Remove support for attribute 
interrupt("user"). (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/Sema/riscv-interrupt-attr.c


Index: clang/test/Sema/riscv-interrupt-attr.c
===
--- clang/test/Sema/riscv-interrupt-attr.c
+++ clang/test/Sema/riscv-interrupt-attr.c
@@ -4,26 +4,21 @@
 // RUN: %clang_cc1 %s -triple riscv64-unknown-elf -verify -fsyntax-only
 
 #if defined(CHECK_IR)
-// CHECK-LABEL:  @foo_user() #0
-// CHECK: ret void
-__attribute__((interrupt("user"))) void foo_user(void) {}
-// CHECK-LABEL:  @foo_supervisor() #1
+// CHECK-LABEL:  @foo_supervisor() #0
 // CHECK: ret void
 __attribute__((interrupt("supervisor"))) void foo_supervisor(void) {}
-// CHECK-LABEL:  @foo_machine() #2
+// CHECK-LABEL:  @foo_machine() #1
 // CHECK: ret void
 __attribute__((interrupt("machine"))) void foo_machine(void) {}
-// CHECK-LABEL:  @foo_default() #2
+// CHECK-LABEL:  @foo_default() #1
 // CHECK: ret void
 __attribute__((interrupt())) void foo_default(void) {}
-// CHECK-LABEL:  @foo_default2() #2
+// CHECK-LABEL:  @foo_default2() #1
 // CHECK: ret void
 __attribute__((interrupt())) void foo_default2(void) {}
 // CHECK: attributes #0
-// CHECK: "interrupt"="user"
-// CHECK: attributes #1
 // CHECK: "interrupt"="supervisor"
-// CHECK: attributes #2
+// CHECK: attributes #1
 // CHECK: "interrupt"="machine"
 #else
 struct a { int b; };
@@ -31,8 +26,10 @@
 struct a test __attribute__((interrupt)); // expected-warning {{'interrupt' 
attribute only applies to functions}}
 
 __attribute__((interrupt("USER"))) void foo1(void) {} // expected-warning 
{{'interrupt' attribute argument not supported: USER}}
+__attribute__((interrupt("user"))) void foo1b(void) {} // expected-warning 
{{'interrupt' attribute argument not supported: user}}
+__attribute__((interrupt("MACHINE"))) void foo1c(void) {} // expected-warning 
{{'interrupt' attribute argument not supported: MACHINE}}
 
-__attribute__((interrupt("user", 1))) void foo2(void) {} // expected-error 
{{'interrupt' attribute takes no more than 1 argument}}
+__attribute__((interrupt("machine", 1))) void foo2(void) {} // expected-error 
{{'interrupt' attribute takes no more than 1 argument}}
 
 __attribute__((interrupt)) int foo3(void) {return 0;} // expected-warning 
{{RISC-V 'interrupt' attribute only applies to functions that have a 'void' 
return type}}
 
@@ -41,7 +38,7 @@
 
 __attribute__((interrupt())) void foo5(int a) {} // expected-warning {{RISC-V 
'interrupt' attribute only applies to functions that have no parameters}}
 
-__attribute__((interrupt("user"), interrupt("supervisor"))) void foo6(void) {} 
// expected-warning {{repeated RISC-V 'interrupt' attribute}} \
+__attribute__((interrupt("machine"), interrupt("supervisor"))) void foo6(void) 
{} // expected-warning {{repeated RISC-V 'interrupt' attribute}} \
   // expected-note {{repeated RISC-V 'interrupt' attribute is here}}
 
 __attribute__((interrupt, interrupt)) void foo7(void) {} // expected-warning 
{{repeated RISC-V 'interrupt' attribute}} \
@@ -49,11 +46,9 @@
 
 __attribute__((interrupt(""))) void foo8(void) {} // expected-warning 
{{'interrupt' attribute argument not supported}}
 
-__attribute__((interrupt("user"))) void foo9(void);
 __attribute__((interrupt("supervisor"))) void foo9(void);
 __attribute__((interrupt("machine"))) void foo9(void);
 
-__attribute__((interrupt("user"))) void foo10(void) {}
 __attribute__((interrupt("supervisor"))) void foo11(void) {}
 __attribute__((interrupt("machine"))) void foo12(void) {}
 __attribute__((interrupt())) void foo13(void) {}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -11524,7 +11524,6 @@
 
 const char *Kind;
 switch (Attr->getInterrupt()) {
-case RISCVInterruptAttr::user: Kind = "user"; break;
 case RISCVInterruptAttr::supervisor: Kind = "supervisor"; break;
 case RISCVInterruptAttr::machine: Kind = "machine"; break;
 }
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1864,8 +1864,8 @@
   let Spellings = [GCC<"interrupt">];
   let Subjects = SubjectList<[Function]>;
   let Args = [EnumArgument<"Interrupt", "InterruptType",
-   ["user", "supervisor", "machine"],
-   ["user", "supervisor", "machine"],
+   ["supervisor", "machine"],
+   

[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

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

Is this a potentially breaking change that we need to call out for users to be 
aware of?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D149352: [clang-format] Recognize Verilog type dimension in module header

2023-04-27 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added a reviewer: curdeius.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
sstwcw requested review of this revision.

We had the function `verilogGroupDecl` for that.  However, the type
name would be incorrectly annotated in `isStartOfName` when it was not
a C++ keyword and followed another identifier.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149352

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1615,6 +1615,13 @@
   Tokens = Annotate("extern function [1 : 0] x;");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::colon, TT_BitFieldColon);
+  Tokens = Annotate("module test\n"
+"(input wire [7 : 0] a[7 : 0]);\n"
+"endmodule");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_VerilogDimensionedTypeName);
+  EXPECT_TOKEN(Tokens[7], tok::colon, TT_BitFieldColon);
+  EXPECT_TOKEN(Tokens[13], tok::colon, TT_BitFieldColon);
   // Test case labels and ternary operators.
   Tokens = Annotate("case (x)\n"
 "  x:\n"
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -359,6 +359,12 @@
" input var shortreal in2,\n"
" output tagged_st out);\n"
"endmodule");
+  // There should be a space following the type but not the variable name.
+  verifyFormat("module test\n"
+   "(input wire [7 : 0] a,\n"
+   " input wire b[7 : 0],\n"
+   " input wire [7 : 0] c[7 : 0]);\n"
+   "endmodule");
   // Ports should be grouped by types.
   verifyFormat("module test\n"
"(input [7 : 0] a,\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2161,6 +2161,10 @@
   /// This is a heuristic based on whether \p Tok is an identifier following
   /// something that is likely a type.
   bool isStartOfName(const FormatToken &Tok) {
+// Handled in ExpressionParser for Verilog.
+if (Style.isVerilog())
+  return false;
+
 if (Tok.isNot(tok::identifier) || !Tok.Previous)
   return false;
 


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1615,6 +1615,13 @@
   Tokens = Annotate("extern function [1 : 0] x;");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::colon, TT_BitFieldColon);
+  Tokens = Annotate("module test\n"
+"(input wire [7 : 0] a[7 : 0]);\n"
+"endmodule");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_VerilogDimensionedTypeName);
+  EXPECT_TOKEN(Tokens[7], tok::colon, TT_BitFieldColon);
+  EXPECT_TOKEN(Tokens[13], tok::colon, TT_BitFieldColon);
   // Test case labels and ternary operators.
   Tokens = Annotate("case (x)\n"
 "  x:\n"
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -359,6 +359,12 @@
" input var shortreal in2,\n"
" output tagged_st out);\n"
"endmodule");
+  // There should be a space following the type but not the variable name.
+  verifyFormat("module test\n"
+   "(input wire [7 : 0] a,\n"
+   " input wire b[7 : 0],\n"
+   " input wire [7 : 0] c[7 : 0]);\n"
+   "endmodule");
   // Ports should be grouped by types.
   verifyFormat("module test\n"
"(input [7 : 0] a,\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2161,6 +2161,10 @@
   /// This is a heuristic based on whether \p Tok is an identifier following
   /// something that is likely a type.
   bool isStartOfName(const FormatToken &Tok) {
+// Handled in ExpressionParser for Verilog.
+if (Style.isVerilog())
+  return fals

[PATCH] D141627: [Clang][OpenMP] Fix the issue that list items in `has_device_addr` are still mapped to the target device

2023-04-27 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

If it is okay with is_divece_ptr.  I am okay with it.
Please add a lit test for this?

Thanks.
Jennifer


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141627

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


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

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

In D149314#4302203 , @aaron.ballman 
wrote:

> Is this a potentially breaking change that we need to call out for users to 
> be aware of?

We should mention this in the Clang release notes I think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D148088: [RFC][clangd] Move preamble index task to a seperate task

2023-04-27 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D148088#4302182 , @kuganv wrote:

> 1. We see preamble indexing taking as much as 18% of the time for some files. 
>  Moving  preamble indexing out of the critical path helps there.

Which operation are you measuring? 18% of first diagnostic latency?
Preamble indexing populates necessary information for many of the Clangd 
features. Some examples of the top of my head:

- code completion will not show declarations from preamble if they were not 
deserialized from the preamble (most symbols).
- diagnostics from preamble,
- multi-file rename will miss references inside template bodies.

Doing indexing of the preamble in parallel to other operations is probably an 
improvement as PCH gets available earlier for operations that need it, e.g. 
code completion can start operating faster.
However, if we want to ensure the returned results are the same as they were 
before the patch (at least for the first run), we have to synchronize with the 
operations that populates the index.

For any form of this optimization, I think the implementation is going to be a 
little tricky and we definitely want @kadircet to take a look at it. It's hard 
to list all things in Clangd that rely on preamble indexing
finishing before they run, this change definitely requires a careful design 
review.

> 2. We are also experimenting with preamble caching with clang modules. Early 
> results from this also shows that preamble indexing outside  the critical 
> path improves performance.

Could you elaborate a bit more on what is being cached with modules and how 
this patch would affect it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148088

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


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-27 Thread Dan McGregor via Phabricator via cfe-commits
dankm added inline comments.



Comment at: clang/test/CodeGen/debug-prefix-map.cpp:1
+// RUN: %clang++ -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+

aaron.ballman wrote:
> I'm taking a guess at correcting the RUN line here, but more tweaks may be 
> needed. Basically, `%clang++` isn't a thing, so this test fails. Most of our 
> tests should be testing `%clang_cc1` to test the frontend invocation, but 
> some of the debug prefix map tests use `%clang` to test the driver 
> functionality. I don't think there's a need to test the driver here, so I 
> went with `%clang_cc1`. I'm not 100% certain whether `-debug-info-kind=` is 
> necessary or not, but the other tests seem to be using that, which may be 
> worth paying attention to.
> 
> Finally, there's no need to have a custom check prefix for `FileCheck`, the 
> builtin `CHECK` prefix suffices.
Okay, noted about clang++, it did work for me locally, but that doesn't mean 
it's correct. Good point about only testing the frontend action, the driver 
test is unnecessary.

The custom check prefix is just a cut & paste artefact from copying from the C 
version of the debug-prefix-map test, originally I was going to update that 
test to a C++ file but opted later for just creating a new test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149272

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


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-27 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

In D146557#4301955 , @TIFitis wrote:

> In D146557#4295550 , 
> @kiranchandramohan wrote:
>
>> In D146557#4292223 , @TIFitis 
>> wrote:
>>
>>> Cleaned up how IsBegin argument is passed for createTargetData call.
>>
>> Please submit this directly as an NFC patch.
>
> I have merged it separately.
>
>> We should always work towards simple patches that are easy to review. 
>> Sometimes a big patch is required to give the full context. But it can then 
>> be broken up into small patches for faster review. I have created D149153 
>>  for the `inlineConvertOmpRegions` change.
>
> Thanks for creating your patch. I'll try to make my patches shorter in the 
> future.
>
> Once D149153  is merged I'll rebase this 
> patch.

I have submitted D149153 . 
https://github.com/llvm/llvm-project/commit/1ed522623d95ce7dcf95e711b0f2e3844d2e6be1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

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


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: erichkeane.
aaron.ballman added a comment.

In D149314#4302266 , @asb wrote:

> In D149314#4302203 , @aaron.ballman 
> wrote:
>
>> Is this a potentially breaking change that we need to call out for users to 
>> be aware of?
>
> We should mention this in the Clang release notes I think.

Beyond that, we've got a process for what to do when considering potentially 
breaking changes, we should be following that: 
https://llvm.org/docs/DeveloperPolicy.html#making-potentially-breaking-changes 
Also, if we're all agreed this is potentially breaking, it really should have 
more review time and buy-in from the code owner.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Philip Reames via Phabricator via cfe-commits
reames added a comment.

In D149314#4302300 , @aaron.ballman 
wrote:

> In D149314#4302266 , @asb wrote:
>
>> In D149314#4302203 , 
>> @aaron.ballman wrote:
>>
>>> Is this a potentially breaking change that we need to call out for users to 
>>> be aware of?
>>
>> We should mention this in the Clang release notes I think.
>
> Beyond that, we've got a process for what to do when considering potentially 
> breaking changes, we should be following that: 
> https://llvm.org/docs/DeveloperPolicy.html#making-potentially-breaking-changes
>  Also, if we're all agreed this is potentially breaking, it really should 
> have more review time and buy-in from the code owner.

I don't think this change should count as "potentially breaking" in the sense 
of that document.  We're talking about an experimental feature for an 
experimental ISA extension which never got to ratification.  There's no 
hardware in the wild which implements this (to my knowledge).  Given the churn 
on the RISCV extension side, we've adopted a policy for experimental extensions 
(https://llvm.org/docs/RISCVUsage.html#experimental-extensions) which offers 
much less in the way of support.  I think we should release note it just to be 
friendly, but the process described in your link is significant overkill.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

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

In D149314#4302312 , @reames wrote:

> In D149314#4302300 , @aaron.ballman 
> wrote:
>
>> In D149314#4302266 , @asb wrote:
>>
>>> In D149314#4302203 , 
>>> @aaron.ballman wrote:
>>>
 Is this a potentially breaking change that we need to call out for users 
 to be aware of?
>>>
>>> We should mention this in the Clang release notes I think.
>>
>> Beyond that, we've got a process for what to do when considering potentially 
>> breaking changes, we should be following that: 
>> https://llvm.org/docs/DeveloperPolicy.html#making-potentially-breaking-changes
>>  Also, if we're all agreed this is potentially breaking, it really should 
>> have more review time and buy-in from the code owner.
>
> I don't think this change should count as "potentially breaking" in the sense 
> of that document.  We're talking about an experimental feature for an 
> experimental ISA extension which never got to ratification.  There's no 
> hardware in the wild which implements this (to my knowledge).  Given the 
> churn on the RISCV extension side, we've adopted a policy for experimental 
> extensions (https://llvm.org/docs/RISCVUsage.html#experimental-extensions) 
> which offers much less in the way of support.  I think we should release note 
> it just to be friendly, but the process described in your link is significant 
> overkill.

If we don't need to use that process, it's totally reasonable to skip it. It 
wasn't clear just how disruptive this change is from the review summary and 
there was not really any chance for discussion before this landed. Release 
noting it would be fine by me if the folks with more knowledge in this area 
think that's sufficient.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-27 Thread Dan McGregor via Phabricator via cfe-commits
dankm added inline comments.



Comment at: clang/test/CodeGen/debug-prefix-map.cpp:1
+// RUN: %clang++ -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+

dankm wrote:
> aaron.ballman wrote:
> > I'm taking a guess at correcting the RUN line here, but more tweaks may be 
> > needed. Basically, `%clang++` isn't a thing, so this test fails. Most of 
> > our tests should be testing `%clang_cc1` to test the frontend invocation, 
> > but some of the debug prefix map tests use `%clang` to test the driver 
> > functionality. I don't think there's a need to test the driver here, so I 
> > went with `%clang_cc1`. I'm not 100% certain whether `-debug-info-kind=` is 
> > necessary or not, but the other tests seem to be using that, which may be 
> > worth paying attention to.
> > 
> > Finally, there's no need to have a custom check prefix for `FileCheck`, the 
> > builtin `CHECK` prefix suffices.
> Okay, noted about clang++, it did work for me locally, but that doesn't mean 
> it's correct. Good point about only testing the frontend action, the driver 
> test is unnecessary.
> 
> The custom check prefix is just a cut & paste artefact from copying from the 
> C version of the debug-prefix-map test, originally I was going to update that 
> test to a C++ file but opted later for just creating a new test.
Ah, I see now it failed on the windows build in my test. Neat.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149272

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


[PATCH] D149193: [Driver] Add -dumpdir and change -gsplit-dwarf .dwo names for linking

2023-04-27 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D149193#4300885 , @MaskRay wrote:

> I think the patch as-is implements all the useful parts of GCC's complex 
> rules and in the absence of `-dumpbase` (we deliberately don't implement), 
> the rule almost exactly matches GCC unless we do `gcc -g -gsplit-dwarf d/a.c 
> -o e/a.out` (instead of other filenames).
>
> https://maskray.me/blog/2023-04-25-compiler-output-files records all my 
> findings.

I agree that the special-casing of `a.out` when explicitly specified is odd.

Another option to avoid any confusion or debates over exact behavior relative 
to GCC would be to just make our own option. Rather than add `-dumpdir` we 
could add `-dump-prefix` or something. I'm also OK with just implementing a 
simpler subset of the GCC options though (i.e. what you have already).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149193

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


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-27 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 517595.
dankm added a comment.

Correct test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149272

Files:
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclarationName.cpp
  clang/test/CodeGen/debug-prefix-map.cpp


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK: !DISubprogram(name: "(unnamed struct at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}",
Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream &OS, const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream &OS, const PrintingPolicy &Policy) const 
{
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream &OS) const {


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK: !DISubprogram(name: "(unnamed struct at ./UNLIKELY_PATH/empty{{/|}}{{.*}}",
Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream &OS, const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream &OS, const PrintingPolicy &Policy) const {
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream &OS) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

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

In D149314#4302312 , @reames wrote:

> In D149314#4302300 , @aaron.ballman 
> wrote:
>
>> In D149314#4302266 , @asb wrote:
>>
>>> In D149314#4302203 , 
>>> @aaron.ballman wrote:
>>>
 Is this a potentially breaking change that we need to call out for users 
 to be aware of?
>>>
>>> We should mention this in the Clang release notes I think.
>>
>> Beyond that, we've got a process for what to do when considering potentially 
>> breaking changes, we should be following that: 
>> https://llvm.org/docs/DeveloperPolicy.html#making-potentially-breaking-changes
>>  Also, if we're all agreed this is potentially breaking, it really should 
>> have more review time and buy-in from the code owner.
>
> I don't think this change should count as "potentially breaking" in the sense 
> of that document.  We're talking about an experimental feature for an 
> experimental ISA extension which never got to ratification.  There's no 
> hardware in the wild which implements this (to my knowledge).  Given the 
> churn on the RISCV extension side, we've adopted a policy for experimental 
> extensions (https://llvm.org/docs/RISCVUsage.html#experimental-extensions) 
> which offers much less in the way of support.  I think we should release note 
> it just to be friendly, but the process described in your link is significant 
> overkill.

+1 on this. The upstream (RISC-V side) process for the ISA extension lifecycle 
and their ratification is now properly established, and we gate 
not-yet-ratified things behind `-menable-experimental-extensions` going 
forward. This review perhaps could have been held open a bit longer to check 
there's no concerns, and thanks to Aaron for raising the question. But I think 
a release note only is the appropriate option here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D148601: [Clang] Handle Error message to output proper Prefix

2023-04-27 Thread Usman Akinyemi via Phabricator via cfe-commits
Unique_Usman added a comment.

In D148601#4301977 , @aaron.ballman 
wrote:

> Thank you for working on this! These changes should come with test coverage 
> (we have a handful of verifier tests in `clang/test/Frontend` -- you can add 
> a new test file there), but I don't think a release note is required because 
> this is a fix for internal functionality. The test should cover the simple 
> case of `-verify=something` as well as a more complex test with 
> `-verify=something, something_else`.

Thank you, will work on this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148601

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


[clang] 4ab76b7 - [AArch64][InlineAsm]Add Clang support for flag output constraints

2023-04-27 Thread Mingming Liu via cfe-commits

Author: Mingming Liu
Date: 2023-04-27T09:39:08-07:00
New Revision: 4ab76b77cee0e27510d5d5cb3072ee7e92d96eec

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

LOG: [AArch64][InlineAsm]Add Clang support for flag output constraints

- Mention this change in Clang release notes

Before:
- Clang emits "invalid output constraint '=@cceq' in asm" 
https://gcc.godbolt.org/z/b9crfEo8h

After:
- For aarch64 targets (with __aarch64__ defined), Clang validates and parses 
flag output constraints to generate LLVM IR.

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

Added: 
clang/test/CodeGen/inline-asm-aarch64-flag-output.c
clang/test/Preprocessor/aarch64_asm_flag_output.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/test/Preprocessor/init-aarch64.c
clang/test/Preprocessor/predefined-win-macros.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 26fdffe920e95..aff9ce3782532 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -416,6 +416,15 @@ Arm and AArch64 Support
 - Clang builtin ``__arithmetic_fence`` and the command line option 
``-fprotect-parens``
   are now enabled for AArch64.
 
+- Clang supports flag output operands by which conditions in the NZCV could be 
outputs
+  of inline assembly for AArch64. This change is more consistent with the 
behavior of
+  GCC.
+
+   .. code-block:: c
+
+ // int a = foo(); int* b = bar();
+ asm("ands %w[a], %w[a], #3" : [a] "+r"(a), "=@cceq"(*b));
+
 Windows Support
 ^^^
 

diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 67ba5f6b35145..3840139d27434 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -333,6 +333,8 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
  MacroBuilder &Builder) const {
   // Target identification.
   Builder.defineMacro("__aarch64__");
+  // Inline assembly supports AArch64 flag outputs.
+  Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
   // For bare-metal.
   if (getTriple().getOS() == llvm::Triple::UnknownOS &&
   getTriple().isOSBinFormatELF())
@@ -1210,6 +1212,52 @@ ArrayRef 
AArch64TargetInfo::getGCCRegAliases() const {
   return llvm::ArrayRef(GCCRegAliases);
 }
 
+// Returns the length of cc constraint.
+static unsigned matchAsmCCConstraint(const char *Name) {
+  constexpr unsigned len = 5;
+  auto RV = llvm::StringSwitch(Name)
+.Case("@cceq", len)
+.Case("@ccne", len)
+.Case("@cchs", len)
+.Case("@cccs", len)
+.Case("@", len)
+.Case("@cclo", len)
+.Case("@ccmi", len)
+.Case("@ccpl", len)
+.Case("@ccvs", len)
+.Case("@ccvc", len)
+.Case("@cchi", len)
+.Case("@ccls", len)
+.Case("@ccge", len)
+.Case("@cclt", len)
+.Case("@ccgt", len)
+.Case("@ccle", len)
+.Default(0);
+  return RV;
+}
+
+std::string
+AArch64TargetInfo::convertConstraint(const char *&Constraint) const {
+  std::string R;
+  switch (*Constraint) {
+  case 'U': // Three-character constraint; add "@3" hint for later parsing.
+R = std::string("@3") + std::string(Constraint, 3);
+Constraint += 2;
+break;
+  case '@':
+if (const unsigned Len = matchAsmCCConstraint(Constraint)) {
+  std::string Converted = "{" + std::string(Constraint, Len) + "}";
+  Constraint += Len - 1;
+  return Converted;
+}
+return std::string(1, *Constraint);
+  default:
+R = TargetInfo::convertConstraint(Constraint);
+break;
+  }
+  return R;
+}
+
 bool AArch64TargetInfo::validateAsmConstraint(
 const char *&Name, TargetInfo::ConstraintInfo &Info) const {
   switch (*Name) {
@@ -1257,6 +1305,13 @@ bool AArch64TargetInfo::validateAsmConstraint(
   case 'y': // SVE registers (V0-V7)
 Info.setAllowsRegister();
 return true;
+  case '@':
+// CC condition
+if (const unsigned Len = matchAsmCCConstraint(Name)) {
+  Name += Len - 1;
+  Info.setAllowsRegister();
+  return true;
+}
   }
   return false;
 }

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 967a888f6b6f8..cce80e10f2bb1 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -173,19 +173,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   ArrayRef getGCCRegNames() const override;
   ArrayRef getGCCRegAliases() const override;
 
-  std::strin

[PATCH] D149123: [AArch64][InlineAsm]Add Clang support for flag output constraints

2023-04-27 Thread Mingming Liu 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 rG4ab76b77cee0: [AArch64][InlineAsm]Add Clang support for flag 
output constraints (authored by mingmingl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149123

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/test/CodeGen/inline-asm-aarch64-flag-output.c
  clang/test/Preprocessor/aarch64_asm_flag_output.c
  clang/test/Preprocessor/init-aarch64.c
  clang/test/Preprocessor/predefined-win-macros.c

Index: clang/test/Preprocessor/predefined-win-macros.c
===
--- clang/test/Preprocessor/predefined-win-macros.c
+++ clang/test/Preprocessor/predefined-win-macros.c
@@ -129,4 +129,5 @@
 // CHECK-ARM64-MINGW: #define WINNT 1
 // CHECK-ARM64-MINGW: #define _WIN32 1
 // CHECK-ARM64-MINGW: #define _WIN64 1
+// CHECK-ARM64-MINGW: #define __GCC_ASM_FLAG_OUTPUTS__ 1
 // CHECK-ARM64-MINGW: #define __aarch64__ 1
Index: clang/test/Preprocessor/init-aarch64.c
===
--- clang/test/Preprocessor/init-aarch64.c
+++ clang/test/Preprocessor/init-aarch64.c
@@ -106,6 +106,7 @@
 // AARCH64-NEXT: #define __FLT_RADIX__ 2
 // AARCH64-NEXT: #define __FP_FAST_FMA 1
 // AARCH64-NEXT: #define __FP_FAST_FMAF 1
+// AARCH64-NEXT: #define __GCC_ASM_FLAG_OUTPUTS__ 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
Index: clang/test/Preprocessor/aarch64_asm_flag_output.c
===
--- /dev/null
+++ clang/test/Preprocessor/aarch64_asm_flag_output.c
@@ -0,0 +1,3 @@
+// RUN: %clang -target aarch64-unknown-unknown -x c -E -dM -o - %s | FileCheck -match-full-lines %s
+
+// CHECK: #define __GCC_ASM_FLAG_OUTPUTS__ 1
Index: clang/test/CodeGen/inline-asm-aarch64-flag-output.c
===
--- /dev/null
+++ clang/test/CodeGen/inline-asm-aarch64-flag-output.c
@@ -0,0 +1,130 @@
+// RUN: %clang_cc1 -O2 -emit-llvm %s -o - -triple aarch64 | FileCheck %s
+
+int test_cceq(int a, int* b) {
+// CHECK-LABEL: @test_cceq
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@cceq},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@cceq"(*b));
+  return a;
+}
+
+int test_ccne(int a, int* b) {
+// CHECK-LABEL: @test_ccne
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@ccne},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@ccne"(*b));
+  return a;
+}
+
+int test_cccs(int a, int* b) {
+// CHECK-LABEL: @test_cccs
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@cccs},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@cccs"(*b));
+  return a;
+}
+
+int test_cchs(int a, int* b) {
+// CHECK-LABEL: @test_cchs
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@cchs},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@cchs"(*b));
+  return a;
+}
+
+int test_(int a, int* b) {
+// CHECK-LABEL: @test_
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@"(*b));
+  return a;
+}
+
+int test_cclo(int a, int* b) {
+// CHECK-LABEL: @test_cclo
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@cclo},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@cclo"(*b));
+  return a;
+}
+
+int test_ccmi(int a, int* b) {
+// CHECK-LABEL: @test_ccmi
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@ccmi},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@ccmi"(*b));
+  return a;
+}
+
+int test_ccpl(int a, int* b) {
+// CHECK-LABEL: @test_ccpl
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@ccpl},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@ccpl"(*b));
+  return a;
+}
+
+int test_ccvs(int a, int* b) {
+// CHECK-LABEL: @test_ccvs
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@ccvs},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@ccvs"(*b));
+  return a;
+}
+
+int test_ccvc(int a, int* b) {
+// CHECK-LABEL: @test_ccvc
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@ccvc},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@ccvc"(*b));
+  return a;
+}
+
+int test_cchi(int a, int* b) {
+// CHECK-LABEL: @test_cchi
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@cchi},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@cchi"(*b))

[PATCH] D147218: [OpenMP][Flang][MLIR] Lowering of OpenMP requires directive from parse tree to MLIR

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

Remove checks from lowering that belong in semantic analysis


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147218

Files:
  flang/include/flang/Lower/OpenMP.h
  flang/lib/Lower/Bridge.cpp
  flang/lib/Lower/OpenMP.cpp
  flang/test/Lower/OpenMP/requires-error.f90
  flang/test/Lower/OpenMP/requires-notarget.f90
  flang/test/Lower/OpenMP/requires.f90

Index: flang/test/Lower/OpenMP/requires.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires.f90
@@ -0,0 +1,14 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks the lowering of requires into MLIR
+
+!CHECK:  module attributes {
+!CHECK-SAME: omp.atomic_default_mem_order = #omp
+!CHECK-SAME: omp.requires = #omp
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
+
+subroutine f
+  !$omp declare target
+end subroutine f
Index: flang/test/Lower/OpenMP/requires-notarget.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires-notarget.f90
@@ -0,0 +1,12 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks that requires lowering into MLIR skips creating the
+! omp.requires attribute with target-related clauses if there are no device
+! functions in the compilation unit
+
+!CHECK:  module attributes {
+!CHECK-SAME: omp.atomic_default_mem_order = #omp
+!CHECK-NOT:  omp.requires
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
Index: flang/test/Lower/OpenMP/requires-error.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires-error.f90
@@ -0,0 +1,15 @@
+! RUN: not %flang_fc1 -emit-fir -fopenmp %s -o - 2>&1 | FileCheck %s
+
+! This test checks that requires lowering into MLIR skips creating the
+! omp.requires attribute with target-related clauses if there are no device
+! functions in the compilation unit
+
+!CHECK:  error: {{.*}} conflicting atomic_default_mem_order clause found:
+!CHECK-SAME: acq_rel != seq_cst
+program requires
+  !$omp requires atomic_default_mem_order(seq_cst)
+end program requires
+
+subroutine f()
+  !$omp requires atomic_default_mem_order(acq_rel)
+end subroutine f
Index: flang/lib/Lower/OpenMP.cpp
===
--- flang/lib/Lower/OpenMP.cpp
+++ flang/lib/Lower/OpenMP.cpp
@@ -24,7 +24,9 @@
 #include "flang/Semantics/tools.h"
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/Dialect/SCF/IR/SCF.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include 
 
 using namespace mlir;
 
@@ -2239,11 +2241,13 @@
   converter.bindSymbol(sym, symThreadprivateExv);
 }
 
-void handleDeclareTarget(Fortran::lower::AbstractConverter &converter,
- Fortran::lower::pft::Evaluation &eval,
- const Fortran::parser::OpenMPDeclareTargetConstruct
- &declareTargetConstruct) {
-  llvm::SmallVector symbols;
+/// Extract the list of function and variable symbols affected by the given
+/// 'declare target' directive and return the intended device type for them.
+static mlir::omp::DeclareTargetDeviceType getDeclareTargetInfo(
+Fortran::lower::pft::Evaluation &eval,
+const Fortran::parser::OpenMPDeclareTargetConstruct &declareTargetConstruct,
+SmallVectorImpl &symbols) {
+  // Gather the symbols
   auto findFuncAndVarSyms = [&](const Fortran::parser::OmpObjectList &objList) {
 for (const auto &ompObject : objList.v) {
   Fortran::common::visit(
@@ -2261,12 +2265,11 @@
 }
   };
 
+  // The default capture type
+  auto deviceType = Fortran::parser::OmpDeviceTypeClause::Type::Any;
   const auto &spec{std::get(
   declareTargetConstruct.t)};
-  auto mod = converter.getFirOpBuilder().getModule();
 
-  // The default capture type
-  auto deviceType = Fortran::parser::OmpDeviceTypeClause::Type::Any;
   if (const auto *objectList{
   Fortran::parser::Unwrap(spec.u)}) {
 // Case: declare target(func, var1, var2)
@@ -2288,8 +2291,7 @@
  std::get_if(
  &clause.u)}) {
 // Case: declare target link(var1, var2)...
-TODO(converter.getCurrentLocation(),
- "the link clause is currently unsupported");
+TODO_NOLOC("the link clause is currently unsupported");
   } else if (const auto *deviceClause{
  std::get_if(
  &clause.u)}) {
@@ -2299,6 +2301,24 @@
 }
   }
 
+  switch (deviceType) {
+  case Fortran::parser::OmpDeviceTypeClause::Type::Any:
+return mlir::

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

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



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:3150
+  SMLoc Loc = Operands[1]->getStartLoc();
+  return Error(Loc, "'rs1' and 'rs2' mast be different.");
+}

mast -> must


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] D149314: [RISCV] Remove support for attribute interrupt("user").

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

In D149314#4302342 , @asb wrote:

> In D149314#4302312 , @reames wrote:
>
>> In D149314#4302300 , 
>> @aaron.ballman wrote:
>>
>>> In D149314#4302266 , @asb wrote:
>>>
 In D149314#4302203 , 
 @aaron.ballman wrote:

> Is this a potentially breaking change that we need to call out for users 
> to be aware of?

 We should mention this in the Clang release notes I think.
>>>
>>> Beyond that, we've got a process for what to do when considering 
>>> potentially breaking changes, we should be following that: 
>>> https://llvm.org/docs/DeveloperPolicy.html#making-potentially-breaking-changes
>>>  Also, if we're all agreed this is potentially breaking, it really should 
>>> have more review time and buy-in from the code owner.
>>
>> I don't think this change should count as "potentially breaking" in the 
>> sense of that document.  We're talking about an experimental feature for an 
>> experimental ISA extension which never got to ratification.  There's no 
>> hardware in the wild which implements this (to my knowledge).  Given the 
>> churn on the RISCV extension side, we've adopted a policy for experimental 
>> extensions (https://llvm.org/docs/RISCVUsage.html#experimental-extensions) 
>> which offers much less in the way of support.  I think we should release 
>> note it just to be friendly, but the process described in your link is 
>> significant overkill.
>
> +1 on this. The upstream (RISC-V side) process for the ISA extension 
> lifecycle and their ratification is now properly established, and we gate 
> not-yet-ratified things behind `-menable-experimental-extensions` going 
> forward. This review perhaps could have been held open a bit longer to check 
> there's no concerns, and thanks to Aaron for raising the question. But I 
> think a release note only is the appropriate option here.

SGTM, thank you for the discussion!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D149301: [clang] Fix a crash with parenthesized aggregate initialization and base classes

2023-04-27 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, good catch! I think you should add a release note for this when landing, 
and this seems pretty reasonable to consider backporting to 16.x, WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149301

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


[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

2023-04-27 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added inline comments.



Comment at: clang/test/Frontend/backend-attribute-error-warning-optimize.c:12
   foo(); // expected-error {{call to 'foo' declared with 'error' attribute: oh 
no foo}}
+ // expected-note@* {{In function 'baz'}}
   if (x())

aaron.ballman wrote:
> nickdesaulniers wrote:
> > cjdb wrote:
> > > aaron.ballman wrote:
> > > > nickdesaulniers wrote:
> > > > > nickdesaulniers wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > Instead of allowing this note to appear anywhere in the file, I 
> > > > > > > think it's better to use "bookmark" comments. e.g.,
> > > > > > > ```
> > > > > > > void baz() { // #baz_defn
> > > > > > > }
> > > > > > > 
> > > > > > > void foo() {
> > > > > > >   baz(); // expected-note@#baz_defn {{whatever note text}}
> > > > > > > }
> > > > > > > ```
> > > > > > > so that we're testing where the diagnostic is emitted. (This is 
> > > > > > > especially important given that the changes are about location 
> > > > > > > tracking.)
> > > > > > oh, that's new (to me)! will do
> > > > > It looks like the "bookmarks" don't work because the notes do not 
> > > > > line+col info. They follow the warning/error diagnostic which does, 
> > > > > on the bottom most call site.
> > > > > 
> > > > > The warning is supposed to be emitted on the callsite, not the 
> > > > > definition.
> > > > I still don't think this is reasonable for test coverage because this 
> > > > means we'll accept the note *anywhere* in the file. This makes it much 
> > > > too easy to regress the behavior accidentally (e.g., accidentally emit 
> > > > all the notes on line 1 of the file). I think we need *some* way to 
> > > > nail down where these notes are emitted in the test. However, I might 
> > > > be asking you to solve "please track location information through the 
> > > > backend" for that, so perhaps this isn't a reasonable request?
> > > > 
> > > > Also, CC @cjdb for awareness of how this kind of diagnostic is produced 
> > > > (Chris is working on an idea for how we emit diagnostics so we get 
> > > > better structured information from them, so knowing about this novel 
> > > > approach might impact that idea).
> > > Very interesting, thanks for the heads up! Cross-phase diagnostics are 
> > > definitely something I hadn't considered, and it **does** impact the 
> > > design (but not in a derailing way).
> > I think we're back at "please track location information through the 
> > backend".
> > 
> > That is the tradeoff with this approach; not measurably regressing 
> > performance when these attributes aren't used in source in exchange for 
> > Note diagnostics that lack precise line+col info, but in practice provide 
> > enough info for the user to understand what's going wrong where.
> > 
> > Your call if the tradeoff is worth it.
> Here's my thinking, please correct any misunderstandings I have:
> 
> * This functionality is primarily for use with `_FORTIFY_SOURCE` (but not 
> solely for that purpose), and that's an important security feature used by 
> glibc and the Linux kernel.
> * Security of C and C++ source code is Very Important, especially now that 
> various gov't agencies [1][2] are suggesting to not use C or C++ for new 
> projects specifically because the security posture of the languages and their 
> tools.
> * Therefore, the ergonomics of this functionality are quite important for the 
> intended use cases and the ecosystem as a whole.
> * Emitting only the function name but without location information does not 
> give a good user experience, especially in circumstances where the function 
> has multiple overloads, because it pushes the burden onto the programmer to 
> figure out which functions are actually involved in the call chain. This 
> issue is also present in C because of support for 
> `__attribute__((overloadable))` and is not just a C++ concern.
> * The compile-time performance costs of tracking this location information 
> are roughly 1%, and there are no runtime or binary size overhead costs unless 
> other functionality is enabled (such as emitting debug info).
> * We can determine whether we need to enable this location tracking while 
> building the AST when we see one of these two attributes being used, so we 
> could enable this functionality selectively without burdening the user with 
> enabling it manually via a flag. (We could still consider giving the user a 
> flag to never track this even in the presence of the attributes if a user had 
> a compelling use case for it.)
> 
> If this is all reasonably accurate, I think it's worth seriously considering 
> accepting the costs. I don't want to increase our compile time overhead, but 
> at the same time, if ~1% is a "make or break" amount of compile-time 
> performance to lose, we should be addressing *that* issue rather than 
> hamstringing a user-facing diagnostic feature related to security. It's hard 
> to argue "that CVE was totally worth it because we co

[PATCH] D149193: [Driver] Add -dumpdir and change -gsplit-dwarf .dwo names for linking

2023-04-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked an inline comment as done.
MaskRay added a comment.

In D149193#4302337 , @scott.linder 
wrote:

> In D149193#4300885 , @MaskRay wrote:
>
>> I think the patch as-is implements all the useful parts of GCC's complex 
>> rules and in the absence of `-dumpbase` (we deliberately don't implement), 
>> the rule almost exactly matches GCC unless we do `gcc -g -gsplit-dwarf d/a.c 
>> -o e/a.out` (instead of other filenames).
>>
>> https://maskray.me/blog/2023-04-25-compiler-output-files records all my 
>> findings.
>
> I agree that the special-casing of `a.out` when explicitly specified is odd.
>
> Another option to avoid any confusion or debates over exact behavior relative 
> to GCC would be to just make our own option. Rather than add `-dumpdir` we 
> could add `-dump-prefix` or something. I'm also OK with just implementing a 
> simpler subset of the GCC options though (i.e. what you have already).

I have thought about this option, using a name like `--aux-prefix=` (I'd prefer 
aux to dump), but since the behaviors are nearly identical (if we ignore the 
GCC `-o d/a.out` special case), I think using `-dumpdir` is still fine, and 
users won't need to remember two options when they have the needs.

I think the GCC `-o e/a.out` special case is a bug to detect `gcc -g 
-gsplit-dwarf d/a.c` (without `-o`; `a.dwo`). If the bug is fixed, its 
`-dumpdir` behavior should be identical (for all the experiments I have done) 
to what this patch implements.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149193

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


[PATCH] D149301: [clang] Fix a crash with parenthesized aggregate initialization and base classes

2023-04-27 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 517636.
ayzhao added a comment.

add release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149301

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -200,3 +200,26 @@
   // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}}
 }
 }
+
+namespace gh62296 {
+struct L {
+protected:
+  L(int);
+  // expected-note@-1 2{{declared protected here}}
+};
+
+struct M : L {};
+
+struct N {
+  L l;
+};
+
+M m(42);
+// expected-error@-1 {{base class 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a 
parenthesized list of values is a C++20 extension}}
+
+N n(43);
+// expected-error@-1 {{field of type 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a 
parenthesized list of values is a C++20 extension}}
+
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5449,8 +5449,9 @@
   } else if (auto *RT = Entity.getType()->getAs()) {
 const CXXRecordDecl *RD = cast(RT->getDecl());
 
-auto BaseRange = map_range(RD->bases(), [&S](auto &base) {
-  return InitializedEntity::InitializeBase(S.getASTContext(), &base, 
false);
+auto BaseRange = map_range(RD->bases(), [&](auto &base) {
+  return InitializedEntity::InitializeBase(S.getASTContext(), &base, false,
+   &Entity);
 });
 auto FieldRange = map_range(RD->fields(), [](auto *field) {
   return InitializedEntity::InitializeMember(field);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -331,6 +331,9 @@
   constructor declaration.
   (`#62361 `_)
   (`#62362 `_)
+- Fix crash when attempting to perform parenthesized initialization of an
+  aggregate with a base class with only non-public constructors.
+  (`#62296 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -200,3 +200,26 @@
   // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}}
 }
 }
+
+namespace gh62296 {
+struct L {
+protected:
+  L(int);
+  // expected-note@-1 2{{declared protected here}}
+};
+
+struct M : L {};
+
+struct N {
+  L l;
+};
+
+M m(42);
+// expected-error@-1 {{base class 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a parenthesized list of values is a C++20 extension}}
+
+N n(43);
+// expected-error@-1 {{field of type 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a parenthesized list of values is a C++20 extension}}
+
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5449,8 +5449,9 @@
   } else if (auto *RT = Entity.getType()->getAs()) {
 const CXXRecordDecl *RD = cast(RT->getDecl());
 
-auto BaseRange = map_range(RD->bases(), [&S](auto &base) {
-  return InitializedEntity::InitializeBase(S.getASTContext(), &base, false);
+auto BaseRange = map_range(RD->bases(), [&](auto &base) {
+  return InitializedEntity::InitializeBase(S.getASTContext(), &base, false,
+   &Entity);
 });
 auto FieldRange = map_range(RD->fields(), [](auto *field) {
   return InitializedEntity::InitializeMember(field);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -331,6 +331,9 @@
   constructor declaration.
   (`#62361 `_)
   (`#62362 `_)
+- Fix crash when attempting to perform parenthesized initialization of an
+  aggregate with a base class with only non-public constructors.
+  (`#62296 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits m

[PATCH] D149301: [clang] Fix a crash with parenthesized aggregate initialization and base classes

2023-04-27 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added a comment.

In D149301#4302621 , @aaron.ballman 
wrote:

> I think you should add a release note for this when landing,

Done

> and this seems pretty reasonable to consider backporting to 16.x, WDYT?

Agreed, given that this is a crash.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149301

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


[clang] 7417e9d - [clang] Fix a crash with parenthesized aggregate initialization and base classes

2023-04-27 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-04-27T10:43:16-07:00
New Revision: 7417e9d75c9af7dd0d3dad12eebdee84b10b56d7

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

LOG: [clang] Fix a crash with parenthesized aggregate initialization and base 
classes

When calling InitializeBase(...), TryOrBuidlParenListInit(...) needs to
pass in the parent entity; otherwise, we erroneously try to cast
CurContext to a CXXConstructorDecl[0], which can't be done since we're
performing aggregate initialization, not constructor initialization.

Field initialization is not affected, but this patch still adds some
tests for it.

Fixes 62296

[0]: 
https://github.com/llvm/llvm-project/blob/33d6bd1c667456f7f4a9d338a7996a30a3af50a3/clang/lib/Sema/SemaAccess.cpp#L1696

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index aff9ce378253..85eb445a8739 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -331,6 +331,9 @@ Bug Fixes in This Version
   constructor declaration.
   (`#62361 `_)
   (`#62362 `_)
+- Fix crash when attempting to perform parenthesized initialization of an
+  aggregate with a base class with only non-public constructors.
+  (`#62296 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 243c3c1c9a4d..c218470d37ae 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5449,8 +5449,9 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 const CXXRecordDecl *RD = cast(RT->getDecl());
 
-auto BaseRange = map_range(RD->bases(), [&S](auto &base) {
-  return InitializedEntity::InitializeBase(S.getASTContext(), &base, 
false);
+auto BaseRange = map_range(RD->bases(), [&](auto &base) {
+  return InitializedEntity::InitializeBase(S.getASTContext(), &base, false,
+   &Entity);
 });
 auto FieldRange = map_range(RD->fields(), [](auto *field) {
   return InitializedEntity::InitializeMember(field);

diff  --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index a5f39ff6c477..c9d73327025c 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -200,3 +200,26 @@ void bar() {
   // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}}
 }
 }
+
+namespace gh62296 {
+struct L {
+protected:
+  L(int);
+  // expected-note@-1 2{{declared protected here}}
+};
+
+struct M : L {};
+
+struct N {
+  L l;
+};
+
+M m(42);
+// expected-error@-1 {{base class 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a 
parenthesized list of values is a C++20 extension}}
+
+N n(43);
+// expected-error@-1 {{field of type 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a 
parenthesized list of values is a C++20 extension}}
+
+}



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


[PATCH] D149301: [clang] Fix a crash with parenthesized aggregate initialization and base classes

2023-04-27 Thread Alan Zhao 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 rG7417e9d75c9a: [clang] Fix a crash with parenthesized 
aggregate initialization and base classes (authored by ayzhao).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149301

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -200,3 +200,26 @@
   // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}}
 }
 }
+
+namespace gh62296 {
+struct L {
+protected:
+  L(int);
+  // expected-note@-1 2{{declared protected here}}
+};
+
+struct M : L {};
+
+struct N {
+  L l;
+};
+
+M m(42);
+// expected-error@-1 {{base class 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a 
parenthesized list of values is a C++20 extension}}
+
+N n(43);
+// expected-error@-1 {{field of type 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a 
parenthesized list of values is a C++20 extension}}
+
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5449,8 +5449,9 @@
   } else if (auto *RT = Entity.getType()->getAs()) {
 const CXXRecordDecl *RD = cast(RT->getDecl());
 
-auto BaseRange = map_range(RD->bases(), [&S](auto &base) {
-  return InitializedEntity::InitializeBase(S.getASTContext(), &base, 
false);
+auto BaseRange = map_range(RD->bases(), [&](auto &base) {
+  return InitializedEntity::InitializeBase(S.getASTContext(), &base, false,
+   &Entity);
 });
 auto FieldRange = map_range(RD->fields(), [](auto *field) {
   return InitializedEntity::InitializeMember(field);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -331,6 +331,9 @@
   constructor declaration.
   (`#62361 `_)
   (`#62362 `_)
+- Fix crash when attempting to perform parenthesized initialization of an
+  aggregate with a base class with only non-public constructors.
+  (`#62296 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -200,3 +200,26 @@
   // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}}
 }
 }
+
+namespace gh62296 {
+struct L {
+protected:
+  L(int);
+  // expected-note@-1 2{{declared protected here}}
+};
+
+struct M : L {};
+
+struct N {
+  L l;
+};
+
+M m(42);
+// expected-error@-1 {{base class 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a parenthesized list of values is a C++20 extension}}
+
+N n(43);
+// expected-error@-1 {{field of type 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a parenthesized list of values is a C++20 extension}}
+
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5449,8 +5449,9 @@
   } else if (auto *RT = Entity.getType()->getAs()) {
 const CXXRecordDecl *RD = cast(RT->getDecl());
 
-auto BaseRange = map_range(RD->bases(), [&S](auto &base) {
-  return InitializedEntity::InitializeBase(S.getASTContext(), &base, false);
+auto BaseRange = map_range(RD->bases(), [&](auto &base) {
+  return InitializedEntity::InitializeBase(S.getASTContext(), &base, false,
+   &Entity);
 });
 auto FieldRange = map_range(RD->fields(), [](auto *field) {
   return InitializedEntity::InitializeMember(field);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -331,6 +331,9 @@
   constructor declaration.
   (`#62361 `_)
   (`#62362 `_)
+- Fix crash when attempting to perform parenthesized initialization of an
+  aggregate with a base class with only non-public constructors.
+  (`#62296 

[clang] d7354fb - Keep multiple-include optimization for null directives

2023-04-27 Thread Aaron Ballman via cfe-commits

Author: Elliot Goodrich
Date: 2023-04-27T13:44:11-04:00
New Revision: d7354fb63471a7a38993280c8264fd8d57432dc7

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

LOG: Keep multiple-include optimization for null directives

The multiple-include optimization allows Clang to avoid opening a
files when they contain #pragma once or a proper include guard.

Both GCC and Microsoft Visual Studio allow null directives outside of
the #ifndef/#endif pair without disabling this multiple-include
optimization. GCC documents this behavior here
https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html.

> There must be no directives outside the controlling directive pair,
> but the null directive (a line containing nothing other than a
> single '#' and possibly whitespace) is permitted.

However, Clang disables the multiple-include optimization when
encountering the null directive.

In particular, this slows down preprocessing of most projects that
depend on boost as many boost libraries depend on the boost
preprocessor library, which contains null directives outside the
include guard on every header file.

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

Added: 
clang/test/Preprocessor/multiple-inclusion-opt.cpp
clang/test/Preprocessor/multiple-inclusion-opt.h

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Lex/MultipleIncludeOpt.h
clang/lib/Lex/PPDirectives.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 85eb445a87392..71b197a2ad297 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,6 +157,8 @@ Non-comprehensive list of changes in this release
 - A new builtin type trait ``__is_trivially_equaltiy_comparable`` has been 
added,
   which checks whether comparing two instances of a type is equivalent to
   ``memcmp(&lhs, &rhs, sizeof(T)) == 0``.
+- Clang now ignores null directives outside of the include guard when deciding
+  whether a file can be enabled for the multiple-include optimization.
 
 New Compiler Flags
 --

diff  --git a/clang/include/clang/Lex/MultipleIncludeOpt.h 
b/clang/include/clang/Lex/MultipleIncludeOpt.h
index 7ceb7e53c75d7..8e570226c4b27 100644
--- a/clang/include/clang/Lex/MultipleIncludeOpt.h
+++ b/clang/include/clang/Lex/MultipleIncludeOpt.h
@@ -108,6 +108,12 @@ class MultipleIncludeOpt {
 ImmediatelyAfterTopLevelIfndef = false;
   }
 
+  /// SetReadToken - Set whether the value of 'ReadAnyTokens'.  Called to
+  /// override when encountering tokens outside of the include guard that have
+  /// no effect if the file in question is is included multiple times (e.g. the
+  /// null directive).
+  void SetReadToken(bool Value) { ReadAnyTokens = Value; }
+
   /// ExpandedMacro - When a macro is expanded with this lexer as the current
   /// buffer, this method is called to disable the MIOpt if needed.
   void ExpandedMacro() { DidMacroExpansion = true; }

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 3132d57a62d3f..7e4ba9851446a 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1177,6 +1177,10 @@ void Preprocessor::HandleDirective(Token &Result) {
 
   switch (Result.getKind()) {
   case tok::eod:
+// Ignore the null directive with regards to the multiple-include
+// optimization, i.e. allow the null directive to appear outside of the
+// include guard and still enable the multiple-include optimization.
+CurPPLexer->MIOpt.SetReadToken(ReadAnyTokensBeforeDirective);
 return;   // null directive.
   case tok::code_completion:
 setCodeCompletionReached();

diff  --git a/clang/test/Preprocessor/multiple-inclusion-opt.cpp 
b/clang/test/Preprocessor/multiple-inclusion-opt.cpp
new file mode 100644
index 0..0da20331fada6
--- /dev/null
+++ b/clang/test/Preprocessor/multiple-inclusion-opt.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -E -P -H %s 2>&1 | grep "multiple-inclusion-opt.h" | count 1
+
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"

diff  --git a/clang/test/Preprocessor/multiple-inclusion-opt.h 
b/clang/test/Preprocessor/multiple-inclusion-opt.h
new file mode 100644
index 0..d346c9d5d22e4
--- /dev/null
+++ b/clang/test/Preprocessor/multiple-inclusion-opt.h
@@ -0,0 +1,18 @@
+# // null directive and comments before include guard
+
+#ifndef MULTIPLE_INCLUSION_OPT
+
+int foo();
+
+// The position of the define should not matter
+#define MULTIPLE_INCLUSION_OPT
+
+int bar();
+
+#endif
+
+#
+#
+/* Two null directives
+   and a multiline comment
+   after the #endif */



_

[PATCH] D147928: [clang] Keep multiple-include optimization for null directives

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd7354fb63471: Keep multiple-include optimization for null 
directives (authored by IncludeGuardian, committed by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147928

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Lex/MultipleIncludeOpt.h
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/multiple-inclusion-opt.cpp
  clang/test/Preprocessor/multiple-inclusion-opt.h


Index: clang/test/Preprocessor/multiple-inclusion-opt.h
===
--- /dev/null
+++ clang/test/Preprocessor/multiple-inclusion-opt.h
@@ -0,0 +1,18 @@
+# // null directive and comments before include guard
+
+#ifndef MULTIPLE_INCLUSION_OPT
+
+int foo();
+
+// The position of the define should not matter
+#define MULTIPLE_INCLUSION_OPT
+
+int bar();
+
+#endif
+
+#
+#
+/* Two null directives
+   and a multiline comment
+   after the #endif */
Index: clang/test/Preprocessor/multiple-inclusion-opt.cpp
===
--- /dev/null
+++ clang/test/Preprocessor/multiple-inclusion-opt.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -E -P -H %s 2>&1 | grep "multiple-inclusion-opt.h" | count 1
+
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1177,6 +1177,10 @@
 
   switch (Result.getKind()) {
   case tok::eod:
+// Ignore the null directive with regards to the multiple-include
+// optimization, i.e. allow the null directive to appear outside of the
+// include guard and still enable the multiple-include optimization.
+CurPPLexer->MIOpt.SetReadToken(ReadAnyTokensBeforeDirective);
 return;   // null directive.
   case tok::code_completion:
 setCodeCompletionReached();
Index: clang/include/clang/Lex/MultipleIncludeOpt.h
===
--- clang/include/clang/Lex/MultipleIncludeOpt.h
+++ clang/include/clang/Lex/MultipleIncludeOpt.h
@@ -108,6 +108,12 @@
 ImmediatelyAfterTopLevelIfndef = false;
   }
 
+  /// SetReadToken - Set whether the value of 'ReadAnyTokens'.  Called to
+  /// override when encountering tokens outside of the include guard that have
+  /// no effect if the file in question is is included multiple times (e.g. the
+  /// null directive).
+  void SetReadToken(bool Value) { ReadAnyTokens = Value; }
+
   /// ExpandedMacro - When a macro is expanded with this lexer as the current
   /// buffer, this method is called to disable the MIOpt if needed.
   void ExpandedMacro() { DidMacroExpansion = true; }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -157,6 +157,8 @@
 - A new builtin type trait ``__is_trivially_equaltiy_comparable`` has been 
added,
   which checks whether comparing two instances of a type is equivalent to
   ``memcmp(&lhs, &rhs, sizeof(T)) == 0``.
+- Clang now ignores null directives outside of the include guard when deciding
+  whether a file can be enabled for the multiple-include optimization.
 
 New Compiler Flags
 --


Index: clang/test/Preprocessor/multiple-inclusion-opt.h
===
--- /dev/null
+++ clang/test/Preprocessor/multiple-inclusion-opt.h
@@ -0,0 +1,18 @@
+# // null directive and comments before include guard
+
+#ifndef MULTIPLE_INCLUSION_OPT
+
+int foo();
+
+// The position of the define should not matter
+#define MULTIPLE_INCLUSION_OPT
+
+int bar();
+
+#endif
+
+#
+#
+/* Two null directives
+   and a multiline comment
+   after the #endif */
Index: clang/test/Preprocessor/multiple-inclusion-opt.cpp
===
--- /dev/null
+++ clang/test/Preprocessor/multiple-inclusion-opt.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -E -P -H %s 2>&1 | grep "multiple-inclusion-opt.h" | count 1
+
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1177,6 +1177,10 @@
 
   switch (Result.getKind()) {
   case tok::eod:
+// Ignore the null directive with regards to the multiple-include
+// optimization, i.e. allow the null directive to appear outside of the
+// include g

  1   2   >