[PATCH] D120217: [clang-format] Add an option to insert braces after control statements

2022-02-21 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.

LGTM!




Comment at: clang/lib/Format/Format.cpp:1850
+  for (FormatToken *Token = Line->First; Token; Token = Token->Next) {
+if (Token->Finalized || Token->BraceCount == 0)
+  continue;

I think that we can skip the whole line if the first token on line is finalized.


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

https://reviews.llvm.org/D120217

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


[PATCH] D119221: [clang][lexer] Allow u8 character literal prefixes in C2x

2022-02-21 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 410236.

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

https://reviews.llvm.org/D119221

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/Lexer.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Lexer/utf8-char-literal.cpp
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -720,7 +720,7 @@
 
   Adding the u8 character prefix
   http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2418.pdf";>N2418
-  No
+  Clang 15
 
 
   Remove support for function definitions with identifier lists
Index: clang/test/Lexer/utf8-char-literal.cpp
===
--- clang/test/Lexer/utf8-char-literal.cpp
+++ clang/test/Lexer/utf8-char-literal.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c2x -DC2X -x c -fsyntax-only -verify %s
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++1z -fsyntax-only -verify %s
 
 int array0[u'ñ' == u'\xf1'? 1 : -1];
@@ -12,4 +13,16 @@
 char d = u8'\u1234'; // expected-error {{character too large for enclosing character literal type}}
 char e = u8'ሴ'; // expected-error {{character too large for enclosing character literal type}}
 char f = u8'ab'; // expected-error {{Unicode character literals may not contain multiple characters}}
+#elif defined(C2X)
+char a = u8'ñ';  // expected-error {{character too large for enclosing character literal type}}
+char b = u8'\x80';   // ok
+char c = u8'\u0080'; // expected-error {{universal character name refers to a control character}}
+char d = u8'\u1234'; // expected-error {{character too large for enclosing character literal type}}
+char e = u8'ሴ';  // expected-error {{character too large for enclosing character literal type}}
+char f = u8'ab'; // expected-error {{Unicode character literals may not contain multiple characters}}
+_Static_assert(
+_Generic(u8'a',
+ default : 0,
+ unsigned char : 1),
+"Surprise!");
 #endif
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -3551,6 +3551,8 @@
   QualType Ty;
   if (Literal.isWide())
 Ty = Context.WideCharTy; // L'x' -> wchar_t in C and C++.
+  else if (Literal.isUTF8() && getLangOpts().C2x)
+Ty = Context.UnsignedCharTy; // u8'x' -> unsigned char in C2x
   else if (Literal.isUTF8() && getLangOpts().Char8)
 Ty = Context.Char8Ty; // u8'x' -> char8_t when it exists.
   else if (Literal.isUTF16())
@@ -3560,7 +3562,8 @@
   else if (!getLangOpts().CPlusPlus || Literal.isMultiChar())
 Ty = Context.IntTy;   // 'x' -> int in C, 'wxyz' -> int in C++.
   else
-Ty = Context.CharTy;  // 'x' -> char in C++
+Ty = Context.CharTy; // 'x' -> char in C++;
+ // u8'x' -> char in C11-C17 and in C++ without char8_t.
 
   CharacterLiteral::CharacterKind Kind = CharacterLiteral::Ascii;
   if (Literal.isWide())
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -3459,7 +3459,10 @@
 MIOpt.ReadToken();
 return LexNumericConstant(Result, CurPtr);
 
-  case 'u':   // Identifier (uber) or C11/C++11 UTF-8 or UTF-16 string literal
+  // Identifer (e.g., uber), or
+  // UTF-8 (C2x/C++17) or UTF-16 (C11/C++11) character literal, or
+  // UTF-8 or UTF-16 string literal (C11/C++11).
+  case 'u':
 // Notify MIOpt that we read a non-whitespace/non-comment token.
 MIOpt.ReadToken();
 
@@ -3493,7 +3496,7 @@
ConsumeChar(ConsumeChar(CurPtr, SizeTmp, Result),
SizeTmp2, Result),
tok::utf8_string_literal);
-if (Char2 == '\'' && LangOpts.CPlusPlus17)
+if (Char2 == '\'' && (LangOpts.CPlusPlus17 || LangOpts.C2x))
   return LexCharConstant(
   Result, ConsumeChar(ConsumeChar(CurPtr, SizeTmp, Result),
   SizeTmp2, Result),
@@ -3517,7 +3520,7 @@
 // treat u like the start of an identifier.
 return LexIdentifierContinue(Result, CurPtr);
 
-  case 'U':   // Identifier (Uber) or C11/C++11 UTF-32 string literal
+  case 'U': // Identifier (e.g. Uber) or C11/C++11 UTF-32 string literal
 // Notify MIOpt that we read a non-whitespace/non-comment token.
 MIOpt.ReadToken();
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -101,6 +101,7 @@
 ---
 
 - Imple

[PATCH] D119221: [clang][lexer] Allow u8 character literal prefixes in C2x

2022-02-21 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/test/Lexer/utf8-char-literal.cpp:24
+char g = u8'\x80';  // expected-warning {{implicit conversion from 
'int' to 'char' changes value from 128 to -128}}
 #endif

tahonermann wrote:
> We should also exercise the preprocessor with something like this:
>   #if u8'\xff' != 0xff
>   #error uh oh
>   #endif
> 
> Hmm, this currently fails for C++20 for both Clang and gcc unless 
> `-funsigned-char` is passed. That seems wrong. 
> https://godbolt.org/z/Tb7z85ToG. MSVC gets this wrong too, but I think for a 
> different reason; see the implementation impact section of [[ 
> https://wg21.link/p2029 | P2029 ]] if curious.
This also fails in C2x.


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

https://reviews.llvm.org/D119221

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


[PATCH] D95588: [RISCV] Implement the MC layer support of P extension

2022-02-21 Thread Jim Lin via Phabricator via cfe-commits
Jim marked 2 inline comments as done.
Jim added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoP.td:909
+
+// kmar64 has a aliased instruction kmada32 belong to zpn sub-extension on 
RV64.
+let DecoderNamespace = "RISCV32Zpsfoperand_",

Jim wrote:
> jrtc27 wrote:
> > Having the same instruction in two different extensions under two different 
> > names is insane. Currently this implementation lets you use the "wrong" 
> > name for kmar64 with Zpn. But I would prefer the spec weren't crazy.
> I am still working on fixing it (from spec or ...) . But it is spec issue.
Remove alias inst first. I will discuss with P-extension maintainer on this 
issue.
Could this issue be fixed by a future revision?



Comment at: llvm/lib/Target/RISCV/RISCVRegisterInfo.td:228
+
+def GPR32Pair : RegisterClass<"RISCV", [untyped], 64, (add GPR32Pairs)> {
+  let Size = 64;

jrtc27 wrote:
> Jim wrote:
> > jrtc27 wrote:
> > > Why is this untyped?
> > GPR32Pair has untyped type. 
> > In code generation, It captures some operation with i64 type supported by 
> > Zpsoperand to untyped during legalization. 
> > In my mind, untyped is used to be represented special type don't need any 
> > legalization.
> > I refer to ARMRegisterInfo.td that defines GPRPair with untyped.
> So, presumably it can't be i64 because that would then make i64 a legal type? 
> Maybe that's fine, maybe it's not, but alternatively it could be typed as 
> v2i32 here (can include v4i16 and v8i8 too) and cast if/when needed. Craig 
> maybe you have thoughts on this? But untyped always feels like laziness to me 
> that results in TableGen being unable to help you when it comes to type 
> checking, with rare exceptions.
All of operation node having untyped operands are customized SDNode lowered in 
RISCVISelLowering.cpp.  And matched to a specific pattern. 
untyped couldn't be as v2i32, v4i16 or v8i8 in the same time. The operand type 
has been checked in custom lowering.

The lowering for operation with specific operand types (v2i32, v4i16, v8i8 or 
i64 in this case) would be set cutsom and lowered to customized SDNode (This 
SDNode has untyped operands). 
Different operand types with the same operation are lowered to different 
customized SDNode.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95588

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


[PATCH] D95588: [RISCV] Implement the MC layer support of P extension

2022-02-21 Thread Jim Lin via Phabricator via cfe-commits
Jim marked an inline comment as done.
Jim added inline comments.



Comment at: llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int.ll:4360
 ; LMULMAX1-RV64-NEXT:vid.v v10
+; LMULMAX1-RV64-NEXT:vadd.vi v11, v10, 2
+; LMULMAX1-RV64-NEXT:lui a2, %hi(.LCPI132_2)

The change for this testcase is that GPRJALR regclass is subsumed by 
GPR32Pair_with_gpr32_pair_lo_in_GPRNoX0X2 regclass.
And register pressure calculation is different.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95588

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


[clang] ab28488 - [C++20][Modules][1/8] Track valid import state.

2022-02-21 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-02-21T09:09:37Z
New Revision: ab28488efe6de6f8fa856a1dfd8c0320d41d7608

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

LOG: [C++20][Modules][1/8] Track valid import state.

In C++20 modules imports must be together and at the start of the module.
Rather than growing more ad-hoc flags to test state, this keeps track of the
phase of of a valid module TU (first decl, global module frag, module,
private module frag).  If the phasing is broken (with some diagnostic) the
pattern does not conform to a valid C++20 module, and we set the state
accordingly.

We can thus issue diagnostics when imports appear in the wrong places and
decouple the C++20 modules state from other module variants (modules-ts and
clang modules).  Additionally, we attempt to diagnose wrong imports before
trying to find the module where possible (the latter will generally emit an
unhelpful diagnostic about the module not being available).

Although this generally simplifies the handling of C++20 module import
diagnostics, the motivation was that, in particular, it allows detecting
invalid imports like:

import module A;

int some_decl();

import module B;

where being in a module purview is insufficient to identify them.

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

Added: 
clang/test/Modules/cxx20-import-diagnostics-a.cpp

Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/Interpreter/IncrementalParser.cpp
clang/lib/Parse/ParseAST.cpp
clang/lib/Parse/ParseObjc.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaModule.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index e23810f402365..f21e841bcdd38 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1539,6 +1539,10 @@ def err_private_module_fragment_expected_semi : Error<
 def err_missing_before_module_end : Error<"expected %0 at end of module">;
 def err_unsupported_module_partition : Error<
   "sorry, module partitions are not yet supported">;
+def err_import_not_allowed_here : Error<
+  "imports must immediately follow the module declaration">;
+def err_import_in_wrong_fragment : Error<
+  "module%select{| partition}0 imports cannot be in the 
%select{global|private}1 module fragment">;
 
 def err_export_empty : Error<"export declaration cannot be empty">;
 }

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 981800a7e2356..08d492a7ec721 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -464,14 +464,17 @@ class Parser : public CodeCompletionHandler {
   void Initialize();
 
   /// Parse the first top-level declaration in a translation unit.
-  bool ParseFirstTopLevelDecl(DeclGroupPtrTy &Result);
+  bool ParseFirstTopLevelDecl(DeclGroupPtrTy &Result,
+  Sema::ModuleImportState &ImportState);
 
   /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if
   /// the EOF was encountered.
-  bool ParseTopLevelDecl(DeclGroupPtrTy &Result, bool IsFirstDecl = false);
+  bool ParseTopLevelDecl(DeclGroupPtrTy &Result,
+ Sema::ModuleImportState &ImportState);
   bool ParseTopLevelDecl() {
 DeclGroupPtrTy Result;
-return ParseTopLevelDecl(Result);
+Sema::ModuleImportState IS = Sema::ModuleImportState::NotACXX20Module;
+return ParseTopLevelDecl(Result, IS);
   }
 
   /// ConsumeToken - Consume the current 'peek token' and lex the next one.
@@ -3491,8 +3494,9 @@ class Parser : public CodeCompletionHandler {
 
   
//======//
   // Modules
-  DeclGroupPtrTy ParseModuleDecl(bool IsFirstDecl);
-  Decl *ParseModuleImport(SourceLocation AtLoc);
+  DeclGroupPtrTy ParseModuleDecl(Sema::ModuleImportState &ImportState);
+  Decl *ParseModuleImport(SourceLocation AtLoc,
+  Sema::ModuleImportState &ImportState);
   bool parseMisplacedModuleImport();
   bool tryParseMisplacedModuleImport() {
 tok::TokenKind Kind = Tok.getKind();

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c1e846c55dee7..dfa12ad40b72a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2949,11 +2949,24 @@ class Sema final {
 Implementation, ///< 'module X;'
   };
 
+  /// An enumeration to represent the transition of states in parsing module
+  /// fragments and imports.  If we are not parsing a C+

[PATCH] D118196: [syntax][pseudo] Implement LR parsing table.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks, I really like the way the tests look now!




Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:78
+  Shift,
+  // Reduce by a rule, the value is a ruleID.
+  Reduce,

// Pops 



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h:80
+  Reduce,
+  // Signals that we have parsd the input successfully.
+  Accept,

parsd -> parsed



Comment at: clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp:28
+  case LRTable::Action::GoTo:
+return OS << llvm::formatv("goTo state {0}", A.getGoToState());
+  case LRTable::Action::Accept:

nit: goTo -> go to, like dumpForTests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118196

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


[PATCH] D120236: Add more sources to Taint analysis

2022-02-21 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 created this revision.
gamesh411 added a reviewer: steakhal.
Herald added subscribers: martong, Szelethus, dkrupp.
Herald added a reviewer: Szelethus.
gamesh411 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add more functions as taint sources to GenericTaintChecker.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120236

Files:
  clang/docs/analyzer/checkers.rst
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/test/Analysis/taint-generic.c

Index: clang/test/Analysis/taint-generic.c
===
--- clang/test/Analysis/taint-generic.c
+++ clang/test/Analysis/taint-generic.c
@@ -352,6 +352,119 @@
   return 1 / x; // expected-warning {{Division by a tainted value, possibly zero}}
 }
 
+int scanf_s(const char *format, ...);
+int scanf_s_is_source(int *out) {
+  scanf_s("%d", out);
+  return 1 / *out; // expected-warning {{Division by a tainted value, possibly zero}}
+}
+
+int getopt(int argc, char *const argv[], const char *optstring);
+int getopt_is_source(int argc, char **argv) {
+  int opt = getopt(argc, argv, "nt:");
+  return 1 / opt; // expected-warning {{Division by a tainted value, possibly zero}}
+}
+
+struct option {
+  const char *name;
+  int has_arg;
+  int *flag;
+  int val;
+};
+int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex);
+int getopt_long_is_source(int argc, char **argv) {
+  int option_index = 0;
+  struct option long_opts[] = {{0, 0, 0, 0}};
+  int opt = getopt_long(argc, argv, "a:b:02", long_opts, &option_index);
+  return 1 / opt; // expected-warning {{Division by a tainted value, possibly zero}}
+}
+
+int getopt_long_only(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex);
+int getopt_long_only_is_source(int argc, char **argv) {
+  int option_index = 0;
+  struct option long_opts[] = {{0, 0, 0, 0}};
+  int opt = getopt_long_only(argc, argv, "a:b:02", long_opts, &option_index);
+  return 1 / opt; // expected-warning {{Division by a tainted value, possibly zero}}
+}
+
+#define _IO_FILE FILE
+int _IO_getc(_IO_FILE *__fp);
+int underscore_IO_getc_is_source(_IO_FILE *fp) {
+  char c = _IO_getc(fp);
+  return 1 / c; // expected-warning {{Division by a tainted value, possibly zero}}
+}
+
+char *getcwd(char *buf, size_t size);
+int getcwd_is_source(char *buf, size_t size) {
+  char *c = getcwd(buf, size);
+  return system(c); // expected-warning {{Untrusted data is passed to a system call}}
+}
+
+char *getwd(char *buf);
+int getwd_is_source(char *buf) {
+  char *c = getwd(buf);
+  return system(c); // expected-warning {{Untrusted data is passed to a system call}}
+}
+
+typedef signed long long ssize_t;
+ssize_t readlink(const char *path, char *buf, size_t bufsiz);
+int readlink_is_source(char *path, char *buf, size_t bufsiz) {
+  ssize_t s = readlink(path, buf, bufsiz);
+  system(buf);  // expected-warning {{Untrusted data is passed to a system call}}
+  return 1 / s; // expected-warning {{Division by a tainted value, possibly zero}}
+}
+
+char *get_current_dir_name(void);
+int get_current_dir_name_is_source() {
+  char *d = get_current_dir_name();
+  return system(d); // expected-warning {{Untrusted data is passed to a system call}}
+}
+
+int gethostname(char *name, size_t len);
+int gethostname_is_source(char *name, size_t len) {
+  gethostname(name, len);
+  return system(name); // expected-warning {{Untrusted data is passed to a system call}}
+}
+
+struct sockaddr;
+typedef size_t socklen_t;
+int getnameinfo(const struct sockaddr *restrict addr, socklen_t addrlen,
+   char *restrict host, socklen_t hostlen,
+   char *restrict serv, socklen_t servlen, int flags);
+int getnameinfo_is_source(const struct sockaddr *restrict addr, socklen_t addrlen,
+   char *restrict host, socklen_t hostlen,
+   char *restrict serv, socklen_t servlen, int flags) {
+  getnameinfo(addr, addrlen, host, hostlen, serv, servlen, flags);
+
+  system(host); // expected-warning {{Untrusted data is passed to a system call}}
+  return system(serv); // expected-warning {{Untrusted data is passed to a system call}}
+}
+
+int getseuserbyname(const char *linuxuser, char **selinuxuser, char **level);
+int getseuserbyname_is_source(const char* linuxuser, char **selinuxuser, char**level) {
+  getseuserbyname(linuxuser, selinuxuser, level);
+  system(selinuxuser[0]); // expected-warning {{Untrusted data is passed to a system call}}
+  return system(level[0]);// expected-warning {{Untrusted data is passed to a system call}}
+}
+
+typedef int gid_t;
+int getgroups(int size, gid_t list[]);
+int getgroups_is_source(int size, gid_t list[]) {
+  getgroups(size, list);
+  return 1 / list[0]; // expected-warning {{Division by a tainted value, possibly zero}}
+}
+
+char *getlogin(vo

[PATCH] D120217: [clang-format] Add an option to insert braces after control statements

2022-02-21 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 410244.
owenpan added a comment.

In `insertBraces()` in `Format.cpp`, skip an annotated line if its first token 
is finalized.


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

https://reviews.llvm.org/D120217

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -19474,6 +19474,7 @@
   CHECK_PARSE_BOOL_FIELD(IndentRequiresClause, "IndentRequires");
   CHECK_PARSE_BOOL(IndentRequiresClause);
   CHECK_PARSE_BOOL(IndentWrappedFunctionNames);
+  CHECK_PARSE_BOOL(InsertBraces);
   CHECK_PARSE_BOOL(KeepEmptyLinesAtTheStartOfBlocks);
   CHECK_PARSE_BOOL(ObjCSpaceAfterProperty);
   CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
@@ -24300,6 +24301,200 @@
   verifyFormat("template  struct Foo {};", Style);
 }
 
+TEST_F(FormatTest, InsertBraces) {
+  FormatStyle Style = getLLVMStyle();
+  Style.InsertBraces = true;
+
+  verifyFormat("// clang-format off\n"
+   "if (a) f();\n"
+   "// clang-format on\n"
+   "if (b) {\n"
+   "  g();\n"
+   "}",
+   "// clang-format off\n"
+   "if (a) f();\n"
+   "// clang-format on\n"
+   "if (b) g();",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  switch (b) {\n"
+   "  case 1:\n"
+   "c = 0;\n"
+   "break;\n"
+   "  default:\n"
+   "c = 1;\n"
+   "  }\n"
+   "}",
+   "if (a)\n"
+   "  switch (b) {\n"
+   "  case 1:\n"
+   "c = 0;\n"
+   "break;\n"
+   "  default:\n"
+   "c = 1;\n"
+   "  }",
+   Style);
+
+  verifyFormat("for (auto node : nodes) {\n"
+   "  if (node) {\n"
+   "break;\n"
+   "  }\n"
+   "}",
+   "for (auto node : nodes)\n"
+   "  if (node)\n"
+   "break;",
+   Style);
+
+  verifyFormat("for (auto node : nodes) {\n"
+   "  if (node)\n"
+   "}",
+   "for (auto node : nodes)\n"
+   "  if (node)",
+   Style);
+
+  verifyFormat("do {\n"
+   "  --a;\n"
+   "} while (a);",
+   "do\n"
+   "  --a;\n"
+   "while (a);",
+   Style);
+
+  verifyFormat("if (i) {\n"
+   "  ++i;\n"
+   "} else {\n"
+   "  --i;\n"
+   "}",
+   "if (i)\n"
+   "  ++i;\n"
+   "else {\n"
+   "  --i;\n"
+   "}",
+   Style);
+
+  verifyFormat("void f() {\n"
+   "  while (j--) {\n"
+   "while (i) {\n"
+   "  --i;\n"
+   "}\n"
+   "  }\n"
+   "}",
+   "void f() {\n"
+   "  while (j--)\n"
+   "while (i)\n"
+   "  --i;\n"
+   "}",
+   Style);
+
+  verifyFormat("f({\n"
+   "  if (a) {\n"
+   "g();\n"
+   "  }\n"
+   "});",
+   "f({\n"
+   "  if (a)\n"
+   "g();\n"
+   "});",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  f();\n"
+   "} else if (b) {\n"
+   "  g();\n"
+   "} else {\n"
+   "  h();\n"
+   "}",
+   "if (a)\n"
+   "  f();\n"
+   "else if (b)\n"
+   "  g();\n"
+   "else\n"
+   "  h();",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  f();\n"
+   "}\n"
+   "// comment\n"
+   "/* comment */",
+   "if (a)\n"
+   "  f();\n"
+   "// comment\n"
+   "/* comment */",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  // foo\n"
+   "  // bar\n"
+   "  f();\n"
+   "}",
+   "if (a)\n"
+   "  // foo\n"
+   "  // bar\n"
+   "  f();",
+   Style);
+
+  verifyFormat("if (a) { // comment\n"
+   "  // comment\n"
+   "  f();\n"
+   "}",
+   "if (a) // comment\n"
+   "  // comment\n"
+   "  f();",
+  

[PATCH] D120217: [clang-format] Add an option to insert braces after control statements

2022-02-21 Thread Owen Pan via Phabricator via cfe-commits
owenpan marked an inline comment as done.
owenpan added inline comments.



Comment at: clang/lib/Format/Format.cpp:1850
+  for (FormatToken *Token = Line->First; Token; Token = Token->Next) {
+if (Token->Finalized || Token->BraceCount == 0)
+  continue;

curdeius wrote:
> I think that we can skip the whole line if the first token on line is 
> finalized.
Good point!


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

https://reviews.llvm.org/D120217

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


[PATCH] D120237: [clang-format][NFC] Simplify if in ContinuationIndenter::addTokenOCL

2022-02-21 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: owenpan, MyDeveloperDay, curdeius.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Setting a boolean within an if and only using it in the very next if is a bit 
confusing. Merge it into one if.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120237

Files:
  clang/lib/Format/ContinuationIndenter.cpp


Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -787,14 +787,12 @@
 //   OuterFunction(InnerFunctionCall( // break
 //   ParameterToInnerFunction))   // break
 //   .SecondInnerFunctionCall();
-bool HasTrailingCall = false;
 if (Previous.MatchingParen) {
   const FormatToken *Next = Previous.MatchingParen->getNextNonComment();
-  HasTrailingCall = Next && Next->isMemberAccess();
+  if (Next && Next->isMemberAccess() && State.Stack.size() > 1 &&
+  State.Stack[State.Stack.size() - 2].CallContinuation == 0)
+CurrentState.LastSpace = State.Column;
 }
-if (HasTrailingCall && State.Stack.size() > 1 &&
-State.Stack[State.Stack.size() - 2].CallContinuation == 0)
-  CurrentState.LastSpace = State.Column;
   }
 }
 


Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -787,14 +787,12 @@
 //   OuterFunction(InnerFunctionCall( // break
 //   ParameterToInnerFunction))   // break
 //   .SecondInnerFunctionCall();
-bool HasTrailingCall = false;
 if (Previous.MatchingParen) {
   const FormatToken *Next = Previous.MatchingParen->getNextNonComment();
-  HasTrailingCall = Next && Next->isMemberAccess();
+  if (Next && Next->isMemberAccess() && State.Stack.size() > 1 &&
+  State.Stack[State.Stack.size() - 2].CallContinuation == 0)
+CurrentState.LastSpace = State.Column;
 }
-if (HasTrailingCall && State.Stack.size() > 1 &&
-State.Stack[State.Stack.size() - 2].CallContinuation == 0)
-  CurrentState.LastSpace = State.Column;
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120196: [clang-tidy][NFC] Remove Tristate from CachedGlobList

2022-02-21 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz accepted this revision.
salman-javed-nz added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120196

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


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2022-02-21 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

Because I happened to also run into this, reduced IR for `-mtriple=riscv32 
-mattr=+d` is:

  define float @test(float %x) {
%1 = tail call float asm sideeffect alignstack "mv a0, a0", 
"={x10},{x10}"(float 0.00e+00)
ret float 0.00e+00
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93298

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


[clang] b32ead4 - Increase the limit on parser diagnostics

2022-02-21 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2022-02-21T11:44:48+01:00
New Revision: b32ead41b16af993918b14b243d08d04dcdcd4c9

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

LOG: Increase the limit on parser diagnostics

We're really close to the limit
$ grep -c DIAG tools/clang/include/clang/Basic/DiagnosticParseKinds.inc
598

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticIDs.h

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index ba5f5acc8ce6..8139ffd375a2 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -34,7 +34,7 @@ namespace clang {
   DIAG_SIZE_FRONTEND  =  150,
   DIAG_SIZE_SERIALIZATION =  120,
   DIAG_SIZE_LEX   =  400,
-  DIAG_SIZE_PARSE =  600,
+  DIAG_SIZE_PARSE =  700,
   DIAG_SIZE_AST   =  250,
   DIAG_SIZE_COMMENT   =  100,
   DIAG_SIZE_CROSSTU   =  100,



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


[PATCH] D116290: [clang-format] Add enforcement of consistent `class`/typename` keyword for template arguments

2022-02-21 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang added a comment.

> Will you still work on this?

I don't know. I currently have more high-priority work, and don't know 
whether/when I will find time for this review again.
Also, I realized that I will have to read up more about class-template 
parameters, e.g. I don't quite understand 
https://quuxplusone.github.io/blog/2019/12/27/template-typename-fun/, yet.

So, if you are asking to figure out if you should still review this in more 
detail: No, for the time being you should not.
If you are asking because you would like to take over this commit and finish it 
so that it can land: Yes, I would be happy to hand this over


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116290

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


[PATCH] D119599: [clang-format] Add option to align compound assignments like `+=`

2022-02-21 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 410271.
sstwcw retitled this revision from "Add option to align compound assignments 
like `+=`" to "[clang-format] Add option to align compound assignments like 
`+=`".
sstwcw added a comment.
Herald added subscribers: llvm-commits, dexonsmith.
Herald added a project: LLVM.

Use struct for the alignment options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119599

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestJS.cpp
  llvm/docs/YamlIO.rst
  llvm/include/llvm/Support/YAMLTraits.h

Index: llvm/include/llvm/Support/YAMLTraits.h
===
--- llvm/include/llvm/Support/YAMLTraits.h
+++ llvm/include/llvm/Support/YAMLTraits.h
@@ -63,6 +63,7 @@
   // static void mapping(IO &io, T &fields);
   // Optionally may provide:
   // static std::string validate(IO &io, T &fields);
+  // static void enumInput(IO &io, T &value);
   //
   // The optional flow flag will cause generated YAML to use a flow mapping
   // (e.g. { a: 0, b: 1 }):
@@ -446,6 +447,31 @@
   static bool const value = (sizeof(test>(nullptr)) == 1);
 };
 
+// Test if MappingContextTraits::enumInput() is defined on type T.
+template  struct has_MappingEnumInputTraits {
+  using Signature_validate = void (*)(class IO &, T &);
+
+  template 
+  static char test(SameType *);
+
+  template  static double test(...);
+
+  static bool const value =
+  (sizeof(test>(nullptr)) == 1);
+};
+
+// Test if MappingTraits::enumInput() is defined on type T.
+template  struct has_MappingEnumInputTraits {
+  using Signature_validate = void (*)(class IO &, T &);
+
+  template 
+  static char test(SameType *);
+
+  template  static double test(...);
+
+  static bool const value = (sizeof(test>(nullptr)) == 1);
+};
+
 // Test if SequenceTraits is defined on type T.
 template 
 struct has_SequenceMethodTraits
@@ -1061,20 +1087,45 @@
 io.endMapping();
 }
 
+#define MAPPING_COMMON()   \
+  do { \
+if (has_FlowTraits>::value) { \
+  io.beginFlowMapping();   \
+  detail::doMapping(io, Val, Ctx); \
+  io.endFlowMapping(); \
+} else {   \
+  io.beginMapping();   \
+  detail::doMapping(io, Val, Ctx); \
+  io.endMapping(); \
+}  \
+  } while (false)
+
 template 
-std::enable_if_t::value, void>
+std::enable_if_t::value &&
+ has_MappingEnumInputTraits::value,
+ void>
 yamlize(IO &io, T &Val, bool, Context &Ctx) {
-  if (has_FlowTraits>::value) {
-io.beginFlowMapping();
-detail::doMapping(io, Val, Ctx);
-io.endFlowMapping();
-  } else {
-io.beginMapping();
-detail::doMapping(io, Val, Ctx);
-io.endMapping();
+  if (!io.outputting()) {
+io.beginEnumScalar();
+MappingTraits::enumInput(io, Val);
+bool Matched = !io.matchEnumFallback();
+io.endEnumScalar();
+if (Matched)
+  return;
   }
+  MAPPING_COMMON();
 }
 
+template 
+std::enable_if_t::value &&
+ !has_MappingEnumInputTraits::value,
+ void>
+yamlize(IO &io, T &Val, bool, Context &Ctx) {
+  MAPPING_COMMON();
+}
+
+#undef MAPPING_COMMON
+
 template 
 std::enable_if_t::value, void>
 yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
Index: llvm/docs/YamlIO.rst
===
--- llvm/docs/YamlIO.rst
+++ llvm/docs/YamlIO.rst
@@ -551,6 +551,43 @@
   }
 };
 
+There are circumstances where we want to allow the entire mapping to be
+read as an enumeration.  For example, say some configuration option
+started as an enumeration.  Then it got more complex so it is now a
+mapping.  But it is necessary to support the old configuration files.
+In that case, add a function ``enumInput`` like for
+``ScalarEnumerationTraits::enumeration``.  Examples:
+
+.. code-block:: c++
+
+template <> struct MappingTraits {
+  static void enumInput(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) {
+IO.enumCase(Value, "None", FormatStyle::AlignConsecutiveStyle({}));
+IO.enumCase(Value, "Consecutive",
+FormatStyle::AlignConsecutiveStyle({

[PATCH] D113545: [C++20] [Module] Support reachable definition initially/partially

2022-02-21 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 410270.
ChuanqiXu edited the summary of this revision.
ChuanqiXu added a reviewer: iains.
ChuanqiXu added a comment.

Implement reachable definition initially/partially.


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

https://reviews.llvm.org/D113545

Files:
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Basic/Module.h
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  
clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/Inputs/Friend-in-reachable-class.cppm
  
clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4-friend-in-reachable-class.cpp
  clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
  clang/test/CXX/module/module.interface/Inputs/p7.cppm
  clang/test/CXX/module/module.interface/p2.cpp
  clang/test/CXX/module/module.interface/p7.cpp
  clang/test/CXX/module/module.reach/Inputs/p4/bar.cppm
  clang/test/CXX/module/module.reach/Inputs/p4/foo.cppm
  clang/test/CXX/module/module.reach/Inputs/p5-A.cppm
  clang/test/CXX/module/module.reach/p4/TransitiveImport.cpp
  clang/test/CXX/module/module.reach/p5.cpp
  clang/test/CXX/module/module.unit/p7/t6.cpp
  clang/test/Modules/Inputs/Reachability-Private/Private.cppm
  clang/test/Modules/Inputs/Reachability-func-default-arg/func_default_arg.cppm
  clang/test/Modules/Inputs/Reachability-func-ret/func_ret.cppm
  
clang/test/Modules/Inputs/Reachability-template-default-arg/template_default_arg.cppm
  clang/test/Modules/Inputs/Reachability-template-instantiation/Templ.cppm
  clang/test/Modules/Inputs/Reachability-template-instantiation/Templ.h
  clang/test/Modules/Inputs/Reachability-template-instantiation/Use.cppm
  clang/test/Modules/Inputs/Reachability-using-templates/mod-templates.cppm
  clang/test/Modules/Inputs/Reachability-using/mod.cppm
  clang/test/Modules/Inputs/derived_class/bar.h
  clang/test/Modules/Inputs/derived_class/foo.cppm
  clang/test/Modules/Inputs/explicitly-specialized-template/X.cppm
  clang/test/Modules/Inputs/explicitly-specialized-template/foo.h
  clang/test/Modules/Inputs/template-function-specialization/foo.cppm
  clang/test/Modules/Inputs/template_default_argument/B.cppm
  clang/test/Modules/Inputs/template_default_argument/templ.h
  clang/test/Modules/Reachability-Private.cpp
  clang/test/Modules/Reachability-func-default-arg.cpp
  clang/test/Modules/Reachability-func-ret.cpp
  clang/test/Modules/Reachability-template-default-arg.cpp
  clang/test/Modules/Reachability-template-instantiation.cpp
  clang/test/Modules/Reachability-using-templates.cpp
  clang/test/Modules/Reachability-using.cpp
  clang/test/Modules/derived_class.cpp
  clang/test/Modules/explicitly-specialized-template.cpp
  clang/test/Modules/template-function-specialization.cpp
  clang/test/Modules/template_default_argument.cpp

Index: clang/test/Modules/template_default_argument.cpp
===
--- /dev/null
+++ clang/test/Modules/template_default_argument.cpp
@@ -0,0 +1,9 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %clang -std=c++20 %S/Inputs/template_default_argument/B.cppm --precompile -o %t/B.pcm
+// RUN: %clang -std=c++20 -fprebuilt-module-path=%t %s -c -o -
+// expected-no-diagnostics
+import B;
+auto foo() {
+  return bar();
+}
Index: clang/test/Modules/template-function-specialization.cpp
===
--- /dev/null
+++ clang/test/Modules/template-function-specialization.cpp
@@ -0,0 +1,18 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %S/Inputs/template-function-specialization/foo.cppm -o %t/foo.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %s -verify -fsyntax-only
+import foo;
+void use() {
+  foo();
+  foo();
+  foo2(); // expected-error {{missing '#include'; 'foo2' must be declared before it is used}}
+ // expected-note@* {{declaration here is not visible}}
+  foo2();   // expected-error {{missing '#include'; 'foo2' must be declared before it is used}}
+ // expected-note@* {{declaration here is not visible}}
+  foo3();
+  foo3();
+
+  foo4();
+  foo4();
+}
Index: clang/test/Modules/explicitly-specialized-template.cpp
===
--- /dev/null
+++ clang/test/Modules/explicitly-specialized-template.cpp
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %clang -std=c++20 %S/Inputs/explicitly-specialized-template/X.cppm --precompile -o %t/X.pcm
+// RUN: %clang -std=c++20 -fprebuilt-module-path=%t %s -fsyntax-only -Xclang -verify -o -
+
+im

[PATCH] D113972: [RFC] [C++20] [Module] Support module partitions initially

2022-02-21 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu abandoned this revision.
ChuanqiXu added a subscriber: iains.
ChuanqiXu added a comment.

Now we prefer  @iains's patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113972

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


[PATCH] D118586: [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-21 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

I think it is helpful to add some tests from https://reviews.llvm.org/D113972


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118586

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


[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/AST.cpp:491
+  // We'll examine visible specializations and see if they yield a unique type.
+  bool VisitParmVarDecl(ParmVarDecl *PVD) {
+if (!PVD->getType()->isDependentType())

Trass3r wrote:
> Since this is implemented generically in the AST, can this functionality 
> easily be reused for a type inlay hint?
In principle yes. Rather than expand the scope further, I'll send a followup 
patch.



Comment at: clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp:88
+  StartsWith("fail: Could not deduce"));
+  EXPECT_EQ(apply("auto X = [](^auto){return 0;}; int Y = X(42);"),
+"auto X = [](int){return 0;}; int Y = X(42);");

nridge wrote:
> sammccall wrote:
> > nridge wrote:
> > > Maybe add a conflicting-deduction case? (I know the GetDeducedType test 
> > > already has one, but here it would be especially wrong.)
> > > 
> > > Also, should we perhaps disable this in header files (maybe excepting 
> > > function-local symbols), since an including source file could have 
> > > additional instantiations?
> > > Maybe add a conflicting-deduction case? (I know the GetDeducedType test 
> > > already has one, but here it would be especially wrong.)
> > Done.
> > 
> > > Also, should we perhaps disable this in header files (maybe excepting 
> > > function-local symbols), since an including source file could have 
> > > additional instantiations?
> > 
> > Disabling features in headers seems sad. Detecting when the function is 
> > local doesn't seem like a great solution to this:
> >  - it's going to be hard to detect the common ways functions are hidden 
> > within headers (`detail` namespaces, inaccessible members, ...)
> >  - it's still going to be wrong when some instantiations come via (local) 
> > templates that are themselves instantiated from the including file
> > 
> > I suspect in most cases where multiple instantiations are intended we're 
> > going to see either no instantiations or many. Can we try it and see if 
> > there are false positive complaints?
> To clarify, I meant excepting only cases like this:
> 
> ```
> // header.hpp
> void foo(std::function callback);
> void bar() {
>   // We know this will only be instantiated with ConceteType,
>   // regardless of what an including source file does
>   foo([](auto x){});
> }
> ```
> 
> but I'm sympathetic to the argument that neither false-positives (we offer a 
> refactoring that breaks code) nor false-negative (we fail to offer a 
> refactoring the user wants to make) are super impactful here and so we should 
> do the easier thing (i.e. not try to restrict at all).
OK, will leave the checks out and see how it goes.

(I agree that's probably the most important case, but I haven't worked in a 
c++20 codebase so I don't know how abbreviated function templates will play out)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

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


[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added a comment.

BTW, D120131  demonstrates the other idea of 
actually using the instantiated AST instead of the template.
It's pretty cool but would need some refinement to be production-ready I 
suppose.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

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


[PATCH] D118586: [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-21 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D118586#3335167 , @ChuanqiXu wrote:

> I think it is helpful to add some tests from https://reviews.llvm.org/D113972

Actually, in response to your concerns, this morning I wrote a multi-partition 
test case to add to this (which does pass).

Would you be able to split out the important test cases from D113972 
 as a separate patch ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118586

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


[PATCH] D120244: [clang][sema] Enable first-class bool support for C2x

2022-02-21 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, tahonermann.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This implements N2393.

I am a bit confused by the proposal only taking about adding "true" and "false" 
constants but then still using "bool" as a type. I'm not sure if this part of 
the patch is 100% correct.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120244

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Sema/c2x-bool.c


Index: clang/test/Sema/c2x-bool.c
===
--- /dev/null
+++ clang/test/Sema/c2x-bool.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c2x -x c -fsyntax-only 
-verify %s
+
+_Static_assert(_Generic(true, _Bool : 1, default: 0));
+_Static_assert(_Generic(false, _Bool : 1, default: 0));
+
+_Static_assert(_Generic(true, bool : 1, default: 0));
+_Static_assert(_Generic(false, bool : 1, default: 0));
+
+_Static_assert(_Generic(true, bool : true, default: false));
+_Static_assert(_Generic(false, bool : true, default: false));
+
+_Static_assert(true == (bool)+1);
+_Static_assert(false == (bool)+0);
+
+
+static void *f = false; // expected-warning {{to null from a constant boolean 
expression}}
+static int one = true;
+static int zero = false;
+
+static void do_work() {
+  char *str = "Foo";
+  str[0] = 'f';
+  str[true] = 'f'; // TODO: This should warn(?)
+}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3245,7 +3245,7 @@
   Opts.RenderScript = IK.getLanguage() == Language::RenderScript;
 
   // OpenCL and C++ both have bool, true, false keywords.
-  Opts.Bool = Opts.OpenCL || Opts.CPlusPlus;
+  Opts.Bool = Opts.OpenCL || Opts.CPlusPlus || Opts.C2x;
 
   // OpenCL has half keyword
   Opts.Half = Opts.OpenCL;


Index: clang/test/Sema/c2x-bool.c
===
--- /dev/null
+++ clang/test/Sema/c2x-bool.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c2x -x c -fsyntax-only -verify %s
+
+_Static_assert(_Generic(true, _Bool : 1, default: 0));
+_Static_assert(_Generic(false, _Bool : 1, default: 0));
+
+_Static_assert(_Generic(true, bool : 1, default: 0));
+_Static_assert(_Generic(false, bool : 1, default: 0));
+
+_Static_assert(_Generic(true, bool : true, default: false));
+_Static_assert(_Generic(false, bool : true, default: false));
+
+_Static_assert(true == (bool)+1);
+_Static_assert(false == (bool)+0);
+
+
+static void *f = false; // expected-warning {{to null from a constant boolean expression}}
+static int one = true;
+static int zero = false;
+
+static void do_work() {
+  char *str = "Foo";
+  str[0] = 'f';
+  str[true] = 'f'; // TODO: This should warn(?)
+}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3245,7 +3245,7 @@
   Opts.RenderScript = IK.getLanguage() == Language::RenderScript;
 
   // OpenCL and C++ both have bool, true, false keywords.
-  Opts.Bool = Opts.OpenCL || Opts.CPlusPlus;
+  Opts.Bool = Opts.OpenCL || Opts.CPlusPlus || Opts.C2x;
 
   // OpenCL has half keyword
   Opts.Half = Opts.OpenCL;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] b9b6938 - [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-21 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-02-21T13:24:11+01:00
New Revision: b9b6938183e837e66ff7450fb2b8a73dce5889c0

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

LOG: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

This makes hover/go-to-definition/expand-auto etc work for auto params in many
common cases.
This includes when a generic lambda is passed to a function accepting
std::function. (The tests don't use this case, it requires a lot of setup).

Note that this doesn't affect the AST of the function body itself, cause its
nodes not to be dependent, improve code completion etc.
(These sort of improvements seem possible, in a similar "if there's a single
instantiation, traverse it instead of the primary template" way).

Fixes https://github.com/clangd/clangd/issues/493
Fixes https://github.com/clangd/clangd/issues/1015

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

Added: 


Modified: 
clang-tools-extra/clangd/AST.cpp
clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
clang-tools-extra/clangd/unittests/ASTTests.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp
clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/AST.cpp 
b/clang-tools-extra/clangd/AST.cpp
index b970325098c65..fe9c4c9f0b18a 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -486,6 +486,87 @@ class DeducedTypeVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  // Handle functions/lambdas with `auto` typed parameters.
+  // We'll examine visible specializations and see if they yield a unique type.
+  bool VisitParmVarDecl(ParmVarDecl *PVD) {
+if (!PVD->getType()->isDependentType())
+  return true;
+// 'auto' here does not name an AutoType, but an implicit template param.
+TemplateTypeParmTypeLoc Auto =
+findContainedAutoTTPLoc(PVD->getTypeSourceInfo()->getTypeLoc());
+if (Auto.isNull() || Auto.getNameLoc() != SearchedLocation)
+  return true;
+// We expect the TTP to be attached to this function template.
+// Find the template and the param index.
+auto *FD = llvm::dyn_cast(PVD->getDeclContext());
+if (!FD)
+  return true;
+auto *FTD = FD->getDescribedFunctionTemplate();
+if (!FTD)
+  return true;
+int ParamIndex = paramIndex(*FTD, *Auto.getDecl());
+if (ParamIndex < 0) {
+  assert(false && "auto TTP is not from enclosing function?");
+  return true;
+}
+
+// Now determine the unique type arg among the implicit specializations.
+const ASTContext &Ctx = PVD->getASTContext();
+QualType UniqueType;
+CanQualType CanUniqueType;
+for (const FunctionDecl *Spec : FTD->specializations()) {
+  // Meaning `auto` is a bit overloaded if the function is specialized.
+  if (Spec->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+return true;
+  // Find the type for this specialization.
+  const auto *Args = Spec->getTemplateSpecializationArgs();
+  if (Args->size() != FTD->getTemplateParameters()->size())
+continue; // no weird variadic stuff
+  QualType SpecType = Args->get(ParamIndex).getAsType();
+  if (SpecType.isNull())
+continue;
+
+  // Deduced types need only be *canonically* equal.
+  CanQualType CanSpecType = Ctx.getCanonicalType(SpecType);
+  if (CanUniqueType.isNull()) {
+CanUniqueType = CanSpecType;
+UniqueType = SpecType;
+continue;
+  }
+  if (CanUniqueType != CanSpecType)
+return true; // deduced type is not unique
+}
+DeducedType = UniqueType;
+return true;
+  }
+
+  // Find the abbreviated-function-template `auto` within a type.
+  // Similar to getContainedAutoTypeLoc, but these `auto`s are
+  // TemplateTypeParmTypes for implicit TTPs, instead of AutoTypes.
+  // Also we don't look very hard, just stripping const, references, pointers.
+  // FIXME: handle more types: vector?
+  static TemplateTypeParmTypeLoc findContainedAutoTTPLoc(TypeLoc TL) {
+if (auto QTL = TL.getAs())
+  return findContainedAutoTTPLoc(QTL.getUnqualifiedLoc());
+if (llvm::isa(TL.getTypePtr()))
+  return findContainedAutoTTPLoc(TL.getNextTypeLoc());
+if (auto TTPTL = TL.getAs()) {
+  if (TTPTL.getTypePtr()->getDecl()->isImplicit())
+return TTPTL;
+}
+return {};
+  }
+
+  static int paramIndex(const TemplateDecl &TD, NamedDecl &Param) {
+unsigned I = 0;
+for (auto *ND : *TD.getTemplateParameters()) {
+  if (&Param == ND)
+return I;
+  ++I;
+}
+return -1;
+  }
+
   QualType DeducedType;
 };
 } // namespace

diff  --git a/clang-tools-extra/clangd/refactor/tweaks

[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb9b6938183e8: [clangd] Treat 'auto' params as 
deduced if there's a single instantiation. (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -80,8 +80,18 @@
   EXPECT_THAT(apply("template  void x() { ^auto y = T::z(); }"),
   StartsWith("fail: Could not deduce type for 'auto' type"));
 
-  ExtraArgs.push_back("-std=c++17");
+  ExtraArgs.push_back("-std=c++20");
   EXPECT_UNAVAILABLE("template  class Y;");
+
+  EXPECT_THAT(apply("auto X = [](^auto){};"),
+  StartsWith("fail: Could not deduce"));
+  EXPECT_EQ(apply("auto X = [](^auto){return 0;}; int Y = X(42);"),
+"auto X = [](int){return 0;}; int Y = X(42);");
+  EXPECT_THAT(apply("auto X = [](^auto){return 0;}; int Y = X(42) + X('c');"),
+  StartsWith("fail: Could not deduce"));
+  // FIXME: should work on constrained auto params, once SourceRange is fixed.
+  EXPECT_UNAVAILABLE("template concept C = true;"
+ "auto X = [](C ^auto *){return 0;};");
 }
 
 } // namespace
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -815,6 +815,12 @@
 }
   )cpp",
 
+  R"cpp(// auto lambda param where there's a single instantiation
+struct [[Bar]] {};
+auto Lambda = [](^auto){ return 0; };
+int x = Lambda(Bar{});
+  )cpp",
+
   R"cpp(// decltype(auto) in function return
 struct [[Bar]] {};
 ^decltype(auto) test() {
Index: clang-tools-extra/clangd/unittests/ASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ASTTests.cpp
@@ -179,20 +179,76 @@
   )cpp",
   "Bar",
   },
+  {
+  R"cpp(
+// Generic lambda param.
+struct Foo{};
+auto Generic = [](^auto x) { return 0; };
+int m = Generic(Foo{});
+  )cpp",
+  "struct Foo",
+  },
+  {
+  R"cpp(
+// Generic lambda instantiated twice, matching deduction.
+struct Foo{};
+using Bar = Foo;
+auto Generic = [](^auto x, auto y) { return 0; };
+int m = Generic(Bar{}, "one");
+int n = Generic(Foo{}, 2);
+  )cpp",
+  "struct Foo",
+  },
+  {
+  R"cpp(
+// Generic lambda instantiated twice, conflicting deduction.
+struct Foo{};
+auto Generic = [](^auto y) { return 0; };
+int m = Generic("one");
+int n = Generic(2);
+  )cpp",
+  nullptr,
+  },
+  {
+  R"cpp(
+// Generic function param.
+struct Foo{};
+int generic(^auto x) { return 0; }
+int m = generic(Foo{});
+  )cpp",
+  "struct Foo",
+  },
+  {
+  R"cpp(
+// More complicated param type involving auto.
+template  concept C = true;
+struct Foo{};
+int generic(C ^auto *x) { return 0; }
+const Foo *Ptr = nullptr;
+int m = generic(Ptr);
+  )cpp",
+  "const struct Foo",
+  },
   };
   for (Test T : Tests) {
 Annotations File(T.AnnotatedCode);
-auto AST = TestTU::withCode(File.code()).build();
+auto TU = TestTU::withCode(File.code());
+TU.ExtraArgs.push_back("-std=c++20");
+auto AST = TU.build();
 SourceManagerForFile SM("foo.cpp", File.code());
 
-SCOPED_TRACE(File.code());
+SCOPED_TRACE(T.AnnotatedCode);
 EXPECT_FALSE(File.points().empty());
 for (Position Pos : File.points()) {
   auto Location = sourceLocationInMainFile(SM.get(), Pos);
   ASSERT_TRUE(!!Location) << llvm::toString(Location.takeError());
   auto DeducedType = getDeducedType(AST.getASTContext(), *Location);
-  ASSERT_TRUE(DeducedType);
-  EXPECT_EQ(DeducedType->getAsString(), T.DeducedType);
+  if (T.DeducedType == nullptr) {
+EXPECT_FALSE(DeducedType);
+  } else {
+ASSERT_TRUE(DeducedType);
+  

[PATCH] D118586: [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-21 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D118586#3335191 , @iains wrote:

> In D118586#3335167 , @ChuanqiXu 
> wrote:
>
>> I think it is helpful to add some tests from https://reviews.llvm.org/D113972
>
> Actually, in response to your concerns, this morning I wrote a 
> multi-partition test case to add to this (which does pass).

Thanks. I think it would be helpful to add it here.

> Would you be able to split out the important test cases from D113972 
>  as a separate patch ?

I found the meaningful test case mainly comes from the example in spec. e.g., 
http://eel.is/c++draft/module.unit#4, http://eel.is/c++draft/module.unit#4, 
http://eel.is/c++draft/module.unit#4


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118586

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


[clang] 071a9b7 - [NFC][RISCV] Fix path checking issue if default sysroot is given

2022-02-21 Thread Kito Cheng via cfe-commits

Author: Kito Cheng
Date: 2022-02-21T20:43:51+08:00
New Revision: 071a9b751a46205dc276069dfbc0d38582736990

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

LOG: [NFC][RISCV] Fix path checking issue if default sysroot is given

Added: 


Modified: 
clang/test/Driver/riscv32-toolchain.c
clang/test/Driver/riscv64-toolchain.c

Removed: 




diff  --git a/clang/test/Driver/riscv32-toolchain.c 
b/clang/test/Driver/riscv32-toolchain.c
index 50859aaccd7da..5d65a2e0acd36 100644
--- a/clang/test/Driver/riscv32-toolchain.c
+++ b/clang/test/Driver/riscv32-toolchain.c
@@ -198,14 +198,14 @@
 // C-RV32-RTLIB-COMPILERRT-ILP32: "{{.*}}clang_rt.crtend-riscv32.o"
 
 // RUN: %clang %s -### -no-canonical-prefixes -target riscv32 \
-// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv32_tree \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv32_tree --sysroot= \
 // RUN:   -resource-dir=%s/Inputs/resource_dir 2>&1 \
 // RUN:   | FileCheck -check-prefix=RESOURCE-INC %s
 // RESOURCE-INC: "-internal-isystem" 
"{{.*}}/Inputs/resource_dir{{/|}}include"
 // RESOURCE-INC: "-internal-isystem" 
"{{.*}}/basic_riscv32_tree{{.*}}riscv32-unknown-elf{{/|}}include"
 
 // RUN: %clang %s -### -no-canonical-prefixes -target riscv32 \
-// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv32_tree \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv32_tree --sysroot= \
 // RUN:   -resource-dir=%s/Inputs/resource_dir -nobuiltininc 2>&1 \
 // RUN:   | FileCheck -check-prefix=NO-RESOURCE-INC %s
 // NO-RESOURCE-INC-NOT: "-internal-isystem" 
"{{.*}}/Inputs/resource_dir{{/|}}include"

diff  --git a/clang/test/Driver/riscv64-toolchain.c 
b/clang/test/Driver/riscv64-toolchain.c
index 59580370c0b34..deb8d077ea9e7 100644
--- a/clang/test/Driver/riscv64-toolchain.c
+++ b/clang/test/Driver/riscv64-toolchain.c
@@ -154,14 +154,14 @@
 // C-RV64-RTLIB-COMPILERRT-LP64: "{{.*}}clang_rt.crtend-riscv64.o"
 
 // RUN: %clang %s -### -no-canonical-prefixes -target riscv64 \
-// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree --sysroot= \
 // RUN:   -resource-dir=%s/Inputs/resource_dir 2>&1 \
 // RUN:   | FileCheck -check-prefix=RESOURCE-INC %s
 // RESOURCE-INC: "-internal-isystem" 
"{{.*}}/Inputs/resource_dir{{/|}}include"
 // RESOURCE-INC: "-internal-isystem" 
"{{.*}}/basic_riscv64_tree/{{.*}}riscv64-unknown-elf{{/|}}include"
 
 // RUN: %clang %s -### -no-canonical-prefixes -target riscv64 \
-// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree \
+// RUN:   --gcc-toolchain=%S/Inputs/basic_riscv64_tree --sysroot= \
 // RUN:   -resource-dir=%s/Inputs/resource_dir -nobuiltininc 2>&1 \
 // RUN:   | FileCheck -check-prefix=NO-RESOURCE-INC %s
 // NO-RESOURCE-INC-NOT: "-internal-isystem" 
"{{.*}}Inputs/resource_dir{{/|}}include"



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


[PATCH] D118586: [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-21 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D118586#3335235 , @ChuanqiXu wrote:

> In D118586#3335191 , @iains wrote:
>
>> In D118586#3335167 , @ChuanqiXu 
>> wrote:
>>
>>> I think it is helpful to add some tests from 
>>> https://reviews.llvm.org/D113972
>>
>> Actually, in response to your concerns, this morning I wrote a 
>> multi-partition test case to add to this (which does pass).
>
> Thanks. I think it would be helpful to add it here.
>
>> Would you be able to split out the important test cases from D113972 
>>  as a separate patch ?
>
> I found the meaningful test case mainly comes from the example in spec. e.g., 
> http://eel.is/c++draft/module.unit#4, http://eel.is/c++draft/module.unit#4, 
> http://eel.is/c++draft/module.unit#4

Right, actually it is my intention to have each of the examples in the std as a 
test case (this is what I have in my working branch) but, obviously, we can 
only introduce them when the features they show are implemented.  So (for 
example) 4/8 adds 10.1 examples 1 and 2.   5/8 adds in 10.3 ex1 and ex2 .. and 
so on ..

However, maybe I should review if some of the others should be accepted already 
:)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118586

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


[PATCH] D120244: [clang][sema] Enable first-class bool support for C2x

2022-02-21 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/Sema/c2x-bool.c:10
+_Static_assert(_Generic(true, bool : true, default: false));
+_Static_assert(_Generic(false, bool : true, default: false));
+

Not that clang-format wanted me to format these two lines, but the result was 
pretty ugly:

```
-_Static_assert(_Generic(true, bool : true, default: false));
-_Static_assert(_Generic(false, bool : true, default: false));
+_Static_assert(_Generic(true, bool
+: true, default
+: false));
+_Static_assert(_Generic(false, bool
+: true, default
+: false));
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120244

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


[PATCH] D120200: [Clang][OpenMP] Add Sema support for atomic compare capture

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Do we have ast print/dump tests for correct constructs?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120200

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


[PATCH] D120225: [Clang][Sema] Check unexpected else statement in cond-update-stmt

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120225

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


[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2022-02-21 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

Another full run on LLVM with:

  $ ./clang-tools-extra/clang-tidy/tool/run-clang-tidy.py \
-clang-tidy-binary 
~/software/llvm-project/build_clang_tidy/bin/clang-tidy \
-checks="-*,cppcoreguidelines-const-correctness" \
-config "{CheckOptions: [{key: 
'cppcoreguidelines-const-correctness.TransformValues', value: 1}, {key: 
'cppcoreguidelines-const-correctness.TransformReferences', value: 1}, {key: 
'cppcoreguidelines-const-correctness.WarnPointersAsValues', value: true}, {key: 
'cppcoreguidelines-const-correctness.TransformPointersAsValues', value: 
true}]}" \
-fix 2>&1 | tee ../transformation.log

Yields to this: ` 3822 files changed, 159256 insertions(+), 159256 deletions(-)`
and requires manual changes:
F22182704: to_fix.patch 
 23 files changed, 45 insertions(+), 45 deletions(-)

the issues were:

- missing `{}` initialization after a variable became `const` if a destructor 
was missing
- the analysis got confused for some `insert(llvm::Function* f)` calls and made 
the objects `const`. Those are false positives, but with a really low rate

after applying the patch `ninja check-all` is successfull.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

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


[PATCH] D120246: [flang][driver] Add support for `--target`/`--triple`

2022-02-21 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski created this revision.
awarzynski added reviewers: rovka, clementval, schweitz, Leporacanthicus.
Herald added subscribers: dang, usaxena95, kadircet.
Herald added a reviewer: sscalpone.
Herald added a project: Flang.
awarzynski requested review of this revision.
Herald added subscribers: cfe-commits, jdoerfert, ilya-biryukov.
Herald added a project: clang.

This patch adds support for:

- `--target` in the compiler driver (`flang-new`)
- `--triple` in the frontend driver (`flang-new -fc1`)

The semantics of these flags are inherited from `clangDriver`, i.e.
consistent with `clang --target` and `clang -cc1 --triple`,
respectively.

A new structure is defined, `TargetOptions`, that will hold various
Frontend options related to the target. Currently, this is mostly a
placeholder that contains the target triple. In the future, it will be
used for storing e.g. the CPU to tune for or the target features to
enable.

Additionally, the following target/triple related options are enabled
[*]: `-print-ffective-triple`, `-print-target-triple`. Definitions in
Options.td are updated accordingly and, to facilated testing,
`-emit-llvm` is added to the list of options available in `flang-new`
(previously it was only enabled in `flang-new -fc1`).

[X] These options were actually available before (like all other options

defined in `clangDriver`), but not included in `flang-new --help`.
Before this change, `flang-new` would just use `native` for defining the
target, so these options were of little value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120246

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/print-target-triple.f90
  flang/test/Driver/target.f90

Index: flang/test/Driver/target.f90
===
--- /dev/null
+++ flang/test/Driver/target.f90
@@ -0,0 +1,13 @@
+!  Test that --target indeed sets the target
+
+!-
+! RUN LINES
+!-
+! RUN: %flang --target=unknown-unknown-unknown -emit-llvm -c %s \
+! RUN:   -o %t.o -### 2>&1 | FileCheck %s
+
+!-
+! EXPECTED OUTPUT
+!-
+! CHECK: Target: unknown-unknown-unknown
+! CHECK: "-triple" "unknown-unknown-unknown"
Index: flang/test/Driver/print-target-triple.f90
===
--- /dev/null
+++ flang/test/Driver/print-target-triple.f90
@@ -0,0 +1,16 @@
+! Test that -print-target-triple prints correct triple
+
+!-
+! RUN LINES
+!-
+! RUN: %flang -print-target-triple 2>&1 --target=aarch64-linux-gnu \
+! RUN:   | FileCheck --check-prefix=AARCH64 %s
+
+! RUN: %flang -print-target-triple 2>&1 --target=x86_64-linux-gnu \
+! RUN:   | FileCheck --check-prefix=X86_64 %s
+
+!-
+! EXPECTED OUTPUT
+!-
+! X86_64: x86_64-unknown-linux-gnu
+! AARCH64: aarch64-unknown-linux-gnu
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -21,6 +21,7 @@
 ! HELP-NEXT: -cpp   Enable predefined and command line preprocessor macros
 ! HELP-NEXT: -c Only run preprocess, compile, and assemble steps
 ! HELP-NEXT: -D = Define  to  (or 1 if  omitted)
+! HELP-NEXT: -emit-llvm Use the LLVM representation for assembler and object files
 ! HELP-NEXT: -E Only run the preprocessor
 ! HELP-NEXT: -falternative-parameter-statement
 ! HELP-NEXT: Enable the old style PARAMETER statement
@@ -50,8 +51,11 @@
 ! HELP-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -pedantic  Warn on language extensions
+! HELP-NEXT: -print-effective-triple Print the effective target triple
+! HELP-NEXT: -print-target-triplePrint the normalized target triple
 ! HELP-NEXT: -P Disable linemarker output in -E mode
 ! HELP-NEXT: -std=   Language standard to compile for
+! HELP-NEXT: --target=   Generate code for the given target
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 ! HELP-NEXT: -WEnable the specified warning
@@ -124,6 +128,7 @@
 ! HELP-FC1-NEXT: -P Disable linemarker output in -E mode
 ! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
+! HELP-FC1-N

[PATCH] D120200: [Clang][OpenMP] Add Sema support for atomic compare capture

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D120200#3335250 , @ABataev wrote:

> Do we have ast print/dump tests for correct constructs?

It's in the parser patch which has already been merged. 
https://reviews.llvm.org/D116261


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120200

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


[clang] 6da6064 - [Clang][Sema] Check unexpected else statement in cond-update-stmt

2022-02-21 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2022-02-21T08:20:34-05:00
New Revision: 6da60647cda2fad4d93e359ef3afaea18599b2ba

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

LOG: [Clang][Sema] Check unexpected else statement in cond-update-stmt

In 'cond-update-stmt', `else` statement is not expected. This patch adds
the check in Sema.

Reviewed By: ABataev

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/atomic_messages.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1719db4871ff3..0d301e76c92d7 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10526,7 +10526,7 @@ def err_omp_atomic_compare : Error<
 def note_omp_atomic_compare: Note<
   "%select{expected compound statement|expected exactly one expression 
statement|expected assignment statement|expected conditional operator|expect 
result value to be at false expression|"
   "expect binary operator in conditional expression|expect '<', '>' or '==' as 
order operator|expect comparison in a form of 'x == e', 'e == x', 'x ordop 
expr', or 'expr ordop x'|"
-  "expect lvalue for result value|expect scalar value|expect integer value}0">;
+  "expect lvalue for result value|expect scalar value|expect integer 
value|unexpected 'else' statement}0">;
 def err_omp_atomic_several_clauses : Error<
   "directive '#pragma omp atomic' cannot contain more than one 'read', 
'write', 'update', 'capture', or 'compare' clause">;
 def err_omp_several_mem_order_clauses : Error<

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index ec0d095e89950..c32609e4e32e3 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -10974,6 +10974,8 @@ class OpenMPAtomicCompareChecker {
 NotScalar,
 /// Not an integer.
 NotInteger,
+/// 'else' statement is not expected.
+UnexpectedElse,
 /// No error.
 NoError,
   };
@@ -1,6 +3,13 @@ bool 
OpenMPAtomicCompareChecker::checkCondUpdateStmt(IfStmt *S,
 return false;
   }
 
+  if (S->getElse()) {
+ErrorInfo.Error = ErrorTy::UnexpectedElse;
+ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = S->getElse()->getBeginLoc();
+ErrorInfo.ErrorRange = ErrorInfo.NoteRange = 
S->getElse()->getSourceRange();
+return false;
+  }
+
   return true;
 }
 

diff  --git a/clang/test/OpenMP/atomic_messages.c 
b/clang/test/OpenMP/atomic_messages.c
index 22f7be91662b5..c66cd19b5aca3 100644
--- a/clang/test/OpenMP/atomic_messages.c
+++ b/clang/test/OpenMP/atomic_messages.c
@@ -473,6 +473,15 @@ void compare(void) {
   x = e;
 d = e;
   }
+// omp51-error@+7 {{the statement for 'atomic compare' must be a compound 
statement of form '{x = expr ordop x ? expr : x;}', '{x = x ordop expr? expr : 
x;}', '{x = x == e ? d : x;}', '{x = e == x ? d : x;}', or 'if(expr ordop x) {x 
= expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', 'if(e == x) 
{x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 
'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+6 {{unexpected 'else' statement}}
+#pragma omp atomic compare
+  {
+if (x > e)
+  x = e;
+else
+  d = e;
+  }
   float fx = 0.0f;
   float fd = 0.0f;
   float fe = 0.0f;



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


[PATCH] D120225: [Clang][Sema] Check unexpected else statement in cond-update-stmt

2022-02-21 Thread Shilei Tian 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 rG6da60647cda2: [Clang][Sema] Check unexpected else statement 
in cond-update-stmt (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120225

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/atomic_messages.c


Index: clang/test/OpenMP/atomic_messages.c
===
--- clang/test/OpenMP/atomic_messages.c
+++ clang/test/OpenMP/atomic_messages.c
@@ -473,6 +473,15 @@
   x = e;
 d = e;
   }
+// omp51-error@+7 {{the statement for 'atomic compare' must be a compound 
statement of form '{x = expr ordop x ? expr : x;}', '{x = x ordop expr? expr : 
x;}', '{x = x == e ? d : x;}', '{x = e == x ? d : x;}', or 'if(expr ordop x) {x 
= expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', 'if(e == x) 
{x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 
'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+6 {{unexpected 'else' statement}}
+#pragma omp atomic compare
+  {
+if (x > e)
+  x = e;
+else
+  d = e;
+  }
   float fx = 0.0f;
   float fd = 0.0f;
   float fe = 0.0f;
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -10974,6 +10974,8 @@
 NotScalar,
 /// Not an integer.
 NotInteger,
+/// 'else' statement is not expected.
+UnexpectedElse,
 /// No error.
 NoError,
   };
@@ -1,6 +3,13 @@
 return false;
   }
 
+  if (S->getElse()) {
+ErrorInfo.Error = ErrorTy::UnexpectedElse;
+ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = S->getElse()->getBeginLoc();
+ErrorInfo.ErrorRange = ErrorInfo.NoteRange = 
S->getElse()->getSourceRange();
+return false;
+  }
+
   return true;
 }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10526,7 +10526,7 @@
 def note_omp_atomic_compare: Note<
   "%select{expected compound statement|expected exactly one expression 
statement|expected assignment statement|expected conditional operator|expect 
result value to be at false expression|"
   "expect binary operator in conditional expression|expect '<', '>' or '==' as 
order operator|expect comparison in a form of 'x == e', 'e == x', 'x ordop 
expr', or 'expr ordop x'|"
-  "expect lvalue for result value|expect scalar value|expect integer value}0">;
+  "expect lvalue for result value|expect scalar value|expect integer 
value|unexpected 'else' statement}0">;
 def err_omp_atomic_several_clauses : Error<
   "directive '#pragma omp atomic' cannot contain more than one 'read', 
'write', 'update', 'capture', or 'compare' clause">;
 def err_omp_several_mem_order_clauses : Error<


Index: clang/test/OpenMP/atomic_messages.c
===
--- clang/test/OpenMP/atomic_messages.c
+++ clang/test/OpenMP/atomic_messages.c
@@ -473,6 +473,15 @@
   x = e;
 d = e;
   }
+// omp51-error@+7 {{the statement for 'atomic compare' must be a compound statement of form '{x = expr ordop x ? expr : x;}', '{x = x ordop expr? expr : x;}', '{x = x == e ? d : x;}', '{x = e == x ? d : x;}', or 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+6 {{unexpected 'else' statement}}
+#pragma omp atomic compare
+  {
+if (x > e)
+  x = e;
+else
+  d = e;
+  }
   float fx = 0.0f;
   float fd = 0.0f;
   float fe = 0.0f;
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -10974,6 +10974,8 @@
 NotScalar,
 /// Not an integer.
 NotInteger,
+/// 'else' statement is not expected.
+UnexpectedElse,
 /// No error.
 NoError,
   };
@@ -1,6 +3,13 @@
 return false;
   }
 
+  if (S->getElse()) {
+ErrorInfo.Error = ErrorTy::UnexpectedElse;
+ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = S->getElse()->getBeginLoc();
+ErrorInfo.ErrorRange = ErrorInfo.NoteRange = S->getElse()->getSourceRange();
+return false;
+  }
+
   return true;
 }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/c

[PATCH] D120200: [Clang][OpenMP] Add Sema support for atomic compare capture

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120200

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


[PATCH] D120236: Add more sources to Taint analysis

2022-02-21 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Sorry for the wall-of-nits. Overall, looks great.




Comment at: clang/docs/analyzer/checkers.rst:2358
 Default sources defined by ``GenericTaintChecker``:
-``fdopen``, ``fopen``, ``freopen``, ``getch``, ``getchar``, 
``getchar_unlocked``, ``gets``, ``scanf``, ``socket``, ``wgetch``
+ ``_IO_getc``, ``fdopen``, ``fopen``, ``freopen``, ``get_current_dir_name``, 
``getch``, ``getchar``, ``getchar_unlocked``, ``getcw``, ``getcwd``, 
``getgroups``, ``gethostname``, ``getlogin``, ``getlogin_r``, ``getnameinfo``, 
``getopt``, ``getopt_long``, ``getopt_only``, ``gets``, ``getseuserbyname``, 
``readlink``, ``scanf``, ``scanf_s``, ``socket``, ``wgetch``
 

typo/dup?
I cannot recognize the `getcw()` call. Could you please refer to the 
specification or an instance where it was defined?



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:546-548
   {{"gets"}, TR::Source({{0}, ReturnValueIndex})},
   {{"scanf"}, TR::Source({{}, 1})},
+  {{"scanf_s"}, TR::Source({{}, {1}})},

If we handle `gets`, `scanf`, we should also model the `*_s` versions as well.
```lang=C
char *gets_s(char *s, rsize_t n);
int scanf_s(const char *restrict format, ...);
int fscanf_s(FILE *restrict stream, const char *restrict format, ...);
int sscanf_s(const char *restrict s, const char *restrict format, ...);
int vscanf_s(const char *restrict format, va_list arg);
int vfscanf_s(FILE *restrict stream, const char *restrict format, va_list arg);
int vsscanf_s(const char *restrict s, const char *restrict format, va_list arg);
```



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:550-552
+  {{"getopt"}, TR::Source({{ReturnValueIndex}})},
+  {{"getopt_long"}, TR::Source({{ReturnValueIndex}})},
+  {{"getopt_long_only"}, TR::Source({{ReturnValueIndex}})},

IMO these functions are highly domain-specific.
On errors, they return specific/well-defined values e.g. `-1`, `'?'` or `':'`.
That being said, the analyzer does not have this knowledge, thus it will model 
these as `conjured` symbols.
If these values were modeled as tainted, we would likely introduce the number 
of false-positives regarding our limited capabilities of modeling the function 
accurately.

tldr; I'm against these three rules; or alternatively prove that my concerns 
are not issues on real code bases.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:556
+  {{"getwd"}, TR::Source({{0, ReturnValueIndex}})},
+  {{"readlink"}, TR::Source({{1, ReturnValueIndex}})},
+  {{"get_current_dir_name"}, TR::Source({{ReturnValueIndex}})},

We should check `readlinkat` as well.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:559
+  {{"gethostname"}, TR::Source({{0}})},
+  {{"getnameinfo"}, TR::Source({{2, 4}})},
+  {{"getseuserbyname"}, TR::Source({{1, 2}})},

In what cases can this function introduce taint?



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:561
+  {{"getseuserbyname"}, TR::Source({{1, 2}})},
+  {{"getgroups"}, TR::Source({{1}})},
+  {{"getlogin"}, TR::Source({{ReturnValueIndex}})},

>On success, `getgroups()` returns the number of supplementary group IDs. On 
>error, -1 is returned, and `errno` is set appropriately.

According to this, the return value index should be also tainted.



Comment at: clang/test/Analysis/taint-generic.c:385
+  struct option long_opts[] = {{0, 0, 0, 0}};
+  int opt = getopt_long_only(argc, argv, "a:b:02", long_opts, &option_index);
+  return 1 / opt; // expected-warning {{Division by a tainted value, possibly 
zero}}

Well, this can never return zero.
What we should do is to do a state-split for the failure case; since the 
application should definitely handle a failure in this part; thus the split 
would be justified.



Comment at: clang/test/Analysis/taint-generic.c:392
+int underscore_IO_getc_is_source(_IO_FILE *fp) {
+  char c = _IO_getc(fp);
+  return 1 / c; // expected-warning {{Division by a tainted value, possibly 
zero}}

Sometimes we taint the `fd` and propagate based on that, and othertimes, we 
simply just return taint.
However, I think it still looks like a better tradeoff this way.
I just wanted to highlight this. Maybe a comment on the CallDescription would 
be beneficial in describing this discrepancy.



Comment at: clang/test/Analysis/taint-generic.c:413
+  system(buf);  // expected-warning {{Untrusted data is passed to a system 
call}}
+  return 1 / s; // expected-warning {{Division by a tainted value, possibly 
zero}}
+}

Well, it can never be zero AFAIK. It might be `-1` on error, or the number of 
bytes stored into `buf`.
So, I would rather modify the exa

[PATCH] D120236: Add more sources to Taint analysis

2022-02-21 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Also great to see that the docs are in-sync to the code, which is a great plus!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120236

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


[PATCH] D120236: [analyzer] Add more sources to Taint analysis

2022-02-21 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

The pre-merge checks failed due to an unrelated test case: 
`Driver/hip-link-bundle-archive.hip` (on Windows); so I think we are good to go 
on that part.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120236

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


[PATCH] D117977: [cmake] Don't export `LLVM_TOOLS_INSTALL_DIR` anymore

2022-02-21 Thread Joachim Protze via Phabricator via cfe-commits
protze.joachim added a comment.

I think in openmp/tools currently only libraries and header files get 
installed, but no binaries.

I suggest to define `OPENMP_TOOLS_INSTALL_BINDIR`, 
`OPENMP_TOOLS_INSTALL_LIBDIR`, and `OPENMP_TOOLS_INSTALL_INCLUDEDIR` and 
probably base these variables on OPENMP_TOOLS_INSTALL_DIR, if defined (e.g., 
for distro builds), or OPENMP_INSTALL_{BIN|LIB|INCLUDE}DIR as fallback.

openmp/tools/*/CMakeLists.txt should then use these variables instead of the 
various variables they use currently.




Comment at: openmp/tools/CMakeLists.txt:1-3
+set(OPENMP_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
+"Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")
+mark_as_advanced(OPENMP_TOOLS_INSTALL_DIR)

Is this variable used anywhere?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117977

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


[PATCH] D120251: [clang][driver][wasm] Fix libstdc++ target-dependent include dir

2022-02-21 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added a reviewer: sbc100.
Herald added subscribers: sunfish, jgravelle-google, dschuff.
tbaeder requested review of this revision.
Herald added subscribers: cfe-commits, aheejin.
Herald added a project: clang.

As an alternative to https://reviews.llvm.org/D119056 that addresses the issues 
raised with that patch and fixes the test case to succeed.

I think this does what Jonathan explained in 
https://reviews.llvm.org/D119056#3313911


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120251

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.cpp


Index: clang/test/Driver/wasm-toolchain.cpp
===
--- clang/test/Driver/wasm-toolchain.cpp
+++ clang/test/Driver/wasm-toolchain.cpp
@@ -80,7 +80,7 @@
 // COMPILE_STDCXX: clang{{.*}}" "-cc1"
 // COMPILE_STDCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]*]]"
 // COMPILE_STDCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
-// COMPILE_STDCXX: "-internal-isystem" 
"[[SYSROOT:[^"]+]]/include/wasm32-wasi/c++/4.8"
+// COMPILE_STDCXX: "-internal-isystem" 
"[[SYSROOT:[^"]+]]/include/c++/4.8/wasm32-wasi"
 // COMPILE_STDCXX: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/c++/4.8"
 // COMPILE_STDCXX: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
 // COMPILE_STDCXX: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/wasm32-wasi"
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -528,7 +528,7 @@
 
   // First add the per-target include path if the OS is known.
   if (IsKnownOs) {
-std::string TargetDir = LibPath + "/" + MultiarchTriple + "/c++/" + 
Version;
+std::string TargetDir = LibPath + "/c++/" + Version + "/" + 
MultiarchTriple;
 addSystemInclude(DriverArgs, CC1Args, TargetDir);
   }
 


Index: clang/test/Driver/wasm-toolchain.cpp
===
--- clang/test/Driver/wasm-toolchain.cpp
+++ clang/test/Driver/wasm-toolchain.cpp
@@ -80,7 +80,7 @@
 // COMPILE_STDCXX: clang{{.*}}" "-cc1"
 // COMPILE_STDCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]*]]"
 // COMPILE_STDCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
-// COMPILE_STDCXX: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/wasm32-wasi/c++/4.8"
+// COMPILE_STDCXX: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/c++/4.8/wasm32-wasi"
 // COMPILE_STDCXX: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/c++/4.8"
 // COMPILE_STDCXX: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
 // COMPILE_STDCXX: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/wasm32-wasi"
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -528,7 +528,7 @@
 
   // First add the per-target include path if the OS is known.
   if (IsKnownOs) {
-std::string TargetDir = LibPath + "/" + MultiarchTriple + "/c++/" + Version;
+std::string TargetDir = LibPath + "/c++/" + Version + "/" + MultiarchTriple;
 addSystemInclude(DriverArgs, CC1Args, TargetDir);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120252: [Clang][OpenMP] Fix wrong form of 'cond-update-stmt' in atomic_ast_print.cpp

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, ABataev.
Herald added subscribers: guansong, yaxunl.
tianshilei1992 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

In `clang/test/OpenMP/atomic_ast_print.cpp` for `atomic compare capture`,
it was using 'cond-expr-stmt' instead of 'cond-update-stmt'. The spec only 
supports
'cond-update-stmt'.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120252

Files:
  clang/test/OpenMP/atomic_ast_print.cpp

Index: clang/test/OpenMP/atomic_ast_print.cpp
===
--- clang/test/OpenMP/atomic_ast_print.cpp
+++ clang/test/OpenMP/atomic_ast_print.cpp
@@ -47,9 +47,9 @@
 #pragma omp atomic compare
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture
   { v = a == b; if (v) a = c; }
 #endif
@@ -76,9 +76,9 @@
 #pragma omp atomic compare seq_cst
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture seq_cst
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare seq_cst capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture seq_cst
   { v = a == b; if (v) a = c; }
 #endif
@@ -105,9 +105,9 @@
 #pragma omp atomic compare acq_rel
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture acq_rel
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare acq_rel capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture acq_rel
   { v = a == b; if (v) a = c; }
 #endif
@@ -134,9 +134,9 @@
 #pragma omp atomic compare acquire
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture acquire
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare acquire capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture acquire
   { v = a == b; if (v) a = c; }
 #endif
@@ -163,9 +163,9 @@
 #pragma omp atomic compare release
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture release
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare release capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture release
   { v = a == b; if (v) a = c; }
 #endif
@@ -192,9 +192,9 @@
 #pragma omp atomic compare relaxed
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture relaxed
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare relaxed capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture relaxed
   { v = a == b; if (v) a = c; }
 #endif
@@ -221,9 +221,9 @@
 #pragma omp atomic compare hint(6)
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture hint(6)
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare hint(6) capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture hint(6)
   { v = a == b; if (v) a = c; }
 #endif
@@ -261,12 +261,16 @@
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a > b ? b : a;
+// CHECK-51-NEXT: if (a > b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a < b ? b : a;
+// CHECK-51-NEXT: if (a < b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
@@ -304,12 +308,16 @@
 // CHECK-51-NEXT: #pragma omp atomic compare capture seq_cst
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a > b ? b : a;
+// CHECK-51-NEXT: if (a > b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare seq_cst capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a < b ? b : a;
+// CHECK-51-NEXT: if (a < b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare capture seq_cst
 // CHECK-51-NEXT: {
@@ -347,12 +355,16 @@
 // CHECK-51-NEXT: #pragma omp atomic compare capture acq_rel
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a > b ? b : a;
+// CHECK-51-NEXT: if (a > b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare acq_rel capture
 // 

[PATCH] D120252: [Clang][OpenMP] Fix wrong form of 'cond-update-stmt' in atomic_ast_print.cpp

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120252

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


[PATCH] D112932: [WIP] Use llvm.is_fpclass to implement FP classification functions

2022-02-21 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 410303.
sepavloff added a comment.

Updated patch because the base revision is updated


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112932

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h

Index: clang/lib/CodeGen/TargetInfo.h
===
--- clang/lib/CodeGen/TargetInfo.h
+++ clang/lib/CodeGen/TargetInfo.h
@@ -126,16 +126,6 @@
 return Address;
   }
 
-  /// Performs a target specific test of a floating point value for things
-  /// like IsNaN, Infinity, ... Nullptr is returned if no implementation
-  /// exists.
-  virtual llvm::Value *
-  testFPKind(llvm::Value *V, unsigned BuiltinID, CGBuilderTy &Builder,
- CodeGenModule &CGM) const {
-assert(V->getType()->isFloatingPointTy() && "V should have an FP type.");
-return nullptr;
-  }
-
   /// Corrects the low-level LLVM type for a given constraint and "usual"
   /// type.
   ///
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7363,48 +7363,6 @@
   SystemZTargetCodeGenInfo(CodeGenTypes &CGT, bool HasVector, bool SoftFloatABI)
   : TargetCodeGenInfo(
 std::make_unique(CGT, HasVector, SoftFloatABI)) {}
-
-  llvm::Value *testFPKind(llvm::Value *V, unsigned BuiltinID,
-  CGBuilderTy &Builder,
-  CodeGenModule &CGM) const override {
-assert(V->getType()->isFloatingPointTy() && "V should have an FP type.");
-// Only use TDC in constrained FP mode.
-if (!Builder.getIsFPConstrained())
-  return nullptr;
-
-llvm::Type *Ty = V->getType();
-if (Ty->isFloatTy() || Ty->isDoubleTy() || Ty->isFP128Ty()) {
-  llvm::Module &M = CGM.getModule();
-  auto &Ctx = M.getContext();
-  llvm::Function *TDCFunc =
-  llvm::Intrinsic::getDeclaration(&M, llvm::Intrinsic::s390_tdc, Ty);
-  unsigned TDCBits = 0;
-  switch (BuiltinID) {
-  case Builtin::BI__builtin_isnan:
-TDCBits = 0xf;
-break;
-  case Builtin::BIfinite:
-  case Builtin::BI__finite:
-  case Builtin::BIfinitef:
-  case Builtin::BI__finitef:
-  case Builtin::BIfinitel:
-  case Builtin::BI__finitel:
-  case Builtin::BI__builtin_isfinite:
-TDCBits = 0xfc0;
-break;
-  case Builtin::BI__builtin_isinf:
-TDCBits = 0x30;
-break;
-  default:
-break;
-  }
-  if (TDCBits)
-return Builder.CreateCall(
-TDCFunc,
-{V, llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), TDCBits)});
-}
-return nullptr;
-  }
 };
 }
 
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -29,6 +29,7 @@
 #include "clang/CodeGen/CGFunctionInfo.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APInt.h"
+#include "llvm/ADT/FloatingPointMode.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Analysis/ValueTracking.h"
@@ -2247,6 +2248,16 @@
   }
 }
 
+static Value *createCallToIsFPClass(CodeGenFunction *CGF, const CallExpr *Call,
+unsigned Test) {
+  auto TestV = llvm::ConstantInt::get(CGF->Int32Ty, Test);
+  const Expr *Arg = Call->getNumArgs() == 1 ? Call->getArg(0) : Call->getArg(1);
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*CGF, Call);
+  Value *V = CGF->EmitScalarExpr(Arg);
+  Function *F = CGF->CGM.getIntrinsic(Intrinsic::is_fpclass, V->getType());
+  return CGF->Builder.CreateCall(F, {V, TestV});
+}
+
 RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
 const CallExpr *E,
 ReturnValueSlot ReturnValue) {
@@ -3092,37 +3103,55 @@
 // ZExt bool to int type.
 return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType(;
   }
-  case Builtin::BI__builtin_isnan: {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
-Value *V = EmitScalarExpr(E->getArg(0));
-llvm::Type *Ty = V->getType();
-const llvm::fltSemantics &Semantics = Ty->getFltSemantics();
-if (!Builder.getIsFPConstrained() ||
-Builder.getDefaultConstrainedExcept() == fp::ebIgnore ||
-!Ty->isIEEE()) {
-  V = Builder.CreateFCmpUNO(V, V, "cmp");
-  return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType(;
-}
 
-if (Value *Result = getTargetHooks().testFPKind(V, BuiltinID, Builder, CGM))
-  return RValue::get(Result);
+  case Builtin::BI__builtin_isnan:
+return RValue::get(
+Builder.CreateZExt(cre

[PATCH] D116153: [ARM][AArch64] Add missing v8.x checks

2022-02-21 Thread Victor Campos via Phabricator via cfe-commits
vhscampos added a comment.

I don't see any problem with the patch, but we should wait on @SjoerdMeijer.


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

https://reviews.llvm.org/D116153

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


[PATCH] D114714: [C++20][Modules][2/8] Add enumerations for partition modules and stream them.

2022-02-21 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 410305.
iains added a comment.

rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114714

Files:
  clang/include/clang/Basic/Module.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Serialization/ASTWriter.cpp


Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -2674,7 +2674,7 @@
   Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION));
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent
-  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Kind
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Kind
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -261,6 +261,8 @@
: ModuleScopes.back().Module->Kind) {
   case Module::ModuleMapModule:
   case Module::GlobalModuleFragment:
+  case Module::ModulePartitionImplementation:
+  case Module::ModulePartitionInterface:
 Diag(PrivateLoc, diag::err_private_module_fragment_not_module);
 return nullptr;
 
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1550,6 +1550,8 @@
 return nullptr;
 
   case Module::ModuleInterfaceUnit:
+  case Module::ModulePartitionInterface:
+  case Module::ModulePartitionImplementation:
 return M;
 
   case Module::GlobalModuleFragment: {
Index: clang/include/clang/Basic/Module.h
===
--- clang/include/clang/Basic/Module.h
+++ clang/include/clang/Basic/Module.h
@@ -106,9 +106,15 @@
 /// of header files.
 ModuleMapModule,
 
-/// This is a C++ Modules TS module interface unit.
+/// This is a C++20 module interface unit.
 ModuleInterfaceUnit,
 
+/// This is a C++ 20 module partition interface.
+ModulePartitionInterface,
+
+/// This is a C++ 20 module partition implementation.
+ModulePartitionImplementation,
+
 /// This is a fragment of the global module within some C++ module.
 GlobalModuleFragment,
 
@@ -150,7 +156,9 @@
 
   /// Does this Module scope describe part of the purview of a named C++ 
module?
   bool isModulePurview() const {
-return Kind == ModuleInterfaceUnit || Kind == PrivateModuleFragment;
+return Kind == ModuleInterfaceUnit || Kind == ModulePartitionInterface ||
+   Kind == ModulePartitionImplementation ||
+   Kind == PrivateModuleFragment;
   }
 
   /// Does this Module scope describe a fragment of the global module within
@@ -506,6 +514,9 @@
 Parent->SubModules.push_back(this);
   }
 
+  /// Is this a module partition.
+  bool isModulePartition() const { return Name.find(':') != std::string::npos; 
}
+
   /// Retrieve the full name of this module, including the path from
   /// its top-level module.
   /// \param AllowStringLiterals If \c true, components that might not be


Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -2674,7 +2674,7 @@
   Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION));
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent
-  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Kind
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Kind
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -261,6 +261,8 @@
: ModuleScopes.back().Module->Kind) {
   case Module::ModuleMapModule:
   case Module::GlobalModuleFragment:
+  case Module::ModulePartitionImplementation:
+  case Module::ModulePartitionInterface:
 Diag(PrivateLoc, diag::err_private_module_fragment_not_module);
 return nullptr;
 
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1550,6 +1550,8 @@
 return n

[PATCH] D116153: [ARM][AArch64] Add missing v8.x checks

2022-02-21 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

Ah, sorry, forgot about this.  Can you upload the patch with some more context 
please so I can have a quick look again?


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

https://reviews.llvm.org/D116153

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


[PATCH] D116153: [ARM][AArch64] Add missing v8.x checks

2022-02-21 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 updated this revision to Diff 410310.
tyb0807 edited the summary of this revision.
tyb0807 added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116153

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Preprocessor/aarch64-target-features.c


Index: clang/test/Preprocessor/aarch64-target-features.c
===
--- clang/test/Preprocessor/aarch64-target-features.c
+++ clang/test/Preprocessor/aarch64-target-features.c
@@ -294,7 +294,7 @@
 // CHECK-MCPU-CARMEL: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-feature" 
"+v8.2a" "-target-feature" "+fp-armv8" "-target-feature" "+neon" 
"-target-feature" "+crc" "-target-feature" "+crypto" "-target-feature" 
"+fullfp16" "-target-feature" "+ras" "-target-feature" "+lse" "-target-feature" 
"+rdm" "-target-feature" "+sha2" "-target-feature" "+aes"
 
 // RUN: %clang -target x86_64-apple-macosx -arch arm64 -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-ARCH-ARM64 %s
-// CHECK-ARCH-ARM64: "-target-cpu" "apple-m1" "-target-feature" "+v8.5a" 
"-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-feature" 
"+crc" "-target-feature" "+crypto" "-target-feature" "+dotprod" 
"-target-feature" "+fp16fml" "-target-feature" "+ras" "-target-feature" "+lse" 
"-target-feature" "+rdm" "-target-feature" "+rcpc" "-target-feature" "+zcm" 
"-target-feature" "+zcz" "-target-feature" "+fullfp16" "-target-feature" 
"+sha2" "-target-feature" "+aes"
+// CHECK-ARCH-ARM64: "-target-cpu" "apple-m1" "-target-feature" "+v8.5a" 
"-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-feature" 
"+crc" "-target-feature" "+crypto" "-target-feature" "+dotprod" 
"-target-feature" "+fp16fml" "-target-feature" "+ras" "-target-feature" "+lse" 
"-target-feature" "+rdm" "-target-feature" "+rcpc" "-target-feature" "+zcm" 
"-target-feature" "+zcz" "-target-feature" "+fullfp16" "-target-feature" "+sm4" 
"-target-feature" "+sha3" "-target-feature" "+sha2" "-target-feature" "+aes"
 
 // RUN: %clang -target x86_64-apple-macosx -arch arm64_32 -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-ARCH-ARM64_32 %s
 // CHECK-ARCH-ARM64_32: "-target-cpu" "apple-s4" "-target-feature" "+v8.3a" 
"-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-feature" 
"+crc" "-target-feature" "+crypto" "-target-feature" "+fullfp16" 
"-target-feature" "+ras" "-target-feature" "+lse" "-target-feature" "+rdm" 
"-target-feature" "+rcpc" "-target-feature" "+zcm" "-target-feature" "+zcz" 
"-target-feature" "+sha2" "-target-feature" "+aes"
@@ -390,7 +390,13 @@
 // Check +crypto:
 //
 // RUN: %clang -target aarch64 -march=armv8.4a+crypto -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-CRYPTO84 %s
-// CHECK-CRYPTO84: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-feature" 
"+v8.4a" "-target-feature" "+crypto" "-target-feature" "+sm4" "-target-feature" 
"+sha3" "-target-feature" "+sha2" "-target-feature" "+aes"
+// RUN: %clang -target aarch64 -march=armv8.5a+crypto -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-CRYPTO85 %s
+// RUN: %clang -target aarch64 -march=armv8.6a+crypto -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-CRYPTO86 %s
+// RUN: %clang -target aarch64 -march=armv8.7a+crypto -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-CRYPTO87 %s
+// CHECK-CRYPTO84: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-feature" 
"+v8.4a"{{.*}} "-target-feature" "+crypto" "-target-feature" "+sm4" 
"-target-feature" "+sha3" "-target-feature" "+sha2" "-target-feature" "+aes"
+// CHECK-CRYPTO85: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-feature" 
"+v8.5a"{{.*}} "-target-feature" "+crypto" "-target-feature" "+sm4" 
"-target-feature" "+sha3" "-target-feature" "+sha2" "-target-feature" "+aes"
+// CHECK-CRYPTO86: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-feature" 
"+v8.6a"{{.*}} "-target-feature" "+crypto" "-target-feature" "+sm4" 
"-target-feature" "+sha3" "-target-feature" "+sha2" "-target-feature" "+aes"
+// CHECK-CRYPTO87: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-feature" 
"+v8.7a"{{.*}} "-target-feature" "+crypto" "-target-feature" "+sm4" 
"-target-feature" "+sha3" "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto:
 //
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -393,6 +393,9 @@
   }
 
   if (std::find(ItBegin, ItEnd, "+v8.4a") != ItEnd ||
+  std::find(ItBegin, ItEnd, "+v8.5a") != ItEnd ||
+  std::find(ItBegin, ItEnd, "+v8.6a") != ItEnd ||
+  std::find(ItBegin, ItEnd, "+v8.7a") != ItEnd ||
   std::find(ItBegin, ItEnd, "+v8.8a") != ItEnd ||
   std::find(ItBegin, ItEnd, "+v9a") != ItEnd ||
   std::find(ItBegin, ItEnd, "+v9.1a") != ItEnd ||
Index: clang/lib/Basi

[PATCH] D116153: [ARM][AArch64] Add missing v8.x checks

2022-02-21 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added inline comments.



Comment at: clang/lib/Basic/Targets/ARM.cpp:958
   case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
   case llvm::ARM::ArchKind::ARMV8_8A:

I see tests for the crypto stuff, but is there or do we need a test for 
whatever `getTargetDefinesARMV83A` is setting?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116153

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


[PATCH] D114382: [clang] Fix wrong -Wunused-local-typedef warning within a template function

2022-02-21 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114382

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


[PATCH] D116153: [ARM][AArch64] Add missing v8.x checks

2022-02-21 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 added inline comments.



Comment at: clang/lib/Basic/Targets/ARM.cpp:958
   case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
   case llvm::ARM::ArchKind::ARMV8_8A:

SjoerdMeijer wrote:
> I see tests for the crypto stuff, but is there or do we need a test for 
> whatever `getTargetDefinesARMV83A` is setting?
I'm not sure that we need a test for this, as none of the other architectures 
really have this. What do you think @SjoerdMeijer @vhscampos ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116153

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


[PATCH] D116153: [ARM][AArch64] Add missing v8.x checks

2022-02-21 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added inline comments.



Comment at: clang/lib/Basic/Targets/ARM.cpp:958
   case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
   case llvm::ARM::ArchKind::ARMV8_8A:

tyb0807 wrote:
> SjoerdMeijer wrote:
> > I see tests for the crypto stuff, but is there or do we need a test for 
> > whatever `getTargetDefinesARMV83A` is setting?
> I'm not sure that we need a test for this, as none of the other architectures 
> really have this. What do you think @SjoerdMeijer @vhscampos ?
I am expecting tests for the ACLE macros that this patch defines for v8.7 to be 
added to `clang/test/Preprocessor/arm-target-features.c`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116153

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


[PATCH] D120200: [Clang][OpenMP] Add Sema support for atomic compare capture

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 410313.
tianshilei1992 added a comment.

fix tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120200

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/atomic_messages.c
  clang/test/OpenMP/atomic_messages.cpp

Index: clang/test/OpenMP/atomic_messages.cpp
===
--- clang/test/OpenMP/atomic_messages.cpp
+++ clang/test/OpenMP/atomic_messages.cpp
@@ -928,7 +928,7 @@
 }
 
 int mixed() {
-  int a, b = 0;
+  int a, v, b = 0;
 // expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause}}
 // expected-note@+1 {{'read' clause used here}}
 #pragma omp atomic read write
@@ -957,7 +957,7 @@
 // expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'compare' clause}}
 // expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'capture' clause}}
 #pragma omp atomic compare compare capture capture
-  a = b;
+  { v = a; if (a > b) a = b; }
 #endif
   // expected-note@+1 {{in instantiation of function template specialization 'mixed' requested here}}
   return mixed();
Index: clang/test/OpenMP/atomic_messages.c
===
--- clang/test/OpenMP/atomic_messages.c
+++ clang/test/OpenMP/atomic_messages.c
@@ -500,4 +500,199 @@
   fx = fe;
   }
 }
+
+void compare_capture(void) {
+  int x = 0;
+  int d = 0;
+  int e = 0;
+  int v = 0;
+  int r = 0;
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+2 {{expected compound statement}}
+#pragma omp atomic compare capture
+  if (x == e) {}
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+2 {{expected exactly one expression statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+x = d;
+v = x;
+  }
+// omp51-error@+4 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+3 {{expected assignment statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+bbar();
+  }
+// omp51-error@+4 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+3 {{expected assignment statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+x += d;
+  }
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where '

[PATCH] D120254: [OpenCL] Align subgroup builtin guards

2022-02-21 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: azabaznov.
Herald added subscribers: Naghasan, ldrumm, yaxunl.
svenvh requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Until now, subgroup builtins are available with `opencl-c.h` when at
least one of `cl_intel_subgroups`, `cl_khr_subgroups`, or
`__opencl_c_subgroups` is defined.  With `-fdeclare-opencl-builtins`,
subgroup builtins are conditionalized on `cl_khr_subgroups` only.

Align `-fdeclare-opencl-builtins` to `opencl-c.h` by introducing the
internal `__opencl_subgroup_builtins` macro.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120254

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Headers/opencl-c.h
  clang/lib/Sema/OpenCLBuiltins.td
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl


Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -DNO_HEADER
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -finclude-default-header
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER 
-cl-ext=-cl_intel_subgroups
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header 
-cl-ext=-cl_intel_subgroups
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header
@@ -79,6 +79,7 @@
 #define cl_khr_subgroup_non_uniform_arithmetic 1
 #define cl_khr_subgroup_clustered_reduce 1
 #define __opencl_c_read_write_images 1
+#define __opencl_subgroup_builtins 1
 #endif
 
 #if (__OPENCL_CPP_VERSION__ == 100 || __OPENCL_C_VERSION__ == 200)
Index: clang/lib/Sema/OpenCLBuiltins.td
===
--- clang/lib/Sema/OpenCLBuiltins.td
+++ clang/lib/Sema/OpenCLBuiltins.td
@@ -83,7 +83,7 @@
 
 // FunctionExtension definitions.
 def FuncExtNone  : FunctionExtension<"">;
-def FuncExtKhrSubgroups  : 
FunctionExtension<"cl_khr_subgroups">;
+def FuncExtKhrSubgroups  : 
FunctionExtension<"__opencl_subgroup_builtins">;
 def FuncExtKhrSubgroupExtendedTypes  : 
FunctionExtension<"cl_khr_subgroup_extended_types">;
 def FuncExtKhrSubgroupNonUniformVote : 
FunctionExtension<"cl_khr_subgroup_non_uniform_vote">;
 def FuncExtKhrSubgroupBallot : 
FunctionExtension<"cl_khr_subgroup_ballot">;
Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ clang/lib/Headers/opencl-c.h
@@ -16282,7 +16282,7 @@
 
 // OpenCL Extension v2.0 s9.17 - Sub-groups
 
-#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) || 
defined(__opencl_c_subgroups)
+#if defined(__opencl_subgroup_builtins)
 // Shared Sub Group Functions
 uint__ovld get_sub_group_size(void);
 uint__ovld get_max_sub_group_size(void);
@@ -16381,7 +16381,7 @@
 double  __ovld __conv sub_group_scan_inclusive_max(double x);
 #endif //cl_khr_fp64
 
-#endif //cl_khr_subgroups cl_intel_subgroups __opencl_c_subgroups
+#endif // __opencl_subgroup_builtins
 
 #if defined(cl_khr_subgroup_extended_types)
 char __ovld __conv sub_group_broadcast( char value, uint index );
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -80,6 +80,11 @@
 #define __opencl_c_named_address_space_builtins 1
 #endif // !defined(__opencl_c_generic_address_space)
 
+#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) || 
defined(__opencl_c_subgroups)
+// Internal feature macro to provide subgroup builtins.
+#define __opencl_subgroup_builtins 1
+#endif
+
 // built-in scalar data types:
 
 /**


Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
==

[clang] 3a3d9ae - [Clang][OpenMP] Fix wrong form of 'cond-update-stmt' in atomic_ast_print.cpp

2022-02-21 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2022-02-21T11:40:09-05:00
New Revision: 3a3d9ae545925162ebbe820639cd2fe072ff4dd8

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

LOG: [Clang][OpenMP] Fix wrong form of 'cond-update-stmt' in 
atomic_ast_print.cpp

In `clang/test/OpenMP/atomic_ast_print.cpp` for `atomic compare capture`,
it was using 'cond-expr-stmt' instead of 'cond-update-stmt'. The spec only 
supports
'cond-update-stmt'.

Reviewed By: ABataev

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

Added: 


Modified: 
clang/test/OpenMP/atomic_ast_print.cpp

Removed: 




diff  --git a/clang/test/OpenMP/atomic_ast_print.cpp 
b/clang/test/OpenMP/atomic_ast_print.cpp
index 7502fdc339c2a..201f62ab2117e 100644
--- a/clang/test/OpenMP/atomic_ast_print.cpp
+++ b/clang/test/OpenMP/atomic_ast_print.cpp
@@ -47,9 +47,9 @@ T foo(T argc) {
 #pragma omp atomic compare
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture
   { v = a == b; if (v) a = c; }
 #endif
@@ -76,9 +76,9 @@ T foo(T argc) {
 #pragma omp atomic compare seq_cst
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture seq_cst
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare seq_cst capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture seq_cst
   { v = a == b; if (v) a = c; }
 #endif
@@ -105,9 +105,9 @@ T foo(T argc) {
 #pragma omp atomic compare acq_rel
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture acq_rel
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare acq_rel capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture acq_rel
   { v = a == b; if (v) a = c; }
 #endif
@@ -134,9 +134,9 @@ T foo(T argc) {
 #pragma omp atomic compare acquire
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture acquire
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare acquire capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture acquire
   { v = a == b; if (v) a = c; }
 #endif
@@ -163,9 +163,9 @@ T foo(T argc) {
 #pragma omp atomic compare release
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture release
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare release capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture release
   { v = a == b; if (v) a = c; }
 #endif
@@ -192,9 +192,9 @@ T foo(T argc) {
 #pragma omp atomic compare relaxed
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture relaxed
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare relaxed capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture relaxed
   { v = a == b; if (v) a = c; }
 #endif
@@ -221,9 +221,9 @@ T foo(T argc) {
 #pragma omp atomic compare hint(6)
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture hint(6)
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare hint(6) capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture hint(6)
   { v = a == b; if (v) a = c; }
 #endif
@@ -261,12 +261,16 @@ T foo(T argc) {
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a > b ? b : a;
+// CHECK-51-NEXT: if (a > b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a < b ? b : a;
+// CHECK-51-NEXT: if (a < b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
@@ -304,12 +308,16 @@ T foo(T argc) {
 // CHECK-51-NEXT: #pragma omp atomic compare capture seq_cst
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a > b ? b : a;
+// CHECK-51-NEXT: if (a > b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare seq_cst capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a < b ? b : a;
+// CHECK-51-NEXT: if (a < b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHE

[PATCH] D120252: [Clang][OpenMP] Fix wrong form of 'cond-update-stmt' in atomic_ast_print.cpp

2022-02-21 Thread Shilei Tian 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 rG3a3d9ae54592: [Clang][OpenMP] Fix wrong form of 
'cond-update-stmt' in atomic_ast_print.cpp (authored by 
tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120252

Files:
  clang/test/OpenMP/atomic_ast_print.cpp

Index: clang/test/OpenMP/atomic_ast_print.cpp
===
--- clang/test/OpenMP/atomic_ast_print.cpp
+++ clang/test/OpenMP/atomic_ast_print.cpp
@@ -47,9 +47,9 @@
 #pragma omp atomic compare
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture
   { v = a == b; if (v) a = c; }
 #endif
@@ -76,9 +76,9 @@
 #pragma omp atomic compare seq_cst
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture seq_cst
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare seq_cst capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture seq_cst
   { v = a == b; if (v) a = c; }
 #endif
@@ -105,9 +105,9 @@
 #pragma omp atomic compare acq_rel
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture acq_rel
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare acq_rel capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture acq_rel
   { v = a == b; if (v) a = c; }
 #endif
@@ -134,9 +134,9 @@
 #pragma omp atomic compare acquire
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture acquire
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare acquire capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture acquire
   { v = a == b; if (v) a = c; }
 #endif
@@ -163,9 +163,9 @@
 #pragma omp atomic compare release
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture release
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare release capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture release
   { v = a == b; if (v) a = c; }
 #endif
@@ -192,9 +192,9 @@
 #pragma omp atomic compare relaxed
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture relaxed
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare relaxed capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture relaxed
   { v = a == b; if (v) a = c; }
 #endif
@@ -221,9 +221,9 @@
 #pragma omp atomic compare hint(6)
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture hint(6)
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare hint(6) capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture hint(6)
   { v = a == b; if (v) a = c; }
 #endif
@@ -261,12 +261,16 @@
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a > b ? b : a;
+// CHECK-51-NEXT: if (a > b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a < b ? b : a;
+// CHECK-51-NEXT: if (a < b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
@@ -304,12 +308,16 @@
 // CHECK-51-NEXT: #pragma omp atomic compare capture seq_cst
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a > b ? b : a;
+// CHECK-51-NEXT: if (a > b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare seq_cst capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a < b ? b : a;
+// CHECK-51-NEXT: if (a < b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare capture seq_cst
 // CHECK-51-NEXT: {
@@ -347,12 +355,16 @@
 // CHECK-51-NEXT: #pragma omp atomic compare capture acq_rel
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a > b ? b : a;
+// CHECK-51-NEXT: if (a > b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare acq_rel capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a < b ? b : a;
+// CHECK-51-NEXT: if (a 

[PATCH] D120254: [OpenCL] Align subgroup builtin guards

2022-02-21 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: clang/lib/Headers/opencl-c-base.h:85
+// Internal feature macro to provide subgroup builtins.
+#define __opencl_subgroup_builtins 1
+#endif

I'm in doubt whether we could just reuse `__opencl_c_subgroups` for this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120254

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


[PATCH] D116153: [ARM][AArch64] Add missing v8.x checks

2022-02-21 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 added inline comments.



Comment at: clang/lib/Basic/Targets/ARM.cpp:958
   case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
   case llvm::ARM::ArchKind::ARMV8_8A:

SjoerdMeijer wrote:
> tyb0807 wrote:
> > SjoerdMeijer wrote:
> > > I see tests for the crypto stuff, but is there or do we need a test for 
> > > whatever `getTargetDefinesARMV83A` is setting?
> > I'm not sure that we need a test for this, as none of the other 
> > architectures really have this. What do you think @SjoerdMeijer @vhscampos ?
> I am expecting tests for the ACLE macros that this patch defines for v8.7 to 
> be added to `clang/test/Preprocessor/arm-target-features.c`.
In that case, for consistency, I think we should also add tests for ACLE macros 
for other versions (v8.4/5/6/8) as well. And for AArch64 too. It sounds a bit 
out of scope, but it ensures consistency IMHO


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116153

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


[PATCH] D120254: [OpenCL] Align subgroup builtin guards

2022-02-21 Thread fonz vermund via Phabricator via cfe-commits
fonzvermund added a comment.

https://njonlinecasinos.webgarden.com/casinos/nj-casino-reviews/tropicana-online-casino
http://playlegalsportsbetting.com/borgata-online-casino-pa/
https://casinowatchnj.com/borgata-online-casino/
https://casinowatchnj.com/betmgm-online-casino/
https://casinowatchpa.com/tropicana-online-casino-pa/
https://casinowatchpa.com/betrivers-casino/
https://casinowatchnj.com/
https://playlegalsportsbetting.com/unibet-betting/
https://legal-sportsbetting.com/draftkings-sportsbook-is-live-in-new-york/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120254

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


[PATCH] D120200: [Clang][OpenMP] Add Sema support for atomic compare capture

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 410318.
tianshilei1992 added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120200

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/atomic_messages.c
  clang/test/OpenMP/atomic_messages.cpp

Index: clang/test/OpenMP/atomic_messages.cpp
===
--- clang/test/OpenMP/atomic_messages.cpp
+++ clang/test/OpenMP/atomic_messages.cpp
@@ -928,7 +928,7 @@
 }
 
 int mixed() {
-  int a, b = 0;
+  int a, v, b = 0;
 // expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause}}
 // expected-note@+1 {{'read' clause used here}}
 #pragma omp atomic read write
@@ -957,7 +957,7 @@
 // expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'compare' clause}}
 // expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'capture' clause}}
 #pragma omp atomic compare compare capture capture
-  a = b;
+  { v = a; if (a > b) a = b; }
 #endif
   // expected-note@+1 {{in instantiation of function template specialization 'mixed' requested here}}
   return mixed();
Index: clang/test/OpenMP/atomic_messages.c
===
--- clang/test/OpenMP/atomic_messages.c
+++ clang/test/OpenMP/atomic_messages.c
@@ -500,4 +500,199 @@
   fx = fe;
   }
 }
+
+void compare_capture(void) {
+  int x = 0;
+  int d = 0;
+  int e = 0;
+  int v = 0;
+  int r = 0;
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+2 {{expected compound statement}}
+#pragma omp atomic compare capture
+  if (x == e) {}
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+2 {{expected exactly one expression statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+x = d;
+v = x;
+  }
+// omp51-error@+4 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+3 {{expected assignment statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+bbar();
+  }
+// omp51-error@+4 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+3 {{expected assignment statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+x += d;
+  }
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' 

[PATCH] D120254: [OpenCL] Align subgroup builtin guards

2022-02-21 Thread fonz vermund via Phabricator via cfe-commits
fonzvermund added a comment.

http://webonlinegambling.idea.informer.com/
https://webonlinegambling.com/mobile-casinos/
http://playlegalsportsbetting.idea.informer.com/
http://legalsportsbetting.idea.informer.com/
https://sourceforge.net/u/legalsportsbet/profile
https://www.theodysseyonline.com/user/@legalsportsbet
https://www.question2answer.org/qa/user/legalsportsbet


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120254

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


[PATCH] D116153: [ARM][AArch64] Add missing v8.x checks

2022-02-21 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added inline comments.



Comment at: clang/lib/Basic/Targets/ARM.cpp:958
   case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
   case llvm::ARM::ArchKind::ARMV8_8A:

tyb0807 wrote:
> SjoerdMeijer wrote:
> > tyb0807 wrote:
> > > SjoerdMeijer wrote:
> > > > I see tests for the crypto stuff, but is there or do we need a test for 
> > > > whatever `getTargetDefinesARMV83A` is setting?
> > > I'm not sure that we need a test for this, as none of the other 
> > > architectures really have this. What do you think @SjoerdMeijer 
> > > @vhscampos ?
> > I am expecting tests for the ACLE macros that this patch defines for v8.7 
> > to be added to `clang/test/Preprocessor/arm-target-features.c`.
> In that case, for consistency, I think we should also add tests for ACLE 
> macros for other versions (v8.4/5/6/8) as well. And for AArch64 too. It 
> sounds a bit out of scope, but it ensures consistency IMHO
The subject says 

> [ARM][AArch64] Add missing v8.x checks

so looks perfect in scope to me. :)




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116153

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


[PATCH] D118586: [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-21 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 410320.
iains added a comment.

rebased, added a multi-partition testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118586

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/CXX/module/module.unit/p3.cpp
  clang/test/CXX/module/module.unit/p8.cpp
  clang/test/Modules/cxx20-multiple-partitions.cpp
  clang/test/Modules/cxx20-partition-diagnostics-a.cpp

Index: clang/test/Modules/cxx20-partition-diagnostics-a.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-partition-diagnostics-a.cpp
@@ -0,0 +1,18 @@
+// Module Partition diagnostics
+
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -D TU=1 -x c++ %s -verify
+
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -D TU=2 -x c++ %s -verify
+
+#if TU == 1
+
+import :B; // expected-error {{module partition imports must be within a module purview}}
+
+#elif TU == 2
+module; // expected-error {{missing 'module' declaration at end of global module fragment introduced here}}
+
+import :Part; // expected-error {{module partition imports cannot be in the global module fragment}}
+
+#else
+#error "no TU set"
+#endif
Index: clang/test/Modules/cxx20-multiple-partitions.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-multiple-partitions.cpp
@@ -0,0 +1,49 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=1 -x c++ %s \
+// RUN:  -o %t/A_part1.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=2 -x c++ %s \
+// RUN:  -o %t/A_part2.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=3 -x c++ %s \
+// RUN:  -o %t/A_part3.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=4 -x c++ %s \
+// RUN:  -fmodule-file=%t/A_part1.pcm -fmodule-file=%t/A_part2.pcm \
+// RUN:  -fmodule-file=%t/A_part3.pcm -o %t/A.pcm
+
+// expected-no-diagnostics
+
+#if TU == 1
+
+export module A:Part1;
+
+int part1();
+
+#elif TU == 2
+
+export module A:Part2;
+
+int part2();
+
+#elif TU == 3
+
+export module A:Part3;
+
+int part3();
+
+#elif TU == 4
+
+export module A;
+
+import :Part1;
+export import :Part2;
+import :Part3;
+
+int foo();
+
+#else
+#error "no TU set"
+#endif
Index: clang/test/CXX/module/module.unit/p8.cpp
===
--- clang/test/CXX/module/module.unit/p8.cpp
+++ clang/test/CXX/module/module.unit/p8.cpp
@@ -12,7 +12,7 @@
 
 #elif MODE == 1
 // expected-no-diagnostics
-module foo;
+module foo; // Implementation, implicitly imports foo.
 #define IMPORTED
 
 #elif MODE == 2
@@ -21,15 +21,15 @@
 #define IMPORTED
 
 #elif MODE == 3
-export module bar;
+export module bar; // A different module
 
 #elif MODE == 4
-module foo:bar; // expected-error {{not yet supported}}
-#define IMPORTED // FIXME
+module foo:bar; // Partition implementation
+//#define IMPORTED (we don't import foo here)
 
 #elif MODE == 5
-export module foo:bar; // expected-error {{not yet supported}} expected-error {{redefinition}} expected-note@* {{loaded from}}
-#define IMPORTED // FIXME
+export module foo:bar; // Partition interface
+//#define IMPORTED  (we don't import foo here)
 
 #endif
 
Index: clang/test/CXX/module/module.unit/p3.cpp
===
--- clang/test/CXX/module/module.unit/p3.cpp
+++ clang/test/CXX/module/module.unit/p3.cpp
@@ -1,4 +1,4 @@
 // RUN: %clang_cc1 -std=c++2a -verify %s
 
-export module foo:bar; // expected-error {{sorry, module partitions are not yet supported}}
-import :baz; // expected-error {{sorry, module partitions are not yet supported}}
+export module foo:bar;
+import :baz; // expected-error {{module 'foo:baz' not found}}
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -54,6 +54,23 @@
   }
 }
 
+// We represent the primary and partition names as 'Paths' which are sections
+// of the hierarchical access path for a clang module.  However for C++20
+// the periods in a name are just another character, and we will need to
+// flatten them into a string.
+static std::string stringFromPath(ModuleIdPath Path) {
+  std::string Name;
+  if (Path.empty())
+return Name;
+
+  for (auto &Piece : Path) {
+if (!Name.empty())
+  Name += ".";
+Name += Piece.first->getName();
+  }
+  return Name;
+}
+
 Sema::DeclGroupPtrTy
 Sema::ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc) {
   if (!ModuleScopes.empty() &&
@@ -80,11 +97,10 @@
   return nullptr;
 }
 
-Sema::DeclGroupPtrTy Sema::ActOnModuleDecl(So

[PATCH] D120258: [clangd] Add inlay hints for auto-typed parameters with one instantiation.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: nridge, Trass3r.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This takes a similar approach as b9b6938183e 
, and 
shares some code.
The code sharing is limited as inlay hints wants to deduce the type of the
variable rather than the type of the `auto` per-se.

It drops support (in both places) for multiple instantiations yielding the same
type, as this is pretty rare and hard to build a nice API around.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120258

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp

Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -247,7 +247,7 @@
   Visitor.F = Filter;
   Visitor.TraverseDecl(AST.getASTContext().getTranslationUnitDecl());
   if (Visitor.Decls.size() != 1) {
-llvm::errs() << Visitor.Decls.size() << " symbols matched.";
+llvm::errs() << Visitor.Decls.size() << " symbols matched.\n";
 assert(Visitor.Decls.size() == 1);
   }
   return *Visitor.Decls.front();
Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -676,6 +676,15 @@
   ExpectedHint{": int", "var"});
 }
 
+TEST(TypeHints, SinglyInstantiatedTemplate) {
+  assertTypeHints(R"cpp(
+auto $lambda[[x]] = [](auto *$param[[y]]) { return 42; };
+int m = x("foo");
+  )cpp",
+  ExpectedHint{": (lambda)", "lambda"},
+  ExpectedHint{": const char *", "param"});
+}
+
 TEST(DesignatorHints, Basic) {
   assertDesignatorHints(R"cpp(
 struct S { int x, y, z; };
Index: clang-tools-extra/clangd/unittests/ASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ASTTests.cpp
@@ -30,6 +30,7 @@
 namespace {
 using testing::Contains;
 using testing::Each;
+using testing::IsEmpty;
 
 TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
   struct Test {
@@ -192,12 +193,12 @@
   R"cpp(
 // Generic lambda instantiated twice, matching deduction.
 struct Foo{};
-using Bar = Foo;
 auto Generic = [](^auto x, auto y) { return 0; };
-int m = Generic(Bar{}, "one");
+int m = Generic(Foo{}, "one");
 int n = Generic(Foo{}, 2);
   )cpp",
-  "struct Foo",
+  // No deduction although both instantiations yield the same result :-(
+  nullptr,
   },
   {
   R"cpp(
@@ -253,6 +254,119 @@
   }
 }
 
+TEST(ClangdAST, GetOnlyInstantiation) {
+  struct {
+const char *Code;
+llvm::StringLiteral NodeType;
+const char *Name;
+  } Cases[] = {
+  {
+  R"cpp(
+template  class X {};
+X x;
+  )cpp",
+  "CXXRecord",
+  "template<> class X {}",
+  },
+  {
+  R"cpp(
+template  T X = T{};
+int y = X;
+  )cpp",
+  "Var",
+  // VarTemplateSpecializationDecl doesn't print as template<>...
+  "char X = char{}",
+  },
+  {
+  R"cpp(
+template  int X(T) { return 42; }
+int y = X("text");
+  )cpp",
+  "Function",
+  "template<> int X(const char *)",
+  },
+  {
+  R"cpp(
+int X(auto *x) { return 42; }
+int y = X("text");
+  )cpp",
+  "Function",
+  "template<> int X(const char *x)",
+  },
+  };
+
+  for (const auto &Case : Cases) {
+SCOPED_TRACE(Case.Code);
+auto TU = TestTU::withCode(Case.Code);
+TU.ExtraArgs.push_back("-std=c++20");
+auto AST = TU.build();
+AST.getASTContext().getTranslationUnitDecl()->dump();
+PrintingPolicy PP = AST.getASTContext().getPrintingPolicy();
+PP.TerseOutput = true;
+std::string Name;
+if (auto *Result = getOnlyInstantiation(
+const_cast(&findDecl(AST, [&](const NamedDecl &D) {
+  return D.getDescribedTemplate() != nullptr &&
+ D.getDeclKindName() == Case.NodeType;
+} {
+  llvm::raw_string_ostream OS(Name);
+  Result->print(OS, PP);
+}
+
+if (Case.Name)
+  EXP

[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

D120258  is the followup with inlay hints.

It rearranges some of the code from this patch for reuse, and proposes dropping 
support for multiple instantiations yielding the same result, as this 
inevitably pushes complexity into each place this is used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

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


[PATCH] D119481: run-clang-tidy: Fix infinite loop on windows

2022-02-21 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth accepted this revision.
JonasToth added a comment.
This revision is now accepted and ready to land.

LGTM with a small nit




Comment at: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py:69
   while not os.path.isfile(os.path.join(result, path)):
-if os.path.realpath(result) == '/':
+parent = os.path.dirname(result)
+if result == parent:

please delete the whitespace at the end of the line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119481

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


[PATCH] D120160: [Clang] Add `-funstable` flag to enable unstable and experimental features

2022-02-21 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver accepted this revision.
zoecarver added a comment.
This revision is now accepted and ready to land.

This looks great, thanks Egor!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120160

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


[PATCH] D54141: [clang-tidy] add deduplication support for run-clang-tidy.py

2022-02-21 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth abandoned this revision.
JonasToth added a comment.
Herald added a subscriber: mgehre.

won't happen anymore realistically.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D54141

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


[PATCH] D120262: [OpenCL] Handle TypeExtensions in OpenCLBuiltinFileEmitter

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

Until now, any types that had TypeExtensions attached to them were not
guarded with those extensions.  Extend the OpenCLBuiltinFileEmitter
such that all required extensions are emitted for the types of a
builtin function.

The `clang-tblgen -gen-clang-opencl-builtin-tests` emitter will now
produce e.g.:

  #if defined(cl_khr_fp16) && defined(cl_khr_fp64)
  half8 test11802_convert_half8_rtp(double8 arg1) {
return convert_half8_rtp(arg1);
  }
  #endif // TypeExtension


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120262

Files:
  clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Index: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
===
--- clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -17,6 +17,7 @@
 #include "TableGenBackends.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -293,6 +294,14 @@
   // was emitted.
   std::string emitVersionGuard(const Record *Builtin);
 
+  // Emit an #if guard for all type extensions required for the given type
+  // strings.
+  std::string
+  emitTypeExtensionGuards(const SmallVectorImpl &Signature);
+
+  // Map type strings to type extensions (e.g. "half2" -> "cl_khr_fp16").
+  StringMap TypeExtMap;
+
   // Contains OpenCL builtin functions and related information, stored as
   // Record instances. They are coming from the associated TableGen file.
   RecordKeeper &Records;
@@ -1057,7 +1066,16 @@
 // Insert the Cartesian product of the types and vector sizes.
 for (const auto &Vector : VectorList) {
   for (const auto &Type : TypeList) {
-ExpandedArg.push_back(getTypeString(Type, Flags, Vector));
+std::string FullType = getTypeString(Type, Flags, Vector);
+ExpandedArg.push_back(FullType);
+
+// If the type requires an extension, add a TypeExtMap entry mapping
+// the full type name to the extension.
+StringRef Ext =
+Arg->getValueAsDef("Extension")->getValueAsString("ExtName");
+if (!Ext.empty() && TypeExtMap.find(FullType) == TypeExtMap.end()) {
+  TypeExtMap.insert({FullType, Ext});
+}
   }
 }
 NumSignatures = std::max(NumSignatures, ExpandedArg.size());
@@ -1141,6 +1159,41 @@
   return OptionalEndif;
 }
 
+std::string OpenCLBuiltinFileEmitterBase::emitTypeExtensionGuards(
+const SmallVectorImpl &Signature) {
+  std::string OptionalEndif;
+  SmallSet ExtSet;
+
+  // Iterate over all types to gather the set of required TypeExtensions.
+  for (const auto &Ty : Signature) {
+StringRef TypeExt = TypeExtMap.lookup(Ty);
+if (!TypeExt.empty()) {
+  // The TypeExtensions are space-separated in the .td file.
+  SmallVector ExtVec;
+  TypeExt.split(ExtVec, " ");
+  for (const auto Ext : ExtVec) {
+ExtSet.insert(Ext);
+  }
+}
+  }
+
+  // Emit the #if when at least one extension is required.
+  if (!ExtSet.empty()) {
+OS << "#if ";
+bool isFirst = true;
+for (const auto Ext : ExtSet) {
+  if (!isFirst)
+OS << " && ";
+  OS << "defined(" << Ext << ")";
+  isFirst = false;
+}
+OS << "\n";
+OptionalEndif = "#endif // TypeExtension\n";
+  }
+
+  return OptionalEndif;
+}
+
 void OpenCLBuiltinTestEmitter::emit() {
   emitSourceFileHeader("OpenCL Builtin exhaustive testing", OS);
 
@@ -1163,6 +1216,8 @@
 std::string OptionalVersionEndif = emitVersionGuard(B);
 
 for (const auto &Signature : FTypes) {
+  std::string OptionalTypeExtEndif = emitTypeExtensionGuards(Signature);
+
   // Emit function declaration.
   OS << Signature[0] << " test" << TestID++ << "_" << Name << "(";
   if (Signature.size() > 1) {
@@ -1189,6 +1244,7 @@
 
   // End of function body.
   OS << "}\n";
+  OS << OptionalTypeExtEndif;
 }
 
 OS << OptionalVersionEndif;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-02-21 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D119199: replace clang LLVM_ENABLE_PLUGINS -> CLANG_PLUGIN_SUPPORT in tests

2022-02-21 Thread Cristian Adam via Phabricator via cfe-commits
cristian.adam added a comment.

`release/14.x` now configures but fails to build on MSVC2019 with `-D 
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON` like at https://reviews.llvm.org/D00

  FAILED: bin/CTTestTidyModule.dll
  cmd.exe /C "cd . && C:\tools\cmake\bin\cmake.exe -E vs_link_dll 
--intdir=tools\clang\tools\extra\test\CMakeFiles\CTTestTidyModule.dir 
--rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\rc.exe 
--mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\mt.exe --manifests  -- 
C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe
 /nologo 
tools\clang\tools\extra\test\CMakeFiles\CTTestTidyModule.dir\clang-tidy\CTTestTidyModule.cpp.obj
  /out:bin\CTTestTidyModule.dll /implib:lib\CTTestTidyModule.lib 
/pdb:bin\CTTestTidyModule.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO  
lib\clang-tidy.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib 
ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib  && cd ."
  LINK: command 
"C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe
 /nologo 
tools\clang\tools\extra\test\CMakeFiles\CTTestTidyModule.dir\clang-tidy\CTTestTidyModule.cpp.obj
 /out:bin\CTTestTidyModule.dll /implib:lib\CTTestTidyModule.lib 
/pdb:bin\CTTestTidyModule.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO 
lib\clang-tidy.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib 
ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST 
/MANIFESTFILE:bin\CTTestTidyModule.dll.manifest" failed (exit code 1120) with 
the following output:
  CTTestTidyModule.cpp.obj : error LNK2001: unresolved external symbol "class 
clang::ast_matchers::internal::VariadicDynCastAllOfMatcher const 
clang::ast_matchers::translationUnitDecl" 
(?translationUnitDecl@ast_matchers@clang@@3V?$VariadicDynCastAllOfMatcher@VDecl@clang@@VTranslationUnitDecl@2@@internal@12@B)
  bin\CTTestTidyModule.dll : fatal error LNK1120: 1 unresolved externals


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119199

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


[PATCH] D119162: [Pseudo] Token/TokenStream, PP directive parser.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 410340.
sammccall marked 26 inline comments as done.
sammccall added a comment.
Herald added a subscriber: dexonsmith.

address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119162

Files:
  clang/include/clang/Basic/TokenKinds.h
  clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h
  clang/include/clang/Tooling/Syntax/Pseudo/Token.h
  clang/lib/Basic/TokenKinds.cpp
  clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt
  clang/lib/Tooling/Syntax/Pseudo/Lex.cpp
  clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp
  clang/lib/Tooling/Syntax/Pseudo/Token.cpp
  clang/test/Syntax/Inputs/example.c
  clang/test/Syntax/lex.test
  clang/tools/clang-pseudo/ClangPseudo.cpp
  clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt
  clang/unittests/Tooling/Syntax/Pseudo/PreprocessTest.cpp
  clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp

Index: clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp
@@ -0,0 +1,178 @@
+//===--- TokenTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Syntax/Pseudo/Token.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/TokenKinds.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace syntax {
+namespace pseudo {
+namespace {
+
+using testing::AllOf;
+using testing::ElementsAre;
+using testing::ElementsAreArray;
+using testing::Not;
+
+MATCHER_P2(token, Text, Kind, "") {
+  return arg.Kind == Kind && arg.text() == Text;
+}
+
+MATCHER_P(hasFlag, Flag, "") { return arg.flag(Flag); }
+
+MATCHER_P2(lineIndent, Line, Indent, "") {
+  return arg.Line == (unsigned)Line && arg.Indent == (unsigned)Indent;
+}
+
+TEST(TokenTest, Lex) {
+  LangOptions Opts;
+  std::string Code = R"cpp(
+#include 
+int main() {
+  return 42; // the answer
+}
+  )cpp";
+  TokenStream Raw = lex(Code, Opts);
+  ASSERT_TRUE(Raw.isFinalized());
+  EXPECT_THAT(Raw.tokens(),
+  ElementsAreArray({
+  // Lexing of directives is weird, especially  strings.
+  token("#", tok::hash),
+  token("include", tok::raw_identifier),
+  token("<", tok::less),
+  token("stdio", tok::raw_identifier),
+  token(".", tok::period),
+  token("h", tok::raw_identifier),
+  token(">", tok::greater),
+
+  token("int", tok::raw_identifier),
+  token("main", tok::raw_identifier),
+  token("(", tok::l_paren),
+  token(")", tok::r_paren),
+  token("{", tok::l_brace),
+  token("return", tok::raw_identifier),
+  token("42", tok::numeric_constant),
+  token(";", tok::semi),
+  token("// the answer", tok::comment),
+  token("}", tok::r_brace),
+  }));
+
+  TokenStream Cooked = cook(Raw, Opts);
+  ASSERT_TRUE(Cooked.isFinalized());
+  EXPECT_THAT(Cooked.tokens(),
+  ElementsAreArray({
+  // Cooked identifier types in directives are not meaningful.
+  token("#", tok::hash),
+  token("include", tok::identifier),
+  token("<", tok::less),
+  token("stdio", tok::identifier),
+  token(".", tok::period),
+  token("h", tok::identifier),
+  token(">", tok::greater),
+
+  token("int", tok::kw_int),
+  token("main", tok::identifier),
+  token("(", tok::l_paren),
+  token(")", tok::r_paren),
+  token("{", tok::l_brace),
+  token("return", tok::kw_return),
+  token("42", tok::numeric_constant),
+  token(";", tok::semi),
+  token("// the answer", tok::comment),
+  token("}", tok::r_brace),
+  }));
+  // Check raw tokens point back into original source code.
+  EXPECT_EQ(Raw.tokens().front().text().begin(), &Code[Code.find('#')]);
+}
+
+TEST(TokenTest, LineContinuation) {
+  LangOptions Opts;
+  std::string Code = R"cpp(
+one_\
+token
+two \
+tokens
+  )cpp";
+  TokenStream Raw = lex(Code, Opts);
+  EXPECT_THAT(
+  Raw.tokens(),
+  ElementsAre(AllOf(token("one_\\\ntoken", tok::raw_identifier),
+hasFlag(LexFlags::StartsPPLine),
+hasFlag(LexFlags

[PATCH] D119162: [Pseudo] Token/TokenStream, PP directive parser.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h:49
+/// | `printf("hello, ");
+/// |-+ Conditional -+ Directive #ifndef NDEBUG
+/// | |-+ Code printf("debug\n");

hokein wrote:
> is the `-+ Directive` expected?
Yes, this is `Cond.Branches[0].first`.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h:103
+// FIXME: This approximates std::variant.
+// Switch once we can use C++17.
+class PPStructure::Chunk {

hokein wrote:
> yeah, this should be happened soon, see 
> https://discourse.llvm.org/t/rfc-increasing-the-gcc-and-clang-requirements-to-support-c-17-in-llvm/59983.
I hope so, but I'm not holding my breath.
(It'll happen soon enough that I'm not going to worry about optimizing this 
though)



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Token.h:64
+  /// Zero-based line number.
+  uint32_t Line = 0;
+  /// Width of whitespace before the first token on this line.

hokein wrote:
> nit: mention this is the line number for the start of token, a token can be 
> multiple-line.
> 
> I think the meaning of line number is token-stream-dependent, right? For a 
> lex token-stream, it is raw line number; For a cook token stream, it might 
> take the backslash continued line into account?
> 
> mention this is the line number for the start of token
Done.

> I think the meaning of line number is token-stream-dependent, right? 
This always refers to the original source code - a backslash continued line 
won't reduce the line number. Expanded the comment.




Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Token.h:89
+  uint32_t size() const { return End - Begin; }
+  static Range empty(unsigned Index) { return Range{Index, Index}; }
+};

hokein wrote:
> nit: unsigned -> Token::Index
> 
> I'd probably drop it (looks like only one place using it, inclining it should 
> be fine), the name empty is usually a method checking the Range is empty 
> rather than creating an empty Range.
This will be used in a bunch more places, and inlining it is awkward:
 - often have to extract an expression to a variable to avoid duplicating it
 - it's IMO much less obvious at the callsite the intent is to specify an empty 
range

You're right about the name though, renamed to emptyAt which hopefully avoids 
that association.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Token.h:130
+assert(&T != Storage.data() && "start sentinel");
+assert(&T >= Storage.data() && &T < Storage.data() + Storage.size());
+return &T - Tokens.data();

hokein wrote:
> `>=` => `>`, since we have checked above.
I'm not sure why that change would be an improvement, can you elaborate?

The two assertions are that we own the token, and that it's not the start 
sentinel. I think changing the condition makes that less clear.

(Reordered them though, as the start-sentinel assertion seems secondary)



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Token.h:166
+/// Tokens at the start of an unescaped newline (where a directive may start)
+/// will have StartsPPLine.
+/// "word-like" tokens such as identifiers and keywords will be raw_identifier.

hokein wrote:
> I think it would be clearer to give more details (for example, give some 
> examples) in the comment to clarify -- it took me quite a while to understand 
> "an unescaped newline" (I guess this refers to the backslash continued line?).
> 
> And having a PP in the name seems a little confusing, it somehow indicates 
> this flag  is PP-specific, e.g. for a simple example without any PP structure 
> `int a;` the `int` token has the  `StartsPPLine` being set.
Oops, this sentence didn't make much sense. The point is that the preprocessor 
distinguishes between logical and physical lines:

```
#define X(error) \
  #error // this is not a directive
auto m = X(foo); // string "foo"
```

This concept of "logical line" and the rules around it are specific to the 
preprocessor. The rest of the parser is line-agnostic or uses physical line 
numbers. So I think PP belongs in the name.

Expanded the comment here.



Comment at: clang/lib/Tooling/Syntax/Pseudo/Lex.cpp:65
+
+if (CT.isAtStartOfLine())
+  Tok.setFlag(LexFlags::StartsPPLine);

hokein wrote:
> just want to double-check this is the behavior we want,
> 
> From the clang's token comment:
> ```
> TokenFlags::StartOfLine  // At start of line or only after whitespace
> 
> 
> so the `abc` token will have this flag
> ```
> abc // abc has two leading spaces.
Yes. This matches the logic clang uses (Lexer.cpp:657) to decide whether a hash 
starts a PP directive, which is what this flag is intended to emulate.



Comment at: clang/lib/Tool

[clang] e2855e1 - [Clang][OpenMP] Add Sema support for atomic compare capture

2022-02-21 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2022-02-21T14:21:02-05:00
New Revision: e2855e17601e8a193bf07b0533be69dbf85b811c

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

LOG: [Clang][OpenMP] Add Sema support for atomic compare capture

This patch adds Sema support for `atomic compare capture`.

Reviewed By: ABataev

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/atomic_messages.c
clang/test/OpenMP/atomic_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0d301e76c92d..1854c8e522b8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10523,10 +10523,16 @@ def err_omp_atomic_compare : Error<
   " '{x = x == e ? d : x;}', '{x = e == x ? d : x;}', or 'if(expr ordop x) {x 
= expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}',"
   " 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 
'expr', 'e', and 'd' are expressions with scalar type,"
   " and 'ordop' is one of '<' or '>'.">;
+def err_omp_atomic_compare_capture : Error<
+  "the statement for 'atomic compare capture' must be a compound statement of 
form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} 
else {v = x;}}',"
+  " '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = 
x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr 
ordop x) {x = expr;}',"
+  " 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = 
d;}' where 'x', 'r', and 'v' are lvalue expressions with scalar type, 'expr', 
'e', and 'd' are expressions with scalar type,"
+  " and 'ordop' is one of '<' or '>'.">;
 def note_omp_atomic_compare: Note<
   "%select{expected compound statement|expected exactly one expression 
statement|expected assignment statement|expected conditional operator|expect 
result value to be at false expression|"
   "expect binary operator in conditional expression|expect '<', '>' or '==' as 
order operator|expect comparison in a form of 'x == e', 'e == x', 'x ordop 
expr', or 'expr ordop x'|"
-  "expect lvalue for result value|expect scalar value|expect integer 
value|unexpected 'else' statement}0">;
+  "expect lvalue for result value|expect scalar value|expect integer 
value|unexpected 'else' statement|expect '==' operator|expect an assignment 
statement 'v = x'|"
+  "expect a 'if' statement|expect no more than two statements|expect a 
compound statement|expect 'else' statement|expect a form 'r = x == e; if (r) 
...'}0">;
 def err_omp_atomic_several_clauses : Error<
   "directive '#pragma omp atomic' cannot contain more than one 'read', 
'write', 'update', 'capture', or 'compare' clause">;
 def err_omp_several_mem_order_clauses : Error<

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index c32609e4e32e..43386c1ef8ed 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -10976,6 +10976,20 @@ class OpenMPAtomicCompareChecker {
 NotInteger,
 /// 'else' statement is not expected.
 UnexpectedElse,
+/// Not an equality operator.
+NotEQ,
+/// Invalid assignment (not v == x).
+InvalidAssignment,
+/// Not if statement
+NotIfStmt,
+/// More than two statements in a compund statement.
+MoreThanTwoStmts,
+/// Not a compound statement.
+NotCompoundStmt,
+/// No else statement.
+NoElse,
+/// Not 'if (r)'.
+InvalidCondition,
 /// No error.
 NoError,
   };
@@ -10999,7 +11013,7 @@ class OpenMPAtomicCompareChecker {
   Expr *getCond() const { return C; }
   bool isXBinopExpr() const { return IsXBinopExpr; }
 
-private:
+protected:
   /// Reference to ASTContext
   ASTContext &ContextRef;
   /// 'x' lvalue part of the source atomic expression.
@@ -11026,6 +11040,35 @@ class OpenMPAtomicCompareChecker {
 
   /// Check if all captured values have right type.
   bool checkType(ErrorInfoTy &ErrorInfo) const;
+
+  static bool CheckValue(const Expr *E, ErrorInfoTy &ErrorInfo,
+ bool ShouldBeLValue) {
+if (ShouldBeLValue && !E->isLValue()) {
+  ErrorInfo.Error = ErrorTy::XNotLValue;
+  ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
+  ErrorInfo.ErrorRange = ErrorInfo.NoteRange = E->getSourceRange();
+  return false;
+}
+
+if (!E->isInstantiationDependent()) {
+  QualType QTy = E->getType();
+  if (!QTy->isScalarType()) {
+ErrorInfo.Error = ErrorTy::NotScalar;
+ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
+ErrorInfo.E

[PATCH] D120200: [Clang][OpenMP] Add Sema support for atomic compare capture

2022-02-21 Thread Shilei Tian 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 rGe2855e17601e: [Clang][OpenMP] Add Sema support for atomic 
compare capture (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120200

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/atomic_messages.c
  clang/test/OpenMP/atomic_messages.cpp

Index: clang/test/OpenMP/atomic_messages.cpp
===
--- clang/test/OpenMP/atomic_messages.cpp
+++ clang/test/OpenMP/atomic_messages.cpp
@@ -928,7 +928,7 @@
 }
 
 int mixed() {
-  int a, b = 0;
+  int a, v, b = 0;
 // expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause}}
 // expected-note@+1 {{'read' clause used here}}
 #pragma omp atomic read write
@@ -957,7 +957,7 @@
 // expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'compare' clause}}
 // expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'capture' clause}}
 #pragma omp atomic compare compare capture capture
-  a = b;
+  { v = a; if (a > b) a = b; }
 #endif
   // expected-note@+1 {{in instantiation of function template specialization 'mixed' requested here}}
   return mixed();
Index: clang/test/OpenMP/atomic_messages.c
===
--- clang/test/OpenMP/atomic_messages.c
+++ clang/test/OpenMP/atomic_messages.c
@@ -500,4 +500,199 @@
   fx = fe;
   }
 }
+
+void compare_capture(void) {
+  int x = 0;
+  int d = 0;
+  int e = 0;
+  int v = 0;
+  int r = 0;
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+2 {{expected compound statement}}
+#pragma omp atomic compare capture
+  if (x == e) {}
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+2 {{expected exactly one expression statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+x = d;
+v = x;
+  }
+// omp51-error@+4 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+3 {{expected assignment statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+bbar();
+  }
+// omp51-error@+4 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+3 {{expected assignment statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+x += d;
+  }
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt'

[PATCH] D120266: [clang][CodeGen] Avoid emitting ifuncs with undefined resolvers

2022-02-21 Thread Itay Bookstein via Phabricator via cfe-commits
ibookstein created this revision.
ibookstein added reviewers: erichkeane, rsmith, MaskRay.
ibookstein requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The purpose of this change is to fix the following codegen bug:

// main.c
__attribute__((cpu_specific(generic)))
int *foo(void) { static int z; return &z;}
int main() { return *foo() = 5; }

// other.c
__attribute__((cpu_dispatch(generic))) int *foo(void);

// run:
clang main.c other.c -o main; ./main

This will segfault prior to the change, and return the correct
exit code 5 after the change.

The underlying cause is that when a translation unit contains
a cpu_specific function without the corresponding cpu_dispatch
(which is a valid use-case, they can be put into different
translation units), the generated code binds the reference to
foo() against a GlobalIFunc whose resolver is undefined. This
is invalid (the resolver must be defined in the same translation
unit as the ifunc), but historically the LLVM bitcode verifier
did not check that. The generated code then binds against the
resolver rather than the ifunc, so it ends up calling the
resolver rather than the resolvee. In the example above it treats
its return value as an int *, therefore trying to write to program
text.

The root issue at the representation level is that GlobalIFunc,
like GlobalAlias, does not support a "declaration" state. The
object which provides the correct semantics in these cases
is a Function declaration, but unlike Functions, changing a
declaration to a definition in the GlobalIFunc case constitutes
a change of the object type (as opposed to simply emitting code
into the function).

I think this limitation is unlikely to change, so I implemented
the fix by rewriting the generated IR to use a function
declaration instead of an ifunc if the resolver ends up undefined.
This uses takeName + replaceAllUsesWith in similar vein to
other places where the correct IR object type cannot be known
up front locally, like in CodeGenModule::EmitAliasDefinition.
In this case, we don't know whether the translation unit
will contain the cpu_dispatch when generating code for a reference
bound against a cpu_specific symbol.

It is also possible to generate the reference as a Function
declaration first, and 'upgrade' it to a GlobalIFunc once a
cpu_dispatch is encountered, which is somewhat more 'natural'.
That would involve a larger code change, though, so I wanted to
get feedback on the viability of the approach first.

Signed-off-by: Itay Bookstein 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120266

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/attr-cpuspecific.c

Index: clang/test/CodeGen/attr-cpuspecific.c
===
--- clang/test/CodeGen/attr-cpuspecific.c
+++ clang/test/CodeGen/attr-cpuspecific.c
@@ -8,6 +8,7 @@
 #endif // _MSC_VER
 
 // Each version should have an IFunc and an alias.
+// LINUX: @SingleVersion = weak_odr alias void (), void ()* @SingleVersion.ifunc
 // LINUX: @TwoVersions = weak_odr alias void (), void ()* @TwoVersions.ifunc
 // LINUX: @TwoVersionsSameAttr = weak_odr alias void (), void ()* @TwoVersionsSameAttr.ifunc
 // LINUX: @ThreeVersionsSameAttr = weak_odr alias void (), void ()* @ThreeVersionsSameAttr.ifunc
@@ -18,8 +19,8 @@
 // LINUX: @GenericAndPentium = weak_odr alias i32 (i32, double), i32 (i32, double)* @GenericAndPentium.ifunc
 // LINUX: @DispatchFirst = weak_odr alias i32 (), i32 ()* @DispatchFirst.ifunc
 
-// LINUX: @TwoVersions.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersions.resolver
 // LINUX: @SingleVersion.ifunc = weak_odr ifunc void (), void ()* ()* @SingleVersion.resolver
+// LINUX: @TwoVersions.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersions.resolver
 // LINUX: @TwoVersionsSameAttr.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersionsSameAttr.resolver
 // LINUX: @ThreeVersionsSameAttr.ifunc = weak_odr ifunc void (), void ()* ()* @ThreeVersionsSameAttr.resolver
 // LINUX: @NoSpecifics.ifunc = weak_odr ifunc void (), void ()* ()* @NoSpecifics.resolver
@@ -34,6 +35,21 @@
 // LINUX: define{{.*}} void @SingleVersion.S() #[[S:[0-9]+]]
 // WINDOWS: define dso_local void @SingleVersion.S() #[[S:[0-9]+]]
 
+ATTR(cpu_dispatch(ivybridge))
+void SingleVersion(void);
+// LINUX: define weak_odr void ()* @SingleVersion.resolver()
+// LINUX: call void @__cpu_indicator_init
+// LINUX: ret void ()* @SingleVersion.S
+// LINUX: call void @llvm.trap
+// LINUX: unreachable
+
+// WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
+// WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: call void @SingleVersion.S()
+// WINDOWS-NEXT: ret void
+// WINDOWS: call void @llvm.trap
+// WINDOWS: unreachable
+
 ATTR(cpu_specific(ivybridge))
 void NotCalled(void){}
 // LINUX: define{{.*}} void @NotCalled.S() #[[S]]
@@ -80,6 +96,10 @@
 // CHECK: define {{.*}

[PATCH] D118587: [C++20][Modules][4/8] Handle generation of partition implementation CMIs.

2022-02-21 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 410348.
iains added a comment.

rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118587

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/cxx20-10-1-ex1.cpp
  clang/test/Modules/cxx20-10-1-ex2.cpp
  clang/test/Modules/cxx20-import-diagnostics-a.cpp

Index: clang/test/Modules/cxx20-import-diagnostics-a.cpp
===
--- clang/test/Modules/cxx20-import-diagnostics-a.cpp
+++ clang/test/Modules/cxx20-import-diagnostics-a.cpp
@@ -94,9 +94,9 @@
 #elif TU == 6
 
 module;
-// We can only have preprocessor commands here, which could include an include
+// We can only have preprocessor directives here, which permits an include-
 // translated header unit.  However those are identified specifically by the
-// preprocessor; non-preprocessed user code should not contain an import here.
+// preprocessor; non-preprocessed user code should not contain an 'import' here.
 import B; // expected-error {{module imports cannot be in the global module fragment}}
 
 export module D;
Index: clang/test/Modules/cxx20-10-1-ex2.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-1-ex2.cpp
@@ -0,0 +1,60 @@
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=1 -x c++ %s \
+// RUN:  -o %t/B_Y.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=2 -x c++ %s \
+// RUN:  -fmodule-file=%t/B_Y.pcm -o %t/B.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=3 -x c++ %s \
+// RUN:   -o %t/B_X1.pcm -verify
+
+// Not expected to work yet.
+//  %clang_cc1 -std=c++20 -emit-module-interface -D TU=4 -x c++ %s \
+//   -fmodule-file=%t/B.pcm  -o %t/B_X2.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -D TU=5 -x c++ %s \
+// RUN:  -fmodule-file=%t/B.pcm  -o %t/b_tu5.s
+
+// RUN: %clang_cc1 -std=c++20 -S -D TU=6 -x c++ %s \
+// RUN:  -fmodule-file=%t/B.pcm  -o %t/b_tu6.s -verify
+
+// Not expected to work yet.
+//  %clang_cc1 -std=c++20 -emit-module-interface -D TU=7 -x c++ %s \
+//   -fmodule-file=%t/B_X2.pcm  -o %t/B_X3.pcm -verify
+
+#if TU == 1
+  module B:Y;
+  int y();
+// expected-no-diagnostics
+#elif TU == 2
+  export module B;
+  import :Y;
+  int n = y();
+// expected-no-diagnostics
+#elif TU == 3
+  module B:X1; // does not implicitly import B
+  int &a = n;  // expected-error {{use of undeclared identifier }}
+#elif TU == 4
+  module B:X2; // does not implicitly import B
+  import B;
+  int &b = n; // OK
+// expected-no-diagnostics
+#elif TU == 5
+  module B; // implicitly imports B
+  int &c = n; // OK
+// expected-no-diagnostics
+#elif TU == 6
+  import B;
+  // error, n is module-local and this is not a module.
+  int &c = n; // expected-error {{use of undeclared identifier}}
+#elif TU == 7
+  module B:X3; // does not implicitly import B
+  import :X2; // X2 is an implementation so exports nothing.
+  // error: n not visible here.
+  int &c = n; // expected-error {{use of undeclared identifier }}
+#else
+#error "no TU set"
+#endif
Index: clang/test/Modules/cxx20-10-1-ex1.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-1-ex1.cpp
@@ -0,0 +1,50 @@
+// The example in the standard is not in required build order.
+// revised here
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=1 -x c++ %s \
+// RUN:  -o %t/A_Internals.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=2 -x c++ %s \
+// RUN:  -fmodule-file=%t/A_Internals.pcm -o %t/A_Foo.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=3 -x c++ %s \
+// RUN:  -fmodule-file=%t/A_Foo.pcm -o %t/A.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj  -D TU=4 -x c++ %s \
+// RUN:  -fmodule-file=%t/A.pcm -o %t/ex1.o
+
+// expected-no-diagnostics
+
+#if TU == 1
+
+module A:Internals;
+int bar();
+
+#elif TU == 2
+
+export module A:Foo;
+
+import :Internals;
+
+export int foo() { return 2 * (bar() + 1); }
+
+#elif TU == 3
+
+export module A;
+export import :Foo;
+export int baz();
+
+#elif TU == 4
+module A;
+
+import :Internals;
+
+int bar() { return baz() - 10; }
+int baz() { return 30; }
+
+#else
+#error "no TU set"
+#endif
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -110,9 +110,24 @@
   // module state;
   ImportState = ModuleImportState::NotACXX20Module;
 
-  // A module implementation unit requires that we are not compiling a module
-  // of any kind. A module interface unit requires that we are not compiling a
-  // module map.
+  bool IsPartition = !Partition.empty();
+  if (IsPartition)
+switch (MDK) {
+case ModuleDe

[PATCH] D120270: [OpenMP] Try to embed offloading objects after codegen

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield.
Herald added subscribers: ormris, guansong, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Currently we use the `-fembed-offload-object` option to embed a binary
file into the host as a named section. This is currently only used as a
codegen action, meaning we only handle this option correctly when the
input is a bitcode file. This patch adds the same handling to embed an
offloading object after we complete code generation. This allows us to
embed the object correctly if the input file is source or bitcode.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120270

Files:
  clang/include/clang/CodeGen/BackendUtil.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -43,6 +43,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
+#include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -587,6 +588,9 @@
 EmitModuleLinkOptions();
   }
 
+  // If there is device offloading code embed it in the host now.
+  EmbedObject(getModule(), CodeGenOpts, getDiags());
+
   // On ELF we pass the dependent library specifiers directly to the linker
   // without manipulating them. This is in contrast to other platforms where
   // they are mapped to a specific linker option by the compiler. This
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -1134,7 +1134,7 @@
 TheModule->setTargetTriple(TargetOpts.Triple);
   }
 
-  EmbedObject(TheModule.get(), CodeGenOpts, Diagnostics);
+  EmbedObject(*TheModule.get(), CodeGenOpts, Diagnostics);
   EmbedBitcode(TheModule.get(), CodeGenOpts, *MainFile);
 
   LLVMContext &Ctx = TheModule->getContext();
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1753,7 +1753,7 @@
   CGOpts.CmdArgs);
 }
 
-void clang::EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts,
+void clang::EmbedObject(llvm::Module &M, const CodeGenOptions &CGOpts,
 DiagnosticsEngine &Diags) {
   if (CGOpts.OffloadObjects.empty())
 return;
@@ -1771,12 +1771,12 @@
 if (std::error_code EC = ObjectOrErr.getError()) {
   auto DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
   "could not open '%0' for embedding");
-  Diags.Report(DiagID) << std::get<0>(FilenameAndSection);
+  Diags.Report(DiagID) << FilenameAndSection.first;
   return;
 }
 
 SmallString<128> SectionName(
-{".llvm.offloading.", std::get<1>(FilenameAndSection)});
-llvm::embedBufferInModule(*M, **ObjectOrErr, SectionName);
+{".llvm.offloading.", FilenameAndSection.second});
+llvm::embedBufferInModule(M, **ObjectOrErr, SectionName);
   }
 }
Index: clang/include/clang/CodeGen/BackendUtil.h
===
--- clang/include/clang/CodeGen/BackendUtil.h
+++ clang/include/clang/CodeGen/BackendUtil.h
@@ -45,7 +45,7 @@
   void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts,
 llvm::MemoryBufferRef Buf);
 
-  void EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts,
+  void EmbedObject(llvm::Module &M, const CodeGenOptions &CGOpts,
DiagnosticsEngine &Diags);
 }
 


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -43,6 +43,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
+#include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -587,6 +588,9 @@
 EmitModuleLinkOptions();
   }
 
+  // If there is device offloading code embed it in the host now.
+  EmbedObject(getModule(), CodeGenOpts, getDiags());
+
   // On ELF we pass the dependent library specifiers directly to the linker
   // without manipulating them. This is in contrast to other platforms where
   // they are mapped to a specific linker option by the compiler. This
Index: clang/lib/CodeGen/CodeGenAction.cpp
=

[PATCH] D120271: [Clang] Add offload kind to embedded offload object

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This patch adds the offload kind to the embedded section name in
preparation for offloading to different kinda like CUDA or HIP. Also
simplify the key handling by adding a dense map info implementation for
the device file struct.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120271

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -151,15 +151,43 @@
 
 /// Information for a device offloading file extracted from the host.
 struct DeviceFile {
-  DeviceFile(StringRef TheTriple, StringRef Arch, StringRef Filename)
-  : TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
-
-  const std::string TheTriple;
-  const std::string Arch;
-  const std::string Filename;
+  DeviceFile(StringRef OffloadKind, StringRef TheTriple, StringRef Arch,
+ StringRef Filename)
+  : OffloadKind(OffloadKind), TheTriple(TheTriple), Arch(Arch),
+Filename(Filename) {}
+
+  std::string OffloadKind;
+  std::string TheTriple;
+  std::string Arch;
+  std::string Filename;
+};
 
-  operator std::string() const { return TheTriple + "-" + Arch; }
+namespace llvm {
+/// Helper that allows DeviceFile to be used as a key in a DenseMap.
+template <> struct DenseMapInfo {
+  static DeviceFile getEmptyKey() {
+return {DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey()};
+  }
+  static DeviceFile getTombstoneKey() {
+return {DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey()};
+  }
+  static unsigned getHashValue(const DeviceFile &I) {
+return DenseMapInfo::getHashValue(I.OffloadKind) ^
+   DenseMapInfo::getHashValue(I.TheTriple) ^
+   DenseMapInfo::getHashValue(I.Arch);
+  }
+  static bool isEqual(const DeviceFile &LHS, const DeviceFile &RHS) {
+return LHS.OffloadKind == RHS.OffloadKind &&
+   LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
+  }
 };
+} // namespace llvm
 
 namespace {
 
@@ -187,7 +215,7 @@
 DeviceFile getBitcodeLibrary(StringRef LibraryStr) {
   auto DeviceAndPath = StringRef(LibraryStr).split('=');
   auto TripleAndArch = DeviceAndPath.first.rsplit('-');
-  return DeviceFile(TripleAndArch.first, TripleAndArch.second,
+  return DeviceFile("openmp", TripleAndArch.first, TripleAndArch.second,
 DeviceAndPath.second);
 }
 
@@ -266,16 +294,17 @@
 
 SmallVector SectionFields;
 Name->split(SectionFields, '.');
-StringRef DeviceTriple = SectionFields[3];
-StringRef Arch = SectionFields[4];
+StringRef Kind = SectionFields[3];
+StringRef DeviceTriple = SectionFields[4];
+StringRef Arch = SectionFields[5];
 
 if (Expected Contents = Sec.getContents()) {
   SmallString<128> TempFile;
   StringRef DeviceExtension = getDeviceFileExtension(
   DeviceTriple, identify_magic(*Contents) == file_magic::bitcode);
-  if (Error Err =
-  createOutputFile(Prefix + "-device-" + DeviceTriple + "-" + Arch,
-   DeviceExtension, TempFile))
+  if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" +
+   DeviceTriple + "-" + Arch,
+   DeviceExtension, TempFile))
 return std::move(Err);
 
   Expected> OutputOrErr =
@@ -287,7 +316,7 @@
   if (Error E = Output->commit())
 return std::move(E);
 
-  DeviceFiles.emplace_back(DeviceTriple, Arch, TempFile);
+  DeviceFiles.emplace_back(Kind, DeviceTriple, Arch, TempFile);
   ToBeStripped.push_back(*Name);
 }
   }
@@ -376,6 +405,7 @@
 
 SmallVector SectionFields;
 GV.getSection().split(SectionFields, '.');
+StringRef Kind = SectionFields[3];
 StringRef DeviceTriple = SectionFields[3];
 StringRef Arch = SectionFields[4];
 
@@ -383,9 +413,9 @@
 SmallString<128> TempFile;
 StringRef DeviceExtension = getDeviceFileExtension(
 DeviceTriple, identify_magic(Contents) == file_magic::bitcode);
-if (Error Err =
-createOutputFile(Prefix + "-device-" + DeviceTriple + "-" + Arch,
- DeviceExtension, TempFile))
+if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" + DeviceTriple +
+ "-" + Arch,
+ DeviceExtension, TempF

[PATCH] D120272: [CUDA] Add driver support for compiling CUDA with the new driver

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield, tra, yaxunl.
Herald added a subscriber: carlosgalvezp.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This patch adds the basic support for the clang driver to compile and link CUDA
using the new offloading driver. This requires handling the CUDA offloading kind
and embedding the generated files into the host. This will allow us to link
OpenMP code with CUDA code in the linker wrapper.

Depends on D120270  D120271 



Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120272

Files:
  clang/include/clang/Driver/Compilation.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp

Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4374,6 +4374,7 @@
   // one input.
   bool IsCuda = JA.isOffloading(Action::OFK_Cuda);
   bool IsCudaDevice = JA.isDeviceOffloading(Action::OFK_Cuda);
+  bool IsCudaHost = JA.isHostOffloading(Action::OFK_Cuda);
   bool IsHIP = JA.isOffloading(Action::OFK_HIP);
   bool IsHIPDevice = JA.isDeviceOffloading(Action::OFK_HIP);
   bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP);
@@ -4397,6 +4398,7 @@
 
   InputInfoList ModuleHeaderInputs;
   InputInfoList OpenMPHostInputs;
+  InputInfoList CudaHostInputs;
   const InputInfo *CudaDeviceInput = nullptr;
   const InputInfo *OpenMPDeviceInput = nullptr;
   for (const InputInfo &I : Inputs) {
@@ -4411,6 +4413,8 @@
 << types::getTypeName(Expected);
   }
   ModuleHeaderInputs.push_back(I);
+} else if (IsCudaHost && Args.hasArg(options::OPT_fopenmp_new_driver)) {
+  CudaHostInputs.push_back(I);
 } else if ((IsCuda || IsHIP) && !CudaDeviceInput) {
   CudaDeviceInput = &I;
 } else if (IsOpenMPDevice && !OpenMPDeviceInput) {
@@ -6929,6 +6933,7 @@
 auto OpenMPTCs = C.getOffloadToolChains();
 for (auto TI = OpenMPTCs.first, TE = OpenMPTCs.second; TI != TE;
  ++TI, ++InputFile) {
+  assert(InputFile->isFilename() && "Offloading requires a filename");
   const ToolChain *TC = TI->second;
   const ArgList &TCArgs = C.getArgsForToolChain(TC, "", Action::OFK_OpenMP);
   StringRef File =
@@ -6941,6 +6946,25 @@
   TC->getTripleString() + "." +
   TCArgs.getLastArgValue(options::OPT_march_EQ) + "." + InputName));
 }
+  } else if (IsCudaHost && !CudaHostInputs.empty()) {
+const ToolChain *CudaTC = C.getSingleOffloadToolChain();
+for (const auto &InputFile : CudaHostInputs) {
+  assert(InputFile.isFilename() && "Offloading requires a filename");
+  StringRef File =
+  C.getArgs().MakeArgString(CudaTC->getInputFilename(InputFile));
+  StringRef InputName = Clang::getBaseInputStem(Args, Inputs);
+  // The CUDA toolchain should have a bound arch appended to the filename.
+  StringRef Arch = File.split(".").first.rsplit('-').second;
+  // CUDA offloads both the PTX and Cubin so we need a uniqe section name.
+  if (File.endswith(".s"))
+CmdArgs.push_back(Args.MakeArgString(
+"-fembed-offload-object=" + File + "," + "cuda." +
+CudaTC->getTripleString() + "." + Arch + ".ptx." + InputName));
+  else
+CmdArgs.push_back(Args.MakeArgString(
+"-fembed-offload-object=" + File + "," + "cuda." +
+CudaTC->getTripleString() + "." + Arch + "." + InputName));
+}
   }
 
   if (Triple.isAMDGPU()) {
@@ -8189,6 +8213,7 @@
   const Driver &D = getToolChain().getDriver();
   const llvm::Triple TheTriple = getToolChain().getTriple();
   auto OpenMPTCRange = C.getOffloadToolChains();
+  auto CudaTCRange = C.getOffloadToolChains();
   ArgStringList CmdArgs;
 
   // Pass the CUDA path to the linker wrapper tool.
@@ -8202,6 +8227,16 @@
   break;
 }
   }
+  for (auto &I : llvm::make_range(CudaTCRange.first, CudaTCRange.second)) {
+const ToolChain *TC = I.second;
+if (TC->getTriple().isNVPTX()) {
+  CudaInstallationDetector CudaInstallation(D, TheTriple, Args);
+  if (CudaInstallation.isValid())
+CmdArgs.push_back(Args.MakeArgString(
+"--cuda-path=" + CudaInstallation.getInstallPath()));
+  break;
+}
+  }
 
   // Get the AMDGPU math libraries.
   // FIXME: This method is bad, remove once AMDGPU has a proper math library
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -3830,11 +3830,6 @@
   // Builder to be used to build offloading actions.
   OffloadingActionBuilder OffloadBuilder(C, Args, Inputs);
 
-  // Offload kinds active for this compilation.
-  unsigned OffloadKinds = Action::OFK_None;
-  if (C

[PATCH] D120273: [OpenMP] Allow CUDA to be linked with OpenMP using the new driver

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield.
Herald added subscribers: guansong, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

After basic support for embedding and handling CUDA files was added to
the new driver, we should be able to call CUDA functions from OpenMP
code. This patch makes the necessary changes to successfuly link in CUDA
programs that were compiled using the new driver. With this patch it
should be possible to compile device-only CUDA code (no kernels) and
call it from OpenMP as follows:

  $ clang++ cuda.cu -fopenmp-new-driver -offload-arch=sm_70 -c
  $ clang++ openmp.cpp cuda.o -fopenmp-new-driver -fopenmp 
-fopenmp-targets=nvptx64 -Xopenmp-target=nvptx64 -march=sm_70

Currently this requires using a host variant to suppress the generation
of a CPU-side fallback call.

Depends on D120272 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120273

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -163,7 +163,10 @@
 };
 
 namespace llvm {
-/// Helper that allows DeviceFile to be used as a key in a DenseMap.
+/// Helper that allows DeviceFile to be used as a key in a DenseMap. For now we
+/// assume device files with matching architectures and triples but different
+/// offloading kinds should be handlded together, this may not be true in the
+/// future.
 template <> struct DenseMapInfo {
   static DeviceFile getEmptyKey() {
 return {DenseMapInfo::getEmptyKey(),
@@ -178,13 +181,11 @@
 DenseMapInfo::getTombstoneKey()};
   }
   static unsigned getHashValue(const DeviceFile &I) {
-return DenseMapInfo::getHashValue(I.OffloadKind) ^
-   DenseMapInfo::getHashValue(I.TheTriple) ^
+return DenseMapInfo::getHashValue(I.TheTriple) ^
DenseMapInfo::getHashValue(I.Arch);
   }
   static bool isEqual(const DeviceFile &LHS, const DeviceFile &RHS) {
-return LHS.OffloadKind == RHS.OffloadKind &&
-   LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
+return LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
   }
 };
 } // namespace llvm
@@ -196,10 +197,12 @@
   SmallVectorImpl &DeviceFiles);
 
 static StringRef getDeviceFileExtension(StringRef DeviceTriple,
-bool IsBitcode = false) {
+file_magic magic) {
   Triple TheTriple(DeviceTriple);
-  if (TheTriple.isAMDGPU() || IsBitcode)
+  if (magic == file_magic::bitcode)
 return "bc";
+  if (TheTriple.isNVPTX() && magic == file_magic::unknown)
+return "s";
   if (TheTriple.isNVPTX())
 return "cubin";
   return "o";
@@ -300,8 +303,8 @@
 
 if (Expected Contents = Sec.getContents()) {
   SmallString<128> TempFile;
-  StringRef DeviceExtension = getDeviceFileExtension(
-  DeviceTriple, identify_magic(*Contents) == file_magic::bitcode);
+  StringRef DeviceExtension =
+  getDeviceFileExtension(DeviceTriple, identify_magic(*Contents));
   if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" +
DeviceTriple + "-" + Arch,
DeviceExtension, TempFile))
@@ -411,8 +414,8 @@
 
 StringRef Contents = CDS->getAsString();
 SmallString<128> TempFile;
-StringRef DeviceExtension = getDeviceFileExtension(
-DeviceTriple, identify_magic(Contents) == file_magic::bitcode);
+StringRef DeviceExtension =
+getDeviceFileExtension(DeviceTriple, identify_magic(Contents));
 if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" + DeviceTriple +
  "-" + Arch,
  DeviceExtension, TempFile))
@@ -908,7 +911,22 @@
   return createFileError(File, EC);
 
 file_magic Type = identify_magic((*BufferOrErr)->getBuffer());
-if (Type != file_magic::bitcode) {
+switch (Type) {
+case file_magic::bitcode: {
+  Expected> InputFileOrErr =
+  llvm::lto::InputFile::create(**BufferOrErr);
+  if (!InputFileOrErr)
+return InputFileOrErr.takeError();
+
+  // Save the input file and the buffer associated with its memory.
+  BitcodeFiles.push_back(std::move(*InputFileOrErr));
+  SavedBuffers.push_back(std::move(*BufferOrErr));
+  continue;
+}
+case file_magic::elf_relocatable:
+case file_magic::elf_shared_object:
+case file_magic::macho_object:
+case file_magic::coff_object: {
   Expected> ObjFile =
   ObjectFile::createObjectFile(**BufferOrErr, Type);
   if (!ObjFile)
@@ -926,15 +94

[PATCH] D120266: [clang][CodeGen] Avoid emitting ifuncs with undefined resolvers

2022-02-21 Thread Itay Bookstein via Phabricator via cfe-commits
ibookstein updated this revision to Diff 410360.
ibookstein added a comment.

clang-format + description wording


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120266

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/attr-cpuspecific.c

Index: clang/test/CodeGen/attr-cpuspecific.c
===
--- clang/test/CodeGen/attr-cpuspecific.c
+++ clang/test/CodeGen/attr-cpuspecific.c
@@ -8,6 +8,7 @@
 #endif // _MSC_VER
 
 // Each version should have an IFunc and an alias.
+// LINUX: @SingleVersion = weak_odr alias void (), void ()* @SingleVersion.ifunc
 // LINUX: @TwoVersions = weak_odr alias void (), void ()* @TwoVersions.ifunc
 // LINUX: @TwoVersionsSameAttr = weak_odr alias void (), void ()* @TwoVersionsSameAttr.ifunc
 // LINUX: @ThreeVersionsSameAttr = weak_odr alias void (), void ()* @ThreeVersionsSameAttr.ifunc
@@ -18,8 +19,8 @@
 // LINUX: @GenericAndPentium = weak_odr alias i32 (i32, double), i32 (i32, double)* @GenericAndPentium.ifunc
 // LINUX: @DispatchFirst = weak_odr alias i32 (), i32 ()* @DispatchFirst.ifunc
 
-// LINUX: @TwoVersions.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersions.resolver
 // LINUX: @SingleVersion.ifunc = weak_odr ifunc void (), void ()* ()* @SingleVersion.resolver
+// LINUX: @TwoVersions.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersions.resolver
 // LINUX: @TwoVersionsSameAttr.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersionsSameAttr.resolver
 // LINUX: @ThreeVersionsSameAttr.ifunc = weak_odr ifunc void (), void ()* ()* @ThreeVersionsSameAttr.resolver
 // LINUX: @NoSpecifics.ifunc = weak_odr ifunc void (), void ()* ()* @NoSpecifics.resolver
@@ -34,6 +35,21 @@
 // LINUX: define{{.*}} void @SingleVersion.S() #[[S:[0-9]+]]
 // WINDOWS: define dso_local void @SingleVersion.S() #[[S:[0-9]+]]
 
+ATTR(cpu_dispatch(ivybridge))
+void SingleVersion(void);
+// LINUX: define weak_odr void ()* @SingleVersion.resolver()
+// LINUX: call void @__cpu_indicator_init
+// LINUX: ret void ()* @SingleVersion.S
+// LINUX: call void @llvm.trap
+// LINUX: unreachable
+
+// WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
+// WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: call void @SingleVersion.S()
+// WINDOWS-NEXT: ret void
+// WINDOWS: call void @llvm.trap
+// WINDOWS: unreachable
+
 ATTR(cpu_specific(ivybridge))
 void NotCalled(void){}
 // LINUX: define{{.*}} void @NotCalled.S() #[[S]]
@@ -80,6 +96,10 @@
 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.S() #[[S]]
 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.Z() #[[K]]
 
+ATTR(cpu_specific(knl))
+int CpuSpecificNoDispatch(void) { return 1; }
+// CHECK: define {{.*}}i32 @CpuSpecificNoDispatch.Z() #[[K:[0-9]+]]
+
 void usages(void) {
   SingleVersion();
   // LINUX: @SingleVersion.ifunc()
@@ -93,6 +113,9 @@
   ThreeVersionsSameAttr();
   // LINUX: @ThreeVersionsSameAttr.ifunc()
   // WINDOWS: @ThreeVersionsSameAttr()
+  CpuSpecificNoDispatch();
+  // LINUX: @CpuSpecificNoDispatch.ifunc()
+  // WINDOWS: @CpuSpecificNoDispatch()
 }
 
 // has an extra config to emit!
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -42,6 +42,7 @@
 class Constant;
 class ConstantInt;
 class Function;
+class GlobalIFunc;
 class GlobalValue;
 class DataLayout;
 class FunctionType;
@@ -352,6 +353,10 @@
   /// we properly emit the iFunc.
   std::vector MultiVersionFuncs;
 
+  /// List of multiversion IFuncs we have emitted. Used to downgrade into
+  /// function declarations when we do not emit a definition for the resolver.
+  std::vector MultiVersionIFuncs;
+
   typedef llvm::StringMap > ReplacementsTy;
   ReplacementsTy Replacements;
 
@@ -1555,6 +1560,10 @@
 
   void emitMultiVersionFunctions();
 
+  /// Replace multiversion IFuncs whose resolver is undefined with function
+  /// declarations.
+  void replaceUndefinedMultiVersionIFuncs();
+
   /// Emit any vtables which we deferred and still have a use for.
   void EmitDeferredVTables();
 
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -508,6 +508,7 @@
   applyReplacements();
   checkAliases();
   emitMultiVersionFunctions();
+  replaceUndefinedMultiVersionIFuncs();
   EmitCXXGlobalInitFunc();
   EmitCXXGlobalCleanUpFunc();
   registerGlobalDtorsWithAtExit();
@@ -3289,6 +3290,22 @@
 EmitGlobalFunctionDefinition(GD, GV);
 }
 
+void CodeGenModule::replaceUndefinedMultiVersionIFuncs() {
+  for (llvm::GlobalIFunc *GIF : MultiVersionIFuncs) {
+llvm::Function *Resolver = GIF->getResolverFunction();
+if (!Resolver->isDeclaration())
+  continue;
+
+auto *DeclTy = cast(GIF->getValueTyp

[PATCH] D118632: [Clang]OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG with a nit




Comment at: clang/include/clang/AST/StmtOpenMP.h:2970
+  }
+  /// Get
+  Expr *getCondExpr() {

Fix comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D120217: [clang-format] Add an option to insert braces after control statements

2022-02-21 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 410365.
owenpan marked an inline comment as done.
owenpan added a comment.

If the line immediately following `// clang-format off` is a line comment, 
`assert(!Token->Finalized)` will fail. Fixed it and updated the corresponding 
unit test.


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

https://reviews.llvm.org/D120217

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -19474,6 +19474,7 @@
   CHECK_PARSE_BOOL_FIELD(IndentRequiresClause, "IndentRequires");
   CHECK_PARSE_BOOL(IndentRequiresClause);
   CHECK_PARSE_BOOL(IndentWrappedFunctionNames);
+  CHECK_PARSE_BOOL(InsertBraces);
   CHECK_PARSE_BOOL(KeepEmptyLinesAtTheStartOfBlocks);
   CHECK_PARSE_BOOL(ObjCSpaceAfterProperty);
   CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
@@ -24300,6 +24301,202 @@
   verifyFormat("template  struct Foo {};", Style);
 }
 
+TEST_F(FormatTest, InsertBraces) {
+  FormatStyle Style = getLLVMStyle();
+  Style.InsertBraces = true;
+
+  verifyFormat("// clang-format off\n"
+   "// comment\n"
+   "if (a) f();\n"
+   "// clang-format on\n"
+   "if (b) {\n"
+   "  g();\n"
+   "}",
+   "// clang-format off\n"
+   "// comment\n"
+   "if (a) f();\n"
+   "// clang-format on\n"
+   "if (b) g();",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  switch (b) {\n"
+   "  case 1:\n"
+   "c = 0;\n"
+   "break;\n"
+   "  default:\n"
+   "c = 1;\n"
+   "  }\n"
+   "}",
+   "if (a)\n"
+   "  switch (b) {\n"
+   "  case 1:\n"
+   "c = 0;\n"
+   "break;\n"
+   "  default:\n"
+   "c = 1;\n"
+   "  }",
+   Style);
+
+  verifyFormat("for (auto node : nodes) {\n"
+   "  if (node) {\n"
+   "break;\n"
+   "  }\n"
+   "}",
+   "for (auto node : nodes)\n"
+   "  if (node)\n"
+   "break;",
+   Style);
+
+  verifyFormat("for (auto node : nodes) {\n"
+   "  if (node)\n"
+   "}",
+   "for (auto node : nodes)\n"
+   "  if (node)",
+   Style);
+
+  verifyFormat("do {\n"
+   "  --a;\n"
+   "} while (a);",
+   "do\n"
+   "  --a;\n"
+   "while (a);",
+   Style);
+
+  verifyFormat("if (i) {\n"
+   "  ++i;\n"
+   "} else {\n"
+   "  --i;\n"
+   "}",
+   "if (i)\n"
+   "  ++i;\n"
+   "else {\n"
+   "  --i;\n"
+   "}",
+   Style);
+
+  verifyFormat("void f() {\n"
+   "  while (j--) {\n"
+   "while (i) {\n"
+   "  --i;\n"
+   "}\n"
+   "  }\n"
+   "}",
+   "void f() {\n"
+   "  while (j--)\n"
+   "while (i)\n"
+   "  --i;\n"
+   "}",
+   Style);
+
+  verifyFormat("f({\n"
+   "  if (a) {\n"
+   "g();\n"
+   "  }\n"
+   "});",
+   "f({\n"
+   "  if (a)\n"
+   "g();\n"
+   "});",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  f();\n"
+   "} else if (b) {\n"
+   "  g();\n"
+   "} else {\n"
+   "  h();\n"
+   "}",
+   "if (a)\n"
+   "  f();\n"
+   "else if (b)\n"
+   "  g();\n"
+   "else\n"
+   "  h();",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  f();\n"
+   "}\n"
+   "// comment\n"
+   "/* comment */",
+   "if (a)\n"
+   "  f();\n"
+   "// comment\n"
+   "/* comment */",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  // foo\n"
+   "  // bar\n"
+   "  f();\n"
+   "}",
+   "if (a)\n"
+   "  // foo\n"
+   "  // bar\n"
+   "  f();",
+   Style);
+
+  verifyFormat("if (a) { // comment\n"
+   "

[clang] f9c3310 - [OPENMP]Fix PR49366: crash on VLAs in task untied regions.

2022-02-21 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2022-02-21T12:28:47-08:00
New Revision: f9c3310d32c62b28c10084a0104563aeeecc06ec

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

LOG: [OPENMP]Fix PR49366: crash on VLAs in task untied regions.

We need to capture the local variables into a record in task untied
regions but clang does not support record with VLA data members.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaType.cpp
clang/test/OpenMP/task_messages.cpp
clang/test/OpenMP/taskloop_loop_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1854c8e522b82..11fcd5ff5a323 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10893,6 +10893,8 @@ def err_omp_clause_requires_dispatch_construct : Error<
   "'%0' clause requires 'dispatch' context selector">;
 def err_omp_append_args_with_varargs : Error<
   "'append_args' is not allowed with varargs functions">;
+def err_openmp_vla_in_task_untied : Error<
+  "variable length arrays are not supported in OpenMP tasking regions with 
'untied' clause">;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index dfa12ad40b72a..2d47a20711817 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10688,6 +10688,10 @@ class Sema final {
   void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller,
  const FunctionDecl *Callee,
  SourceLocation Loc);
+
+  /// Return true if currently in OpenMP task with untied clause context.
+  bool isInOpenMPTaskUntiedContext() const;
+
   /// Return true inside OpenMP declare target region.
   bool isInOpenMPDeclareTargetContext() const {
 return !DeclareTargetNesting.empty();

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 43386c1ef8edb..ad8d304ef43c3 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -176,6 +176,7 @@ class DSAStackTy {
 bool HasMutipleLoops = false;
 const Decl *PossiblyLoopCounter = nullptr;
 bool NowaitRegion = false;
+bool UntiedRegion = false;
 bool CancelRegion = false;
 bool LoopStart = false;
 bool BodyComplete = false;
@@ -851,6 +852,15 @@ class DSAStackTy {
   return Parent->NowaitRegion;
 return false;
   }
+  /// Marks current region as untied (it has a 'untied' clause).
+  void setUntiedRegion(bool IsUntied = true) {
+getTopOfStack().UntiedRegion = IsUntied;
+  }
+  /// Return true if current region is untied.
+  bool isUntiedRegion() const {
+const SharingMapTy *Top = getTopOfStackOrNull();
+return Top ? Top->UntiedRegion : false;
+  }
   /// Marks parent region as cancel region.
   void setParentCancelRegion(bool Cancel = true) {
 if (SharingMapTy *Parent = getSecondOnStackOrNull())
@@ -2158,6 +2168,11 @@ unsigned Sema::getOpenMPNestingLevel() const {
   return DSAStack->getNestingLevel();
 }
 
+bool Sema::isInOpenMPTaskUntiedContext() const {
+  return isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) &&
+ DSAStack->isUntiedRegion();
+}
+
 bool Sema::isInOpenMPTargetExecutionDirective() const {
   return (isOpenMPTargetExecutionDirective(DSAStack->getCurrentDirective()) &&
   !DSAStack->isClauseParsingMode()) ||
@@ -16232,6 +16247,7 @@ OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation 
StartLoc,
 
 OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc,
  SourceLocation EndLoc) {
+  DSAStack->setUntiedRegion();
   return new (Context) OMPUntiedClause(StartLoc, EndLoc);
 }
 

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 74969749e54ae..35d4c386211e5 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2458,6 +2458,9 @@ QualType Sema::BuildArrayType(QualType T, 
ArrayType::ArraySizeModifier ASM,
   } else if (isSFINAEContext()) {
 VLADiag = diag::err_vla_in_sfinae;
 VLAIsError = true;
+  } else if (getLangOpts().OpenMP && isInOpenMPTaskUntiedContext()) {
+VLADiag = diag::err_openmp_vla_in_task_untied;
+VLAIsError = true;
   } else {
 VLADiag = diag::ext_vla;
 VLAIsError = false;

diff  --git a/clang/test/OpenMP/task_messages.cpp 
b/clang/test/OpenMP/task_messages.cpp
index 13cbfb6c45693..86a3f0d481316 100644
--- a/clang/test/OpenMP/task_messages.cpp
+++ b/c

[PATCH] D99436: [OPENMP]Fix PR49366: crash on VLAs in task untied regions.

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf9c3310d32c6: [OPENMP]Fix PR49366: crash on VLAs in task 
untied regions. (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99436

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/OpenMP/task_messages.cpp
  clang/test/OpenMP/taskloop_loop_messages.cpp

Index: clang/test/OpenMP/taskloop_loop_messages.cpp
===
--- clang/test/OpenMP/taskloop_loop_messages.cpp
+++ clang/test/OpenMP/taskloop_loop_messages.cpp
@@ -691,7 +691,7 @@
 
 void test_loop_eh() {
   const int N = 100;
-  float a[N], b[N], c[N];
+  float a[N], b[N], c[N]; // expected-note {{declared here}}
 #pragma omp parallel
 #pragma omp taskloop
   for (int i = 0; i < 10; i++) {
@@ -729,6 +729,13 @@
   void g() { throw 0; }
 };
   }
+// expected-error@+5 {{variable length arrays are not supported in OpenMP tasking regions with 'untied' clause}}
+// expected-note@+4 {{read of non-constexpr variable 'c' is not allowed in a constant expression}}
+#pragma omp taskloop untied
+  {
+  for (int i = 0; i < 10; ++i)
+int array[(int)c[0]];
+  }
 }
 
 void test_loop_firstprivate_lastprivate() {
Index: clang/test/OpenMP/task_messages.cpp
===
--- clang/test/OpenMP/task_messages.cpp
+++ clang/test/OpenMP/task_messages.cpp
@@ -173,7 +173,7 @@
   int &b = a;
   S sa;
   S &sb = sa;
-  int r;
+  int r; // expected-note {{declared here}}
 #pragma omp task { // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
   foo();
 #pragma omp task( // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
@@ -330,6 +330,12 @@
 // expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
 #pragma omp task mergeable mergeable
   ++r;
+// expected-error@+4 {{variable length arrays are not supported in OpenMP tasking regions with 'untied' clause}}
+// expected-note@+3 {{read of non-const variable 'r' is not allowed in a constant expression}}
+#pragma omp task untied
+  {
+int array[r];
+  }
   volatile omp_event_handle_t evt;
   omp_event_handle_t sevt;
   const omp_event_handle_t cevt = evt;
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2458,6 +2458,9 @@
   } else if (isSFINAEContext()) {
 VLADiag = diag::err_vla_in_sfinae;
 VLAIsError = true;
+  } else if (getLangOpts().OpenMP && isInOpenMPTaskUntiedContext()) {
+VLADiag = diag::err_openmp_vla_in_task_untied;
+VLAIsError = true;
   } else {
 VLADiag = diag::ext_vla;
 VLAIsError = false;
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -176,6 +176,7 @@
 bool HasMutipleLoops = false;
 const Decl *PossiblyLoopCounter = nullptr;
 bool NowaitRegion = false;
+bool UntiedRegion = false;
 bool CancelRegion = false;
 bool LoopStart = false;
 bool BodyComplete = false;
@@ -851,6 +852,15 @@
   return Parent->NowaitRegion;
 return false;
   }
+  /// Marks current region as untied (it has a 'untied' clause).
+  void setUntiedRegion(bool IsUntied = true) {
+getTopOfStack().UntiedRegion = IsUntied;
+  }
+  /// Return true if current region is untied.
+  bool isUntiedRegion() const {
+const SharingMapTy *Top = getTopOfStackOrNull();
+return Top ? Top->UntiedRegion : false;
+  }
   /// Marks parent region as cancel region.
   void setParentCancelRegion(bool Cancel = true) {
 if (SharingMapTy *Parent = getSecondOnStackOrNull())
@@ -2158,6 +2168,11 @@
   return DSAStack->getNestingLevel();
 }
 
+bool Sema::isInOpenMPTaskUntiedContext() const {
+  return isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) &&
+ DSAStack->isUntiedRegion();
+}
+
 bool Sema::isInOpenMPTargetExecutionDirective() const {
   return (isOpenMPTargetExecutionDirective(DSAStack->getCurrentDirective()) &&
   !DSAStack->isClauseParsingMode()) ||
@@ -16232,6 +16247,7 @@
 
 OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc,
  SourceLocation EndLoc) {
+  DSAStack->setUntiedRegion();
   return new (Context) OMPUntiedClause(StartLoc, EndLoc);
 }
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clan

[libunwind] 3fa2e66 - [libunwind] Further fix for 32-bit PowerPC processors without AltiVec

2022-02-21 Thread Brad Smith via cfe-commits

Author: George Koehler
Date: 2022-02-21T15:31:23-05:00
New Revision: 3fa2e66c10aadac1d209afadba34d90c9bd95221

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

LOG: [libunwind] Further fix for 32-bit PowerPC processors without AltiVec

https://reviews.llvm.org/D91906 did most of the work necessary to fix libunwind 
on
32-bit PowerPC processors without AltiVec, but there was one more piece 
necessary.

Reviewed By: luporl

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

Added: 


Modified: 
libunwind/src/UnwindRegistersSave.S

Removed: 




diff  --git a/libunwind/src/UnwindRegistersSave.S 
b/libunwind/src/UnwindRegistersSave.S
index 9566bb0335fee..b39489235ce63 100644
--- a/libunwind/src/UnwindRegistersSave.S
+++ b/libunwind/src/UnwindRegistersSave.S
@@ -603,9 +603,11 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
   stw 30,128(3)
   stw 31,132(3)
 
+#if defined(__ALTIVEC__)
   // save VRSave register
   mfspr   0, 256
   stw 0, 156(3)
+#endif
   // save CR registers
   mfcr0
   stw 0, 136(3)



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


[PATCH] D120258: [clangd] Add inlay hints for auto-typed parameters with one instantiation.

2022-02-21 Thread Trass3r via Phabricator via cfe-commits
Trass3r added a comment.

Looks like this only covers a subset.
I see hints for some generic lambdas but not for others while hovering over 
auto reveals the type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120258

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


[PATCH] D120258: [clangd] Add inlay hints for auto-typed parameters with one instantiation.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks - any chance you can reduce an example where hover works and inlay hints 
do not?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120258

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


[PATCH] D118632: [Clang]OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D118632#3336094 , @ABataev wrote:

> LG with a nit

Actually I got two question in the inline comments. Can you please take a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D120273: [OpenMP] Allow CUDA to be linked with OpenMP using the new driver

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 410370.
jhuber6 added a comment.

Make sure we don't pass PTX to nvlink.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120273

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -163,7 +163,10 @@
 };
 
 namespace llvm {
-/// Helper that allows DeviceFile to be used as a key in a DenseMap.
+/// Helper that allows DeviceFile to be used as a key in a DenseMap. For now we
+/// assume device files with matching architectures and triples but different
+/// offloading kinds should be handlded together, this may not be true in the
+/// future.
 template <> struct DenseMapInfo {
   static DeviceFile getEmptyKey() {
 return {DenseMapInfo::getEmptyKey(),
@@ -178,13 +181,11 @@
 DenseMapInfo::getTombstoneKey()};
   }
   static unsigned getHashValue(const DeviceFile &I) {
-return DenseMapInfo::getHashValue(I.OffloadKind) ^
-   DenseMapInfo::getHashValue(I.TheTriple) ^
+return DenseMapInfo::getHashValue(I.TheTriple) ^
DenseMapInfo::getHashValue(I.Arch);
   }
   static bool isEqual(const DeviceFile &LHS, const DeviceFile &RHS) {
-return LHS.OffloadKind == RHS.OffloadKind &&
-   LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
+return LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
   }
 };
 } // namespace llvm
@@ -196,10 +197,12 @@
   SmallVectorImpl &DeviceFiles);
 
 static StringRef getDeviceFileExtension(StringRef DeviceTriple,
-bool IsBitcode = false) {
+file_magic magic) {
   Triple TheTriple(DeviceTriple);
-  if (TheTriple.isAMDGPU() || IsBitcode)
+  if (magic == file_magic::bitcode)
 return "bc";
+  if (TheTriple.isNVPTX() && magic == file_magic::unknown)
+return "s";
   if (TheTriple.isNVPTX())
 return "cubin";
   return "o";
@@ -300,8 +303,8 @@
 
 if (Expected Contents = Sec.getContents()) {
   SmallString<128> TempFile;
-  StringRef DeviceExtension = getDeviceFileExtension(
-  DeviceTriple, identify_magic(*Contents) == file_magic::bitcode);
+  StringRef DeviceExtension =
+  getDeviceFileExtension(DeviceTriple, identify_magic(*Contents));
   if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" +
DeviceTriple + "-" + Arch,
DeviceExtension, TempFile))
@@ -411,8 +414,8 @@
 
 StringRef Contents = CDS->getAsString();
 SmallString<128> TempFile;
-StringRef DeviceExtension = getDeviceFileExtension(
-DeviceTriple, identify_magic(Contents) == file_magic::bitcode);
+StringRef DeviceExtension =
+getDeviceFileExtension(DeviceTriple, identify_magic(Contents));
 if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" + DeviceTriple +
  "-" + Arch,
  DeviceExtension, TempFile))
@@ -632,7 +635,8 @@
 
   // Add extracted input files.
   for (StringRef Input : InputFiles)
-CmdArgs.push_back(Input);
+if (Input.endswith(".cubin"))
+  CmdArgs.push_back(Input);
 
   if (sys::ExecuteAndWait(*NvlinkPath, CmdArgs))
 return createStringError(inconvertibleErrorCode(), "'nvlink' failed");
@@ -908,7 +912,22 @@
   return createFileError(File, EC);
 
 file_magic Type = identify_magic((*BufferOrErr)->getBuffer());
-if (Type != file_magic::bitcode) {
+switch (Type) {
+case file_magic::bitcode: {
+  Expected> InputFileOrErr =
+  llvm::lto::InputFile::create(**BufferOrErr);
+  if (!InputFileOrErr)
+return InputFileOrErr.takeError();
+
+  // Save the input file and the buffer associated with its memory.
+  BitcodeFiles.push_back(std::move(*InputFileOrErr));
+  SavedBuffers.push_back(std::move(*BufferOrErr));
+  continue;
+}
+case file_magic::elf_relocatable:
+case file_magic::elf_shared_object:
+case file_magic::macho_object:
+case file_magic::coff_object: {
   Expected> ObjFile =
   ObjectFile::createObjectFile(**BufferOrErr, Type);
   if (!ObjFile)
@@ -926,15 +945,10 @@
 else
   UsedInSharedLib.insert(Saver.save(*Name));
   }
-} else {
-  Expected> InputFileOrErr =
-  llvm::lto::InputFile::create(**BufferOrErr);
-  if (!InputFileOrErr)
-return InputFileOrErr.takeError();
-
-  // Save the input file and the buffer associated with its memory.
-  BitcodeFiles.push_back(std::move(*InputFileOrErr));
-  SavedBuffers.push_back(std::move(*BufferOrErr));
+  continue;
+}
+

[PATCH] D118632: [Clang][OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D118632#3336133 , @tianshilei1992 
wrote:

> In D118632#3336094 , @ABataev wrote:
>
>> LG with a nit
>
> Actually I got two question in the inline comments. Can you please take a 
> look?

Could you point me?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D118588: [C++20][Modules]5/8] Diagnose wrong import/export for partition CMIs.

2022-02-21 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 410371.
iains added a comment.

rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118588

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/cxx20-10-3-ex1.cpp
  clang/test/Modules/cxx20-10-3-ex2.cpp
  clang/test/Modules/cxx20-import-diagnostics-a.cpp

Index: clang/test/Modules/cxx20-import-diagnostics-a.cpp
===
--- clang/test/Modules/cxx20-import-diagnostics-a.cpp
+++ clang/test/Modules/cxx20-import-diagnostics-a.cpp
@@ -117,13 +117,13 @@
 
 module B;
 
-import B; // expected-error {{import of module 'B' appears within same top-level module 'B'}}
+import B; // expected-error {{import of module 'B' appears within its own implementation}}
 
 #elif TU == 9
 
 export module B;
 
-import B; // expected-error {{import of module 'B' appears within same top-level module 'B'}}
+import B; // expected-error {{import of module 'B' appears within its own interface}}
 
 #elif TU == 10
 
Index: clang/test/Modules/cxx20-10-3-ex2.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-3-ex2.cpp
@@ -0,0 +1,28 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=0 -x c++ %s \
+// RUN:  -o %t/M.pcm
+
+// RUN: %clang_cc1 -std=c++20 -S -D TU=1 -x c++ %s \
+// RUN:  -fmodule-file=%t/M.pcm -o %t/tu_8.s -verify
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=2 -x c++ %s \
+// RUN:  -o %t/M.pcm -verify
+
+#if TU == 0
+export module M;
+
+#elif TU == 1
+module M;
+  // error: cannot import M in its own unit
+import M; // expected-error {{import of module 'M' appears within its own implementation}}
+
+#elif TU == 2
+export module M;
+  // error: cannot import M in its own unit
+import M; // expected-error {{import of module 'M' appears within its own interface}}
+
+#else
+#error "no TU set"
+#endif
Index: clang/test/Modules/cxx20-10-3-ex1.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-3-ex1.cpp
@@ -0,0 +1,36 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=1 -x c++ %s \
+// RUN:  -o %t/M_PartImpl.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=2 -x c++ %s \
+// RUN:  -fmodule-file=%t/M_PartImpl.pcm -o %t/M.pcm -verify
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=3 -x c++ %s \
+// RUN:  -o %t/M_Part.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=4 -x c++ %s \
+// RUN:  -fmodule-file=%t/M_Part.pcm -o %t/M.pcm
+
+#if TU == 1
+module M:PartImpl;
+
+// expected-no-diagnostics
+#elif TU == 2
+export module M;
+ // error: exported partition :Part is an implementation unit
+export import :PartImpl; // expected-error {{module partition implementations cannot be exported}}
+
+#elif TU == 3
+export module M:Part;
+
+// expected-no-diagnostics
+#elif TU == 4
+export module M;
+export import :Part;
+
+// expected-no-diagnostics
+#else
+#error "no TU set"
+#endif
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -403,10 +403,16 @@
   }
 
   // Diagnose self-import before attempting a load.
+  // [module.import]/9
+  // A module implementation unit of a module M that is not a module partition
+  // shall not contain a module-import-declaration nominating M.
+  // (for an implementation, the module interface is imported implicitly,
+  //  but that's handled in the module decl code).
+
   if (getLangOpts().CPlusPlusModules && isCurrentModulePurview() &&
   getCurrentModule()->Name == ModuleName) {
-Diag(ImportLoc, diag::err_module_self_import)
-<< ModuleName << getLangOpts().CurrentModule;
+Diag(ImportLoc, diag::err_module_self_import_cxx20)
+<< ModuleName << !ModuleScopes.back().ModuleInterface;
 return true;
   }
 
@@ -440,8 +446,7 @@
   // of the same top-level module. Until we do, make it an error rather than
   // silently ignoring the import.
   // FIXME: Should we warn on a redundant import of the current module?
-  if (!getLangOpts().CPlusPlusModules &&
-  Mod->getTopLevelModuleName() == getLangOpts().CurrentModule &&
+  if (Mod->getTopLevelModuleName() == getLangOpts().CurrentModule &&
   (getLangOpts().isCompilingModule() || !getLangOpts().ModulesTS)) {
 Diag(ImportLoc, getLangOpts().isCompilingModule()
 ? diag::err_module_self_import
@@ -482,7 +487,12 @@
   if (!ModuleScopes.empty())
 Context.addModuleInitializer(ModuleScopes.back().Module, Import);
 
-  if (!ModuleScopes.empty() && ModuleScopes.back().ModuleInterface) {
+  // A module (partition) implementat

[PATCH] D120278: [clang-format] Don't break semi after requires clause regardless of the chosen style

2022-02-21 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: owenpan, MyDeveloperDay, curdeius, JohelEGP.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120278

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23853,6 +23853,11 @@
"}",
Style);
 
+  verifyFormat("template \n"
+   "int bar(T t)\n"
+   "  requires F;",
+   Style);
+
   Style.IndentRequiresClause = false;
   verifyFormat("template \n"
"requires F\n"
@@ -23873,6 +23878,7 @@
   verifyFormat("template  requires Foo struct Bar {};\n"
"template  requires Foo void bar() {}\n"
"template  void bar() requires Foo {}\n"
+   "template  void bar() requires Foo;\n"
"template  requires Foo Bar(T) -> Bar;",
Style);
 
@@ -23925,6 +23931,9 @@
"void bar()\n"
"requires Foo {}\n"
"template \n"
+   "void bar()\n"
+   "requires Foo;\n"
+   "template \n"
"requires Foo Bar(T) -> Bar;",
Style);
 
@@ -23984,6 +23993,7 @@
"template \n"
"void bar() requires Foo\n"
"{}\n"
+   "template  void bar() requires Foo;\n"
"template  requires Foo\n"
"Bar(T) -> Bar;",
Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3964,7 +3964,7 @@
   return Style.BreakBeforeConceptDeclarations == FormatStyle::BBCDS_Always;
 return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes;
   }
-  if (Left.ClosesRequiresClause) {
+  if (Left.ClosesRequiresClause && Right.isNot(tok::semi)) {
 switch (Style.RequiresClausePosition) {
 case FormatStyle::RCPS_OwnLine:
 case FormatStyle::RCPS_WithPreceding:


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23853,6 +23853,11 @@
"}",
Style);
 
+  verifyFormat("template \n"
+   "int bar(T t)\n"
+   "  requires F;",
+   Style);
+
   Style.IndentRequiresClause = false;
   verifyFormat("template \n"
"requires F\n"
@@ -23873,6 +23878,7 @@
   verifyFormat("template  requires Foo struct Bar {};\n"
"template  requires Foo void bar() {}\n"
"template  void bar() requires Foo {}\n"
+   "template  void bar() requires Foo;\n"
"template  requires Foo Bar(T) -> Bar;",
Style);
 
@@ -23925,6 +23931,9 @@
"void bar()\n"
"requires Foo {}\n"
"template \n"
+   "void bar()\n"
+   "requires Foo;\n"
+   "template \n"
"requires Foo Bar(T) -> Bar;",
Style);
 
@@ -23984,6 +23993,7 @@
"template \n"
"void bar() requires Foo\n"
"{}\n"
+   "template  void bar() requires Foo;\n"
"template  requires Foo\n"
"Bar(T) -> Bar;",
Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3964,7 +3964,7 @@
   return Style.BreakBeforeConceptDeclarations == FormatStyle::BBCDS_Always;
 return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes;
   }
-  if (Left.ClosesRequiresClause) {
+  if (Left.ClosesRequiresClause && Right.isNot(tok::semi)) {
 switch (Style.RequiresClausePosition) {
 case FormatStyle::RCPS_OwnLine:
 case FormatStyle::RCPS_WithPreceding:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120280: [CMake][Fuchsia] Disable assertions and analyzer for stage 1

2022-02-21 Thread Petr Hosek 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 rGeec3488cf1d8: [CMake][Fuchsia] Disable assertions and 
analyzer for stage 1 (authored by phosek).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120280

Files:
  clang/cmake/caches/Fuchsia.cmake


Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -6,8 +6,8 @@
 
 set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld;llvm;polly" CACHE STRING 
"")
 
-set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
 set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
@@ -29,13 +29,14 @@
 endif()
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
-set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
+set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
 
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 
-set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 if(APPLE)
   set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")


Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -6,8 +6,8 @@
 
 set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld;llvm;polly" CACHE STRING "")
 
-set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
 set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
@@ -29,13 +29,14 @@
 endif()
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
-set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
+set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
 
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 
-set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 if(APPLE)
   set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] eec3488 - [CMake][Fuchsia] Disable assertions and analyzer for stage 1

2022-02-21 Thread Petr Hosek via cfe-commits

Author: Petr Hosek
Date: 2022-02-21T13:31:13-08:00
New Revision: eec3488cf1d84d3503d5a8535b64374b79287bb9

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

LOG: [CMake][Fuchsia] Disable assertions and analyzer for stage 1

We don't need these in the first stage compiler and disabling these
helps a bit with the compile time and runtime performance.

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

Added: 


Modified: 
clang/cmake/caches/Fuchsia.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia.cmake 
b/clang/cmake/caches/Fuchsia.cmake
index a531f9f1c10d8..8e9e44d5917ed 100644
--- a/clang/cmake/caches/Fuchsia.cmake
+++ b/clang/cmake/caches/Fuchsia.cmake
@@ -6,8 +6,8 @@ set(PACKAGE_VENDOR Fuchsia CACHE STRING "")
 
 set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld;llvm;polly" CACHE STRING 
"")
 
-set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
 set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
@@ -29,13 +29,14 @@ if(NOT APPLE)
 endif()
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
-set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
+set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
 
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 
-set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 if(APPLE)
   set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")



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


[PATCH] D120258: [clangd] Add inlay hints for auto-typed parameters with one instantiation.

2022-02-21 Thread Trass3r via Phabricator via cfe-commits
Trass3r added a comment.

No apparent differences. Is there a way to automatically reduce it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120258

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


[PATCH] D118632: [Clang][OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D118632#3336145 , @ABataev wrote:

> In D118632#3336133 , 
> @tianshilei1992 wrote:
>
>> In D118632#3336094 , @ABataev 
>> wrote:
>>
>>> LG with a nit
>>
>> Actually I got two question in the inline comments. Can you please take a 
>> look?
>
> Could you point me?

Sure.




Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:6041
+  llvm::Value *EVal = CGF.EmitScalarExpr(E->IgnoreImpCasts());
+  llvm::Value *DVal = D ? CGF.EmitScalarExpr(D->IgnoreImpCasts()) : nullptr;
+

tianshilei1992 wrote:
> Using `D->IgnoreImpCasts()` can make sure to avoid the case that `char` is 
> casted to `int` in binary operation. However, say, if user writes the 
> following code:
> ```
> int x;
> #pragma omp atomic compare
>   x = x > 1.01 ? 1.01 : x;
> ```
> `1.01` here will be casted to `1` by clang, and a warning will be emitted. 
> Because we ignore the implicit cast, in Sema, it is taken as floating point 
> value. However, we already told user that it is casted to `1`, which is a 
> little weird to emit an error then.
@ABataev Here.



Comment at: clang/test/OpenMP/atomic_compare_codegen.cpp:1990
+// CHECK-NEXT:[[DD:%.*]] = alloca double, align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i8, i8* [[CE]], align 1
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw umin i8* [[CX]], i8 [[TMP0]] 
monotonic, align 1

tianshilei1992 wrote:
> tianshilei1992 wrote:
> > I think the `store` here is redundant. Is it because I'm using 
> > `CGF.EmitScalarExpr`?
> Oh, shoot. `load` here, instead of `store`.
And here. @ABataev 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D120282: [Format] Remove unused LineContainsContinuedForLoopSection. NFC

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: MyDeveloperDay.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120282

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/ContinuationIndenter.h


Index: clang/lib/Format/ContinuationIndenter.h
===
--- clang/lib/Format/ContinuationIndenter.h
+++ clang/lib/Format/ContinuationIndenter.h
@@ -419,9 +419,6 @@
   /// The token that needs to be next formatted.
   FormatToken *NextToken;
 
-  /// \c true if this line contains a continued for-loop section.
-  bool LineContainsContinuedForLoopSection;
-
   /// \c true if \p NextToken should not continue this line.
   bool NoContinuation;
 
@@ -468,9 +465,6 @@
   return NextToken < Other.NextToken;
 if (Column != Other.Column)
   return Column < Other.Column;
-if (LineContainsContinuedForLoopSection !=
-Other.LineContainsContinuedForLoopSection)
-  return LineContainsContinuedForLoopSection;
 if (NoContinuation != Other.NoContinuation)
   return NoContinuation;
 if (StartOfLineLevel != Other.StartOfLineLevel)
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -253,7 +253,6 @@
   State.Stack.push_back(ParenState(/*Tok=*/nullptr, FirstIndent, FirstIndent,
/*AvoidBinPacking=*/false,
/*NoLineBreak=*/false));
-  State.LineContainsContinuedForLoopSection = false;
   State.NoContinuation = false;
   State.StartOfStringLiteral = 0;
   State.StartOfLineLevel = 0;
@@ -343,8 +342,6 @@
 return true;
   if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren))
 return true;
-  if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
-return true;
   if (Style.Language == FormatStyle::LK_ObjC &&
   Style.ObjCBreakBeforeNestedBlockParam &&
   Current.ObjCSelectorNameParts > 1 &&


Index: clang/lib/Format/ContinuationIndenter.h
===
--- clang/lib/Format/ContinuationIndenter.h
+++ clang/lib/Format/ContinuationIndenter.h
@@ -419,9 +419,6 @@
   /// The token that needs to be next formatted.
   FormatToken *NextToken;
 
-  /// \c true if this line contains a continued for-loop section.
-  bool LineContainsContinuedForLoopSection;
-
   /// \c true if \p NextToken should not continue this line.
   bool NoContinuation;
 
@@ -468,9 +465,6 @@
   return NextToken < Other.NextToken;
 if (Column != Other.Column)
   return Column < Other.Column;
-if (LineContainsContinuedForLoopSection !=
-Other.LineContainsContinuedForLoopSection)
-  return LineContainsContinuedForLoopSection;
 if (NoContinuation != Other.NoContinuation)
   return NoContinuation;
 if (StartOfLineLevel != Other.StartOfLineLevel)
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -253,7 +253,6 @@
   State.Stack.push_back(ParenState(/*Tok=*/nullptr, FirstIndent, FirstIndent,
/*AvoidBinPacking=*/false,
/*NoLineBreak=*/false));
-  State.LineContainsContinuedForLoopSection = false;
   State.NoContinuation = false;
   State.StartOfStringLiteral = 0;
   State.StartOfLineLevel = 0;
@@ -343,8 +342,6 @@
 return true;
   if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren))
 return true;
-  if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
-return true;
   if (Style.Language == FormatStyle::LK_ObjC &&
   Style.ObjCBreakBeforeNestedBlockParam &&
   Current.ObjCSelectorNameParts > 1 &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >